Skip to content

Commit c036a10

Browse files
committed
Make UserTypeProjection projections Opaque
Also shifts comments explaining why Stable MIR drops an optional variant name field, for `Downcast` projection elements, to the `Place::stable` function.
1 parent ae1726b commit c036a10

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,11 @@ impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> {
712712
to: *to,
713713
from_end: *from_end,
714714
},
715+
// MIR includes an `Option<Symbol>` argument for `Downcast` that is the name of the
716+
// variant, used for printing MIR. However this information should also be accessible
717+
// via a lookup using the `VariantIdx`. The `Option<Symbol>` argument is therefore
718+
// dropped when converting to Stable MIR. A brief justification for this decision can be
719+
// found at https://github.com/rust-lang/rust/pull/117517#issuecomment-1811683486
715720
Downcast(_, idx) => stable_mir::mir::ProjectionElem::Downcast(idx.stable(tables)),
716721
OpaqueCast(ty) => stable_mir::mir::ProjectionElem::OpaqueCast(ty.stable(tables)),
717722
Subtype(ty) => stable_mir::mir::ProjectionElem::Subtype(ty.stable(tables)),
@@ -723,7 +728,7 @@ impl<'tcx> Stable<'tcx> for mir::UserTypeProjection {
723728
type T = stable_mir::mir::UserTypeProjection;
724729

725730
fn stable(&self, _tables: &mut Tables<'tcx>) -> Self::T {
726-
UserTypeProjection { base: self.base.as_usize(), projection: format!("{:?}", self.projs) }
731+
UserTypeProjection { base: self.base.as_usize(), projection: opaque(&self.projs) }
727732
}
728733
}
729734

compiler/stable_mir/src/mir/body.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,6 @@ pub enum ProjectionElem {
465465
},
466466

467467
/// "Downcast" to a variant of an enum or a coroutine.
468-
//
469-
// TODO(klinvill): MIR includes an Option<Symbol> argument that is the name of the variant, used
470-
// for printing MIR. However I don't see it used anywhere. Is such a field needed or can we just
471-
// include the VariantIdx which could be used to recover the field name if needed?
472468
Downcast(VariantIdx),
473469

474470
/// Like an explicit cast from an opaque type to a concrete type, but without
@@ -488,7 +484,7 @@ pub enum ProjectionElem {
488484
pub struct UserTypeProjection {
489485
pub base: UserTypeAnnotationIndex,
490486

491-
pub projection: String,
487+
pub projection: Opaque,
492488
}
493489

494490
pub type Local = usize;

0 commit comments

Comments
 (0)