Skip to content

Commit 0d6749c

Browse files
authored
Rollup merge of #112178 - GuillaumeGomez:fix-inline-private-intermediate, r=notriddle
Fix bug where private item with intermediate doc hidden re-export was not inlined This fixes this bug: ```rust mod private { /// Original. pub struct Bar3; } /// Hidden. #[doc(hidden)] pub use crate::private::Bar3; /// Visible. pub use self::Bar3 as Reexport; ``` In this case, `private::Bar3` should be inlined and renamed `Reexport` but instead we have: ``` pub use self::Bar3 as Reexport; ``` and no links. There were actually two issues: the first one is that we forgot to check if the next intermediate re-export was doc hidden. The second was that we made the `#[doc(hidden)]` attribute inheritable, which shouldn't be possible. r? `@notriddle`
2 parents cbc3e3f + d029800 commit 0d6749c

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

src/librustdoc/clean/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,8 @@ fn get_all_import_attributes<'hir>(
21802180
// This is the "original" reexport so we get all its attributes without filtering them.
21812181
attrs = import_attrs.iter().map(|attr| (Cow::Borrowed(attr), Some(def_id))).collect();
21822182
first = false;
2183-
} else {
2183+
// We don't add attributes of an intermediate re-export if it has `#[doc(hidden)]`.
2184+
} else if !cx.tcx.is_doc_hidden(def_id) {
21842185
add_without_unwanted_attributes(&mut attrs, import_attrs, is_inline, Some(def_id));
21852186
}
21862187
}

src/librustdoc/visit_ast.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
246246
glob: bool,
247247
please_inline: bool,
248248
) -> bool {
249-
debug!("maybe_inline_local res: {:?}", res);
249+
debug!("maybe_inline_local (renamed: {renamed:?}) res: {res:?}");
250250

251251
if renamed == Some(kw::Underscore) {
252252
// We never inline `_` reexports.
@@ -308,6 +308,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
308308
.cache
309309
.effective_visibilities
310310
.is_directly_public(tcx, item_def_id.to_def_id()) &&
311+
!tcx.is_doc_hidden(item_def_id) &&
311312
!inherits_doc_hidden(tcx, item_def_id, None)
312313
{
313314
// The imported item is public and not `doc(hidden)` so no need to inline it.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This test ensures that if a private item is re-exported with an intermediate
2+
// `#[doc(hidden)]` re-export, it'll still be inlined (and not include any attribute
3+
// from the doc hidden re-export.
4+
5+
#![crate_name = "foo"]
6+
7+
// @has 'foo/index.html'
8+
// There should only be one struct displayed.
9+
// @count - '//*[@id="main-content"]/*[@class="small-section-header"]' 1
10+
// @has - '//*[@id="main-content"]/*[@class="small-section-header"]' 'Structs'
11+
// @has - '//*[@id="main-content"]//a[@href="struct.Reexport.html"]' 'Reexport'
12+
// @has - '//*[@id="main-content"]//*[@class="desc docblock-short"]' 'Visible. Original.'
13+
14+
mod private {
15+
/// Original.
16+
pub struct Bar3;
17+
}
18+
19+
/// Hidden.
20+
#[doc(hidden)]
21+
pub use crate::private::Bar3;
22+
/// Visible.
23+
pub use self::Bar3 as Reexport;

tests/rustdoc/reexport-attr-merge.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ pub use Foo1 as Foo2;
1919
// First we ensure that only the reexport `Bar2` and the inlined struct `Bar`
2020
// are inlined.
2121
// @count - '//a[@class="struct"]' 2
22-
// Then we check that both `cfg` are displayed.
22+
// Then we check that `cfg` is displayed for base item, but not for intermediate re-exports.
2323
// @has - '//*[@class="stab portability"]' 'foo'
24-
// @has - '//*[@class="stab portability"]' 'bar'
24+
// @!has - '//*[@class="stab portability"]' 'bar'
2525
// And finally we check that the only element displayed is `Bar`.
2626
// @has - '//a[@class="struct"]' 'Bar'
2727
#[doc(inline)]

0 commit comments

Comments
 (0)