@@ -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 > {
@@ -335,27 +327,27 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
335
327
trace ! ( "const eval: {:?} ({})" , key, instance) ;
336
328
}
337
329
338
- let cid = key. value ;
330
+ eval_in_interpreter ( tcx, key. value , key. param_env )
331
+ }
332
+
333
+ fn eval_in_interpreter < ' tcx , R : InterpretationResult < ' tcx > > (
334
+ tcx : TyCtxt < ' tcx > ,
335
+ cid : GlobalId < ' tcx > ,
336
+ param_env : ty:: ParamEnv < ' tcx > ,
337
+ ) -> Result < R , ErrorHandled > {
339
338
let def = cid. instance . def . def_id ( ) ;
340
339
let is_static = tcx. is_static ( def) ;
341
340
342
- let ecx = InterpCx :: new (
341
+ let mut ecx = InterpCx :: new (
343
342
tcx,
344
343
tcx. def_span ( def) ,
345
- key . param_env ,
344
+ param_env,
346
345
// Statics (and promoteds inside statics) may access mutable global memory, because unlike consts
347
346
// they do not have to behave "as if" they were evaluated at runtime.
348
347
// For consts however we want to ensure they behave "as if" they were evaluated at runtime,
349
348
// so we have to reject reading mutable global memory.
350
349
CompileTimeInterpreter :: new ( CanAccessMutGlobal :: from ( is_static) , CheckAlignment :: Error ) ,
351
350
) ;
352
- eval_in_interpreter ( ecx, cid)
353
- }
354
-
355
- fn eval_in_interpreter < ' mir , ' tcx , R : InterpretationResult < ' tcx > > (
356
- mut ecx : InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ,
357
- cid : GlobalId < ' tcx > ,
358
- ) -> Result < R , ErrorHandled > {
359
351
let res = ecx. load_mir ( cid. instance . def , cid. promoted ) ;
360
352
match res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) ) {
361
353
Err ( error) => {
0 commit comments