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:
Alex Waygood 2024-10-20 22:25:27 +01:00 committed by GitHub
parent 7fd8e30eed
commit 72adb09bf3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 72 additions and 73 deletions

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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 => {