@@ -9,16 +9,16 @@ use rustc_data_structures::fx::FxHashMap;
9
9
use rustc_hir:: def:: DefKind ;
10
10
use rustc_middle:: mir:: interpret:: { AllocId , ConstAllocation , InterpResult , Scalar } ;
11
11
use rustc_middle:: mir:: visit:: { MutVisitor , PlaceContext , Visitor } ;
12
- use rustc_middle:: mir:: * ;
12
+ use rustc_middle:: mir:: { self , * } ;
13
13
use rustc_middle:: query:: TyCtxtAt ;
14
- use rustc_middle:: ty:: layout:: { LayoutOf , TyAndLayout } ;
14
+ use rustc_middle:: ty:: layout:: { HasParamEnv , LayoutOf , TyAndLayout } ;
15
15
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
16
16
use rustc_mir_dataflow:: value_analysis:: {
17
17
Map , PlaceIndex , State , TrackElem , ValueAnalysis , ValueAnalysisWrapper , ValueOrPlace ,
18
18
} ;
19
19
use rustc_mir_dataflow:: { lattice:: FlatSet , Analysis , Results , ResultsVisitor } ;
20
20
use rustc_span:: def_id:: DefId ;
21
- use rustc_span:: DUMMY_SP ;
21
+ use rustc_span:: { Span , DUMMY_SP } ;
22
22
use rustc_target:: abi:: { Abi , FieldIdx , Size , VariantIdx , FIRST_VARIANT } ;
23
23
24
24
/// Macro for machine-specific `InterpError` without allocation.
@@ -393,7 +393,9 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
393
393
}
394
394
}
395
395
Operand :: Constant ( box constant) => {
396
- if let Ok ( constant) = self . ecx . eval_mir_constant ( & constant. const_ , None , None ) {
396
+ if let Ok ( constant) =
397
+ DummyMachine :: eval_mir_constant ( & self . ecx , & constant. const_ , None )
398
+ {
397
399
self . assign_constant ( state, place, constant, & [ ] ) ;
398
400
}
399
401
}
@@ -889,6 +891,23 @@ impl<'tcx> Visitor<'tcx> for OperandCollector<'tcx, '_, '_, '_> {
889
891
890
892
pub ( crate ) struct DummyMachine ;
891
893
894
+ impl DummyMachine {
895
+ /// Evaluate a MIR constant that doesn't have to be already pre-checked via `required_consts`.
896
+ pub fn eval_mir_constant < ' tcx > (
897
+ ecx : & InterpCx < ' _ , ' tcx , Self > ,
898
+ const_ : & mir:: Const < ' tcx > ,
899
+ span : Option < Span > ,
900
+ ) -> InterpResult < ' tcx , OpTy < ' tcx > > {
901
+ let const_val = const_. eval ( * ecx. tcx , ecx. param_env ( ) , span) . map_err ( |err| {
902
+ // This *may* be the only time we're actually evaluating this const, so show a note at
903
+ // the place it is used.
904
+ err. emit_note ( * ecx. tcx ) ;
905
+ err
906
+ } ) ?;
907
+ ecx. const_val_to_op ( const_val, const_. ty ( ) , None )
908
+ }
909
+ }
910
+
892
911
impl HasStaticRootDefId for DummyMachine {
893
912
fn static_def_id ( & self ) -> Option < rustc_hir:: def_id:: LocalDefId > {
894
913
None
0 commit comments