@@ -762,6 +762,15 @@ fn check_item<'tcx>(
762
762
{
763
763
worklist. push ( ( id. owner_id . def_id , comes_from_allow) ) ;
764
764
} 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
+
765
774
unsolved_items. push ( ( id, id. owner_id . def_id ) ) ;
766
775
}
767
776
@@ -772,6 +781,14 @@ fn check_item<'tcx>(
772
781
{
773
782
worklist. push ( ( local_def_id, comes_from_allow) ) ;
774
783
} 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
+
775
792
// We only care about associated items of traits,
776
793
// because they cannot be visited directly,
777
794
// so we later mark them as live if their corresponding traits
@@ -804,6 +821,13 @@ fn check_item<'tcx>(
804
821
worklist. push ( ( id. owner_id . def_id , ComesFromAllowExpect :: No ) ) ;
805
822
}
806
823
}
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
+ }
807
831
_ => { }
808
832
}
809
833
}
@@ -813,14 +837,9 @@ fn check_trait_item(
813
837
worklist : & mut Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
814
838
id : hir:: TraitItemId ,
815
839
) {
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) ) ;
824
843
}
825
844
}
826
845
0 commit comments