@@ -762,6 +762,15 @@ fn check_item<'tcx>(
762762 {
763763 worklist. push ( ( id. owner_id . def_id , comes_from_allow) ) ;
764764 } else if of_trait {
765+ if let Some ( trait_def_id) = tcx
766+ . impl_trait_ref ( id. owner_id . def_id )
767+ . and_then ( |trait_ref| trait_ref. skip_binder ( ) . def_id . as_local ( ) )
768+ && let Some ( comes_from_allow) =
769+ has_allow_dead_code_or_lang_attr ( tcx, trait_def_id)
770+ {
771+ worklist. push ( ( id. owner_id . def_id , comes_from_allow) ) ;
772+ }
773+
765774 unsolved_items. push ( ( id, id. owner_id . def_id ) ) ;
766775 }
767776
@@ -772,6 +781,14 @@ fn check_item<'tcx>(
772781 {
773782 worklist. push ( ( local_def_id, comes_from_allow) ) ;
774783 } else if of_trait {
784+ if let Some ( trait_item_def_id) = tcx. associated_item ( def_id) . trait_item_def_id
785+ && let Some ( trait_item_local_def_id) = trait_item_def_id. as_local ( )
786+ && let Some ( comes_from_allow) =
787+ has_allow_dead_code_or_lang_attr ( tcx, trait_item_local_def_id)
788+ {
789+ worklist. push ( ( local_def_id, comes_from_allow) ) ;
790+ }
791+
775792 // We only care about associated items of traits,
776793 // because they cannot be visited directly,
777794 // so we later mark them as live if their corresponding traits
@@ -804,6 +821,13 @@ fn check_item<'tcx>(
804821 worklist. push ( ( id. owner_id . def_id , ComesFromAllowExpect :: No ) ) ;
805822 }
806823 }
824+ DefKind :: Trait => {
825+ if let Some ( comes_from_allow) =
826+ has_allow_dead_code_or_lang_attr ( tcx, id. owner_id . def_id )
827+ {
828+ worklist. push ( ( id. owner_id . def_id , comes_from_allow) ) ;
829+ }
830+ }
807831 _ => { }
808832 }
809833}
@@ -813,14 +837,9 @@ fn check_trait_item(
813837 worklist : & mut Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
814838 id : hir:: TraitItemId ,
815839) {
816- use hir:: TraitItemKind :: { Const , Fn , Type } ;
817-
818- let trait_item = tcx. hir_trait_item ( id) ;
819- if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Type ( _, Some ( _) ) | Fn ( ..) )
820- && let Some ( comes_from_allow) =
821- has_allow_dead_code_or_lang_attr ( tcx, trait_item. owner_id . def_id )
822- {
823- worklist. push ( ( trait_item. owner_id . def_id , comes_from_allow) ) ;
840+ let trait_item_id = tcx. hir_trait_item ( id) . owner_id . def_id ;
841+ if let Some ( comes_from_allow) = has_allow_dead_code_or_lang_attr ( tcx, trait_item_id) {
842+ worklist. push ( ( trait_item_id, comes_from_allow) ) ;
824843 }
825844}
826845
0 commit comments