@@ -7,14 +7,15 @@ use rustc_hir::{self as hir, def_id::DefId, definitions::DefPathData};
7
7
use rustc_index:: vec:: IndexVec ;
8
8
use rustc_macros:: HashStable ;
9
9
use rustc_middle:: mir;
10
+ use rustc_middle:: mir:: interpret:: { InterpError , InvalidProgramInfo } ;
10
11
use rustc_middle:: ty:: layout:: { self , LayoutError , LayoutOf , LayoutOfHelpers , TyAndLayout } ;
11
12
use rustc_middle:: ty:: {
12
13
self , query:: TyCtxtAt , subst:: SubstsRef , ParamEnv , Ty , TyCtxt , TypeFoldable ,
13
14
} ;
14
15
use rustc_mir_dataflow:: storage:: AlwaysLiveLocals ;
15
16
use rustc_query_system:: ich:: StableHashingContext ;
16
17
use rustc_session:: Limit ;
17
- use rustc_span:: { Pos , Span } ;
18
+ use rustc_span:: { Pos , Span , DUMMY_SP } ;
18
19
use rustc_target:: abi:: { Align , HasDataLayout , Size , TargetDataLayout } ;
19
20
20
21
use super :: {
@@ -508,7 +509,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
508
509
pub ( super ) fn subst_from_current_frame_and_normalize_erasing_regions < T : TypeFoldable < ' tcx > > (
509
510
& self ,
510
511
value : T ,
511
- ) -> T {
512
+ ) -> Result < T , InterpError < ' tcx > > {
512
513
self . subst_from_frame_and_normalize_erasing_regions ( self . frame ( ) , value)
513
514
}
514
515
@@ -518,8 +519,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
518
519
& self ,
519
520
frame : & Frame < ' mir , ' tcx , M :: PointerTag , M :: FrameExtra > ,
520
521
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
+ } )
523
534
}
524
535
525
536
/// 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> {
554
565
let layout = from_known_layout ( self . tcx , self . param_env , layout, || {
555
566
let local_ty = frame. body . local_decls [ local] . ty ;
556
567
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) ? ;
558
569
self . layout_of ( local_ty)
559
570
} ) ?;
560
571
if let Some ( state) = frame. locals . get ( local) {
@@ -702,7 +713,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
702
713
for const_ in & body. required_consts {
703
714
let span = const_. span ;
704
715
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 ) ? ;
706
717
self . mir_const_to_op ( & const_, None ) . map_err ( |err| {
707
718
// If there was an error, set the span of the current frame to this constant.
708
719
// Avoiding doing this when evaluation succeeds.
0 commit comments