@@ -409,6 +409,48 @@ impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> {
409
409
}
410
410
}
411
411
412
+ pub fn mir_const_from_ty_const < ' tcx > (
413
+ tables : & mut Tables < ' tcx > ,
414
+ ty_const : ty:: Const < ' tcx > ,
415
+ ty : Ty < ' tcx > ,
416
+ ) -> stable_mir:: ty:: MirConst {
417
+ let kind = match ty_const. kind ( ) {
418
+ ty:: Value ( ty, val) => {
419
+ let val = match val {
420
+ ty:: ValTree :: Leaf ( scalar) => ty:: ValTree :: Leaf ( scalar) ,
421
+ ty:: ValTree :: Branch ( branch) => {
422
+ ty:: ValTree :: Branch ( tables. tcx . lift ( branch) . unwrap ( ) )
423
+ }
424
+ } ;
425
+ let ty = tables. tcx . lift ( ty) . unwrap ( ) ;
426
+ let const_val = tables. tcx . valtree_to_const_val ( ( ty, val) ) ;
427
+ if matches ! ( const_val, mir:: ConstValue :: ZeroSized ) {
428
+ stable_mir:: ty:: ConstantKind :: ZeroSized
429
+ } else {
430
+ stable_mir:: ty:: ConstantKind :: Allocated ( alloc:: new_allocation (
431
+ ty, const_val, tables,
432
+ ) )
433
+ }
434
+ }
435
+ ty:: ParamCt ( param) => stable_mir:: ty:: ConstantKind :: Param ( param. stable ( tables) ) ,
436
+ ty:: ErrorCt ( _) => unreachable ! ( ) ,
437
+ ty:: InferCt ( _) => unreachable ! ( ) ,
438
+ ty:: BoundCt ( _, _) => unimplemented ! ( ) ,
439
+ ty:: PlaceholderCt ( _) => unimplemented ! ( ) ,
440
+ ty:: Unevaluated ( uv) => {
441
+ stable_mir:: ty:: ConstantKind :: Unevaluated ( stable_mir:: ty:: UnevaluatedConst {
442
+ def : tables. const_def ( uv. def ) ,
443
+ args : uv. args . stable ( tables) ,
444
+ promoted : None ,
445
+ } )
446
+ }
447
+ ty:: ExprCt ( _) => unimplemented ! ( ) ,
448
+ } ;
449
+ let stable_ty = tables. intern_ty ( ty) ;
450
+ let id = tables. intern_mir_const ( mir:: Const :: Ty ( ty, ty_const) ) ;
451
+ stable_mir:: ty:: MirConst :: new ( kind, stable_ty, id)
452
+ }
453
+
412
454
impl < ' tcx > Stable < ' tcx > for ty:: Const < ' tcx > {
413
455
type T = stable_mir:: ty:: TyConst ;
414
456
0 commit comments