@@ -155,10 +155,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
155155
156156    fn  handle_res ( & mut  self ,  res :  Res )  { 
157157        match  res { 
158-             Res :: Def ( 
159-                 DefKind :: Const  | DefKind :: AssocConst  | DefKind :: AssocTy  | DefKind :: TyAlias , 
160-                 def_id, 
161-             )  => { 
158+             Res :: Def ( DefKind :: Const  | DefKind :: AssocConst  | DefKind :: TyAlias ,  def_id)  => { 
162159                self . check_def_id ( def_id) ; 
163160            } 
164161            _ if  self . in_pat  => { } 
@@ -469,7 +466,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
469466                    intravisit:: walk_item ( self ,  item) 
470467                } 
471468                hir:: ItemKind :: ForeignMod  {  .. }  => { } 
472-                 hir:: ItemKind :: Trait ( _ ,  _ ,  _ ,  _ ,  trait_item_refs )  => { 
469+                 hir:: ItemKind :: Trait ( .. )  => { 
473470                    for  impl_def_id in  self . tcx . all_impls ( item. owner_id . to_def_id ( ) )  { 
474471                        if  let  Some ( local_def_id)  = impl_def_id. as_local ( ) 
475472                            && let  ItemKind :: Impl ( impl_ref)  =
@@ -482,12 +479,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
482479                            intravisit:: walk_path ( self ,  impl_ref. of_trait . unwrap ( ) . path ) ; 
483480                        } 
484481                    } 
485-                     // mark assoc ty live if the trait is live 
486-                     for  trait_item in  trait_item_refs { 
487-                         if  let  hir:: AssocItemKind :: Type  = trait_item. kind  { 
488-                             self . check_def_id ( trait_item. id . owner_id . to_def_id ( ) ) ; 
489-                         } 
490-                     } 
482+ 
491483                    intravisit:: walk_item ( self ,  item) 
492484                } 
493485                _ => intravisit:: walk_item ( self ,  item) , 
@@ -504,8 +496,9 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
504496                            && let  ItemKind :: Impl ( impl_ref)  =
505497                                self . tcx . hir ( ) . expect_item ( local_impl_id) . kind 
506498                        { 
507-                             if  !ty_ref_to_pub_struct ( self . tcx ,  impl_ref. self_ty ) 
508-                                 . ty_and_all_fields_are_public 
499+                             if  !matches ! ( trait_item. kind,  hir:: TraitItemKind :: Type ( ..) ) 
500+                                 && !ty_ref_to_pub_struct ( self . tcx ,  impl_ref. self_ty ) 
501+                                     . ty_and_all_fields_are_public 
509502                            { 
510503                                // skip impl-items of non pure pub ty, 
511504                                // cause we don't know the ty is constructed or not, 
@@ -844,8 +837,9 @@ fn check_item<'tcx>(
844837                // for trait impl blocks, 
845838                // mark the method live if the self_ty is public, 
846839                // or the method is public and may construct self 
847-                 if  tcx. visibility ( local_def_id) . is_public ( ) 
848-                     && ( ty_and_all_fields_are_public || may_construct_self) 
840+                 if  of_trait && matches ! ( tcx. def_kind( local_def_id) ,  DefKind :: AssocTy ) 
841+                     || tcx. visibility ( local_def_id) . is_public ( ) 
842+                         && ( ty_and_all_fields_are_public || may_construct_self) 
849843                { 
850844                    // if the impl item is public, 
851845                    // and the ty may be constructed or can be constructed in foreign crates, 
@@ -882,13 +876,10 @@ fn check_trait_item(
882876    worklist :  & mut  Vec < ( LocalDefId ,  ComesFromAllowExpect ) > , 
883877    id :  hir:: TraitItemId , 
884878)  { 
885-     use  hir:: TraitItemKind :: { Const ,  Fn ,  Type } ; 
886-     if  matches ! ( 
887-         tcx. def_kind( id. owner_id) , 
888-         DefKind :: AssocConst  | DefKind :: AssocTy  | DefKind :: AssocFn 
889-     )  { 
879+     use  hir:: TraitItemKind :: { Const ,  Fn } ; 
880+     if  matches ! ( tcx. def_kind( id. owner_id) ,  DefKind :: AssocConst  | DefKind :: AssocFn )  { 
890881        let  trait_item = tcx. hir ( ) . trait_item ( id) ; 
891-         if  matches ! ( trait_item. kind,  Const ( _,  Some ( _) )  | Type ( _ ,   Some ( _ ) )  |  Fn ( ..) ) 
882+         if  matches ! ( trait_item. kind,  Const ( _,  Some ( _) )  | Fn ( ..) ) 
892883            && let  Some ( comes_from_allow)  =
893884                has_allow_dead_code_or_lang_attr ( tcx,  trait_item. owner_id . def_id ) 
894885        { 
@@ -930,7 +921,7 @@ fn create_and_seed_worklist(
930921                    // checks impls, impl-items and pub structs with all public fields later 
931922                    match  tcx. def_kind ( id)  { 
932923                        DefKind :: Impl  {  .. }  => false , 
933-                         DefKind :: AssocConst  | DefKind :: AssocTy  |  DefKind :: AssocFn  => !matches ! ( tcx. associated_item( id) . container,  AssocItemContainer :: ImplContainer ) , 
924+                         DefKind :: AssocConst  | DefKind :: AssocFn  => !matches ! ( tcx. associated_item( id) . container,  AssocItemContainer :: ImplContainer ) , 
934925                        DefKind :: Struct  => struct_all_fields_are_public ( tcx,  id. to_def_id ( ) )  || has_allow_dead_code_or_lang_attr ( tcx,  id) . is_some ( ) , 
935926                        _ => true 
936927                    } ) 
@@ -1217,7 +1208,6 @@ impl<'tcx> DeadVisitor<'tcx> {
12171208        } 
12181209        match  self . tcx . def_kind ( def_id)  { 
12191210            DefKind :: AssocConst 
1220-             | DefKind :: AssocTy 
12211211            | DefKind :: AssocFn 
12221212            | DefKind :: Fn 
12231213            | DefKind :: Static  {  .. } 
@@ -1259,14 +1249,15 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
12591249            || ( def_kind == DefKind :: Trait  && live_symbols. contains ( & item. owner_id . def_id ) ) 
12601250        { 
12611251            for  & def_id in  tcx. associated_item_def_ids ( item. owner_id . def_id )  { 
1262-                 // We have diagnosed unused assocs  in traits 
1252+                 // We have diagnosed unused assoc consts and fns  in traits 
12631253                if  matches ! ( def_kind,  DefKind :: Impl  {  of_trait:  true  } ) 
1264-                     && matches ! ( tcx. def_kind( def_id) ,  DefKind :: AssocConst  | DefKind :: AssocTy  |  DefKind :: AssocFn ) 
1254+                     && matches ! ( tcx. def_kind( def_id) ,  DefKind :: AssocConst  | DefKind :: AssocFn ) 
12651255                    // skip unused public inherent methods, 
12661256                    // cause we have diagnosed unconstructed struct 
12671257                    || matches ! ( def_kind,  DefKind :: Impl  {  of_trait:  false  } ) 
12681258                        && tcx. visibility ( def_id) . is_public ( ) 
12691259                        && ty_ref_to_pub_struct ( tcx,  tcx. hir ( ) . item ( item) . expect_impl ( ) . self_ty ) . ty_is_public 
1260+                     || def_kind == DefKind :: Trait  && tcx. def_kind ( def_id)  == DefKind :: AssocTy 
12701261                { 
12711262                    continue ; 
12721263                } 
0 commit comments