@@ -18,7 +18,7 @@ use rustc_hir::{self as hir, ImplItem, ImplItemKind, Node, PatKind, QPath, TyKin
18
18
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
19
19
use rustc_middle:: middle:: privacy:: Level ;
20
20
use rustc_middle:: query:: Providers ;
21
- use rustc_middle:: ty:: { self , TyCtxt } ;
21
+ use rustc_middle:: ty:: { self , AssocTag , TyCtxt } ;
22
22
use rustc_middle:: { bug, span_bug} ;
23
23
use rustc_session:: lint:: builtin:: DEAD_CODE ;
24
24
use rustc_session:: lint:: { self , LintExpectationId } ;
@@ -115,7 +115,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
115
115
116
116
fn handle_res ( & mut self , res : Res ) {
117
117
match res {
118
- Res :: Def ( DefKind :: Const | DefKind :: AssocConst | DefKind :: TyAlias , def_id) => {
118
+ Res :: Def (
119
+ DefKind :: Const | DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: TyAlias ,
120
+ def_id,
121
+ ) => {
119
122
self . check_def_id ( def_id) ;
120
123
}
121
124
_ if self . in_pat => { }
@@ -482,7 +485,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
482
485
) -> bool {
483
486
let trait_def_id = match self . tcx . def_kind ( local_def_id) {
484
487
// assoc impl items of traits are live if the corresponding trait items are live
485
- DefKind :: AssocFn => self
488
+ DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn => self
486
489
. tcx
487
490
. associated_item ( local_def_id)
488
491
. trait_item_def_id
@@ -647,6 +650,31 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
647
650
648
651
self . in_pat = in_pat;
649
652
}
653
+
654
+ fn visit_trait_ref ( & mut self , t : & ' tcx hir:: TraitRef < ' tcx > ) {
655
+ if let Some ( trait_def_id) = t. path . res . opt_def_id ( )
656
+ && let Some ( segment) = t. path . segments . last ( )
657
+ && let Some ( args) = segment. args
658
+ {
659
+ for constraint in args. constraints {
660
+ if let Some ( local_def_id) = self
661
+ . tcx
662
+ . associated_items ( trait_def_id)
663
+ . find_by_ident_and_kind (
664
+ self . tcx ,
665
+ constraint. ident ,
666
+ AssocTag :: Const ,
667
+ trait_def_id,
668
+ )
669
+ . and_then ( |item| item. def_id . as_local ( ) )
670
+ {
671
+ self . worklist . push ( ( local_def_id, ComesFromAllowExpect :: No ) ) ;
672
+ }
673
+ }
674
+ }
675
+
676
+ intravisit:: walk_trait_ref ( self , t) ;
677
+ }
650
678
}
651
679
652
680
fn has_allow_dead_code_or_lang_attr (
@@ -744,18 +772,12 @@ fn check_item<'tcx>(
744
772
{
745
773
worklist. push ( ( local_def_id, comes_from_allow) ) ;
746
774
} else if of_trait {
747
- // FIXME: This condition can be removed
748
- // if we support dead check for assoc consts and tys.
749
- if !matches ! ( tcx. def_kind( local_def_id) , DefKind :: AssocFn ) {
750
- worklist. push ( ( local_def_id, ComesFromAllowExpect :: No ) ) ;
751
- } else {
752
- // We only care about associated items of traits,
753
- // because they cannot be visited directly,
754
- // so we later mark them as live if their corresponding traits
755
- // or trait items and self types are both live,
756
- // but inherent associated items can be visited and marked directly.
757
- unsolved_items. push ( ( id, local_def_id) ) ;
758
- }
775
+ // We only care about associated items of traits,
776
+ // because they cannot be visited directly,
777
+ // so we later mark them as live if their corresponding traits
778
+ // or trait items and self types are both live,
779
+ // but inherent associated items can be visited and marked directly.
780
+ unsolved_items. push ( ( id, local_def_id) ) ;
759
781
}
760
782
}
761
783
}
@@ -791,15 +813,14 @@ fn check_trait_item(
791
813
worklist : & mut Vec < ( LocalDefId , ComesFromAllowExpect ) > ,
792
814
id : hir:: TraitItemId ,
793
815
) {
794
- use hir:: TraitItemKind :: { Const , Fn } ;
795
- if matches ! ( tcx. def_kind( id. owner_id) , DefKind :: AssocConst | DefKind :: AssocFn ) {
796
- let trait_item = tcx. hir_trait_item ( id) ;
797
- if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Fn ( ..) )
798
- && let Some ( comes_from_allow) =
799
- has_allow_dead_code_or_lang_attr ( tcx, trait_item. owner_id . def_id )
800
- {
801
- worklist. push ( ( trait_item. owner_id . def_id , comes_from_allow) ) ;
802
- }
816
+ use hir:: TraitItemKind :: { Const , Fn , Type } ;
817
+
818
+ let trait_item = tcx. hir_trait_item ( id) ;
819
+ if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Type ( _, Some ( _) ) | Fn ( ..) )
820
+ && let Some ( comes_from_allow) =
821
+ has_allow_dead_code_or_lang_attr ( tcx, trait_item. owner_id . def_id )
822
+ {
823
+ worklist. push ( ( trait_item. owner_id . def_id , comes_from_allow) ) ;
803
824
}
804
825
}
805
826
@@ -1163,6 +1184,7 @@ impl<'tcx> DeadVisitor<'tcx> {
1163
1184
}
1164
1185
match self . tcx . def_kind ( def_id) {
1165
1186
DefKind :: AssocConst
1187
+ | DefKind :: AssocTy
1166
1188
| DefKind :: AssocFn
1167
1189
| DefKind :: Fn
1168
1190
| DefKind :: Static { .. }
0 commit comments