@@ -26,8 +26,8 @@ use syntax_pos;
26
26
// function, then we should explore its block to check for codes that
27
27
// may need to be marked as live.
28
28
fn should_explore < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
29
- node_id : ast :: NodeId ) -> bool {
30
- match tcx. hir ( ) . find ( node_id ) {
29
+ hir_id : hir :: HirId ) -> bool {
30
+ match tcx. hir ( ) . find_by_hir_id ( hir_id ) {
31
31
Some ( Node :: Item ( ..) ) |
32
32
Some ( Node :: ImplItem ( ..) ) |
33
33
Some ( Node :: ForeignItem ( ..) ) |
@@ -39,33 +39,33 @@ fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
39
39
}
40
40
41
41
struct MarkSymbolVisitor < ' a , ' tcx : ' a > {
42
- worklist : Vec < ast :: NodeId > ,
42
+ worklist : Vec < hir :: HirId > ,
43
43
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
44
44
tables : & ' a ty:: TypeckTables < ' tcx > ,
45
- live_symbols : FxHashSet < ast :: NodeId > ,
45
+ live_symbols : FxHashSet < hir :: HirId > ,
46
46
repr_has_repr_c : bool ,
47
47
in_pat : bool ,
48
48
inherited_pub_visibility : bool ,
49
49
ignore_variant_stack : Vec < DefId > ,
50
50
// maps from tuple struct constructors to tuple struct items
51
- struct_constructors : FxHashMap < ast :: NodeId , ast :: NodeId > ,
51
+ struct_constructors : FxHashMap < hir :: HirId , hir :: HirId > ,
52
52
}
53
53
54
54
impl < ' a , ' tcx > MarkSymbolVisitor < ' a , ' tcx > {
55
55
fn check_def_id ( & mut self , def_id : DefId ) {
56
- if let Some ( node_id ) = self . tcx . hir ( ) . as_local_node_id ( def_id) {
57
- if should_explore ( self . tcx , node_id ) ||
58
- self . struct_constructors . contains_key ( & node_id ) {
59
- self . worklist . push ( node_id ) ;
56
+ if let Some ( hir_id ) = self . tcx . hir ( ) . as_local_hir_id ( def_id) {
57
+ if should_explore ( self . tcx , hir_id ) ||
58
+ self . struct_constructors . contains_key ( & hir_id ) {
59
+ self . worklist . push ( hir_id ) ;
60
60
}
61
- self . live_symbols . insert ( node_id ) ;
61
+ self . live_symbols . insert ( hir_id ) ;
62
62
}
63
63
}
64
64
65
65
fn insert_def_id ( & mut self , def_id : DefId ) {
66
- if let Some ( node_id ) = self . tcx . hir ( ) . as_local_node_id ( def_id) {
67
- debug_assert ! ( !should_explore( self . tcx, node_id ) ) ;
68
- self . live_symbols . insert ( node_id ) ;
66
+ if let Some ( hir_id ) = self . tcx . hir ( ) . as_local_hir_id ( def_id) {
67
+ debug_assert ! ( !should_explore( self . tcx, hir_id ) ) ;
68
+ self . live_symbols . insert ( hir_id ) ;
69
69
}
70
70
}
71
71
@@ -136,7 +136,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
136
136
// tuple struct constructor function
137
137
let id = self . struct_constructors . get ( & id) . cloned ( ) . unwrap_or ( id) ;
138
138
139
- if let Some ( node) = self . tcx . hir ( ) . find ( id) {
139
+ if let Some ( node) = self . tcx . hir ( ) . find_by_hir_id ( id) {
140
140
self . live_symbols . insert ( id) ;
141
141
self . visit_node ( node) ;
142
142
}
@@ -217,7 +217,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
217
217
let live_fields = def. fields ( ) . iter ( ) . filter ( |f| {
218
218
has_repr_c || inherited_pub_visibility || f. vis . node . is_pub ( )
219
219
} ) ;
220
- self . live_symbols . extend ( live_fields. map ( |f| f. id ) ) ;
220
+ self . live_symbols . extend ( live_fields. map ( |f| f. hir_id ) ) ;
221
221
222
222
intravisit:: walk_struct_def ( self , def) ;
223
223
}
@@ -285,7 +285,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
285
285
}
286
286
287
287
fn has_allow_dead_code_or_lang_attr ( tcx : TyCtxt < ' _ , ' _ , ' _ > ,
288
- id : ast :: NodeId ,
288
+ id : hir :: HirId ,
289
289
attrs : & [ ast:: Attribute ] ) -> bool {
290
290
if attr:: contains_name ( attrs, "lang" ) {
291
291
return true ;
@@ -306,7 +306,7 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>,
306
306
return true ;
307
307
}
308
308
309
- let def_id = tcx. hir ( ) . local_def_id ( id) ;
309
+ let def_id = tcx. hir ( ) . local_def_id_from_hir_id ( id) ;
310
310
let cg_attrs = tcx. codegen_fn_attrs ( def_id) ;
311
311
312
312
// #[used], #[no_mangle], #[export_name], etc also keeps the item alive
@@ -333,25 +333,25 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>,
333
333
// 2) We are not sure to be live or not
334
334
// * Implementation of a trait method
335
335
struct LifeSeeder < ' k , ' tcx : ' k > {
336
- worklist : Vec < ast :: NodeId > ,
336
+ worklist : Vec < hir :: HirId > ,
337
337
krate : & ' k hir:: Crate ,
338
338
tcx : TyCtxt < ' k , ' tcx , ' tcx > ,
339
339
// see `MarkSymbolVisitor::struct_constructors`
340
- struct_constructors : FxHashMap < ast :: NodeId , ast :: NodeId > ,
340
+ struct_constructors : FxHashMap < hir :: HirId , hir :: HirId > ,
341
341
}
342
342
343
343
impl < ' v , ' k , ' tcx > ItemLikeVisitor < ' v > for LifeSeeder < ' k , ' tcx > {
344
344
fn visit_item ( & mut self , item : & hir:: Item ) {
345
345
let allow_dead_code = has_allow_dead_code_or_lang_attr ( self . tcx ,
346
- item. id ,
346
+ item. hir_id ,
347
347
& item. attrs ) ;
348
348
if allow_dead_code {
349
- self . worklist . push ( item. id ) ;
349
+ self . worklist . push ( item. hir_id ) ;
350
350
}
351
351
match item. node {
352
352
hir:: ItemKind :: Enum ( ref enum_def, _) if allow_dead_code => {
353
353
self . worklist . extend ( enum_def. variants . iter ( )
354
- . map ( |variant| variant. node . data . id ( ) ) ) ;
354
+ . map ( |variant| variant. node . data . hir_id ( ) ) ) ;
355
355
}
356
356
hir:: ItemKind :: Trait ( .., ref trait_item_refs) => {
357
357
for trait_item_ref in trait_item_refs {
@@ -360,9 +360,9 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
360
360
hir:: TraitItemKind :: Const ( _, Some ( _) ) |
361
361
hir:: TraitItemKind :: Method ( _, hir:: TraitMethod :: Provided ( _) ) => {
362
362
if has_allow_dead_code_or_lang_attr ( self . tcx ,
363
- trait_item. id ,
363
+ trait_item. hir_id ,
364
364
& trait_item. attrs ) {
365
- self . worklist . push ( trait_item. id ) ;
365
+ self . worklist . push ( trait_item. hir_id ) ;
366
366
}
367
367
}
368
368
_ => { }
@@ -374,14 +374,14 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
374
374
let impl_item = self . krate . impl_item ( impl_item_ref. id ) ;
375
375
if opt_trait. is_some ( ) ||
376
376
has_allow_dead_code_or_lang_attr ( self . tcx ,
377
- impl_item. id ,
377
+ impl_item. hir_id ,
378
378
& impl_item. attrs ) {
379
- self . worklist . push ( impl_item_ref. id . node_id ) ;
379
+ self . worklist . push ( self . tcx . hir ( ) . node_to_hir_id ( impl_item_ref. id . node_id ) ) ;
380
380
}
381
381
}
382
382
}
383
383
hir:: ItemKind :: Struct ( ref variant_data, _) => {
384
- self . struct_constructors . insert ( variant_data. id ( ) , item. id ) ;
384
+ self . struct_constructors . insert ( variant_data. hir_id ( ) , item. hir_id ) ;
385
385
}
386
386
_ => ( )
387
387
}
@@ -400,16 +400,16 @@ fn create_and_seed_worklist<'a, 'tcx>(
400
400
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
401
401
access_levels : & privacy:: AccessLevels ,
402
402
krate : & hir:: Crate ,
403
- ) -> ( Vec < ast :: NodeId > , FxHashMap < ast :: NodeId , ast :: NodeId > ) {
403
+ ) -> ( Vec < hir :: HirId > , FxHashMap < hir :: HirId , hir :: HirId > ) {
404
404
let worklist = access_levels. map . iter ( ) . filter_map ( |( & id, level) | {
405
405
if level >= & privacy:: AccessLevel :: Reachable {
406
- Some ( id )
406
+ Some ( tcx . hir ( ) . node_to_hir_id ( id ) )
407
407
} else {
408
408
None
409
409
}
410
410
} ) . chain (
411
411
// Seed entry point
412
- tcx. entry_fn ( LOCAL_CRATE ) . map ( |( def_id, _) | tcx. hir ( ) . as_local_node_id ( def_id) . unwrap ( ) )
412
+ tcx. entry_fn ( LOCAL_CRATE ) . map ( |( def_id, _) | tcx. hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) )
413
413
) . collect :: < Vec < _ > > ( ) ;
414
414
415
415
// Seed implemented trait items
@@ -427,7 +427,7 @@ fn create_and_seed_worklist<'a, 'tcx>(
427
427
fn find_live < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
428
428
access_levels : & privacy:: AccessLevels ,
429
429
krate : & hir:: Crate )
430
- -> FxHashSet < ast :: NodeId > {
430
+ -> FxHashSet < hir :: HirId > {
431
431
let ( worklist, struct_constructors) = create_and_seed_worklist ( tcx, access_levels, krate) ;
432
432
let mut symbol_visitor = MarkSymbolVisitor {
433
433
worklist,
@@ -446,7 +446,7 @@ fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
446
446
447
447
struct DeadVisitor < ' a , ' tcx : ' a > {
448
448
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
449
- live_symbols : FxHashSet < ast :: NodeId > ,
449
+ live_symbols : FxHashSet < hir :: HirId > ,
450
450
}
451
451
452
452
impl < ' a , ' tcx > DeadVisitor < ' a , ' tcx > {
@@ -461,33 +461,33 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
461
461
| hir:: ItemKind :: Union ( ..) => true ,
462
462
_ => false
463
463
} ;
464
- should_warn && !self . symbol_is_live ( item. id )
464
+ should_warn && !self . symbol_is_live ( item. hir_id )
465
465
}
466
466
467
467
fn should_warn_about_field ( & mut self , field : & hir:: StructField ) -> bool {
468
468
let field_type = self . tcx . type_of ( self . tcx . hir ( ) . local_def_id ( field. id ) ) ;
469
469
!field. is_positional ( )
470
- && !self . symbol_is_live ( field. id )
470
+ && !self . symbol_is_live ( field. hir_id )
471
471
&& !field_type. is_phantom_data ( )
472
- && !has_allow_dead_code_or_lang_attr ( self . tcx , field. id , & field. attrs )
472
+ && !has_allow_dead_code_or_lang_attr ( self . tcx , field. hir_id , & field. attrs )
473
473
}
474
474
475
475
fn should_warn_about_variant ( & mut self , variant : & hir:: VariantKind ) -> bool {
476
- !self . symbol_is_live ( variant. data . id ( ) )
476
+ !self . symbol_is_live ( variant. data . hir_id ( ) )
477
477
&& !has_allow_dead_code_or_lang_attr ( self . tcx ,
478
- variant. data . id ( ) ,
478
+ variant. data . hir_id ( ) ,
479
479
& variant. attrs )
480
480
}
481
481
482
482
fn should_warn_about_foreign_item ( & mut self , fi : & hir:: ForeignItem ) -> bool {
483
- !self . symbol_is_live ( fi. id )
484
- && !has_allow_dead_code_or_lang_attr ( self . tcx , fi. id , & fi. attrs )
483
+ !self . symbol_is_live ( fi. hir_id )
484
+ && !has_allow_dead_code_or_lang_attr ( self . tcx , fi. hir_id , & fi. attrs )
485
485
}
486
486
487
- // id := node id of an item's definition.
487
+ // id := HIR id of an item's definition.
488
488
fn symbol_is_live (
489
489
& mut self ,
490
- id : ast :: NodeId ,
490
+ id : hir :: HirId ,
491
491
) -> bool {
492
492
if self . live_symbols . contains ( & id) {
493
493
return true ;
@@ -496,12 +496,12 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
496
496
// This is done to handle the case where, for example, the static
497
497
// method of a private type is used, but the type itself is never
498
498
// called directly.
499
- let def_id = self . tcx . hir ( ) . local_def_id ( id) ;
499
+ let def_id = self . tcx . hir ( ) . local_def_id_from_hir_id ( id) ;
500
500
let inherent_impls = self . tcx . inherent_impls ( def_id) ;
501
501
for & impl_did in inherent_impls. iter ( ) {
502
502
for & item_did in & self . tcx . associated_item_def_ids ( impl_did) [ ..] {
503
- if let Some ( item_node_id ) = self . tcx . hir ( ) . as_local_node_id ( item_did) {
504
- if self . live_symbols . contains ( & item_node_id ) {
503
+ if let Some ( item_hir_id ) = self . tcx . hir ( ) . as_local_hir_id ( item_did) {
504
+ if self . live_symbols . contains ( & item_hir_id ) {
505
505
return true ;
506
506
}
507
507
}
@@ -511,18 +511,18 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
511
511
}
512
512
513
513
fn warn_dead_code ( & mut self ,
514
- id : ast :: NodeId ,
514
+ id : hir :: HirId ,
515
515
span : syntax_pos:: Span ,
516
516
name : ast:: Name ,
517
517
node_type : & str ,
518
518
participle : & str ) {
519
519
if !name. as_str ( ) . starts_with ( "_" ) {
520
520
self . tcx
521
- . lint_node ( lint:: builtin:: DEAD_CODE ,
522
- id,
523
- span,
524
- & format ! ( "{} is never {}: `{}`" ,
525
- node_type, participle, name) ) ;
521
+ . lint_hir ( lint:: builtin:: DEAD_CODE ,
522
+ id,
523
+ span,
524
+ & format ! ( "{} is never {}: `{}`" ,
525
+ node_type, participle, name) ) ;
526
526
}
527
527
}
528
528
}
@@ -555,7 +555,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
555
555
_ => "used"
556
556
} ;
557
557
self . warn_dead_code (
558
- item. id ,
558
+ item. hir_id ,
559
559
span,
560
560
item. ident . name ,
561
561
item. node . descriptive_variant ( ) ,
@@ -572,7 +572,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
572
572
g : & ' tcx hir:: Generics ,
573
573
id : hir:: HirId ) {
574
574
if self . should_warn_about_variant ( & variant. node ) {
575
- self . warn_dead_code ( variant. node . data . id ( ) , variant. span , variant. node . ident . name ,
575
+ self . warn_dead_code ( variant. node . data . hir_id ( ) , variant. span , variant. node . ident . name ,
576
576
"variant" , "constructed" ) ;
577
577
} else {
578
578
intravisit:: walk_variant ( self , variant, g, id) ;
@@ -581,24 +581,24 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
581
581
582
582
fn visit_foreign_item ( & mut self , fi : & ' tcx hir:: ForeignItem ) {
583
583
if self . should_warn_about_foreign_item ( fi) {
584
- self . warn_dead_code ( fi. id , fi. span , fi. ident . name ,
584
+ self . warn_dead_code ( fi. hir_id , fi. span , fi. ident . name ,
585
585
fi. node . descriptive_variant ( ) , "used" ) ;
586
586
}
587
587
intravisit:: walk_foreign_item ( self , fi) ;
588
588
}
589
589
590
590
fn visit_struct_field ( & mut self , field : & ' tcx hir:: StructField ) {
591
591
if self . should_warn_about_field ( & field) {
592
- self . warn_dead_code ( field. id , field. span , field. ident . name , "field" , "used" ) ;
592
+ self . warn_dead_code ( field. hir_id , field. span , field. ident . name , "field" , "used" ) ;
593
593
}
594
594
intravisit:: walk_struct_field ( self , field) ;
595
595
}
596
596
597
597
fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem ) {
598
598
match impl_item. node {
599
599
hir:: ImplItemKind :: Const ( _, body_id) => {
600
- if !self . symbol_is_live ( impl_item. id ) {
601
- self . warn_dead_code ( impl_item. id ,
600
+ if !self . symbol_is_live ( impl_item. hir_id ) {
601
+ self . warn_dead_code ( impl_item. hir_id ,
602
602
impl_item. span ,
603
603
impl_item. ident . name ,
604
604
"associated const" ,
@@ -607,9 +607,10 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
607
607
self . visit_nested_body ( body_id)
608
608
}
609
609
hir:: ImplItemKind :: Method ( _, body_id) => {
610
- if !self . symbol_is_live ( impl_item. id ) {
610
+ if !self . symbol_is_live ( impl_item. hir_id ) {
611
611
let span = self . tcx . sess . source_map ( ) . def_span ( impl_item. span ) ;
612
- self . warn_dead_code ( impl_item. id , span, impl_item. ident . name , "method" , "used" ) ;
612
+ self . warn_dead_code ( impl_item. hir_id , span, impl_item. ident . name , "method" ,
613
+ "used" ) ;
613
614
}
614
615
self . visit_nested_body ( body_id)
615
616
}
0 commit comments