@@ -1313,6 +1313,7 @@ struct SearchInterfaceForPrivateItemsVisitor<'a, 'tcx: 'a> {
13131313 min_visibility : ty:: Visibility ,
13141314 has_pub_restricted : bool ,
13151315 has_old_errors : bool ,
1316+ in_assoc_ty : bool ,
13161317}
13171318
13181319impl < ' a , ' tcx : ' a > SearchInterfaceForPrivateItemsVisitor < ' a , ' tcx > {
@@ -1373,11 +1374,11 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
13731374 self . min_visibility = vis;
13741375 }
13751376 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 {
13771378 struct_span_err ! ( self . tcx. sess, self . span, E0445 ,
13781379 "private trait `{}` in public interface" , trait_ref)
13791380 . span_label ( self . span , format ! (
1380- "private trait can't be public " ) )
1381+ "can't leak private trait " ) )
13811382 . emit ( ) ;
13821383 } else {
13831384 self . tcx . lint_node ( lint:: builtin:: PRIVATE_IN_PUBLIC ,
@@ -1428,7 +1429,7 @@ impl<'a, 'tcx: 'a> TypeVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'
14281429 self . min_visibility = vis;
14291430 }
14301431 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 {
14321433 let mut err = struct_span_err ! ( self . tcx. sess, self . span, E0446 ,
14331434 "private type `{}` in public interface" , ty) ;
14341435 err. span_label ( self . span , "can't leak private type" ) ;
@@ -1489,6 +1490,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
14891490 required_visibility,
14901491 has_pub_restricted : self . has_pub_restricted ,
14911492 has_old_errors,
1493+ in_assoc_ty : false ,
14921494 }
14931495 }
14941496}
@@ -1529,6 +1531,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
15291531
15301532 for trait_item_ref in trait_item_refs {
15311533 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 ;
15321535 check. generics ( ) . predicates ( ) ;
15331536
15341537 if trait_item_ref. kind == hir:: AssociatedItemKind :: Type &&
@@ -1579,10 +1582,10 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
15791582
15801583 for impl_item_ref in impl_item_refs {
15811584 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 ( ) ;
15861589
15871590 // Recurse for e.g. `impl Trait` (see `visit_ty`).
15881591 self . inner_visibility = impl_item_vis;
@@ -1597,7 +1600,9 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
15971600 self . check ( item. id , vis) . generics ( ) . predicates ( ) ;
15981601 for impl_item_ref in impl_item_refs {
15991602 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 ( ) ;
16011606
16021607 // Recurse for e.g. `impl Trait` (see `visit_ty`).
16031608 self . inner_visibility = vis;
0 commit comments