@@ -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 {
@@ -1343,11 +1343,11 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
1343
1343
if self . item_is_public ( & impl_item_ref. id . node_id , & impl_item_ref. vis ) {
1344
1344
let impl_item = self . tcx . hir ( ) . impl_item ( impl_item_ref. id ) ;
1345
1345
match impl_item_ref. kind {
1346
- hir :: AssociatedItemKind :: Const => {
1346
+ AssociatedItemKind :: Const => {
1347
1347
found_pub_static = true ;
1348
1348
intravisit:: walk_impl_item ( self , impl_item) ;
1349
1349
}
1350
- hir :: AssociatedItemKind :: Method { has_self : false } => {
1350
+ AssociatedItemKind :: Method { has_self : false } => {
1351
1351
found_pub_static = true ;
1352
1352
intravisit:: walk_impl_item ( self , impl_item) ;
1353
1353
}
@@ -1568,6 +1568,24 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
1568
1568
in_assoc_ty : false ,
1569
1569
}
1570
1570
}
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
+ }
1571
1589
}
1572
1590
1573
1591
impl < ' a , ' tcx > Visitor < ' tcx > for PrivateItemsInPublicInterfacesVisitor < ' a , ' tcx > {
@@ -1602,16 +1620,8 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
1602
1620
self . check ( item. id , item_visibility) . generics ( ) . predicates ( ) ;
1603
1621
1604
1622
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) ;
1615
1625
}
1616
1626
}
1617
1627
hir:: ItemKind :: TraitAlias ( ..) => {
@@ -1657,9 +1667,8 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
1657
1667
} else {
1658
1668
impl_vis
1659
1669
} ;
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) ;
1663
1672
}
1664
1673
}
1665
1674
}
0 commit comments