From 5dd0375ae0ae0b2995c3be738a1da7bf774402d3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 18 Oct 2018 11:59:56 +0200 Subject: [PATCH] turn casts-to-raw into a proper raw-reborrow; that is just cleaner --- src/librustc_mir/interpret/cast.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index 62c42c4a4938..ff07f44ac5fd 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -37,7 +37,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> kind: CastKind, dest: PlaceTy<'tcx, M::PointerTag>, ) -> EvalResult<'tcx> { - let src_layout = src.layout; use rustc::mir::CastKind::*; match kind { Unsize => { @@ -45,29 +44,28 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> } Misc => { + let src_layout = src.layout; let src = self.read_value(src)?; - if M::ENABLE_PTR_TRACKING_HOOKS && - src.layout.ty.is_region_ptr() && dest.layout.ty.is_unsafe_ptr() - { + let src = if M::ENABLE_PTR_TRACKING_HOOKS && src_layout.ty.is_region_ptr() { + // The only `Misc` casts on references are those creating raw pointers. + assert!(dest.layout.ty.is_unsafe_ptr()); // For the purpose of the "ptr tag hooks", treat this as creating // a new, raw reference. let place = self.ref_to_mplace(src)?; - let _val = self.create_ref(place, None)?; - // FIXME: The blog post said we should now also erase the tag. - // That would amount to using `_val` instead of `src` from here on. - // However, do we really want to do that? `transmute` doesn't - // do it either and we have to support that, somehow. - } + self.create_ref(place, None)? + } else { + *src + }; - if self.type_is_fat_ptr(src.layout.ty) { - match (*src, self.type_is_fat_ptr(dest.layout.ty)) { + if self.type_is_fat_ptr(src_layout.ty) { + match (src, self.type_is_fat_ptr(dest.layout.ty)) { // pointers to extern types (Value::Scalar(_),_) | // slices and trait objects to other slices/trait objects (Value::ScalarPair(..), true) => { // No change to value - self.write_value(*src, dest)?; + self.write_value(src, dest)?; } // slices and trait objects to thin pointers (dropping the metadata) (Value::ScalarPair(data, _), false) => { @@ -79,7 +77,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> layout::Variants::Single { index } => { if let Some(def) = src_layout.ty.ty_adt_def() { // Cast from a univariant enum - assert!(src.layout.is_zst()); + assert!(src_layout.is_zst()); let discr_val = def .discriminant_for_variant(*self.tcx, index) .val;