Skip to content

Commit

Permalink
fix box derefs in var debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
beepster4096 committed Jun 16, 2022
1 parent 6003c25 commit 28ff0df
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions compiler/rustc_mir_transform/src/elaborate_box_derefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,37 @@ impl<'tcx> MirPass<'tcx> for ElaborateBoxDerefs {
}

visitor.patch.apply(body);

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() {
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();

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;
}
}

if let Some(mut new_projections) = new_projections {
new_projections.extend_from_slice(&place.projection[last_deref..]);
place.projection = tcx.intern_place_elems(&new_projections);
}
}
}
} else {
// box is not present, this pass doesn't need to do anything
}
Expand Down

0 comments on commit 28ff0df

Please sign in to comment.