@@ -10,6 +10,7 @@ use rustc_middle::span_bug;
10
10
use rustc_session:: Session ;
11
11
use rustc_span:: source_map:: SourceMap ;
12
12
use rustc_span:: { Span , DUMMY_SP } ;
13
+ use std:: ops:: ControlFlow :: { self , Continue } ;
13
14
14
15
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
15
16
pub ( super ) struct NodeCollector < ' a , ' hir > {
@@ -110,39 +111,44 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
110
111
/// deep walking so that we walk nested items in the context of
111
112
/// their outer items.
112
113
113
- fn visit_nested_item ( & mut self , item : ItemId ) {
114
+ fn visit_nested_item ( & mut self , item : ItemId ) -> ControlFlow < ! > {
114
115
debug ! ( "visit_nested_item: {:?}" , item) ;
115
116
self . insert_nested ( item. owner_id . def_id ) ;
117
+ Continue ( ( ) )
116
118
}
117
119
118
- fn visit_nested_trait_item ( & mut self , item_id : TraitItemId ) {
120
+ fn visit_nested_trait_item ( & mut self , item_id : TraitItemId ) -> ControlFlow < ! > {
119
121
self . insert_nested ( item_id. owner_id . def_id ) ;
122
+ Continue ( ( ) )
120
123
}
121
124
122
- fn visit_nested_impl_item ( & mut self , item_id : ImplItemId ) {
125
+ fn visit_nested_impl_item ( & mut self , item_id : ImplItemId ) -> ControlFlow < ! > {
123
126
self . insert_nested ( item_id. owner_id . def_id ) ;
127
+ Continue ( ( ) )
124
128
}
125
129
126
- fn visit_nested_foreign_item ( & mut self , foreign_id : ForeignItemId ) {
130
+ fn visit_nested_foreign_item ( & mut self , foreign_id : ForeignItemId ) -> ControlFlow < ! > {
127
131
self . insert_nested ( foreign_id. owner_id . def_id ) ;
132
+ Continue ( ( ) )
128
133
}
129
134
130
- fn visit_nested_body ( & mut self , id : BodyId ) {
135
+ fn visit_nested_body ( & mut self , id : BodyId ) -> ControlFlow < ! > {
131
136
debug_assert_eq ! ( id. hir_id. owner, self . owner) ;
132
137
let body = self . bodies [ & id. hir_id . local_id ] ;
133
- self . visit_body ( body) ;
138
+ self . visit_body ( body)
134
139
}
135
140
136
- fn visit_param ( & mut self , param : & ' hir Param < ' hir > ) {
141
+ fn visit_param ( & mut self , param : & ' hir Param < ' hir > ) -> ControlFlow < ! > {
137
142
let node = Node :: Param ( param) ;
138
143
self . insert ( param. pat . span , param. hir_id , node) ;
139
144
self . with_parent ( param. hir_id , |this| {
140
145
intravisit:: walk_param ( this, param) ;
141
146
} ) ;
147
+ Continue ( ( ) )
142
148
}
143
149
144
150
#[ instrument( level = "debug" , skip( self ) ) ]
145
- fn visit_item ( & mut self , i : & ' hir Item < ' hir > ) {
151
+ fn visit_item ( & mut self , i : & ' hir Item < ' hir > ) -> ControlFlow < ! > {
146
152
debug_assert_eq ! ( i. owner_id, self . owner) ;
147
153
self . with_parent ( i. hir_id ( ) , |this| {
148
154
if let ItemKind :: Struct ( struct_def, _) = & i. kind {
@@ -153,147 +159,165 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
153
159
}
154
160
intravisit:: walk_item ( this, i) ;
155
161
} ) ;
162
+ Continue ( ( ) )
156
163
}
157
164
158
165
#[ instrument( level = "debug" , skip( self ) ) ]
159
- fn visit_foreign_item ( & mut self , fi : & ' hir ForeignItem < ' hir > ) {
166
+ fn visit_foreign_item ( & mut self , fi : & ' hir ForeignItem < ' hir > ) -> ControlFlow < ! > {
160
167
debug_assert_eq ! ( fi. owner_id, self . owner) ;
161
168
self . with_parent ( fi. hir_id ( ) , |this| {
162
169
intravisit:: walk_foreign_item ( this, fi) ;
163
170
} ) ;
171
+ Continue ( ( ) )
164
172
}
165
173
166
- fn visit_generic_param ( & mut self , param : & ' hir GenericParam < ' hir > ) {
174
+ fn visit_generic_param ( & mut self , param : & ' hir GenericParam < ' hir > ) -> ControlFlow < ! > {
167
175
self . insert ( param. span , param. hir_id , Node :: GenericParam ( param) ) ;
168
- intravisit:: walk_generic_param ( self , param) ;
176
+ intravisit:: walk_generic_param ( self , param)
169
177
}
170
178
171
- fn visit_const_param_default ( & mut self , param : HirId , ct : & ' hir AnonConst ) {
179
+ fn visit_const_param_default ( & mut self , param : HirId , ct : & ' hir AnonConst ) -> ControlFlow < ! > {
172
180
self . with_parent ( param, |this| {
173
181
intravisit:: walk_const_param_default ( this, ct) ;
174
- } )
182
+ } ) ;
183
+ Continue ( ( ) )
175
184
}
176
185
177
186
#[ instrument( level = "debug" , skip( self ) ) ]
178
- fn visit_trait_item ( & mut self , ti : & ' hir TraitItem < ' hir > ) {
187
+ fn visit_trait_item ( & mut self , ti : & ' hir TraitItem < ' hir > ) -> ControlFlow < ! > {
179
188
debug_assert_eq ! ( ti. owner_id, self . owner) ;
180
189
self . with_parent ( ti. hir_id ( ) , |this| {
181
190
intravisit:: walk_trait_item ( this, ti) ;
182
191
} ) ;
192
+ Continue ( ( ) )
183
193
}
184
194
185
195
#[ instrument( level = "debug" , skip( self ) ) ]
186
- fn visit_impl_item ( & mut self , ii : & ' hir ImplItem < ' hir > ) {
196
+ fn visit_impl_item ( & mut self , ii : & ' hir ImplItem < ' hir > ) -> ControlFlow < ! > {
187
197
debug_assert_eq ! ( ii. owner_id, self . owner) ;
188
198
self . with_parent ( ii. hir_id ( ) , |this| {
189
199
intravisit:: walk_impl_item ( this, ii) ;
190
200
} ) ;
201
+ Continue ( ( ) )
191
202
}
192
203
193
- fn visit_pat ( & mut self , pat : & ' hir Pat < ' hir > ) {
204
+ fn visit_pat ( & mut self , pat : & ' hir Pat < ' hir > ) -> ControlFlow < ! > {
194
205
self . insert ( pat. span , pat. hir_id , Node :: Pat ( pat) ) ;
195
206
196
207
self . with_parent ( pat. hir_id , |this| {
197
208
intravisit:: walk_pat ( this, pat) ;
198
209
} ) ;
210
+ Continue ( ( ) )
199
211
}
200
212
201
- fn visit_pat_field ( & mut self , field : & ' hir PatField < ' hir > ) {
213
+ fn visit_pat_field ( & mut self , field : & ' hir PatField < ' hir > ) -> ControlFlow < ! > {
202
214
self . insert ( field. span , field. hir_id , Node :: PatField ( field) ) ;
203
215
self . with_parent ( field. hir_id , |this| {
204
216
intravisit:: walk_pat_field ( this, field) ;
205
217
} ) ;
218
+ Continue ( ( ) )
206
219
}
207
220
208
- fn visit_arm ( & mut self , arm : & ' hir Arm < ' hir > ) {
221
+ fn visit_arm ( & mut self , arm : & ' hir Arm < ' hir > ) -> ControlFlow < ! > {
209
222
let node = Node :: Arm ( arm) ;
210
223
211
224
self . insert ( arm. span , arm. hir_id , node) ;
212
225
213
226
self . with_parent ( arm. hir_id , |this| {
214
227
intravisit:: walk_arm ( this, arm) ;
215
228
} ) ;
229
+ Continue ( ( ) )
216
230
}
217
231
218
- fn visit_anon_const ( & mut self , constant : & ' hir AnonConst ) {
232
+ fn visit_anon_const ( & mut self , constant : & ' hir AnonConst ) -> ControlFlow < ! > {
219
233
self . insert ( DUMMY_SP , constant. hir_id , Node :: AnonConst ( constant) ) ;
220
234
221
235
self . with_parent ( constant. hir_id , |this| {
222
236
intravisit:: walk_anon_const ( this, constant) ;
223
237
} ) ;
238
+ Continue ( ( ) )
224
239
}
225
240
226
- fn visit_expr ( & mut self , expr : & ' hir Expr < ' hir > ) {
241
+ fn visit_expr ( & mut self , expr : & ' hir Expr < ' hir > ) -> ControlFlow < ! > {
227
242
self . insert ( expr. span , expr. hir_id , Node :: Expr ( expr) ) ;
228
243
229
244
self . with_parent ( expr. hir_id , |this| {
230
245
intravisit:: walk_expr ( this, expr) ;
231
246
} ) ;
247
+ Continue ( ( ) )
232
248
}
233
249
234
- fn visit_expr_field ( & mut self , field : & ' hir ExprField < ' hir > ) {
250
+ fn visit_expr_field ( & mut self , field : & ' hir ExprField < ' hir > ) -> ControlFlow < ! > {
235
251
self . insert ( field. span , field. hir_id , Node :: ExprField ( field) ) ;
236
252
self . with_parent ( field. hir_id , |this| {
237
253
intravisit:: walk_expr_field ( this, field) ;
238
254
} ) ;
255
+ Continue ( ( ) )
239
256
}
240
257
241
- fn visit_stmt ( & mut self , stmt : & ' hir Stmt < ' hir > ) {
258
+ fn visit_stmt ( & mut self , stmt : & ' hir Stmt < ' hir > ) -> ControlFlow < ! > {
242
259
self . insert ( stmt. span , stmt. hir_id , Node :: Stmt ( stmt) ) ;
243
260
244
261
self . with_parent ( stmt. hir_id , |this| {
245
262
intravisit:: walk_stmt ( this, stmt) ;
246
263
} ) ;
264
+ Continue ( ( ) )
247
265
}
248
266
249
- fn visit_path_segment ( & mut self , path_segment : & ' hir PathSegment < ' hir > ) {
267
+ fn visit_path_segment ( & mut self , path_segment : & ' hir PathSegment < ' hir > ) -> ControlFlow < ! > {
250
268
self . insert ( path_segment. ident . span , path_segment. hir_id , Node :: PathSegment ( path_segment) ) ;
251
- intravisit:: walk_path_segment ( self , path_segment) ;
269
+ intravisit:: walk_path_segment ( self , path_segment)
252
270
}
253
271
254
- fn visit_ty ( & mut self , ty : & ' hir Ty < ' hir > ) {
272
+ fn visit_ty ( & mut self , ty : & ' hir Ty < ' hir > ) -> ControlFlow < ! > {
255
273
self . insert ( ty. span , ty. hir_id , Node :: Ty ( ty) ) ;
256
274
257
275
self . with_parent ( ty. hir_id , |this| {
258
276
intravisit:: walk_ty ( this, ty) ;
259
277
} ) ;
278
+ Continue ( ( ) )
260
279
}
261
280
262
- fn visit_infer ( & mut self , inf : & ' hir InferArg ) {
281
+ fn visit_infer ( & mut self , inf : & ' hir InferArg ) -> ControlFlow < ! > {
263
282
self . insert ( inf. span , inf. hir_id , Node :: Infer ( inf) ) ;
264
283
265
284
self . with_parent ( inf. hir_id , |this| {
266
285
intravisit:: walk_inf ( this, inf) ;
267
286
} ) ;
287
+ Continue ( ( ) )
268
288
}
269
289
270
- fn visit_trait_ref ( & mut self , tr : & ' hir TraitRef < ' hir > ) {
290
+ fn visit_trait_ref ( & mut self , tr : & ' hir TraitRef < ' hir > ) -> ControlFlow < ! > {
271
291
self . insert ( tr. path . span , tr. hir_ref_id , Node :: TraitRef ( tr) ) ;
272
292
273
293
self . with_parent ( tr. hir_ref_id , |this| {
274
294
intravisit:: walk_trait_ref ( this, tr) ;
275
295
} ) ;
296
+ Continue ( ( ) )
276
297
}
277
298
278
- fn visit_block ( & mut self , block : & ' hir Block < ' hir > ) {
299
+ fn visit_block ( & mut self , block : & ' hir Block < ' hir > ) -> ControlFlow < ! > {
279
300
self . insert ( block. span , block. hir_id , Node :: Block ( block) ) ;
280
301
self . with_parent ( block. hir_id , |this| {
281
302
intravisit:: walk_block ( this, block) ;
282
303
} ) ;
304
+ Continue ( ( ) )
283
305
}
284
306
285
- fn visit_local ( & mut self , l : & ' hir Local < ' hir > ) {
307
+ fn visit_local ( & mut self , l : & ' hir Local < ' hir > ) -> ControlFlow < ! > {
286
308
self . insert ( l. span , l. hir_id , Node :: Local ( l) ) ;
287
309
self . with_parent ( l. hir_id , |this| {
288
310
intravisit:: walk_local ( this, l) ;
289
- } )
311
+ } ) ;
312
+ Continue ( ( ) )
290
313
}
291
314
292
- fn visit_lifetime ( & mut self , lifetime : & ' hir Lifetime ) {
315
+ fn visit_lifetime ( & mut self , lifetime : & ' hir Lifetime ) -> ControlFlow < ! > {
293
316
self . insert ( lifetime. ident . span , lifetime. hir_id , Node :: Lifetime ( lifetime) ) ;
317
+ Continue ( ( ) )
294
318
}
295
319
296
- fn visit_variant ( & mut self , v : & ' hir Variant < ' hir > ) {
320
+ fn visit_variant ( & mut self , v : & ' hir Variant < ' hir > ) -> ControlFlow < ! > {
297
321
self . insert ( v. span , v. hir_id , Node :: Variant ( v) ) ;
298
322
self . with_parent ( v. hir_id , |this| {
299
323
// Register the constructor of this variant.
@@ -302,43 +326,49 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
302
326
}
303
327
intravisit:: walk_variant ( this, v) ;
304
328
} ) ;
329
+ Continue ( ( ) )
305
330
}
306
331
307
- fn visit_field_def ( & mut self , field : & ' hir FieldDef < ' hir > ) {
332
+ fn visit_field_def ( & mut self , field : & ' hir FieldDef < ' hir > ) -> ControlFlow < ! > {
308
333
self . insert ( field. span , field. hir_id , Node :: Field ( field) ) ;
309
334
self . with_parent ( field. hir_id , |this| {
310
335
intravisit:: walk_field_def ( this, field) ;
311
336
} ) ;
337
+ Continue ( ( ) )
312
338
}
313
339
314
- fn visit_assoc_type_binding ( & mut self , type_binding : & ' hir TypeBinding < ' hir > ) {
340
+ fn visit_assoc_type_binding (
341
+ & mut self ,
342
+ type_binding : & ' hir TypeBinding < ' hir > ,
343
+ ) -> ControlFlow < !> {
315
344
self . insert ( type_binding. span , type_binding. hir_id , Node :: TypeBinding ( type_binding) ) ;
316
345
self . with_parent ( type_binding. hir_id , |this| {
317
- intravisit:: walk_assoc_type_binding ( this, type_binding)
318
- } )
346
+ intravisit:: walk_assoc_type_binding ( this, type_binding) ;
347
+ } ) ;
348
+ Continue ( ( ) )
319
349
}
320
350
321
- fn visit_trait_item_ref ( & mut self , ii : & ' hir TraitItemRef ) {
351
+ fn visit_trait_item_ref ( & mut self , ii : & ' hir TraitItemRef ) -> ControlFlow < ! > {
322
352
// Do not visit the duplicate information in TraitItemRef. We want to
323
353
// map the actual nodes, not the duplicate ones in the *Ref.
324
354
let TraitItemRef { id, ident : _, kind : _, span : _ } = * ii;
325
355
326
- self . visit_nested_trait_item ( id) ;
356
+ self . visit_nested_trait_item ( id)
327
357
}
328
358
329
- fn visit_impl_item_ref ( & mut self , ii : & ' hir ImplItemRef ) {
359
+ fn visit_impl_item_ref ( & mut self , ii : & ' hir ImplItemRef ) -> ControlFlow < ! > {
330
360
// Do not visit the duplicate information in ImplItemRef. We want to
331
361
// map the actual nodes, not the duplicate ones in the *Ref.
332
362
let ImplItemRef { id, ident : _, kind : _, span : _, trait_item_def_id : _ } = * ii;
333
363
334
- self . visit_nested_impl_item ( id) ;
364
+ self . visit_nested_impl_item ( id)
335
365
}
336
366
337
- fn visit_foreign_item_ref ( & mut self , fi : & ' hir ForeignItemRef ) {
367
+ fn visit_foreign_item_ref ( & mut self , fi : & ' hir ForeignItemRef ) -> ControlFlow < ! > {
338
368
// Do not visit the duplicate information in ForeignItemRef. We want to
339
369
// map the actual nodes, not the duplicate ones in the *Ref.
340
370
let ForeignItemRef { id, ident : _, span : _ } = * fi;
341
371
342
- self . visit_nested_foreign_item ( id) ;
372
+ self . visit_nested_foreign_item ( id)
343
373
}
344
374
}
0 commit comments