about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-10-18 11:59:56 +0200
committerRalf Jung <post@ralfj.de>2018-10-18 13:11:09 +0200
commit5dd0375ae0ae0b2995c3be738a1da7bf774402d3 (patch)
tree62c060a0db325deaeb26d9ffd34bbf2eb14d6b3c
parentc885d8b41e5cc22ae08447c7eadfc65a15a7af9a (diff)
downloadrust-5dd0375ae0ae0b2995c3be738a1da7bf774402d3.tar.gz
rust-5dd0375ae0ae0b2995c3be738a1da7bf774402d3.zip
turn casts-to-raw into a proper raw-reborrow; that is just cleaner
-rw-r--r--src/librustc_mir/interpret/cast.rs26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs
index 62c42c4a493..ff07f44ac5f 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;