1
Fork 0

Stop doing weird index stuff in ElaborateBoxDerefs

This commit is contained in:
Michael Goulet 2024-08-02 17:28:05 -04:00
parent f82eb4d0a0
commit 2e52d61807
4 changed files with 77 additions and 8 deletions

View file

@ -116,29 +116,30 @@ impl<'tcx> MirPass<'tcx> for ElaborateBoxDerefs {
for debug_info in body.var_debug_info.iter_mut() {
if let VarDebugInfoContents::Place(place) = &mut debug_info.value {
let mut new_projections: Option<Vec<_>> = None;
let mut last_deref = 0;
for (i, (base, elem)) in place.iter_projections().enumerate() {
for (base, elem) in place.iter_projections() {
let base_ty = base.ty(&body.local_decls, tcx).ty;
if elem == PlaceElem::Deref && base_ty.is_box() {
let new_projections = new_projections.get_or_insert_default();
// Clone the projections before us, since now we need to mutate them.
let new_projections =
new_projections.get_or_insert_with(|| base.projection.to_vec());
let (unique_ty, nonnull_ty, ptr_ty) =
build_ptr_tys(tcx, base_ty.boxed_ty(), unique_did, nonnull_did);
new_projections.extend_from_slice(&base.projection[last_deref..]);
new_projections.extend_from_slice(&build_projection(
unique_ty, nonnull_ty, ptr_ty,
));
new_projections.push(PlaceElem::Deref);
last_deref = i;
} else if let Some(new_projections) = new_projections.as_mut() {
// Keep building up our projections list once we've started it.
new_projections.push(elem);
}
}
if let Some(mut new_projections) = new_projections {
new_projections.extend_from_slice(&place.projection[last_deref..]);
// Store the mutated projections if we actually changed something.
if let Some(new_projections) = new_projections {
place.projection = tcx.mk_place_elems(&new_projections);
}
}