Shrink a loop to its looping part and move out the part that runs after the loop

This commit is contained in:
Oli Scherer 2024-04-09 07:53:12 +00:00
parent 626fd4b258
commit f014e91a38

View File

@ -144,13 +144,16 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
.skip(num_args) .skip(num_args)
.enumerate() .enumerate()
{ {
let (mut parent_field_idx, mut parent_capture);
loop { loop {
let &(parent_field_idx, parent_capture) = (parent_field_idx, parent_capture) =
parent_captures.peek().expect("we ran out of parent captures!"); *parent_captures.peek().expect("we ran out of parent captures!");
// A parent matches a child they share the same prefix of projections. // A parent matches a child they share the same prefix of projections.
// The child may have more, if it is capturing sub-fields out of // The child may have more, if it is capturing sub-fields out of
// something that is captured by-move in the parent closure. // something that is captured by-move in the parent closure.
if !child_prefix_matches_parent_projections(parent_capture, child_capture) { if child_prefix_matches_parent_projections(parent_capture, child_capture) {
break;
}
// Make sure the field was used at least once. // Make sure the field was used at least once.
assert!( assert!(
field_used_at_least_once, field_used_at_least_once,
@ -159,7 +162,6 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
field_used_at_least_once = false; field_used_at_least_once = false;
// Skip this field. // Skip this field.
let _ = parent_captures.next().unwrap(); let _ = parent_captures.next().unwrap();
continue;
} }
// Store this set of additional projections (fields and derefs). // Store this set of additional projections (fields and derefs).
@ -203,8 +205,6 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
); );
field_used_at_least_once = true; field_used_at_least_once = true;
break;
}
} }
// Pop the last parent capture // Pop the last parent capture