diff --git a/crates/red_knot_python_semantic/src/semantic_index/builder.rs b/crates/red_knot_python_semantic/src/semantic_index/builder.rs index 61e810ffb38e4..abbdd3f0c4186 100644 --- a/crates/red_knot_python_semantic/src/semantic_index/builder.rs +++ b/crates/red_knot_python_semantic/src/semantic_index/builder.rs @@ -1012,7 +1012,7 @@ where // Add symbols and definitions for the parameters to the lambda scope. if let Some(parameters) = &lambda.parameters { - for parameter in &**parameters { + for parameter in parameters { self.declare_parameter(parameter); } } diff --git a/crates/red_knot_python_semantic/src/types.rs b/crates/red_knot_python_semantic/src/types.rs index 71df2ac1e7d23..3944126f2c38e 100644 --- a/crates/red_knot_python_semantic/src/types.rs +++ b/crates/red_knot_python_semantic/src/types.rs @@ -597,7 +597,7 @@ impl<'db> Type<'db> { tuple .elements(db) .iter() - .zip(other_tuple.elements(db).iter()) + .zip(other_tuple.elements(db)) .any(|(e1, e2)| e1.is_disjoint_from(db, *e2)) } else { true @@ -863,7 +863,7 @@ impl<'db> Type<'db> { fn iterate(self, db: &'db dyn Db) -> IterationOutcome<'db> { if let Type::Tuple(tuple_type) = self { return IterationOutcome::Iterable { - element_ty: UnionType::from_elements(db, &**tuple_type.elements(db)), + element_ty: UnionType::from_elements(db, tuple_type.elements(db)), }; } @@ -1310,7 +1310,7 @@ impl<'db> CallOutcome<'db> { let mut not_callable = vec![]; let mut union_builder = UnionBuilder::new(db); let mut revealed = false; - for outcome in &**outcomes { + for outcome in outcomes { let return_ty = match outcome { Self::NotCallable { not_callable_ty } => { not_callable.push(*not_callable_ty); diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index b5dd5df59b0bf..5c2cffc8339f8 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -2809,7 +2809,7 @@ impl<'db> TypeInferenceBuilder<'db> { } = compare; self.infer_expression(left); - for right in comparators.as_ref() { + for right in comparators { self.infer_expression(right); } @@ -2823,10 +2823,10 @@ impl<'db> TypeInferenceBuilder<'db> { Self::infer_chained_boolean_types( self.db, ast::BoolOp::And, - std::iter::once(left.as_ref()) - .chain(comparators.as_ref().iter()) + std::iter::once(&**left) + .chain(comparators) .tuple_windows::<(_, _)>() - .zip(ops.iter()) + .zip(ops) .map(|((left, right), op)| { let left_ty = self.expression_ty(left); let right_ty = self.expression_ty(right); @@ -3036,8 +3036,8 @@ impl<'db> TypeInferenceBuilder<'db> { } (Type::Tuple(lhs), Type::Tuple(rhs)) => { // Note: This only works on heterogeneous tuple types. - let lhs_elements = lhs.elements(self.db).as_ref(); - let rhs_elements = rhs.elements(self.db).as_ref(); + let lhs_elements = lhs.elements(self.db); + let rhs_elements = rhs.elements(self.db); let mut lexicographic_type_comparison = |op| self.infer_lexicographic_type_comparison(lhs_elements, op, rhs_elements); diff --git a/crates/red_knot_python_semantic/src/types/narrow.rs b/crates/red_knot_python_semantic/src/types/narrow.rs index 16577e3ddf48e..7d9d58995320b 100644 --- a/crates/red_knot_python_semantic/src/types/narrow.rs +++ b/crates/red_knot_python_semantic/src/types/narrow.rs @@ -153,7 +153,7 @@ impl<'db> NarrowingConstraintsBuilder<'db> { let symbol = self.symbols().symbol_id_by_name(id).unwrap(); let scope = self.scope(); let inference = infer_expression_types(self.db, expression); - for (op, comparator) in std::iter::zip(&**ops, &**comparators) { + for (op, comparator) in std::iter::zip(ops, comparators) { let comp_ty = inference.expression_ty(comparator.scoped_ast_id(self.db, scope)); match op { ast::CmpOp::IsNot => { diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 3d4ab46a6d9af..821d74eb4d0b7 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -732,7 +732,7 @@ impl<'a> Visitor<'a> for Checker<'a> { // The default values of the parameters needs to be evaluated in the enclosing // scope. - for parameter in &**parameters { + for parameter in parameters { if let Some(expr) = parameter.default() { self.visit_expr(expr); } @@ -744,7 +744,7 @@ impl<'a> Visitor<'a> for Checker<'a> { self.visit_type_params(type_params); } - for parameter in &**parameters { + for parameter in parameters { if let Some(expr) = parameter.annotation() { if singledispatch && !parameter.is_variadic() { self.visit_runtime_required_annotation(expr); diff --git a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs index edd7c93e0c830..ec6acffebd29d 100644 --- a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs +++ b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_unused_path_parameter.rs @@ -141,7 +141,7 @@ pub(crate) fn fastapi_unused_path_parameter( .parameters .args .iter() - .chain(function_def.parameters.kwonlyargs.iter()) + .chain(&function_def.parameters.kwonlyargs) .map(|ParameterWithDefault { parameter, .. }| { parameter_alias(parameter, checker.semantic()) .unwrap_or_else(|| parameter.name.as_str()) diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs index 5c3bfb1e4129c..162af2b907305 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/zip_without_explicit_strict.rs @@ -116,7 +116,7 @@ fn is_infinite_iterator(arg: &Expr, semantic: &SemanticModel) -> bool { } // Ex) `iterools.repeat(1, times=None)` - for keyword in &**keywords { + for keyword in keywords { if keyword.arg.as_ref().is_some_and(|name| name == "times") { if keyword.value.is_none_literal_expr() { return true; diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs b/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs index 03e25673bd3c3..fede8ba3681d8 100644 --- a/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs +++ b/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs @@ -110,7 +110,7 @@ fn check_log_record_attr_clash(checker: &mut Checker, extra: &Keyword) { .. }) => { if checker.semantic().match_builtin_expr(func, "dict") { - for keyword in &**keywords { + for keyword in keywords { if let Some(attr) = &keyword.arg { if is_reserved_attr(attr) { checker.diagnostics.push(Diagnostic::new( diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs index 426d81543da6e..34eb68943f693 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs @@ -78,7 +78,7 @@ pub(crate) fn custom_type_var_return_type( let Some(self_or_cls_annotation) = args .posonlyargs .iter() - .chain(args.args.iter()) + .chain(&args.args) .next() .and_then(|parameter_with_default| parameter_with_default.parameter.annotation.as_ref()) else { 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 71e2d162a93bf..15a92bae415b4 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 @@ -140,7 +140,7 @@ pub(crate) fn bad_exit_annotation(checker: &mut Checker, function: &StmtFunction let non_self_positional_args: SmallVec<[&ParameterWithDefault; 3]> = parameters .posonlyargs .iter() - .chain(parameters.args.iter()) + .chain(¶meters.args) .skip(1) .collect(); diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs index b4e4d5fafe462..fce0ea72420b0 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs @@ -252,7 +252,7 @@ impl UnittestAssert { FxHashMap::with_capacity_and_hasher(args.len() + keywords.len(), FxBuildHasher); // Process positional arguments. - for (arg_name, value) in arg_spec.iter().zip(args.iter()) { + for (arg_name, value) in arg_spec.iter().zip(args) { args_map.insert(arg_name, value); } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs index 7c4cd90b12f53..699544081361c 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs @@ -65,7 +65,7 @@ pub(crate) fn if_with_same_arms(checker: &mut Checker, stmt_if: &ast::StmtIf) { if !current_branch .body .iter() - .zip(following_branch.body.iter()) + .zip(following_branch.body) .all(|(stmt1, stmt2)| ComparableStmt::from(stmt1) == ComparableStmt::from(stmt2)) { continue; diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs index c5117544f0427..0a59cdb866299 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs @@ -248,12 +248,7 @@ pub(crate) fn literal_comparisons(checker: &mut Checker, compare: &ast::ExprComp } // Check each comparator in order. - for (index, (op, next)) in compare - .ops - .iter() - .zip(compare.comparators.iter()) - .enumerate() - { + for (index, (op, next)) in compare.ops.iter().zip(&compare.comparators).enumerate() { if helpers::is_constant_non_singleton(comparator) { comparator = next; continue; diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs index 3adaef03ab543..7e57b9cc8f93d 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs @@ -62,10 +62,10 @@ impl Violation for TypeComparison { /// E721 pub(crate) fn type_comparison(checker: &mut Checker, compare: &ast::ExprCompare) { - for (left, right) in std::iter::once(compare.left.as_ref()) - .chain(compare.comparators.iter()) + for (left, right) in std::iter::once(&*compare.left) + .chain(&compare.comparators) .tuple_windows() - .zip(compare.ops.iter()) + .zip(&compare.ops) .filter(|(_, op)| matches!(op, CmpOp::Eq | CmpOp::NotEq)) .map(|((left, right), _)| (left, right)) { diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs index 4a296de44e845..acbfd5ef14849 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs @@ -870,7 +870,7 @@ pub(crate) fn string_dot_format_missing_argument( let missing: Vec = summary .autos .iter() - .chain(summary.indices.iter()) + .chain(&summary.indices) .filter(|&&i| i >= args.len()) .map(ToString::to_string) .chain( diff --git a/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs b/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs index 3b0166bfd9885..db7d246ec6166 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs @@ -76,7 +76,7 @@ pub(crate) fn compare_to_empty_string( let mut first = true; for ((lhs, rhs), op) in std::iter::once(left) - .chain(comparators.iter()) + .chain(comparators) .tuple_windows::<(&Expr, &Expr)>() .zip(ops) { diff --git a/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs b/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs index df46b79883a7d..f55906a324988 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/comparison_of_constant.rs @@ -57,7 +57,7 @@ pub(crate) fn comparison_of_constant( comparators: &[Expr], ) { for ((left, right), op) in std::iter::once(left) - .chain(comparators.iter()) + .chain(comparators) .tuple_windows() .zip(ops) { diff --git a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs index 27533f35e2eab..2984fb6d9beb7 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs @@ -55,7 +55,7 @@ pub(crate) fn comparison_with_itself( comparators: &[Expr], ) { for ((left, right), op) in std::iter::once(left) - .chain(comparators.iter()) + .chain(comparators) .tuple_windows() .zip(ops) { diff --git a/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs b/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs index 5ec9859cf2358..506f53b9d5209 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/duplicate_bases.rs @@ -64,7 +64,7 @@ pub(crate) fn duplicate_bases(checker: &mut Checker, name: &str, arguments: Opti let bases = &arguments.args; let mut seen: FxHashSet<&str> = FxHashSet::with_capacity_and_hasher(bases.len(), FxBuildHasher); - for base in &**bases { + for base in bases { if let Expr::Name(ast::ExprName { id, .. }) = base { if !seen.insert(id) { let mut diagnostic = Diagnostic::new( diff --git a/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs index 5e2463df4def1..2ae14884f7f84 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/magic_value_comparison.rs @@ -97,10 +97,7 @@ fn is_magic_value(literal_expr: LiteralExpressionRef, allowed_types: &[ConstantT /// PLR2004 pub(crate) fn magic_value_comparison(checker: &mut Checker, left: &Expr, comparators: &[Expr]) { - for (left, right) in std::iter::once(left) - .chain(comparators.iter()) - .tuple_windows() - { + for (left, right) in std::iter::once(left).chain(comparators).tuple_windows() { // If both of the comparators are literals, skip rule for the whole expression. // R0133: comparison-of-constants if as_literal(left).is_some() && as_literal(right).is_some() { @@ -108,7 +105,7 @@ pub(crate) fn magic_value_comparison(checker: &mut Checker, left: &Expr, compara } } - for comparison_expr in std::iter::once(left).chain(comparators.iter()) { + for comparison_expr in std::iter::once(left).chain(comparators) { if let Some(value) = as_literal(comparison_expr) { if is_magic_value(value, &checker.settings.pylint.allow_magic_value_types) { checker.diagnostics.push(Diagnostic::new( diff --git a/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs index fdc3347e2de64..4329a69f906e8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nan_comparison.rs @@ -49,7 +49,7 @@ impl Violation for NanComparison { /// PLW0177 pub(crate) fn nan_comparison(checker: &mut Checker, left: &Expr, comparators: &[Expr]) { - for expr in std::iter::once(left).chain(comparators.iter()) { + for expr in std::iter::once(left).chain(comparators) { if let Some(qualified_name) = checker.semantic().resolve_qualified_name(expr) { match qualified_name.segments() { ["numpy", "nan" | "NAN" | "NaN"] => { diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs index adb9544c3b05e..56f2343343033 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs @@ -108,7 +108,7 @@ pub(crate) fn repeated_equality_comparison(checker: &mut Checker, bool_op: &ast: // Break into sequences of consecutive comparisons. let mut sequences: Vec<(Vec, Vec<&Expr>)> = Vec::new(); let mut last = None; - for (index, comparator) in indices.iter().zip(comparators.iter()) { + for (index, comparator) in indices.iter().zip(comparators) { if last.is_some_and(|last| last + 1 == *index) { let (indices, comparators) = sequences.last_mut().unwrap(); indices.push(*index); diff --git a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs index 3a89da451ec9f..e42b176829bde 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs @@ -179,7 +179,7 @@ pub(crate) fn unnecessary_lambda(checker: &mut Checker, lambda: &ExprLambda) { if call_posargs.len() != lambda_posargs.len() { return; } - for (param, arg) in lambda_posargs.iter().zip(call_posargs.iter()) { + for (param, arg) in lambda_posargs.iter().zip(call_posargs) { let Expr::Name(ast::ExprName { id, .. }) = arg else { return; }; diff --git a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs index 4dce615771ed6..1a69095473d1b 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs @@ -143,10 +143,10 @@ fn concatenate_expressions(expr: &Expr) -> Option<(Expr, Type)> { } // If the splat element is itself a list/tuple, insert them in the other list/tuple. Expr::List(ast::ExprList { elts, .. }) if matches!(type_, Type::List) => { - other_elements.iter().chain(elts.iter()).cloned().collect() + other_elements.iter().chain(elts).cloned().collect() } Expr::Tuple(ast::ExprTuple { elts, .. }) if matches!(type_, Type::Tuple) => { - other_elements.iter().chain(elts.iter()).cloned().collect() + other_elements.iter().chain(elts).cloned().collect() } _ => return None, }; 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 fbc652084d7d5..7ecfe19b1346d 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 @@ -189,12 +189,12 @@ fn should_be_fstring( .filter_map(ast::Expr::as_call_expr) { let ast::Arguments { keywords, args, .. } = &expr.arguments; - for keyword in &**keywords { + for keyword in keywords { if let Some(ident) = keyword.arg.as_ref() { arg_names.insert(&ident.id); } } - for arg in &**args { + for arg in args { if let ast::Expr::Name(ast::ExprName { id, .. }) = arg { arg_names.insert(id); } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs index 4d975889d1df6..132459592c6bb 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs @@ -100,7 +100,7 @@ impl<'a> StatementVisitor<'a> for RaiseStatementVisitor<'a> { Stmt::Try(ast::StmtTry { body, finalbody, .. }) => { - for stmt in body.iter().chain(finalbody.iter()) { + for stmt in body.iter().chain(finalbody) { walk_stmt(self, stmt); } } diff --git a/crates/ruff_linter/src/source_kind.rs b/crates/ruff_linter/src/source_kind.rs index 6c70b58dc80fd..f067fe49dbb4c 100644 --- a/crates/ruff_linter/src/source_kind.rs +++ b/crates/ruff_linter/src/source_kind.rs @@ -135,9 +135,8 @@ impl std::fmt::Display for SourceKindDiff<'_> { } DiffKind::IpyNotebook(original, modified) => { // Cell indices are 1-based. - for ((idx, src_cell), dst_cell) in (1u32..) - .zip(original.cells().iter()) - .zip(modified.cells().iter()) + for ((idx, src_cell), dst_cell) in + (1u32..).zip(original.cells()).zip(modified.cells()) { let (Cell::Code(src_cell), Cell::Code(dst_cell)) = (src_cell, dst_cell) else { continue; diff --git a/crates/ruff_python_ast/src/node.rs b/crates/ruff_python_ast/src/node.rs index ca3bbf27f3382..0eb967e0c440a 100644 --- a/crates/ruff_python_ast/src/node.rs +++ b/crates/ruff_python_ast/src/node.rs @@ -2731,7 +2731,7 @@ impl AstNode for ast::ExprCompare { visitor.visit_expr(left); - for (op, comparator) in ops.iter().zip(&**comparators) { + for (op, comparator) in ops.iter().zip(comparators) { visitor.visit_cmp_op(op); visitor.visit_expr(comparator); } diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 68ca97aa0ff89..d2e584279cef4 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -2048,7 +2048,7 @@ impl PartialEq for ConcatenatedStringLiteral { // The `zip` here is safe because we have checked the length of both parts. self.strings .iter() - .zip(other.strings.iter()) + .zip(&other.strings) .all(|(s1, s2)| s1 == s2) } } @@ -3660,6 +3660,14 @@ impl<'a> IntoIterator for &'a Parameters { } } +impl<'a> IntoIterator for &'a Box { + type IntoIter = ParametersIterator<'a>; + type Item = AnyParameterRef<'a>; + fn into_iter(self) -> Self::IntoIter { + (&**self).into_iter() + } +} + /// An alternative type of AST `arg`. This is used for each function argument that might have a default value. /// Used by `Arguments` original type. /// diff --git a/crates/ruff_python_ast/src/visitor.rs b/crates/ruff_python_ast/src/visitor.rs index 687a4bcf14019..0f16af535461c 100644 --- a/crates/ruff_python_ast/src/visitor.rs +++ b/crates/ruff_python_ast/src/visitor.rs @@ -459,10 +459,10 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) { range: _, }) => { visitor.visit_expr(left); - for cmp_op in &**ops { + for cmp_op in ops { visitor.visit_cmp_op(cmp_op); } - for expr in &**comparators { + for expr in comparators { visitor.visit_expr(expr); } } diff --git a/crates/ruff_python_codegen/src/generator.rs b/crates/ruff_python_codegen/src/generator.rs index 89d4702f8dd25..68b4ff606425d 100644 --- a/crates/ruff_python_codegen/src/generator.rs +++ b/crates/ruff_python_codegen/src/generator.rs @@ -1024,7 +1024,7 @@ impl<'a> Generator<'a> { group_if!(precedence::CMP, { let new_lvl = precedence::CMP + 1; self.unparse_expr(left, new_lvl); - for (op, cmp) in ops.iter().zip(&**comparators) { + for (op, cmp) in ops.iter().zip(comparators) { let op = match op { CmpOp::Eq => " == ", CmpOp::NotEq => " != ", diff --git a/crates/ruff_python_formatter/src/pattern/pattern_arguments.rs b/crates/ruff_python_formatter/src/pattern/pattern_arguments.rs index 6add2788c3238..3bbfa4ceceb57 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_arguments.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_arguments.rs @@ -48,7 +48,7 @@ impl FormatNodeRule for FormatPatternArguments { pattern.format().with_options(Parentheses::Preserve), ) })) - .nodes(item.keywords.iter()); + .nodes(&item.keywords); } } diff --git a/crates/ruff_python_semantic/src/analyze/typing.rs b/crates/ruff_python_semantic/src/analyze/typing.rs index 073b6334a6515..d915bfa8b6901 100644 --- a/crates/ruff_python_semantic/src/analyze/typing.rs +++ b/crates/ruff_python_semantic/src/analyze/typing.rs @@ -487,7 +487,7 @@ fn check_type(binding: &Binding, semantic: &SemanticModel) -> bo // The type checker might know how to infer the type based on `init_expr`. Some(Stmt::Assign(ast::StmtAssign { targets, value, .. })) => targets .iter() - .find_map(|target| match_value(binding, target, value.as_ref())) + .find_map(|target| match_value(binding, target, value)) .is_some_and(|value| T::match_initializer(value, semantic)), // ```python @@ -496,7 +496,7 @@ fn check_type(binding: &Binding, semantic: &SemanticModel) -> bo // // In this situation, we check only the annotation. Some(Stmt::AnnAssign(ast::StmtAnnAssign { annotation, .. })) => { - T::match_annotation(annotation.as_ref(), semantic) + T::match_annotation(annotation, semantic) } _ => false, @@ -512,7 +512,7 @@ fn check_type(binding: &Binding, semantic: &SemanticModel) -> bo .expressions(source) .find_map(|expr| expr.as_named_expr()) .and_then(|ast::ExprNamed { target, value, .. }| { - match_value(binding, target.as_ref(), value.as_ref()) + match_value(binding, target, value) }) .is_some_and(|value| T::match_initializer(value, semantic)) }) @@ -543,13 +543,13 @@ fn check_type(binding: &Binding, semantic: &SemanticModel) -> bo // // We trust the annotation and see if the type checker matches the annotation. Some(Stmt::FunctionDef(ast::StmtFunctionDef { parameters, .. })) => { - let Some(parameter) = find_parameter(parameters.as_ref(), binding) else { + let Some(parameter) = find_parameter(parameters, binding) else { return false; }; let Some(ref annotation) = parameter.parameter.annotation else { return false; }; - T::match_annotation(annotation.as_ref(), semantic) + T::match_annotation(annotation, semantic) } _ => false, @@ -562,7 +562,7 @@ fn check_type(binding: &Binding, semantic: &SemanticModel) -> bo // // It's a typed declaration, type annotation is the only source of information. Some(Stmt::AnnAssign(ast::StmtAnnAssign { annotation, .. })) => { - T::match_annotation(annotation.as_ref(), semantic) + T::match_annotation(annotation, semantic) } _ => false, }, @@ -726,7 +726,7 @@ impl TypeChecker for IoBaseChecker { // Ex) `open("file.txt")` semantic - .resolve_qualified_name(func.as_ref()) + .resolve_qualified_name(func) .is_some_and(|qualified_name| { matches!( qualified_name.segments(), @@ -899,7 +899,7 @@ pub fn find_binding_value<'a>(binding: &Binding, semantic: &'a SemanticModel) -> .expressions(parent_id) .find_map(|expr| expr.as_named_expr()); if let Some(ast::ExprNamed { target, value, .. }) = parent { - return match_value(binding, target.as_ref(), value.as_ref()); + return match_value(binding, target, value); } } // Ex) `x = 1` @@ -907,14 +907,14 @@ pub fn find_binding_value<'a>(binding: &Binding, semantic: &'a SemanticModel) -> Some(Stmt::Assign(ast::StmtAssign { value, targets, .. })) => { return targets .iter() - .find_map(|target| match_value(binding, target, value.as_ref())) + .find_map(|target| match_value(binding, target, value)) } Some(Stmt::AnnAssign(ast::StmtAnnAssign { value: Some(value), target, .. })) => { - return match_value(binding, target, value.as_ref()); + return match_value(binding, target, value); } _ => {} }, @@ -958,7 +958,7 @@ fn match_value<'a>(binding: &Binding, target: &Expr, value: &'a Expr) -> Option< /// Given a target and value, find the value that's assigned to the given symbol. fn match_target<'a>(binding: &Binding, targets: &[Expr], values: &'a [Expr]) -> Option<&'a Expr> { - for (target, value) in targets.iter().zip(values.iter()) { + for (target, value) in targets.iter().zip(values) { match target { Expr::Tuple(ast::ExprTuple { elts: target_elts, .. diff --git a/crates/ruff_python_semantic/src/model.rs b/crates/ruff_python_semantic/src/model.rs index 959ab5226d3c9..7c7967e80e36c 100644 --- a/crates/ruff_python_semantic/src/model.rs +++ b/crates/ruff_python_semantic/src/model.rs @@ -795,7 +795,7 @@ impl<'a> SemanticModel<'a> { let resolved: QualifiedName = qualified_name .segments() .iter() - .chain(tail.iter()) + .chain(tail) .copied() .collect(); Some(resolved) @@ -809,7 +809,7 @@ impl<'a> SemanticModel<'a> { .segments() .iter() .take(1) - .chain(tail.iter()) + .chain(tail) .copied() .collect(), ) @@ -832,7 +832,7 @@ impl<'a> SemanticModel<'a> { qualified_name .segments() .iter() - .chain(tail.iter()) + .chain(tail) .copied() .collect() }; diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index 5d95fac9d01f2..17a1deb6c3ea1 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -803,7 +803,7 @@ impl LintConfiguration { .select .iter() .flatten() - .chain(selection.extend_select.iter()) + .chain(&selection.extend_select) .filter(|s| s.specificity() == spec) { for rule in selector.rules(&preview) { @@ -830,7 +830,7 @@ impl LintConfiguration { .fixable .iter() .flatten() - .chain(selection.extend_fixable.iter()) + .chain(&selection.extend_fixable) .filter(|s| s.specificity() == spec) { for rule in selector.all_rules() { diff --git a/crates/ruff_workspace/src/resolver.rs b/crates/ruff_workspace/src/resolver.rs index 04750c8509362..ae9f46f1a97b8 100644 --- a/crates/ruff_workspace/src/resolver.rs +++ b/crates/ruff_workspace/src/resolver.rs @@ -219,7 +219,7 @@ impl<'a> Resolver<'a> { /// Return an iterator over the resolved [`Settings`] in this [`Resolver`]. pub fn settings(&self) -> impl Iterator { - std::iter::once(&self.pyproject_config.settings).chain(self.settings.iter()) + std::iter::once(&self.pyproject_config.settings).chain(&self.settings) } }