diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 6bcb6f8f37b..925d4a3bdd8 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -477,7 +477,19 @@ fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { match self { Copy(place) => stable_mir::mir::Operand::Copy(place.stable(tables)), Move(place) => stable_mir::mir::Operand::Move(place.stable(tables)), - Constant(c) => stable_mir::mir::Operand::Constant(c.to_string()), + Constant(c) => stable_mir::mir::Operand::Constant(c.stable(tables)), + } + } +} + +impl<'tcx> Stable<'tcx> for mir::Constant<'tcx> { + type T = stable_mir::mir::Constant; + + fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { + stable_mir::mir::Constant { + span: self.span.stable(tables), + user_ty: self.user_ty.map(|u| u.as_usize()).or(None), + literal: self.literal.stable(tables), } } } diff --git a/compiler/rustc_smir/src/stable_mir/mir/body.rs b/compiler/rustc_smir/src/stable_mir/mir/body.rs index a2ab51ff846..72f719c2a5e 100644 --- a/compiler/rustc_smir/src/stable_mir/mir/body.rs +++ b/compiler/rustc_smir/src/stable_mir/mir/body.rs @@ -1,8 +1,8 @@ use crate::rustc_internal::Opaque; use crate::stable_mir::ty::{ - AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region, + AdtDef, ClosureDef, Const, ConstantKind, GeneratorDef, GenericArgs, Movability, Region, }; -use crate::stable_mir::{self, ty::Ty}; +use crate::stable_mir::{self, ty::Ty, Span}; #[derive(Clone, Debug)] pub struct Body { @@ -324,7 +324,7 @@ pub enum AggregateKind { pub enum Operand { Copy(Place), Move(Place), - Constant(String), + Constant(Constant), } #[derive(Clone, Debug)] @@ -348,6 +348,13 @@ pub struct UserTypeProjection { type UserTypeAnnotationIndex = usize; +#[derive(Clone, Debug)] +pub struct Constant { + pub span: Span, + pub user_ty: Option, + pub literal: ConstantKind, +} + #[derive(Clone, Debug)] pub struct SwitchTarget { pub value: u128,