diff options
| -rw-r--r-- | src/librustc_mir/const_eval/eval_queries.rs | 15 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/place.rs | 17 |
2 files changed, 14 insertions, 18 deletions
diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index f28517c6672..b0add10dcac 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -117,12 +117,23 @@ pub(super) fn op_to_const<'tcx>( // structs containing such. op.try_as_mplace(ecx) }; + + let to_const_value = |mplace: MPlaceTy<'_>| match mplace.ptr { + Scalar::Ptr(ptr) => { + let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id); + ConstValue::ByRef { alloc, offset: ptr.offset } + } + Scalar::Raw { data, .. } => { + assert_eq!(data, mplace.layout.align.abi.bytes().into()); + ConstValue::Scalar(Scalar::zst()) + } + }; let val = match immediate { - Ok(mplace) => mplace.to_const_value(ecx.tcx.tcx), + Ok(mplace) => to_const_value(mplace), // see comment on `let try_as_immediate` above Err(ImmTy { imm: Immediate::Scalar(x), .. }) => match x { ScalarMaybeUndef::Scalar(s) => ConstValue::Scalar(s), - ScalarMaybeUndef::Undef => op.assert_mem_place(ecx).to_const_value(ecx.tcx.tcx), + ScalarMaybeUndef::Undef => to_const_value(op.assert_mem_place(ecx)), }, Err(ImmTy { imm: Immediate::ScalarPair(a, b), .. }) => { let (data, start) = match a.not_undef().unwrap() { diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 54a692c66e3..c8499d845dd 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -6,13 +6,12 @@ use std::convert::TryFrom; use std::hash::Hash; use rustc::mir; -use rustc::mir::interpret::{truncate, ConstValue}; +use rustc::mir::interpret::truncate; use rustc::ty::layout::{ self, Align, HasDataLayout, LayoutOf, PrimitiveExt, Size, TyLayout, VariantIdx, }; use rustc::ty::TypeFoldable; use rustc::ty::{self, Ty}; -use rustc::ty::{self, Ty, TyCtxt}; use rustc_macros::HashStable; use super::{ @@ -196,20 +195,6 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> { _ => bug!("vtable not supported on type {:?}", self.layout.ty), } } - - #[inline(always)] - pub fn to_const_value(self, tcx: TyCtxt<'tcx>) -> ConstValue<'tcx> { - match self.mplace.ptr { - Scalar::Ptr(ptr) => { - let alloc = tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id); - ConstValue::ByRef { alloc, offset: ptr.offset } - } - Scalar::Raw { data, .. } => { - assert_eq!(data, self.layout.align.abi.bytes().into()); - ConstValue::Scalar(Scalar::zst()) - } - } - } } // These are defined here because they produce a place. |
