Skip to content

Commit 5948079

Browse files
committed
rustdoc: Don't show private modules
1 parent 79e144e commit 5948079

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/librustdoc/html/render.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub struct Cache {
157157
priv stack: ~[~str],
158158
priv parent_stack: ~[ast::NodeId],
159159
priv search_index: ~[IndexItem],
160+
priv privmod: bool,
160161
}
161162

162163
/// Helper struct to render all source code to HTML pages
@@ -241,6 +242,7 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
241242
parent_stack: ~[],
242243
search_index: ~[],
243244
extern_locations: HashMap::new(),
245+
privmod: false,
244246
};
245247
cache.stack.push(crate.name.clone());
246248
crate = cache.fold_crate(crate);
@@ -455,6 +457,16 @@ impl<'a> SourceCollector<'a> {
455457

456458
impl DocFolder for Cache {
457459
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
460+
// If this is a private module, we don't want it in the search index.
461+
let orig_privmod = match item.inner {
462+
clean::ModuleItem(..) => {
463+
let prev = self.privmod;
464+
self.privmod = prev || item.visibility != Some(ast::public);
465+
prev
466+
}
467+
_ => self.privmod,
468+
};
469+
458470
// Register any generics to their corresponding string. This is used
459471
// when pretty-printing types
460472
match item.inner {
@@ -530,7 +542,7 @@ impl DocFolder for Cache {
530542
_ => Some((None, self.stack.as_slice()))
531543
};
532544
match parent {
533-
Some((parent, path)) => {
545+
Some((parent, path)) if !self.privmod => {
534546
self.search_index.push(IndexItem {
535547
ty: shortty(&item),
536548
name: s.to_owned(),
@@ -539,7 +551,7 @@ impl DocFolder for Cache {
539551
parent: parent,
540552
});
541553
}
542-
None => {}
554+
Some(..) | None => {}
543555
}
544556
}
545557
None => {}
@@ -612,8 +624,12 @@ impl DocFolder for Cache {
612624
// Private modules may survive the strip-private pass if
613625
// they contain impls for public types, but those will get
614626
// stripped here
615-
clean::Item { inner: clean::ModuleItem(ref m), .. }
616-
if m.items.len() == 0 => None,
627+
clean::Item { inner: clean::ModuleItem(ref m),
628+
visibility, .. }
629+
if (m.items.len() == 0 &&
630+
item.doc_value().is_none()) ||
631+
visibility != Some(ast::public) => None,
632+
617633
i => Some(i),
618634
}
619635
}
@@ -622,6 +638,7 @@ impl DocFolder for Cache {
622638

623639
if pushed { self.stack.pop(); }
624640
if parent_pushed { self.parent_stack.pop(); }
641+
self.privmod = orig_privmod;
625642
return ret;
626643
}
627644
}

0 commit comments

Comments
 (0)