Skip to content

Commit

Permalink
Use iter::position in truncate_capture_for_move
Browse files Browse the repository at this point in the history
  • Loading branch information
arora-aman committed Feb 16, 2021
1 parent 1b86ad8 commit f99e152
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f99e152

Please sign in to comment.