@@ -9,16 +9,16 @@ use rustc_data_structures::fx::FxHashMap;
99use rustc_hir:: def:: DefKind ;
1010use rustc_middle:: mir:: interpret:: { AllocId , ConstAllocation , InterpResult , Scalar } ;
1111use rustc_middle:: mir:: visit:: { MutVisitor , PlaceContext , Visitor } ;
12- use rustc_middle:: mir:: * ;
12+ use rustc_middle:: mir:: { self , * } ;
1313use rustc_middle:: query:: TyCtxtAt ;
14- use rustc_middle:: ty:: layout:: { LayoutOf , TyAndLayout } ;
14+ use rustc_middle:: ty:: layout:: { HasParamEnv , LayoutOf , TyAndLayout } ;
1515use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
1616use rustc_mir_dataflow:: value_analysis:: {
1717 Map , PlaceIndex , State , TrackElem , ValueAnalysis , ValueAnalysisWrapper , ValueOrPlace ,
1818} ;
1919use rustc_mir_dataflow:: { lattice:: FlatSet , Analysis , Results , ResultsVisitor } ;
2020use rustc_span:: def_id:: DefId ;
21- use rustc_span:: DUMMY_SP ;
21+ use rustc_span:: { Span , DUMMY_SP } ;
2222use rustc_target:: abi:: { Abi , FieldIdx , Size , VariantIdx , FIRST_VARIANT } ;
2323
2424/// Macro for machine-specific `InterpError` without allocation.
@@ -393,7 +393,9 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
393393 }
394394 }
395395 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+ {
397399 self . assign_constant ( state, place, constant, & [ ] ) ;
398400 }
399401 }
@@ -889,6 +891,23 @@ impl<'tcx> Visitor<'tcx> for OperandCollector<'tcx, '_, '_, '_> {
889891
890892pub ( crate ) struct DummyMachine ;
891893
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+
892911impl HasStaticRootDefId for DummyMachine {
893912 fn static_def_id ( & self ) -> Option < rustc_hir:: def_id:: LocalDefId > {
894913 None
0 commit comments