@@ -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.
@@ -546,21 +547,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
546
547
visit:: walk_foreign_item ( self , fi) ;
547
548
}
548
549
549
- fn visit_fn ( & mut self , fk : visit:: FnKind < ' v > ,
550
- _: & ' v ast:: FnDecl , block : & ' v ast:: Block ,
551
- span : codemap:: Span , id : ast:: NodeId ) {
552
- // Have to warn method here because methods are not ast::Item
553
- match fk {
554
- visit:: FkMethod ( name, _) => {
555
- if !self . symbol_is_live ( id, None ) {
556
- self . warn_dead_code ( id, span, name, "method" ) ;
557
- }
558
- }
559
- _ => ( )
560
- }
561
- visit:: walk_block ( self , block) ;
562
- }
563
-
564
550
fn visit_struct_field ( & mut self , field : & ast:: StructField ) {
565
551
if self . should_warn_about_field ( & field. node ) {
566
552
self . warn_dead_code ( field. node . id , field. span ,
@@ -570,13 +556,37 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
570
556
visit:: walk_struct_field ( self , field) ;
571
557
}
572
558
573
- // Overwrite so that we don't warn the trait method itself.
574
- fn visit_trait_item ( & mut self , trait_method : & ast:: TraitItem ) {
575
- match trait_method. node {
576
- ast:: ConstTraitItem ( _, _) => { }
559
+ fn visit_impl_item ( & mut self , impl_item : & ast:: ImplItem ) {
560
+ match impl_item. node {
561
+ ast:: ConstImplItem ( _, ref expr) => {
562
+ if !self . symbol_is_live ( impl_item. id , None ) {
563
+ self . warn_dead_code ( impl_item. id , impl_item. span ,
564
+ impl_item. ident , "associated const" ) ;
565
+ }
566
+ visit:: walk_expr ( self , expr)
567
+ }
568
+ ast:: MethodImplItem ( _, ref body) => {
569
+ if !self . symbol_is_live ( impl_item. id , None ) {
570
+ self . warn_dead_code ( impl_item. id , impl_item. span ,
571
+ impl_item. ident , "method" ) ;
572
+ }
573
+ visit:: walk_block ( self , body)
574
+ }
575
+ ast:: TypeImplItem ( ..) |
576
+ ast:: MacImplItem ( ..) => { }
577
+ }
578
+ }
579
+
580
+ // Overwrite so that we don't warn the trait item itself.
581
+ fn visit_trait_item ( & mut self , trait_item : & ast:: TraitItem ) {
582
+ match trait_item. node {
583
+ ast:: ConstTraitItem ( _, Some ( ref expr) ) => {
584
+ visit:: walk_expr ( self , expr)
585
+ }
577
586
ast:: MethodTraitItem ( _, Some ( ref body) ) => {
578
587
visit:: walk_block ( self , body)
579
588
}
589
+ ast:: ConstTraitItem ( _, None ) |
580
590
ast:: MethodTraitItem ( _, None ) |
581
591
ast:: TypeTraitItem ( ..) => { }
582
592
}
0 commit comments