From c39ca8fe6d3fb77684d2919a58b77cca95671ab7 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Sat, 11 Jan 2025 09:51:58 +0100 Subject: [PATCH] Upgrade Rust toolchain to 1.84.0 (#15408) --- Cargo.toml | 3 ++ crates/red_knot_server/src/session/index.rs | 2 +- crates/red_knot_workspace/src/workspace.rs | 2 +- crates/ruff/src/args.rs | 2 +- crates/ruff_db/src/system.rs | 4 +-- crates/ruff_formatter/src/printer/mod.rs | 7 +--- crates/ruff_linter/src/docstrings/sections.rs | 2 +- crates/ruff_linter/src/fix/mod.rs | 2 +- crates/ruff_linter/src/noqa.rs | 6 +--- .../src/rules/pyupgrade/rules/f_strings.rs | 2 +- .../rules/super_call_with_parameters.rs | 2 +- .../pyupgrade/rules/use_pep646_unpack.rs | 4 +-- .../rules/refurb/rules/print_empty_string.rs | 2 +- crates/ruff_python_ast/src/nodes.rs | 2 +- .../src/comments/format.rs | 2 +- crates/ruff_python_semantic/src/model.rs | 33 +++++++++---------- crates/ruff_server/src/session/index.rs | 2 +- rust-toolchain.toml | 2 +- 18 files changed, 36 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 60c66c7b6e..0ac875e0fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -211,6 +211,9 @@ redundant_clone = "warn" debug_assert_with_mut_call = "warn" unused_peekable = "warn" +# Diagnostics are not actionable: Enable once https://github.com/rust-lang/rust-clippy/issues/13774 is resolved. +large_stack_arrays = "allow" + [profile.release] # Note that we set these explicitly, and these values # were chosen based on a trade-off between compile times diff --git a/crates/red_knot_server/src/session/index.rs b/crates/red_knot_server/src/session/index.rs index 62f00e1de7..8b455ac392 100644 --- a/crates/red_knot_server/src/session/index.rs +++ b/crates/red_knot_server/src/session/index.rs @@ -74,7 +74,7 @@ impl Index { DocumentKey::NotebookCell(url) } else if Path::new(url.path()) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("ipynb")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("ipynb")) { DocumentKey::Notebook(url) } else { diff --git a/crates/red_knot_workspace/src/workspace.rs b/crates/red_knot_workspace/src/workspace.rs index 6b7134ecfc..671a2a85ef 100644 --- a/crates/red_knot_workspace/src/workspace.rs +++ b/crates/red_knot_workspace/src/workspace.rs @@ -285,7 +285,7 @@ impl Workspace { open_files.contains(&file) } else if let Some(system_path) = file.path(db).as_system_path() { self.package(db, system_path) - .map_or(false, |package| package.contains_file(db, file)) + .is_some_and(|package| package.contains_file(db, file)) } else { file.path(db).is_system_virtual_path() } diff --git a/crates/ruff/src/args.rs b/crates/ruff/src/args.rs index b88f3c6746..3b274c2365 100644 --- a/crates/ruff/src/args.rs +++ b/crates/ruff/src/args.rs @@ -959,7 +959,7 @@ A `--config` flag must either be a path to a `.toml` configuration file // We want to display the most helpful error to the user as possible. if Path::new(value) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("toml")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("toml")) { if !value.contains('=') { tip.push_str(&format!( diff --git a/crates/ruff_db/src/system.rs b/crates/ruff_db/src/system.rs index 1d0bcf5e0b..4a7edc8d0b 100644 --- a/crates/ruff_db/src/system.rs +++ b/crates/ruff_db/src/system.rs @@ -87,13 +87,13 @@ pub trait System: Debug { /// Returns `true` if `path` exists and is a directory. fn is_directory(&self, path: &SystemPath) -> bool { self.path_metadata(path) - .map_or(false, |metadata| metadata.file_type.is_directory()) + .is_ok_and(|metadata| metadata.file_type.is_directory()) } /// Returns `true` if `path` exists and is a file. fn is_file(&self, path: &SystemPath) -> bool { self.path_metadata(path) - .map_or(false, |metadata| metadata.file_type.is_file()) + .is_ok_and(|metadata| metadata.file_type.is_file()) } /// Returns the current working directory diff --git a/crates/ruff_formatter/src/printer/mod.rs b/crates/ruff_formatter/src/printer/mod.rs index 4fcd711322..3881e14d70 100644 --- a/crates/ruff_formatter/src/printer/mod.rs +++ b/crates/ruff_formatter/src/printer/mod.rs @@ -497,12 +497,7 @@ impl<'a> Printer<'a> { dest: self.state.buffer.text_len(), }; - if self - .state - .source_markers - .last() - .map_or(true, |last| last != &marker) - { + if self.state.source_markers.last() != Some(&marker) { self.state.source_markers.push(marker); } } diff --git a/crates/ruff_linter/src/docstrings/sections.rs b/crates/ruff_linter/src/docstrings/sections.rs index f46802e12b..bed29daedb 100644 --- a/crates/ruff_linter/src/docstrings/sections.rs +++ b/crates/ruff_linter/src/docstrings/sections.rs @@ -540,7 +540,7 @@ fn is_docstring_section( // The return value of the function. // """ // ``` - if previous_line.map_or(false, |line| line.trim().is_empty()) { + if previous_line.is_some_and(|line| line.trim().is_empty()) { return true; } diff --git a/crates/ruff_linter/src/fix/mod.rs b/crates/ruff_linter/src/fix/mod.rs index 51f9775c6c..50051693a3 100644 --- a/crates/ruff_linter/src/fix/mod.rs +++ b/crates/ruff_linter/src/fix/mod.rs @@ -38,7 +38,7 @@ pub(crate) fn fix_file( diagnostic .fix .as_ref() - .map_or(false, |fix| fix.applies(required_applicability)) + .is_some_and(|fix| fix.applies(required_applicability)) }) .peekable(); diff --git a/crates/ruff_linter/src/noqa.rs b/crates/ruff_linter/src/noqa.rs index 258b4931ca..ac8d2cf552 100644 --- a/crates/ruff_linter/src/noqa.rs +++ b/crates/ruff_linter/src/noqa.rs @@ -78,11 +78,7 @@ impl<'a> Directive<'a> { comment_start = text[..comment_start].trim_end().len(); // The next character has to be the `#` character. - if text[..comment_start] - .chars() - .last() - .map_or(true, |c| c != '#') - { + if !text[..comment_start].ends_with('#') { continue; } comment_start -= '#'.len_utf8(); diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs index 213126c32b..81500d4be9 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs @@ -493,7 +493,7 @@ pub(crate) fn f_strings(checker: &mut Checker, call: &ast::ExprCall, summary: &F checker .semantic() .resolve_qualified_name(call.func.as_ref()) - .map_or(false, |qualified_name| { + .is_some_and(|qualified_name| { matches!( qualified_name.segments(), ["django", "utils", "translation", "gettext" | "gettext_lazy"] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs index 132dddb2ce..83680f35a8 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs @@ -145,7 +145,7 @@ pub(crate) fn super_call_with_parameters(checker: &mut Checker, call: &ast::Expr .resolve_qualified_name(func) .is_some_and(|name| name.segments() == ["dataclasses", "dataclass"]) { - arguments.find_keyword("slots").map_or(false, |keyword| { + arguments.find_keyword("slots").is_some_and(|keyword| { matches!( keyword.value, Expr::BooleanLiteral(ast::ExprBooleanLiteral { value: true, .. }) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs index b31e59a537..f22e5a4f55 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep646_unpack.rs @@ -117,7 +117,7 @@ fn in_subscript_index(expr: &ExprSubscript, semantic: &SemanticModel) -> bool { } // E.g., `Generic[DType, Unpack[int]]`. - if parent.slice.as_tuple_expr().map_or(false, |slice| { + if parent.slice.as_tuple_expr().is_some_and(|slice| { slice .elts .iter() @@ -144,5 +144,5 @@ fn in_vararg(expr: &ExprSubscript, semantic: &SemanticModel) -> bool { .as_ref() .and_then(|vararg| vararg.annotation.as_ref()) .and_then(|annotation| annotation.as_subscript_expr()) - .map_or(false, |annotation| annotation == expr) + == Some(expr) } diff --git a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs index f5a6c7de4a..3ca8a0644b 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs @@ -144,7 +144,7 @@ pub(crate) fn print_empty_string(checker: &mut Checker, call: &ast::ExprCall) { let empty_separator = call .arguments .find_keyword("sep") - .map_or(false, |keyword| is_empty_string(&keyword.value)); + .is_some_and(|keyword| is_empty_string(&keyword.value)); if !empty_separator { return; } diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index e844eb0534..58457c6b42 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -1732,7 +1732,7 @@ impl StringLiteralValue { pub fn is_unicode(&self) -> bool { self.iter() .next() - .map_or(false, |part| part.flags.prefix().is_unicode()) + .is_some_and(|part| part.flags.prefix().is_unicode()) } /// Returns a slice of all the [`StringLiteral`] parts contained in this value. diff --git a/crates/ruff_python_formatter/src/comments/format.rs b/crates/ruff_python_formatter/src/comments/format.rs index 8da3d1daea..1aef8d61ab 100644 --- a/crates/ruff_python_formatter/src/comments/format.rs +++ b/crates/ruff_python_formatter/src/comments/format.rs @@ -85,7 +85,7 @@ pub(crate) struct FormatLeadingAlternateBranchComments<'a> { impl Format> for FormatLeadingAlternateBranchComments<'_> { fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> { - if self.last_node.map_or(false, |preceding| { + if self.last_node.is_some_and(|preceding| { should_insert_blank_line_after_class_in_stub_file(preceding, None, f.context()) }) { write!(f, [empty_line(), leading_comments(self.comments)])?; diff --git a/crates/ruff_python_semantic/src/model.rs b/crates/ruff_python_semantic/src/model.rs index b8c13a22ca..c7ac8f8f46 100644 --- a/crates/ruff_python_semantic/src/model.rs +++ b/crates/ruff_python_semantic/src/model.rs @@ -1002,24 +1002,21 @@ impl<'a> SemanticModel<'a> { let value_name = UnqualifiedName::from_expr(value)?; let (_, tail) = value_name.segments().split_first()?; - let resolved: QualifiedName = if qualified_name - .segments() - .first() - .map_or(false, |segment| *segment == ".") - { - from_relative_import( - self.module.qualified_name()?, - qualified_name.segments(), - tail, - )? - } else { - qualified_name - .segments() - .iter() - .chain(tail) - .copied() - .collect() - }; + let resolved: QualifiedName = + if qualified_name.segments().first().copied() == Some(".") { + from_relative_import( + self.module.qualified_name()?, + qualified_name.segments(), + tail, + )? + } else { + qualified_name + .segments() + .iter() + .chain(tail) + .copied() + .collect() + }; Some(resolved) } BindingKind::Builtin => { diff --git a/crates/ruff_server/src/session/index.rs b/crates/ruff_server/src/session/index.rs index 25129e73fe..feed9814ed 100644 --- a/crates/ruff_server/src/session/index.rs +++ b/crates/ruff_server/src/session/index.rs @@ -125,7 +125,7 @@ impl Index { DocumentKey::NotebookCell(url) } else if Path::new(url.path()) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("ipynb")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("ipynb")) { DocumentKey::Notebook(url) } else { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index a718dc2fc8..9db33c0e40 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.83" +channel = "1.84"