@@ -1083,8 +1083,21 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
10831083 type T = stable_mir:: ty:: Const ;
10841084
10851085 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+ }
10881101 }
10891102}
10901103
@@ -1155,26 +1168,18 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
11551168 type T = stable_mir:: ty:: ConstantKind ;
11561169
11571170 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 ,
11681173 ConstantKind :: Unevaluated ( unev_const, ty) => {
11691174 stable_mir:: ty:: ConstantKind :: Unevaluated ( stable_mir:: ty:: UnevaluatedConst {
1170- ty : tables. intern_ty ( * ty) ,
1175+ ty : tables. intern_ty ( ty) ,
11711176 def : tables. const_def ( unev_const. def ) ,
11721177 args : unev_const. args . stable ( tables) ,
11731178 promoted : unev_const. promoted . map ( |u| u. as_u32 ( ) ) ,
11741179 } )
11751180 }
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) )
11781183 }
11791184 }
11801185 }
0 commit comments