Skip to content

Commit 791dd00

Browse files
committed
Auto merge of #164853 - dianqk:downcast, r=<try>
Introduce AssumeVariant pass
2 parents 12433c3 + b262734 commit 791dd00

118 files changed

Lines changed: 979 additions & 233 deletions

File tree

Some content is hidden

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

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4279,7 +4279,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> {
42794279
},
42804280
ProjectionElem::OpaqueCast { .. }
42814281
| ProjectionElem::Field(..)
4282-
| ProjectionElem::Downcast(..) => {
4282+
| ProjectionElem::Downcast { .. } => {
42834283
match place_ty.ty.kind() {
42844284
ty::Adt(def, _) if def.has_dtor(tcx) => {
42854285
// Report the outermost adt with a destructor

‎compiler/rustc_borrowck/src/diagnostics/mod.rs‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
369369
autoderef_index = match place.projection.iter().rposition(|elem| {
370370
!matches!(
371371
elem,
372-
ProjectionElem::Deref | ProjectionElem::Downcast(..)
372+
ProjectionElem::Deref | ProjectionElem::Downcast { .. }
373373
)
374374
}) {
375375
Some(index) => Some(index + 1),
@@ -382,8 +382,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
382382
}
383383
}
384384
ProjectionElem::PhantomDeref => (),
385-
ProjectionElem::Downcast(..) if opt.including_downcast => return None,
386-
ProjectionElem::Downcast(..) => (),
385+
ProjectionElem::Downcast { .. } if opt.including_downcast => return None,
386+
ProjectionElem::Downcast { .. } => (),
387387
ProjectionElem::OpaqueCast(..) => (),
388388
ProjectionElem::UnwrapUnsafeBinder(_) => (),
389389
ProjectionElem::Field(field, _ty) => {
@@ -425,15 +425,13 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
425425
}
426426

427427
fn describe_name(&self, place: PlaceRef<'tcx>) -> Option<Symbol> {
428-
for elem in place.projection.into_iter() {
429-
match elem {
430-
ProjectionElem::Downcast(Some(name), _) => {
431-
return Some(*name);
432-
}
433-
_ => {}
428+
place.projection.into_iter().find_map(|elem| {
429+
if let ProjectionElem::Downcast { name: Some(name), .. } = elem {
430+
Some(*name)
431+
} else {
432+
None
434433
}
435-
}
436-
None
434+
})
437435
}
438436

439437
/// Appends end-user visible description of the `local` place to `buf`. If `local` doesn't have
@@ -465,7 +463,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
465463
| ProjectionElem::Subslice { .. } => {
466464
PlaceRef { local, projection: proj_base }.ty(self.body, self.infcx.tcx)
467465
}
468-
ProjectionElem::Downcast(..) => place.ty(self.body, self.infcx.tcx),
466+
ProjectionElem::Downcast { .. } => place.ty(self.body, self.infcx.tcx),
469467
ProjectionElem::OpaqueCast(ty) | ProjectionElem::UnwrapUnsafeBinder(ty) => {
470468
PlaceTy::from_ty(*ty)
471469
}
@@ -1055,12 +1053,15 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
10551053
}
10561054
}
10571055

1058-
let normal_ret =
1059-
if moved_place.projection.iter().any(|p| matches!(p, ProjectionElem::Downcast(..))) {
1060-
PatUse(stmt.source_info.span)
1061-
} else {
1062-
OtherUse(stmt.source_info.span)
1063-
};
1056+
let normal_ret = if moved_place
1057+
.projection
1058+
.iter()
1059+
.any(|p| matches!(p, ProjectionElem::Downcast { .. }))
1060+
{
1061+
PatUse(stmt.source_info.span)
1062+
} else {
1063+
OtherUse(stmt.source_info.span)
1064+
};
10641065

10651066
// We are trying to find MIR of the form:
10661067
// ```

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
199199
| ProjectionElem::ConstantIndex { .. }
200200
| ProjectionElem::OpaqueCast { .. }
201201
| ProjectionElem::Subslice { .. }
202-
| ProjectionElem::Downcast(..)
202+
| ProjectionElem::Downcast { .. }
203203
| ProjectionElem::UnwrapUnsafeBinder(_),
204204
],
205205
} => bug!("Unexpected immutable place."),

‎compiler/rustc_borrowck/src/lib.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
20202020
// `Downcast` : only changes information about a `Place` without moving.
20212021
// So it's safe to skip these.
20222022
ProjectionElem::OpaqueCast(_)
2023-
| ProjectionElem::Downcast(_, _)
2023+
| ProjectionElem::Downcast { .. }
20242024
| ProjectionElem::UnwrapUnsafeBinder(_)
20252025
| ProjectionElem::PhantomDeref => (),
20262026
}
@@ -2252,7 +2252,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
22522252
// assigning to (P->variant) is okay if assigning to `P` is okay
22532253
//
22542254
// FIXME: is this true even if P is an adt with a dtor?
2255-
| ProjectionElem::Downcast(_/*adt_def*/, _/*variant_idx*/) =>
2255+
| ProjectionElem::Downcast{..} =>
22562256
{}
22572257

