Skip to content

Commit 4a742a6

Browse files
committed
Revert "Rollup merge of rust-lang#98582 - oli-obk:unconstrained_opaque_type, r=estebank"
This reverts commit 6f8fb91, reversing changes made to 7210e46.
1 parent 03d488b commit 4a742a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+205
-396
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2155,9 +2155,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21552155
}
21562156
StorageDeadOrDrop::Destructor(_) => kind,
21572157
},
2158-
ProjectionElem::OpaqueCast { .. }
2159-
| ProjectionElem::Field(..)
2160-
| ProjectionElem::Downcast(..) => {
2158+
ProjectionElem::Field(..) | ProjectionElem::Downcast(..) => {
21612159
match place_ty.ty.kind() {
21622160
ty::Adt(def, _) if def.has_dtor(tcx) => {
21632161
// Report the outermost adt with a destructor

compiler/rustc_borrowck/src/diagnostics/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
226226
}
227227
ProjectionElem::Downcast(..) if including_downcast.0 => return None,
228228
ProjectionElem::Downcast(..) => (),
229-
ProjectionElem::OpaqueCast(..) => (),
230229
ProjectionElem::Field(field, _ty) => {
231230
// FIXME(project-rfc_2229#36): print capture precisely here.
232231
if let Some(field) = self.is_upvar_field_projection(PlaceRef {
@@ -287,7 +286,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
287286
PlaceRef { local, projection: proj_base }.ty(self.body, self.infcx.tcx)
288287
}
289288
ProjectionElem::Downcast(..) => place.ty(self.body, self.infcx.tcx),
290-
ProjectionElem::OpaqueCast(ty) => PlaceTy::from_ty(*ty),
291289
ProjectionElem::Field(_, field_type) => PlaceTy::from_ty(*field_type),
292290
},
293291
};

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
169169
..,
170170
ProjectionElem::Index(_)
171171
| ProjectionElem::ConstantIndex { .. }
172-
| ProjectionElem::OpaqueCast { .. }
173172
| ProjectionElem::Subslice { .. }
174173
| ProjectionElem::Downcast(..),
175174
],

compiler/rustc_borrowck/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17881788
for (place_base, elem) in place.iter_projections().rev() {
17891789
match elem {
17901790
ProjectionElem::Index(_/*operand*/) |
1791-
ProjectionElem::OpaqueCast(_) |
17921791
ProjectionElem::ConstantIndex { .. } |
17931792
// assigning to P[i] requires P to be valid.
17941793
ProjectionElem::Downcast(_/*adt_def*/, _/*variant_idx*/) =>
@@ -2180,7 +2179,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21802179
| ProjectionElem::Index(..)
21812180
| ProjectionElem::ConstantIndex { .. }
21822181
| ProjectionElem::Subslice { .. }
2183-
| ProjectionElem::OpaqueCast { .. }
21842182
| ProjectionElem::Downcast(..) => {
21852183
let upvar_field_projection = self.is_upvar_field_projection(place);
21862184
if let Some(field) = upvar_field_projection {

compiler/rustc_borrowck/src/places_conflict.rs

-13
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ fn place_components_conflict<'tcx>(
255255
| (ProjectionElem::Index { .. }, _, _)
256256
| (ProjectionElem::ConstantIndex { .. }, _, _)
257257
| (ProjectionElem::Subslice { .. }, _, _)
258-
| (ProjectionElem::OpaqueCast { .. }, _, _)
259258
| (ProjectionElem::Downcast { .. }, _, _) => {
260259
// Recursive case. This can still be disjoint on a
261260
// further iteration if this a shallow access and
@@ -323,17 +322,6 @@ fn place_projection_conflict<'tcx>(
323322
debug!("place_element_conflict: DISJOINT-OR-EQ-DEREF");
324323
Overlap::EqualOrDisjoint
325324
}
326-
(ProjectionElem::OpaqueCast(v1), ProjectionElem::OpaqueCast(v2)) => {
327-
if v1 == v2 {
328-
// same type - recur.
329-
debug!("place_element_conflict: DISJOINT-OR-EQ-OPAQUE");
330-
Overlap::EqualOrDisjoint
331-
} else {
332-
// Different types. Disjoint!
333-
debug!("place_element_conflict: DISJOINT-OPAQUE");
334-
Overlap::Disjoint
335-
}
336-
}
337325
(ProjectionElem::Field(f1, _), ProjectionElem::Field(f2, _)) => {
338326
if f1 == f2 {
339327
// same field (e.g., `a.y` vs. `a.y`) - recur.
@@ -537,7 +525,6 @@ fn place_projection_conflict<'tcx>(
537525
| ProjectionElem::Field(..)
538526
| ProjectionElem::Index(..)
539527
| ProjectionElem::ConstantIndex { .. }
540-
| ProjectionElem::OpaqueCast { .. }
541528
| ProjectionElem::Subslice { .. }
542529
| ProjectionElem::Downcast(..),
543530
_,

compiler/rustc_borrowck/src/prefixes.rs

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
8181
}
8282
ProjectionElem::Downcast(..)
8383
| ProjectionElem::Subslice { .. }
84-
| ProjectionElem::OpaqueCast { .. }
8584
| ProjectionElem::ConstantIndex { .. }
8685
| ProjectionElem::Index(_) => {
8786
cursor = cursor_base;

compiler/rustc_borrowck/src/type_check/mod.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -790,19 +790,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
790790
}
791791
PlaceTy::from_ty(fty)
792792
}
793-
ProjectionElem::OpaqueCast(ty) => {
794-
let ty = self.sanitize_type(place, ty);
795-
let ty = self.cx.normalize(ty, location);
796-
self.cx
797-
.eq_types(
798-
base.ty,
799-
ty,
800-
location.to_locations(),
801-
ConstraintCategory::TypeAnnotation,
802-
)
803-
.unwrap();
804-
PlaceTy::from_ty(ty)
805-
}
806793
}
807794
}
808795

@@ -1208,11 +1195,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12081195
tcx,
12091196
self.param_env,
12101197
proj,
1211-
|this, field, _| {
1198+
|this, field, ()| {
12121199
let ty = this.field_ty(tcx, field);
12131200
self.normalize(ty, locations)
12141201
},
1215-
|_, _| unreachable!(),
12161202
);
12171203
curr_projected_ty = projected_ty;
12181204
}
@@ -2507,7 +2493,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25072493
}
25082494
ProjectionElem::Field(..)
25092495
| ProjectionElem::Downcast(..)
2510-
| ProjectionElem::OpaqueCast(..)
25112496
| ProjectionElem::Index(..)
25122497
| ProjectionElem::ConstantIndex { .. }
25132498
| ProjectionElem::Subslice { .. } => {

compiler/rustc_codegen_cranelift/src/base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,6 @@ pub(crate) fn codegen_place<'tcx>(
825825
cplace = cplace.place_deref(fx);
826826
}
827827
}
828-
PlaceElem::OpaqueCast(ty) => cplace = cplace.place_opaque_cast(fx, ty),
829828
PlaceElem::Field(field, _ty) => {
830829
cplace = cplace.place_field(fx, field);
831830
}

compiler/rustc_codegen_cranelift/src/value_and_place.rs

-8
Original file line numberDiff line numberDiff line change
@@ -615,14 +615,6 @@ impl<'tcx> CPlace<'tcx> {
615615
}
616616
}
617617

