@@ -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,29 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
647
650
648
651
self . in_pat = in_pat;
649
652
}
653
+
654
+ fn visit_poly_trait_ref ( & mut self , t : & ' tcx hir:: PolyTraitRef < ' tcx > ) {
655
+ // Mark the assoc const appears in poly-trait-ref live
656
+ if let Some ( pathsegment) = t. trait_ref . path . segments . last ( )
657
+ && let Some ( args) = pathsegment. args
658
+ {
659
+ for constraint in args. constraints {
660
+ if let Some ( item) = self
661
+ . tcx
662
+ . associated_items ( pathsegment. res . def_id ( ) )
663
+ . filter_by_name_unhygienic ( constraint. ident . name )
664
+ . find ( |i| {
665
+ matches ! ( i. kind, ty:: AssocKind :: Const { .. } )
666
+ && i. ident ( self . tcx ) . normalize_to_macros_2_0 ( ) == constraint. ident
667
+ } )
668
+ && let Some ( local_def_id) = item. def_id . as_local ( )
669
+ {
670
+ self . worklist . push ( ( local_def_id, ComesFromAllowExpect :: No ) ) ;
671
+ }
672
+ }
673
+ }
674
+ intravisit:: walk_poly_trait_ref ( self , t) ;
675
+ }
650
676
}
651
677
652
678
fn has_allow_dead_code_or_lang_attr (
@@ -744,18 +770,12 @@ fn check_item<'tcx>(
744
770
{
745
771
worklist. push ( ( local_def_id, comes_from_allow) ) ;
746
772
} 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
- }
773
+ // We only care about associated items of traits,
774
+ // because they cannot be visited directly,
775
+ // so we later mark them as live if their corresponding traits
776
+ // or trait items and self types are both live,
777
+ // but inherent associated items can be visited and marked directly.
778
+ unsolved_items. push ( ( id, local_def_id) ) ;
759
779
}
760
780
}
761
781
}
@@ -792,7 +812,10 @@ fn check_trait_item(
792
812
id : hir:: TraitItemId ,
793
813
) {
794
814
use hir:: TraitItemKind :: { Const , Fn } ;
795
- if matches ! ( tcx. def_kind( id. owner_id) , DefKind :: AssocConst | DefKind :: AssocFn ) {
815
+ if matches ! (
816
+ tcx. def_kind( id. owner_id) ,
817
+ DefKind :: AssocConst | DefKind :: AssocTy | DefKind :: AssocFn
818
+ ) {
796
819
let trait_item = tcx. hir_trait_item ( id) ;
797
820
if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Fn ( ..) )
798
821
&& let Some ( comes_from_allow) =
@@ -1163,6 +1186,7 @@ impl<'tcx> DeadVisitor<'tcx> {
1163
1186
}
1164
1187
match self . tcx . def_kind ( def_id) {
1165
1188
DefKind :: AssocConst
1189
+ | DefKind :: AssocTy
1166
1190
| DefKind :: AssocFn
1167
1191
| DefKind :: Fn
1168
1192
| DefKind :: Static { .. }
0 commit comments