Skip to content

Commit 243d82d

Browse files
committed
rustdoc: Private modules can be included in docs
Changed `rustdoc` so that if we do not have the `strip-private` pass enabled private modules will be included in the generated documentation. Also changed `strip-private` pass to actually remove private modules.
1 parent e4ead7b commit 243d82d

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

src/librustdoc/html/render.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ pub struct Cache {
188188
stack: Vec<String>,
189189
parent_stack: Vec<ast::DefId>,
190190
search_index: Vec<IndexItem>,
191-
privmod: bool,
192191
public_items: NodeSet,
193192

194193
// In rare case where a structure is defined in one module but implemented
@@ -319,7 +318,6 @@ pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: Path) ->
319318
search_index: Vec::new(),
320319
extern_locations: HashMap::new(),
321320
primitive_locations: HashMap::new(),
322-
privmod: false,
323321
public_items: public_items,
324322
orphan_methods: Vec::new(),
325323
traits: analysis.as_ref().map(|a| {
@@ -762,16 +760,6 @@ impl<'a> SourceCollector<'a> {
762760

763761
impl DocFolder for Cache {
764762
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
765-
// If this is a private module, we don't want it in the search index.
766-
let orig_privmod = match item.inner {
767-
clean::ModuleItem(..) => {
768-
let prev = self.privmod;
769-
self.privmod = prev || item.visibility != Some(ast::Public);
770-
prev
771-
}
772-
_ => self.privmod,
773-
};
774-
775763
// Register any generics to their corresponding string. This is used
776764
// when pretty-printing types
777765
match item.inner {
@@ -859,7 +847,7 @@ impl DocFolder for Cache {
859847
};
860848

861849
match parent {
862-
(parent, Some(path)) if is_method || (!self.privmod && !hidden_field) => {
850+
(parent, Some(path)) if is_method || !hidden_field => {
863851
self.search_index.push(IndexItem {
864852
ty: shortty(&item),
865853
name: s.to_string(),
@@ -868,7 +856,7 @@ impl DocFolder for Cache {
868856
parent: parent,
869857
});
870858
}
871-
(Some(parent), None) if is_method || (!self.privmod && !hidden_field)=> {
859+
(Some(parent), None) if is_method || !hidden_field => {
872860
if ast_util::is_local(parent) {
873861
// We have a parent, but we don't know where they're
874862
// defined yet. Wait for later to index this item.
@@ -893,7 +881,7 @@ impl DocFolder for Cache {
893881
clean::StructItem(..) | clean::EnumItem(..) |
894882
clean::TypedefItem(..) | clean::TraitItem(..) |
895883
clean::FunctionItem(..) | clean::ModuleItem(..) |
896-
clean::ForeignFunctionItem(..) if !self.privmod => {
884+
clean::ForeignFunctionItem(..) => {
897885
// Reexported items mean that the same id can show up twice
898886
// in the rustdoc ast that we're looking at. We know,
899887
// however, that a reexported item doesn't show up in the
@@ -910,7 +898,7 @@ impl DocFolder for Cache {
910898
}
911899
// link variants to their parent enum because pages aren't emitted
912900
// for each variant
913-
clean::VariantItem(..) if !self.privmod => {
901+
clean::VariantItem(..) => {
914902
let mut stack = self.stack.clone();
915903
stack.pop();
916904
self.paths.insert(item.def_id, (stack, item_type::Enum));
@@ -1022,7 +1010,6 @@ impl DocFolder for Cache {
10221010

10231011
if pushed { self.stack.pop().unwrap(); }
10241012
if parent_pushed { self.parent_stack.pop().unwrap(); }
1025-
self.privmod = orig_privmod;
10261013
return ret;
10271014
}
10281015
}
@@ -1191,7 +1178,7 @@ impl Context {
11911178
// these modules are recursed into, but not rendered normally (a
11921179
// flag on the context).
11931180
if !self.render_redirect_pages {
1194-
self.render_redirect_pages = ignore_private_item(&item);
1181+
self.render_redirect_pages = ignore_empty_item(&item);
11951182
}
11961183

11971184
match item.inner {
@@ -1442,7 +1429,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
14421429
try!(document(w, item));
14431430

14441431
let mut indices = range(0, items.len()).filter(|i| {
1445-
!ignore_private_item(&items[*i])
1432+
!ignore_empty_item(&items[*i])
14461433
}).collect::<Vec<uint>>();
14471434

14481435
fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: uint, idx2: uint) -> Ordering {
@@ -2159,7 +2146,7 @@ impl<'a> fmt::Show for Sidebar<'a> {
21592146
fn build_sidebar(m: &clean::Module) -> HashMap<String, Vec<String>> {
21602147
let mut map = HashMap::new();
21612148
for item in m.items.iter() {
2162-
if ignore_private_item(item) { continue }
2149+
if ignore_empty_item(item) { continue }
21632150

21642151
let short = shortty(item).to_static_str();
21652152
let myname = match item.name {
@@ -2213,11 +2200,10 @@ fn item_primitive(w: &mut fmt::Formatter,
22132200
render_methods(w, it)
22142201
}
22152202

2216-
fn ignore_private_item(it: &clean::Item) -> bool {
2203+
fn ignore_empty_item(it: &clean::Item) -> bool {
22172204
match it.inner {
22182205
clean::ModuleItem(ref m) => {
2219-
(m.items.len() == 0 && it.doc_value().is_none()) ||
2220-
it.visibility != Some(ast::Public)
2206+
(m.items.len() == 0 && it.doc_value().is_none())
22212207
}
22222208
clean::PrimitiveItem(..) => it.visibility != Some(ast::Public),
22232209
_ => false,

src/librustdoc/passes.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,11 @@ impl<'a> fold::DocFolder for Stripper<'a> {
168168
}
169169
}
170170

171-
// handled below
172-
clean::ModuleItem(..) => {}
171+
clean::ModuleItem(..) => {
172+
if i.visibility != Some(ast::Public) {
173+
return None
174+
}
175+
}
173176

174177
// trait impls for private items should be stripped
175178
clean::ImplItem(clean::Impl{

0 commit comments

Comments
 (0)