Skip to content

Commit de6d914

Browse files
committed
remove Subtype projections
1 parent 70e814b commit de6d914

File tree

33 files changed

+37
-229
lines changed

33 files changed

+37
-229
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3971,7 +3971,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
39713971
}
39723972
ProjectionElem::ConstantIndex { .. }
39733973
| ProjectionElem::Subslice { .. }
3974-
| ProjectionElem::Subtype(_)
39753974
| ProjectionElem::Index(_) => kind,
39763975
},
39773976
place_ty.projection_ty(tcx, elem),

compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
243243
ProjectionElem::Downcast(..) if opt.including_downcast => return None,
244244
ProjectionElem::Downcast(..) => (),
245245
ProjectionElem::OpaqueCast(..) => (),
246-
ProjectionElem::Subtype(..) => (),
247246
ProjectionElem::Field(field, _ty) => {
248247
// FIXME(project-rfc_2229#36): print capture precisely here.
249248
if let Some(field) = self.is_upvar_field_projection(PlaceRef {
@@ -324,9 +323,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
324323
PlaceRef { local, projection: proj_base }.ty(self.body, self.infcx.tcx)
325324
}
326325
ProjectionElem::Downcast(..) => place.ty(self.body, self.infcx.tcx),
327-
ProjectionElem::Subtype(ty) | ProjectionElem::OpaqueCast(ty) => {
328-
PlaceTy::from_ty(*ty)
329-
}
326+
ProjectionElem::OpaqueCast(ty) => PlaceTy::from_ty(*ty),
330327
ProjectionElem::Field(_, field_type) => PlaceTy::from_ty(*field_type),
331328
},
332329
};

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
164164
[
165165
..,
166166
ProjectionElem::Index(_)
167-
| ProjectionElem::Subtype(_)
168167
| ProjectionElem::ConstantIndex { .. }
169168
| ProjectionElem::OpaqueCast { .. }
170169
| ProjectionElem::Subslice { .. }

compiler/rustc_borrowck/src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1712,11 +1712,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
17121712
},
17131713
// `OpaqueCast`: only transmutes the type, so no moves there.
17141714
// `Downcast` : only changes information about a `Place` without moving.
1715-
// `Subtype` : only transmutes the type, so no moves.
17161715
// So it's safe to skip these.
1717-
ProjectionElem::OpaqueCast(_)
1718-
| ProjectionElem::Subtype(_)
1719-
| ProjectionElem::Downcast(_, _) => (),
1716+
ProjectionElem::OpaqueCast(_) | ProjectionElem::Downcast(_, _) => (),
17201717
}
17211718

17221719
place_ty = place_ty.projection_ty(tcx, elem);
@@ -1940,7 +1937,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
19401937
for (place_base, elem) in place.iter_projections().rev() {
19411938
match elem {
19421939
ProjectionElem::Index(_/*operand*/) |
1943-
ProjectionElem::Subtype(_) |
19441940
ProjectionElem::OpaqueCast(_) |
19451941
ProjectionElem::ConstantIndex { .. } |
19461942
// assigning to P[i] requires P to be valid.
@@ -2332,7 +2328,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
23322328
| ProjectionElem::Index(..)
23332329
| ProjectionElem::ConstantIndex { .. }
23342330
| ProjectionElem::Subslice { .. }
2335-
| ProjectionElem::Subtype(..)
23362331
| ProjectionElem::OpaqueCast { .. }
23372332
| ProjectionElem::Downcast(..) => {
23382333
let upvar_field_projection = self.is_upvar_field_projection(place);

compiler/rustc_borrowck/src/places_conflict.rs

-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ fn place_components_conflict<'tcx>(
249249
| (ProjectionElem::ConstantIndex { .. }, _, _)
250250
| (ProjectionElem::Subslice { .. }, _, _)
251251
| (ProjectionElem::OpaqueCast { .. }, _, _)
252-
| (ProjectionElem::Subtype(_), _, _)
253252
| (ProjectionElem::Downcast { .. }, _, _) => {
254253
// Recursive case. This can still be disjoint on a
255254
// further iteration if this a shallow access and
@@ -509,7 +508,6 @@ fn place_projection_conflict<'tcx>(
509508
| ProjectionElem::Field(..)
510509
| ProjectionElem::Index(..)
511510
| ProjectionElem::ConstantIndex { .. }
512-
| ProjectionElem::Subtype(_)
513511
| ProjectionElem::OpaqueCast { .. }
514512
| ProjectionElem::Subslice { .. }
515513
| ProjectionElem::Downcast(..),

compiler/rustc_borrowck/src/prefixes.rs

-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ impl<'tcx> Iterator for Prefixes<'tcx> {
7373
| ProjectionElem::Index(_) => {
7474
cursor = cursor_base;
7575
}
76-
ProjectionElem::Subtype(..) => {
77-
panic!("Subtype projection is not allowed before borrow check")
78-
}
7976
ProjectionElem::Deref => {
8077
match self.kind {
8178
PrefixSet::Shallow => {

compiler/rustc_borrowck/src/type_check/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
698698
}
699699
PlaceTy::from_ty(fty)
700700
}
701-
ProjectionElem::Subtype(_) => {
702-
bug!("ProjectionElem::Subtype shouldn't exist in borrowck")
703-
}
704701
ProjectionElem::OpaqueCast(ty) => {
705702
let ty = self.sanitize_type(place, ty);
706703
let ty = self.cx.normalize(ty, location);
@@ -2700,9 +2697,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
27002697
| ProjectionElem::Subslice { .. } => {
27012698
// other field access
27022699
}
2703-
ProjectionElem::Subtype(_) => {
2704-
bug!("ProjectionElem::Subtype shouldn't exist in borrowck")
2705-
}
27062700
}
27072701
}
27082702
}

compiler/rustc_codegen_cranelift/src/base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,6 @@ pub(crate) fn codegen_place<'tcx>(
981981
cplace = cplace.place_deref(fx);
982982
}
983983
PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"),
984-
PlaceElem::Subtype(ty) => cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty)),
985984
PlaceElem::Field(field, _ty) => {
986985
cplace = cplace.place_field(fx, field);
987986
}

compiler/rustc_codegen_cranelift/src/value_and_place.rs

-10
Original file line numberDiff line numberDiff line change
@@ -708,16 +708,6 @@ impl<'tcx> CPlace<'tcx> {
708708
}
709709
}
710710

