diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2024-04-11 17:01:27 -0700 | 
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2024-04-21 11:08:37 -0700 | 
| commit | de64ff76f8abd65222f9f6db56e7652976c5339b (patch) | |
| tree | 396dcbf3c27c725c4ae2f2978ae9a72da610813d /compiler/rustc_const_eval/src/interpret/step.rs | |
| parent | 4f4442655ee755b68fc04386f243c637a64f8320 (diff) | |
| download | rust-de64ff76f8abd65222f9f6db56e7652976c5339b.tar.gz rust-de64ff76f8abd65222f9f6db56e7652976c5339b.zip | |
Use it in the library, and `InstSimplify` it away in the easy places
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/step.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/step.rs | 17 | 
1 files changed, 16 insertions, 1 deletions
| diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index c3f26da8a79..460cd377c8f 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -9,7 +9,7 @@ use rustc_middle::mir; use rustc_middle::ty::layout::LayoutOf; use rustc_target::abi::{FieldIdx, FIRST_VARIANT}; -use super::{ImmTy, InterpCx, InterpResult, Machine, PlaceTy, Projectable, Scalar}; +use super::{ImmTy, Immediate, InterpCx, InterpResult, Machine, PlaceTy, Projectable, Scalar}; use crate::util; impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { @@ -303,6 +303,21 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let variant_dest = self.project_downcast(dest, variant_index)?; (variant_index, variant_dest, active_field_index) } + mir::AggregateKind::RawPtr(..) => { + // Trying to `project_field` into pointers tends not to work, + // so build the `Immediate` from the parts directly. + let [data, meta] = &operands.raw else { + bug!("{kind:?} should have 2 operands, had {operands:?}"); + }; + let data = self.eval_operand(data, None)?; + let data = self.read_pointer(&data)?; + let meta = self.eval_operand(meta, None)?; + let meta = self.read_mem_place_meta(&meta)?; + let ptr_imm = Immediate::new_pointer_with_meta(data, meta, self); + let ptr = ImmTy::from_immediate(ptr_imm, dest.layout); + self.copy_op(&ptr, dest)?; + return Ok(()); + } _ => (FIRST_VARIANT, dest.clone(), None), }; if active_field_index.is_some() { | 
