@@ -7,14 +7,15 @@ use rustc_hir::{self as hir, def_id::DefId, definitions::DefPathData};
77use rustc_index:: vec:: IndexVec ;
88use rustc_macros:: HashStable ;
99use rustc_middle:: mir;
10+ use rustc_middle:: mir:: interpret:: { InterpError , InvalidProgramInfo } ;
1011use rustc_middle:: ty:: layout:: { self , LayoutError , LayoutOf , LayoutOfHelpers , TyAndLayout } ;
1112use rustc_middle:: ty:: {
1213 self , query:: TyCtxtAt , subst:: SubstsRef , ParamEnv , Ty , TyCtxt , TypeFoldable ,
1314} ;
1415use rustc_mir_dataflow:: storage:: AlwaysLiveLocals ;
1516use rustc_query_system:: ich:: StableHashingContext ;
1617use rustc_session:: Limit ;
17- use rustc_span:: { Pos , Span } ;
18+ use rustc_span:: { Pos , Span , DUMMY_SP } ;
1819use rustc_target:: abi:: { Align , HasDataLayout , Size , TargetDataLayout } ;
1920
2021use super :: {
@@ -508,7 +509,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
508509 pub ( super ) fn subst_from_current_frame_and_normalize_erasing_regions < T : TypeFoldable < ' tcx > > (
509510 & self ,
510511 value : T ,
511- ) -> T {
512+ ) -> Result < T , InterpError < ' tcx > > {
512513 self . subst_from_frame_and_normalize_erasing_regions ( self . frame ( ) , value)
513514 }
514515
@@ -518,8 +519,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
518519 & self ,
519520 frame : & Frame < ' mir , ' tcx , M :: PointerTag , M :: FrameExtra > ,
520521 value : T ,
521- ) -> T {
522- frame. instance . subst_mir_and_normalize_erasing_regions ( * self . tcx , self . param_env , value)
522+ ) -> Result < T , InterpError < ' tcx > > {
523+ frame
524+ . instance
525+ . try_subst_mir_and_normalize_erasing_regions ( * self . tcx , self . param_env , value)
526+ . or_else ( |e| {
527+ self . tcx . sess . delay_span_bug (
528+ DUMMY_SP ,
529+ format ! ( "failed to normalize {}" , e. get_type_for_failure( ) ) . as_str ( ) ,
530+ ) ;
531+
532+ Err ( InterpError :: InvalidProgram ( InvalidProgramInfo :: TooGeneric ) )
533+ } )
523534 }
524535
525536 /// The `substs` are assumed to already be in our interpreter "universe" (param_env).
@@ -554,7 +565,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
554565 let layout = from_known_layout ( self . tcx , self . param_env , layout, || {
555566 let local_ty = frame. body . local_decls [ local] . ty ;
556567 let local_ty =
557- self . subst_from_frame_and_normalize_erasing_regions ( frame, local_ty) ;
568+ self . subst_from_frame_and_normalize_erasing_regions ( frame, local_ty) ? ;
558569 self . layout_of ( local_ty)
559570 } ) ?;
560571 if let Some ( state) = frame. locals . get ( local) {
@@ -702,7 +713,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
702713 for const_ in & body. required_consts {
703714 let span = const_. span ;
704715 let const_ =
705- self . subst_from_current_frame_and_normalize_erasing_regions ( const_. literal ) ;
716+ self . subst_from_current_frame_and_normalize_erasing_regions ( const_. literal ) ? ;
706717 self . mir_const_to_op ( & const_, None ) . map_err ( |err| {
707718 // If there was an error, set the span of the current frame to this constant.
708719 // Avoiding doing this when evaluation succeeds.
0 commit comments