@@ -786,18 +786,9 @@ fn check_item<'tcx>(
786
786
// for trait impl blocks,
787
787
// mark the method live if the self_ty is public,
788
788
// or the method is public and may construct self
789
- if of_trait
790
- && ( !matches ! ( tcx. def_kind( local_def_id) , DefKind :: AssocFn )
791
- || tcx. visibility ( local_def_id) . is_public ( )
792
- && ( ty_is_pure_pub || may_construct_self) )
793
- {
794
- // if the impl item is public,
795
- // and the ty may be constructed or can be constructed in foreign crates,
796
- // mark the impl item live
797
- worklist. push ( ( local_def_id, ComesFromAllowExpect :: No ) ) ;
798
- } else if !of_trait
799
- && tcx. visibility ( local_def_id) . is_public ( )
800
- && ( ty_is_pure_pub || may_construct_self)
789
+ if of_trait && matches ! ( tcx. def_kind( local_def_id) , DefKind :: AssocTy )
790
+ || tcx. visibility ( local_def_id) . is_public ( )
791
+ && ( ty_is_pure_pub || may_construct_self)
801
792
{
802
793
// if the impl item is public,
803
794
// and the ty may be constructed or can be constructed in foreign crates,
@@ -882,7 +873,7 @@ fn create_and_seed_worklist(
882
873
// checks impls, impl-items and pub structs with all public fields later
883
874
match tcx. def_kind ( id) {
884
875
DefKind :: Impl { .. } => false ,
885
- DefKind :: AssocFn => !matches ! ( tcx. associated_item( id) . container, AssocItemContainer :: ImplContainer ) ,
876
+ DefKind :: AssocConst | DefKind :: AssocFn => !matches ! ( tcx. associated_item( id) . container, AssocItemContainer :: ImplContainer ) ,
886
877
DefKind :: Struct => struct_all_fields_are_public ( tcx, id. to_def_id ( ) ) ,
887
878
_ => true
888
879
} )
@@ -1158,13 +1149,13 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
1158
1149
|| ( def_kind == DefKind :: Trait && live_symbols. contains ( & item. owner_id . def_id ) )
1159
1150
{
1160
1151
for & def_id in tcx. associated_item_def_ids ( item. owner_id . def_id ) {
1161
- // We have diagnosed unused methods in traits
1152
+ // We have diagnosed unused assoc consts and fns in traits
1162
1153
if matches ! ( def_kind, DefKind :: Impl { of_trait: true } )
1163
- && tcx. def_kind ( def_id) == DefKind :: AssocFn
1154
+ && matches ! ( tcx. def_kind( def_id) , DefKind :: AssocConst | DefKind :: AssocFn )
1164
1155
// skip unused public inherent methods,
1165
1156
// cause we have diagnosed unconstructed struct
1166
1157
|| matches ! ( def_kind, DefKind :: Impl { of_trait: false } ) && tcx. visibility ( def_id) . is_public ( ) && ty_ref_to_pub_struct ( tcx, tcx. hir ( ) . item ( item) . expect_impl ( ) . self_ty )
1167
- || def_kind == DefKind :: Trait && tcx. def_kind ( def_id) != DefKind :: AssocFn
1158
+ || def_kind == DefKind :: Trait && tcx. def_kind ( def_id) == DefKind :: AssocTy
1168
1159
{
1169
1160
continue ;
1170
1161
}
0 commit comments