@@ -750,12 +750,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
750750
751751 // Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
752752 if M :: POST_MONO_CHECKS {
753- // `ctfe_query` does some error message decoration that we want to be in effect here.
754- self . ctfe_query ( None , |tcx| {
755- body. post_mono_checks ( * tcx, self . param_env , |c| {
756- self . subst_from_current_frame_and_normalize_erasing_regions ( c)
757- } )
758- } ) ?;
753+ for & const_ in & body. required_consts {
754+ let c =
755+ self . subst_from_current_frame_and_normalize_erasing_regions ( const_. const_ ) ?;
756+ c. eval ( * self . tcx , self . param_env , Some ( const_. span ) ) . map_err ( |err| {
757+ err. emit_note ( * self . tcx ) ;
758+ err
759+ } ) ?;
760+ }
759761 }
760762
761763 // done
@@ -1054,14 +1056,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10541056 Ok ( ( ) )
10551057 }
10561058
1057- /// Call a query that can return `ErrorHandled`. If `span` is `Some`, point to that span when an error occurs.
1059+ /// Call a query that can return `ErrorHandled`. Should be used for statics and other globals.
1060+ /// (`mir::Const`/`ty::Const` have `eval` methods that can be used directly instead.)
10581061 pub fn ctfe_query < T > (
10591062 & self ,
1060- span : Option < Span > ,
10611063 query : impl FnOnce ( TyCtxtAt < ' tcx > ) -> Result < T , ErrorHandled > ,
10621064 ) -> Result < T , ErrorHandled > {
10631065 // Use a precise span for better cycle errors.
1064- query ( self . tcx . at ( span . unwrap_or_else ( || self . cur_span ( ) ) ) ) . map_err ( |err| {
1066+ query ( self . tcx . at ( self . cur_span ( ) ) ) . map_err ( |err| {
10651067 err. emit_note ( * self . tcx ) ;
10661068 err
10671069 } )
@@ -1082,7 +1084,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10821084 } else {
10831085 self . param_env
10841086 } ;
1085- let val = self . ctfe_query ( None , |tcx| tcx. eval_to_allocation_raw ( param_env. and ( gid) ) ) ?;
1087+ let val = self . ctfe_query ( |tcx| tcx. eval_to_allocation_raw ( param_env. and ( gid) ) ) ?;
10861088 self . raw_const_to_mplace ( val)
10871089 }
10881090
@@ -1092,7 +1094,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10921094 span : Option < Span > ,
10931095 layout : Option < TyAndLayout < ' tcx > > ,
10941096 ) -> InterpResult < ' tcx , OpTy < ' tcx , M :: Provenance > > {
1095- let const_val = self . ctfe_query ( span, |tcx| val. eval ( * tcx, self . param_env , span) ) ?;
1097+ let const_val = val. eval ( * self . tcx , self . param_env , span) . map_err ( |err| {
1098+ // FIXME: somehow this is reachable even when POST_MONO_CHECKS is on.
1099+ // Are we not always populating `required_consts`?
1100+ err. emit_note ( * self . tcx ) ;
1101+ err
1102+ } ) ?;
10961103 self . const_val_to_op ( const_val, val. ty ( ) , layout)
10971104 }
10981105
0 commit comments