Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assorted rustdoc fixes #11461

Merged
merged 5 commits into from
Jan 11, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rustdoc: Don't show private modules
  • Loading branch information
alexcrichton committed Jan 10, 2014
commit 594807951f0a7761ad31642168fd3728b78923dc
25 changes: 21 additions & 4 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -455,6 +457,16 @@ impl<'a> SourceCollector<'a> {

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 {
Expand Down Expand Up @@ -530,7 +542,7 @@ impl DocFolder for Cache {
_ => 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(),
Expand All @@ -539,7 +551,7 @@ impl DocFolder for Cache {
parent: parent,
});
}
None => {}
Some(..) | None => {}
}
}
None => {}
Expand Down Expand Up @@ -612,8 +624,12 @@ impl DocFolder for Cache {
// 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),
}
}
Expand All @@ -622,6 +638,7 @@ impl DocFolder for Cache {

if pushed { self.stack.pop(); }
if parent_pushed { self.parent_stack.pop(); }
self.privmod = orig_privmod;
return ret;
}
}
Expand Down