Skip to content

Commit 8742619

Browse files
authored
Rollup merge of #42592 - ollie27:rustdoc_empty_modules, r=steveklabnik
rustdoc: Stop stripping empty modules There is no good reason to strip empty modules with no documentation and doing so causes subtle problems. Fixes #42590
2 parents b646ca9 + 7298dab commit 8742619

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
@@ -1334,7 +1334,7 @@ impl Context {
13341334
// these modules are recursed into, but not rendered normally
13351335
// (a flag on the context).
13361336
if !self.render_redirect_pages {
1337-
self.render_redirect_pages = maybe_ignore_item(&item);
1337+
self.render_redirect_pages = item.is_stripped();
13381338
}
13391339

13401340
if item.is_mod() {
@@ -1417,7 +1417,7 @@ impl Context {
14171417
// BTreeMap instead of HashMap to get a sorted output
14181418
let mut map = BTreeMap::new();
14191419
for item in &m.items {
1420-
if maybe_ignore_item(item) { continue }
1420+
if item.is_stripped() { continue }
14211421

14221422
let short = item.type_().css_class();
14231423
let myname = match item.name {
@@ -1718,7 +1718,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
17181718
if let clean::DefaultImplItem(..) = items[*i].inner {
17191719
return false;
17201720
}
1721-
!maybe_ignore_item(&items[*i])
1721+
!items[*i].is_stripped()
17221722
}).collect::<Vec<usize>>();
17231723

17241724
// the order of item types in the listing
@@ -1887,17 +1887,6 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
18871887
Ok(())
18881888
}
18891889

1890-
fn maybe_ignore_item(it: &clean::Item) -> bool {
1891-
match it.inner {
1892-
clean::StrippedItem(..) => true,
1893-
clean::ModuleItem(ref m) => {
1894-
it.doc_value().is_none() && m.items.is_empty()
1895-
&& it.visibility != Some(clean::Public)
1896-
},
1897-
_ => false,
1898-
}
1899-
}
1900-
19011890
fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<String> {
19021891
let mut stability = vec![];
19031892

@@ -3317,7 +3306,7 @@ fn sidebar_module(fmt: &mut fmt::Formatter, _it: &clean::Item,
33173306
if let clean::DefaultImplItem(..) = it.inner {
33183307
false
33193308
} else {
3320-
!maybe_ignore_item(it) && !it.is_stripped() && it.type_() == myty
3309+
!it.is_stripped() && it.type_() == myty
33213310
}
33223311
}) {
33233312
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)