@@ -750,12 +750,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
750
750
751
751
// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
752
752
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
+ }
759
761
}
760
762
761
763
// done
@@ -1054,14 +1056,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1054
1056
Ok ( ( ) )
1055
1057
}
1056
1058
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.)
1058
1061
pub fn ctfe_query < T > (
1059
1062
& self ,
1060
- span : Option < Span > ,
1061
1063
query : impl FnOnce ( TyCtxtAt < ' tcx > ) -> Result < T , ErrorHandled > ,
1062
1064
) -> Result < T , ErrorHandled > {
1063
1065
// 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| {
1065
1067
err. emit_note ( * self . tcx ) ;
1066
1068
err
1067
1069
} )
@@ -1082,7 +1084,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1082
1084
} else {
1083
1085
self . param_env
1084
1086
} ;
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) ) ) ?;
1086
1088
self . raw_const_to_mplace ( val)
1087
1089
}
1088
1090
@@ -1092,7 +1094,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1092
1094
span : Option < Span > ,
1093
1095
layout : Option < TyAndLayout < ' tcx > > ,
1094
1096
) -> 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
+ } ) ?;
1096
1103
self . const_val_to_op ( const_val, val. ty ( ) , layout)
1097
1104
}
1098
1105
0 commit comments