about summary refs log tree commit diff
path: root/compiler/rustc_middle
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-12-19 22:37:12 +0000
committerbors <bors@rust-lang.org>2022-12-19 22:37:12 +0000
commit696563efc5c3c0d87a601dff22966d2c5eb20a5e (patch)
tree4ea1804b177b7c0d04af15a36bd716316583dc94 /compiler/rustc_middle
parent935dc07218b4bf6e20231e44eb9263b612fd649b (diff)
parent5457db94108b3c3ca75e1875b7e60bc4ea6b4b66 (diff)
Auto merge of #105905 - lqd:revert-103880, r=jackh726
Revert #103880 "Use non-ascribed type as field's type in mir"

This PR prepares a revert for #103880 to fix #105809, #105881, #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 #105809. There is no MCVE for the #105881 and #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 #96514 as it was fixed by the original PR.

Opening as draft to allow time for a possible fix.

r? `@jackh726`
Diffstat (limited to 'compiler/rustc_middle')
-rw-r--r--compiler/rustc_middle/src/mir/mod.rs4
-rw-r--r--compiler/rustc_middle/src/mir/syntax.rs39
-rw-r--r--compiler/rustc_middle/src/mir/tcx.rs15
3 files changed, 13 insertions, 45 deletions
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs
index e909b2f74aa..bdaa586c698 100644
--- a/compiler/rustc_middle/src/mir/mod.rs
+++ b/compiler/rustc_middle/src/mir/mod.rs
@@ -1488,7 +1488,7 @@ impl<'tcx> StatementKind<'tcx> {
 ///////////////////////////////////////////////////////////////////////////
 // Places
 
-impl<V, T, U> ProjectionElem<V, T, U> {
+impl<V, T> ProjectionElem<V, T> {
     /// Returns `true` if the target of this projection may refer to a different region of memory
     /// than the base.
     fn is_indirect(&self) -> bool {
@@ -1517,7 +1517,7 @@ impl<V, T, U> ProjectionElem<V, T, U> {
 
 /// Alias for projections as they appear in `UserTypeProjection`, where we
 /// need neither the `V` parameter for `Index` nor the `T` for `Field`.
-pub type ProjectionKind = ProjectionElem<(), (), ()>;
+pub type ProjectionKind = ProjectionElem<(), ()>;
 
 rustc_index::newtype_index! {
     /// A [newtype'd][wrapper] index type in the MIR [control-flow graph][CFG]
diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs
index a6ca04f5e62..99e59c770d7 100644
--- a/compiler/rustc_middle/src/mir/syntax.rs
+++ b/compiler/rustc_middle/src/mir/syntax.rs
@@ -890,18 +890,11 @@ pub struct Place<'tcx> {
     pub projection: &'tcx List<PlaceElem<'tcx>>,
 }
 
-/// The different kinds of projections that can be used in the projection of a `Place`.
-///
-/// `T1` is the generic type for a field projection. For an actual projection on a `Place`
-/// this parameter will always be `Ty`, but the field type can be unavailable when
-/// building (by using `PlaceBuilder`) places that correspond to upvars.
-/// `T2` is the generic type for an `OpaqueCast` (is generic since it's abstracted over
-/// in dataflow analysis, see `AbstractElem`).
 #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
 #[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
-pub enum ProjectionElem<V, T1, T2> {
+pub enum ProjectionElem<V, T> {
     Deref,
-    Field(Field, T1),
+    Field(Field, T),
     /// Index into a slice/array.
     ///
     /// 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> {
 
     /// Like an explicit cast from an opaque type to a concrete type, but without
     /// requiring an intermediate variable.
-    OpaqueCast(T2),
+    OpaqueCast(T),
 }
 
 /// Alias for projections as they appear in places, where the base is a place
 /// and the index is a local.
-pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>, Ty<'tcx>>;
-
-/// Alias for projections that appear in `PlaceBuilder::Upvar`, for which
-/// we cannot provide any field types.
-pub type UpvarProjectionElem<'tcx> = ProjectionElem<Local, (), Ty<'tcx>>;
-
-impl<'tcx> From<PlaceElem<'tcx>> for UpvarProjectionElem<'tcx> {
-    fn from(elem: PlaceElem<'tcx>) -> Self {
-        match elem {
-            ProjectionElem::Deref => ProjectionElem::Deref,
-            ProjectionElem::Field(field, _) => ProjectionElem::Field(field, ()),
-            ProjectionElem::Index(v) => ProjectionElem::Index(v),
-            ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
-                ProjectionElem::ConstantIndex { offset, min_length, from_end }
-            }
-            ProjectionElem::Subslice { from, to, from_end } => {
-                ProjectionElem::Subslice { from, to, from_end }
-            }
-            ProjectionElem::Downcast(opt_sym, variant_idx) => {
-                ProjectionElem::Downcast(opt_sym, variant_idx)
-            }
-            ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty),
-        }
-    }
-}
+pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>;
 
 ///////////////////////////////////////////////////////////////////////////
 // Operands
diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs
index 1e289fc4abe..8d2a8f33d6a 100644
--- a/compiler/rustc_middle/src/mir/tcx.rs
+++ b/compiler/rustc_middle/src/mir/tcx.rs
@@ -28,8 +28,8 @@ impl<'tcx> PlaceTy<'tcx> {
     /// `place_ty.field_ty(tcx, f)` computes the type at a given field
     /// of a record or enum-variant. (Most clients of `PlaceTy` can
     /// instead just extract the relevant type directly from their
-    /// `PlaceElem`, but some instances of `ProjectionElem<V, T1, T2>` do
-    /// not carry a `Ty` for `T1` or `T2`.)
+    /// `PlaceElem`, but some instances of `ProjectionElem<V, T>` do
+    /// not carry a `Ty` for `T`.)
     ///
     /// Note that the resulting type has not been normalized.
     pub fn field_ty(self, tcx: TyCtxt<'tcx>, f: Field) -> Ty<'tcx> {
@@ -64,18 +64,17 @@ impl<'tcx> PlaceTy<'tcx> {
     /// `Ty` or downcast variant corresponding to that projection.
     /// The `handle_field` callback must map a `Field` to its `Ty`,
     /// (which should be trivial when `T` = `Ty`).
-    pub fn projection_ty_core<V, T1, T2>(
+    pub fn projection_ty_core<V, T>(
         self,
         tcx: TyCtxt<'tcx>,
         param_env: ty::ParamEnv<'tcx>,
-        elem: &ProjectionElem<V, T1, T2>,
-        mut handle_field: impl FnMut(&Self, Field, T1) -> Ty<'tcx>,
-        mut handle_opaque_cast: impl FnMut(&Self, T2) -> Ty<'tcx>,
+        elem: &ProjectionElem<V, T>,
+        mut handle_field: impl FnMut(&Self, Field, T) -> Ty<'tcx>,
+        mut handle_opaque_cast: impl FnMut(&Self, T) -> Ty<'tcx>,
     ) -> PlaceTy<'tcx>
     where
         V: ::std::fmt::Debug,
-        T1: ::std::fmt::Debug + Copy,
-        T2: ::std::fmt::Debug + Copy,
+        T: ::std::fmt::Debug + Copy,
     {
         if self.variant_index.is_some() && !matches!(elem, ProjectionElem::Field(..)) {
             bug!("cannot use non field projection on downcasted place")