about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-12-20 09:58:10 +0000
committerbors <bors@rust-lang.org>2018-12-20 09:58:10 +0000
commit4755e2f3b635ad7391ba88b18672b05cbae5ba4c (patch)
tree84bf0164c0a79f6b3f8e9f87fab480181e9606e0
parent817dda7df0164669487568fbcd33acb4ef512bc2 (diff)
parentc1160a8f8662c743170c895332f5c82ca26e4d4a (diff)
downloadrust-4755e2f3b635ad7391ba88b18672b05cbae5ba4c.tar.gz
rust-4755e2f3b635ad7391ba88b18672b05cbae5ba4c.zip
Auto merge of #56741 - RalfJung:retag-to-raw, r=oli-obk
treat ref-to-raw cast like a reborrow: do a special kind of retag

r? @oli-obk

Cc @nikomatsakis
-rw-r--r--src/librustc/ich/impls_mir.rs4
-rw-r--r--src/librustc/mir/mod.rs48
-rw-r--r--src/librustc/mir/visit.rs18
-rw-r--r--src/librustc_codegen_ssa/mir/statement.rs1
-rw-r--r--src/librustc_mir/borrow_check/mod.rs1
-rw-r--r--src/librustc_mir/borrow_check/nll/invalidation.rs1
-rw-r--r--src/librustc_mir/borrow_check/nll/type_check/mod.rs1
-rw-r--r--src/librustc_mir/dataflow/impls/borrows.rs1
-rw-r--r--src/librustc_mir/dataflow/move_paths/builder.rs1
-rw-r--r--src/librustc_mir/interpret/cast.rs20
-rw-r--r--src/librustc_mir/interpret/machine.rs12
-rw-r--r--src/librustc_mir/interpret/step.rs8
-rw-r--r--src/librustc_mir/shim.rs13
-rw-r--r--src/librustc_mir/transform/add_retag.rs55
-rw-r--r--src/librustc_mir/transform/check_unsafety.rs1
-rw-r--r--src/librustc_mir/transform/generator.rs2
-rw-r--r--src/librustc_mir/transform/inline.rs9
-rw-r--r--src/librustc_mir/transform/qualify_consts.rs1
-rw-r--r--src/librustc_mir/transform/qualify_min_const_fn.rs1
-rw-r--r--src/librustc_mir/transform/remove_noop_landing_pads.rs3
-rw-r--r--src/librustc_mir/transform/rustc_peek.rs1
-rw-r--r--src/test/mir-opt/retag.rs2
22 files changed, 76 insertions, 128 deletions
diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs
index a46e12be1ae..d82020f59a1 100644
--- a/src/librustc/ich/impls_mir.rs
+++ b/src/librustc/ich/impls_mir.rs
@@ -200,13 +200,13 @@ impl_stable_hash_for!(impl<'gcx> for enum mir::StatementKind<'gcx> [ mir::Statem
     SetDiscriminant { place, variant_index },
     StorageLive(place),
     StorageDead(place),
-    EscapeToRaw(place),
-    Retag { fn_entry, two_phase, place },
+    Retag(retag_kind, place),
     AscribeUserType(place, variance, c_ty),
     Nop,
     InlineAsm { asm, outputs, inputs },
 });
 
+impl_stable_hash_for!(enum mir::RetagKind { FnEntry, TwoPhase, Raw, Default });
 impl_stable_hash_for!(enum mir::FakeReadCause { ForMatchGuard, ForMatchedPlace, ForLet });
 
 impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Place<'gcx> {
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs
index 9dff3277917..dc14450e8d2 100644
--- a/src/librustc/mir/mod.rs
+++ b/src/librustc/mir/mod.rs
@@ -1788,23 +1788,7 @@ pub enum StatementKind<'tcx> {
     /// by miri and only generated when "-Z mir-emit-retag" is passed.
     /// See <https://internals.rust-lang.org/t/stacked-borrows-an-aliasing-model-for-rust/8153/>
     /// for more details.
