@@ -11,6 +11,7 @@ struct DerefChecker<'a, 'tcx> {
1111 tcx : TyCtxt < ' tcx > ,
1212 patcher : MirPatch < ' tcx > ,
1313 local_decls : & ' a LocalDecls < ' tcx > ,
14+ add_deref_metadata : bool ,
1415}
1516
1617impl < ' a , ' tcx > MutVisitor < ' tcx > for DerefChecker < ' a , ' tcx > {
@@ -39,7 +40,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
3940 let temp = self . patcher . new_local_with_info (
4041 ty,
4142 self . local_decls [ p_ref. local ] . source_info . span ,
42- LocalInfo :: DerefTemp ,
43+ if self . add_deref_metadata {
44+ LocalInfo :: DerefTemp
45+ } else {
46+ LocalInfo :: Boring
47+ } ,
4348 ) ;
4449
4550 // We are adding current p_ref's projections to our
@@ -50,7 +55,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
5055 self . patcher . add_assign (
5156 loc,
5257 Place :: from ( temp) ,
53- Rvalue :: CopyForDeref ( deref_place) ,
58+ if self . add_deref_metadata {
59+ Rvalue :: CopyForDeref ( deref_place)
60+ } else {
61+ Rvalue :: Use ( Operand :: Copy ( deref_place) )
62+ } ,
5463 ) ;
5564 place_local = temp;
5665 last_len = p_ref. projection . len ( ) ;
@@ -67,9 +76,14 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
6776 }
6877}
6978
70- pub ( super ) fn deref_finder < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
79+ pub ( super ) fn deref_finder < ' tcx > (
80+ tcx : TyCtxt < ' tcx > ,
81+ body : & mut Body < ' tcx > ,
82+ add_deref_metadata : bool ,
83+ ) {
7184 let patch = MirPatch :: new ( body) ;
72- let mut checker = DerefChecker { tcx, patcher : patch, local_decls : & body. local_decls } ;
85+ let mut checker =
86+ DerefChecker { tcx, patcher : patch, local_decls : & body. local_decls , add_deref_metadata } ;
7387
7488 for ( bb, data) in body. basic_blocks . as_mut_preserves_cfg ( ) . iter_enumerated_mut ( ) {
7589 checker. visit_basic_block_data ( bb, data) ;
@@ -80,7 +94,7 @@ pub(super) fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
8094
8195impl < ' tcx > crate :: MirPass < ' tcx > for Derefer {
8296 fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
83- deref_finder ( tcx, body) ;
97+ deref_finder ( tcx, body, true ) ;
8498 }
8599
86100 fn is_required ( & self ) -> bool {
0 commit comments