Transmute from NonNull to pointer when elaborating a box deref (MCP807)
This commit is contained in:
parent
fd98df8f14
commit
ad5f912d96
12 changed files with 29 additions and 28 deletions
|
@ -29,13 +29,8 @@ fn build_ptr_tys<'tcx>(
|
|||
pub(super) fn build_projection<'tcx>(
|
||||
unique_ty: Ty<'tcx>,
|
||||
nonnull_ty: Ty<'tcx>,
|
||||
ptr_ty: Ty<'tcx>,
|
||||
) -> [PlaceElem<'tcx>; 3] {
|
||||
[
|
||||
PlaceElem::Field(FieldIdx::ZERO, unique_ty),
|
||||
PlaceElem::Field(FieldIdx::ZERO, nonnull_ty),
|
||||
PlaceElem::Field(FieldIdx::ZERO, ptr_ty),
|
||||
]
|
||||
) -> [PlaceElem<'tcx>; 2] {
|
||||
[PlaceElem::Field(FieldIdx::ZERO, unique_ty), PlaceElem::Field(FieldIdx::ZERO, nonnull_ty)]
|
||||
}
|
||||
|
||||
struct ElaborateBoxDerefVisitor<'a, 'tcx> {
|
||||
|
@ -75,10 +70,14 @@ impl<'a, 'tcx> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'a, 'tcx> {
|
|||
self.patch.add_assign(
|
||||
location,
|
||||
Place::from(ptr_local),
|
||||
Rvalue::Use(Operand::Copy(
|
||||
Place::from(place.local)
|
||||
.project_deeper(&build_projection(unique_ty, nonnull_ty, ptr_ty), tcx),
|
||||
)),
|
||||
Rvalue::Cast(
|
||||
CastKind::Transmute,
|
||||
Operand::Copy(
|
||||
Place::from(place.local)
|
||||
.project_deeper(&build_projection(unique_ty, nonnull_ty), tcx),
|
||||
),
|
||||
ptr_ty,
|
||||
),
|
||||
);
|
||||
|
||||
place.local = ptr_local;
|
||||
|
@ -133,8 +132,10 @@ impl<'tcx> crate::MirPass<'tcx> for ElaborateBoxDerefs {
|
|||
let (unique_ty, nonnull_ty, ptr_ty) =
|
||||
build_ptr_tys(tcx, boxed_ty, unique_did, nonnull_did);
|
||||
|
||||
new_projections
|
||||
.extend_from_slice(&build_projection(unique_ty, nonnull_ty, ptr_ty));
|
||||
new_projections.extend_from_slice(&build_projection(unique_ty, nonnull_ty));
|
||||
// While we can't project into `NonNull<_>` in a basic block
|
||||
// due to MCP#807, this is debug info where it's fine.
|
||||
new_projections.push(PlaceElem::Field(FieldIdx::ZERO, ptr_ty));
|
||||
new_projections.push(PlaceElem::Deref);
|
||||
} else if let Some(new_projections) = new_projections.as_mut() {
|
||||
// Keep building up our projections list once we've started it.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue