about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAman Arora <me@aman-arora.com>2021-02-13 01:59:35 -0500
committerAman Arora <me@aman-arora.com>2021-02-15 22:00:40 -0500
commitf99e152e5a02d75e5df1a10b33d4e8592cd25fee (patch)
treea0a5cd7249358f39de114caea5b8d86f0a064880
parent1b86ad8485a1937ecd16b2dd5d9c5feb4eac93ec (diff)
downloadrust-f99e152e5a02d75e5df1a10b33d4e8592cd25fee.tar.gz
rust-f99e152e5a02d75e5df1a10b33d4e8592cd25fee.zip
Use iter::position in truncate_capture_for_move
-rw-r--r--compiler/rustc_typeck/src/check/upvar.rs14
1 files changed, 4 insertions, 10 deletions
diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs
index fbbc1fba877..69c09528662 100644
--- a/compiler/rustc_typeck/src/check/upvar.rs
+++ b/compiler/rustc_typeck/src/check/upvar.rs
@@ -1461,16 +1461,10 @@ fn restrict_capture_precision<'tcx>(mut place: Place<'tcx>) -> Place<'tcx> {
 
 /// Truncates a place so that the resultant capture doesn't move data out of a reference
 fn truncate_capture_for_move(mut place: Place<'tcx>) -> Place<'tcx> {
-    for (i, proj) in place.projections.iter().enumerate() {
-        match proj.kind {
-            ProjectionKind::Deref => {
-                // We only drop Derefs in case of move closures
-                // There might be an index projection or raw ptr ahead, so we don't stop here.
-                place.projections.truncate(i);
-                return place;
-            }
-            _ => {}
-        }
+    if let Some(i) = place.projections.iter().position(|proj| proj.kind == ProjectionKind::Deref) {
+        // We only drop Derefs in case of move closures
+        // There might be an index projection or raw ptr ahead, so we don't stop here.
+        place.projections.truncate(i);
     }
 
     place