711-
/// Used for `ProjectionElem::Subtype`, `ty` has to be monomorphized before
712-
/// passed on.
713-
pub(crate) fn place_transmute_type(
714-
self,
715-
fx: &mut FunctionCx<'_, '_, 'tcx>,
716-
ty: Ty<'tcx>,
717-
) -> CPlace<'tcx> {
718-
CPlace { inner: self.inner, layout: fx.layout_of(ty) }
719-
}
720-
721711
pub(crate) fn place_field(
722712
self,
723713
fx: &mut FunctionCx<'_, '_, 'tcx>,

compiler/rustc_codegen_ssa/src/mir/place.rs

-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
495495
mir::ProjectionElem::OpaqueCast(ty) => {
496496
bug!("encountered OpaqueCast({ty}) in codegen")
497497
}
498-
mir::ProjectionElem::Subtype(ty) => cg_base.project_type(bx, self.monomorphize(ty)),
499498
mir::ProjectionElem::Index(index) => {
500499
let index = &mir::Operand::Copy(mir::Place::from(index));
501500
let index = self.codegen_operand(bx, index);

compiler/rustc_const_eval/src/check_consts/qualifs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ where
290290
ProjectionElem::Index(index) if in_local(index) => return true,
291291

292292
ProjectionElem::Deref
293-
| ProjectionElem::Subtype(_)
294293
| ProjectionElem::Field(_, _)
295294
| ProjectionElem::OpaqueCast(_)
296295
| ProjectionElem::ConstantIndex { .. }

compiler/rustc_const_eval/src/interpret/eval_context.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::query::TyCtxtAt;
1212
use rustc_middle::ty::layout::{
1313
self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
1414
};
15-
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypingEnv, Variance};
15+
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypingEnv};
1616
use rustc_middle::{mir, span_bug};
1717
use rustc_session::Limit;
1818
use rustc_span::Span;
@@ -114,7 +114,6 @@ impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
114114
}
115115

