Skip to content

Commit 3148e6a

Browse files
committed
subtyping_projections
1 parent 1770912 commit 3148e6a

File tree

28 files changed

+431
-5
lines changed

28 files changed

+431
-5
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2828,6 +2828,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
28282828
}
28292829
ProjectionElem::ConstantIndex { .. }
28302830
| ProjectionElem::Subslice { .. }
2831+
| ProjectionElem::Subtype(_)
28312832
| ProjectionElem::Index(_) => kind,
28322833
},
28332834
place_ty.projection_ty(tcx, elem),

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
242242
ProjectionElem::Downcast(..) if opt.including_downcast => return None,
243243
ProjectionElem::Downcast(..) => (),
244244
ProjectionElem::OpaqueCast(..) => (),
245+
ProjectionElem::Subtype(..) => (),
245246
ProjectionElem::Field(field, _ty) => {
246247
// FIXME(project-rfc_2229#36): print capture precisely here.
247248
if let Some(field) = self.is_upvar_field_projection(PlaceRef {
@@ -317,6 +318,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
317318
PlaceRef { local, projection: [proj_base @ .., elem] } => match elem {
318319
ProjectionElem::Deref
319320
| ProjectionElem::Index(..)
321+
| ProjectionElem::Subtype(..)
320322
| ProjectionElem::ConstantIndex { .. }
321323
| ProjectionElem::Subslice { .. } => {
322324
PlaceRef { local, projection: proj_base }.ty(self.body, self.infcx.tcx)

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
159159
[
160160
..,
161161
ProjectionElem::Index(_)
162+
| ProjectionElem::Subtype(_)
162163
| ProjectionElem::ConstantIndex { .. }
163164
| ProjectionElem::OpaqueCast { .. }
164165
| ProjectionElem::Subslice { .. }

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18031803
for (place_base, elem) in place.iter_projections().rev() {
18041804
match elem {
18051805
ProjectionElem::Index(_/*operand*/) |
1806+
ProjectionElem::Subtype(_) |
18061807
ProjectionElem::OpaqueCast(_) |
18071808
ProjectionElem::ConstantIndex { .. } |
18081809
// assigning to P[i] requires P to be valid.
@@ -2191,6 +2192,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21912192
| ProjectionElem::Index(..)
21922193
| ProjectionElem::ConstantIndex { .. }
21932194
| ProjectionElem::Subslice { .. }
2195+
| ProjectionElem::Subtype(..)
21942196
| ProjectionElem::OpaqueCast { .. }
21952197
| ProjectionElem::Downcast(..) => {
21962198
let upvar_field_projection = self.is_upvar_field_projection(place);

compiler/rustc_borrowck/src/places_conflict.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ fn place_components_conflict<'tcx>(
243243
}
244244

245245
(ProjectionElem::Deref, _, Deep)
246+
| (ProjectionElem::Subtype(_), _, _)
246247
| (ProjectionElem::Deref, _, AccessDepth::Drop)
247248
| (ProjectionElem::Field { .. }, _, _)
248249
| (ProjectionElem::Index { .. }, _, _)
@@ -359,6 +360,7 @@ fn place_projection_conflict<'tcx>(
359360
(
360361
ProjectionElem::Index(..),
361362
ProjectionElem::Index(..)
363+
| ProjectionElem::Subtype(..)
362364
| ProjectionElem::ConstantIndex { .. }
363365
| ProjectionElem::Subslice { .. },
364366
)
@@ -503,6 +505,7 @@ fn place_projection_conflict<'tcx>(
503505
debug!("place_element_conflict: DISJOINT-OR-EQ-SLICE-SUBSLICES");
504506
Overlap::EqualOrDisjoint
505507
}
508+
(ProjectionElem::Subtype(_), _) => Overlap::EqualOrDisjoint,
506509
(
507510
ProjectionElem::Deref
508511
| ProjectionElem::Field(..)

compiler/rustc_borrowck/src/prefixes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
8989
cursor = cursor_base;
9090
continue 'cursor;
9191
}
92+
ProjectionElem::Subtype(..) => continue 'cursor,
9293
ProjectionElem::Deref => {
9394
// (handled below)
9495
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
621621
span_mirbug_and_err!(self, place, "deref of non-pointer {:?}", base_ty)
622622
}))
623623
}
624+
ProjectionElem::Subtype(ty) => PlaceTy::from_ty(ty),
624625
ProjectionElem::Index(i) => {
625626
let index_ty = Place::from(i).ty(self.body(), tcx).ty;
626627
if index_ty != tcx.types.usize {
@@ -2556,6 +2557,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25562557
}
25572558
}
25582559
ProjectionElem::Field(..)
2560+
| ProjectionElem::Subtype(..)
25592561
| ProjectionElem::Downcast(..)
25602562
| ProjectionElem::OpaqueCast(..)
25612563
| ProjectionElem::Index(..)

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,9 @@ pub(crate) fn codegen_place<'tcx>(
872872

873873
for elem in place.projection {
874874
match elem {
875+
PlaceElem::Subtype(_) => {
876+
continue;
877+
}
875878
PlaceElem::Deref => {
876879
cplace = cplace.place_deref(fx);
877880
}

compiler/rustc_codegen_ssa/src/mir/place.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
499499
subslice
500500
}
501501
mir::ProjectionElem::Downcast(_, v) => cg_base.project_downcast(bx, v),
502+
mir::ProjectionElem::Subtype(_) => continue,
502503
};
503504
}
504505
debug!("codegen_place(place={:?}) => {:?}", place_ref, cg_base);

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
665665
let mut op = self.local_to_op(self.frame(), mir_place.local, layout)?;
666666
// Using `try_fold` turned out to be bad for performance, hence the loop.
667667
for elem in mir_place.projection.iter() {
668+
if elem.is_subtype() {
669+
continue;
670+
}
668671
op = self.project(&op, elem)?
669672
}
670673

0 commit comments

Comments
 (0)