@@ -88,11 +88,8 @@ pub fn sanity_check_via_rustc_peek<'tcx, O>(
88
88
def_id : DefId ,
89
89
_attributes : & [ ast:: Attribute ] ,
90
90
results : & DataflowResults < ' tcx , O > ,
91
- ) where
92
- O : BitDenotation < ' tcx , Idx = MovePathIndex > + HasMoveData < ' tcx > ,
93
- {
91
+ ) where O : RustcPeekAt < ' tcx > {
94
92
debug ! ( "sanity_check_via_rustc_peek def_id: {:?}" , def_id) ;
95
- let move_data = results. operator ( ) . move_data ( ) ;
96
93
97
94
let peek_calls = body
98
95
. basic_blocks ( )
@@ -121,19 +118,7 @@ pub fn sanity_check_via_rustc_peek<'tcx, O>(
121
118
let loc = Location { block : bb, statement_index } ;
122
119
let flow_state = dataflow:: state_for_location ( loc, results. operator ( ) , results, body) ;
123
120
124
- match move_data. rev_lookup . find ( peeking_at_place) {
125
- LookupResult :: Exact ( peek_mpi) => {
126
- let bit_state = flow_state. contains ( peek_mpi) ;
127
- debug ! ( "rustc_peek({:?} = &{:?}) bit_state: {}" ,
128
- call. arg, peeking_at_place, bit_state) ;
129
- if !bit_state {
130
- tcx. sess . span_err ( call. span , "rustc_peek: bit not set" ) ;
131
- }
132
- }
133
- LookupResult :: Parent ( ..) => {
134
- tcx. sess . span_err ( call. span , "rustc_peek: argument untracked" ) ;
135
- }
136
- }
121
+ results. operator ( ) . peek_at ( tcx, peeking_at_place, & flow_state, call) ;
137
122
} else {
138
123
let msg = "rustc_peek: argument expression \
139
124
must be immediate borrow of form `&expr`";
@@ -159,7 +144,8 @@ fn value_assigned_to_local<'a, 'tcx>(
159
144
None
160
145
}
161
146
162
- struct PeekCall {
147
+ #[ derive( Clone , Copy , Debug ) ]
148
+ pub struct PeekCall {
163
149
arg : Local ,
164
150
span : Span ,
165
151
}
@@ -203,3 +189,39 @@ impl PeekCall {
203
189
None
204
190
}
205
191
}
192
+
193
+ pub trait RustcPeekAt < ' tcx > : BitDenotation < ' tcx > {
194
+ fn peek_at (
195
+ & self ,
196
+ tcx : TyCtxt < ' tcx > ,
197
+ place : & mir:: Place < ' tcx > ,
198
+ flow_state : & BitSet < Self :: Idx > ,
199
+ call : PeekCall ,
200
+ ) ;
201
+ }
202
+
203
+ impl < ' tcx , O > RustcPeekAt < ' tcx > for O
204
+ where O : BitDenotation < ' tcx , Idx = MovePathIndex > + HasMoveData < ' tcx > ,
205
+ {
206
+ fn peek_at (
207
+ & self ,
208
+ tcx : TyCtxt < ' tcx > ,
209
+ place : & mir:: Place < ' tcx > ,
210
+ flow_state : & BitSet < Self :: Idx > ,
211
+ call : PeekCall ,
212
+ ) {
213
+ match self . move_data ( ) . rev_lookup . find ( place) {
214
+ LookupResult :: Exact ( peek_mpi) => {
215
+ let bit_state = flow_state. contains ( peek_mpi) ;
216
+ debug ! ( "rustc_peek({:?} = &{:?}) bit_state: {}" ,
217
+ call. arg, place, bit_state) ;
218
+ if !bit_state {
219
+ tcx. sess . span_err ( call. span , "rustc_peek: bit not set" ) ;
220
+ }
221
+ }
222
+ LookupResult :: Parent ( ..) => {
223
+ tcx. sess . span_err ( call. span , "rustc_peek: argument untracked" ) ;
224
+ }
225
+ }
226
+ }
227
+ }
0 commit comments