提交 59480795 编写于 作者: A Alex Crichton

rustdoc: Don't show private modules

上级 79e144ed
......@@ -157,6 +157,7 @@ pub struct Cache {
priv stack: ~[~str],
priv parent_stack: ~[ast::NodeId],
priv search_index: ~[IndexItem],
priv privmod: bool,
}
/// Helper struct to render all source code to HTML pages
......@@ -241,6 +242,7 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
parent_stack: ~[],
search_index: ~[],
extern_locations: HashMap::new(),
privmod: false,
};
cache.stack.push(crate.name.clone());
crate = cache.fold_crate(crate);
......@@ -455,6 +457,16 @@ fn emit_source(&mut self, filename: &str) -> bool {
impl DocFolder for Cache {
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
// If this is a private module, we don't want it in the search index.
let orig_privmod = match item.inner {
clean::ModuleItem(..) => {
let prev = self.privmod;
self.privmod = prev || item.visibility != Some(ast::public);
prev
}
_ => self.privmod,
};
// Register any generics to their corresponding string. This is used
// when pretty-printing types
match item.inner {
......@@ -530,7 +542,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
_ => Some((None, self.stack.as_slice()))
};
match parent {
Some((parent, path)) => {
Some((parent, path)) if !self.privmod => {
self.search_index.push(IndexItem {
ty: shortty(&item),
name: s.to_owned(),
......@@ -539,7 +551,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
parent: parent,
});
}
None => {}
Some(..) | None => {}
}
}
None => {}
......@@ -612,8 +624,12 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
// Private modules may survive the strip-private pass if
// they contain impls for public types, but those will get
// stripped here
clean::Item { inner: clean::ModuleItem(ref m), .. }
if m.items.len() == 0 => None,
clean::Item { inner: clean::ModuleItem(ref m),
visibility, .. }
if (m.items.len() == 0 &&
item.doc_value().is_none()) ||
visibility != Some(ast::public) => None,
i => Some(i),
}
}
......@@ -622,6 +638,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
if pushed { self.stack.pop(); }
if parent_pushed { self.parent_stack.pop(); }
self.privmod = orig_privmod;
return ret;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册