@@ -40,6 +40,7 @@ pub(super) struct NodeCollector<'a, 'hir> {
4040
4141 dep_graph : & ' a DepGraph ,
4242 definitions : & ' a definitions:: Definitions ,
43+ hir_to_node_id : & ' a FxHashMap < HirId , NodeId > ,
4344
4445 hcx : StableHashingContext < ' a > ,
4546
@@ -100,6 +101,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
100101 krate : & ' hir Crate ,
101102 dep_graph : & ' a DepGraph ,
102103 definitions : & ' a definitions:: Definitions ,
104+ hir_to_node_id : & ' a FxHashMap < HirId , NodeId > ,
103105 mut hcx : StableHashingContext < ' a > )
104106 -> NodeCollector < ' a , ' hir > {
105107 let root_mod_def_path_hash = definitions. def_path_hash ( CRATE_DEF_INDEX ) ;
@@ -155,6 +157,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
155157 currently_in_body : false ,
156158 dep_graph,
157159 definitions,
160+ hir_to_node_id,
158161 hcx,
159162 hir_body_nodes,
160163 } ;
@@ -228,8 +231,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
228231 self . map [ id. as_usize ( ) ] = Some ( entry) ;
229232 }
230233
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 > ) {
233235 let entry = Entry {
234236 parent : self . parent_node ,
235237 parent_hir : self . parent_hir ,
@@ -241,6 +243,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
241243 node,
242244 } ;
243245
246+ let node_id = self . hir_to_node_id [ & hir_id] ;
247+
244248 // Make sure that the DepNode of some node coincides with the HirId
245249 // owner of that node.
246250 if cfg ! ( debug_assertions) {
@@ -361,13 +365,12 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
361365 debug_assert_eq ! ( i. hir_id. owner,
362366 self . definitions. opt_def_index( i. id) . unwrap( ) ) ;
363367 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) ) ;
365369 this. with_parent ( i. id , i. hir_id , |this| {
366370 if let ItemKind :: Struct ( ref struct_def, _) = i. node {
367371 // If this is a tuple-like struct, register the constructor.
368372 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) ) ;
371374 }
372375 }
373376 intravisit:: walk_item ( this, i) ;
@@ -376,24 +379,23 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
376379 }
377380
378381 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) ) ;
381383
382384 self . with_parent ( foreign_item. id , foreign_item. hir_id , |this| {
383385 intravisit:: walk_foreign_item ( this, foreign_item) ;
384386 } ) ;
385387 }
386388
387389 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) ) ;
389391 intravisit:: walk_generic_param ( self , param) ;
390392 }
391393
392394 fn visit_trait_item ( & mut self , ti : & ' hir TraitItem ) {
393395 debug_assert_eq ! ( ti. hir_id. owner,
394396 self . definitions. opt_def_index( ti. id) . unwrap( ) ) ;
395397 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) ) ;
397399
398400 this. with_parent ( ti. id , ti. hir_id , |this| {
399401 intravisit:: walk_trait_item ( this, ti) ;
@@ -405,7 +407,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
405407 debug_assert_eq ! ( ii. hir_id. owner,
406408 self . definitions. opt_def_index( ii. id) . unwrap( ) ) ;
407409 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) ) ;
409411
410412 this. with_parent ( ii. id , ii. hir_id , |this| {
411413 intravisit:: walk_impl_item ( this, ii) ;
@@ -419,55 +421,55 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
419421 } else {
420422 Node :: Pat ( pat)
421423 } ;
422- self . insert ( pat. span , pat. id , pat . hir_id , node) ;
424+ self . insert ( pat. span , pat. hir_id , node) ;
423425
424426 self . with_parent ( pat. id , pat. hir_id , |this| {
425427 intravisit:: walk_pat ( this, pat) ;
426428 } ) ;
427429 }
428430
429431 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) ) ;
431433
432434 self . with_parent ( constant. id , constant. hir_id , |this| {
433435 intravisit:: walk_anon_const ( this, constant) ;
434436 } ) ;
435437 }
436438
437439 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) ) ;
439441
440442 self . with_parent ( expr. id , expr. hir_id , |this| {
441443 intravisit:: walk_expr ( this, expr) ;
442444 } ) ;
443445 }
444446
445447 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) ) ;
447449
448450 self . with_parent ( stmt. id , stmt. hir_id , |this| {
449451 intravisit:: walk_stmt ( this, stmt) ;
450452 } ) ;
451453 }
452454
453455 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 ( ) {
455457 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) ) ;
457459 }
458460 intravisit:: walk_path_segment ( self , path_span, path_segment) ;
459461 }
460462
461463 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) ) ;
463465
464466 self . with_parent ( ty. id , ty. hir_id , |this| {
465467 intravisit:: walk_ty ( this, ty) ;
466468 } ) ;
467469 }
468470
469471 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) ) ;
471473
472474 self . with_parent ( tr. ref_id , tr. hir_ref_id , |this| {
473475 intravisit:: walk_trait_ref ( this, tr) ;
@@ -481,21 +483,21 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
481483 }
482484
483485 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) ) ;
485487 self . with_parent ( block. id , block. hir_id , |this| {
486488 intravisit:: walk_block ( this, block) ;
487489 } ) ;
488490 }
489491
490492 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) ) ;
492494 self . with_parent ( l. id , l. hir_id , |this| {
493495 intravisit:: walk_local ( this, l)
494496 } )
495497 }
496498
497499 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) ) ;
499501 }
500502
501503 fn visit_vis ( & mut self , visibility : & ' hir Visibility ) {
@@ -504,7 +506,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
504506 VisibilityKind :: Crate ( _) |
505507 VisibilityKind :: Inherited => { }
506508 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) ) ;
508510 self . with_parent ( id, hir_id, |this| {
509511 intravisit:: walk_vis ( this, visibility) ;
510512 } ) ;
@@ -516,19 +518,19 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
516518 let def_index = self . definitions . opt_def_index ( macro_def. id ) . unwrap ( ) ;
517519
518520 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) ) ;
520522 } ) ;
521523 }
522524
523525 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) ) ;
525527 self . with_parent ( v. node . data . id ( ) , v. node . data . hir_id ( ) , |this| {
526528 intravisit:: walk_variant ( this, v, g, item_id) ;
527529 } ) ;
528530 }
529531
530532 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) ) ;
532534 self . with_parent ( field. id , field. hir_id , |this| {
533535 intravisit:: walk_struct_field ( this, field) ;
534536 } ) ;
0 commit comments