Skip to content

Commit 480ac69

Browse files
Rollup merge of #111997 - GuillaumeGomez:re-export-doc-hidden-macros, r=notriddle
Fix re-export of doc hidden macro not showing up It's part of the follow-up of #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`
2 parents cd8132b + 898dfc6 commit 480ac69

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

src/librustdoc/clean/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,8 @@ fn clean_use_statement_inner<'tcx>(
25922592
} else {
25932593
if inline_attr.is_none()
25942594
&& let Res::Def(DefKind::Mod, did) = path.res
2595-
&& !did.is_local() && did.is_crate_root()
2595+
&& !did.is_local()
2596+
&& did.is_crate_root()
25962597
{
25972598
// if we're `pub use`ing an extern crate root, don't inline it unless we
25982599
// were specifically asked for it

src/librustdoc/visit_ast.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,27 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
305305
return false;
306306
}
307307

308-
if !self.view_item_stack.insert(res_did) {
308+
let is_bang_macro = matches!(
309+
tcx.hir().get_by_def_id(res_did),
310+
Node::Item(&hir::Item { kind: hir::ItemKind::Macro(_, MacroKind::Bang), .. })
311+
);
312+
313+
if !self.view_item_stack.insert(res_did) && !is_bang_macro {
309314
return false;
310315
}
311316

312317
let ret = match tcx.hir().get_by_def_id(res_did) {
318+
// Bang macros are handled a bit on their because of how they are handled by the
319+
// compiler. If they have `#[doc(hidden)]` and the re-export doesn't have
320+
// `#[doc(inline)]`, then we don't inline it.
321+
Node::Item(_)
322+
if is_bang_macro
323+
&& !please_inline
324+
&& renamed.is_some()
325+
&& self.cx.tcx.is_doc_hidden(ori_res_did) =>
326+
{
327+
return false;
328+
}
313329
Node::Item(&hir::Item { kind: hir::ItemKind::Mod(ref m), .. }) if glob => {
314330
let prev = mem::replace(&mut self.inlining, true);
315331
for &i in m.item_ids {

tests/rustdoc/reexport-doc-hidden.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ macro_rules! foo {
2121
() => {};
2222
}
2323

24-
// This is a bug: https://github.com/rust-lang/rust/issues/59368
25-
// @!has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
24+
// @has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
2625
pub use crate::foo as Macro;

tests/rustdoc/reexport-hidden-macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

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

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

18-
/// not displayed
1919
pub use crate::foo as Macro;
2020
/// Displayed
2121
#[doc(inline)]
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// This test ensures that all re-exports of doc hidden elements are displayed.
2+
3+
#![crate_name = "foo"]
4+
5+
#[doc(hidden)]
6+
pub struct Bar;
7+
8+
#[macro_export]
9+
#[doc(hidden)]
10+
macro_rules! foo {
11+
() => {};
12+
}
13+
14+
// @has 'foo/index.html'
15+
// @has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
16+
pub use crate::foo as Macro;
17+
// @has - '//*[@id="reexport.Macro2"]/code' 'pub use crate::foo as Macro2;'
18+
pub use crate::foo as Macro2;
19+
// @has - '//*[@id="reexport.Boo"]/code' 'pub use crate::Bar as Boo;'
20+
pub use crate::Bar as Boo;
21+
// @has - '//*[@id="reexport.Boo2"]/code' 'pub use crate::Bar as Boo2;'
22+
pub use crate::Bar as Boo2;
23+
24+
pub fn fofo() {}
25+
26+
// @has - '//*[@id="reexport.f1"]/code' 'pub use crate::fofo as f1;'
27+
pub use crate::fofo as f1;
28+
// @has - '//*[@id="reexport.f2"]/code' 'pub use crate::fofo as f2;'
29+
pub use crate::fofo as f2;
30+
31+
pub mod sub {
32+
// @has 'foo/sub/index.html'
33+
// @has - '//*[@id="reexport.Macro"]/code' 'pub use crate::foo as Macro;'
34+
pub use crate::foo as Macro;
35+
// @has - '//*[@id="reexport.Macro2"]/code' 'pub use crate::foo as Macro2;'
36+
pub use crate::foo as Macro2;
37+
38+
// @has - '//*[@id="reexport.f1"]/code' 'pub use crate::fofo as f1;'
39+
pub use crate::fofo as f1;
40+
// @has - '//*[@id="reexport.f2"]/code' 'pub use crate::fofo as f2;'
41+
pub use crate::fofo as f2;
42+
}

0 commit comments

Comments
 (0)