Skip to content

Commit 688e531

Browse files
committed
Split out a complex if condition into a named function
1 parent bd12986 commit 688e531

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,10 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
148148
let Some(&(parent_field_idx, parent_capture)) = parent_captures.peek() else {
149149
bug!("we ran out of parent captures!")
150150
};
151-
152-
let PlaceBase::Upvar(parent_base) = parent_capture.place.base else {
153-
bug!("expected capture to be an upvar");
154-
};
155-
let PlaceBase::Upvar(child_base) = child_capture.place.base else {
156-
bug!("expected capture to be an upvar");
157-
};
158-
159-
assert!(
160-
child_capture.place.projections.len() >= parent_capture.place.projections.len()
161-
);
162151
// A parent matches a child they share the same prefix of projections.
163152
// The child may have more, if it is capturing sub-fields out of
164153
// something that is captured by-move in the parent closure.
165-
if parent_base.var_path.hir_id != child_base.var_path.hir_id
166-
|| !std::iter::zip(
167-
&child_capture.place.projections,
168-
&parent_capture.place.projections,
169-
)
170-
.all(|(child, parent)| child.kind == parent.kind)
171-
{
154+
if !child_prefix_matches_parent_projections(parent_capture, child_capture) {
172155
// Make sure the field was used at least once.
173156
assert!(
174157
field_used_at_least_once,
@@ -258,6 +241,23 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
258241
}
259242
}
260243

244+
fn child_prefix_matches_parent_projections(
245+
parent_capture: &ty::CapturedPlace<'_>,
246+
child_capture: &ty::CapturedPlace<'_>,
247+
) -> bool {
248+
let PlaceBase::Upvar(parent_base) = parent_capture.place.base else {
249+
bug!("expected capture to be an upvar");
250+
};
251+
let PlaceBase::Upvar(child_base) = child_capture.place.base else {
252+
bug!("expected capture to be an upvar");
253+
};
254+
255+
assert!(child_capture.place.projections.len() >= parent_capture.place.projections.len());
256+
parent_base.var_path.hir_id == child_base.var_path.hir_id
257+
&& std::iter::zip(&child_capture.place.projections, &parent_capture.place.projections)
258+
.all(|(child, parent)| child.kind == parent.kind)
259+
}
260+
261261
struct MakeByMoveBody<'tcx> {
262262
tcx: TyCtxt<'tcx>,
263263
field_remapping: UnordMap<FieldIdx, (FieldIdx, Ty<'tcx>, bool, &'tcx [Projection<'tcx>])>,

0 commit comments

Comments
 (0)