@@ -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 => { }
@@ -470,7 +467,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
470
467
intravisit:: walk_item ( self , item)
471
468
}
472
469
hir:: ItemKind :: ForeignMod { .. } => { }
473
- hir:: ItemKind :: Trait ( _ , _ , _ , _ , trait_item_refs ) => {
470
+ hir:: ItemKind :: Trait ( .. ) => {
474
471
for impl_def_id in self . tcx . all_impls ( item. owner_id . to_def_id ( ) ) {
475
472
if let Some ( local_def_id) = impl_def_id. as_local ( )
476
473
&& let ItemKind :: Impl ( impl_ref) =
@@ -483,12 +480,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
483
480
intravisit:: walk_path ( self , impl_ref. of_trait . unwrap ( ) . path ) ;
484
481
}
485
482
}
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
+
492
484
intravisit:: walk_item ( self , item)
493
485
}
494
486
_ => intravisit:: walk_item ( self , item) ,
@@ -505,8 +497,9 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
505
497
&& let ItemKind :: Impl ( impl_ref) =
506
498
self . tcx . hir ( ) . expect_item ( local_impl_id) . kind
507
499
{
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
510
503
{
511
504
// skip impl-items of non pure pub ty,
512
505
// cause we don't know the ty is constructed or not,
@@ -845,8 +838,9 @@ fn check_item<'tcx>(
845
838
// for trait impl blocks,
846
839
// mark the method live if the self_ty is public,
847
840
// 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)
850
844
{
851
845
// if the impl item is public,
852
846
// and the ty may be constructed or can be constructed in foreign crates,
@@ -883,13 +877,10 @@ fn check_trait_item(
883
877
worklist : & mut Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
884
878
id : hir:: TraitItemId ,
885
879
) {
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 ) {
891
882
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 ( ..) )
893
884
&& let Some ( comes_from_allow) =
894
885
has_allow_dead_code_or_lang_attr ( tcx, trait_item. owner_id . def_id )
895
886
{
@@ -931,7 +922,7 @@ fn create_and_seed_worklist(
931
922
// checks impls, impl-items and pub structs with all public fields later
932
923
match tcx. def_kind ( id) {
933
924
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 ) ,
935
926
DefKind :: Struct => struct_all_fields_are_public ( tcx, id. to_def_id ( ) ) || has_allow_dead_code_or_lang_attr ( tcx, id) . is_some ( ) ,
936
927
_ => true
937
928
} )
@@ -1218,7 +1209,6 @@ impl<'tcx> DeadVisitor<'tcx> {
1218
1209
}
1219
1210
match self . tcx . def_kind ( def_id) {
1220
1211
DefKind :: AssocConst
1221
- | DefKind :: AssocTy
1222
1212
| DefKind :: AssocFn
1223
1213
| DefKind :: Fn
1224
1214
| DefKind :: Static { .. }
@@ -1260,14 +1250,15 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
1260
1250
|| ( def_kind == DefKind :: Trait && live_symbols. contains ( & item. owner_id . def_id ) )
1261
1251
{
1262
1252
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
1264
1254
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 )
1266
1256
// skip unused public inherent methods,
1267
1257
// cause we have diagnosed unconstructed struct
1268
1258
|| matches ! ( def_kind, DefKind :: Impl { of_trait: false } )
1269
1259
&& tcx. visibility ( def_id) . is_public ( )
1270
1260
&& 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
1271
1262
{
1272
1263
continue ;
1273
1264
}
0 commit comments