Skip to content

Commit 7298dab

Browse files
committed
rustdoc: Stop stripping empty modules
There is no good reason to strip empty modules with no documentation and doing so causes subtle problems.
1 parent 19193d6 commit 7298dab

File tree

4 files changed

+60
-28
lines changed

4 files changed

+60
-28
lines changed

src/librustdoc/html/render.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ impl Context {
13491349
// these modules are recursed into, but not rendered normally
13501350
// (a flag on the context).
13511351
if !self.render_redirect_pages {
1352-
self.render_redirect_pages = maybe_ignore_item(&item);
1352+
self.render_redirect_pages = item.is_stripped();
13531353
}
13541354

13551355
if item.is_mod() {
@@ -1432,7 +1432,7 @@ impl Context {
14321432
// BTreeMap instead of HashMap to get a sorted output
14331433
let mut map = BTreeMap::new();
14341434
for item in &m.items {
1435-
if maybe_ignore_item(item) { continue }
1435+
if item.is_stripped() { continue }
14361436

14371437
let short = item.type_().css_class();
14381438
let myname = match item.name {
@@ -1733,7 +1733,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
17331733
if let clean::DefaultImplItem(..) = items[*i].inner {
17341734
return false;
17351735
}
1736-
!maybe_ignore_item(&items[*i])
1736+
!items[*i].is_stripped()
17371737
}).collect::<Vec<usize>>();
17381738

17391739
// the order of item types in the listing
@@ -1902,17 +1902,6 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
19021902
Ok(())
19031903
}
19041904

1905-
fn maybe_ignore_item(it: &clean::Item) -> bool {
1906-
match it.inner {
1907-
clean::StrippedItem(..) => true,
1908-
clean::ModuleItem(ref m) => {
1909-
it.doc_value().is_none() && m.items.is_empty()
1910-
&& it.visibility != Some(clean::Public)
1911-
},
1912-
_ => false,
1913-
}
1914-
}
1915-
19161905
fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<String> {
19171906
let mut stability = vec![];
19181907

@@ -3332,7 +3321,7 @@ fn sidebar_module(fmt: &mut fmt::Formatter, _it: &clean::Item,
33323321
if let clean::DefaultImplItem(..) = it.inner {
33333322
false
33343323
} else {
3335-
!maybe_ignore_item(it) && !it.is_stripped() && it.type_() == myty
3324+
!it.is_stripped() && it.type_() == myty
33363325
}
33373326
}) {
33383327
let (short, name) = match myty {

src/librustdoc/passes/mod.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,12 @@ impl<'a> fold::DocFolder for Stripper<'a> {
145145
self.fold_item_recur(i)
146146
};
147147

148-
i.and_then(|i| {
149-
match i.inner {
150-
// emptied modules have no need to exist
151-
clean::ModuleItem(ref m)
152-
if m.items.is_empty() &&
153-
i.doc_value().is_none() => None,
154-
_ => {
155-
if self.update_retained {
156-
self.retained.insert(i.def_id);
157-
}
158-
Some(i)
159-
}
148+
if let Some(ref i) = i {
149+
if self.update_retained {
150+
self.retained.insert(i.def_id);
160151
}
161-
})
152+
}
153+
i
162154
}
163155
}
164156

src/test/rustdoc/empty-mod-private.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-tidy-linelength
12+
// compile-flags: --no-defaults --passes collapse-docs --passes unindent-comments --passes strip-priv-imports
13+
14+
// @has 'empty_mod_private/index.html' '//a[@href="foo/index.html"]' 'foo'
15+
// @has 'empty_mod_private/sidebar-items.js' 'foo'
16+
// @matches 'empty_mod_private/foo/index.html' '//h1' 'Module empty_mod_private::foo'
17+
mod foo {}
18+
19+
// @has 'empty_mod_private/index.html' '//a[@href="bar/index.html"]' 'bar'
20+
// @has 'empty_mod_private/sidebar-items.js' 'bar'
21+
// @matches 'empty_mod_private/bar/index.html' '//h1' 'Module empty_mod_private::bar'
22+
mod bar {
23+
// @has 'empty_mod_private/bar/index.html' '//a[@href="baz/index.html"]' 'baz'
24+
// @has 'empty_mod_private/bar/sidebar-items.js' 'baz'
25+
// @matches 'empty_mod_private/bar/baz/index.html' '//h1' 'Module empty_mod_private::bar::baz'
26+
mod baz {}
27+
}

src/test/rustdoc/empty-mod-public.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// @has 'empty_mod_public/index.html' '//a[@href="foo/index.html"]' 'foo'
12+
// @has 'empty_mod_public/sidebar-items.js' 'foo'
13+
// @matches 'empty_mod_public/foo/index.html' '//h1' 'Module empty_mod_public::foo'
14+
pub mod foo {}
15+
16+
// @has 'empty_mod_public/index.html' '//a[@href="bar/index.html"]' 'bar'
17+
// @has 'empty_mod_public/sidebar-items.js' 'bar'
18+
// @matches 'empty_mod_public/bar/index.html' '//h1' 'Module empty_mod_public::bar'
19+
pub mod bar {
20+
// @has 'empty_mod_public/bar/index.html' '//a[@href="baz/index.html"]' 'baz'
21+
// @has 'empty_mod_public/bar/sidebar-items.js' 'baz'
22+
// @matches 'empty_mod_public/bar/baz/index.html' '//h1' 'Module empty_mod_public::bar::baz'
23+
pub mod baz {}
24+
}

0 commit comments

Comments
 (0)