@@ -13,7 +13,7 @@ extern crate rustc_typeck;
13
13
extern crate syntax_pos;
14
14
extern crate rustc_data_structures;
15
15
16
- use rustc:: hir:: { self , Node , PatKind } ;
16
+ use rustc:: hir:: { self , Node , PatKind , AssociatedItemKind } ;
17
17
use rustc:: hir:: def:: Def ;
18
18
use rustc:: hir:: def_id:: { CRATE_DEF_INDEX , LOCAL_CRATE , CrateNum , DefId } ;
19
19
use rustc:: hir:: intravisit:: { self , Visitor , NestedVisitorMap } ;
@@ -548,7 +548,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
548
548
let mut reach = self . reach ( trait_item_ref. id . node_id , item_level) ;
549
549
reach. generics ( ) . predicates ( ) ;
550
550
551
- if trait_item_ref. kind == hir :: AssociatedItemKind :: Type &&
551
+ if trait_item_ref. kind == AssociatedItemKind :: Type &&
552
552
!trait_item_ref. defaultness . has_value ( ) {
553
553
// No type to visit.
554
554
} else {
@@ -1333,11 +1333,11 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
1333
1333
if self . item_is_public ( & impl_item_ref. id . node_id , & impl_item_ref. vis ) {
1334
1334
let impl_item = self . tcx . hir ( ) . impl_item ( impl_item_ref. id ) ;
1335
1335
match impl_item_ref. kind {
1336
- hir :: AssociatedItemKind :: Const => {
1336
+ AssociatedItemKind :: Const => {
1337
1337
found_pub_static = true ;
1338
1338
intravisit:: walk_impl_item ( self , impl_item) ;
1339
1339
}
1340
- hir :: AssociatedItemKind :: Method { has_self : false } => {
1340
+ AssociatedItemKind :: Method { has_self : false } => {
1341
1341
found_pub_static = true ;
1342
1342
intravisit:: walk_impl_item ( self , impl_item) ;
1343
1343
}
@@ -1558,6 +1558,24 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
1558
1558
in_assoc_ty : false ,
1559
1559
}
1560
1560
}
1561
+
1562
+ fn check_trait_or_impl_item ( & self , node_id : ast:: NodeId , assoc_item_kind : AssociatedItemKind ,
1563
+ defaultness : hir:: Defaultness , vis : ty:: Visibility ) {
1564
+ let mut check = self . check ( node_id, vis) ;
1565
+
1566
+ let ( check_ty, is_assoc_ty) = match assoc_item_kind {
1567
+ AssociatedItemKind :: Const | AssociatedItemKind :: Method { .. } => ( true , false ) ,
1568
+ AssociatedItemKind :: Type => ( defaultness. has_value ( ) , true ) ,
1569
+ // `ty()` for existential types is the underlying type,
1570
+ // it's not a part of interface, so we skip it.
1571
+ AssociatedItemKind :: Existential => ( false , true ) ,
1572
+ } ;
1573
+ check. in_assoc_ty = is_assoc_ty;
1574
+ check. generics ( ) . predicates ( ) ;
1575
+ if check_ty {
1576
+ check. ty ( ) ;
1577
+ }
1578
+ }
1561
1579
}
1562
1580
1563
1581
impl < ' a , ' tcx > Visitor < ' tcx > for PrivateItemsInPublicInterfacesVisitor < ' a , ' tcx > {
@@ -1592,16 +1610,8 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
1592
1610
self . check ( item. id , item_visibility) . generics ( ) . predicates ( ) ;
1593
1611
1594
1612
for trait_item_ref in trait_item_refs {
1595
- let mut check = self . check ( trait_item_ref. id . node_id , item_visibility) ;
1596
- check. in_assoc_ty = trait_item_ref. kind == hir:: AssociatedItemKind :: Type ;
1597
- check. generics ( ) . predicates ( ) ;
1598
-
1599
- if trait_item_ref. kind == hir:: AssociatedItemKind :: Type &&
1600
- !trait_item_ref. defaultness . has_value ( ) {
1601
- // No type to visit.
1602
- } else {
1603
- check. ty ( ) ;
1604
- }
1613
+ self . check_trait_or_impl_item ( trait_item_ref. id . node_id , trait_item_ref. kind ,
1614
+ trait_item_ref. defaultness , item_visibility) ;
1605
1615
}
1606
1616
}
1607
1617
hir:: ItemKind :: TraitAlias ( ..) => {
@@ -1647,9 +1657,8 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
1647
1657
} else {
1648
1658
impl_vis
1649
1659
} ;
1650
- let mut check = self . check ( impl_item. id , impl_item_vis) ;
1651
- check. in_assoc_ty = impl_item_ref. kind == hir:: AssociatedItemKind :: Type ;
1652
- check. generics ( ) . predicates ( ) . ty ( ) ;
1660
+ self . check_trait_or_impl_item ( impl_item_ref. id . node_id , impl_item_ref. kind ,
1661
+ impl_item_ref. defaultness , impl_item_vis) ;
1653
1662
}
1654
1663
}
1655
1664
}
0 commit comments