From e8bd4ef1e5e9ccbcbc7501300a69dc799e1cd078 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 9 Mar 2023 13:32:07 +0100 Subject: [PATCH 1/2] Don't hide anonymous re-exports but never inline them --- src/librustdoc/visit_ast.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 5bbbff175cf..a96bdbbfe2d 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -223,6 +223,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { ) -> bool { debug!("maybe_inline_local res: {:?}", res); + if renamed == Some(kw::Underscore) { + // We never inline `_` reexports. + return false; + } + if self.cx.output_format.is_json() { return false; } @@ -329,8 +334,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { self.visit_foreign_item_inner(item, None); } } - // If we're inlining, skip private items or item reexported as "_". - _ if self.inlining && (!is_pub || renamed == Some(kw::Underscore)) => {} + // If we're inlining, skip private items. + _ if self.inlining && !is_pub => {} hir::ItemKind::GlobalAsm(..) => {} hir::ItemKind::Use(_, hir::UseKind::ListStem) => {} hir::ItemKind::Use(path, kind) => { From 9b788da2daf8e63dde464e2c0676ac350bccff01 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 9 Mar 2023 13:32:39 +0100 Subject: [PATCH 2/2] Update rustdoc anonymous reexport test and add regression test for #108931 --- tests/rustdoc/anonymous-reexport.rs | 8 +++++-- .../issue-108931-anonymous-reexport.rs | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/rustdoc/issue-108931-anonymous-reexport.rs diff --git a/tests/rustdoc/anonymous-reexport.rs b/tests/rustdoc/anonymous-reexport.rs index 6b884ff14df..839c1a30346 100644 --- a/tests/rustdoc/anonymous-reexport.rs +++ b/tests/rustdoc/anonymous-reexport.rs @@ -4,9 +4,13 @@ // @has 'foo/index.html' // @has - '//*[@id="main-content"]' '' -// We check that the only "h2" present is for "Bla". -// @count - '//*[@id="main-content"]/h2' 1 +// We check that the only "h2" present are "Structs" (for "Bla") and "Re-exports". +// @count - '//*[@id="main-content"]/h2' 2 // @has - '//*[@id="main-content"]/h2' 'Structs' +// @has - '//*[@id="main-content"]/h2' 'Re-exports' +// The 3 re-exports. +// @count - '//*[@id="main-content"]//*[@class="item-table"]//li//code' 3 +// The public struct. // @count - '//*[@id="main-content"]//a[@class="struct"]' 1 mod ext { diff --git a/tests/rustdoc/issue-108931-anonymous-reexport.rs b/tests/rustdoc/issue-108931-anonymous-reexport.rs new file mode 100644 index 00000000000..302f7413398 --- /dev/null +++ b/tests/rustdoc/issue-108931-anonymous-reexport.rs @@ -0,0 +1,21 @@ +// Ensuring that anonymous re-exports are always inlined. + +#![crate_name = "foo"] + +pub mod foo { + pub struct Foo; +} + +mod bar { + pub struct Bar; +} + +// @has 'foo/index.html' +// We check that the only "h2" present are "Re-exports" and "Modules". +// @count - '//*[@id="main-content"]/h2' 2 +// @has - '//*[@id="main-content"]/h2' 'Re-exports' +// @has - '//*[@id="main-content"]/h2' 'Modules' +// @has - '//*[@id="main-content"]//*[@class="item-table"]//li//code' 'pub use foo::Foo as _;' +// @has - '//*[@id="main-content"]//*[@class="item-table"]//li//code' 'pub use bar::Bar as _;' +pub use foo::Foo as _; +pub use bar::Bar as _;