Skip to content

Commit 7efee8d

Browse files
committed
Use rposition to find the position of an elem
1 parent e9c4114 commit 7efee8d

File tree

1 file changed

+7
-8
lines changed
  • src/librustc_mir/build/matches

1 file changed

+7
-8
lines changed

src/librustc_mir/build/matches/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -942,16 +942,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
942942
for Binding { source, .. }
943943
in matched_candidates.iter().flat_map(|candidate| &candidate.bindings)
944944
{
945-
for (i, elem) in source.projection.iter().enumerate().rev() {
945+
if let Some(i) =
946+
source.projection.iter().rposition(|elem| *elem == ProjectionElem::Deref)
947+
{
946948
let proj_base = &source.projection[..i];
947949

948-
if let ProjectionElem::Deref = elem {
949-
fake_borrows.insert(Place {
950-
base: source.base.clone(),
951-
projection: proj_base.to_vec().into_boxed_slice(),
952-
});
953-
break;
954-
}
950+
fake_borrows.insert(Place {
951+
base: source.base.clone(),
952+
projection: proj_base.to_vec().into_boxed_slice(),
953+
});
955954
}
956955
}
957956
}

0 commit comments

Comments
 (0)