Skip to content

Commit f99e152

Browse files
committed
Use iter::position in truncate_capture_for_move
1 parent 1b86ad8 commit f99e152

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

compiler/rustc_typeck/src/check/upvar.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -1461,16 +1461,10 @@ fn restrict_capture_precision<'tcx>(mut place: Place<'tcx>) -> Place<'tcx> {
14611461

14621462
/// Truncates a place so that the resultant capture doesn't move data out of a reference
14631463
fn truncate_capture_for_move(mut place: Place<'tcx>) -> Place<'tcx> {
1464-
for (i, proj) in place.projections.iter().enumerate() {
1465-
match proj.kind {
1466-
ProjectionKind::Deref => {
1467-
// We only drop Derefs in case of move closures
1468-
// There might be an index projection or raw ptr ahead, so we don't stop here.
1469-
place.projections.truncate(i);
1470-
return place;
1471-
}
1472-
_ => {}
1473-
}
1464+
if let Some(i) = place.projections.iter().position(|proj| proj.kind == ProjectionKind::Deref) {
1465+
// We only drop Derefs in case of move closures
1466+
// There might be an index projection or raw ptr ahead, so we don't stop here.
1467+
place.projections.truncate(i);
14741468
}
14751469

14761470
place

0 commit comments

Comments
 (0)