@@ -71,7 +71,9 @@ impl<'tcx> fmt::Display for LazyDefPathStr<'tcx> {
71
71
pub trait DefIdVisitor < ' tcx > {
72
72
type Result : VisitorResult = ( ) ;
73
73
const SHALLOW : bool = false ;
74
- const SKIP_ASSOC_TYS : bool = false ;
74
+ fn skip_assoc_tys ( & self ) -> bool {
75
+ false
76
+ }
75
77
76
78
fn tcx ( & self ) -> TyCtxt < ' tcx > ;
77
79
fn visit_def_id ( & mut self , def_id : DefId , kind : & str , descr : & dyn fmt:: Display )
@@ -212,7 +214,7 @@ where
212
214
}
213
215
}
214
216
ty:: Alias ( kind @ ( ty:: Inherent | ty:: Weak | ty:: Projection ) , data) => {
215
- if V :: SKIP_ASSOC_TYS {
217
+ if self . def_id_visitor . skip_assoc_tys ( ) {
216
218
// Visitors searching for minimal visibility/reachability want to
217
219
// conservatively approximate associated types like `Type::Alias`
218
220
// as visible/reachable even if `Type` is private.
@@ -323,7 +325,9 @@ impl<'a, 'tcx, VL: VisibilityLike, const SHALLOW: bool> DefIdVisitor<'tcx>
323
325
for FindMin < ' a , ' tcx , VL , SHALLOW >
324
326
{
325
327
const SHALLOW : bool = SHALLOW ;
326
- const SKIP_ASSOC_TYS : bool = true ;
328
+ fn skip_assoc_tys ( & self ) -> bool {
329
+ true
330
+ }
327
331
fn tcx ( & self ) -> TyCtxt < ' tcx > {
328
332
self . tcx
329
333
}
@@ -341,7 +345,7 @@ trait VisibilityLike: Sized {
341
345
def_id : LocalDefId ,
342
346
) -> Self ;
343
347
344
- // Returns an over-approximation (`SKIP_ASSOC_TYS ` = true) of visibility due to
348
+ // Returns an over-approximation (`skip_assoc_tys() ` = true) of visibility due to
345
349
// associated types for which we can't determine visibility precisely.
346
350
fn of_impl < const SHALLOW : bool > (
347
351
def_id : LocalDefId ,
@@ -1350,6 +1354,7 @@ struct SearchInterfaceForPrivateItemsVisitor<'tcx> {
1350
1354
required_effective_vis : Option < EffectiveVisibility > ,
1351
1355
in_assoc_ty : bool ,
1352
1356
in_primary_interface : bool ,
1357
+ skip_assoc_tys : bool ,
1353
1358
}
1354
1359
1355
1360
impl SearchInterfaceForPrivateItemsVisitor < ' _ > {
@@ -1396,6 +1401,14 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1396
1401
self
1397
1402
}
1398
1403
1404
+ fn trait_ref ( & mut self ) -> & mut Self {
1405
+ self . in_primary_interface = true ;
1406
+ if let Some ( trait_ref) = self . tcx . impl_trait_ref ( self . item_def_id ) {
1407
+ self . visit_trait ( trait_ref. instantiate_identity ( ) ) ;
1408
+ }
1409
+ self
1410
+ }
1411
+
1399
1412
fn check_def_id ( & mut self , def_id : DefId , kind : & str , descr : & dyn fmt:: Display ) -> bool {
1400
1413
if self . leaks_private_dep ( def_id) {
1401
1414
self . tcx . emit_node_span_lint (
@@ -1493,6 +1506,9 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1493
1506
1494
1507
impl < ' tcx > DefIdVisitor < ' tcx > for SearchInterfaceForPrivateItemsVisitor < ' tcx > {
1495
1508
type Result = ControlFlow < ( ) > ;
1509
+ fn skip_assoc_tys ( & self ) -> bool {
1510
+ self . skip_assoc_tys
1511
+ }
1496
1512
fn tcx ( & self ) -> TyCtxt < ' tcx > {
1497
1513
self . tcx
1498
1514
}
@@ -1529,6 +1545,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
1529
1545
required_effective_vis,
1530
1546
in_assoc_ty : false ,
1531
1547
in_primary_interface : true ,
1548
+ skip_assoc_tys : false ,
1532
1549
}
1533
1550
}
1534
1551
@@ -1724,13 +1741,18 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
1724
1741
self . effective_visibilities ,
1725
1742
) ;
1726
1743
1727
- // check that private components do not appear in the generics or predicates of inherent impls
1728
- // this check is intentionally NOT performed for impls of traits, per #90586
1744
+ let mut check = self . check ( item. owner_id . def_id , impl_vis, Some ( impl_ev) ) ;
1745
+ // Generics and predicates of trait impls are intentionally not checked
1746
+ // for private components (#90586).
1729
1747
if impl_. of_trait . is_none ( ) {
1730
- self . check ( item. owner_id . def_id , impl_vis, Some ( impl_ev) )
1731
- . generics ( )
1732
- . predicates ( ) ;
1748
+ check. generics ( ) . predicates ( ) ;
1733
1749
}
1750
+ // Skip checking private components in associated types, due to lack of full
1751
+ // normalization they produce very ridiculous false positives.
1752
+ // FIXME: Remove this when full normalization is implemented.
1753
+ check. skip_assoc_tys = true ;
1754
+ check. ty ( ) . trait_ref ( ) ;
1755
+
1734
1756
for impl_item_ref in impl_. items {
1735
1757
let impl_item_vis = if impl_. of_trait . is_none ( ) {
1736
1758
min (
0 commit comments