Skip to content

Commit 066ec12

Browse files
committed
Ensure that eval_to_allocation_raw isn't called on static items from miri
1 parent fec0b54 commit 066ec12

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -1074,17 +1074,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10741074
instance: ty::Instance<'tcx>,
10751075
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
10761076
let gid = GlobalId { instance, promoted: None };
1077-
// For statics we pick `ParamEnv::reveal_all`, because statics don't have generics
1078-
// and thus don't care about the parameter environment. While we could just use
1079-
// `self.param_env`, that would mean we invoke the query to evaluate the static
1080-
// with different parameter environments, thus causing the static to be evaluated
1081-
// multiple times.
1082-
let param_env = if self.tcx.is_static(gid.instance.def_id()) {
1083-
ty::ParamEnv::reveal_all()
1077+
let val = if self.tcx.is_static(gid.instance.def_id()) {
1078+
let alloc_id = self.tcx.reserve_and_set_static_alloc(gid.instance.def_id());
1079+
1080+
let ty = instance.ty(self.tcx.tcx, self.param_env);
1081+
mir::ConstAlloc { alloc_id, ty }
10841082
} else {
1085-
self.param_env
1083+
self.ctfe_query(|tcx| tcx.eval_to_allocation_raw(self.param_env.and(gid)))?
10861084
};
1087-
let val = self.ctfe_query(|tcx| tcx.eval_to_allocation_raw(param_env.and(gid)))?;
10881085
self.raw_const_to_mplace(val)
10891086
}
10901087

0 commit comments

Comments
 (0)