@@ -39,7 +39,7 @@ use util::ppaux::{ty_to_string};
39
39
use util:: nodemap:: { FnvHashMap , NodeSet } ;
40
40
use lint:: { Level , Context , LintPass , LintArray , Lint } ;
41
41
42
- use std:: collections:: BitSet ;
42
+ use std:: collections:: { HashSet , BitSet } ;
43
43
use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
44
44
use std:: num:: SignedInt ;
45
45
use std:: { cmp, slice} ;
@@ -1437,6 +1437,9 @@ pub struct MissingDoc {
1437
1437
/// Stack of whether #[doc(hidden)] is set
1438
1438
/// at each level which has lint attributes.
1439
1439
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 > ,
1440
1443
}
1441
1444
1442
1445
impl MissingDoc {
@@ -1445,6 +1448,7 @@ impl MissingDoc {
1445
1448
struct_def_stack : vec ! ( ) ,
1446
1449
in_variant : false ,
1447
1450
doc_hidden_stack : vec ! ( false ) ,
1451
+ private_traits : HashSet :: new ( ) ,
1448
1452
}
1449
1453
}
1450
1454
@@ -1531,18 +1535,46 @@ impl LintPass for MissingDoc {
1531
1535
ast:: ItemMod ( ..) => "a module" ,
1532
1536
ast:: ItemEnum ( ..) => "an enum" ,
1533
1537
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
+ } ,
1535
1549
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
+ } ,
1536
1564
_ => return
1537
1565
} ;
1566
+
1538
1567
self . check_missing_docs_attrs ( cx, Some ( it. id ) , & it. attrs , it. span , desc) ;
1539
1568
}
1540
1569
1541
1570
fn check_trait_item ( & mut self , cx : & Context , trait_item : & ast:: TraitItem ) {
1571
+ if self . private_traits . contains ( & trait_item. id ) { return }
1572
+
1542
1573
let desc = match trait_item. node {
1543
1574
ast:: MethodTraitItem ( ..) => "a trait method" ,
1544
1575
ast:: TypeTraitItem ( ..) => "an associated type"
1545
1576
} ;
1577
+
1546
1578
self . check_missing_docs_attrs ( cx, Some ( trait_item. id ) ,
1547
1579
& trait_item. attrs ,
1548
1580
trait_item. span , desc) ;
0 commit comments