diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2019-08-24 16:04:32 -0700 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2019-09-09 18:16:49 -0300 |
| commit | 7efee8dd05b4a2439451b47de8df79c959faffcd (patch) | |
| tree | 24042bf5be936e570365e4951fdf6d1f880d0364 | |
| parent | e9c41148c0c834d13d6f45bfd99c8f23781c5d31 (diff) | |
| download | rust-7efee8dd05b4a2439451b47de8df79c959faffcd.tar.gz rust-7efee8dd05b4a2439451b47de8df79c959faffcd.zip | |
Use rposition to find the position of an elem
| -rw-r--r-- | src/librustc_mir/build/matches/mod.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 8c94723e3cc..64368ab6046 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -942,16 +942,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { for Binding { source, .. } in matched_candidates.iter().flat_map(|candidate| &candidate.bindings) { - for (i, elem) in source.projection.iter().enumerate().rev() { + if let Some(i) = + source.projection.iter().rposition(|elem| *elem == ProjectionElem::Deref) + { let proj_base = &source.projection[..i]; - if let ProjectionElem::Deref = elem { - fake_borrows.insert(Place { - base: source.base.clone(), - projection: proj_base.to_vec().into_boxed_slice(), - }); - break; - } + fake_borrows.insert(Place { + base: source.base.clone(), + projection: proj_base.to_vec().into_boxed_slice(), + }); } } } |
