Skip to content

Commit 696563e

Browse files
committed
Auto merge of rust-lang#105905 - lqd:revert-103880, r=jackh726
Revert rust-lang#103880 "Use non-ascribed type as field's type in mir" This PR prepares a revert for rust-lang#103880 to fix rust-lang#105809, rust-lang#105881, rust-lang#105886 and others (like the duplicates of the first one), in case an actual fix can't get done today. I've also added the MCVE from rust-lang#105809. There is no MCVE for the rust-lang#105881 and rust-lang#105886 ICEs yet however, so there are no tests for them here, although we'll need one before relanding the original changes. Were this PR to land, it would also reopen rust-lang#96514 as it was fixed by the original PR. Opening as draft to allow time for a possible fix. r? `@jackh726`
2 parents 935dc07 + 5457db9 commit 696563e

File tree

15 files changed

+135
-433
lines changed

15 files changed

+135
-433
lines changed

compiler/rustc_middle/src/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ impl<'tcx> StatementKind<'tcx> {
14881488
///////////////////////////////////////////////////////////////////////////
14891489
// Places
14901490

1491-
impl<V, T, U> ProjectionElem<V, T, U> {
1491+
impl<V, T> ProjectionElem<V, T> {
14921492
/// Returns `true` if the target of this projection may refer to a different region of memory
14931493
/// than the base.
14941494
fn is_indirect(&self) -> bool {
@@ -1517,7 +1517,7 @@ impl<V, T, U> ProjectionElem<V, T, U> {
15171517

15181518
/// Alias for projections as they appear in `UserTypeProjection`, where we
15191519
/// need neither the `V` parameter for `Index` nor the `T` for `Field`.
1520-
pub type ProjectionKind = ProjectionElem<(), (), ()>;
1520+
pub type ProjectionKind = ProjectionElem<(), ()>;
15211521

15221522
rustc_index::newtype_index! {
15231523
/// A [newtype'd][wrapper] index type in the MIR [control-flow graph][CFG]

compiler/rustc_middle/src/mir/syntax.rs

+4-35
Original file line numberDiff line numberDiff line change
@@ -890,18 +890,11 @@ pub struct Place<'tcx> {
890890
pub projection: &'tcx List<PlaceElem<'tcx>>,
891891
}
892892

893-
/// The different kinds of projections that can be used in the projection of a `Place`.
894-
///
895-
/// `T1` is the generic type for a field projection. For an actual projection on a `Place`
896-
/// this parameter will always be `Ty`, but the field type can be unavailable when
897-
/// building (by using `PlaceBuilder`) places that correspond to upvars.
898-
/// `T2` is the generic type for an `OpaqueCast` (is generic since it's abstracted over
899-
/// in dataflow analysis, see `AbstractElem`).
900893
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
901894
#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
902-
pub enum ProjectionElem<V, T1, T2> {
895+
pub enum ProjectionElem<V, T> {
903896
Deref,
904-
Field(Field, T1),
897+
Field(Field, T),
905898
/// Index into a slice/array.
906899
///
907900
/// Note that this does not also dereference, and so it does not exactly correspond to slice
@@ -957,36 +950,12 @@ pub enum ProjectionElem<V, T1, T2> {
957950

958951
/// Like an explicit cast from an opaque type to a concrete type, but without
959952
/// requiring an intermediate variable.
960-
OpaqueCast(T2),
953+
OpaqueCast(T),
961954
}
962955

963956
/// Alias for projections as they appear in places, where the base is a place
964957
/// and the index is a local.
965-
pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>, Ty<'tcx>>;
966-
967-
/// Alias for projections that appear in `PlaceBuilder::Upvar`, for which
968-
/// we cannot provide any field types.
969-
pub type UpvarProjectionElem<'tcx> = ProjectionElem<Local, (), Ty<'tcx>>;
970-
971-
impl<'tcx> From<PlaceElem<'tcx>> for UpvarProjectionElem<'tcx> {
972-
fn from(elem: PlaceElem<'tcx>) -> Self {
973-
match elem {
974-
ProjectionElem::Deref => ProjectionElem::Deref,
975-
ProjectionElem::Field(field, _) => ProjectionElem::Field(field, ()),
976-
ProjectionElem::Index(v) => ProjectionElem::Index(v),
977-
ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
978-
ProjectionElem::ConstantIndex { offset, min_length, from_end }
979-
}
980-
ProjectionElem::Subslice { from, to, from_end } => {
981-
ProjectionElem::Subslice { from, to, from_end }
982-
}
983-
ProjectionElem::Downcast(opt_sym, variant_idx) => {
984-
ProjectionElem::Downcast(opt_sym, variant_idx)
985-
}
986-
ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty),
987-
}
988-
}
989-
}
958+
pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>;
990959

991960
///////////////////////////////////////////////////////////////////////////
992961
// Operands

compiler/rustc_middle/src/mir/tcx.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ impl<'tcx> PlaceTy<'tcx> {
2828
/// `place_ty.field_ty(tcx, f)` computes the type at a given field
2929
/// of a record or enum-variant. (Most clients of `PlaceTy` can
3030
/// instead just extract the relevant type directly from their
31-
/// `PlaceElem`, but some instances of `ProjectionElem<V, T1, T2>` do
32-
/// not carry a `Ty` for `T1` or `T2`.)
31+
/// `PlaceElem`, but some instances of `ProjectionElem<V, T>` do
32+
/// not carry a `Ty` for `T`.)
3333
///
3434
/// Note that the resulting type has not been normalized.
3535
pub fn field_ty(self, tcx: TyCtxt<'tcx>, f: Field) -> Ty<'tcx> {
@@ -64,18 +64,17 @@ impl<'tcx> PlaceTy<'tcx> {
6464
/// `Ty` or downcast variant corresponding to that projection.
6565
/// The `handle_field` callback must map a `Field` to its `Ty`,
6666
/// (which should be trivial when `T` = `Ty`).
67-
pub fn projection_ty_core<V, T1, T2>(
67+
pub fn projection_ty_core<V, T>(
6868
self,
6969
tcx: TyCtxt<'tcx>,
7070
param_env: ty::ParamEnv<'tcx>,
71-
elem: &ProjectionElem<V, T1, T2>,
72-
mut handle_field: impl FnMut(&Self, Field, T1) -> Ty<'tcx>,
73-
mut handle_opaque_cast: impl FnMut(&Self, T2) -> Ty<'tcx>,
71+
elem: &ProjectionElem<V, T>,
72+
mut handle_field: impl FnMut(&Self, Field, T) -> Ty<'tcx>,
73+
mut handle_opaque_cast: impl FnMut(&Self, T) -> Ty<'tcx>,
7474
) -> PlaceTy<'tcx>
7575
where
7676
V: ::std::fmt::Debug,
77-
T1: ::std::fmt::Debug + Copy,
78-
T2: ::std::fmt::Debug + Copy,
77+
T: ::std::fmt::Debug + Copy,
7978
{
8079
if self.variant_index.is_some() && !matches!(elem, ProjectionElem::Field(..)) {
8180
bug!("cannot use non field projection on downcasted place")

0 commit comments

Comments
 (0)