From f646c1e43445f5edff741c8572cb7d52bdb97ce1 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 15 Mar 2021 11:52:00 +0000 Subject: [PATCH] Explain why we do not allow const_to_valtree to read from statics --- compiler/rustc_mir/src/const_eval/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir/src/const_eval/mod.rs b/compiler/rustc_mir/src/const_eval/mod.rs index ca165f2c8cbe..4086c18c3d20 100644 --- a/compiler/rustc_mir/src/const_eval/mod.rs +++ b/compiler/rustc_mir/src/const_eval/mod.rs @@ -44,7 +44,12 @@ pub(crate) fn const_to_valtree<'tcx>( param_env: ty::ParamEnv<'tcx>, raw: ConstAlloc<'tcx>, ) -> Option> { - let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false); + let ecx = mk_eval_cx( + tcx, DUMMY_SP, param_env, + // It is absolutely crucial for soundness that + // we do not read from static items or other mutable memory. + false, + ); let place = ecx.raw_const_to_mplace(raw).unwrap(); const_to_valtree_inner(&ecx, &place) }