From f99e152e5a02d75e5df1a10b33d4e8592cd25fee Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Sat, 13 Feb 2021 01:59:35 -0500 Subject: [PATCH] Use iter::position in truncate_capture_for_move --- compiler/rustc_typeck/src/check/upvar.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index fbbc1fba8771f..69c09528662d3 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