@@ -15,7 +15,6 @@ use rustc_middle::middle::privacy;
15
15
use rustc_middle:: ty:: { self , DefIdTree , TyCtxt } ;
16
16
use rustc_session:: lint;
17
17
18
- use rustc_ast as ast;
19
18
use rustc_span:: symbol:: { sym, Symbol } ;
20
19
21
20
// Any local node that may call something in its body block should be
@@ -346,11 +345,8 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
346
345
}
347
346
}
348
347
349
- fn has_allow_dead_code_or_lang_attr (
350
- tcx : TyCtxt < ' _ > ,
351
- id : hir:: HirId ,
352
- attrs : & [ ast:: Attribute ] ,
353
- ) -> bool {
348
+ fn has_allow_dead_code_or_lang_attr ( tcx : TyCtxt < ' _ > , id : hir:: HirId ) -> bool {
349
+ let attrs = tcx. hir ( ) . attrs ( id) ;
354
350
if tcx. sess . contains_name ( attrs, sym:: lang) {
355
351
return true ;
356
352
}
@@ -400,8 +396,7 @@ struct LifeSeeder<'k, 'tcx> {
400
396
401
397
impl < ' v , ' k , ' tcx > ItemLikeVisitor < ' v > for LifeSeeder < ' k , ' tcx > {
402
398
fn visit_item ( & mut self , item : & hir:: Item < ' _ > ) {
403
- let allow_dead_code =
404
- has_allow_dead_code_or_lang_attr ( self . tcx , item. hir_id ( ) , & item. attrs ) ;
399
+ let allow_dead_code = has_allow_dead_code_or_lang_attr ( self . tcx , item. hir_id ( ) ) ;
405
400
if allow_dead_code {
406
401
self . worklist . push ( item. hir_id ( ) ) ;
407
402
}
@@ -424,11 +419,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
424
419
for impl_item_ref in items {
425
420
let impl_item = self . krate . impl_item ( impl_item_ref. id ) ;
426
421
if of_trait. is_some ( )
427
- || has_allow_dead_code_or_lang_attr (
428
- self . tcx ,
429
- impl_item. hir_id ( ) ,
430
- & impl_item. attrs ,
431
- )
422
+ || has_allow_dead_code_or_lang_attr ( self . tcx , impl_item. hir_id ( ) )
432
423
{
433
424
self . worklist . push ( impl_item_ref. id . hir_id ( ) ) ;
434
425
}
@@ -446,7 +437,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
446
437
fn visit_trait_item ( & mut self , trait_item : & hir:: TraitItem < ' _ > ) {
447
438
use hir:: TraitItemKind :: { Const , Fn } ;
448
439
if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Fn ( _, hir:: TraitFn :: Provided ( _) ) )
449
- && has_allow_dead_code_or_lang_attr ( self . tcx , trait_item. hir_id ( ) , & trait_item . attrs )
440
+ && has_allow_dead_code_or_lang_attr ( self . tcx , trait_item. hir_id ( ) )
450
441
{
451
442
self . worklist . push ( trait_item. hir_id ( ) ) ;
452
443
}
@@ -459,11 +450,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
459
450
fn visit_foreign_item ( & mut self , foreign_item : & hir:: ForeignItem < ' _ > ) {
460
451
use hir:: ForeignItemKind :: { Fn , Static } ;
461
452
if matches ! ( foreign_item. kind, Static ( ..) | Fn ( ..) )
462
- && has_allow_dead_code_or_lang_attr (
463
- self . tcx ,
464
- foreign_item. hir_id ( ) ,
465
- & foreign_item. attrs ,
466
- )
453
+ && has_allow_dead_code_or_lang_attr ( self . tcx , foreign_item. hir_id ( ) )
467
454
{
468
455
self . worklist . push ( foreign_item. hir_id ( ) ) ;
469
456
}
@@ -543,17 +530,16 @@ impl DeadVisitor<'tcx> {
543
530
!field. is_positional ( )
544
531
&& !self . symbol_is_live ( field. hir_id )
545
532
&& !field_type. is_phantom_data ( )
546
- && !has_allow_dead_code_or_lang_attr ( self . tcx , field. hir_id , & field . attrs )
533
+ && !has_allow_dead_code_or_lang_attr ( self . tcx , field. hir_id )
547
534
}
548
535
549
536
fn should_warn_about_variant ( & mut self , variant : & hir:: Variant < ' _ > ) -> bool {
550
- !self . symbol_is_live ( variant. id )
551
- && !has_allow_dead_code_or_lang_attr ( self . tcx , variant. id , & variant. attrs )
537
+ !self . symbol_is_live ( variant. id ) && !has_allow_dead_code_or_lang_attr ( self . tcx , variant. id )
552
538
}
553
539
554
540
fn should_warn_about_foreign_item ( & mut self , fi : & hir:: ForeignItem < ' _ > ) -> bool {
555
541
!self . symbol_is_live ( fi. hir_id ( ) )
556
- && !has_allow_dead_code_or_lang_attr ( self . tcx , fi. hir_id ( ) , & fi . attrs )
542
+ && !has_allow_dead_code_or_lang_attr ( self . tcx , fi. hir_id ( ) )
557
543
}
558
544
559
545
// id := HIR id of an item's definition.
0 commit comments