From e160882721c758a1e369a6212f8845abf2dd80d9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 1 Jun 2022 12:24:39 +0200 Subject: [PATCH 1/2] Hide anonymous reexports in generated documentation --- src/librustdoc/visit_ast.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index d57868caf7a..00553d3f007 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -286,8 +286,8 @@ fn visit_item( self.visit_foreign_item(item, None, om); } } - // If we're inlining, skip private items. - _ if self.inlining && !is_pub => {} + // If we're inlining, skip private items or item reexported as "_". + _ if self.inlining && (!is_pub || renamed == Some(kw::Underscore)) => {} hir::ItemKind::GlobalAsm(..) => {} hir::ItemKind::Use(_, hir::UseKind::ListStem) => {} hir::ItemKind::Use(path, kind) => { From 1d12b7eb2992cd40485e638c9dde01bbf194dffb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 1 Jun 2022 12:25:04 +0200 Subject: [PATCH 2/2] Add test for anonymous reexports --- src/test/rustdoc/anonymous-reexport.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/rustdoc/anonymous-reexport.rs diff --git a/src/test/rustdoc/anonymous-reexport.rs b/src/test/rustdoc/anonymous-reexport.rs new file mode 100644 index 00000000000..6b884ff14df --- /dev/null +++ b/src/test/rustdoc/anonymous-reexport.rs @@ -0,0 +1,22 @@ +#![crate_name = "foo"] + +// This test ensures we don't display anonymous (non-inline) re-exports of public items. + +// @has 'foo/index.html' +// @has - '//*[@id="main-content"]' '' +// We check that the only "h2" present is for "Bla". +// @count - '//*[@id="main-content"]/h2' 1 +// @has - '//*[@id="main-content"]/h2' 'Structs' +// @count - '//*[@id="main-content"]//a[@class="struct"]' 1 + +mod ext { + pub trait Foo {} + pub trait Bar {} + pub struct S; +} + +pub use crate::ext::Foo as _; +pub use crate::ext::Bar as _; +pub use crate::ext::S as _; + +pub struct Bla;