Skip to content

Commit 673f447

Browse files
committed
Auto merge of #115025 - ouz-a:ouz_testing, r=lcnr
Make subtyping explicit in MIR This adds new mir-opt that pushes new `ProjectionElem` called `ProjectionElem::Subtype(T)` to `Rvalue` of a subtyped assignment so we can unsoundness issues like #107205 Addresses #112651 r? `@lcnr`
2 parents f04620a + 27f88ee commit 673f447

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Diff for: src/base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ pub(crate) fn codegen_place<'tcx>(
876876
cplace = cplace.place_deref(fx);
877877
}
878878
PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"),
879+
PlaceElem::Subtype(ty) => cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty)),
879880
PlaceElem::Field(field, _ty) => {
880881
cplace = cplace.place_field(fx, field);
881882
}

Diff for: src/value_and_place.rs

+10
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,16 @@ impl<'tcx> CPlace<'tcx> {
674674
}
675675
}
676676

677+
/// Used for `ProjectionElem::Subtype`, `ty` has to be monomorphized before
678+
/// passed on.
679+
pub(crate) fn place_transmute_type(
680+
self,
681+
fx: &mut FunctionCx<'_, '_, 'tcx>,
682+
ty: Ty<'tcx>,
683+
) -> CPlace<'tcx> {
684+
CPlace { inner: self.inner, layout: fx.layout_of(ty) }
685+
}
686+
677687
pub(crate) fn place_field(
678688
self,
679689
fx: &mut FunctionCx<'_, '_, 'tcx>,

0 commit comments

Comments
 (0)