Skip to content

Commit 29a4453

Browse files
committed
Merge the two autoref vecs into one in autoderef_method_receiver
1 parent 9e5fa74 commit 29a4453

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

crates/hir-ty/src/method_resolution.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -821,9 +821,9 @@ pub fn iterate_method_candidates_dyn(
821821

822822
let mut table = InferenceTable::new(db, env.clone());
823823
let ty = table.instantiate_canonical(ty.clone());
824-
let (deref_chain, adj) = autoderef_method_receiver(&mut table, ty);
824+
let deref_chain = autoderef_method_receiver(&mut table, ty);
825825

826-
let result = deref_chain.into_iter().zip(adj).try_for_each(|(receiver_ty, adj)| {
826+
let result = deref_chain.into_iter().try_for_each(|(receiver_ty, adj)| {
827827
iterate_method_candidates_with_autoref(
828828
&receiver_ty,
829829
adj,
@@ -867,7 +867,7 @@ fn iterate_method_candidates_with_autoref(
867867
return ControlFlow::Continue(());
868868
}
869869

870-
let iterate_method_candidates_by_receiver = |receiver_ty, first_adjustment| {
870+
let mut iterate_method_candidates_by_receiver = move |receiver_ty, first_adjustment| {
871871
iterate_method_candidates_by_receiver(
872872
receiver_ty,
873873
first_adjustment,
@@ -1199,8 +1199,8 @@ pub fn resolve_indexing_op(
11991199
) -> Option<ReceiverAdjustments> {
12001200
let mut table = InferenceTable::new(db, env.clone());
12011201
let ty = table.instantiate_canonical(ty);
1202-
let (deref_chain, adj) = autoderef_method_receiver(&mut table, ty);
1203-
for (ty, adj) in deref_chain.into_iter().zip(adj) {
1202+
let deref_chain = autoderef_method_receiver(&mut table, ty);
1203+
for (ty, adj) in deref_chain {
12041204
let goal = generic_implements_goal(db, env.clone(), index_trait, &ty);
12051205
if db.trait_solve(env.krate, goal.cast(Interner)).is_some() {
12061206
return Some(adj);
@@ -1410,25 +1410,24 @@ fn generic_implements_goal(
14101410
fn autoderef_method_receiver(
14111411
table: &mut InferenceTable<'_>,
14121412
ty: Ty,
1413-
) -> (Vec<Canonical<Ty>>, Vec<ReceiverAdjustments>) {
1414-
let (mut deref_chain, mut adjustments): (Vec<_>, Vec<_>) = (Vec::new(), Vec::new());
1413+
) -> Vec<(Canonical<Ty>, ReceiverAdjustments)> {
1414+
let mut deref_chain: Vec<_> = Vec::new();
14151415
let mut autoderef = autoderef::Autoderef::new(table, ty);
14161416
while let Some((ty, derefs)) = autoderef.next() {
1417-
deref_chain.push(autoderef.table.canonicalize(ty).value);
1418-
adjustments.push(ReceiverAdjustments {
1419-
autoref: None,
1420-
autoderefs: derefs,
1421-
unsize_array: false,
1422-
});
1417+
deref_chain.push((
1418+
autoderef.table.canonicalize(ty).value,
1419+
ReceiverAdjustments { autoref: None, autoderefs: derefs, unsize_array: false },
1420+
));
14231421
}
14241422
// As a last step, we can do array unsizing (that's the only unsizing that rustc does for method receivers!)
1425-
if let (Some((TyKind::Array(parameters, _), binders)), Some(adj)) = (
1426-
deref_chain.last().map(|ty| (ty.value.kind(Interner), ty.binders.clone())),
1427-
adjustments.last().cloned(),
1428-
) {
1423+
if let Some((TyKind::Array(parameters, _), binders, adj)) =
1424+
deref_chain.last().map(|(ty, adj)| (ty.value.kind(Interner), ty.binders.clone(), adj))
1425+
{
14291426
let unsized_ty = TyKind::Slice(parameters.clone()).intern(Interner);
1430-
deref_chain.push(Canonical { value: unsized_ty, binders });
1431-
adjustments.push(ReceiverAdjustments { unsize_array: true, ..adj });
1427+
deref_chain.push((
1428+
Canonical { value: unsized_ty, binders },
1429+
ReceiverAdjustments { unsize_array: true, ..adj.clone() },
1430+
));
14321431
}
1433-
(deref_chain, adjustments)
1432+
deref_chain
14341433
}

crates/hir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3376,7 +3376,7 @@ impl Type {
33763376
scope: &SemanticsScope<'_>,
33773377
with_local_impls: Option<Module>,
33783378
name: Option<&Name>,
3379-
mut callback: impl FnMut(Function) -> Option<T>,
3379+
callback: impl FnMut(Function) -> Option<T>,
33803380
) -> Option<T> {
33813381
self.iterate_method_candidates_with_traits(
33823382
db,

0 commit comments

Comments
 (0)