about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2019-12-20 12:31:52 +0100
committerOliver Scherer <github35764891676564198441@oli-obk.de>2019-12-26 22:50:17 +0100
commita7a011d2fa97530f30ff2e7112c04723ba611152 (patch)
treea8e97ae3ad57ded920706bfb6def3e90658dee5a
parent0e969b73f6f633187a829111d3e80423e85fd513 (diff)
downloadrust-a7a011d2fa97530f30ff2e7112c04723ba611152.tar.gz
rust-a7a011d2fa97530f30ff2e7112c04723ba611152.zip
Immediately evaluate and validate constants when we want them as operands
-rw-r--r--src/librustc_mir/interpret/operand.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs
index 82974f338d2..110dadbfb37 100644
--- a/src/librustc_mir/interpret/operand.rs
+++ b/src/librustc_mir/interpret/operand.rs
@@ -578,9 +578,16 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
             ty::ConstKind::Param(_) => throw_inval!(TooGeneric),
             ty::ConstKind::Unevaluated(def_id, substs) => {
                 let instance = self.resolve(def_id, substs)?;
-                // FIXME: don't use `const_eval_raw` for regular constants, instead use `const_eval`
-                // which immediately validates the result before we continue with it here.
-                return Ok(OpTy::from(self.const_eval_raw(GlobalId { instance, promoted: None })?));
+                let param_env = if self.tcx.is_static(def_id) {
+                    ty::ParamEnv::reveal_all()
+                } else {
+                    self.param_env
+                };
+                let val =
+                    self.tcx.const_eval(param_env.and(GlobalId { instance, promoted: None }))?;
+                // "recurse". This is only ever going into a recusion depth of 1, because after
+                // `const_eval` we don't have `Unevaluated` anymore.
+                return self.eval_const_to_op(val, layout);
             }
             ty::ConstKind::Value(val_val) => val_val,
         };