@@ -228,7 +228,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
228
228
self . map [ id. as_usize ( ) ] = Some ( entry) ;
229
229
}
230
230
231
- fn insert ( & mut self , span : Span , id : NodeId , node : Node < ' hir > ) {
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 > ) {
232
233
let entry = Entry {
233
234
parent : self . parent_node ,
234
235
parent_hir : self . parent_hir ,
@@ -243,18 +244,18 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
243
244
// Make sure that the DepNode of some node coincides with the HirId
244
245
// owner of that node.
245
246
if cfg ! ( debug_assertions) {
246
- let hir_id = self . definitions . node_to_hir_id ( id ) ;
247
+ assert_eq ! ( self . definitions. node_to_hir_id( node_id ) , hir_id ) ;
247
248
248
249
if hir_id. owner != self . current_dep_node_owner {
249
- let node_str = match self . definitions . opt_def_index ( id ) {
250
+ let node_str = match self . definitions . opt_def_index ( node_id ) {
250
251
Some ( def_index) => {
251
252
self . definitions . def_path ( def_index) . to_string_no_crate ( )
252
253
}
253
254
None => format ! ( "{:?}" , node)
254
255
} ;
255
256
256
257
let forgot_str = if hir_id == crate :: hir:: DUMMY_HIR_ID {
257
- format ! ( "\n Maybe you forgot to lower the node id {:?}?" , id )
258
+ format ! ( "\n Maybe you forgot to lower the node id {:?}?" , node_id )
258
259
} else {
259
260
String :: new ( )
260
261
} ;
@@ -276,13 +277,21 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
276
277
}
277
278
}
278
279
279
- self . insert_entry ( id , entry) ;
280
+ self . insert_entry ( node_id , entry) ;
280
281
}
281
282
282
- fn with_parent < F : FnOnce ( & mut Self ) > ( & mut self , parent_id : NodeId , f : F ) {
283
+ fn with_parent < F : FnOnce ( & mut Self ) > (
284
+ & mut self ,
285
+ parent_node_id : NodeId ,
286
+ parent_hir_id : HirId ,
287
+ f : F ,
288
+ ) {
283
289
let parent_node = self . parent_node ;
284
- self . parent_node = parent_id;
290
+ self . parent_node = parent_node_id;
291
+ let parent_hir = self . parent_hir ;
292
+ self . parent_hir = parent_hir_id;
285
293
f ( self ) ;
294
+ self . parent_hir = parent_hir;
286
295
self . parent_node = parent_node;
287
296
}
288
297
@@ -352,12 +361,13 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
352
361
debug_assert_eq ! ( i. hir_id. owner,
353
362
self . definitions. opt_def_index( i. id) . unwrap( ) ) ;
354
363
self . with_dep_node_owner ( i. hir_id . owner , i, |this| {
355
- this. insert ( i. span , i. id , Node :: Item ( i) ) ;
356
- this. with_parent ( i. id , |this| {
364
+ this. insert ( i. span , i. id , i . hir_id , Node :: Item ( i) ) ;
365
+ this. with_parent ( i. id , i . hir_id , |this| {
357
366
if let ItemKind :: Struct ( ref struct_def, _) = i. node {
358
367
// If this is a tuple-like struct, register the constructor.
359
368
if !struct_def. is_struct ( ) {
360
- this. insert ( i. span , struct_def. id ( ) , Node :: StructCtor ( struct_def) ) ;
369
+ this. insert ( i. span , struct_def. id ( ) , struct_def. hir_id ( ) ,
370
+ Node :: StructCtor ( struct_def) ) ;
361
371
}
362
372
}
363
373
intravisit:: walk_item ( this, i) ;
@@ -366,25 +376,26 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
366
376
}
367
377
368
378
fn visit_foreign_item ( & mut self , foreign_item : & ' hir ForeignItem ) {
369
- self . insert ( foreign_item. span , foreign_item. id , Node :: ForeignItem ( foreign_item) ) ;
379
+ self . insert ( foreign_item. span , foreign_item. id , foreign_item. hir_id ,
380
+ Node :: ForeignItem ( foreign_item) ) ;
370
381
371
- self . with_parent ( foreign_item. id , |this| {
382
+ self . with_parent ( foreign_item. id , foreign_item . hir_id , |this| {
372
383
intravisit:: walk_foreign_item ( this, foreign_item) ;
373
384
} ) ;
374
385
}
375
386
376
387
fn visit_generic_param ( & mut self , param : & ' hir GenericParam ) {
377
- self . insert ( param. span , param. id , Node :: GenericParam ( param) ) ;
388
+ self . insert ( param. span , param. id , param . hir_id , Node :: GenericParam ( param) ) ;
378
389
intravisit:: walk_generic_param ( self , param) ;
379
390
}
380
391
381
392
fn visit_trait_item ( & mut self , ti : & ' hir TraitItem ) {
382
393
debug_assert_eq ! ( ti. hir_id. owner,
383
394
self . definitions. opt_def_index( ti. id) . unwrap( ) ) ;
384
395
self . with_dep_node_owner ( ti. hir_id . owner , ti, |this| {
385
- this. insert ( ti. span , ti. id , Node :: TraitItem ( ti) ) ;
396
+ this. insert ( ti. span , ti. id , ti . hir_id , Node :: TraitItem ( ti) ) ;
386
397
387
- this. with_parent ( ti. id , |this| {
398
+ this. with_parent ( ti. id , ti . hir_id , |this| {
388
399
intravisit:: walk_trait_item ( this, ti) ;
389
400
} ) ;
390
401
} ) ;
@@ -394,9 +405,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
394
405
debug_assert_eq ! ( ii. hir_id. owner,
395
406
self . definitions. opt_def_index( ii. id) . unwrap( ) ) ;
396
407
self . with_dep_node_owner ( ii. hir_id . owner , ii, |this| {
397
- this. insert ( ii. span , ii. id , Node :: ImplItem ( ii) ) ;
408
+ this. insert ( ii. span , ii. id , ii . hir_id , Node :: ImplItem ( ii) ) ;
398
409
399
- this. with_parent ( ii. id , |this| {
410
+ this. with_parent ( ii. id , ii . hir_id , |this| {
400
411
intravisit:: walk_impl_item ( this, ii) ;
401
412
} ) ;
402
413
} ) ;
@@ -408,93 +419,93 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
408
419
} else {
409
420
Node :: Pat ( pat)
410
421
} ;
411
- self . insert ( pat. span , pat. id , node) ;
422
+ self . insert ( pat. span , pat. id , pat . hir_id , node) ;
412
423
413
- self . with_parent ( pat. id , |this| {
424
+ self . with_parent ( pat. id , pat . hir_id , |this| {
414
425
intravisit:: walk_pat ( this, pat) ;
415
426
} ) ;
416
427
}
417
428
418
429
fn visit_anon_const ( & mut self , constant : & ' hir AnonConst ) {
419
- self . insert ( DUMMY_SP , constant. id , Node :: AnonConst ( constant) ) ;
430
+ self . insert ( DUMMY_SP , constant. id , constant . hir_id , Node :: AnonConst ( constant) ) ;
420
431
421
- self . with_parent ( constant. id , |this| {
432
+ self . with_parent ( constant. id , constant . hir_id , |this| {
422
433
intravisit:: walk_anon_const ( this, constant) ;
423
434
} ) ;
424
435
}
425
436
426
437
fn visit_expr ( & mut self , expr : & ' hir Expr ) {
427
- self . insert ( expr. span , expr. id , Node :: Expr ( expr) ) ;
438
+ self . insert ( expr. span , expr. id , expr . hir_id , Node :: Expr ( expr) ) ;
428
439
429
- self . with_parent ( expr. id , |this| {
440
+ self . with_parent ( expr. id , expr . hir_id , |this| {
430
441
intravisit:: walk_expr ( this, expr) ;
431
442
} ) ;
432
443
}
433
444
434
445
fn visit_stmt ( & mut self , stmt : & ' hir Stmt ) {
435
- let id = stmt. id ;
436
- self . insert ( stmt. span , id, Node :: Stmt ( stmt) ) ;
446
+ self . insert ( stmt. span , stmt. id , stmt. hir_id , Node :: Stmt ( stmt) ) ;
437
447
438
- self . with_parent ( id , |this| {
448
+ self . with_parent ( stmt . id , stmt . hir_id , |this| {
439
449
intravisit:: walk_stmt ( this, stmt) ;
440
450
} ) ;
441
451
}
442
452
443
453
fn visit_path_segment ( & mut self , path_span : Span , path_segment : & ' hir PathSegment ) {
444
- if let Some ( id) = path_segment. id {
445
- self . insert ( path_span, id, Node :: PathSegment ( path_segment) ) ;
454
+ if let Some ( node_id) = path_segment. id {
455
+ let hir_id = path_segment. hir_id . unwrap ( ) ;
456
+ self . insert ( path_span, node_id, hir_id, Node :: PathSegment ( path_segment) ) ;
446
457
}
447
458
intravisit:: walk_path_segment ( self , path_span, path_segment) ;
448
459
}
449
460
450
461
fn visit_ty ( & mut self , ty : & ' hir Ty ) {
451
- self . insert ( ty. span , ty. id , Node :: Ty ( ty) ) ;
462
+ self . insert ( ty. span , ty. id , ty . hir_id , Node :: Ty ( ty) ) ;
452
463
453
- self . with_parent ( ty. id , |this| {
464
+ self . with_parent ( ty. id , ty . hir_id , |this| {
454
465
intravisit:: walk_ty ( this, ty) ;
455
466
} ) ;
456
467
}
457
468
458
469
fn visit_trait_ref ( & mut self , tr : & ' hir TraitRef ) {
459
- self . insert ( tr. path . span , tr. ref_id , Node :: TraitRef ( tr) ) ;
470
+ self . insert ( tr. path . span , tr. ref_id , tr . hir_ref_id , Node :: TraitRef ( tr) ) ;
460
471
461
- self . with_parent ( tr. ref_id , |this| {
472
+ self . with_parent ( tr. ref_id , tr . hir_ref_id , |this| {
462
473
intravisit:: walk_trait_ref ( this, tr) ;
463
474
} ) ;
464
475
}
465
476
466
477
fn visit_fn ( & mut self , fk : intravisit:: FnKind < ' hir > , fd : & ' hir FnDecl ,
467
- b : BodyId , s : Span , id : NodeId ) {
468
- assert_eq ! ( self . parent_node , id) ;
478
+ b : BodyId , s : Span , id : HirId ) {
479
+ assert_eq ! ( self . parent_hir , id) ;
469
480
intravisit:: walk_fn ( self , fk, fd, b, s, id) ;
470
481
}
471
482
472
483
fn visit_block ( & mut self , block : & ' hir Block ) {
473
- self . insert ( block. span , block. id , Node :: Block ( block) ) ;
474
- self . with_parent ( block. id , |this| {
484
+ self . insert ( block. span , block. id , block . hir_id , Node :: Block ( block) ) ;
485
+ self . with_parent ( block. id , block . hir_id , |this| {
475
486
intravisit:: walk_block ( this, block) ;
476
487
} ) ;
477
488
}
478
489
479
490
fn visit_local ( & mut self , l : & ' hir Local ) {
480
- self . insert ( l. span , l. id , Node :: Local ( l) ) ;
481
- self . with_parent ( l. id , |this| {
491
+ self . insert ( l. span , l. id , l . hir_id , Node :: Local ( l) ) ;
492
+ self . with_parent ( l. id , l . hir_id , |this| {
482
493
intravisit:: walk_local ( this, l)
483
494
} )
484
495
}
485
496
486
497
fn visit_lifetime ( & mut self , lifetime : & ' hir Lifetime ) {
487
- self . insert ( lifetime. span , lifetime. id , Node :: Lifetime ( lifetime) ) ;
498
+ self . insert ( lifetime. span , lifetime. id , lifetime . hir_id , Node :: Lifetime ( lifetime) ) ;
488
499
}
489
500
490
501
fn visit_vis ( & mut self , visibility : & ' hir Visibility ) {
491
502
match visibility. node {
492
503
VisibilityKind :: Public |
493
504
VisibilityKind :: Crate ( _) |
494
505
VisibilityKind :: Inherited => { }
495
- VisibilityKind :: Restricted { id, .. } => {
496
- self . insert ( visibility. span , id, Node :: Visibility ( visibility) ) ;
497
- self . with_parent ( id, |this| {
506
+ VisibilityKind :: Restricted { id, hir_id , .. } => {
507
+ self . insert ( visibility. span , id, hir_id , Node :: Visibility ( visibility) ) ;
508
+ self . with_parent ( id, hir_id , |this| {
498
509
intravisit:: walk_vis ( this, visibility) ;
499
510
} ) ;
500
511
}
@@ -505,21 +516,20 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
505
516
let def_index = self . definitions . opt_def_index ( macro_def. id ) . unwrap ( ) ;
506
517
507
518
self . with_dep_node_owner ( def_index, macro_def, |this| {
508
- this. insert ( macro_def. span , macro_def. id , Node :: MacroDef ( macro_def) ) ;
519
+ this. insert ( macro_def. span , macro_def. id , macro_def . hir_id , Node :: MacroDef ( macro_def) ) ;
509
520
} ) ;
510
521
}
511
522
512
- fn visit_variant ( & mut self , v : & ' hir Variant , g : & ' hir Generics , item_id : NodeId ) {
513
- let id = v. node . data . id ( ) ;
514
- self . insert ( v. span , id, Node :: Variant ( v) ) ;
515
- self . with_parent ( id, |this| {
523
+ 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) ) ;
525
+ self . with_parent ( v. node . data . id ( ) , v. node . data . hir_id ( ) , |this| {
516
526
intravisit:: walk_variant ( this, v, g, item_id) ;
517
527
} ) ;
518
528
}
519
529
520
530
fn visit_struct_field ( & mut self , field : & ' hir StructField ) {
521
- self . insert ( field. span , field. id , Node :: Field ( field) ) ;
522
- self . with_parent ( field. id , |this| {
531
+ self . insert ( field. span , field. id , field . hir_id , Node :: Field ( field) ) ;
532
+ self . with_parent ( field. id , field . hir_id , |this| {
523
533
intravisit:: walk_struct_field ( this, field) ;
524
534
} ) ;
525
535
}
0 commit comments