@@ -72,7 +72,9 @@ impl<'tcx> fmt::Display for LazyDefPathStr<'tcx> {
7272pub trait DefIdVisitor < ' tcx > {
7373 type Result : VisitorResult = ( ) ;
7474 const SHALLOW : bool = false ;
75- const SKIP_ASSOC_TYS : bool = false ;
75+ fn skip_assoc_tys ( & self ) -> bool {
76+ false
77+ }
7678
7779 fn tcx ( & self ) -> TyCtxt < ' tcx > ;
7880 fn visit_def_id ( & mut self , def_id : DefId , kind : & str , descr : & dyn fmt:: Display )
@@ -213,7 +215,7 @@ where
213215 }
214216 }
215217 ty:: Alias ( kind @ ( ty:: Inherent | ty:: Weak | ty:: Projection ) , data) => {
216- if V :: SKIP_ASSOC_TYS {
218+ if self . def_id_visitor . skip_assoc_tys ( ) {
217219 // Visitors searching for minimal visibility/reachability want to
218220 // conservatively approximate associated types like `Type::Alias`
219221 // as visible/reachable even if `Type` is private.
@@ -324,7 +326,9 @@ impl<'a, 'tcx, VL: VisibilityLike, const SHALLOW: bool> DefIdVisitor<'tcx>
324326 for FindMin < ' a , ' tcx , VL , SHALLOW >
325327{
326328 const SHALLOW : bool = SHALLOW ;
327- const SKIP_ASSOC_TYS : bool = true ;
329+ fn skip_assoc_tys ( & self ) -> bool {
330+ true
331+ }
328332 fn tcx ( & self ) -> TyCtxt < ' tcx > {
329333 self . tcx
330334 }
@@ -342,7 +346,7 @@ trait VisibilityLike: Sized {
342346 def_id : LocalDefId ,
343347 ) -> Self ;
344348
345- // Returns an over-approximation (`SKIP_ASSOC_TYS ` = true) of visibility due to
349+ // Returns an over-approximation (`skip_assoc_tys() ` = true) of visibility due to
346350 // associated types for which we can't determine visibility precisely.
347351 fn of_impl < const SHALLOW : bool > (
348352 def_id : LocalDefId ,
@@ -1352,6 +1356,7 @@ struct SearchInterfaceForPrivateItemsVisitor<'tcx> {
13521356 required_effective_vis : Option < EffectiveVisibility > ,
13531357 in_assoc_ty : bool ,
13541358 in_primary_interface : bool ,
1359+ skip_assoc_tys : bool ,
13551360}
13561361
13571362impl SearchInterfaceForPrivateItemsVisitor < ' _ > {
@@ -1398,6 +1403,14 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
13981403 self
13991404 }
14001405
1406+ fn trait_ref ( & mut self ) -> & mut Self {
1407+ self . in_primary_interface = true ;
1408+ if let Some ( trait_ref) = self . tcx . impl_trait_ref ( self . item_def_id ) {
1409+ let _ = self . visit_trait ( trait_ref. instantiate_identity ( ) ) ;
1410+ }
1411+ self
1412+ }
1413+
14011414 fn check_def_id ( & mut self , def_id : DefId , kind : & str , descr : & dyn fmt:: Display ) -> bool {
14021415 if self . leaks_private_dep ( def_id) {
14031416 self . tcx . emit_node_span_lint (
@@ -1495,6 +1508,9 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
14951508
14961509impl < ' tcx > DefIdVisitor < ' tcx > for SearchInterfaceForPrivateItemsVisitor < ' tcx > {
14971510 type Result = ControlFlow < ( ) > ;
1511+ fn skip_assoc_tys ( & self ) -> bool {
1512+ self . skip_assoc_tys
1513+ }
14981514 fn tcx ( & self ) -> TyCtxt < ' tcx > {
14991515 self . tcx
15001516 }
@@ -1531,6 +1547,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
15311547 required_effective_vis,
15321548 in_assoc_ty : false ,
15331549 in_primary_interface : true ,
1550+ skip_assoc_tys : false ,
15341551 }
15351552 }
15361553
@@ -1726,13 +1743,18 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
17261743 self . effective_visibilities ,
17271744 ) ;
17281745
1729- // check that private components do not appear in the generics or predicates of inherent impls
1730- // this check is intentionally NOT performed for impls of traits, per #90586
1746+ let mut check = self . check ( item. owner_id . def_id , impl_vis, Some ( impl_ev) ) ;
1747+ // Generics and predicates of trait impls are intentionally not checked
1748+ // for private components (#90586).
17311749 if impl_. of_trait . is_none ( ) {
1732- self . check ( item. owner_id . def_id , impl_vis, Some ( impl_ev) )
1733- . generics ( )
1734- . predicates ( ) ;
1750+ check. generics ( ) . predicates ( ) ;
17351751 }
1752+ // Skip checking private components in associated types, due to lack of full
1753+ // normalization they produce very ridiculous false positives.
1754+ // FIXME: Remove this when full normalization is implemented.
1755+ check. skip_assoc_tys = true ;
1756+ check. ty ( ) . trait_ref ( ) ;
1757+
17361758 for impl_item_ref in impl_. items {
17371759 let impl_item_vis = if impl_. of_trait . is_none ( ) {
17381760 min (
0 commit comments