Skip to content

Commit 01794cc

Browse files
committed
auto merge of #11461 : alexcrichton/rust/rustdoc-fixes, r=brson
See the commits.
2 parents e57424b + 60880af commit 01794cc

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

mk/docs.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ $(eval $(call libdoc,std,$(STDLIB_CRATE),$(CFG_BUILD)))
308308
$(eval $(call libdoc,extra,$(EXTRALIB_CRATE),$(CFG_BUILD)))
309309
$(eval $(call libdoc,native,$(LIBNATIVE_CRATE),$(CFG_BUILD)))
310310
$(eval $(call libdoc,green,$(LIBGREEN_CRATE),$(CFG_BUILD)))
311+
$(eval $(call libdoc,rustuv,$(LIBRUSTUV_CRATE),$(CFG_BUILD)))
311312

312313
$(eval $(call compiledoc,rustc,$(COMPILER_CRATE),$(CFG_BUILD)))
313314
$(eval $(call compiledoc,syntax,$(LIBSYNTAX_CRATE),$(CFG_BUILD)))

src/librustdoc/html/render.rs

Lines changed: 22 additions & 5 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
}
@@ -1186,7 +1203,7 @@ fn item_struct(w: &mut Writer, it: &clean::Item, s: &clean::Struct) {
11861203

11871204
document(w, it);
11881205
match s.struct_type {
1189-
doctree::Plain => {
1206+
doctree::Plain if s.fields.len() > 0 => {
11901207
write!(w, "<h2 class='fields'>Fields</h2>\n<table>");
11911208
for field in s.fields.iter() {
11921209
write!(w, "<tr><td id='structfield.{name}'>\

src/librustdoc/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub fn opts() -> ~[groups::OptGroup] {
8383
use extra::getopts::groups::*;
8484
~[
8585
optflag("h", "help", "show this help message"),
86+
optflag("", "version", "print rustdoc's version"),
8687
optopt("r", "input-format", "the input type of the specified file",
8788
"[rust|json]"),
8889
optopt("w", "output-format", "the output type to write",
@@ -119,6 +120,9 @@ pub fn main_args(args: &[~str]) -> int {
119120
if matches.opt_present("h") || matches.opt_present("help") {
120121
usage(args[0]);
121122
return 0;
123+
} else if matches.opt_present("version") {
124+
rustc::version(args[0]);
125+
return 0;
122126
}
123127

124128
if matches.free.len() == 0 {

src/librustdoc/passes.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ impl<'a> fold::DocFolder for Stripper<'a> {
136136
Some(i) => {
137137
match i.inner {
138138
// emptied modules/impls have no need to exist
139-
clean::ModuleItem(ref m) if m.items.len() == 0 => None,
139+
clean::ModuleItem(ref m)
140+
if m.items.len() == 0 &&
141+
i.doc_value().is_none() => None,
140142
clean::ImplItem(ref i) if i.methods.len() == 0 => None,
141143
_ => {
142144
self.retained.insert(i.id);

0 commit comments

Comments
 (0)