Split out a complex if condition into a named function
This commit is contained in:
parent
bd12986fd6
commit
688e531925
1 changed files with 18 additions and 18 deletions
|
@ -148,27 +148,10 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
|
||||||
let Some(&(parent_field_idx, parent_capture)) = parent_captures.peek() else {
|
let Some(&(parent_field_idx, parent_capture)) = parent_captures.peek() else {
|
||||||
bug!("we ran out of parent captures!")
|
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.
|
// 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 parent_base.var_path.hir_id != child_base.var_path.hir_id
|
if !child_prefix_matches_parent_projections(parent_capture, child_capture) {
|
||||||
|| !std::iter::zip(
|
|
||||||
&child_capture.place.projections,
|
|
||||||
&parent_capture.place.projections,
|
|
||||||
)
|
|
||||||
.all(|(child, parent)| child.kind == parent.kind)
|
|
||||||
{
|
|
||||||
// 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,
|
||||||
|
@ -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> {
|
struct MakeByMoveBody<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
field_remapping: UnordMap<FieldIdx, (FieldIdx, Ty<'tcx>, bool, &'tcx [Projection<'tcx>])>,
|
field_remapping: UnordMap<FieldIdx, (FieldIdx, Ty<'tcx>, bool, &'tcx [Projection<'tcx>])>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue