@@ -115,7 +115,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
115115
116116 fn handle_res ( & mut self , res : Res ) {
117117 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+ ) => {
119122 self . check_def_id ( def_id) ;
120123 }
121124 _ if self . in_pat => { }
@@ -482,7 +485,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
482485 ) -> bool {
483486 let trait_def_id = match self . tcx . def_kind ( local_def_id) {
484487 // 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
486489 . tcx
487490 . associated_item ( local_def_id)
488491 . trait_item_def_id
@@ -647,6 +650,29 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
647650
648651 self . in_pat = in_pat;
649652 }
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+ }
650676}
651677
652678fn has_allow_dead_code_or_lang_attr (
@@ -744,18 +770,12 @@ fn check_item<'tcx>(
744770 {
745771 worklist. push ( ( local_def_id, comes_from_allow) ) ;
746772 } 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) ) ;
759779 }
760780 }
761781 }
@@ -792,7 +812,10 @@ fn check_trait_item(
792812 id : hir:: TraitItemId ,
793813) {
794814 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+ ) {
796819 let trait_item = tcx. hir_trait_item ( id) ;
797820 if matches ! ( trait_item. kind, Const ( _, Some ( _) ) | Fn ( ..) )
798821 && let Some ( comes_from_allow) =
@@ -1163,6 +1186,7 @@ impl<'tcx> DeadVisitor<'tcx> {
11631186 }
11641187 match self . tcx . def_kind ( def_id) {
11651188 DefKind :: AssocConst
1189+ | DefKind :: AssocTy
11661190 | DefKind :: AssocFn
11671191 | DefKind :: Fn
11681192 | DefKind :: Static { .. }
0 commit comments