Skip to content

Commit a43ac06

Browse files
committed
Also use Const in SMIR instead of just ConstantKind
1 parent 7242c65 commit a43ac06

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,22 +1210,26 @@ impl<'tcx> Stable<'tcx> for ty::TraitDef {
12101210
}
12111211

12121212
impl<'tcx> Stable<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
1213-
type T = stable_mir::ty::ConstantKind;
1213+
type T = stable_mir::ty::Const;
12141214

12151215
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
12161216
match *self {
1217-
ConstantKind::Ty(c) => c.stable(tables).literal,
1218-
ConstantKind::Unevaluated(unev_const, ty) => {
1219-
stable_mir::ty::ConstantKind::Unevaluated(stable_mir::ty::UnevaluatedConst {
1220-
ty: tables.intern_ty(ty),
1221-
def: tables.const_def(unev_const.def),
1222-
args: unev_const.args.stable(tables),
1223-
promoted: unev_const.promoted.map(|u| u.as_u32()),
1224-
})
1225-
}
1226-
ConstantKind::Val(val, ty) => {
1227-
stable_mir::ty::ConstantKind::Allocated(alloc::new_allocation(ty, val, tables))
1228-
}
1217+
ConstantKind::Ty(c) => c.stable(tables),
1218+
ConstantKind::Unevaluated(unev_const, ty) => stable_mir::ty::Const {
1219+
literal: stable_mir::ty::ConstantKind::Unevaluated(
1220+
stable_mir::ty::UnevaluatedConst {
1221+
ty: tables.intern_ty(ty),
1222+
def: tables.const_def(unev_const.def),
1223+
args: unev_const.args.stable(tables),
1224+
promoted: unev_const.promoted.map(|u| u.as_u32()),
1225+
},
1226+
),
1227+
},
1228+
ConstantKind::Val(val, ty) => stable_mir::ty::Const {
1229+
literal: stable_mir::ty::ConstantKind::Allocated(alloc::new_allocation(
1230+
ty, val, tables,
1231+
)),
1232+
},
12291233
}
12301234
}
12311235
}

compiler/rustc_smir/src/stable_mir/mir/body.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::rustc_internal::Opaque;
22
use crate::stable_mir::ty::{
3-
AdtDef, ClosureDef, Const, ConstantKind, GeneratorDef, GenericArgs, Movability, Region,
3+
AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region,
44
};
55
use crate::stable_mir::{self, ty::Ty, Span};
66

@@ -352,7 +352,7 @@ type UserTypeAnnotationIndex = usize;
352352
pub struct Constant {
353353
pub span: Span,
354354
pub user_ty: Option<UserTypeAnnotationIndex>,
355-
pub literal: ConstantKind,
355+
pub literal: Const,
356356
}
357357

358358
#[derive(Clone, Debug)]

tests/ui-fulldeps/stable-mir/crate-info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
113113
for block in monomorphic.body().blocks {
114114
match &block.terminator {
115115
stable_mir::mir::Terminator::Call { func, .. } => match func {
116-
stable_mir::mir::Operand::Constant(c) => match &c.literal {
116+
stable_mir::mir::Operand::Constant(c) => match &c.literal.literal {
117117
stable_mir::ty::ConstantKind::Allocated(alloc) => {
118118
assert!(alloc.bytes.is_empty())
119119
}

0 commit comments

Comments
 (0)