summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
diff options
context:
space:
mode:
authorb-naber <bn263@gmx.de>2022-06-27 16:32:47 +0200
committerb-naber <bn263@gmx.de>2022-09-13 17:40:59 +0200
commita4bbb8db5c4c702265b8afcc1313684a127ddd6a (patch)
treef1643aa200cd35761c02faf68189ec86276fb0d9 /compiler/rustc_const_eval/src/interpret
parent7098c181f8447810fadb1776d3ffa3cdc93ce402 (diff)
downloadrust-a4bbb8db5c4c702265b8afcc1313684a127ddd6a.tar.gz
rust-a4bbb8db5c4c702265b8afcc1313684a127ddd6a.zip
use ty::Unevaluated<'tcx, ()> in type system
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
-rw-r--r--compiler/rustc_const_eval/src/interpret/operand.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs
index f6c4f7dd112..9784de1fffc 100644
--- a/compiler/rustc_const_eval/src/interpret/operand.rs
+++ b/compiler/rustc_const_eval/src/interpret/operand.rs
@@ -565,7 +565,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
             }
             ty::ConstKind::Unevaluated(uv) => {
                 let instance = self.resolve(uv.def, uv.substs)?;
-                Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into())
+                Ok(self.eval_to_allocation(GlobalId { instance, promoted: None })?.into())
             }
             ty::ConstKind::Bound(..) | ty::ConstKind::Infer(..) => {
                 span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", c)
@@ -578,6 +578,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
         }
     }
 
+    /// Tries to evaluate an unevaluated constant from the MIR (and not the type-system).
+    #[inline]
+    pub fn uneval_to_op(
+        &self,
+        uneval: &ty::Unevaluated<'tcx>,
+    ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
+        let instance = self.resolve(uneval.def, uneval.substs)?;
+        Ok(self.eval_to_allocation(GlobalId { instance, promoted: None })?.into())
+    }
+
     pub fn mir_const_to_op(
         &self,
         val: &mir::ConstantKind<'tcx>,
@@ -586,6 +596,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
         match val {
             mir::ConstantKind::Ty(ct) => self.const_to_op(*ct, layout),
             mir::ConstantKind::Val(val, ty) => self.const_val_to_op(*val, *ty, layout),
+            mir::ConstantKind::Unevaluated(uv, _) => self.uneval_to_op(uv),
         }
     }