@@ -40,6 +40,7 @@ pub(super) struct NodeCollector<'a, 'hir> {
40
40
41
41
dep_graph : & ' a DepGraph ,
42
42
definitions : & ' a definitions:: Definitions ,
43
+ hir_to_node_id : & ' a FxHashMap < HirId , NodeId > ,
43
44
44
45
hcx : StableHashingContext < ' a > ,
45
46
@@ -100,6 +101,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
100
101
krate : & ' hir Crate ,
101
102
dep_graph : & ' a DepGraph ,
102
103
definitions : & ' a definitions:: Definitions ,
104
+ hir_to_node_id : & ' a FxHashMap < HirId , NodeId > ,
103
105
mut hcx : StableHashingContext < ' a > )
104
106
-> NodeCollector < ' a , ' hir > {
105
107
let root_mod_def_path_hash = definitions. def_path_hash ( CRATE_DEF_INDEX ) ;
@@ -155,6 +157,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
155
157
currently_in_body : false ,
156
158
dep_graph,
157
159
definitions,
160
+ hir_to_node_id,
158
161
hcx,
159
162
hir_body_nodes,
160
163
} ;
@@ -228,8 +231,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
228
231
self . map [ id. as_usize ( ) ] = Some ( entry) ;
229
232
}
230
233
231
- // FIXME(ljedrz): devise a way to get rid of this NodeId
232
- fn insert ( & mut self , span : Span , node_id : NodeId , hir_id : HirId , node : Node < ' hir > ) {
234
+ fn insert ( & mut self , span : Span , hir_id : HirId , node : Node < ' hir > ) {
233
235
let entry = Entry {
234
236
parent : self . parent_node ,
235
237
parent_hir : self . parent_hir ,
@@ -241,6 +243,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
241
243
node,
242
244
} ;
243
245
246
+ let node_id = self . hir_to_node_id [ & hir_id] ;
247
+
244
248
// Make sure that the DepNode of some node coincides with the HirId
245
249
// owner of that node.
246
250
if cfg ! ( debug_assertions) {
@@ -361,13 +365,12 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
361
365
debug_assert_eq ! ( i. hir_id. owner,
362
366
self . definitions. opt_def_index( i. id) . unwrap( ) ) ;
363
367
self . with_dep_node_owner ( i. hir_id . owner , i, |this| {
364
- this. insert ( i. span , i. id , i . hir_id , Node :: Item ( i) ) ;
368
+ this. insert ( i. span , i. hir_id , Node :: Item ( i) ) ;
365
369
this. with_parent ( i. id , i. hir_id , |this| {
366
370
if let ItemKind :: Struct ( ref struct_def, _) = i. node {
367
371
// If this is a tuple-like struct, register the constructor.
368
372
if !struct_def. is_struct ( ) {
369
- this. insert ( i. span , struct_def. id ( ) , struct_def. hir_id ( ) ,
370
- Node :: StructCtor ( struct_def) ) ;
373
+ this. insert ( i. span , struct_def. hir_id ( ) , Node :: StructCtor ( struct_def) ) ;
371
374
}
372
375
}
373
376
intravisit:: walk_item ( this, i) ;
@@ -376,24 +379,23 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
376
379
}
377
380
378
381
fn visit_foreign_item ( & mut self , foreign_item : & ' hir ForeignItem ) {
379
- self . insert ( foreign_item. span , foreign_item. id , foreign_item. hir_id ,
380
- Node :: ForeignItem ( foreign_item) ) ;
382
+ self . insert ( foreign_item. span , foreign_item. hir_id , Node :: ForeignItem ( foreign_item) ) ;
381
383
382
384
self . with_parent ( foreign_item. id , foreign_item. hir_id , |this| {
383
385
intravisit:: walk_foreign_item ( this, foreign_item) ;
384
386
} ) ;
385
387
}
386
388
387
389
fn visit_generic_param ( & mut self , param : & ' hir GenericParam ) {
388
- self . insert ( param. span , param. id , param . hir_id , Node :: GenericParam ( param) ) ;
390
+ self . insert ( param. span , param. hir_id , Node :: GenericParam ( param) ) ;
389
391
intravisit:: walk_generic_param ( self , param) ;
390
392
}
391
393
392
394
fn visit_trait_item ( & mut self , ti : & ' hir TraitItem ) {
393
395
debug_assert_eq ! ( ti. hir_id. owner,
394
396
self . definitions. opt_def_index( ti. id) . unwrap( ) ) ;
395
397
self . with_dep_node_owner ( ti. hir_id . owner , ti, |this| {
396
- this. insert ( ti. span , ti. id , ti . hir_id , Node :: TraitItem ( ti) ) ;
398
+ this. insert ( ti. span , ti. hir_id , Node :: TraitItem ( ti) ) ;
397
399
398
400
this. with_parent ( ti. id , ti. hir_id , |this| {
399
401
intravisit:: walk_trait_item ( this, ti) ;
@@ -405,7 +407,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
405
407
debug_assert_eq ! ( ii. hir_id. owner,
406
408
self . definitions. opt_def_index( ii. id) . unwrap( ) ) ;
407
409
self . with_dep_node_owner ( ii. hir_id . owner , ii, |this| {
408
- this. insert ( ii. span , ii. id , ii . hir_id , Node :: ImplItem ( ii) ) ;
410
+ this. insert ( ii. span , ii. hir_id , Node :: ImplItem ( ii) ) ;
409
411
410
412
this. with_parent ( ii. id , ii. hir_id , |this| {
411
413
intravisit:: walk_impl_item ( this, ii) ;
@@ -419,55 +421,55 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
419
421
} else {
420
422
Node :: Pat ( pat)
421
423
} ;
422
- self . insert ( pat. span , pat. id , pat . hir_id , node) ;
424
+ self . insert ( pat. span , pat. hir_id , node) ;
423
425
424
426
self . with_parent ( pat. id , pat. hir_id , |this| {
425
427
intravisit:: walk_pat ( this, pat) ;
426
428
} ) ;
427
429
}
428
430
429
431
fn visit_anon_const ( & mut self , constant : & ' hir AnonConst ) {
430
- self . insert ( DUMMY_SP , constant. id , constant . hir_id , Node :: AnonConst ( constant) ) ;
432
+ self . insert ( DUMMY_SP , constant. hir_id , Node :: AnonConst ( constant) ) ;
431
433
432
434
self . with_parent ( constant. id , constant. hir_id , |this| {
433
435
intravisit:: walk_anon_const ( this, constant) ;
434
436
} ) ;
435
437
}
436
438
437
439
fn visit_expr ( & mut self , expr : & ' hir Expr ) {
438
- self . insert ( expr. span , expr. id , expr . hir_id , Node :: Expr ( expr) ) ;
440
+ self . insert ( expr. span , expr. hir_id , Node :: Expr ( expr) ) ;
439
441
440
442
self . with_parent ( expr. id , expr. hir_id , |this| {
441
443
intravisit:: walk_expr ( this, expr) ;
442
444
} ) ;
443
445
}
444
446
445
447
fn visit_stmt ( & mut self , stmt : & ' hir Stmt ) {
446
- self . insert ( stmt. span , stmt. id , stmt . hir_id , Node :: Stmt ( stmt) ) ;
448
+ self . insert ( stmt. span , stmt. hir_id , Node :: Stmt ( stmt) ) ;
447
449
448
450
self . with_parent ( stmt. id , stmt. hir_id , |this| {
449
451
intravisit:: walk_stmt ( this, stmt) ;
450
452
} ) ;
451
453
}
452
454
453
455
fn visit_path_segment ( & mut self , path_span : Span , path_segment : & ' hir PathSegment ) {
454
- if let Some ( node_id ) = path_segment. id {
456
+ if path_segment. id . is_some ( ) {
455
457
let hir_id = path_segment. hir_id . unwrap ( ) ;
456
- self . insert ( path_span, node_id , hir_id, Node :: PathSegment ( path_segment) ) ;
458
+ self . insert ( path_span, hir_id, Node :: PathSegment ( path_segment) ) ;
457
459
}
458
460
intravisit:: walk_path_segment ( self , path_span, path_segment) ;
459
461
}
460
462
461
463
fn visit_ty ( & mut self , ty : & ' hir Ty ) {
462
- self . insert ( ty. span , ty. id , ty . hir_id , Node :: Ty ( ty) ) ;
464
+ self . insert ( ty. span , ty. hir_id , Node :: Ty ( ty) ) ;
463
465
464
466
self . with_parent ( ty. id , ty. hir_id , |this| {
465
467
intravisit:: walk_ty ( this, ty) ;
466
468
} ) ;
467
469
}
468
470
469
471
fn visit_trait_ref ( & mut self , tr : & ' hir TraitRef ) {
470
- self . insert ( tr. path . span , tr. ref_id , tr . hir_ref_id , Node :: TraitRef ( tr) ) ;
472
+ self . insert ( tr. path . span , tr. hir_ref_id , Node :: TraitRef ( tr) ) ;
471
473
472
474
self . with_parent ( tr. ref_id , tr. hir_ref_id , |this| {
473
475
intravisit:: walk_trait_ref ( this, tr) ;
@@ -481,21 +483,21 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
481
483
}
482
484
483
485
fn visit_block ( & mut self , block : & ' hir Block ) {
484
- self . insert ( block. span , block. id , block . hir_id , Node :: Block ( block) ) ;
486
+ self . insert ( block. span , block. hir_id , Node :: Block ( block) ) ;
485
487
self . with_parent ( block. id , block. hir_id , |this| {
486
488
intravisit:: walk_block ( this, block) ;
487
489
} ) ;
488
490
}
489
491
490
492
fn visit_local ( & mut self , l : & ' hir Local ) {
491
- self . insert ( l. span , l. id , l . hir_id , Node :: Local ( l) ) ;
493
+ self . insert ( l. span , l. hir_id , Node :: Local ( l) ) ;
492
494
self . with_parent ( l. id , l. hir_id , |this| {
493
495
intravisit:: walk_local ( this, l)
494
496
} )
495
497
}
496
498
497
499
fn visit_lifetime ( & mut self , lifetime : & ' hir Lifetime ) {
498
- self . insert ( lifetime. span , lifetime. id , lifetime . hir_id , Node :: Lifetime ( lifetime) ) ;
500
+ self . insert ( lifetime. span , lifetime. hir_id , Node :: Lifetime ( lifetime) ) ;
499
501
}
500
502
501
503
fn visit_vis ( & mut self , visibility : & ' hir Visibility ) {
@@ -504,7 +506,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
504
506
VisibilityKind :: Crate ( _) |
505
507
VisibilityKind :: Inherited => { }
506
508
VisibilityKind :: Restricted { id, hir_id, .. } => {
507
- self . insert ( visibility. span , id , hir_id, Node :: Visibility ( visibility) ) ;
509
+ self . insert ( visibility. span , hir_id, Node :: Visibility ( visibility) ) ;
508
510
self . with_parent ( id, hir_id, |this| {
509
511
intravisit:: walk_vis ( this, visibility) ;
510
512
} ) ;
@@ -516,19 +518,19 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
516
518
let def_index = self . definitions . opt_def_index ( macro_def. id ) . unwrap ( ) ;
517
519
518
520
self . with_dep_node_owner ( def_index, macro_def, |this| {
519
- this. insert ( macro_def. span , macro_def. id , macro_def . hir_id , Node :: MacroDef ( macro_def) ) ;
521
+ this. insert ( macro_def. span , macro_def. hir_id , Node :: MacroDef ( macro_def) ) ;
520
522
} ) ;
521
523
}
522
524
523
525
fn visit_variant ( & mut self , v : & ' hir Variant , g : & ' hir Generics , item_id : HirId ) {
524
- self . insert ( v. span , v. node . data . id ( ) , v . node . data . hir_id ( ) , Node :: Variant ( v) ) ;
526
+ self . insert ( v. span , v. node . data . hir_id ( ) , Node :: Variant ( v) ) ;
525
527
self . with_parent ( v. node . data . id ( ) , v. node . data . hir_id ( ) , |this| {
526
528
intravisit:: walk_variant ( this, v, g, item_id) ;
527
529
} ) ;
528
530
}
529
531
530
532
fn visit_struct_field ( & mut self , field : & ' hir StructField ) {
531
- self . insert ( field. span , field. id , field . hir_id , Node :: Field ( field) ) ;
533
+ self . insert ( field. span , field. hir_id , Node :: Field ( field) ) ;
532
534
self . with_parent ( field. id , field. hir_id , |this| {
533
535
intravisit:: walk_struct_field ( this, field) ;
534
536
} ) ;
0 commit comments