116116
/// Test if it is valid for a MIR assignment to assign `src`-typed place to `dest`-typed value.
117-
/// This test should be symmetric, as it is primarily about layout compatibility.
118117
pub(super) fn mir_assign_valid_types<'tcx>(
119118
tcx: TyCtxt<'tcx>,
120119
typing_env: TypingEnv<'tcx>,
@@ -125,7 +124,7 @@ pub(super) fn mir_assign_valid_types<'tcx>(
125124
// all normal lifetimes are erased, higher-ranked types with their
126125
// late-bound lifetimes are still around and can lead to type
127126
// differences.
128-
if util::relate_types(tcx, typing_env, Variance::Covariant, src.ty, dest.ty) {
127+
if util::sub_types(tcx, typing_env, src.ty, dest.ty) {
129128
// Make sure the layout is equal, too -- just to be safe. Miri really
130129
// needs layout equality. For performance reason we skip this check when
131130
// the types are equal. Equal types *can* have different layouts when

compiler/rustc_const_eval/src/interpret/projection.rs

-2
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,6 @@ where
381381
OpaqueCast(ty) => {
382382
span_bug!(self.cur_span(), "OpaqueCast({ty}) encountered after borrowck")
383383
}
384-
// We don't want anything happening here, this is here as a dummy.
385-
Subtype(_) => base.transmute(base.layout(), self)?,
386384
Field(field, _) => self.project_field(base, field.index())?,
387385
Downcast(_, variant) => self.project_downcast(base, variant)?,
388386
Deref => self.deref_pointer(&base.to_op(self)?)?.into(),

compiler/rustc_const_eval/src/util/compare_types.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ pub fn sub_types<'tcx>(
2020

2121
/// Returns whether `src` is a subtype of `dest`, i.e. `src <: dest`.
2222
///
23-
/// When validating assignments, the variance should be `Covariant`. When checking
24-
/// during `MirPhase` >= `MirPhase::Runtime(RuntimePhase::Initial)` variance should be `Invariant`
25-
/// because we want to check for type equality.
23+
/// When validating assignments, the variance should be `Covariant` and
24+
/// `sub_types` should be used instead.
2625
pub fn relate_types<'tcx>(
2726
tcx: TyCtxt<'tcx>,
2827
typing_env: TypingEnv<'tcx>,

compiler/rustc_middle/src/mir/pretty.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,6 @@ fn pre_fmt_projection(projection: &[PlaceElem<'_>], fmt: &mut Formatter<'_>) ->
12701270
for &elem in projection.iter().rev() {
12711271
match elem {
12721272
ProjectionElem::OpaqueCast(_)
1273-
| ProjectionElem::Subtype(_)
12741273
| ProjectionElem::Downcast(_, _)
12751274
| ProjectionElem::Field(_, _) => {
12761275
write!(fmt, "(")?;
@@ -1293,9 +1292,6 @@ fn post_fmt_projection(projection: &[PlaceElem<'_>], fmt: &mut Formatter<'_>) ->
12931292
ProjectionElem::OpaqueCast(ty) => {
12941293
write!(fmt, " as {ty})")?;
12951294
}
1296-
ProjectionElem::Subtype(ty) => {
1297-
write!(fmt, " as subtype {ty})")?;
1298-
}
12991295
ProjectionElem::Downcast(Some(name), _index) => {
13001296
write!(fmt, " as {name})")?;
13011297
}

compiler/rustc_middle/src/mir/statement.rs

-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ impl<V, T> ProjectionElem<V, T> {
5959
Self::Field(_, _)
6060
| Self::Index(_)
6161
| Self::OpaqueCast(_)
62-
| Self::Subtype(_)
6362
| Self::ConstantIndex { .. }
6463
| Self::Subslice { .. }
6564
| Self::Downcast(_, _) => false,
@@ -73,7 +72,6 @@ impl<V, T> ProjectionElem<V, T> {
7372
Self::Deref | Self::Index(_) => false,
7473
Self::Field(_, _)
7574
| Self::OpaqueCast(_)
76-
| Self::Subtype(_)
7775
| Self::ConstantIndex { .. }
7876
| Self::Subslice { .. }
7977
| Self::Downcast(_, _) => true,
@@ -99,7 +97,6 @@ impl<V, T> ProjectionElem<V, T> {
9997
| Self::Field(_, _) => true,
10098
Self::ConstantIndex { from_end: true, .. }
10199
| Self::Index(_)
102-
| Self::Subtype(_)
103100
| Self::OpaqueCast(_)
104101
| Self::Subslice { .. } => false,
105102
}

compiler/rustc_middle/src/mir/syntax.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1182,18 +1182,6 @@ pub enum ProjectionElem<V, T> {
11821182
/// Like an explicit cast from an opaque type to a concrete type, but without
11831183
/// requiring an intermediate variable.
11841184
OpaqueCast(T),
1185-
1186-
/// A `Subtype(T)` projection is applied to any `StatementKind::Assign` where
1187-
/// type of lvalue doesn't match the type of rvalue, the primary goal is making subtyping
1188-
/// explicit during optimizations and codegen.
1189-
///
1190-
/// This projection doesn't impact the runtime behavior of the program except for potentially changing
1191-
/// some type metadata of the interpreter or codegen backend.
1192-
///
1193-
/// This goal is achieved with mir_transform pass `Subtyper`, which runs right after
1194-
/// borrowchecker, as we only care about subtyping that can affect trait selection and
1195-
/// `TypeId`.
1196-
Subtype(T),
11971185
}
11981186

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

compiler/rustc_middle/src/mir/tcx.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'tcx> PlaceTy<'tcx> {
6868
tcx: TyCtxt<'tcx>,
6969
elem: &ProjectionElem<V, T>,
7070
mut handle_field: impl FnMut(&Self, FieldIdx, T) -> Ty<'tcx>,
71-
mut handle_opaque_cast_and_subtype: impl FnMut(&Self, T) -> Ty<'tcx>,
71+
mut handle_opaque_cast: impl FnMut(&Self, T) -> Ty<'tcx>,
7272
) -> PlaceTy<'tcx>
7373
where
7474
V: ::std::fmt::Debug,
@@ -105,12 +105,7 @@ impl<'tcx> PlaceTy<'tcx> {
105105
PlaceTy { ty: self.ty, variant_index: Some(index) }
106106
}
107107
ProjectionElem::Field(f, fty) => PlaceTy::from_ty(handle_field(&self, f, fty)),
108-
ProjectionElem::OpaqueCast(ty) => {
109-
PlaceTy::from_ty(handle_opaque_cast_and_subtype(&self, ty))
110-
}
111-
ProjectionElem::Subtype(ty) => {
112-
PlaceTy::from_ty(handle_opaque_cast_and_subtype(&self, ty))
113-
}
108+
ProjectionElem::OpaqueCast(ty) => PlaceTy::from_ty(handle_opaque_cast(&self, ty)),
114109
};
115110
debug!("projection_ty self: {:?} elem: {:?} yields: {:?}", self, elem, answer);
116111
answer

compiler/rustc_middle/src/mir/visit.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1142,11 +1142,6 @@ macro_rules! visit_place_fns {
11421142
self.visit_ty(&mut new_ty, TyContext::Location(location));
11431143
if ty != new_ty { Some(PlaceElem::OpaqueCast(new_ty)) } else { None }
11441144
}
1145-
PlaceElem::Subtype(ty) => {
1146-
let mut new_ty = ty;
1147-
self.visit_ty(&mut new_ty, TyContext::Location(location));
1148-
if ty != new_ty { Some(PlaceElem::Subtype(new_ty)) } else { None }
1149-
}
11501145
PlaceElem::Deref
11511146
| PlaceElem::ConstantIndex { .. }
11521147
| PlaceElem::Subslice { .. }
@@ -1213,9 +1208,7 @@ macro_rules! visit_place_fns {
12131208
location: Location,
12141209
) {
12151210
match elem {
1216-
ProjectionElem::OpaqueCast(ty)
1217-
| ProjectionElem::Subtype(ty)
1218-
| ProjectionElem::Field(_, ty) => {
1211+
ProjectionElem::OpaqueCast(ty) | ProjectionElem::Field(_, ty) => {
12191212
self.visit_ty(ty, TyContext::Location(location));
12201213
}
12211214
ProjectionElem::Index(local) => {

compiler/rustc_mir_build/src/build/expr/as_place.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ fn convert_to_hir_projections_and_truncate_for_capture(
102102
variant = Some(*idx);
103103
continue;
104104
}
105-
// These do not affect anything, they just make sure we know the right type.
106-
ProjectionElem::OpaqueCast(_) | ProjectionElem::Subtype(..) => continue,
105+
// This does not affect anything, it just makes sure we know the right type.
106+
ProjectionElem::OpaqueCast(_) => continue,
107107
ProjectionElem::Index(..)
108108
| ProjectionElem::ConstantIndex { .. }
109109
| ProjectionElem::Subslice { .. } => {
@@ -712,7 +712,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
712712
ProjectionElem::Field(..)
713713
| ProjectionElem::Downcast(..)
714714
| ProjectionElem::OpaqueCast(..)
715-
| ProjectionElem::Subtype(..)
716715
| ProjectionElem::ConstantIndex { .. }
717716
| ProjectionElem::Subslice { .. } => (),
718717
}

compiler/rustc_mir_dataflow/src/move_paths/abs_domain.rs

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ impl<'tcx> Lift for PlaceElem<'tcx> {
5757
ProjectionElem::ConstantIndex { offset, min_length, from_end }
5858
}
5959
ProjectionElem::Downcast(a, u) => ProjectionElem::Downcast(a, u),
60-
ProjectionElem::Subtype(ty) => ProjectionElem::Subtype(ty.lift()),
6160
}
6261
}
6362
}

compiler/rustc_mir_dataflow/src/move_paths/builder.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,8 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
226226
},
227227
// `OpaqueCast`:Only transmutes the type, so no moves there.
228228
// `Downcast` :Only changes information about a `Place` without moving.
229-
// `Subtype` :Only transmutes the type, so moves.
230229
// So it's safe to skip these.
231-
ProjectionElem::OpaqueCast(_)
232-
| ProjectionElem::Subtype(_)
233-
| ProjectionElem::Downcast(_, _) => (),
230+
ProjectionElem::OpaqueCast(_) | ProjectionElem::Downcast(_, _) => (),
234231
}
235232
let elem_ty = PlaceTy::from_ty(place_ty).projection_ty(tcx, elem).ty;
236233
if !(self.filter)(elem_ty) {

0 commit comments

Comments
 (0)