618-
pub(crate) fn place_opaque_cast(
619-
self,
620-
fx: &mut FunctionCx<'_, '_, 'tcx>,
621-
ty: Ty<'tcx>,
622-
) -> CPlace<'tcx> {
623-
CPlace { inner: self.inner, layout: fx.layout_of(ty) }
624-
}
625-
626618
pub(crate) fn place_field(
627619
self,
628620
fx: &mut FunctionCx<'_, '_, 'tcx>,

compiler/rustc_codegen_ssa/src/mir/place.rs

-16
Original file line numberDiff line numberDiff line change
@@ -411,21 +411,6 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
411411
downcast
412412
}
413413

414-
pub fn project_type<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
415-
&self,
416-
bx: &mut Bx,
417-
ty: Ty<'tcx>,
418-
) -> Self {
419-
let mut downcast = *self;
420-
downcast.layout = bx.cx().layout_of(ty);
421-
422-
// Cast to the appropriate type.
423-
let variant_ty = bx.cx().backend_type(downcast.layout);
424-
downcast.llval = bx.pointercast(downcast.llval, bx.cx().type_ptr_to(variant_ty));
425-
426-
downcast
427-
}
428-
429414
pub fn storage_live<Bx: BuilderMethods<'a, 'tcx, Value = V>>(&self, bx: &mut Bx) {
430415
bx.lifetime_start(self.llval, self.layout.size);
431416
}
@@ -474,7 +459,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
474459
mir::ProjectionElem::Field(ref field, _) => {
475460
cg_base.project_field(bx, field.index())
476461
}
477-
mir::ProjectionElem::OpaqueCast(ty) => cg_base.project_type(bx, ty),
478462
mir::ProjectionElem::Index(index) => {
479463
let index = &mir::Operand::Copy(mir::Place::from(index));
480464
let index = self.codegen_operand(bx, index);

compiler/rustc_const_eval/src/interpret/projection.rs

-10
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,6 @@ where
349349
) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> {
350350
use rustc_middle::mir::ProjectionElem::*;
351351
Ok(match proj_elem {
352-
OpaqueCast(ty) => {
353-
let mut place = base.clone();
354-
place.layout = self.layout_of(ty)?;
355-
place
356-
}
357352
Field(field, _) => self.place_field(base, field.index())?,
358353
Downcast(_, variant) => self.place_downcast(base, variant)?,
359354
Deref => self.deref_operand(&self.place_to_op(base)?)?.into(),
@@ -378,11 +373,6 @@ where
378373
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
379374
use rustc_middle::mir::ProjectionElem::*;
380375
Ok(match proj_elem {
381-
OpaqueCast(ty) => {
382-
let mut op = base.clone();
383-
op.layout = self.layout_of(ty)?;
384-
op
385-
}
386376
Field(field, _) => self.operand_field(base, field.index())?,
387377
Downcast(_, variant) => self.operand_downcast(base, variant)?,
388378
Deref => self.deref_operand(base)?.into(),

compiler/rustc_const_eval/src/transform/check_consts/check.rs

-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
652652

653653
ProjectionElem::ConstantIndex { .. }
654654
| ProjectionElem::Downcast(..)
655-
| ProjectionElem::OpaqueCast(..)
656655
| ProjectionElem::Subslice { .. }
657656
| ProjectionElem::Field(..)
658657
| ProjectionElem::Index(_) => {}

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ where
316316

317317
ProjectionElem::Deref
318318
| ProjectionElem::Field(_, _)
319-
| ProjectionElem::OpaqueCast(_)
320319
| ProjectionElem::ConstantIndex { .. }
321320
| ProjectionElem::Subslice { .. }
322321
| ProjectionElem::Downcast(_, _)

compiler/rustc_const_eval/src/transform/promote_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<'tcx> Validator<'_, 'tcx> {
361361
return Err(Unpromotable);
362362
}
363363
}
364-
ProjectionElem::OpaqueCast(..) | ProjectionElem::Downcast(..) => {
364+
ProjectionElem::Downcast(..) => {
365365
return Err(Unpromotable);
366366
}
367367

compiler/rustc_middle/src/mir/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,6 @@ impl<V, T> ProjectionElem<V, T> {
13971397

13981398
Self::Field(_, _)
13991399
| Self::Index(_)
1400-
| Self::OpaqueCast(_)
14011400
| Self::ConstantIndex { .. }
14021401
| Self::Subslice { .. }
14031402
| Self::Downcast(_, _) => false,
@@ -1575,9 +1574,7 @@ impl Debug for Place<'_> {
15751574
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
15761575
for elem in self.projection.iter().rev() {
15771576
match elem {
1578-
ProjectionElem::OpaqueCast(_)
1579-
| ProjectionElem::Downcast(_, _)
1580-
| ProjectionElem::Field(_, _) => {
1577+
ProjectionElem::Downcast(_, _) | ProjectionElem::Field(_, _) => {
15811578
write!(fmt, "(").unwrap();
15821579
}
15831580
ProjectionElem::Deref => {
@@ -1593,9 +1590,6 @@ impl Debug for Place<'_> {
15931590

15941591
for elem in self.projection.iter() {
15951592
match elem {
1596-
ProjectionElem::OpaqueCast(ty) => {
1597-
write!(fmt, " as {})", ty)?;
1598-
}
15991593
ProjectionElem::Downcast(Some(name), _index) => {
16001594
write!(fmt, " as {})", name)?;
16011595
}

compiler/rustc_middle/src/mir/syntax.rs

-7
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,6 @@ pub type AssertMessage<'tcx> = AssertKind<Operand<'tcx>>;
754754
/// generator has more than one variant, the parent place's variant index must be set, indicating
755755
/// which variant is being used. If it has just one variant, the variant index may or may not be
756756
/// included - the single possible variant is inferred if it is not included.
757-
/// - [`OpaqueCast`](ProjectionElem::OpaqueCast): This projection changes the place's type to the
758-
/// given one, and makes no other changes. A `OpaqueCast` projection on any type other than an
759-
/// opaque type from the current crate is not well-formed.
760757
/// - [`ConstantIndex`](ProjectionElem::ConstantIndex): Computes an offset in units of `T` into the
761758
/// place as described in the documentation for the `ProjectionElem`. The resulting address is
762759
/// the parent's address plus that offset, and the type is `T`. This is only legal if the parent
@@ -859,10 +856,6 @@ pub enum ProjectionElem<V, T> {
859856
///
860857
/// The included Symbol is the name of the variant, used for printing MIR.
861858
Downcast(Option<Symbol>, VariantIdx),
862-
863-
/// Like an explicit cast from an opaque type to a concrete type, but without
864-
/// requiring an intermediate variable.
865-
OpaqueCast(T),
866859
}
867860

868861
/// Alias for projections as they appear in places, where the base is a place

compiler/rustc_middle/src/mir/tcx.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> PlaceTy<'tcx> {
5757
/// `PlaceElem`, where we can just use the `Ty` that is already
5858
/// stored inline on field projection elems.
5959
pub fn projection_ty(self, tcx: TyCtxt<'tcx>, elem: PlaceElem<'tcx>) -> PlaceTy<'tcx> {
60-
self.projection_ty_core(tcx, ty::ParamEnv::empty(), &elem, |_, _, ty| ty, |_, ty| ty)
60+
self.projection_ty_core(tcx, ty::ParamEnv::empty(), &elem, |_, _, ty| ty)
6161
}
6262

6363
/// `place_ty.projection_ty_core(tcx, elem, |...| { ... })`
@@ -71,7 +71,6 @@ impl<'tcx> PlaceTy<'tcx> {
7171
param_env: ty::ParamEnv<'tcx>,
7272
elem: &ProjectionElem<V, T>,
7373
mut handle_field: impl FnMut(&Self, Field, T) -> Ty<'tcx>,
74-
mut handle_opaque_cast: impl FnMut(&Self, T) -> Ty<'tcx>,
7574
) -> PlaceTy<'tcx>
7675
where
7776
V: ::std::fmt::Debug,
@@ -110,7 +109,6 @@ impl<'tcx> PlaceTy<'tcx> {
110109
PlaceTy { ty: self.ty, variant_index: Some(index) }
111110
}
112111
ProjectionElem::Field(f, fty) => PlaceTy::from_ty(handle_field(&self, f, fty)),
113-
ProjectionElem::OpaqueCast(ty) => PlaceTy::from_ty(handle_opaque_cast(&self, ty)),
114112
};
115113
debug!("projection_ty self: {:?} elem: {:?} yields: {:?}", self, elem, answer);
116114
answer

compiler/rustc_middle/src/mir/type_foldable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> {
182182
Ok(match self {
183183
Deref => Deref,
184184
Field(f, ty) => Field(f, ty.try_fold_with(folder)?),
185-
OpaqueCast(ty) => OpaqueCast(ty.try_fold_with(folder)?),
186185
Index(v) => Index(v.try_fold_with(folder)?),
187186
Downcast(symbol, variantidx) => Downcast(symbol, variantidx),
188187
ConstantIndex { offset, min_length, from_end } => {

compiler/rustc_middle/src/mir/visit.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1064,11 +1064,6 @@ macro_rules! visit_place_fns {
10641064
self.visit_ty(&mut new_ty, TyContext::Location(location));
10651065
if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
10661066
}
1067-
PlaceElem::OpaqueCast(ty) => {
1068-
let mut new_ty = ty;
1069-
self.visit_ty(&mut new_ty, TyContext::Location(location));
1070-
if ty != new_ty { Some(PlaceElem::OpaqueCast(new_ty)) } else { None }
1071-
}
10721067
PlaceElem::Deref
10731068
| PlaceElem::ConstantIndex { .. }
10741069
| PlaceElem::Subslice { .. }
@@ -1138,7 +1133,7 @@ macro_rules! visit_place_fns {
11381133
location: Location,
11391134
) {
11401135
match elem {
1141-
ProjectionElem::OpaqueCast(ty) | ProjectionElem::Field(_, ty) => {
1136+
ProjectionElem::Field(_field, ty) => {
11421137
self.visit_ty(ty, TyContext::Location(location));
11431138
}
11441139
ProjectionElem::Index(local) => {

0 commit comments

Comments
 (0)