Skip to content

Commit 6ef07c2

Browse files
authoredMar 10, 2023
Rollup merge of #108936 - GuillaumeGomez:rustdoc-anonymous-reexport, r=notriddle
Rustdoc: don't hide anonymous reexport Fixes #108931. From #108931, it appears that having anonymous re-exports for traits is actually used in some places, so instead of hiding them automatically, we should prevent them to be ever inlined. r? `@notriddle`
2 parents 4bd32ac + 9b788da commit 6ef07c2

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed
 

‎src/librustdoc/visit_ast.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
224224
) -> bool {
225225
debug!("maybe_inline_local res: {:?}", res);
226226

227+
if renamed == Some(kw::Underscore) {
228+
// We never inline `_` reexports.
229+
return false;
230+
}
231+
227232
if self.cx.output_format.is_json() {
228233
return false;
229234
}
@@ -346,8 +351,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
346351
self.visit_foreign_item_inner(item, None);
347352
}
348353
}
349-
// If we're inlining, skip private items or item reexported as "_".
350-
_ if self.inlining && (!is_pub || renamed == Some(kw::Underscore)) => {}
354+
// If we're inlining, skip private items.
355+
_ if self.inlining && !is_pub => {}
351356
hir::ItemKind::GlobalAsm(..) => {}
352357
hir::ItemKind::Use(_, hir::UseKind::ListStem) => {}
353358
hir::ItemKind::Use(path, kind) => {

‎tests/rustdoc/anonymous-reexport.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
// @has 'foo/index.html'
66
// @has - '//*[@id="main-content"]' ''
7-
// We check that the only "h2" present is for "Bla".
8-
// @count - '//*[@id="main-content"]/h2' 1
7+
// We check that the only "h2" present are "Structs" (for "Bla") and "Re-exports".
8+
// @count - '//*[@id="main-content"]/h2' 2
99
// @has - '//*[@id="main-content"]/h2' 'Structs'
10+
// @has - '//*[@id="main-content"]/h2' 'Re-exports'
11+
// The 3 re-exports.
12+
// @count - '//*[@id="main-content"]//*[@class="item-table"]//li//code' 3
13+
// The public struct.
1014
// @count - '//*[@id="main-content"]//a[@class="struct"]' 1
1115

1216
mod ext {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Ensuring that anonymous re-exports are always inlined.
2+
3+
#![crate_name = "foo"]
4+
5+
pub mod foo {
6+
pub struct Foo;
7+
}
8+
9+
mod bar {
10+
pub struct Bar;
11+
}
12+
13+
// @has 'foo/index.html'
14+
// We check that the only "h2" present are "Re-exports" and "Modules".
15+
// @count - '//*[@id="main-content"]/h2' 2
16+
// @has - '//*[@id="main-content"]/h2' 'Re-exports'
17+
// @has - '//*[@id="main-content"]/h2' 'Modules'
18+
// @has - '//*[@id="main-content"]//*[@class="item-table"]//li//code' 'pub use foo::Foo as _;'
19+
// @has - '//*[@id="main-content"]//*[@class="item-table"]//li//code' 'pub use bar::Bar as _;'
20+
pub use foo::Foo as _;
21+
pub use bar::Bar as _;

0 commit comments

Comments
 (0)
Please sign in to comment.