@@ -6,11 +6,13 @@ use rustc_middle::ty::TyCtxt;
66use crate :: patch:: MirPatch ;
77
88pub ( super ) struct Derefer ;
9+ pub ( super ) struct DereferErased ;
910
1011struct DerefChecker < ' a , ' tcx > {
1112 tcx : TyCtxt < ' tcx > ,
1213 patcher : MirPatch < ' tcx > ,
1314 local_decls : & ' a LocalDecls < ' tcx > ,
15+ add_deref_metadata : bool ,
1416}
1517
1618impl < ' a , ' tcx > MutVisitor < ' tcx > for DerefChecker < ' a , ' tcx > {
@@ -39,7 +41,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
3941 let temp = self . patcher . new_local_with_info (
4042 ty,
4143 self . local_decls [ p_ref. local ] . source_info . span ,
42- LocalInfo :: DerefTemp ,
44+ if self . add_deref_metadata {
45+ LocalInfo :: DerefTemp
46+ } else {
47+ LocalInfo :: Boring
48+ } ,
4349 ) ;
4450
4551 // We are adding current p_ref's projections to our
@@ -50,7 +56,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
5056 self . patcher . add_assign (
5157 loc,
5258 Place :: from ( temp) ,
53- Rvalue :: CopyForDeref ( deref_place) ,
59+ if self . add_deref_metadata {
60+ Rvalue :: CopyForDeref ( deref_place)
61+ } else {
62+ Rvalue :: Use ( Operand :: Copy ( deref_place) )
63+ } ,
5464 ) ;
5565 place_local = temp;
5666 last_len = p_ref. projection . len ( ) ;
@@ -67,9 +77,14 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
6777 }
6878}
6979
70- pub ( super ) fn deref_finder < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
80+ pub ( super ) fn deref_finder < ' tcx > (
81+ tcx : TyCtxt < ' tcx > ,
82+ body : & mut Body < ' tcx > ,
83+ add_deref_metadata : bool ,
84+ ) {
7185 let patch = MirPatch :: new ( body) ;
72- let mut checker = DerefChecker { tcx, patcher : patch, local_decls : & body. local_decls } ;
86+ let mut checker =
87+ DerefChecker { tcx, patcher : patch, local_decls : & body. local_decls , add_deref_metadata } ;
7388
7489 for ( bb, data) in body. basic_blocks . as_mut_preserves_cfg ( ) . iter_enumerated_mut ( ) {
7590 checker. visit_basic_block_data ( bb, data) ;
@@ -80,7 +95,17 @@ pub(super) fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
8095
8196impl < ' tcx > crate :: MirPass < ' tcx > for Derefer {
8297 fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
83- deref_finder ( tcx, body) ;
98+ deref_finder ( tcx, body, true ) ;
99+ }
100+
101+ fn is_required ( & self ) -> bool {
102+ true
103+ }
104+ }
105+
106+ impl < ' tcx > crate :: MirPass < ' tcx > for DereferErased {
107+ fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
108+ deref_finder ( tcx, body, false ) ;
84109 }
85110
86111 fn is_required ( & self ) -> bool {
0 commit comments