@@ -155,7 +155,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
155155
156156 fn handle_res ( & mut self , res : Res ) {
157157 match res {
158- Res :: Def ( DefKind :: Const | DefKind :: AssocConst | DefKind :: TyAlias , def_id) => {
158+ Res :: Def (
159+ DefKind :: Const | DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: TyAlias ,
160+ def_id,
161+ ) => {
159162 self . check_def_id ( def_id) ;
160163 }
161164 _ if self . in_pat => { }
@@ -441,7 +444,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
441444 intravisit:: walk_item ( self , item)
442445 }
443446 hir:: ItemKind :: ForeignMod { .. } => { }
444- hir:: ItemKind :: Trait ( .. ) => {
447+ hir:: ItemKind :: Trait ( _ , _ , _ , _ , trait_item_refs ) => {
445448 for impl_def_id in self . tcx . all_impls ( item. owner_id . to_def_id ( ) ) {
446449 if let Some ( local_def_id) = impl_def_id. as_local ( )
447450 && let ItemKind :: Impl ( impl_ref) =
@@ -454,7 +457,12 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
454457 intravisit:: walk_path ( self , impl_ref. of_trait . unwrap ( ) . path ) ;
455458 }
456459 }
457-
460+ // mark assoc ty live if the trait is live
461+ for trait_item in trait_item_refs {
462+ if let hir:: AssocItemKind :: Type = trait_item. kind {
463+ self . check_def_id ( trait_item. id . owner_id . to_def_id ( ) ) ;
464+ }
465+ }
458466 intravisit:: walk_item ( self , item)
459467 }
460468 _ => intravisit:: walk_item ( self , item) ,
@@ -471,9 +479,8 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
471479 && let ItemKind :: Impl ( impl_ref) =
472480 self . tcx . hir ( ) . expect_item ( local_impl_id) . kind
473481 {
474- if !matches ! ( trait_item. kind, hir:: TraitItemKind :: Type ( ..) )
475- && !ty_ref_to_pub_struct ( self . tcx , impl_ref. self_ty )
476- . ty_and_all_fields_are_public
482+ if !ty_ref_to_pub_struct ( self . tcx , impl_ref. self_ty )
483+ . ty_and_all_fields_are_public
477484 {
478485 // skip impl-items of non pure pub ty,
479486 // cause we don't know the ty is constructed or not,
@@ -812,9 +819,8 @@ fn check_item<'tcx>(
812819 // for trait impl blocks,
813820 // mark the method live if the self_ty is public,
814821 // or the method is public and may construct self
815- if of_trait && matches ! ( tcx. def_kind( local_def_id) , DefKind :: AssocTy )
816- || tcx. visibility ( local_def_id) . is_public ( )
817- && ( ty_and_all_fields_are_public || may_construct_self)
822+ if tcx. visibility ( local_def_id) . is_public ( )
823+ && ( ty_and_all_fields_are_public || may_construct_self)
818824 {
819825 // if the impl item is public,
820826 // and the ty may be constructed or can be constructed in foreign crates,
@@ -851,10 +857,13 @@ fn check_trait_item(
851857 worklist : & mut Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
852858 id : hir:: TraitItemId ,
853859) {
854- use hir:: TraitItemKind :: { Const , Fn } ;
855- if matches ! ( tcx. def_kind( id. owner_id) , DefKind :: AssocConst | DefKind :: AssocFn ) {
860+ use hir:: TraitItemKind :: { Const , Fn , Type } ;
861+ if matches ! (
862+ tcx. def_kind( id. owner_id) ,
863+ DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn
864+ ) {
856865 let trait_item = tcx. hir ( ) . trait_item ( id) ;
857- if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Fn ( ..) )
866+ if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Type ( _ , Some ( _ ) ) | Fn ( ..) )
858867 && let Some ( comes_from_allow) =
859868 has_allow_dead_code_or_lang_attr ( tcx, trait_item. owner_id . def_id )
860869 {
@@ -896,7 +905,7 @@ fn create_and_seed_worklist(
896905 // checks impls, impl-items and pub structs with all public fields later
897906 match tcx. def_kind ( id) {
898907 DefKind :: Impl { .. } => false ,
899- DefKind :: AssocConst | DefKind :: AssocFn => !matches ! ( tcx. associated_item( id) . container, AssocItemContainer :: ImplContainer ) ,
908+ DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn => !matches ! ( tcx. associated_item( id) . container, AssocItemContainer :: ImplContainer ) ,
900909 DefKind :: Struct => struct_all_fields_are_public ( tcx, id. to_def_id ( ) ) || has_allow_dead_code_or_lang_attr ( tcx, id) . is_some ( ) ,
901910 _ => true
902911 } )
@@ -1183,6 +1192,7 @@ impl<'tcx> DeadVisitor<'tcx> {
11831192 }
11841193 match self . tcx . def_kind ( def_id) {
11851194 DefKind :: AssocConst
1195+ | DefKind :: AssocTy
11861196 | DefKind :: AssocFn
11871197 | DefKind :: Fn
11881198 | DefKind :: Static { .. }
@@ -1224,15 +1234,14 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
12241234 || ( def_kind == DefKind :: Trait && live_symbols. contains ( & item. owner_id . def_id ) )
12251235 {
12261236 for & def_id in tcx. associated_item_def_ids ( item. owner_id . def_id ) {
1227- // We have diagnosed unused assoc consts and fns in traits
1237+ // We have diagnosed unused assocs in traits
12281238 if matches ! ( def_kind, DefKind :: Impl { of_trait: true } )
1229- && matches ! ( tcx. def_kind( def_id) , DefKind :: AssocConst | DefKind :: AssocFn )
1239+ && matches ! ( tcx. def_kind( def_id) , DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn )
12301240 // skip unused public inherent methods,
12311241 // cause we have diagnosed unconstructed struct
12321242 || matches ! ( def_kind, DefKind :: Impl { of_trait: false } )
12331243 && tcx. visibility ( def_id) . is_public ( )
12341244 && ty_ref_to_pub_struct ( tcx, tcx. hir ( ) . item ( item) . expect_impl ( ) . self_ty ) . ty_is_public
1235- || def_kind == DefKind :: Trait && tcx. def_kind ( def_id) == DefKind :: AssocTy
12361245 {
12371246 continue ;
12381247 }
0 commit comments