-    Retag {
-        /// `fn_entry` indicates whether this is the initial retag that happens in the
-        /// function prolog.
-        fn_entry: bool,
-        /// `two_phase` indicates whether this is just the reservation action of
-        /// a two-phase borrow.
-        two_phase: bool,
-        /// The place to retag
-        place: Place<'tcx>,
-    },
-
-    /// Escape the given reference to a raw pointer, so that it can be accessed
-    /// without precise provenance tracking. These statements are currently only interpreted
-    /// by miri and only generated when "-Z mir-emit-retag" is passed.
-    /// See <https://internals.rust-lang.org/t/stacked-borrows-an-aliasing-model-for-rust/8153/>
-    /// for more details.
-    EscapeToRaw(Operand<'tcx>),
+    Retag(RetagKind, Place<'tcx>),
 
     /// Encodes a user's type ascription. These need to be preserved
     /// intact so that NLL can respect them. For example:
@@ -1824,6 +1808,19 @@ pub enum StatementKind<'tcx> {
     Nop,
 }
 
+/// `RetagKind` describes what kind of retag is to be performed.
+#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, PartialEq, Eq)]
+pub enum RetagKind {
+    /// The initial retag when entering a function
+    FnEntry,
+    /// Retag preparing for a two-phase borrow
+    TwoPhase,
+    /// Retagging raw pointers
+    Raw,
+    /// A "normal" retag
+    Default,
+}
+
 /// The `FakeReadCause` describes the type of pattern why a `FakeRead` statement exists.
 #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)]
 pub enum FakeReadCause {
@@ -1859,13 +1856,16 @@ impl<'tcx> Debug for Statement<'tcx> {
         match self.kind {
             Assign(ref place, ref rv) => write!(fmt, "{:?} = {:?}", place, rv),
             FakeRead(ref cause, ref place) => write!(fmt, "FakeRead({:?}, {:?})", cause, place),
-            Retag { fn_entry, two_phase, ref place } =>
-                write!(fmt, "Retag({}{}{:?})",
-                    if fn_entry { "[fn entry] " } else { "" },
-                    if two_phase { "[2phase] " } else { "" },
+            Retag(ref kind, ref place) =>
+                write!(fmt, "Retag({}{:?})",
+                    match kind {
+                        RetagKind::FnEntry => "[fn entry] ",
+                        RetagKind::TwoPhase => "[2phase] ",
+                        RetagKind::Raw => "[raw] ",
+                        RetagKind::Default => "",
+                    },
                     place,
                 ),
-            EscapeToRaw(ref place) => write!(fmt, "EscapeToRaw({:?})", place),
             StorageLive(ref place) => write!(fmt, "StorageLive({:?})", place),
             StorageDead(ref place) => write!(fmt, "StorageDead({:?})", place),
             SetDiscriminant {
@@ -2979,6 +2979,7 @@ CloneTypeFoldableAndLiftImpls! {
     SourceInfo,
     UpvarDecl,
     FakeReadCause,
+    RetagKind,
     SourceScope,
     SourceScopeData,
     SourceScopeLocalData,
@@ -3046,8 +3047,7 @@ EnumTypeFoldableImpl! {
         (StatementKind::StorageLive)(a),
         (StatementKind::StorageDead)(a),
         (StatementKind::InlineAsm) { asm, outputs, inputs },
-        (StatementKind::Retag) { fn_entry, two_phase, place },
-        (StatementKind::EscapeToRaw)(place),
+        (StatementKind::Retag)(kind, place),
         (StatementKind::AscribeUserType)(a, v, b),
         (StatementKind::Nop),
     }
diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs
index 237f6bc9c7b..278a4dc1d87 100644
--- a/src/librustc/mir/visit.rs
+++ b/src/librustc/mir/visit.rs
@@ -153,11 +153,10 @@ macro_rules! make_mir_visitor {
             }
 
             fn visit_retag(&mut self,
-                           fn_entry: & $($mutability)* bool,
-                           two_phase: & $($mutability)* bool,
+                           kind: & $($mutability)* RetagKind,
                            place: & $($mutability)* Place<'tcx>,
                            location: Location) {
-                self.super_retag(fn_entry, two_phase, place, location);
+                self.super_retag(kind, place, location);
             }
 
             fn visit_place(&mut self,
@@ -385,9 +384,6 @@ macro_rules! make_mir_visitor {
                             location
                         );
                     }
-                    StatementKind::EscapeToRaw(ref $($mutability)* op) => {
-                        self.visit_operand(op, location);
-                    }
                     StatementKind::StorageLive(ref $($mutability)* local) => {
                         self.visit_local(
                             local,
@@ -417,10 +413,9 @@ macro_rules! make_mir_visitor {
                             self.visit_operand(input, location);
                         }
                     }
-                    StatementKind::Retag { ref $($mutability)* fn_entry,
-                                           ref $($mutability)* two_phase,
-                                           ref $($mutability)* place } => {
-                        self.visit_retag(fn_entry, two_phase, place, location);
+                    StatementKind::Retag ( ref $($mutability)* kind,
+                                           ref $($mutability)* place ) => {
+                        self.visit_retag(kind, place, location);
                     }
                     StatementKind::AscribeUserType(
                         ref $($mutability)* place,
@@ -725,8 +720,7 @@ macro_rules! make_mir_visitor {
             }
 
             fn super_retag(&mut self,
-                           _fn_entry: & $($mutability)* bool,
-                           _two_phase: & $($mutability)* bool,
+                           _kind: & $($mutability)* RetagKind,
                            place: & $($mutability)* Place<'tcx>,
                            location: Location) {
                 self.visit_place(
diff --git a/src/librustc_codegen_ssa/mir/statement.rs b/src/librustc_codegen_ssa/mir/statement.rs
index 568a7e7e160..80539b78c70 100644
--- a/src/librustc_codegen_ssa/mir/statement.rs
+++ b/src/librustc_codegen_ssa/mir/statement.rs
@@ -106,7 +106,6 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
             }
             mir::StatementKind::FakeRead(..) |
             mir::StatementKind::Retag { .. } |
-            mir::StatementKind::EscapeToRaw { .. } |
             mir::StatementKind::AscribeUserType(..) |
             mir::StatementKind::Nop => bx,
         }
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs
index 6a2b6165f60..99cc4acb519 100644
--- a/src/librustc_mir/borrow_check/mod.rs
+++ b/src/librustc_mir/borrow_check/mod.rs
@@ -590,7 +590,6 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
             StatementKind::Nop
             | StatementKind::AscribeUserType(..)
             | StatementKind::Retag { .. }
-            | StatementKind::EscapeToRaw { .. }
             | StatementKind::StorageLive(..) => {
                 // `Nop`, `AscribeUserType`, `Retag`, and `StorageLive` are irrelevant
                 // to borrow check.
diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs
index 07bda8af626..d2810de284a 100644
--- a/src/librustc_mir/borrow_check/nll/invalidation.rs
+++ b/src/librustc_mir/borrow_check/nll/invalidation.rs
@@ -135,7 +135,6 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
             StatementKind::Nop |
             StatementKind::AscribeUserType(..) |
             StatementKind::Retag { .. } |
-            StatementKind::EscapeToRaw { .. } |
             StatementKind::StorageLive(..) => {
                 // `Nop`, `AscribeUserType`, `Retag`, and `StorageLive` are irrelevant
                 // to borrow check.
diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
index 9ae82b06766..0a363e931da 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
@@ -1316,7 +1316,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
             | StatementKind::StorageDead(..)
             | StatementKind::InlineAsm { .. }
             | StatementKind::Retag { .. }
-            | StatementKind::EscapeToRaw { .. }
             | StatementKind::Nop => {}
         }
     }
diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs
index f6732b0a0b0..078e2fd4980 100644
--- a/src/librustc_mir/dataflow/impls/borrows.rs
+++ b/src/librustc_mir/dataflow/impls/borrows.rs
@@ -324,7 +324,6 @@ impl<'a, 'gcx, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'gcx, 'tcx> {
             mir::StatementKind::SetDiscriminant { .. } |
             mir::StatementKind::StorageLive(..) |
             mir::StatementKind::Retag { .. } |
-            mir::StatementKind::EscapeToRaw { .. } |
             mir::StatementKind::AscribeUserType(..) |
             mir::StatementKind::Nop => {}
 
diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs
index 7fe27e97d3d..d201a355a2a 100644
--- a/src/librustc_mir/dataflow/move_paths/builder.rs
+++ b/src/librustc_mir/dataflow/move_paths/builder.rs
@@ -302,7 +302,6 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
                           "SetDiscriminant should not exist during borrowck");
             }
             StatementKind::Retag { .. } |
-            StatementKind::EscapeToRaw { .. } |
             StatementKind::AscribeUserType(..) |
             StatementKind::Nop => {}
         }
diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs
index 7d636b77ced..118539fc58e 100644
--- a/src/librustc_mir/interpret/cast.rs
+++ b/src/librustc_mir/interpret/cast.rs
@@ -44,22 +44,16 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
             }
 
             Misc => {
-                let src_layout = src.layout;
                 let src = self.read_immediate(src)?;
 
-                // There are no casts to references
-                assert!(!dest.layout.ty.is_region_ptr());
-                // Hence we make all casts erase the tag
-                let src = src.erase_tag().with_default_tag();
-
-                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
                         (Immediate::Scalar(_),_) |
                         // slices and trait objects to other slices/trait objects
                         (Immediate::ScalarPair(..), true) => {
                             // No change to immediate
-                            self.write_immediate(src, dest)?;
+                            self.write_immediate(*src, dest)?;
                         }
                         // slices and trait objects to thin pointers (dropping the metadata)
                         (Immediate::ScalarPair(data, _), false) => {
@@ -67,11 +61,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
                         }
                     }
                 } else {
-                    match src_layout.variants {
+                    match src.layout.variants {
                         layout::Variants::Single { index } => {
-                            if let Some(def) = src_layout.ty.ty_adt_def() {
+                            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;
@@ -84,7 +78,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
                         layout::Variants::NicheFilling { .. } => {},
                     }
 
-                    let dest_val = self.cast_scalar(src.to_scalar()?, src_layout, dest.layout)?;
+                    let dest_val = self.cast_scalar(src.to_scalar()?, src.layout, dest.layout)?;
                     self.write_scalar(dest_val, dest)?;
                 }
             }
diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs
index 4c7aa887045..e6f3b664c00 100644
--- a/src/librustc_mir/interpret/machine.rs
+++ b/src/librustc_mir/interpret/machine.rs
@@ -203,22 +203,12 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
     #[inline]
     fn retag(
         _ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
-        _fn_entry: bool,
-        _two_phase: bool,
+        _kind: mir::RetagKind,
         _place: PlaceTy<'tcx, Self::PointerTag>,
     ) -> EvalResult<'tcx> {
         Ok(())
     }
 
-    /// Execute an escape-to-raw operation
-    #[inline]
-    fn escape_to_raw(
-        _ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
-        _ptr: OpTy<'tcx, Self::PointerTag>,
-    ) -> EvalResult<'tcx> {
-        Ok(())
-    }
-
     /// Called immediately before a new stack frame got pushed
     fn stack_push(
         ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs
index a6835e4f167..596dba57606 100644
--- a/src/librustc_mir/interpret/step.rs
+++ b/src/librustc_mir/interpret/step.rs
@@ -119,13 +119,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
             FakeRead(..) => {}
 
             // Stacked Borrows.
-            Retag { fn_entry, two_phase, ref place } => {
+            Retag(kind, ref place) => {
                 let dest = self.eval_place(place)?;
-                M::retag(self, fn_entry, two_phase, dest)?;
-            }
-            EscapeToRaw(ref op) => {
-                let op = self.eval_operand(op, None)?;
-                M::escape_to_raw(self, op)?;
+                M::retag(self, kind, dest)?;
             }
 
             // Statements we do not track.
diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs
index 2728833251a..3802b019127 100644
--- a/src/librustc_mir/shim.rs
+++ b/src/librustc_mir/shim.rs
@@ -227,20 +227,11 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         // The first argument (index 0), but add 1 for the return value.
         let dropee_ptr = Place::Local(Local::new(1+0));
         if tcx.sess.opts.debugging_opts.mir_emit_retag {
-            // Function arguments should be retagged
+            // Function arguments should be retagged, and we make this one raw.
             mir.basic_blocks_mut()[START_BLOCK].statements.insert(0, Statement {
                 source_info,
-                kind: StatementKind::Retag {
-                    fn_entry: true,
-                    two_phase: false,
-                    place: dropee_ptr.clone(),
-                },
+                kind: StatementKind::Retag(RetagKind::Raw, dropee_ptr.clone()),
             });
-            // We use raw ptr operations, better prepare the alias tracking for that
-            mir.basic_blocks_mut()[START_BLOCK].statements.insert(1, Statement {
-                source_info,
-                kind: StatementKind::EscapeToRaw(Operand::Copy(dropee_ptr.clone())),
-            })
         }
         let patch = {
             let param_env = tcx.param_env(def_id).with_reveal_all();
diff --git a/src/librustc_mir/transform/add_retag.rs b/src/librustc_mir/transform/add_retag.rs
index 811b85446cb..69c0a68ae70 100644
--- a/src/librustc_mir/transform/add_retag.rs
+++ b/src/librustc_mir/transform/add_retag.rs
@@ -118,7 +118,7 @@ impl MirPass for AddRetag {
             basic_blocks[START_BLOCK].statements.splice(0..0,
                 places.into_iter().map(|place| Statement {
                     source_info,
-                    kind: StatementKind::Retag { fn_entry: true, two_phase: false, place },
+                    kind: StatementKind::Retag(RetagKind::FnEntry, place),
                 })
             );
         }
@@ -154,7 +154,7 @@ impl MirPass for AddRetag {
         for (source_info, dest_place, dest_block) in returns {
             basic_blocks[dest_block].statements.insert(0, Statement {
                 source_info,
-                kind: StatementKind::Retag { fn_entry: false, two_phase: false, place: dest_place },
+                kind: StatementKind::Retag(RetagKind::Default, dest_place),
             });
         }
 
@@ -164,9 +164,9 @@ impl MirPass for AddRetag {
             // We want to insert statements as we iterate.  To this end, we
             // iterate backwards using indices.
             for i in (0..block_data.statements.len()).rev() {
-                match block_data.statements[i].kind {
-                    // If we are casting *from* a reference, we may have to escape-to-raw.
-                    StatementKind::Assign(_, box Rvalue::Cast(
+                let (retag_kind, place) = match block_data.statements[i].kind {
+                    // If we are casting *from* a reference, we may have to retag-as-raw.
+                    StatementKind::Assign(ref place, box Rvalue::Cast(
                         CastKind::Misc,
                         ref src,
                         dest_ty,
@@ -175,42 +175,35 @@ impl MirPass for AddRetag {
                         if src_ty.is_region_ptr() {
                             // The only `Misc` casts on references are those creating raw pointers.
                             assert!(dest_ty.is_unsafe_ptr());
-                            // Insert escape-to-raw before the cast.  We are not concerned
-                            // with stability here: Our EscapeToRaw will not change the value
-                            // that the cast will then use.
-                            // `src` might be a "move", but we rely on this not actually moving
-                            // but just doing a memcpy.  It is crucial that we do EscapeToRaw
-                            // on the src because we need it with its original type.
-                            let source_info = block_data.statements[i].source_info;
-                            block_data.statements.insert(i, Statement {
-                                source_info,
-                                kind: StatementKind::EscapeToRaw(src.clone()),
-                            });
+                            (RetagKind::Raw, place)
+                        } else {
+                            // Some other cast, no retag
+                            continue
                         }
                     }
                     // Assignments of reference or ptr type are the ones where we may have
                     // to update tags.  This includes `x = &[mut] ...` and hence
                     // we also retag after taking a reference!
                     StatementKind::Assign(ref place, box ref rvalue) if needs_retag(place) => {
-                        let two_phase = match rvalue {
-                            Rvalue::Ref(_, borrow_kind, _) =>
-                                borrow_kind.allows_two_phase_borrow(),
-                            _ => false
+                        let kind = match rvalue {
+                            Rvalue::Ref(_, borrow_kind, _)
+                                if borrow_kind.allows_two_phase_borrow()
+                            =>
+                                RetagKind::TwoPhase,
+                            _ =>
+                                RetagKind::Default,
                         };
-                        // Insert a retag after the assignment.
-                        let source_info = block_data.statements[i].source_info;
-                        block_data.statements.insert(i+1, Statement {
-                            source_info,
-                            kind: StatementKind::Retag {
-                                fn_entry: false,
-                                two_phase,
-                                place: place.clone(),
-                            },
-                        });
+                        (kind, place)
                     }
                     // Do nothing for the rest
-                    _ => {},
+                    _ => continue,
                 };
+                // Insert a retag after the statement.
+                let source_info = block_data.statements[i].source_info;
+                block_data.statements.insert(i+1, Statement {
+                    source_info,
+                    kind: StatementKind::Retag(retag_kind, place.clone()),
+                });
             }
         }
     }
diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs
index 36078693840..f6b7f817aad 100644
--- a/src/librustc_mir/transform/check_unsafety.rs
+++ b/src/librustc_mir/transform/check_unsafety.rs
@@ -117,7 +117,6 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
             StatementKind::StorageLive(..) |
             StatementKind::StorageDead(..) |
             StatementKind::Retag { .. } |
-            StatementKind::EscapeToRaw { .. } |
             StatementKind::AscribeUserType(..) |
             StatementKind::Nop => {
                 // safe (at least as emitted during MIR construction)
diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs
index f870e4a2a42..fe19accb031 100644
--- a/src/librustc_mir/transform/generator.rs
+++ b/src/librustc_mir/transform/generator.rs
@@ -689,7 +689,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
         // Alias tracking must know we changed the type
         mir.basic_blocks_mut()[START_BLOCK].statements.insert(0, Statement {
             source_info,
-            kind: StatementKind::EscapeToRaw(Operand::Copy(Place::Local(self_arg()))),
+            kind: StatementKind::Retag(RetagKind::Raw, Place::Local(self_arg())),
         })
     }
 
diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs
index afe0066df1f..88424d75baa 100644
--- a/src/librustc_mir/transform/inline.rs
+++ b/src/librustc_mir/transform/inline.rs
@@ -709,16 +709,17 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
 
     fn visit_retag(
         &mut self,
-        fn_entry: &mut bool,
-        two_phase: &mut bool,
+        kind: &mut RetagKind,
         place: &mut Place<'tcx>,
         loc: Location,
     ) {
-        self.super_retag(fn_entry, two_phase, place, loc);
+        self.super_retag(kind, place, loc);
 
         // We have to patch all inlined retags to be aware that they are no longer
         // happening on function entry.
-        *fn_entry = false;
+        if *kind == RetagKind::FnEntry {
+            *kind = RetagKind::Default;
+        }
     }
 
     fn visit_terminator_kind(&mut self, block: BasicBlock,
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs
index 58a3cb97e41..b854f029e51 100644
--- a/src/librustc_mir/transform/qualify_consts.rs
+++ b/src/librustc_mir/transform/qualify_consts.rs
@@ -1241,7 +1241,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
                 StatementKind::StorageDead(_) |
                 StatementKind::InlineAsm {..} |
                 StatementKind::Retag { .. } |
-                StatementKind::EscapeToRaw { .. } |
                 StatementKind::AscribeUserType(..) |
                 StatementKind::Nop => {}
             }
diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs
index eee167c3579..c1c5b18915a 100644
--- a/src/librustc_mir/transform/qualify_min_const_fn.rs
+++ b/src/librustc_mir/transform/qualify_min_const_fn.rs
@@ -243,7 +243,6 @@ fn check_statement(
         | StatementKind::StorageLive(_)
         | StatementKind::StorageDead(_)
         | StatementKind::Retag { .. }
-        | StatementKind::EscapeToRaw { .. }
         | StatementKind::AscribeUserType(..)
         | StatementKind::Nop => Ok(()),
     }
diff --git a/src/librustc_mir/transform/remove_noop_landing_pads.rs b/src/librustc_mir/transform/remove_noop_landing_pads.rs
index 81b010e7dce..cdab5a1d7b0 100644
--- a/src/librustc_mir/transform/remove_noop_landing_pads.rs
+++ b/src/librustc_mir/transform/remove_noop_landing_pads.rs
@@ -65,8 +65,7 @@ impl RemoveNoopLandingPads {
                 StatementKind::Assign { .. } |
                 StatementKind::SetDiscriminant { .. } |
                 StatementKind::InlineAsm { .. } |
-                StatementKind::Retag { .. } |
-                StatementKind::EscapeToRaw { .. } => {
+                StatementKind::Retag { .. } => {
                     return false;
                 }
             }
diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs
index 0507d0dfdfa..e1eeeb8301c 100644
--- a/src/librustc_mir/transform/rustc_peek.rs
+++ b/src/librustc_mir/transform/rustc_peek.rs
@@ -162,7 +162,6 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
             mir::StatementKind::StorageDead(_) |
             mir::StatementKind::InlineAsm { .. } |
             mir::StatementKind::Retag { .. } |
-            mir::StatementKind::EscapeToRaw { .. } |
             mir::StatementKind::AscribeUserType(..) |
             mir::StatementKind::Nop => continue,
             mir::StatementKind::SetDiscriminant{ .. } =>
diff --git a/src/test/mir-opt/retag.rs b/src/test/mir-opt/retag.rs
index 7da55c0868c..f48862ff933 100644
--- a/src/test/mir-opt/retag.rs
+++ b/src/test/mir-opt/retag.rs
@@ -87,8 +87,8 @@ fn main() {
 //         ...
 //         _14 = &mut (*_10);
 //         Retag(_14);
-//         EscapeToRaw(move _14);
 //         _13 = move _14 as *mut i32 (Misc);
+//         Retag([raw] _13);
 //         ...
 //         _17 = move _18(move _19) -> bb2;
 //     }