@@ -156,10 +156,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
156156
157157 fn handle_res ( & mut self , res : Res ) {
158158 match res {
159- Res :: Def (
160- DefKind :: Const | DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: TyAlias ,
161- def_id,
162- ) => {
159+ Res :: Def ( DefKind :: Const | DefKind :: AssocConst | DefKind :: TyAlias , def_id) => {
163160 self . check_def_id ( def_id) ;
164161 }
165162 _ if self . in_pat => { }
@@ -470,7 +467,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
470467 intravisit:: walk_item ( self , item)
471468 }
472469 hir:: ItemKind :: ForeignMod { .. } => { }
473- hir:: ItemKind :: Trait ( _ , _ , _ , _ , trait_item_refs ) => {
470+ hir:: ItemKind :: Trait ( .. ) => {
474471 for impl_def_id in self . tcx . all_impls ( item. owner_id . to_def_id ( ) ) {
475472 if let Some ( local_def_id) = impl_def_id. as_local ( )
476473 && let ItemKind :: Impl ( impl_ref) =
@@ -483,12 +480,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
483480 intravisit:: walk_path ( self , impl_ref. of_trait . unwrap ( ) . path ) ;
484481 }
485482 }
486- // mark assoc ty live if the trait is live
487- for trait_item in trait_item_refs {
488- if let hir:: AssocItemKind :: Type = trait_item. kind {
489- self . check_def_id ( trait_item. id . owner_id . to_def_id ( ) ) ;
490- }
491- }
483+
492484 intravisit:: walk_item ( self , item)
493485 }
494486 _ => intravisit:: walk_item ( self , item) ,
@@ -505,8 +497,9 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
505497 && let ItemKind :: Impl ( impl_ref) =
506498 self . tcx . hir ( ) . expect_item ( local_impl_id) . kind
507499 {
508- if !ty_ref_to_pub_struct ( self . tcx , impl_ref. self_ty )
509- . ty_and_all_fields_are_public
500+ if !matches ! ( trait_item. kind, hir:: TraitItemKind :: Type ( ..) )
501+ && !ty_ref_to_pub_struct ( self . tcx , impl_ref. self_ty )
502+ . ty_and_all_fields_are_public
510503 {
511504 // skip impl-items of non pure pub ty,
512505 // cause we don't know the ty is constructed or not,
@@ -845,8 +838,9 @@ fn check_item<'tcx>(
845838 // for trait impl blocks,
846839 // mark the method live if the self_ty is public,
847840 // or the method is public and may construct self
848- if tcx. visibility ( local_def_id) . is_public ( )
849- && ( ty_and_all_fields_are_public || may_construct_self)
841+ if of_trait && matches ! ( tcx. def_kind( local_def_id) , DefKind :: AssocTy )
842+ || tcx. visibility ( local_def_id) . is_public ( )
843+ && ( ty_and_all_fields_are_public || may_construct_self)
850844 {
851845 // if the impl item is public,
852846 // and the ty may be constructed or can be constructed in foreign crates,
@@ -883,13 +877,10 @@ fn check_trait_item(
883877 worklist : & mut Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
884878 id : hir:: TraitItemId ,
885879) {
886- use hir:: TraitItemKind :: { Const , Fn , Type } ;
887- if matches ! (
888- tcx. def_kind( id. owner_id) ,
889- DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn
890- ) {
880+ use hir:: TraitItemKind :: { Const , Fn } ;
881+ if matches ! ( tcx. def_kind( id. owner_id) , DefKind :: AssocConst | DefKind :: AssocFn ) {
891882 let trait_item = tcx. hir ( ) . trait_item ( id) ;
892- if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Type ( _ , Some ( _ ) ) | Fn ( ..) )
883+ if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Fn ( ..) )
893884 && let Some ( comes_from_allow) =
894885 has_allow_dead_code_or_lang_attr ( tcx, trait_item. owner_id . def_id )
895886 {
@@ -931,7 +922,7 @@ fn create_and_seed_worklist(
931922 // checks impls, impl-items and pub structs with all public fields later
932923 match tcx. def_kind ( id) {
933924 DefKind :: Impl { .. } => false ,
934- DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn => !matches ! ( tcx. associated_item( id) . container, AssocItemContainer :: ImplContainer ) ,
925+ DefKind :: AssocConst | DefKind :: AssocFn => !matches ! ( tcx. associated_item( id) . container, AssocItemContainer :: ImplContainer ) ,
935926 DefKind :: Struct => struct_all_fields_are_public ( tcx, id. to_def_id ( ) ) || has_allow_dead_code_or_lang_attr ( tcx, id) . is_some ( ) ,
936927 _ => true
937928 } )
@@ -1218,7 +1209,6 @@ impl<'tcx> DeadVisitor<'tcx> {
12181209 }
12191210 match self . tcx . def_kind ( def_id) {
12201211 DefKind :: AssocConst
1221- | DefKind :: AssocTy
12221212 | DefKind :: AssocFn
12231213 | DefKind :: Fn
12241214 | DefKind :: Static { .. }
@@ -1260,14 +1250,15 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
12601250 || ( def_kind == DefKind :: Trait && live_symbols. contains ( & item. owner_id . def_id ) )
12611251 {
12621252 for & def_id in tcx. associated_item_def_ids ( item. owner_id . def_id ) {
1263- // We have diagnosed unused assocs in traits
1253+ // We have diagnosed unused assoc consts and fns in traits
12641254 if matches ! ( def_kind, DefKind :: Impl { of_trait: true } )
1265- && matches ! ( tcx. def_kind( def_id) , DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn )
1255+ && matches ! ( tcx. def_kind( def_id) , DefKind :: AssocConst | DefKind :: AssocFn )
12661256 // skip unused public inherent methods,
12671257 // cause we have diagnosed unconstructed struct
12681258 || matches ! ( def_kind, DefKind :: Impl { of_trait: false } )
12691259 && tcx. visibility ( def_id) . is_public ( )
12701260 && ty_ref_to_pub_struct ( tcx, tcx. hir ( ) . item ( item) . expect_impl ( ) . self_ty ) . ty_is_public
1261+ || def_kind == DefKind :: Trait && tcx. def_kind ( def_id) == DefKind :: AssocTy
12711262 {
12721263 continue ;
12731264 }
0 commit comments