about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-09 07:53:12 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-09 07:53:12 +0000
commitf014e91a38d64caa3e1231bb86cfb7f1dbda279f (patch)
tree6ac1ad0ef8f789a6a842c94f440a9933afef2d10
parent626fd4b258f71ba5f044c31e8e4d50d730d14a1f (diff)
downloadrust-f014e91a38d64caa3e1231bb86cfb7f1dbda279f.tar.gz
rust-f014e91a38d64caa3e1231bb86cfb7f1dbda279f.zip
Shrink a loop to its looping part and move out the part that runs after the loop
-rw-r--r--compiler/rustc_mir_transform/src/coroutine/by_move_body.rs100
1 files changed, 50 insertions, 50 deletions
diff --git a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs
index f0a00ebb586..7979b85225c 100644
--- a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs
+++ b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs
@@ -144,67 +144,67 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
             .skip(num_args)
             .enumerate()
         {
+            let (mut parent_field_idx, mut parent_capture);
             loop {
-                let &(parent_field_idx, parent_capture) =
-                    parent_captures.peek().expect("we ran out of parent captures!");
+                (parent_field_idx, parent_capture) =
+                    *parent_captures.peek().expect("we ran out of parent captures!");
                 // 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
                 // something that is captured by-move in the parent closure.
-                if !child_prefix_matches_parent_projections(parent_capture, child_capture) {
-                    // Make sure the field was used at least once.
-                    assert!(
-                        field_used_at_least_once,
-                        "we captured {parent_capture:#?} but it was not used in the child coroutine?"
-                    );
-                    field_used_at_least_once = false;
-                    // Skip this field.
-                    let _ = parent_captures.next().unwrap();
-                    continue;
+                if child_prefix_matches_parent_projections(parent_capture, child_capture) {
+                    break;
                 }
+                // Make sure the field was used at least once.
+                assert!(
+                    field_used_at_least_once,
+                    "we captured {parent_capture:#?} but it was not used in the child coroutine?"
+                );
+                field_used_at_least_once = false;
+                // Skip this field.
+                let _ = parent_captures.next().unwrap();
+            }
 
-                // Store this set of additional projections (fields and derefs).
-                // We need to re-apply them later.
-                let child_precise_captures =
-                    &child_capture.place.projections[parent_capture.place.projections.len()..];
+            // Store this set of additional projections (fields and derefs).
+            // We need to re-apply them later.
+            let child_precise_captures =
+                &child_capture.place.projections[parent_capture.place.projections.len()..];
 
-                // If the parent captures by-move, and the child captures by-ref, then we
-                // need to peel an additional `deref` off of the body of the child.
-                let needs_deref = child_capture.is_by_ref() && !parent_capture.is_by_ref();
-                if needs_deref {
-                    assert_ne!(
-                        coroutine_kind,
-                        ty::ClosureKind::FnOnce,
-                        "`FnOnce` coroutine-closures return coroutines that capture from \
+            // If the parent captures by-move, and the child captures by-ref, then we
+            // need to peel an additional `deref` off of the body of the child.
+            let needs_deref = child_capture.is_by_ref() && !parent_capture.is_by_ref();
+            if needs_deref {
+                assert_ne!(
+                    coroutine_kind,
+                    ty::ClosureKind::FnOnce,
+                    "`FnOnce` coroutine-closures return coroutines that capture from \
                         their body; it will always result in a borrowck error!"
-                    );
-                }
+                );
+            }
 
-                // Finally, store the type of the parent's captured place. We need
-                // this when building the field projection in the MIR body later on.
-                let mut parent_capture_ty = parent_capture.place.ty();
-                parent_capture_ty = match parent_capture.info.capture_kind {
-                    ty::UpvarCapture::ByValue => parent_capture_ty,
-                    ty::UpvarCapture::ByRef(kind) => Ty::new_ref(
-                        tcx,
-                        tcx.lifetimes.re_erased,
-                        parent_capture_ty,
-                        kind.to_mutbl_lossy(),
-                    ),
-                };
+            // Finally, store the type of the parent's captured place. We need
+            // this when building the field projection in the MIR body later on.
+            let mut parent_capture_ty = parent_capture.place.ty();
+            parent_capture_ty = match parent_capture.info.capture_kind {
+                ty::UpvarCapture::ByValue => parent_capture_ty,
+                ty::UpvarCapture::ByRef(kind) => Ty::new_ref(
+                    tcx,
+                    tcx.lifetimes.re_erased,
+                    parent_capture_ty,
+                    kind.to_mutbl_lossy(),
+                ),
+            };
 
-                field_remapping.insert(
-                    FieldIdx::from_usize(child_field_idx + num_args),
-                    (
-                        FieldIdx::from_usize(parent_field_idx + num_args),
-                        parent_capture_ty,
-                        needs_deref,
-                        child_precise_captures,
-                    ),
-                );
+            field_remapping.insert(
+                FieldIdx::from_usize(child_field_idx + num_args),
+                (
+                    FieldIdx::from_usize(parent_field_idx + num_args),
+                    parent_capture_ty,
+                    needs_deref,
+                    child_precise_captures,
+                ),
+            );
 
-                field_used_at_least_once = true;
-                break;
-            }
+            field_used_at_least_once = true;
         }
 
         // Pop the last parent capture