Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustdoc: don't hide anonymous reexport #108936

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) => {
Expand Down
8 changes: 6 additions & 2 deletions tests/rustdoc/anonymous-reexport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions tests/rustdoc/issue-108931-anonymous-reexport.rs
Original file line number Diff line number Diff line change
@@ -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 _;