From 6d7da7bdbe0ee299a9c915d905ae4e5771d3aae6 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 18 Oct 2024 14:18:26 +0200 Subject: [PATCH] Revert "Upgrade to Rust 1.82 toolchain" (#13810) --- .github/workflows/ci.yaml | 2 +- .github/workflows/publish-playground.yml | 2 +- .github/workflows/publish-wasm.yml | 2 +- crates/red_knot_server/src/server.rs | 2 - .../rules/printf_string_formatting.rs | 53 ++++++++++--------- crates/ruff_macros/src/cache_key.rs | 11 ++-- crates/ruff_macros/src/map_codes.rs | 14 +++-- crates/ruff_macros/src/rule_code_prefix.rs | 7 ++- .../src/pattern/pattern_match_star.rs | 7 ++- crates/ruff_server/src/server.rs | 2 - rust-toolchain.toml | 2 +- 11 files changed, 50 insertions(+), 54 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a7d579706584d..1b44b470a6545 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -193,7 +193,7 @@ jobs: run: rustup target add wasm32-unknown-unknown - uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 18 cache: "npm" cache-dependency-path: playground/package-lock.json - uses: jetli/wasm-pack-action@v0.4.0 diff --git a/.github/workflows/publish-playground.yml b/.github/workflows/publish-playground.yml index 3c251b419bf0d..67d18688adc08 100644 --- a/.github/workflows/publish-playground.yml +++ b/.github/workflows/publish-playground.yml @@ -29,7 +29,7 @@ jobs: run: rustup target add wasm32-unknown-unknown - uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 18 cache: "npm" cache-dependency-path: playground/package-lock.json - uses: jetli/wasm-pack-action@v0.4.0 diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index c33406f118c75..2cab1a873c65b 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -43,7 +43,7 @@ jobs: - run: cp LICENSE crates/ruff_wasm/pkg # wasm-pack does not put the LICENSE file in the pkg - uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 18 registry-url: "https://registry.npmjs.org" - name: "Publish (dry-run)" if: ${{ inputs.plan == '' || fromJson(inputs.plan).announcement_tag_is_implicit }} diff --git a/crates/red_knot_server/src/server.rs b/crates/red_knot_server/src/server.rs index eca1eedfd0ad6..5f198cbb4286c 100644 --- a/crates/red_knot_server/src/server.rs +++ b/crates/red_knot_server/src/server.rs @@ -1,7 +1,6 @@ //! Scheduling, I/O, and API endpoints. use std::num::NonZeroUsize; -#[allow(deprecated)] use std::panic::PanicInfo; use lsp_server::Message; @@ -120,7 +119,6 @@ impl Server { } pub(crate) fn run(self) -> crate::Result<()> { - #[allow(deprecated)] type PanicHook = Box) + 'static + Sync + Send>; struct RestorePanicHook { hook: Option, diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs index 2c66fd26f1a3c..48e6a85aaef66 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs @@ -235,35 +235,38 @@ fn clean_params_dictionary(right: &Expr, locator: &Locator, stylist: &Stylist) - let mut seen: Vec<&str> = vec![]; let mut indent = None; for ast::DictItem { key, value } in items { - if let Some(key) = key { - if let Expr::StringLiteral(ast::ExprStringLiteral { - value: key_string, .. - }) = key - { - // If the dictionary key is not a valid variable name, abort. - if !is_identifier(key_string.to_str()) { - return None; - } - // If there are multiple entries of the same key, abort. - if seen.contains(&key_string.to_str()) { - return None; - } - seen.push(key_string.to_str()); - if is_multi_line { - if indent.is_none() { - indent = indentation(locator, key); + match key { + Some(key) => { + if let Expr::StringLiteral(ast::ExprStringLiteral { + value: key_string, .. + }) = key + { + // If the dictionary key is not a valid variable name, abort. + if !is_identifier(key_string.to_str()) { + return None; + } + // If there are multiple entries of the same key, abort. + if seen.contains(&key_string.to_str()) { + return None; + } + seen.push(key_string.to_str()); + if is_multi_line { + if indent.is_none() { + indent = indentation(locator, key); + } } - } + let value_string = locator.slice(value); + arguments.push(format!("{key_string}={value_string}")); + } else { + // If there are any non-string keys, abort. + return None; + } + } + None => { let value_string = locator.slice(value); - arguments.push(format!("{key_string}={value_string}")); - } else { - // If there are any non-string keys, abort. - return None; + arguments.push(format!("**{value_string}")); } - } else { - let value_string = locator.slice(value); - arguments.push(format!("**{value_string}")); } } // If we couldn't parse out key values, abort. diff --git a/crates/ruff_macros/src/cache_key.rs b/crates/ruff_macros/src/cache_key.rs index 65418ac4aa1d1..6519982950a7d 100644 --- a/crates/ruff_macros/src/cache_key.rs +++ b/crates/ruff_macros/src/cache_key.rs @@ -75,11 +75,12 @@ pub(crate) fn derive_cache_key(item: &DeriveInput) -> syn::Result { } } - let field_attr = if let Some(ident) = &field.ident { - quote!(self.#ident) - } else { - let index = syn::Index::from(i); - quote!(self.#index) + let field_attr = match &field.ident { + Some(ident) => quote!(self.#ident), + None => { + let index = syn::Index::from(i); + quote!(self.#index) + } }; fields.push(quote!(#field_attr.cache_key(key);)); diff --git a/crates/ruff_macros/src/map_codes.rs b/crates/ruff_macros/src/map_codes.rs index 49cdf560691e5..b1534a4bcb6b7 100644 --- a/crates/ruff_macros/src/map_codes.rs +++ b/crates/ruff_macros/src/map_codes.rs @@ -143,10 +143,9 @@ pub(crate) fn map_codes(func: &ItemFn) -> syn::Result { for (prefix, rules) in &rules_by_prefix { let prefix_ident = get_prefix_ident(prefix); let attrs = intersection_all(rules.iter().map(|(.., attrs)| attrs.as_slice())); - let attrs = if attrs.is_empty() { - quote!() - } else { - quote!(#(#attrs)*) + let attrs = match attrs.as_slice() { + [] => quote!(), + [..] => quote!(#(#attrs)*), }; all_codes.push(quote! { #attrs Self::#linter(#linter::#prefix_ident) @@ -162,10 +161,9 @@ pub(crate) fn map_codes(func: &ItemFn) -> syn::Result { }); let prefix_ident = get_prefix_ident(&prefix); let attrs = intersection_all(rules.iter().map(|(.., attrs)| attrs.as_slice())); - let attrs = if attrs.is_empty() { - quote!() - } else { - quote!(#(#attrs)*) + let attrs = match attrs.as_slice() { + [] => quote!(), + [..] => quote!(#(#attrs)*), }; prefix_into_iter_match_arms.extend(quote! { #attrs #linter::#prefix_ident => vec![#(#rule_paths,)*].into_iter(), diff --git a/crates/ruff_macros/src/rule_code_prefix.rs b/crates/ruff_macros/src/rule_code_prefix.rs index 489718cd681e2..04d9f9b1fa42e 100644 --- a/crates/ruff_macros/src/rule_code_prefix.rs +++ b/crates/ruff_macros/src/rule_code_prefix.rs @@ -90,10 +90,9 @@ fn attributes_for_prefix( attributes: &BTreeMap, ) -> proc_macro2::TokenStream { let attrs = intersection_all(codes.iter().map(|code| attributes[code])); - if attrs.is_empty() { - quote!() - } else { - quote!(#(#attrs)*) + match attrs.as_slice() { + [] => quote!(), + [..] => quote!(#(#attrs)*), } } diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs index ba06c45057fbc..515f6b60ca12a 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs @@ -18,10 +18,9 @@ impl FormatNodeRule for FormatPatternMatchStar { write!(f, [token("*"), dangling_comments(dangling)])?; - if let Some(name) = name { - write!(f, [name.format()]) - } else { - write!(f, [token("_")]) + match name { + Some(name) => write!(f, [name.format()]), + None => write!(f, [token("_")]), } } } diff --git a/crates/ruff_server/src/server.rs b/crates/ruff_server/src/server.rs index 67d049ccae02f..2674e76a04b04 100644 --- a/crates/ruff_server/src/server.rs +++ b/crates/ruff_server/src/server.rs @@ -6,7 +6,6 @@ use lsp_types::InitializeParams; use lsp_types::WorkspaceFolder; use std::num::NonZeroUsize; use std::ops::Deref; -#[allow(deprecated)] use std::panic::PanicInfo; use std::str::FromStr; use thiserror::Error; @@ -126,7 +125,6 @@ impl Server { } pub fn run(self) -> crate::Result<()> { - #[allow(deprecated)] type PanicHook = Box) + 'static + Sync + Send>; struct RestorePanicHook { hook: Option, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 76fcadb5b3218..4cef0b738ff63 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.82" +channel = "1.81"