@@ -346,6 +346,7 @@ impl<'v> Visitor<'v> for LifeSeeder {
346
346
ast:: ItemTrait ( _, _, _, ref trait_items) => {
347
347
for trait_item in trait_items {
348
348
match trait_item. node {
349
+ ast:: ConstTraitItem ( _, Some ( _) ) |
349
350
ast:: MethodTraitItem ( _, Some ( _) ) => {
350
351
if has_allow_dead_code_or_lang_attr ( & trait_item. attrs ) {
351
352
self . worklist . push ( trait_item. id ) ;
@@ -358,7 +359,7 @@ impl<'v> Visitor<'v> for LifeSeeder {
358
359
ast:: ItemImpl ( _, _, _, ref opt_trait, _, ref impl_items) => {
359
360
for impl_item in impl_items {
360
361
match impl_item. node {
361
- ast:: ConstImplItem ( ..) => { }
362
+ ast:: ConstImplItem ( ..) |
362
363
ast:: MethodImplItem ( ..) => {
363
364
if opt_trait. is_some ( ) ||
364
365
has_allow_dead_code_or_lang_attr ( & impl_item. attrs ) {
@@ -400,7 +401,7 @@ fn create_and_seed_worklist(tcx: &ty::ctxt,
400
401
None => ( )
401
402
}
402
403
403
- // Seed implemented trait methods
404
+ // Seed implemented trait items
404
405
let mut life_seeder = LifeSeeder {
405
406
worklist : worklist
406
407
} ;
@@ -481,7 +482,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
481
482
|ctor| self . live_symbols . contains ( & ctor) ) {
482
483
return true ;
483
484
}
484
- // If it's a type whose methods are live, then it's live, too.
485
+ // If it's a type whose items are live, then it's live, too.
485
486
// This is done to handle the case where, for example, the static
486
487
// method of a private type is used, but the type itself is never
487
488
// called directly.
@@ -551,21 +552,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
551
552
visit:: walk_foreign_item ( self , fi) ;
552
553
}
553
554
554
- fn visit_fn ( & mut self , fk : visit:: FnKind < ' v > ,
555
- _: & ' v ast:: FnDecl , block : & ' v ast:: Block ,
556
- span : codemap:: Span , id : ast:: NodeId ) {
557
- // Have to warn method here because methods are not ast::Item
558
- match fk {
559
- visit:: FkMethod ( name, _, _) => {
560
- if !self . symbol_is_live ( id, None ) {
561
- self . warn_dead_code ( id, span, name. name , "method" ) ;
562
- }
563
- }
564
- _ => ( )
565
- }
566
- visit:: walk_block ( self , block) ;
567
- }
568
-
569
555
fn visit_struct_field ( & mut self , field : & ast:: StructField ) {
570
556
if self . should_warn_about_field ( & field. node ) {
571
557
self . warn_dead_code ( field. node . id , field. span ,
@@ -575,13 +561,37 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
575
561
visit:: walk_struct_field ( self , field) ;
576
562
}
577
563
578
- // Overwrite so that we don't warn the trait method itself.
579
- fn visit_trait_item ( & mut self , trait_method : & ast:: TraitItem ) {
580
- match trait_method. node {
581
- ast:: ConstTraitItem ( _, _) => { }
564
+ fn visit_impl_item ( & mut self , impl_item : & ast:: ImplItem ) {
565
+ match impl_item. node {
566
+ ast:: ConstImplItem ( _, ref expr) => {
567
+ if !self . symbol_is_live ( impl_item. id , None ) {
568
+ self . warn_dead_code ( impl_item. id , impl_item. span ,
569
+ impl_item. ident . name , "associated const" ) ;
570
+ }
571
+ visit:: walk_expr ( self , expr)
572
+ }
573
+ ast:: MethodImplItem ( _, ref body) => {
574
+ if !self . symbol_is_live ( impl_item. id , None ) {
575
+ self . warn_dead_code ( impl_item. id , impl_item. span ,
576
+ impl_item. ident . name , "method" ) ;
577
+ }
578
+ visit:: walk_block ( self , body)
579
+ }
580
+ ast:: TypeImplItem ( ..) |
581
+ ast:: MacImplItem ( ..) => { }
582
+ }
583
+ }
584
+
585
+ // Overwrite so that we don't warn the trait item itself.
586
+ fn visit_trait_item ( & mut self , trait_item : & ast:: TraitItem ) {
587
+ match trait_item. node {
588
+ ast:: ConstTraitItem ( _, Some ( ref expr) ) => {
589
+ visit:: walk_expr ( self , expr)
590
+ }
582
591
ast:: MethodTraitItem ( _, Some ( ref body) ) => {
583
592
visit:: walk_block ( self , body)
584
593
}
594
+ ast:: ConstTraitItem ( _, None ) |
585
595
ast:: MethodTraitItem ( _, None ) |
586
596
ast:: TypeTraitItem ( ..) => { }
587
597
}
0 commit comments