1- use rustc:: ty:: { self , Ty } ;
1+ use rustc:: ty:: { self , Instance , Ty } ;
2+ use rustc:: ty:: subst:: Subst ;
23use rustc:: ty:: layout:: { self , Align , TyLayout , LayoutOf , VariantIdx , HasTyCtxt } ;
34use rustc:: mir;
45use rustc:: mir:: tcx:: PlaceTy ;
@@ -454,16 +455,25 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
454455 mir:: PlaceRef {
455456 base : mir:: PlaceBase :: Static ( box mir:: Static {
456457 ty,
457- kind : mir:: StaticKind :: Promoted ( promoted) ,
458+ kind : mir:: StaticKind :: Promoted ( promoted, substs) ,
459+ def_id,
458460 } ) ,
459461 projection : None ,
460462 } => {
463+ debug ! ( "promoted={:?}, def_id={:?}, substs={:?}, self_substs={:?}" , promoted, def_id, substs, self . instance. substs) ;
461464 let param_env = ty:: ParamEnv :: reveal_all ( ) ;
465+ let instance = Instance :: new ( * def_id, substs. subst ( bx. tcx ( ) , self . instance . substs ) ) ;
466+ debug ! ( "instance: {:?}" , instance) ;
462467 let cid = mir:: interpret:: GlobalId {
463- instance : self . instance ,
468+ instance : instance,
464469 promoted : Some ( * promoted) ,
465470 } ;
466- let layout = cx. layout_of ( self . monomorphize ( & ty) ) ;
471+ let mono_ty = tcx. subst_and_normalize_erasing_regions (
472+ instance. substs ,
473+ param_env,
474+ ty,
475+ ) ;
476+ let layout = cx. layout_of ( mono_ty) ;
467477 match bx. tcx ( ) . const_eval ( param_env. and ( cid) ) {
468478 Ok ( val) => match val. val {
469479 mir:: interpret:: ConstValue :: ByRef { alloc, offset } => {
@@ -487,7 +497,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
487497 mir:: PlaceRef {
488498 base : mir:: PlaceBase :: Static ( box mir:: Static {
489499 ty,
490- kind : mir:: StaticKind :: Static ( def_id) ,
500+ kind : mir:: StaticKind :: Static ,
501+ def_id,
491502 } ) ,
492503 projection : None ,
493504 } => {
0 commit comments