Skip to content

Commit

Permalink
Rollup merge of rust-lang#111997 - GuillaumeGomez:re-export-doc-hidde…
Browse files Browse the repository at this point in the history
…n-macros, r=notriddle

Fix re-export of doc hidden macro not showing up

It's part of the follow-up of rust-lang#109697.

Re-exports of doc hidden macros should be visible. It was the only kind of re-export of doc hidden item that didn't show up.

r? `@notriddle`
  • Loading branch information
GuillaumeGomez committed May 27, 2023
2 parents cd8132b + 898dfc6 commit 480ac69
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,8 @@ fn clean_use_statement_inner<'tcx>(
} else {
if inline_attr.is_none()
&& let Res::Def(DefKind::Mod, did) = path.res
&& !did.is_local() && did.is_crate_root()
&& !did.is_local()
&& did.is_crate_root()
{
// if we're `pub use`ing an extern crate root, don't inline it unless we
// were specifically asked for it
Expand Down
18 changes: 17 additions & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,27 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
return false;
}

if !self.view_item_stack.insert(res_did) {
let is_bang_macro = matches!(
tcx.hir().get_by_def_id(res_did),
Node::Item(&hir::Item { kind: hir::ItemKind::Macro(_, MacroKind::Bang), .. })
);

if !self.view_item_stack.insert(res_did) && !is_bang_macro {
return false;
}

let ret = match tcx.hir().get_by_def_id(res_did) {
// Bang macros are handled a bit on their because of how they are handled by the
// compiler. If they have `#[doc(hidden)]` and the re-export doesn't have
// `#[doc(inline)]`, then we don't inline it.
Node::Item(_)
if is_bang_macro
&& !please_inline
&& renamed.is_some()
&& self.cx.tcx.is_doc_hidden(ori_res_did) =>
{
return false;
}
Node::Item(&hir::Item { kind: hir::ItemKind::Mod(ref m), .. }) if glob => {
let prev = mem::replace(&mut self.inlining, true);
for &i in m.item_ids {
Expand Down
3 changes: 1 addition & 2 deletions tests/rustdoc/reexport-doc-hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ macro_rules! foo {
() => {};
}

// This is a bug: https://github.com/rust-lang/rust/issues/59368
// @!has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
// @has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
pub use crate::foo as Macro;
2 changes: 1 addition & 1 deletion tests/rustdoc/reexport-hidden-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

// @has 'foo/index.html'
// @has - '//*[@id="main-content"]//a[@href="macro.Macro2.html"]' 'Macro2'
// @has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'

// @has 'foo/macro.Macro2.html'
// @has - '//*[@class="docblock"]' 'Displayed'
Expand All @@ -15,7 +16,6 @@ macro_rules! foo {
() => {};
}

/// not displayed
pub use crate::foo as Macro;
/// Displayed
#[doc(inline)]
Expand Down
42 changes: 42 additions & 0 deletions tests/rustdoc/reexport-of-doc-hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This test ensures that all re-exports of doc hidden elements are displayed.

#![crate_name = "foo"]

#[doc(hidden)]
pub struct Bar;

#[macro_export]
#[doc(hidden)]
macro_rules! foo {
() => {};
}

// @has 'foo/index.html'
// @has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
pub use crate::foo as Macro;
// @has - '//*[@id="reexport.Macro2"]/code' 'pub use crate::foo as Macro2;'
pub use crate::foo as Macro2;
// @has - '//*[@id="reexport.Boo"]/code' 'pub use crate::Bar as Boo;'
pub use crate::Bar as Boo;
// @has - '//*[@id="reexport.Boo2"]/code' 'pub use crate::Bar as Boo2;'
pub use crate::Bar as Boo2;

pub fn fofo() {}

// @has - '//*[@id="reexport.f1"]/code' 'pub use crate::fofo as f1;'
pub use crate::fofo as f1;
// @has - '//*[@id="reexport.f2"]/code' 'pub use crate::fofo as f2;'
pub use crate::fofo as f2;

pub mod sub {
// @has 'foo/sub/index.html'
// @has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
pub use crate::foo as Macro;
// @has - '//*[@id="reexport.Macro2"]/code' 'pub use crate::foo as Macro2;'
pub use crate::foo as Macro2;

// @has - '//*[@id="reexport.f1"]/code' 'pub use crate::fofo as f1;'
pub use crate::fofo as f1;
// @has - '//*[@id="reexport.f2"]/code' 'pub use crate::fofo as f2;'
pub use crate::fofo as f2;
}

0 comments on commit 480ac69

Please sign in to comment.