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:31:20 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-09 07:47:40 +0000
commit688e531925577de3d8f57f717976f7d2d69fd45b (patch)
tree2a1109bc6a5dabe285c2e338e83f60c4cfb92429
parentbd12986fd6659a3091cff7694b8225374f4a26fe (diff)
downloadrust-688e531925577de3d8f57f717976f7d2d69fd45b.tar.gz
rust-688e531925577de3d8f57f717976f7d2d69fd45b.zip
Split out a complex if condition into a named function
-rw-r--r--compiler/rustc_mir_transform/src/coroutine/by_move_body.rs36
1 files changed, 18 insertions, 18 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 320d8fd3977..d88c7bebc73 100644
--- a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs
+++ b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs
@@ -148,27 +148,10 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
                 let Some(&(parent_field_idx, parent_capture)) = parent_captures.peek() else {
                     bug!("we ran out of parent captures!")
                 };
-
-                let PlaceBase::Upvar(parent_base) = parent_capture.place.base else {
-                    bug!("expected capture to be an upvar");
-                };
-                let PlaceBase::Upvar(child_base) = child_capture.place.base else {
-                    bug!("expected capture to be an upvar");
-                };
-
-                assert!(
-                    child_capture.place.projections.len() >= parent_capture.place.projections.len()
-                );
                 // 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 parent_base.var_path.hir_id != child_base.var_path.hir_id
-                    || !std::iter::zip(
-                        &child_capture.place.projections,
-                        &parent_capture.place.projections,
-                    )
-                    .all(|(child, parent)| child.kind == parent.kind)
-                {
+                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,
@@ -258,6 +241,23 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
     }
 }
 
+fn child_prefix_matches_parent_projections(
+    parent_capture: &ty::CapturedPlace<'_>,
+    child_capture: &ty::CapturedPlace<'_>,
+) -> bool {
+    let PlaceBase::Upvar(parent_base) = parent_capture.place.base else {
+        bug!("expected capture to be an upvar");
+    };
+    let PlaceBase::Upvar(child_base) = child_capture.place.base else {
+        bug!("expected capture to be an upvar");
+    };
+
+    assert!(child_capture.place.projections.len() >= parent_capture.place.projections.len());
+    parent_base.var_path.hir_id == child_base.var_path.hir_id
+        && std::iter::zip(&child_capture.place.projections, &parent_capture.place.projections)
+            .all(|(child, parent)| child.kind == parent.kind)
+}
+
 struct MakeByMoveBody<'tcx> {
     tcx: TyCtxt<'tcx>,
     field_remapping: UnordMap<FieldIdx, (FieldIdx, Ty<'tcx>, bool, &'tcx [Projection<'tcx>])>,