@@ -13,7 +13,7 @@ extern crate rustc_typeck;
1313extern crate syntax_pos;
1414extern crate rustc_data_structures;
1515
16- use rustc:: hir:: { self , Node , PatKind } ;
16+ use rustc:: hir:: { self , Node , PatKind , AssociatedItemKind } ;
1717use rustc:: hir:: def:: Def ;
1818use rustc:: hir:: def_id:: { CRATE_DEF_INDEX , LOCAL_CRATE , CrateNum , DefId } ;
1919use rustc:: hir:: intravisit:: { self , Visitor , NestedVisitorMap } ;
@@ -548,7 +548,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
548548 let mut reach = self . reach ( trait_item_ref. id . node_id , item_level) ;
549549 reach. generics ( ) . predicates ( ) ;
550550
551- if trait_item_ref. kind == hir :: AssociatedItemKind :: Type &&
551+ if trait_item_ref. kind == AssociatedItemKind :: Type &&
552552 !trait_item_ref. defaultness . has_value ( ) {
553553 // No type to visit.
554554 } else {
@@ -1343,11 +1343,11 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
13431343 if self . item_is_public ( & impl_item_ref. id . node_id , & impl_item_ref. vis ) {
13441344 let impl_item = self . tcx . hir ( ) . impl_item ( impl_item_ref. id ) ;
13451345 match impl_item_ref. kind {
1346- hir :: AssociatedItemKind :: Const => {
1346+ AssociatedItemKind :: Const => {
13471347 found_pub_static = true ;
13481348 intravisit:: walk_impl_item ( self , impl_item) ;
13491349 }
1350- hir :: AssociatedItemKind :: Method { has_self : false } => {
1350+ AssociatedItemKind :: Method { has_self : false } => {
13511351 found_pub_static = true ;
13521352 intravisit:: walk_impl_item ( self , impl_item) ;
13531353 }
@@ -1568,6 +1568,24 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
15681568 in_assoc_ty : false ,
15691569 }
15701570 }
1571+
1572+ fn check_trait_or_impl_item ( & self , node_id : ast:: NodeId , assoc_item_kind : AssociatedItemKind ,
1573+ defaultness : hir:: Defaultness , vis : ty:: Visibility ) {
1574+ let mut check = self . check ( node_id, vis) ;
1575+
1576+ let ( check_ty, is_assoc_ty) = match assoc_item_kind {
1577+ AssociatedItemKind :: Const | AssociatedItemKind :: Method { .. } => ( true , false ) ,
1578+ AssociatedItemKind :: Type => ( defaultness. has_value ( ) , true ) ,
1579+ // `ty()` for existential types is the underlying type,
1580+ // it's not a part of interface, so we skip it.
1581+ AssociatedItemKind :: Existential => ( false , true ) ,
1582+ } ;
1583+ check. in_assoc_ty = is_assoc_ty;
1584+ check. generics ( ) . predicates ( ) ;
1585+ if check_ty {
1586+ check. ty ( ) ;
1587+ }
1588+ }
15711589}
15721590
15731591impl < ' a , ' tcx > Visitor < ' tcx > for PrivateItemsInPublicInterfacesVisitor < ' a , ' tcx > {
@@ -1602,16 +1620,8 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
16021620 self . check ( item. id , item_visibility) . generics ( ) . predicates ( ) ;
16031621
16041622 for trait_item_ref in trait_item_refs {
1605- let mut check = self . check ( trait_item_ref. id . node_id , item_visibility) ;
1606- check. in_assoc_ty = trait_item_ref. kind == hir:: AssociatedItemKind :: Type ;
1607- check. generics ( ) . predicates ( ) ;
1608-
1609- if trait_item_ref. kind == hir:: AssociatedItemKind :: Type &&
1610- !trait_item_ref. defaultness . has_value ( ) {
1611- // No type to visit.
1612- } else {
1613- check. ty ( ) ;
1614- }
1623+ self . check_trait_or_impl_item ( trait_item_ref. id . node_id , trait_item_ref. kind ,
1624+ trait_item_ref. defaultness , item_visibility) ;
16151625 }
16161626 }
16171627 hir:: ItemKind :: TraitAlias ( ..) => {
@@ -1657,9 +1667,8 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
16571667 } else {
16581668 impl_vis
16591669 } ;
1660- let mut check = self . check ( impl_item. id , impl_item_vis) ;
1661- check. in_assoc_ty = impl_item_ref. kind == hir:: AssociatedItemKind :: Type ;
1662- check. generics ( ) . predicates ( ) . ty ( ) ;
1670+ self . check_trait_or_impl_item ( impl_item_ref. id . node_id , impl_item_ref. kind ,
1671+ impl_item_ref. defaultness , impl_item_vis) ;
16631672 }
16641673 }
16651674 }
0 commit comments