From dd6f6233bd469ddc9296c1ebd7cdb845233c93b1 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Wed, 26 Feb 2025 06:12:43 -0800 Subject: [PATCH] bump MSRV to 1.83 (#16294) According to our new MSRV policy (see https://github.com/astral-sh/ruff/issues/16370 ), bump our MSRV to 1.83 (N - 2), and autofix some new clippy lints. --- Cargo.toml | 2 +- crates/red_knot_project/src/metadata.rs | 4 +-- crates/red_knot_test/src/matcher.rs | 8 +++--- crates/ruff_formatter/src/lib.rs | 4 +-- .../checkers/ast/analyze/deferred_scopes.rs | 8 +++--- crates/ruff_linter/src/docstrings/sections.rs | 2 +- .../src/rules/flake8_bandit/helpers.rs | 2 +- .../rules/hardcoded_sql_expression.rs | 4 +-- .../rules/hashlib_insecure_hash_functions.rs | 2 +- .../rules/tarfile_unsafe_members.rs | 4 +-- .../rules/implicit_namespace_package.rs | 8 +++--- .../rules/flake8_print/rules/print_call.rs | 3 +-- .../flake8_pyi/rules/exit_annotations.rs | 2 +- .../rules/flake8_pytest_style/rules/fail.rs | 2 +- .../rules/flake8_pytest_style/rules/raises.rs | 2 +- .../rules/flake8_pytest_style/rules/warns.rs | 2 +- .../src/rules/flake8_return/rules/function.rs | 2 +- .../rules/flake8_simplify/rules/ast_with.rs | 2 +- .../flake8_simplify/rules/collapsible_if.rs | 2 +- .../ruff_linter/src/rules/isort/normalize.rs | 7 +++-- .../src/rules/pep8_naming/settings.rs | 2 +- .../rules/perflint/rules/manual_list_copy.rs | 2 +- .../missing_whitespace_around_operator.rs | 6 ++--- .../rules/pydoclint/rules/check_docstring.rs | 4 +-- .../rules/pydocstyle/rules/no_signature.rs | 2 +- .../src/rules/pydocstyle/rules/sections.rs | 2 +- .../pylint/rules/potential_index_error.rs | 2 +- .../rules/type_name_incorrect_variance.rs | 4 +-- .../rules/unnecessary_list_index_lookup.rs | 2 +- .../src/rules/pylint/rules/useless_return.rs | 4 +-- .../rules/refurb/rules/int_on_sliced_str.rs | 4 +-- .../rules/refurb/rules/list_reverse_copy.rs | 6 ++--- .../refurb/rules/unnecessary_enumerate.rs | 2 +- .../ruff/rules/missing_fstring_syntax.rs | 2 +- .../src/rules/ruff/rules/sequence_sorting.rs | 4 +-- .../ruff/rules/suppression_comment_visitor.rs | 2 +- crates/ruff_linter/src/rules/ruff/typing.rs | 27 ++++++++----------- crates/ruff_notebook/src/cell.rs | 2 +- crates/ruff_python_ast/src/nodes.rs | 2 +- crates/ruff_python_ast/src/script.rs | 2 +- .../src/comments/visitor.rs | 2 +- .../src/expression/expr_slice.rs | 6 ++--- .../src/other/parameter_with_default.rs | 3 +-- crates/ruff_python_parser/src/lexer.rs | 2 +- .../src/implicit_imports.rs | 2 +- crates/ruff_python_semantic/src/model.rs | 6 ++--- crates/ruff_workspace/src/resolver.rs | 2 +- 47 files changed, 85 insertions(+), 93 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c3257b7126406..81fa8fdf7c56f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ resolver = "2" [workspace.package] edition = "2021" -rust-version = "1.80" +rust-version = "1.83" homepage = "https://docs.astral.sh/ruff" documentation = "https://docs.astral.sh/ruff" repository = "https://github.com/astral-sh/ruff" diff --git a/crates/red_knot_project/src/metadata.rs b/crates/red_knot_project/src/metadata.rs index 363c5fba471aa..d6e174059e0d8 100644 --- a/crates/red_knot_project/src/metadata.rs +++ b/crates/red_knot_project/src/metadata.rs @@ -77,10 +77,10 @@ impl ProjectMetadata { // If the `options` don't specify a python version but the `project.requires-python` field is set, // use that as a lower bound instead. if let Some(project) = project { - if !options + if options .environment .as_ref() - .is_some_and(|env| env.python_version.is_some()) + .is_none_or(|env| env.python_version.is_none()) { if let Some(requires_python) = project.resolve_requires_python_lower_bound()? { let mut environment = options.environment.unwrap_or_default(); diff --git a/crates/red_knot_test/src/matcher.rs b/crates/red_knot_test/src/matcher.rs index d350ec7c61c3e..21598d608bf79 100644 --- a/crates/red_knot_test/src/matcher.rs +++ b/crates/red_knot_test/src/matcher.rs @@ -283,12 +283,12 @@ impl Matcher { let position = unmatched.iter().position(|diagnostic| { !error.rule.is_some_and(|rule| { !(diagnostic.id().is_lint_named(rule) || diagnostic.id().matches(rule)) - }) && !error + }) && error .column - .is_some_and(|col| col != self.column(*diagnostic)) - && !error + .is_none_or(|col| col == self.column(*diagnostic)) + && error .message_contains - .is_some_and(|needle| !diagnostic.message().contains(needle)) + .is_none_or(|needle| diagnostic.message().contains(needle)) }); if let Some(position) = position { unmatched.swap_remove(position); diff --git a/crates/ruff_formatter/src/lib.rs b/crates/ruff_formatter/src/lib.rs index 0a81cb121902e..337200cc0aaa8 100644 --- a/crates/ruff_formatter/src/lib.rs +++ b/crates/ruff_formatter/src/lib.rs @@ -470,13 +470,13 @@ impl Printed { for marker in self.sourcemap { // Take the closest start marker, but skip over start_markers that have the same start. if marker.source <= source_range.start() - && !start_marker.is_some_and(|existing| existing.source >= marker.source) + && start_marker.is_none_or(|existing| existing.source < marker.source) { start_marker = Some(marker); } if marker.source >= source_range.end() - && !end_marker.is_some_and(|existing| existing.source <= marker.source) + && end_marker.is_none_or(|existing| existing.source > marker.source) { end_marker = Some(marker); } diff --git a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs index 2f2bb7bf13308..d5801e9dba53c 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs @@ -177,10 +177,10 @@ pub(crate) fn deferred_scopes(checker: &Checker) { } // If the bindings are in different forks, abort. - if shadowed.source.map_or(true, |left| { + if shadowed.source.is_none_or(|left| { binding .source - .map_or(true, |right| !checker.semantic.same_branch(left, right)) + .is_none_or(|right| !checker.semantic.same_branch(left, right)) }) { continue; } @@ -269,10 +269,10 @@ pub(crate) fn deferred_scopes(checker: &Checker) { } // If the bindings are in different forks, abort. - if shadowed.source.map_or(true, |left| { + if shadowed.source.is_none_or(|left| { binding .source - .map_or(true, |right| !checker.semantic.same_branch(left, right)) + .is_none_or(|right| !checker.semantic.same_branch(left, right)) }) { continue; } diff --git a/crates/ruff_linter/src/docstrings/sections.rs b/crates/ruff_linter/src/docstrings/sections.rs index edfc8bb7dbe5e..aa42af30ef50f 100644 --- a/crates/ruff_linter/src/docstrings/sections.rs +++ b/crates/ruff_linter/src/docstrings/sections.rs @@ -453,7 +453,7 @@ fn is_docstring_section( } // Determine whether the previous line looks like the end of a paragraph. - let previous_line_looks_like_end_of_paragraph = previous_line.map_or(true, |previous_line| { + let previous_line_looks_like_end_of_paragraph = previous_line.is_none_or(|previous_line| { let previous_line = previous_line.trim(); let previous_line_ends_with_punctuation = [',', ';', '.', '-', '\\', '/', ']', '}', ')'] .into_iter() diff --git a/crates/ruff_linter/src/rules/flake8_bandit/helpers.rs b/crates/ruff_linter/src/rules/flake8_bandit/helpers.rs index a79d707f8aa13..917c80f2f4925 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/helpers.rs @@ -20,7 +20,7 @@ pub(super) fn matches_password_name(string: &str) -> bool { } pub(super) fn is_untyped_exception(type_: Option<&Expr>, semantic: &SemanticModel) -> bool { - type_.map_or(true, |type_| { + type_.is_none_or(|type_| { if let Expr::Tuple(ast::ExprTuple { elts, .. }) = &type_ { elts.iter().any(|type_| { semantic diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs index 0515d62d31afb..f29cd41d30c02 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs @@ -62,10 +62,10 @@ pub(crate) fn hardcoded_sql_expression(checker: &Checker, expr: &Expr) { op: Operator::Add, .. }) => { // Only evaluate the full BinOp, not the nested components. - if !checker + if checker .semantic() .current_expression_parent() - .map_or(true, |parent| !parent.is_bin_op_expr()) + .is_some_and(ruff_python_ast::Expr::is_bin_op_expr) { return; } diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs index d2ad1dba8574d..3f97de5050e00 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs @@ -199,7 +199,7 @@ fn detect_insecure_crypt_calls(checker: &Checker, call: &ast::ExprCall) { fn is_used_for_security(arguments: &Arguments) -> bool { arguments .find_keyword("usedforsecurity") - .map_or(true, |keyword| !is_const_false(&keyword.value)) + .is_none_or(|keyword| !is_const_false(&keyword.value)) } #[derive(Debug, Copy, Clone)] diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs index 5d91dabe97024..e27409678ec39 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/tarfile_unsafe_members.rs @@ -53,10 +53,10 @@ pub(crate) fn tarfile_unsafe_members(checker: &Checker, call: &ast::ExprCall) { return; } - if !call + if call .func .as_attribute_expr() - .is_some_and(|attr| attr.attr.as_str() == "extractall") + .is_none_or(|attr| attr.attr.as_str() != "extractall") { return; } diff --git a/crates/ruff_linter/src/rules/flake8_no_pep420/rules/implicit_namespace_package.rs b/crates/ruff_linter/src/rules/flake8_no_pep420/rules/implicit_namespace_package.rs index c0b916bbdc8fc..4e91d2058263a 100644 --- a/crates/ruff_linter/src/rules/flake8_no_pep420/rules/implicit_namespace_package.rs +++ b/crates/ruff_linter/src/rules/flake8_no_pep420/rules/implicit_namespace_package.rs @@ -66,17 +66,17 @@ pub(crate) fn implicit_namespace_package( // Ignore non-`.py` files, which don't require an `__init__.py`. && PySourceType::try_from_path(path).is_some_and(PySourceType::is_py_file) // Ignore any files that are direct children of the project root. - && !path + && path .parent() - .is_some_and( |parent| parent == project_root) + .is_none_or( |parent| parent != project_root) // Ignore any files that are direct children of a source directory (e.g., `src/manage.py`). && !path .parent() .is_some_and( |parent| src.iter().any(|src| src == parent)) // Ignore files that contain a shebang. - && !comment_ranges + && comment_ranges .first().filter(|range| range.start() == TextSize::from(0)) - .is_some_and(|range| ShebangDirective::try_extract(locator.slice(*range)).is_some()) + .is_none_or(|range| ShebangDirective::try_extract(locator.slice(*range)).is_none()) // Ignore PEP 723 scripts. && ScriptTag::parse(locator.contents().as_bytes()).is_none() { diff --git a/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs b/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs index 59ce9542cd728..ec895762912ed 100644 --- a/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs +++ b/crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs @@ -109,8 +109,7 @@ pub(crate) fn print_call(checker: &Checker, call: &ast::ExprCall) { // or `"sys.stderr"`), don't trigger T201. if let Some(keyword) = call.arguments.find_keyword("file") { if !keyword.value.is_none_literal_expr() { - if semantic.resolve_qualified_name(&keyword.value).map_or( - true, + if semantic.resolve_qualified_name(&keyword.value).is_none_or( |qualified_name| { !matches!(qualified_name.segments(), ["sys", "stdout" | "stderr"]) }, diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs index 1202d5cbe2ac0..881da80687e22 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs @@ -294,7 +294,7 @@ fn check_positional_args_for_overloaded_method( predicate: impl FnOnce(&Expr) -> bool, semantic: &SemanticModel, ) -> bool { - parameter.annotation().map_or(true, |annotation| { + parameter.annotation().is_none_or(|annotation| { predicate(annotation) || is_object_or_unused(annotation, semantic) }) } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs index 1702f25b1ea55..998ad78014ed0 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fail.rs @@ -63,7 +63,7 @@ pub(crate) fn fail_call(checker: &Checker, call: &ast::ExprCall) { .arguments .find_argument_value("reason", 0) .or_else(|| call.arguments.find_argument_value("msg", 0)) - .map_or(true, is_empty_or_null_string) + .is_none_or(is_empty_or_null_string) { checker.report_diagnostic(Diagnostic::new(PytestFailWithoutMessage, call.func.range())); } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs index ebaf2e722afbb..4701b9e2fb705 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs @@ -188,7 +188,7 @@ pub(crate) fn raises_call(checker: &Checker, call: &ast::ExprCall) { if call .arguments .find_keyword("match") - .map_or(true, |k| is_empty_or_null_string(&k.value)) + .is_none_or(|k| is_empty_or_null_string(&k.value)) { exception_needs_match(checker, exception); } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/warns.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/warns.rs index df92a3e653af8..3b741f3af6f21 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/warns.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/warns.rs @@ -187,7 +187,7 @@ pub(crate) fn warns_call(checker: &Checker, call: &ast::ExprCall) { if call .arguments .find_keyword("match") - .map_or(true, |k| is_empty_or_null_string(&k.value)) + .is_none_or(|k| is_empty_or_null_string(&k.value)) { warning_needs_match(checker, warning); } diff --git a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs index 2cd869848c560..a28597949e85e 100644 --- a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs +++ b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs @@ -817,7 +817,7 @@ pub(crate) fn function(checker: &Checker, function_def: &ast::StmtFunctionDef) { } else { if checker.enabled(Rule::UnnecessaryReturnNone) { // Skip functions that have a return annotation that is not `None`. - if returns.as_deref().map_or(true, Expr::is_none_literal_expr) { + if returns.as_deref().is_none_or(Expr::is_none_literal_expr) { unnecessary_return_none(checker, decorator_list, &stack); } } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs index fff6dace5be09..b86626984eab7 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs @@ -177,7 +177,7 @@ pub(crate) fn multiple_with_statements( with_stmt, ) { Ok(edit) => { - if edit.content().map_or(true, |content| { + if edit.content().is_none_or(|content| { fits( content, with_stmt.into(), diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs index 76aa2fe5e65c2..43f8facc3c549 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs @@ -120,7 +120,7 @@ pub(crate) fn nested_if_statements( diagnostic.try_set_optional_fix(|| { match collapse_nested_if(checker.locator(), checker.stylist(), nested_if) { Ok(edit) => { - if edit.content().map_or(true, |content| { + if edit.content().is_none_or(|content| { fits( content, (&nested_if).into(), diff --git a/crates/ruff_linter/src/rules/isort/normalize.rs b/crates/ruff_linter/src/rules/isort/normalize.rs index f7f7bcabce9fb..9feb16456634e 100644 --- a/crates/ruff_linter/src/rules/isort/normalize.rs +++ b/crates/ruff_linter/src/rules/isort/normalize.rs @@ -53,10 +53,9 @@ pub(crate) fn normalize_imports<'a>( } => { // Whether to track each member of the import as a separate entry. let isolate_aliases = settings.force_single_line - && module.map_or(true, |module| { - !settings.single_line_exclusions.contains(module) - }) - && !names.first().is_some_and(|alias| alias.name == "*"); + && module + .is_none_or(|module| !settings.single_line_exclusions.contains(module)) + && names.first().is_none_or(|alias| alias.name != "*"); // Insert comments on the statement itself. if isolate_aliases { diff --git a/crates/ruff_linter/src/rules/pep8_naming/settings.rs b/crates/ruff_linter/src/rules/pep8_naming/settings.rs index 9705b7cde05d5..accac6ef6cd5c 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/settings.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/settings.rs @@ -102,7 +102,7 @@ impl IgnoreNames { ) -> Result { // If the user is not customizing the set of ignored names, use the default matcher, // which is hard-coded to avoid expensive regex matching. - if ignore_names.is_none() && extend_ignore_names.as_ref().map_or(true, Vec::is_empty) { + if ignore_names.is_none() && extend_ignore_names.as_ref().is_none_or(Vec::is_empty) { return Ok(IgnoreNames::Default); } diff --git a/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs b/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs index 798647080881c..24ee2ae9c188b 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/manual_list_copy.rs @@ -93,7 +93,7 @@ pub(crate) fn manual_list_copy(checker: &Checker, for_stmt: &ast::StmtFor) { } // Only flag direct list copies (e.g., `for x in y: filtered.append(x)`). - if !arg.as_name_expr().is_some_and(|arg| arg.id == *id) { + if arg.as_name_expr().is_none_or(|arg| arg.id != *id) { return; } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs index 064d7fabd581e..a3e16837e2d7d 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace_around_operator.rs @@ -245,9 +245,9 @@ pub(crate) fn missing_whitespace_around_operator( let has_leading_trivia = prev_token.end() < token.start() || is_non_logical_token(prev_token.kind()); - let has_trailing_trivia = tokens.peek().map_or(true, |next| { - token.end() < next.start() || is_non_logical_token(next.kind()) - }); + let has_trailing_trivia = tokens + .peek() + .is_none_or(|next| token.end() < next.start() || is_non_logical_token(next.kind())); match (has_leading_trivia, has_trailing_trivia) { // Operator with trailing but no leading space, enforce consistent spacing. diff --git a/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs b/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs index 95fb57feedf2b..826d71761501d 100644 --- a/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs +++ b/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs @@ -794,7 +794,7 @@ impl<'a> GeneratorOrIteratorArguments<'a> { match self { Self::Unparameterized => true, Self::Single(_) => true, - Self::Several(elements) => elements.get(2).map_or(true, Expr::is_none_literal_expr), + Self::Several(elements) => elements.get(2).is_none_or(Expr::is_none_literal_expr), } } } @@ -947,7 +947,7 @@ pub(crate) fn check_docstring( match function_def.returns.as_deref() { Some(returns) if !generator_annotation_arguments(returns, semantic).is_some_and( - |arguments| arguments.first().map_or(true, Expr::is_none_literal_expr), + |arguments| arguments.first().is_none_or(Expr::is_none_literal_expr), ) => { diagnostics diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs index d63f698f2ffef..2addede6a4388 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/no_signature.rs @@ -71,7 +71,7 @@ pub(crate) fn no_signature(checker: &Checker, docstring: &Docstring) { let preceded_by_word_boundary = first_line[..index] .chars() .next_back() - .map_or(true, |c| matches!(c, ' ' | '\t' | ';' | ',')); + .is_none_or(|c| matches!(c, ' ' | '\t' | ';' | ',')); if !preceded_by_word_boundary { return false; } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs index 913269f743e03..2535ac71acb69 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs @@ -1871,7 +1871,7 @@ fn args_section(context: &SectionContext) -> FxHashSet { // Reformat each section. let mut args_sections: Vec = vec![]; for line in args_content.trim().lines() { - if line.chars().next().map_or(true, char::is_whitespace) { + if line.chars().next().is_none_or(char::is_whitespace) { // This is a continuation of the documentation for the previous parameter, // because it starts with whitespace. if let Some(last) = args_sections.last_mut() { diff --git a/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs b/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs index 95cb2705bc0f3..5d1081836345b 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/potential_index_error.rs @@ -65,7 +65,7 @@ pub(crate) fn potential_index_error(checker: &Checker, value: &Expr, slice: &Exp // Emit a diagnostic if the index is out of bounds. If the index can't be represented as an // `i64`, but the length _can_, then the index is definitely out of bounds. - if index.map_or(true, |index| index >= length || index < -length) { + if index.is_none_or(|index| index >= length || index < -length) { checker.report_diagnostic(Diagnostic::new(PotentialIndexError, slice.range())); } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs b/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs index b6981f259f7ee..d4b0b7ab16335 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/type_name_incorrect_variance.rs @@ -140,9 +140,9 @@ pub(crate) fn type_name_incorrect_variance(checker: &Checker, value: &Expr) { /// Returns `true` if the parameter name does not match its type variance. fn mismatch(param_name: &str, covariant: Option<&Expr>, contravariant: Option<&Expr>) -> bool { if param_name.ends_with("_co") { - covariant.map_or(true, |covariant| !is_const_true(covariant)) + covariant.is_none_or(|covariant| !is_const_true(covariant)) } else if param_name.ends_with("_contra") { - contravariant.map_or(true, |contravariant| !is_const_true(contravariant)) + contravariant.is_none_or(|contravariant| !is_const_true(contravariant)) } else { covariant.is_some_and(is_const_true) || contravariant.is_some_and(is_const_true) } diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs index e4c2b594d948a..c0874d0d3deb7 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs @@ -154,7 +154,7 @@ fn enumerate_items<'a>( // If the `enumerate` call has a non-zero `start`, don't omit. if !arguments .find_argument_value("start", 1) - .map_or(true, |expr| { + .is_none_or(|expr| { matches!( expr, Expr::NumberLiteral(ast::ExprNumberLiteral { diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs index b06064d842600..513f391f53382 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs @@ -50,7 +50,7 @@ pub(crate) fn useless_return( returns: Option<&Expr>, ) { // Skip functions that have a return annotation that is not `None`. - if !returns.map_or(true, Expr::is_none_literal_expr) { + if !returns.is_none_or(Expr::is_none_literal_expr) { return; } @@ -82,7 +82,7 @@ pub(crate) fn useless_return( // Verify that the return statement is either bare or returns `None`. if !value .as_ref() - .map_or(true, |expr| expr.is_none_literal_expr()) + .is_none_or(|expr| expr.is_none_literal_expr()) { return; }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs b/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs index 252cf0ec46e49..b2da47d6be6cd 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/int_on_sliced_str.rs @@ -106,12 +106,12 @@ pub(crate) fn int_on_sliced_str(checker: &Checker, call: &ExprCall) { if expr_slice.upper.is_some() || expr_slice.step.is_some() { return; } - if !expr_slice + if expr_slice .lower .as_ref() .and_then(|expr| expr.as_number_literal_expr()) .and_then(|expr| expr.value.as_int()) - .is_some_and(|expr| expr.as_u8() == Some(2)) + .is_none_or(|expr| expr.as_u8() != Some(2)) { return; } diff --git a/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs b/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs index 24ba55f860b34..c3995008c728c 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/list_reverse_copy.rs @@ -119,7 +119,7 @@ fn peel_lists(expr: &Expr) -> &Expr { return expr; } - if !func.as_name_expr().is_some_and(|name| name.id == "list") { + if func.as_name_expr().is_none_or(|name| name.id != "list") { return expr; } @@ -175,11 +175,11 @@ fn extract_name_from_sliced_reversed(expr: &Expr) -> Option<&ExprName> { else { return None; }; - if !operand + if operand .as_number_literal_expr() .and_then(|num| num.value.as_int()) .and_then(Int::as_u8) - .is_some_and(|value| value == 1) + .is_none_or(|value| value != 1) { return None; }; diff --git a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs index ae2e7c5241f59..4dceca05bcf47 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs @@ -179,7 +179,7 @@ pub(crate) fn unnecessary_enumerate(checker: &Checker, stmt_for: &ast::StmtFor) // If the `start` argument is set to something other than the `range` default, // there's no clear fix. let start = arguments.find_argument_value("start", 1); - if start.map_or(true, |start| { + if start.is_none_or(|start| { matches!( start, Expr::NumberLiteral(ast::ExprNumberLiteral { diff --git a/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs b/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs index 994e6a3ff2e54..c44bd2cb8a214 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/missing_fstring_syntax.rs @@ -224,7 +224,7 @@ fn should_be_fstring( semantic.scope_id, TypingOnlyBindingsStatus::Disallowed, ) - .map_or(true, |id| semantic.binding(id).kind.is_builtin()) + .is_none_or(|id| semantic.binding(id).kind.is_builtin()) { return false; } diff --git a/crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs b/crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs index 6926170ee9bbf..35715e75aa495 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs @@ -513,7 +513,7 @@ impl<'a> MultilineStringSequenceValue<'a> { // we'll end up with two commas after the final item, which would be invalid syntax) let needs_trailing_comma = self.ends_with_trailing_comma && first_non_trivia_token(TextSize::new(0), &postlude) - .map_or(true, |tok| tok.kind() != SimpleTokenKind::Comma); + .is_none_or(|tok| tok.kind() != SimpleTokenKind::Comma); self.items .sort_by(|a, b| sorting_style.compare(a.value, b.value)); @@ -979,7 +979,7 @@ fn multiline_string_sequence_postlude<'a>( if postlude.len() <= 2 { let mut reversed_postlude_chars = postlude.chars().rev(); if let Some(closing_paren @ (')' | '}' | ']')) = reversed_postlude_chars.next() { - if reversed_postlude_chars.next().map_or(true, |c| c == ',') { + if reversed_postlude_chars.next().is_none_or(|c| c == ',') { return Cow::Owned(format!(",{newline}{leading_indent}{closing_paren}")); } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/suppression_comment_visitor.rs b/crates/ruff_linter/src/rules/ruff/rules/suppression_comment_visitor.rs index b97ed311799c3..24a1423260a9d 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/suppression_comment_visitor.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/suppression_comment_visitor.rs @@ -59,7 +59,7 @@ where fn can_skip(&mut self, node_end: TextSize) -> bool { self.comments .peek() - .map_or(true, |next| next.range.start() >= node_end) + .is_none_or(|next| next.range.start() >= node_end) } } diff --git a/crates/ruff_linter/src/rules/ruff/typing.rs b/crates/ruff_linter/src/rules/ruff/typing.rs index a12ab9b6df482..3c650bfe0bb69 100644 --- a/crates/ruff_linter/src/rules/ruff/typing.rs +++ b/crates/ruff_linter/src/rules/ruff/typing.rs @@ -178,25 +178,20 @@ impl<'a> TypingTarget<'a> { TypingTarget::Union(slice) => slice.is_some_and(|slice| { resolve_slice_value(slice).any(|element| { TypingTarget::try_from_expr(element, checker, version) - .map_or(true, |new_target| { - new_target.contains_none(checker, version) - }) + .is_none_or(|new_target| new_target.contains_none(checker, version)) }) }), TypingTarget::PEP604Union(left, right) => [left, right].iter().any(|element| { - TypingTarget::try_from_expr(element, checker, version).map_or(true, |new_target| { - new_target.contains_none(checker, version) - }) + TypingTarget::try_from_expr(element, checker, version) + .is_none_or(|new_target| new_target.contains_none(checker, version)) }), TypingTarget::Annotated(expr) => expr.is_some_and(|expr| { - TypingTarget::try_from_expr(expr, checker, version).map_or(true, |new_target| { - new_target.contains_none(checker, version) - }) + TypingTarget::try_from_expr(expr, checker, version) + .is_none_or(|new_target| new_target.contains_none(checker, version)) }), TypingTarget::ForwardReference(expr) => { - TypingTarget::try_from_expr(expr, checker, version).map_or(true, |new_target| { - new_target.contains_none(checker, version) - }) + TypingTarget::try_from_expr(expr, checker, version) + .is_none_or(|new_target| new_target.contains_none(checker, version)) } } } @@ -215,22 +210,22 @@ impl<'a> TypingTarget<'a> { TypingTarget::Union(slice) => slice.is_some_and(|slice| { resolve_slice_value(slice).any(|element| { TypingTarget::try_from_expr(element, checker, version) - .map_or(true, |new_target| new_target.contains_any(checker, version)) + .is_none_or(|new_target| new_target.contains_any(checker, version)) }) }), TypingTarget::PEP604Union(left, right) => [left, right].iter().any(|element| { TypingTarget::try_from_expr(element, checker, version) - .map_or(true, |new_target| new_target.contains_any(checker, version)) + .is_none_or(|new_target| new_target.contains_any(checker, version)) }), TypingTarget::Annotated(expr) | TypingTarget::Optional(expr) => { expr.is_some_and(|expr| { TypingTarget::try_from_expr(expr, checker, version) - .map_or(true, |new_target| new_target.contains_any(checker, version)) + .is_none_or(|new_target| new_target.contains_any(checker, version)) }) } TypingTarget::ForwardReference(expr) => { TypingTarget::try_from_expr(expr, checker, version) - .map_or(true, |new_target| new_target.contains_any(checker, version)) + .is_none_or(|new_target| new_target.contains_any(checker, version)) } } } diff --git a/crates/ruff_notebook/src/cell.rs b/crates/ruff_notebook/src/cell.rs index c917dd16274b8..949f55726a1f6 100644 --- a/crates/ruff_notebook/src/cell.rs +++ b/crates/ruff_notebook/src/cell.rs @@ -66,7 +66,7 @@ impl Cell { .metadata .vscode .as_ref() - .map_or(true, |vscode| vscode.language_id == "python") => + .is_none_or(|vscode| vscode.language_id == "python") => { &cell.source } diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 7463fe5068c62..e48349997c99b 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -2800,7 +2800,7 @@ impl Pattern { pub fn is_wildcard(&self) -> bool { match self { Pattern::MatchAs(PatternMatchAs { pattern, .. }) => { - pattern.as_deref().map_or(true, Pattern::is_wildcard) + pattern.as_deref().is_none_or(Pattern::is_wildcard) } Pattern::MatchOr(PatternMatchOr { patterns, .. }) => { patterns.iter().all(Pattern::is_wildcard) diff --git a/crates/ruff_python_ast/src/script.rs b/crates/ruff_python_ast/src/script.rs index f6b592a7b9077..287769d338f5a 100644 --- a/crates/ruff_python_ast/src/script.rs +++ b/crates/ruff_python_ast/src/script.rs @@ -67,7 +67,7 @@ impl ScriptTag { let mut lines = contents.lines(); // Ensure that the first line is exactly `# /// script`. - if !lines.next().is_some_and(|line| line == "# /// script") { + if lines.next().is_none_or(|line| line != "# /// script") { return None; } diff --git a/crates/ruff_python_formatter/src/comments/visitor.rs b/crates/ruff_python_formatter/src/comments/visitor.rs index 52bd5d2009784..0633ffd07015e 100644 --- a/crates/ruff_python_formatter/src/comments/visitor.rs +++ b/crates/ruff_python_formatter/src/comments/visitor.rs @@ -65,7 +65,7 @@ impl<'a, 'builder> CommentsVisitor<'a, 'builder> { fn can_skip(&mut self, node_end: TextSize) -> bool { self.comment_ranges .peek() - .map_or(true, |next_comment| next_comment.start() >= node_end) + .is_none_or(|next_comment| next_comment.start() >= node_end) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_slice.rs b/crates/ruff_python_formatter/src/expression/expr_slice.rs index 29358ab7041d9..6f5f844342b7d 100644 --- a/crates/ruff_python_formatter/src/expression/expr_slice.rs +++ b/crates/ruff_python_formatter/src/expression/expr_slice.rs @@ -60,9 +60,9 @@ impl FormatNodeRule for FormatExprSlice { // Handle spacing around the colon(s) // https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#slices - let lower_simple = lower.as_ref().map_or(true, |expr| is_simple_expr(expr)); - let upper_simple = upper.as_ref().map_or(true, |expr| is_simple_expr(expr)); - let step_simple = step.as_ref().map_or(true, |expr| is_simple_expr(expr)); + let lower_simple = lower.as_ref().is_none_or(|expr| is_simple_expr(expr)); + let upper_simple = upper.as_ref().is_none_or(|expr| is_simple_expr(expr)); + let step_simple = step.as_ref().is_none_or(|expr| is_simple_expr(expr)); let all_simple = lower_simple && upper_simple && step_simple; // lower diff --git a/crates/ruff_python_formatter/src/other/parameter_with_default.rs b/crates/ruff_python_formatter/src/other/parameter_with_default.rs index 74164fb5d9266..a4d09671dfb31 100644 --- a/crates/ruff_python_formatter/src/other/parameter_with_default.rs +++ b/crates/ruff_python_formatter/src/other/parameter_with_default.rs @@ -49,8 +49,7 @@ impl FormatNodeRule for FormatParameterWithDefault { debug_assert!(equals.is_some_and(|token| token.kind == SimpleTokenKind::Equals)); let lparens = tokenizer.next(); debug_assert!(lparens - .as_ref() - .map_or(true, |token| token.kind == SimpleTokenKind::LParen)); + .as_ref().is_none_or(|token| token.kind == SimpleTokenKind::LParen)); lparens.is_none() }); let needs_line_break = needs_line_break_trailing || needs_line_break_leading; diff --git a/crates/ruff_python_parser/src/lexer.rs b/crates/ruff_python_parser/src/lexer.rs index 0bd8472daf8d2..f03630a92435b 100644 --- a/crates/ruff_python_parser/src/lexer.rs +++ b/crates/ruff_python_parser/src/lexer.rs @@ -1256,7 +1256,7 @@ impl<'src> Lexer<'src> { // `IpyEscapeKind::Magic` and `IpyEscapeKind::Help` because of the initial `%` and `??` // tokens. if question_count > 2 - || value.chars().last().map_or(true, is_python_whitespace) + || value.chars().last().is_none_or(is_python_whitespace) || !matches!(self.cursor.first(), '\n' | '\r' | EOF_CHAR) { // Not a help end escape command, so continue with the lexing. diff --git a/crates/ruff_python_resolver/src/implicit_imports.rs b/crates/ruff_python_resolver/src/implicit_imports.rs index 693b6572ca6a1..afa81d27ba8ef 100644 --- a/crates/ruff_python_resolver/src/implicit_imports.rs +++ b/crates/ruff_python_resolver/src/implicit_imports.rs @@ -55,7 +55,7 @@ impl ImplicitImports { // Always prefer stub files over non-stub files. if submodules .get(name) - .map_or(true, |implicit_import| !implicit_import.is_stub_file) + .is_none_or(|implicit_import| !implicit_import.is_stub_file) { submodules.insert( name.to_string(), diff --git a/crates/ruff_python_semantic/src/model.rs b/crates/ruff_python_semantic/src/model.rs index 7805db18c4175..62145f4234da5 100644 --- a/crates/ruff_python_semantic/src/model.rs +++ b/crates/ruff_python_semantic/src/model.rs @@ -344,14 +344,14 @@ impl<'a> SemanticModel<'a> { pub fn is_available_in_scope(&self, member: &str, scope_id: ScopeId) -> bool { self.lookup_symbol_in_scope(member, scope_id, false) .map(|binding_id| &self.bindings[binding_id]) - .map_or(true, |binding| binding.kind.is_builtin()) + .is_none_or(|binding| binding.kind.is_builtin()) } /// Resolve a `del` reference to `symbol` at `range`. pub fn resolve_del(&mut self, symbol: &str, range: TextRange) { let is_unbound = self.scopes[self.scope_id] .get(symbol) - .map_or(true, |binding_id| { + .is_none_or(|binding_id| { // Treat the deletion of a name as a reference to that name. self.add_local_reference(binding_id, ExprContext::Del, range); self.bindings[binding_id].is_unbound() @@ -1508,7 +1508,7 @@ impl<'a> SemanticModel<'a> { if self .global_scope() .get(name) - .map_or(true, |binding_id| self.bindings[binding_id].is_unbound()) + .is_none_or(|binding_id| self.bindings[binding_id].is_unbound()) { let id = self.bindings.push(Binding { kind: BindingKind::Assignment, diff --git a/crates/ruff_workspace/src/resolver.rs b/crates/ruff_workspace/src/resolver.rs index f550f810f6ac1..7c51eb9326c7c 100644 --- a/crates/ruff_workspace/src/resolver.rs +++ b/crates/ruff_workspace/src/resolver.rs @@ -588,7 +588,7 @@ impl ParallelVisitor for PythonFilesVisitor<'_, '_> { match result { Ok(entry) => { // Ignore directories - let resolved = if entry.file_type().map_or(true, |ft| ft.is_dir()) { + let resolved = if entry.file_type().is_none_or(|ft| ft.is_dir()) { None } else if entry.depth() == 0 { // Accept all files that are passed-in directly.