]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/build/matches/mod.rs
Use rposition to find the position of an elem
[rust.git] / src / librustc_mir / build / matches / mod.rs
index 8c94723e3cc2e51a0f57f4f4948e0bd28f07dce9..64368ab604645d6a8986e4a4210fd8846ef42f44 100644 (file)
@@ -942,16 +942,15 @@ fn select_matched_candidates(
             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(),
+                    });
                 }
             }
         }