@@ -712,12 +712,12 @@ impl<'tcx> DeadVisitor<'tcx> {
712712
713713 let parent_info = if let Some ( parent_item) = parent_item {
714714 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 } )
721721 } else {
722722 None
723723 } ;
@@ -800,16 +800,7 @@ impl<'tcx> DeadVisitor<'tcx> {
800800 }
801801
802802 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) {
813804 return ;
814805 }
815806 match self . tcx . def_kind ( def_id) {
@@ -827,6 +818,18 @@ impl<'tcx> DeadVisitor<'tcx> {
827818 _ => { }
828819 }
829820 }
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+ }
830833}
831834
832835fn check_mod_deathness ( tcx : TyCtxt < ' _ > , module : LocalDefId ) {
@@ -837,9 +840,26 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
837840
838841 for item in module_items. items ( ) {
839842 if let hir:: ItemKind :: Impl ( impl_item) = tcx. hir ( ) . item ( item) . kind {
843+ let mut dead_items = Vec :: new ( ) ;
840844 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+ }
842856 }
857+ visitor. warn_multiple_dead_codes (
858+ & dead_items,
859+ "used" ,
860+ Some ( item. owner_id . def_id ) ,
861+ false ,
862+ ) ;
843863 continue ;
844864 }
845865
0 commit comments