@@ -11,6 +11,7 @@ struct DerefChecker<'a, 'tcx> {
11
11
tcx : TyCtxt < ' tcx > ,
12
12
patcher : MirPatch < ' tcx > ,
13
13
local_decls : & ' a LocalDecls < ' tcx > ,
14
+ add_deref_metadata : bool ,
14
15
}
15
16
16
17
impl < ' a , ' tcx > MutVisitor < ' tcx > for DerefChecker < ' a , ' tcx > {
@@ -39,7 +40,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
39
40
let temp = self . patcher . new_local_with_info (
40
41
ty,
41
42
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
+ } ,
43
48
) ;
44
49
45
50
// We are adding current p_ref's projections to our
@@ -50,7 +55,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
50
55
self . patcher . add_assign (
51
56
loc,
52
57
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
+ } ,
54
63
) ;
55
64
place_local = temp;
56
65
last_len = p_ref. projection . len ( ) ;
@@ -67,9 +76,14 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
67
76
}
68
77
}
69
78
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
+ ) {
71
84
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 } ;
73
87
74
88
for ( bb, data) in body. basic_blocks . as_mut_preserves_cfg ( ) . iter_enumerated_mut ( ) {
75
89
checker. visit_basic_block_data ( bb, data) ;
@@ -80,7 +94,7 @@ pub(super) fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
80
94
81
95
impl < ' tcx > crate :: MirPass < ' tcx > for Derefer {
82
96
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
83
- deref_finder ( tcx, body) ;
97
+ deref_finder ( tcx, body, true ) ;
84
98
}
85
99
86
100
fn is_required ( & self ) -> bool {
0 commit comments