@@ -156,10 +156,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
156
156
157
157
fn handle_res ( & mut self , res : Res ) {
158
158
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) => {
163
160
self . check_def_id ( def_id) ;
164
161
}
165
162
_ if self . in_pat => { }
@@ -445,7 +442,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
445
442
intravisit:: walk_item ( self , item)
446
443
}
447
444
hir:: ItemKind :: ForeignMod { .. } => { }
448
- hir:: ItemKind :: Trait ( _ , _ , _ , _ , trait_item_refs ) => {
445
+ hir:: ItemKind :: Trait ( .. ) => {
449
446
for impl_def_id in self . tcx . all_impls ( item. owner_id . to_def_id ( ) ) {
450
447
if let Some ( local_def_id) = impl_def_id. as_local ( )
451
448
&& let ItemKind :: Impl ( impl_ref) =
@@ -458,12 +455,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
458
455
intravisit:: walk_path ( self , impl_ref. of_trait . unwrap ( ) . path ) ;
459
456
}
460
457
}
461
- // mark assoc ty live if the trait is live
462
- for trait_item in trait_item_refs {
463
- if let hir:: AssocItemKind :: Type = trait_item. kind {
464
- self . check_def_id ( trait_item. id . owner_id . to_def_id ( ) ) ;
465
- }
466
- }
458
+
467
459
intravisit:: walk_item ( self , item)
468
460
}
469
461
_ => intravisit:: walk_item ( self , item) ,
@@ -480,8 +472,9 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
480
472
&& let ItemKind :: Impl ( impl_ref) =
481
473
self . tcx . hir ( ) . expect_item ( local_impl_id) . kind
482
474
{
483
- if !ty_ref_to_pub_struct ( self . tcx , impl_ref. self_ty )
484
- . ty_and_all_fields_are_public
475
+ if !matches ! ( trait_item. kind, hir:: TraitItemKind :: Type ( ..) )
476
+ && !ty_ref_to_pub_struct ( self . tcx , impl_ref. self_ty )
477
+ . ty_and_all_fields_are_public
485
478
{
486
479
// skip impl-items of non pure pub ty,
487
480
// cause we don't know the ty is constructed or not,
@@ -820,8 +813,9 @@ fn check_item<'tcx>(
820
813
// for trait impl blocks,
821
814
// mark the method live if the self_ty is public,
822
815
// or the method is public and may construct self
823
- if tcx. visibility ( local_def_id) . is_public ( )
824
- && ( ty_and_all_fields_are_public || may_construct_self)
816
+ if of_trait && matches ! ( tcx. def_kind( local_def_id) , DefKind :: AssocTy )
817
+ || tcx. visibility ( local_def_id) . is_public ( )
818
+ && ( ty_and_all_fields_are_public || may_construct_self)
825
819
{
826
820
// if the impl item is public,
827
821
// and the ty may be constructed or can be constructed in foreign crates,
@@ -858,13 +852,10 @@ fn check_trait_item(
858
852
worklist : & mut Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
859
853
id : hir:: TraitItemId ,
860
854
) {
861
- use hir:: TraitItemKind :: { Const , Fn , Type } ;
862
- if matches ! (
863
- tcx. def_kind( id. owner_id) ,
864
- DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn
865
- ) {
855
+ use hir:: TraitItemKind :: { Const , Fn } ;
856
+ if matches ! ( tcx. def_kind( id. owner_id) , DefKind :: AssocConst | DefKind :: AssocFn ) {
866
857
let trait_item = tcx. hir ( ) . trait_item ( id) ;
867
- if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Type ( _ , Some ( _ ) ) | Fn ( ..) )
858
+ if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Fn ( ..) )
868
859
&& let Some ( comes_from_allow) =
869
860
has_allow_dead_code_or_lang_attr ( tcx, trait_item. owner_id . def_id )
870
861
{
@@ -906,7 +897,7 @@ fn create_and_seed_worklist(
906
897
// checks impls, impl-items and pub structs with all public fields later
907
898
match tcx. def_kind ( id) {
908
899
DefKind :: Impl { .. } => false ,
909
- DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn => !matches ! ( tcx. associated_item( id) . container, AssocItemContainer :: ImplContainer ) ,
900
+ DefKind :: AssocConst | DefKind :: AssocFn => !matches ! ( tcx. associated_item( id) . container, AssocItemContainer :: ImplContainer ) ,
910
901
DefKind :: Struct => struct_all_fields_are_public ( tcx, id. to_def_id ( ) ) || has_allow_dead_code_or_lang_attr ( tcx, id) . is_some ( ) ,
911
902
_ => true
912
903
} )
@@ -1193,7 +1184,6 @@ impl<'tcx> DeadVisitor<'tcx> {
1193
1184
}
1194
1185
match self . tcx . def_kind ( def_id) {
1195
1186
DefKind :: AssocConst
1196
- | DefKind :: AssocTy
1197
1187
| DefKind :: AssocFn
1198
1188
| DefKind :: Fn
1199
1189
| DefKind :: Static { .. }
@@ -1235,14 +1225,15 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
1235
1225
|| ( def_kind == DefKind :: Trait && live_symbols. contains ( & item. owner_id . def_id ) )
1236
1226
{
1237
1227
for & def_id in tcx. associated_item_def_ids ( item. owner_id . def_id ) {
1238
- // We have diagnosed unused assocs in traits
1228
+ // We have diagnosed unused assoc consts and fns in traits
1239
1229
if matches ! ( def_kind, DefKind :: Impl { of_trait: true } )
1240
- && matches ! ( tcx. def_kind( def_id) , DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn )
1230
+ && matches ! ( tcx. def_kind( def_id) , DefKind :: AssocConst | DefKind :: AssocFn )
1241
1231
// skip unused public inherent methods,
1242
1232
// cause we have diagnosed unconstructed struct
1243
1233
|| matches ! ( def_kind, DefKind :: Impl { of_trait: false } )
1244
1234
&& tcx. visibility ( def_id) . is_public ( )
1245
1235
&& ty_ref_to_pub_struct ( tcx, tcx. hir ( ) . item ( item) . expect_impl ( ) . self_ty ) . ty_is_public
1236
+ || def_kind == DefKind :: Trait && tcx. def_kind ( def_id) == DefKind :: AssocTy
1246
1237
{
1247
1238
continue ;
1248
1239
}
0 commit comments