1
Fork 0

Use let/else to de-indent ElaborateBoxDerefs::run_pass.

This commit is contained in:
Nicholas Nethercote 2024-09-09 08:49:47 +10:00
parent cc09ab3c75
commit 181fbd5ce8

View file

@ -92,11 +92,12 @@ pub(super) struct ElaborateBoxDerefs;
impl<'tcx> crate::MirPass<'tcx> for ElaborateBoxDerefs { impl<'tcx> crate::MirPass<'tcx> for ElaborateBoxDerefs {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
if let Some(def_id) = tcx.lang_items().owned_box() { // If box is not present, this pass doesn't need to do anything.
let Some(def_id) = tcx.lang_items().owned_box() else { return };
let unique_did = tcx.adt_def(def_id).non_enum_variant().fields[FieldIdx::ZERO].did; let unique_did = tcx.adt_def(def_id).non_enum_variant().fields[FieldIdx::ZERO].did;
let Some(nonnull_def) = tcx.type_of(unique_did).instantiate_identity().ty_adt_def() let Some(nonnull_def) = tcx.type_of(unique_did).instantiate_identity().ty_adt_def() else {
else {
span_bug!(tcx.def_span(unique_did), "expected Box to contain Unique") span_bug!(tcx.def_span(unique_did), "expected Box to contain Unique")
}; };
@ -132,9 +133,8 @@ impl<'tcx> crate::MirPass<'tcx> for ElaborateBoxDerefs {
let (unique_ty, nonnull_ty, ptr_ty) = let (unique_ty, nonnull_ty, ptr_ty) =
build_ptr_tys(tcx, boxed_ty, unique_did, nonnull_did); build_ptr_tys(tcx, boxed_ty, unique_did, nonnull_did);
new_projections.extend_from_slice(&build_projection( new_projections
unique_ty, nonnull_ty, ptr_ty, .extend_from_slice(&build_projection(unique_ty, nonnull_ty, ptr_ty));
));
new_projections.push(PlaceElem::Deref); new_projections.push(PlaceElem::Deref);
} else if let Some(new_projections) = new_projections.as_mut() { } else if let Some(new_projections) = new_projections.as_mut() {
// Keep building up our projections list once we've started it. // Keep building up our projections list once we've started it.
@ -148,8 +148,5 @@ impl<'tcx> crate::MirPass<'tcx> for ElaborateBoxDerefs {
} }
} }
} }
} else {
// box is not present, this pass doesn't need to do anything
}
} }
} }