@@ -155,10 +155,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
155
155
156
156
fn handle_res ( & mut self , res : Res ) {
157
157
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) => {
162
159
self . check_def_id ( def_id) ;
163
160
}
164
161
_ if self . in_pat => { }
@@ -469,7 +466,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
469
466
intravisit:: walk_item ( self , item)
470
467
}
471
468
hir:: ItemKind :: ForeignMod { .. } => { }
472
- hir:: ItemKind :: Trait ( _ , _ , _ , _ , trait_item_refs ) => {
469
+ hir:: ItemKind :: Trait ( .. ) => {
473
470
for impl_def_id in self . tcx . all_impls ( item. owner_id . to_def_id ( ) ) {
474
471
if let Some ( local_def_id) = impl_def_id. as_local ( )
475
472
&& let ItemKind :: Impl ( impl_ref) =
@@ -482,12 +479,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
482
479
intravisit:: walk_path ( self , impl_ref. of_trait . unwrap ( ) . path ) ;
483
480
}
484
481
}
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
+
491
483
intravisit:: walk_item ( self , item)
492
484
}
493
485
_ => intravisit:: walk_item ( self , item) ,
@@ -504,8 +496,9 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
504
496
&& let ItemKind :: Impl ( impl_ref) =
505
497
self . tcx . hir ( ) . expect_item ( local_impl_id) . kind
506
498
{
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
509
502
{
510
503
// skip impl-items of non pure pub ty,
511
504
// cause we don't know the ty is constructed or not,
@@ -844,8 +837,9 @@ fn check_item<'tcx>(
844
837
// for trait impl blocks,
845
838
// mark the method live if the self_ty is public,
846
839
// 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)
849
843
{
850
844
// if the impl item is public,
851
845
// and the ty may be constructed or can be constructed in foreign crates,
@@ -882,13 +876,10 @@ fn check_trait_item(
882
876
worklist : & mut Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
883
877
id : hir:: TraitItemId ,
884
878
) {
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 ) {
890
881
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 ( ..) )
892
883
&& let Some ( comes_from_allow) =
893
884
has_allow_dead_code_or_lang_attr ( tcx, trait_item. owner_id . def_id )
894
885
{
@@ -930,7 +921,7 @@ fn create_and_seed_worklist(
930
921
// checks impls, impl-items and pub structs with all public fields later
931
922
match tcx. def_kind ( id) {
932
923
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 ) ,
934
925
DefKind :: Struct => struct_all_fields_are_public ( tcx, id. to_def_id ( ) ) || has_allow_dead_code_or_lang_attr ( tcx, id) . is_some ( ) ,
935
926
_ => true
936
927
} )
@@ -1217,7 +1208,6 @@ impl<'tcx> DeadVisitor<'tcx> {
1217
1208
}
1218
1209
match self . tcx . def_kind ( def_id) {
1219
1210
DefKind :: AssocConst
1220
- | DefKind :: AssocTy
1221
1211
| DefKind :: AssocFn
1222
1212
| DefKind :: Fn
1223
1213
| DefKind :: Static { .. }
@@ -1259,14 +1249,15 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
1259
1249
|| ( def_kind == DefKind :: Trait && live_symbols. contains ( & item. owner_id . def_id ) )
1260
1250
{
1261
1251
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
1263
1253
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 )
1265
1255
// skip unused public inherent methods,
1266
1256
// cause we have diagnosed unconstructed struct
1267
1257
|| matches ! ( def_kind, DefKind :: Impl { of_trait: false } )
1268
1258
&& tcx. visibility ( def_id) . is_public ( )
1269
1259
&& 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
1270
1261
{
1271
1262
continue ;
1272
1263
}
0 commit comments