mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-15 08:00:46 +00:00
Simplify iteration idioms (#13834)
Remove unnecessary uses of `.as_ref()`, `.iter()`, `&**` and similar, mostly in situations when iterating over variables. Many of these changes are only possible following #13826, when we bumped our MSRV to 1.80: several useful implementations on `&Box<[T]>` were only stabilised in Rust 1.80. Some of these changes we could have done earlier, however.
This commit is contained in:
parent
7fd8e30eed
commit
72adb09bf3
36 changed files with 72 additions and 73 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<Parameters> {
|
||||
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.
|
||||
///
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue