@@ -1313,6 +1313,7 @@ struct SearchInterfaceForPrivateItemsVisitor<'a, 'tcx: 'a> {
1313
1313
min_visibility : ty:: Visibility ,
1314
1314
has_pub_restricted : bool ,
1315
1315
has_old_errors : bool ,
1316
+ in_assoc_ty : bool ,
1316
1317
}
1317
1318
1318
1319
impl < ' a , ' tcx : ' a > SearchInterfaceForPrivateItemsVisitor < ' a , ' tcx > {
@@ -1373,11 +1374,11 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
1373
1374
self . min_visibility = vis;
1374
1375
}
1375
1376
if !vis. is_at_least ( self . required_visibility , self . tcx ) {
1376
- if self . has_pub_restricted || self . has_old_errors {
1377
+ if self . has_pub_restricted || self . has_old_errors || self . in_assoc_ty {
1377
1378
struct_span_err ! ( self . tcx. sess, self . span, E0445 ,
1378
1379
"private trait `{}` in public interface" , trait_ref)
1379
1380
. span_label ( self . span , format ! (
1380
- "private trait can't be public " ) )
1381
+ "can't leak private trait " ) )
1381
1382
. emit ( ) ;
1382
1383
} else {
1383
1384
self . tcx . lint_node ( lint:: builtin:: PRIVATE_IN_PUBLIC ,
@@ -1428,7 +1429,7 @@ impl<'a, 'tcx: 'a> TypeVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'
1428
1429
self . min_visibility = vis;
1429
1430
}
1430
1431
if !vis. is_at_least ( self . required_visibility , self . tcx ) {
1431
- if self . has_pub_restricted || self . has_old_errors {
1432
+ if self . has_pub_restricted || self . has_old_errors || self . in_assoc_ty {
1432
1433
let mut err = struct_span_err ! ( self . tcx. sess, self . span, E0446 ,
1433
1434
"private type `{}` in public interface" , ty) ;
1434
1435
err. span_label ( self . span , "can't leak private type" ) ;
@@ -1489,6 +1490,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
1489
1490
required_visibility,
1490
1491
has_pub_restricted : self . has_pub_restricted ,
1491
1492
has_old_errors,
1493
+ in_assoc_ty : false ,
1492
1494
}
1493
1495
}
1494
1496
}
@@ -1529,6 +1531,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
1529
1531
1530
1532
for trait_item_ref in trait_item_refs {
1531
1533
let mut check = self . check ( trait_item_ref. id . node_id , item_visibility) ;
1534
+ check. in_assoc_ty = trait_item_ref. kind == hir:: AssociatedItemKind :: Type ;
1532
1535
check. generics ( ) . predicates ( ) ;
1533
1536
1534
1537
if trait_item_ref. kind == hir:: AssociatedItemKind :: Type &&
@@ -1579,10 +1582,10 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
1579
1582
1580
1583
for impl_item_ref in impl_item_refs {
1581
1584
let impl_item = self . tcx . hir . impl_item ( impl_item_ref. id ) ;
1582
- let impl_item_vis =
1583
- ty :: Visibility :: from_hir ( & impl_item. vis , item . id , tcx ) ;
1584
- self . check ( impl_item . id , min ( impl_item_vis , ty_vis ) )
1585
- . generics ( ) . predicates ( ) . ty ( ) ;
1585
+ let impl_item_vis = ty :: Visibility :: from_hir ( & impl_item . vis , item . id , tcx ) ;
1586
+ let mut check = self . check ( impl_item. id , min ( impl_item_vis , ty_vis ) ) ;
1587
+ check. in_assoc_ty = impl_item_ref . kind == hir :: AssociatedItemKind :: Type ;
1588
+ check . generics ( ) . predicates ( ) . ty ( ) ;
1586
1589
1587
1590
// Recurse for e.g. `impl Trait` (see `visit_ty`).
1588
1591
self . inner_visibility = impl_item_vis;
@@ -1597,7 +1600,9 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
1597
1600
self . check ( item. id , vis) . generics ( ) . predicates ( ) ;
1598
1601
for impl_item_ref in impl_item_refs {
1599
1602
let impl_item = self . tcx . hir . impl_item ( impl_item_ref. id ) ;
1600
- self . check ( impl_item. id , vis) . generics ( ) . predicates ( ) . ty ( ) ;
1603
+ let mut check = self . check ( impl_item. id , vis) ;
1604
+ check. in_assoc_ty = impl_item_ref. kind == hir:: AssociatedItemKind :: Type ;
1605
+ check. generics ( ) . predicates ( ) . ty ( ) ;
1601
1606
1602
1607
// Recurse for e.g. `impl Trait` (see `visit_ty`).
1603
1608
self . inner_visibility = vis;
0 commit comments