@@ -39,7 +39,7 @@ use util::ppaux::{ty_to_string};
3939use util:: nodemap:: { FnvHashMap , NodeSet } ;
4040use lint:: { Level , Context , LintPass , LintArray , Lint } ;
4141
42- use std:: collections:: BitSet ;
42+ use std:: collections:: { HashSet , BitSet } ;
4343use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
4444use std:: num:: SignedInt ;
4545use std:: { cmp, slice} ;
@@ -1437,6 +1437,9 @@ pub struct MissingDoc {
14371437 /// Stack of whether #[doc(hidden)] is set
14381438 /// at each level which has lint attributes.
14391439 doc_hidden_stack : Vec < bool > ,
1440+
1441+ /// Private traits or trait items that leaked through. Don't check their methods.
1442+ private_traits : HashSet < ast:: NodeId > ,
14401443}
14411444
14421445impl MissingDoc {
@@ -1445,6 +1448,7 @@ impl MissingDoc {
14451448 struct_def_stack : vec ! ( ) ,
14461449 in_variant : false ,
14471450 doc_hidden_stack : vec ! ( false ) ,
1451+ private_traits : HashSet :: new ( ) ,
14481452 }
14491453 }
14501454
@@ -1531,18 +1535,46 @@ impl LintPass for MissingDoc {
15311535 ast:: ItemMod ( ..) => "a module" ,
15321536 ast:: ItemEnum ( ..) => "an enum" ,
15331537 ast:: ItemStruct ( ..) => "a struct" ,
1534- ast:: ItemTrait ( ..) => "a trait" ,
1538+ ast:: ItemTrait ( _, _, _, ref items) => {
1539+ // Issue #11592, traits are always considered exported, even when private.
1540+ if it. vis == ast:: Visibility :: Inherited {
1541+ self . private_traits . insert ( it. id ) ;
1542+ for itm in items {
1543+ self . private_traits . insert ( itm. id ) ;
1544+ }
1545+ return
1546+ }
1547+ "a trait"
1548+ } ,
15351549 ast:: ItemTy ( ..) => "a type alias" ,
1550+ ast:: ItemImpl ( _, _, _, Some ( ref trait_ref) , _, ref impl_items) => {
1551+ // If the trait is private, add the impl items to private_traits so they don't get
1552+ // reported for missing docs.
1553+ let real_trait = ty:: trait_ref_to_def_id ( cx. tcx , trait_ref) ;
1554+ match cx. tcx . map . find ( real_trait. node ) {
1555+ Some ( ast_map:: NodeItem ( item) ) => if item. vis == ast:: Visibility :: Inherited {
1556+ for itm in impl_items {
1557+ self . private_traits . insert ( itm. id ) ;
1558+ }
1559+ } ,
1560+ _ => { }
1561+ }
1562+ return
1563+ } ,
15361564 _ => return
15371565 } ;
1566+
15381567 self . check_missing_docs_attrs ( cx, Some ( it. id ) , & it. attrs , it. span , desc) ;
15391568 }
15401569
15411570 fn check_trait_item ( & mut self , cx : & Context , trait_item : & ast:: TraitItem ) {
1571+ if self . private_traits . contains ( & trait_item. id ) { return }
1572+
15421573 let desc = match trait_item. node {
15431574 ast:: MethodTraitItem ( ..) => "a trait method" ,
15441575 ast:: TypeTraitItem ( ..) => "an associated type"
15451576 } ;
1577+
15461578 self . check_missing_docs_attrs ( cx, Some ( trait_item. id ) ,
15471579 & trait_item. attrs ,
15481580 trait_item. span , desc) ;
0 commit comments