From 5888556efe102f855f273cd1a7b343fe08d8fc76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Mon, 15 Feb 2021 00:00:00 +0000 Subject: [PATCH] Pass ImmTy by reference not value --- compiler/rustc_mir/src/interpret/cast.rs | 8 ++++---- compiler/rustc_mir/src/interpret/intern.rs | 2 +- compiler/rustc_mir/src/interpret/intrinsics.rs | 2 +- compiler/rustc_mir/src/interpret/place.rs | 6 +++--- compiler/rustc_mir/src/interpret/validity.rs | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_mir/src/interpret/cast.rs b/compiler/rustc_mir/src/interpret/cast.rs index 04c3fad3a13..2d9e6df0ab8 100644 --- a/compiler/rustc_mir/src/interpret/cast.rs +++ b/compiler/rustc_mir/src/interpret/cast.rs @@ -32,7 +32,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Misc => { let src = self.read_immediate(src)?; - let res = self.misc_cast(src, cast_ty)?; + let res = self.misc_cast(&src, cast_ty)?; self.write_immediate(res, dest)?; } @@ -107,7 +107,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { fn misc_cast( &self, - src: ImmTy<'tcx, M::PointerTag>, + src: &ImmTy<'tcx, M::PointerTag>, cast_ty: Ty<'tcx>, ) -> InterpResult<'tcx, Immediate> { use rustc_middle::ty::TyKind::*; @@ -158,13 +158,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let dest_layout = self.layout_of(cast_ty)?; if dest_layout.size == src.layout.size { // Thin or fat pointer that just hast the ptr kind of target type changed. - return Ok(*src); + return Ok(**src); } else { // Casting the metadata away from a fat ptr. assert_eq!(src.layout.size, 2 * self.memory.pointer_size()); assert_eq!(dest_layout.size, self.memory.pointer_size()); assert!(src.layout.ty.is_unsafe_ptr()); - return match *src { + return match **src { Immediate::ScalarPair(data, _) => Ok(data.into()), Immediate::Scalar(..) => span_bug!( self.cur_span(), diff --git a/compiler/rustc_mir/src/interpret/intern.rs b/compiler/rustc_mir/src/interpret/intern.rs index 7f0b74cf6e5..2eba2c4e533 100644 --- a/compiler/rustc_mir/src/interpret/intern.rs +++ b/compiler/rustc_mir/src/interpret/intern.rs @@ -198,7 +198,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory let ty = mplace.layout.ty; if let ty::Ref(_, referenced_ty, ref_mutability) = *ty.kind() { let value = self.ecx.read_immediate(&(*mplace).into())?; - let mplace = self.ecx.ref_to_mplace(value)?; + let mplace = self.ecx.ref_to_mplace(&value)?; assert_eq!(mplace.layout.ty, referenced_ty); // Handle trait object vtables. if let ty::Dynamic(..) = diff --git a/compiler/rustc_mir/src/interpret/intrinsics.rs b/compiler/rustc_mir/src/interpret/intrinsics.rs index 7c53fcbb955..ab1ab69c8d5 100644 --- a/compiler/rustc_mir/src/interpret/intrinsics.rs +++ b/compiler/rustc_mir/src/interpret/intrinsics.rs @@ -143,7 +143,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { sym::min_align_of_val | sym::size_of_val => { // Avoid `deref_operand` -- this is not a deref, the ptr does not have to be // dereferencable! - let place = self.ref_to_mplace(self.read_immediate(&args[0])?)?; + let place = self.ref_to_mplace(&self.read_immediate(&args[0])?)?; let (size, align) = self .size_and_align_of_mplace(place)? .ok_or_else(|| err_unsup_format!("`extern type` does not have known layout"))?; diff --git a/compiler/rustc_mir/src/interpret/place.rs b/compiler/rustc_mir/src/interpret/place.rs index 5dbb49018a6..f86a87c88f4 100644 --- a/compiler/rustc_mir/src/interpret/place.rs +++ b/compiler/rustc_mir/src/interpret/place.rs @@ -303,12 +303,12 @@ where /// Generally prefer `deref_operand`. pub fn ref_to_mplace( &self, - val: ImmTy<'tcx, M::PointerTag>, + val: &ImmTy<'tcx, M::PointerTag>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { let pointee_type = val.layout.ty.builtin_deref(true).expect("`ref_to_mplace` called on non-ptr type").ty; let layout = self.layout_of(pointee_type)?; - let (ptr, meta) = match *val { + let (ptr, meta) = match **val { Immediate::Scalar(ptr) => (ptr.check_init()?, MemPlaceMeta::None), Immediate::ScalarPair(ptr, meta) => { (ptr.check_init()?, MemPlaceMeta::Meta(meta.check_init()?)) @@ -335,7 +335,7 @@ where ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { let val = self.read_immediate(src)?; trace!("deref to {} on {:?}", val.layout.ty, *val); - let place = self.ref_to_mplace(val)?; + let place = self.ref_to_mplace(&val)?; self.mplace_access_checked(place, None) } diff --git a/compiler/rustc_mir/src/interpret/validity.rs b/compiler/rustc_mir/src/interpret/validity.rs index 9c2ae1c7fe3..766c7a299e8 100644 --- a/compiler/rustc_mir/src/interpret/validity.rs +++ b/compiler/rustc_mir/src/interpret/validity.rs @@ -386,7 +386,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' // Handle wide pointers. // Check metadata early, for better diagnostics let place = try_validation!( - self.ecx.ref_to_mplace(value), + self.ecx.ref_to_mplace(&value), self.path, err_ub!(InvalidUninitBytes(None)) => { "uninitialized {}", kind }, );