@@ -168,6 +168,22 @@ impl<'k> StatCollector<'k> {
168
168
}
169
169
}
170
170
171
+ // Used to avoid boilerplate for types with many variants.
172
+ macro_rules! record_variants {
173
+ (
174
+ ( $self: ident, $val: expr, $kind: expr, $id: expr, $mod: ident, $ty: ty, $tykind: ident) ,
175
+ [ $( $variant: ident) ,* ]
176
+ ) => {
177
+ match $kind {
178
+ $(
179
+ $mod:: $tykind:: $variant { .. } => {
180
+ $self. record_variant( stringify!( $ty) , stringify!( $variant) , $id, $val)
181
+ }
182
+ ) *
183
+ }
184
+ } ;
185
+ }
186
+
171
187
impl < ' v > hir_visit:: Visitor < ' v > for StatCollector < ' v > {
172
188
fn visit_param ( & mut self , param : & ' v hir:: Param < ' v > ) {
173
189
self . record ( "Param" , Id :: Node ( param. hir_id ) , param) ;
@@ -200,12 +216,46 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
200
216
}
201
217
202
218
fn visit_item ( & mut self , i : & ' v hir:: Item < ' v > ) {
203
- self . record ( "Item" , Id :: Node ( i. hir_id ( ) ) , i) ;
219
+ record_variants ! (
220
+ ( self , i, i. kind, Id :: Node ( i. hir_id( ) ) , hir, Item , ItemKind ) ,
221
+ [
222
+ ExternCrate ,
223
+ Use ,
224
+ Static ,
225
+ Const ,
226
+ Fn ,
227
+ Macro ,
228
+ Mod ,
229
+ ForeignMod ,
230
+ GlobalAsm ,
231
+ TyAlias ,
232
+ OpaqueTy ,
233
+ Enum ,
234
+ Struct ,
235
+ Union ,
236
+ Trait ,
237
+ TraitAlias ,
238
+ Impl
239
+ ]
240
+ ) ;
204
241
hir_visit:: walk_item ( self , i)
205
242
}
206
243
244
+ fn visit_body ( & mut self , b : & ' v hir:: Body < ' v > ) {
245
+ self . record ( "Body" , Id :: None , b) ;
246
+ hir_visit:: walk_body ( self , b) ;
247
+ }
248
+
249
+ fn visit_mod ( & mut self , m : & ' v hir:: Mod < ' v > , _s : Span , n : HirId ) {
250
+ self . record ( "Mod" , Id :: None , m) ;
251
+ hir_visit:: walk_mod ( self , m, n)
252
+ }
253
+
207
254
fn visit_foreign_item ( & mut self , i : & ' v hir:: ForeignItem < ' v > ) {
208
- self . record ( "ForeignItem" , Id :: Node ( i. hir_id ( ) ) , i) ;
255
+ record_variants ! (
256
+ ( self , i, i. kind, Id :: Node ( i. hir_id( ) ) , hir, ForeignItem , ForeignItemKind ) ,
257
+ [ Fn , Static , Type ]
258
+ ) ;
209
259
hir_visit:: walk_foreign_item ( self , i)
210
260
}
211
261
@@ -220,7 +270,10 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
220
270
}
221
271
222
272
fn visit_stmt ( & mut self , s : & ' v hir:: Stmt < ' v > ) {
223
- self . record ( "Stmt" , Id :: Node ( s. hir_id ) , s) ;
273
+ record_variants ! (
274
+ ( self , s, s. kind, Id :: Node ( s. hir_id) , hir, Stmt , StmtKind ) ,
275
+ [ Local , Item , Expr , Semi ]
276
+ ) ;
224
277
hir_visit:: walk_stmt ( self , s)
225
278
}
226
279
@@ -230,20 +283,80 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
230
283
}
231
284
232
285
fn visit_pat ( & mut self , p : & ' v hir:: Pat < ' v > ) {
233
- self . record ( "Pat" , Id :: Node ( p. hir_id ) , p) ;
286
+ record_variants ! (
287
+ ( self , p, p. kind, Id :: Node ( p. hir_id) , hir, Pat , PatKind ) ,
288
+ [ Wild , Binding , Struct , TupleStruct , Or , Path , Tuple , Box , Ref , Lit , Range , Slice ]
289
+ ) ;
234
290
hir_visit:: walk_pat ( self , p)
235
291
}
236
292
237
- fn visit_expr ( & mut self , ex : & ' v hir:: Expr < ' v > ) {
238
- self . record ( "Expr" , Id :: Node ( ex. hir_id ) , ex) ;
239
- hir_visit:: walk_expr ( self , ex)
293
+ fn visit_pat_field ( & mut self , f : & ' v hir:: PatField < ' v > ) {
294
+ self . record ( "PatField" , Id :: Node ( f. hir_id ) , f) ;
295
+ hir_visit:: walk_pat_field ( self , f)
296
+ }
297
+
298
+ fn visit_expr ( & mut self , e : & ' v hir:: Expr < ' v > ) {
299
+ record_variants ! (
300
+ ( self , e, e. kind, Id :: Node ( e. hir_id) , hir, Expr , ExprKind ) ,
301
+ [
302
+ Box , ConstBlock , Array , Call , MethodCall , Tup , Binary , Unary , Lit , Cast , Type ,
303
+ DropTemps , Let , If , Loop , Match , Closure , Block , Assign , AssignOp , Field , Index ,
304
+ Path , AddrOf , Break , Continue , Ret , InlineAsm , Struct , Repeat , Yield , Err
305
+ ]
306
+ ) ;
307
+ hir_visit:: walk_expr ( self , e)
308
+ }
309
+
310
+ fn visit_let_expr ( & mut self , lex : & ' v hir:: Let < ' v > ) {
311
+ self . record ( "Let" , Id :: Node ( lex. hir_id ) , lex) ;
312
+ hir_visit:: walk_let_expr ( self , lex)
313
+ }
314
+
315
+ fn visit_expr_field ( & mut self , f : & ' v hir:: ExprField < ' v > ) {
316
+ self . record ( "ExprField" , Id :: Node ( f. hir_id ) , f) ;
317
+ hir_visit:: walk_expr_field ( self , f)
240
318
}
241
319
242
320
fn visit_ty ( & mut self , t : & ' v hir:: Ty < ' v > ) {
243
- self . record ( "Ty" , Id :: Node ( t. hir_id ) , t) ;
321
+ record_variants ! (
322
+ ( self , t, t. kind, Id :: Node ( t. hir_id) , hir, Ty , TyKind ) ,
323
+ [
324
+ Slice ,
325
+ Array ,
326
+ Ptr ,
327
+ Rptr ,
328
+ BareFn ,
329
+ Never ,
330
+ Tup ,
331
+ Path ,
332
+ OpaqueDef ,
333
+ TraitObject ,
334
+ Typeof ,
335
+ Infer ,
336
+ Err
337
+ ]
338
+ ) ;
244
339
hir_visit:: walk_ty ( self , t)
245
340
}
246
341
342
+ fn visit_generic_param ( & mut self , p : & ' v hir:: GenericParam < ' v > ) {
343
+ self . record ( "GenericParam" , Id :: Node ( p. hir_id ) , p) ;
344
+ hir_visit:: walk_generic_param ( self , p)
345
+ }
346
+
347
+ fn visit_generics ( & mut self , g : & ' v hir:: Generics < ' v > ) {
348
+ self . record ( "Generics" , Id :: None , g) ;
349
+ hir_visit:: walk_generics ( self , g)
350
+ }
351
+
352
+ fn visit_where_predicate ( & mut self , p : & ' v hir:: WherePredicate < ' v > ) {
353
+ record_variants ! (
354
+ ( self , p, p, Id :: None , hir, WherePredicate , WherePredicate ) ,
355
+ [ BoundPredicate , RegionPredicate , EqPredicate ]
356
+ ) ;
357
+ hir_visit:: walk_where_predicate ( self , p)
358
+ }
359
+
247
360
fn visit_fn (
248
361
& mut self ,
249
362
fk : hir_visit:: FnKind < ' v > ,
@@ -256,24 +369,49 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
256
369
hir_visit:: walk_fn ( self , fk, fd, b, s, id)
257
370
}
258
371
259
- fn visit_where_predicate ( & mut self , predicate : & ' v hir:: WherePredicate < ' v > ) {
260
- self . record ( "WherePredicate" , Id :: None , predicate) ;
261
- hir_visit:: walk_where_predicate ( self , predicate)
372
+ fn visit_use ( & mut self , p : & ' v hir:: Path < ' v > , hir_id : hir:: HirId ) {
373
+ // This is `visit_use`, but the type is `Path` so record it that way.
374
+ self . record ( "Path" , Id :: None , p) ;
375
+ hir_visit:: walk_use ( self , p, hir_id)
262
376
}
263
377
264
378
fn visit_trait_item ( & mut self , ti : & ' v hir:: TraitItem < ' v > ) {
265
- self . record ( "TraitItem" , Id :: Node ( ti. hir_id ( ) ) , ti) ;
379
+ record_variants ! (
380
+ ( self , ti, ti. kind, Id :: Node ( ti. hir_id( ) ) , hir, TraitItem , TraitItemKind ) ,
381
+ [ Const , Fn , Type ]
382
+ ) ;
266
383
hir_visit:: walk_trait_item ( self , ti)
267
384
}
268
385
386
+ fn visit_trait_item_ref ( & mut self , ti : & ' v hir:: TraitItemRef ) {
387
+ self . record ( "TraitItemRef" , Id :: Node ( ti. id . hir_id ( ) ) , ti) ;
388
+ hir_visit:: walk_trait_item_ref ( self , ti)
389
+ }
390
+
269
391
fn visit_impl_item ( & mut self , ii : & ' v hir:: ImplItem < ' v > ) {
270
- self . record ( "ImplItem" , Id :: Node ( ii. hir_id ( ) ) , ii) ;
392
+ record_variants ! (
393
+ ( self , ii, ii. kind, Id :: Node ( ii. hir_id( ) ) , hir, ImplItem , ImplItemKind ) ,
394
+ [ Const , Fn , TyAlias ]
395
+ ) ;
271
396
hir_visit:: walk_impl_item ( self , ii)
272
397
}
273
398
274
- fn visit_param_bound ( & mut self , bounds : & ' v hir:: GenericBound < ' v > ) {
275
- self . record ( "GenericBound" , Id :: None , bounds) ;
276
- hir_visit:: walk_param_bound ( self , bounds)
399
+ fn visit_foreign_item_ref ( & mut self , fi : & ' v hir:: ForeignItemRef ) {
400
+ self . record ( "ForeignItemRef" , Id :: Node ( fi. id . hir_id ( ) ) , fi) ;
401
+ hir_visit:: walk_foreign_item_ref ( self , fi)
402
+ }
403
+
404
+ fn visit_impl_item_ref ( & mut self , ii : & ' v hir:: ImplItemRef ) {
405
+ self . record ( "ImplItemRef" , Id :: Node ( ii. id . hir_id ( ) ) , ii) ;
406
+ hir_visit:: walk_impl_item_ref ( self , ii)
407
+ }
408
+
409
+ fn visit_param_bound ( & mut self , b : & ' v hir:: GenericBound < ' v > ) {
410
+ record_variants ! (
411
+ ( self , b, b, Id :: None , hir, GenericBound , GenericBound ) ,
412
+ [ Trait , LangItemTrait , Outlives ]
413
+ ) ;
414
+ hir_visit:: walk_param_bound ( self , b)
277
415
}
278
416
279
417
fn visit_field_def ( & mut self , s : & ' v hir:: FieldDef < ' v > ) {
@@ -286,14 +424,17 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
286
424
hir_visit:: walk_variant ( self , v)
287
425
}
288
426
289
- fn visit_lifetime ( & mut self , lifetime : & ' v hir:: Lifetime ) {
290
- self . record ( "Lifetime" , Id :: Node ( lifetime. hir_id ) , lifetime) ;
291
- hir_visit:: walk_lifetime ( self , lifetime)
292
- }
293
-
294
- fn visit_qpath ( & mut self , qpath : & ' v hir:: QPath < ' v > , id : hir:: HirId , span : Span ) {
295
- self . record ( "QPath" , Id :: None , qpath) ;
296
- hir_visit:: walk_qpath ( self , qpath, id, span)
427
+ fn visit_generic_arg ( & mut self , ga : & ' v hir:: GenericArg < ' v > ) {
428
+ record_variants ! (
429
+ ( self , ga, ga, Id :: Node ( ga. hir_id( ) ) , hir, GenericArg , GenericArg ) ,
430
+ [ Lifetime , Type , Const , Infer ]
431
+ ) ;
432
+ match ga {
433
+ hir:: GenericArg :: Lifetime ( lt) => self . visit_lifetime ( lt) ,
434
+ hir:: GenericArg :: Type ( ty) => self . visit_ty ( ty) ,
435
+ hir:: GenericArg :: Const ( ct) => self . visit_anon_const ( & ct. value ) ,
436
+ hir:: GenericArg :: Infer ( inf) => self . visit_infer ( inf) ,
437
+ }
297
438
}
298
439
299
440
fn visit_path ( & mut self , path : & ' v hir:: Path < ' v > , _id : hir:: HirId ) {
@@ -306,6 +447,11 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
306
447
hir_visit:: walk_path_segment ( self , path_span, path_segment)
307
448
}
308
449
450
+ fn visit_generic_args ( & mut self , sp : Span , ga : & ' v hir:: GenericArgs < ' v > ) {
451
+ self . record ( "GenericArgs" , Id :: None , ga) ;
452
+ hir_visit:: walk_generic_args ( self , sp, ga)
453
+ }
454
+
309
455
fn visit_assoc_type_binding ( & mut self , type_binding : & ' v hir:: TypeBinding < ' v > ) {
310
456
self . record ( "TypeBinding" , Id :: Node ( type_binding. hir_id ) , type_binding) ;
311
457
hir_visit:: walk_assoc_type_binding ( self , type_binding)
@@ -314,36 +460,25 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
314
460
fn visit_attribute ( & mut self , attr : & ' v ast:: Attribute ) {
315
461
self . record ( "Attribute" , Id :: Attr ( attr. id ) , attr) ;
316
462
}
317
- }
318
463
319
- // Used to avoid boilerplate for types with many variants.
320
- macro_rules! record_variants {
321
- (
322
- ( $self: ident, $val: expr, $kind: expr, $ty: ty, $tykind: ident) , // mandatory pieces
323
- [ $( $variant: ident) ,* ]
324
- ) => {
325
- match $kind {
326
- $(
327
- ast:: $tykind:: $variant { .. } => {
328
- $self. record_variant( stringify!( $ty) , stringify!( $variant) , Id :: None , $val)
329
- }
330
- ) *
331
- }
332
- } ;
464
+ fn visit_inline_asm ( & mut self , asm : & ' v hir:: InlineAsm < ' v > , id : HirId ) {
465
+ self . record ( "InlineAsm" , Id :: None , asm) ;
466
+ hir_visit:: walk_inline_asm ( self , asm, id) ;
467
+ }
333
468
}
334
469
335
470
impl < ' v > ast_visit:: Visitor < ' v > for StatCollector < ' v > {
336
471
fn visit_foreign_item ( & mut self , i : & ' v ast:: ForeignItem ) {
337
472
record_variants ! (
338
- ( self , i, i. kind, ForeignItem , ForeignItemKind ) ,
473
+ ( self , i, i. kind, Id :: None , ast , ForeignItem , ForeignItemKind ) ,
339
474
[ Static , Fn , TyAlias , MacCall ]
340
475
) ;
341
476
ast_visit:: walk_foreign_item ( self , i)
342
477
}
343
478
344
479
fn visit_item ( & mut self , i : & ' v ast:: Item ) {
345
480
record_variants ! (
346
- ( self , i, i. kind, Item , ItemKind ) ,
481
+ ( self , i, i. kind, Id :: None , ast , Item , ItemKind ) ,
347
482
[
348
483
ExternCrate ,
349
484
Use ,
@@ -379,7 +514,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
379
514
380
515
fn visit_stmt ( & mut self , s : & ' v ast:: Stmt ) {
381
516
record_variants ! (
382
- ( self , s, s. kind, Stmt , StmtKind ) ,
517
+ ( self , s, s. kind, Id :: None , ast , Stmt , StmtKind ) ,
383
518
[ Local , Item , Expr , Semi , Empty , MacCall ]
384
519
) ;
385
520
ast_visit:: walk_stmt ( self , s)
@@ -397,7 +532,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
397
532
398
533
fn visit_pat ( & mut self , p : & ' v ast:: Pat ) {
399
534
record_variants ! (
400
- ( self , p, p. kind, Pat , PatKind ) ,
535
+ ( self , p, p. kind, Id :: None , ast , Pat , PatKind ) ,
401
536
[
402
537
Wild ,
403
538
Ident ,
@@ -421,7 +556,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
421
556
422
557
fn visit_expr ( & mut self , e : & ' v ast:: Expr ) {
423
558
record_variants ! (
424
- ( self , e, e. kind, Expr , ExprKind ) ,
559
+ ( self , e, e. kind, Id :: None , ast , Expr , ExprKind ) ,
425
560
[
426
561
Box , Array , ConstBlock , Call , MethodCall , Tup , Binary , Unary , Lit , Cast , Type , Let ,
427
562
If , While , ForLoop , Loop , Match , Closure , Block , Async , Await , TryBlock , Assign ,
@@ -434,7 +569,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
434
569
435
570
fn visit_ty ( & mut self , t : & ' v ast:: Ty ) {
436
571
record_variants ! (
437
- ( self , t, t. kind, Ty , TyKind ) ,
572
+ ( self , t, t. kind, Id :: None , ast , Ty , TyKind ) ,
438
573
[
439
574
Slice ,
440
575
Array ,
@@ -466,7 +601,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
466
601
467
602
fn visit_where_predicate ( & mut self , p : & ' v ast:: WherePredicate ) {
468
603
record_variants ! (
469
- ( self , p, p, WherePredicate , WherePredicate ) ,
604
+ ( self , p, p, Id :: None , ast , WherePredicate , WherePredicate ) ,
470
605
[ BoundPredicate , RegionPredicate , EqPredicate ]
471
606
) ;
472
607
ast_visit:: walk_where_predicate ( self , p)
@@ -479,14 +614,17 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
479
614
480
615
fn visit_assoc_item ( & mut self , i : & ' v ast:: AssocItem , ctxt : ast_visit:: AssocCtxt ) {
481
616
record_variants ! (
482
- ( self , i, i. kind, AssocItem , AssocItemKind ) ,
617
+ ( self , i, i. kind, Id :: None , ast , AssocItem , AssocItemKind ) ,
483
618
[ Const , Fn , TyAlias , MacCall ]
484
619
) ;
485
620
ast_visit:: walk_assoc_item ( self , i, ctxt) ;
486
621
}
487
622
488
623
fn visit_param_bound ( & mut self , b : & ' v ast:: GenericBound , _ctxt : BoundKind ) {
489
- record_variants ! ( ( self , b, b, GenericBound , GenericBound ) , [ Trait , Outlives ] ) ;
624
+ record_variants ! (
625
+ ( self , b, b, Id :: None , ast, GenericBound , GenericBound ) ,
626
+ [ Trait , Outlives ]
627
+ ) ;
490
628
ast_visit:: walk_param_bound ( self , b)
491
629
}
492
630
@@ -519,12 +657,18 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
519
657
// common, so we implement `visit_generic_args` and tolerate the double
520
658
// counting in the former case.
521
659
fn visit_generic_args ( & mut self , sp : Span , g : & ' v ast:: GenericArgs ) {
522
- record_variants ! ( ( self , g, g, GenericArgs , GenericArgs ) , [ AngleBracketed , Parenthesized ] ) ;
660
+ record_variants ! (
661
+ ( self , g, g, Id :: None , ast, GenericArgs , GenericArgs ) ,
662
+ [ AngleBracketed , Parenthesized ]
663
+ ) ;
523
664
ast_visit:: walk_generic_args ( self , sp, g)
524
665
}
525
666
526
667
fn visit_attribute ( & mut self , attr : & ' v ast:: Attribute ) {
527
- record_variants ! ( ( self , attr, attr. kind, Attribute , AttrKind ) , [ Normal , DocComment ] ) ;
668
+ record_variants ! (
669
+ ( self , attr, attr. kind, Id :: None , ast, Attribute , AttrKind ) ,
670
+ [ Normal , DocComment ]
671
+ ) ;
528
672
ast_visit:: walk_attribute ( self , attr)
529
673
}
530
674
0 commit comments