about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_const_eval/src/interpret/place.rs28
-rw-r--r--compiler/rustc_const_eval/src/interpret/step.rs20
2 files changed, 29 insertions, 19 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs
index 5c00dc21d04..8d4d0420cda 100644
--- a/compiler/rustc_const_eval/src/interpret/place.rs
+++ b/compiler/rustc_const_eval/src/interpret/place.rs
@@ -846,6 +846,34 @@ where
         Ok(())
     }
 
+    /// Writes the discriminant of the given variant.
+    #[instrument(skip(self), level = "debug")]
+    pub fn write_aggregate(
+        &mut self,
+        kind: &mir::AggregateKind<'tcx>,
+        operands: &[mir::Operand<'tcx>],
+        dest: &PlaceTy<'tcx, M::Provenance>,
+    ) -> InterpResult<'tcx> {
+        self.write_uninit(&dest)?;
+        let (variant_index, variant_dest, active_field_index) = match *kind {
+            mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
+                let variant_dest = self.place_downcast(&dest, variant_index)?;
+                (variant_index, variant_dest, active_field_index)
+            }
+            _ => (VariantIdx::from_u32(0), dest.clone(), None),
+        };
+        if active_field_index.is_some() {
+            assert_eq!(operands.len(), 1);
+        }
+        for (field_index, operand) in operands.iter().enumerate() {
+            let field_index = active_field_index.unwrap_or(field_index);
+            let field_dest = self.place_field(&variant_dest, field_index)?;
+            let op = self.eval_operand(operand, Some(field_dest.layout))?;
+            self.copy_op(&op, &field_dest, /*allow_transmute*/ false)?;
+        }
+        self.write_discriminant(variant_index, &dest)
+    }
+
     pub fn raw_const_to_mplace(
         &self,
         raw: ConstAlloc<'tcx>,
diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs
index 7e00d90342e..7d9a98da08a 100644
--- a/compiler/rustc_const_eval/src/interpret/step.rs
+++ b/compiler/rustc_const_eval/src/interpret/step.rs
@@ -7,7 +7,6 @@ use either::Either;
 use rustc_middle::mir;
 use rustc_middle::mir::interpret::{InterpResult, Scalar};
 use rustc_middle::ty::layout::LayoutOf;
-use rustc_target::abi::VariantIdx;
 
 use super::{ImmTy, InterpCx, Machine};
 
@@ -200,24 +199,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
             }
 
             Aggregate(box ref kind, ref operands) => {
-                self.write_uninit(&dest)?;
-                let (variant_index, variant_dest, active_field_index) = match *kind {
-                    mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
-                        let variant_dest = self.place_downcast(&dest, variant_index)?;
-                        (variant_index, variant_dest, active_field_index)
-                    }
-                    _ => (VariantIdx::from_u32(0), dest.clone(), None),
-                };
-                if active_field_index.is_some() {
-                    assert_eq!(operands.len(), 1);
-                }
-                for (field_index, operand) in operands.iter().enumerate() {
-                    let field_index = active_field_index.unwrap_or(field_index);
-                    let field_dest = self.place_field(&variant_dest, field_index)?;
-                    let op = self.eval_operand(operand, Some(field_dest.layout))?;
-                    self.copy_op(&op, &field_dest, /*allow_transmute*/ false)?;
-                }
-                self.write_discriminant(variant_index, &dest)?;
+                self.write_aggregate(kind, operands, &dest)?;
             }
 
             Repeat(ref operand, _) => {