@@ -1083,8 +1083,21 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
1083
1083
type T = stable_mir:: ty:: Const ;
1084
1084
1085
1085
fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1086
- let cnst = ConstantKind :: from_const ( * self , tables. tcx ) ;
1087
- stable_mir:: ty:: Const { literal : cnst. stable ( tables) }
1086
+ stable_mir:: ty:: Const {
1087
+ literal : match self . kind ( ) {
1088
+ ty:: Value ( val) => {
1089
+ let const_val = tables. tcx . valtree_to_const_val ( ( self . ty ( ) , val) ) ;
1090
+ stable_mir:: ty:: ConstantKind :: Allocated ( new_allocation (
1091
+ self . ty ( ) ,
1092
+ const_val,
1093
+ tables,
1094
+ ) )
1095
+ }
1096
+ ty:: ParamCt ( param) => stable_mir:: ty:: ConstantKind :: ParamCt ( opaque ( & param) ) ,
1097
+ ty:: ErrorCt ( _) => unreachable ! ( ) ,
1098
+ _ => unimplemented ! ( ) ,
1099
+ } ,
1100
+ }
1088
1101
}
1089
1102
}
1090
1103
@@ -1155,26 +1168,18 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
1155
1168
type T = stable_mir:: ty:: ConstantKind ;
1156
1169
1157
1170
fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1158
- match self {
1159
- ConstantKind :: Ty ( c) => match c. kind ( ) {
1160
- ty:: Value ( val) => {
1161
- let const_val = tables. tcx . valtree_to_const_val ( ( c. ty ( ) , val) ) ;
1162
- stable_mir:: ty:: ConstantKind :: Allocated ( new_allocation ( self , const_val, tables) )
1163
- }
1164
- ty:: ParamCt ( param) => stable_mir:: ty:: ConstantKind :: ParamCt ( opaque ( & param) ) ,
1165
- ty:: ErrorCt ( _) => unreachable ! ( ) ,
1166
- _ => unimplemented ! ( ) ,
1167
- } ,
1171
+ match * self {
1172
+ ConstantKind :: Ty ( c) => c. stable ( tables) . literal ,
1168
1173
ConstantKind :: Unevaluated ( unev_const, ty) => {
1169
1174
stable_mir:: ty:: ConstantKind :: Unevaluated ( stable_mir:: ty:: UnevaluatedConst {
1170
- ty : tables. intern_ty ( * ty) ,
1175
+ ty : tables. intern_ty ( ty) ,
1171
1176
def : tables. const_def ( unev_const. def ) ,
1172
1177
args : unev_const. args . stable ( tables) ,
1173
1178
promoted : unev_const. promoted . map ( |u| u. as_u32 ( ) ) ,
1174
1179
} )
1175
1180
}
1176
- ConstantKind :: Val ( val, _ ) => {
1177
- stable_mir:: ty:: ConstantKind :: Allocated ( new_allocation ( self , * val, tables) )
1181
+ ConstantKind :: Val ( val, ty ) => {
1182
+ stable_mir:: ty:: ConstantKind :: Allocated ( new_allocation ( ty , val, tables) )
1178
1183
}
1179
1184
}
1180
1185
}
0 commit comments