Skip to content

Commit cc00f45

Browse files
committed
Auto merge of #147055 - beepster4096:subtype_is_not_a_projection, r=lcnr
Turn ProjectionElem::Subtype into CastKind::Subtype I noticed that drop elaboration can't, in general, handle `ProjectionElem::SubType`. It creates a disjoint move path that overlaps with other move paths. (`Subslice` does too, and I'm working on a different PR to make that special case less fragile.) If its skipped and treated as the same move path as its parent then `MovePath.place` has multiple possible projections. (It would probably make sense to remove all `Subtype` projections for the canonical place but it doesn't make sense to have this special case for a problem that doesn't actually occur in real MIR.) The only reason this doesn't break is that `Subtype` is always the sole projection of the local its applied to. For the same reason, it works fine as a `CastKind` so I figured that makes more sense than documenting and validating this hidden invariant. cc rust-lang/rust#112651, rust-lang/rust#133258 r? Icnr (bc you've been the main person dealing with `Subtype` it looks like)
2 parents 46ce2bf + a7454d1 commit cc00f45

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
789789
let operand = codegen_operand(fx, operand);
790790
crate::unsize::coerce_unsized_into(fx, operand, lval);
791791
}
792-
Rvalue::Cast(CastKind::Transmute, ref operand, _to_ty) => {
792+
Rvalue::Cast(CastKind::Transmute | CastKind::Subtype, ref operand, _to_ty) => {
793793
let operand = codegen_operand(fx, operand);
794794
lval.write_cvalue_transmute(fx, operand);
795795
}
@@ -996,7 +996,7 @@ pub(crate) fn codegen_place<'tcx>(
996996
cplace = cplace.place_deref(fx);
997997
}
998998
PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"),
999-
PlaceElem::Subtype(ty) | PlaceElem::UnwrapUnsafeBinder(ty) => {
999+
PlaceElem::UnwrapUnsafeBinder(ty) => {
10001000
cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty));
10011001
}
10021002
PlaceElem::Field(field, _ty) => {

src/value_and_place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ impl<'tcx> CPlace<'tcx> {
660660
}
661661
}
662662

663-
/// Used for `ProjectionElem::Subtype`, `ty` has to be monomorphized before
663+
/// Used for `ProjectionElem::UnwrapUnsafeBinder`, `ty` has to be monomorphized before
664664
/// passed on.
665665
pub(crate) fn place_transmute_type(
666666
self,

0 commit comments

Comments
 (0)