22582258
ProjectionElem::UnwrapUnsafeBinder(_) => {
@@ -2666,7 +2666,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
26662666
| ProjectionElem::ConstantIndex { .. }
26672667
| ProjectionElem::Subslice { .. }
26682668
| ProjectionElem::OpaqueCast { .. }
2669-
| ProjectionElem::Downcast(..)
2669+
| ProjectionElem::Downcast { .. }
26702670
| ProjectionElem::UnwrapUnsafeBinder(_) => {
26712671
let upvar_field_projection = self.is_upvar_field_projection(place);
26722672
if let Some(field) = upvar_field_projection {

‎compiler/rustc_borrowck/src/places_conflict.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,10 @@ fn place_projection_conflict<'tcx>(
337337
}
338338
}
339339
}
340-
(ProjectionElem::Downcast(_, v1), ProjectionElem::Downcast(_, v2)) => {
340+
(
341+
ProjectionElem::Downcast { variant_index: v1, .. },
342+
ProjectionElem::Downcast { variant_index: v2, .. },
343+
) => {
341344
// different variants are treated as having disjoint fields,
342345
// even if they occupy the same "space", because it's
343346
// impossible for 2 variants of the same enum to exist
@@ -525,7 +528,7 @@ fn place_projection_conflict<'tcx>(
525528
| ProjectionElem::ConstantIndex { .. }
526529
| ProjectionElem::OpaqueCast { .. }
527530
| ProjectionElem::Subslice { .. }
528-
| ProjectionElem::Downcast(..),
531+
| ProjectionElem::Downcast { .. },
529532
_,
530533
) => bug!(
531534
"mismatched projections in place_element_conflict: {:?} and {:?}",

‎compiler/rustc_borrowck/src/prefixes.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'tcx> Iterator for Prefixes<'tcx> {
5858
self.next = Some(cursor_base);
5959
return Some(cursor);
6060
}
61-
ProjectionElem::Downcast(..)
61+
ProjectionElem::Downcast { .. }
6262
| ProjectionElem::Subslice { .. }
6363
| ProjectionElem::OpaqueCast { .. }
6464
| ProjectionElem::ConstantIndex { .. }

‎compiler/rustc_borrowck/src/type_check/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
18981898
| ProjectionElem::Index(_)
18991899
| ProjectionElem::ConstantIndex { .. }
19001900
| ProjectionElem::Subslice { .. }
1901-
| ProjectionElem::Downcast(..) => {}
1901+
| ProjectionElem::Downcast { .. } => {}
19021902
ProjectionElem::Field(field, fty) => {
19031903
let fty = self.normalize(ty::Unnormalized::new_wip(fty), location);
19041904
let ty = PlaceTy::field_ty(tcx, base_ty.ty, base_ty.variant_index, field);
@@ -2469,7 +2469,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24692469
bug!("unexpected PhantomDeref in add_reborrow_constraint")
24702470
}
24712471
ProjectionElem::Field(..)
2472-
| ProjectionElem::Downcast(..)
2472+
| ProjectionElem::Downcast { .. }
24732473
| ProjectionElem::OpaqueCast(..)
24742474
| ProjectionElem::Index(..)
24752475
| ProjectionElem::ConstantIndex { .. }

‎compiler/rustc_codegen_cranelift/src/base.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,8 @@ pub(crate) fn codegen_place<'tcx>(
10481048
_ => unreachable!(),
10491049
}
10501050
}
1051-
PlaceElem::Downcast(_adt_def, variant) => {
1052-
cplace = cplace.downcast_variant(fx, variant);
1051+
PlaceElem::Downcast { variant_index, .. } => {
1052+
cplace = cplace.downcast_variant(fx, variant_index);
10531053
}
10541054
}
10551055
}

‎compiler/rustc_codegen_ssa/src/mir/analyze.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'b, 'tcx>> LocalAnalyzer<'a, 'b, 'tcx, Bx>
143143
for elem in place_ref.projection {
144144
layout = match *elem {
145145
mir::PlaceElem::Field(fidx, ..) => layout.field(self.fx.cx, fidx.as_usize()),
146-
mir::PlaceElem::Downcast(_, vidx)
146+
mir::PlaceElem::Downcast { variant_index, .. }
147147
if let abi::Variants::Single { index: single_variant } =
148148
layout.variants
149-
&& vidx == single_variant =>
149+
&& variant_index == single_variant =>
150150
{
151-
layout.for_variant(self.fx.cx, vidx)
151+
layout.for_variant(self.fx.cx, variant_index)
152152
}
153153
_ => {
154154
self.locals[place_ref.local] = LocalKind::Memory;

‎compiler/rustc_codegen_ssa/src/mir/debuginfo.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ fn calculate_debuginfo_offset<
191191
*offset += place.layout().fields.offset(field.index());
192192
place = place.project_field(bx, field);
193193
}
194-
mir::ProjectionElem::Downcast(_, variant) => {
195-
place = place.downcast(bx, variant);
194+
mir::ProjectionElem::Downcast { variant_index, .. } => {
195+
place = place.downcast(bx, variant_index);
196196
}
197197
mir::ProjectionElem::ConstantIndex {
198198
offset: index,

0 commit comments

Comments
 (0)