@@ -282,15 +282,7 @@ pub fn eval_static_initializer_provider<'tcx>(
282
282
283
283
let instance = ty:: Instance :: mono ( tcx, def_id. to_def_id ( ) ) ;
284
284
let cid = rustc_middle:: mir:: interpret:: GlobalId { instance, promoted : None } ;
285
- let ecx = InterpCx :: new (
286
- tcx,
287
- tcx. def_span ( def_id) ,
288
- ty:: ParamEnv :: reveal_all ( ) ,
289
- // Statics (and promoteds inside statics) may access other statics, because unlike consts
290
- // they do not have to behave "as if" they were evaluated at runtime.
291
- CompileTimeInterpreter :: new ( CanAccessMutGlobal :: Yes , CheckAlignment :: Error ) ,
292
- ) ;
293
- eval_in_interpreter ( ecx, cid)
285
+ eval_in_interpreter ( tcx, cid, ty:: ParamEnv :: reveal_all ( ) )
294
286
}
295
287
296
288
pub trait InterpretationResult < ' tcx > {
@@ -332,27 +324,27 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
332
324
trace ! ( "const eval: {:?} ({})" , key, instance) ;
333
325
}
334
326
335
- let cid = key. value ;
327
+ eval_in_interpreter ( tcx, key. value , key. param_env )
328
+ }
329
+
330
+ fn eval_in_interpreter < ' tcx , R : InterpretationResult < ' tcx > > (
331
+ tcx : TyCtxt < ' tcx > ,
332
+ cid : GlobalId < ' tcx > ,
333
+ param_env : ty:: ParamEnv < ' tcx > ,
334
+ ) -> Result < R , ErrorHandled > {
336
335
let def = cid. instance . def . def_id ( ) ;
337
336
let is_static = tcx. is_static ( def) ;
338
337
339
- let ecx = InterpCx :: new (
338
+ let mut ecx = InterpCx :: new (
340
339
tcx,
341
340
tcx. def_span ( def) ,
342
- key . param_env ,
341
+ param_env,
343
342
// Statics (and promoteds inside statics) may access mutable global memory, because unlike consts
344
343
// they do not have to behave "as if" they were evaluated at runtime.
345
344
// For consts however we want to ensure they behave "as if" they were evaluated at runtime,
346
345
// so we have to reject reading mutable global memory.
347
346
CompileTimeInterpreter :: new ( CanAccessMutGlobal :: from ( is_static) , CheckAlignment :: Error ) ,
348
347
) ;
349
- eval_in_interpreter ( ecx, cid)
350
- }
351
-
352
- fn eval_in_interpreter < ' mir , ' tcx , R : InterpretationResult < ' tcx > > (
353
- mut ecx : InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
354
- cid : GlobalId < ' tcx > ,
355
- ) -> Result < R , ErrorHandled > {
356
348
let res = ecx. load_mir ( cid. instance . def , cid. promoted ) ;
357
349
match res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) ) {
358
350
Err ( error) => {
0 commit comments