@@ -712,12 +712,12 @@ impl<'tcx> DeadVisitor<'tcx> {
712
712
713
713
let parent_info = if let Some ( parent_item) = parent_item {
714
714
let parent_descr = tcx. def_descr ( parent_item. to_def_id ( ) ) ;
715
- Some ( ParentInfo {
716
- num ,
717
- descr ,
718
- parent_descr ,
719
- span : tcx . def_ident_span ( parent_item ) . unwrap ( ) ,
720
- } )
715
+ let span = if let DefKind :: Impl { .. } = tcx . def_kind ( parent_item ) {
716
+ tcx . def_span ( parent_item )
717
+ } else {
718
+ tcx . def_ident_span ( parent_item ) . unwrap ( )
719
+ } ;
720
+ Some ( ParentInfo { num , descr , parent_descr , span } )
721
721
} else {
722
722
None
723
723
} ;
@@ -800,16 +800,7 @@ impl<'tcx> DeadVisitor<'tcx> {
800
800
}
801
801
802
802
fn check_definition ( & mut self , def_id : LocalDefId ) {
803
- if self . live_symbols . contains ( & def_id) {
804
- return ;
805
- }
806
- if has_allow_dead_code_or_lang_attr ( self . tcx , def_id) {
807
- return ;
808
- }
809
- let Some ( name) = self . tcx . opt_item_name ( def_id. to_def_id ( ) ) else {
810
- return
811
- } ;
812
- if name. as_str ( ) . starts_with ( '_' ) {
803
+ if self . is_live_code ( def_id) {
813
804
return ;
814
805
}
815
806
match self . tcx . def_kind ( def_id) {
@@ -827,6 +818,18 @@ impl<'tcx> DeadVisitor<'tcx> {
827
818
_ => { }
828
819
}
829
820
}
821
+
822
+ fn is_live_code ( & self , def_id : LocalDefId ) -> bool {
823
+ // if we cannot get a name for the item, then we just assume that it is
824
+ // live. I mean, we can't really emit a lint.
825
+ let Some ( name) = self . tcx . opt_item_name ( def_id. to_def_id ( ) ) else {
826
+ return true ;
827
+ } ;
828
+
829
+ self . live_symbols . contains ( & def_id)
830
+ || has_allow_dead_code_or_lang_attr ( self . tcx , def_id)
831
+ || name. as_str ( ) . starts_with ( '_' )
832
+ }
830
833
}
831
834
832
835
fn check_mod_deathness ( tcx : TyCtxt < ' _ > , module : LocalDefId ) {
@@ -837,9 +840,26 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
837
840
838
841
for item in module_items. items ( ) {
839
842
if let hir:: ItemKind :: Impl ( impl_item) = tcx. hir ( ) . item ( item) . kind {
843
+ let mut dead_items = Vec :: new ( ) ;
840
844
for item in impl_item. items {
841
- visitor. check_definition ( item. id . owner_id . def_id ) ;
845
+ match item. kind {
846
+ hir:: AssocItemKind :: Const | hir:: AssocItemKind :: Type => {
847
+ visitor. check_definition ( item. id . owner_id . def_id )
848
+ }
849
+ hir:: AssocItemKind :: Fn { .. } => {
850
+ let did = item. id . owner_id . def_id ;
851
+ if !visitor. is_live_code ( did) {
852
+ dead_items. push ( did)
853
+ }
854
+ }
855
+ }
842
856
}
857
+ visitor. warn_multiple_dead_codes (
858
+ & dead_items,
859
+ "used" ,
860
+ Some ( item. owner_id . def_id ) ,
861
+ false ,
862
+ ) ;
843
863
continue ;
844
864
}
845
865
0 commit comments