]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/interpret/operand.rs
Add a `const_eval` helper to `InterpCx`
[rust.git] / src / librustc_mir / interpret / operand.rs
index a89abe71c654fb7ba46dc9d207bc11fb57d3b2ed..fc63847433b5c0859a7402d04545b56d6a2ff553 100644 (file)
@@ -578,12 +578,14 @@ pub(super) fn eval_operands(
             ty::ConstKind::Param(_) => throw_inval!(TooGeneric),
             ty::ConstKind::Unevaluated(def_id, substs) => {
                 let instance = self.resolve(def_id, substs)?;
-                return Ok(OpTy::from(self.const_eval_raw(GlobalId { instance, promoted: None })?));
-            }
-            ty::ConstKind::Infer(..)
-            | ty::ConstKind::Bound(..)
-            | ty::ConstKind::Placeholder(..) => {
-                bug!("eval_const_to_op: Unexpected ConstKind {:?}", val)
+                // We use `const_eval` here and `const_eval_raw` elsewhere in mir interpretation.
+                // The reason we use `const_eval_raw` everywhere else is to prevent cycles during
+                // validation, because validation automatically reads through any references, thus
+                // potentially requiring the current static to be evaluated again. This is not a
+                // problem here, because we need an operand and operands are always reads.
+                // FIXME(oli-obk): eliminate all the `const_eval_raw` usages when we get rid of
+                // `StaticKind` once and for all.
+                return self.const_eval(GlobalId { instance, promoted: None });
             }
             ty::ConstKind::Value(val_val) => val_val,
         };