@@ -59,7 +59,7 @@ pub(crate) fn eval_promoted<'a, 'mir, 'tcx>(
5959) -> EvalResult < ' tcx , MPlaceTy < ' tcx > > {
6060 let span = tcx. def_span ( cid. instance . def_id ( ) ) ;
6161 let mut ecx = mk_eval_cx ( tcx, span, param_env) ;
62- eval_body_using_ecx ( & mut ecx, cid, Some ( mir) , param_env)
62+ eval_body_using_ecx ( & mut ecx, cid, mir, param_env)
6363}
6464
6565fn mplace_to_const < ' tcx > (
@@ -107,37 +107,15 @@ fn op_to_const<'tcx>(
107107 ty:: Const { val, ty : op. layout . ty }
108108}
109109
110- fn eval_body_and_ecx < ' a , ' mir , ' tcx > (
111- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
112- cid : GlobalId < ' tcx > ,
113- mir : Option < & ' mir mir:: Mir < ' tcx > > ,
114- param_env : ty:: ParamEnv < ' tcx > ,
115- ) -> ( EvalResult < ' tcx , MPlaceTy < ' tcx > > , CompileTimeEvalContext < ' a , ' mir , ' tcx > ) {
116- // we start out with the best span we have
117- // and try improving it down the road when more information is available
118- let span = tcx. def_span ( cid. instance . def_id ( ) ) ;
119- let span = mir. map ( |mir| mir. span ) . unwrap_or ( span) ;
120- let mut ecx = InterpretCx :: new ( tcx. at ( span) , param_env, CompileTimeInterpreter :: new ( ) ) ;
121- let r = eval_body_using_ecx ( & mut ecx, cid, mir, param_env) ;
122- ( r, ecx)
123- }
124-
125110// Returns a pointer to where the result lives
126111fn eval_body_using_ecx < ' mir , ' tcx > (
127112 ecx : & mut CompileTimeEvalContext < ' _ , ' mir , ' tcx > ,
128113 cid : GlobalId < ' tcx > ,
129- mir : Option < & ' mir mir:: Mir < ' tcx > > ,
114+ mir : & ' mir mir:: Mir < ' tcx > ,
130115 param_env : ty:: ParamEnv < ' tcx > ,
131116) -> EvalResult < ' tcx , MPlaceTy < ' tcx > > {
132117 debug ! ( "eval_body_using_ecx: {:?}, {:?}" , cid, param_env) ;
133118 let tcx = ecx. tcx . tcx ;
134- let mut mir = match mir {
135- Some ( mir) => mir,
136- None => ecx. load_mir ( cid. instance . def ) ?,
137- } ;
138- if let Some ( index) = cid. promoted {
139- mir = & mir. promoted [ index] ;
140- }
141119 let layout = ecx. layout_of ( mir. return_ty ( ) . subst ( tcx, cid. instance . substs ) ) ?;
142120 assert ! ( !layout. is_unsized( ) ) ;
143121 let ret = ecx. allocate ( layout, MemoryKind :: Stack ) ;
@@ -618,8 +596,19 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
618596 return Err ( ErrorHandled :: Reported ) ;
619597 }
620598
621- let ( res, ecx) = eval_body_and_ecx ( tcx, cid, None , key. param_env ) ;
622- res. and_then ( |place| {
599+ let span = tcx. def_span ( cid. instance . def_id ( ) ) ;
600+ let mut ecx = InterpretCx :: new ( tcx. at ( span) , key. param_env , CompileTimeInterpreter :: new ( ) ) ;
601+
602+ let res = ecx. load_mir ( cid. instance . def ) ;
603+ res. map ( |mir| {
604+ if let Some ( index) = cid. promoted {
605+ & mir. promoted [ index]
606+ } else {
607+ mir
608+ }
609+ } ) . and_then (
610+ |mir| eval_body_using_ecx ( & mut ecx, cid, mir, key. param_env )
611+ ) . and_then ( |place| {
623612 Ok ( RawConst {
624613 alloc_id : place. to_ptr ( ) . expect ( "we allocated this ptr!" ) . alloc_id ,
625614 ty : place. layout . ty
0 commit comments