about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <github35764891676564198441@oli-obk.de>2021-03-15 11:52:00 +0000
committerOli Scherer <github35764891676564198441@oli-obk.de>2021-03-15 12:06:52 +0000
commitf646c1e43445f5edff741c8572cb7d52bdb97ce1 (patch)
tree401f054c937f6b90003aa0ba1fa3a9859a26874f
parentbc8641a4877a15d4a3184c079e8548029d02d524 (diff)
downloadrust-f646c1e43445f5edff741c8572cb7d52bdb97ce1.tar.gz
rust-f646c1e43445f5edff741c8572cb7d52bdb97ce1.zip
Explain why we do not allow const_to_valtree to read from statics
-rw-r--r--compiler/rustc_mir/src/const_eval/mod.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_mir/src/const_eval/mod.rs b/compiler/rustc_mir/src/const_eval/mod.rs
index ca165f2c8cb..4086c18c3d2 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<ty::ValTree<'tcx>> {
-    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)
 }