Skip to content

Commit faafb73

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 306f43a + a513981 commit faafb73

File tree

4 files changed

+3
-15
lines changed

4 files changed

+3
-15
lines changed

rustc_public/src/mir/body.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -836,14 +836,6 @@ pub enum ProjectionElem {
836836
/// Like an explicit cast from an opaque type to a concrete type, but without
837837
/// requiring an intermediate variable.
838838
OpaqueCast(Ty),
839-
840-
/// A `Subtype(T)` projection is applied to any `StatementKind::Assign` where
841-
/// type of lvalue doesn't match the type of rvalue, the primary goal is making subtyping
842-
/// explicit during optimizations and codegen.
843-
///
844-
/// This projection doesn't impact the runtime behavior of the program except for potentially changing
845-
/// some type metadata of the interpreter or codegen backend.
846-
Subtype(Ty),
847839
}
848840

849841
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
@@ -1028,6 +1020,7 @@ pub enum CastKind {
10281020
PtrToPtr,
10291021
FnPtrToPtr,
10301022
Transmute,
1023+
Subtype,
10311024
}
10321025

10331026
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
@@ -1089,7 +1082,7 @@ impl ProjectionElem {
10891082
Self::subslice_ty(ty, *from, *to, *from_end)
10901083
}
10911084
ProjectionElem::Downcast(_) => Ok(ty),
1092-
ProjectionElem::OpaqueCast(ty) | ProjectionElem::Subtype(ty) => Ok(*ty),
1085+
ProjectionElem::OpaqueCast(ty) => Ok(*ty),
10931086
}
10941087
}
10951088

rustc_public/src/mir/visit.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ macro_rules! visit_place_fns {
471471
ProjectionElem::Subslice { from: _, to: _, from_end: _ } => {}
472472
ProjectionElem::Downcast(_idx) => {}
473473
ProjectionElem::OpaqueCast(ty) => self.visit_ty(ty, location),
474-
ProjectionElem::Subtype(ty) => self.visit_ty(ty, location),
475474
}
476475
}
477476
};
@@ -512,7 +511,6 @@ macro_rules! visit_place_fns {
512511
ProjectionElem::Subslice { from: _, to: _, from_end: _ } => {}
513512
ProjectionElem::Downcast(_idx) => {}
514513
ProjectionElem::OpaqueCast(ty) => self.visit_ty(ty, location),
515-
ProjectionElem::Subtype(ty) => self.visit_ty(ty, location),
516514
}
517515
}
518516
};

rustc_public/src/unstable/convert/internal.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,6 @@ impl RustcInternal for ProjectionElem {
703703
ProjectionElem::OpaqueCast(ty) => {
704704
rustc_middle::mir::PlaceElem::OpaqueCast(ty.internal(tables, tcx))
705705
}
706-
ProjectionElem::Subtype(ty) => {
707-
rustc_middle::mir::PlaceElem::Subtype(ty.internal(tables, tcx))
708-
}
709706
}
710707
}
711708
}

rustc_public/src/unstable/convert/stable/mir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ impl<'tcx> Stable<'tcx> for mir::CastKind {
356356
PtrToPtr => crate::mir::CastKind::PtrToPtr,
357357
FnPtrToPtr => crate::mir::CastKind::FnPtrToPtr,
358358
Transmute => crate::mir::CastKind::Transmute,
359+
Subtype => crate::mir::CastKind::Subtype,
359360
}
360361
}
361362
}
@@ -453,7 +454,6 @@ impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> {
453454
// found at https://github.com/rust-lang/rust/pull/117517#issuecomment-1811683486
454455
Downcast(_, idx) => crate::mir::ProjectionElem::Downcast(idx.stable(tables, cx)),
455456
OpaqueCast(ty) => crate::mir::ProjectionElem::OpaqueCast(ty.stable(tables, cx)),
456-
Subtype(ty) => crate::mir::ProjectionElem::Subtype(ty.stable(tables, cx)),
457457
UnwrapUnsafeBinder(..) => todo!("FIXME(unsafe_binders):"),
458458
}
459459
}

0 commit comments

Comments
 (0)