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