Skip to content

Commit 7b39994

Browse files
Rollup merge of #157838 - qaijuang:rustdoc-hidden-aliased-fields, r=GuillaumeGomez,Urgau
rustdoc: Don't strip hidden items in `AliasedNonLocalStripper` `AliasedNonLocalStripper` currently strips non-local aliased items that are either non-public or `#[doc(hidden)]`. The hidden items are subsequently processed by the `strip-hidden` pass. Because they have already been wrapped as stripped items, that pass removes them instead of retaining them as placeholders. As a result, cross-crate aliased types omit `/* private fields */` and `// some variants omitted`. Handling `#[doc(hidden)]` in `AliasedNonLocalStripper` also means that `--document-hidden-items` cannot display those public fields and variants. This PR leaves hidden-item handling to `strip-hidden`, while `AliasedNonLocalStripper` continues to unconditionally hide non-public items from external types. Fixes #144969. r? @GuillaumeGomez
2 parents d1a2046 + edad264 commit 7b39994

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/librustdoc/passes/strip_aliased_non_local.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ impl DocFolder for NonLocalStripper<'_> {
4747
// FIXME(#125009): Not-local should probably consider same Cargo workspace
4848
if let Some(def_id) = i.def_id()
4949
&& !def_id.is_local()
50-
&& (i.is_doc_hidden()
51-
// Default to *not* stripping items with inherited visibility.
52-
|| i.visibility(self.tcx).is_some_and(|viz| viz != Visibility::Public))
50+
// Default to *not* stripping items with inherited visibility.
51+
&& i.visibility(self.tcx).is_some_and(|viz| viz != Visibility::Public)
5352
{
5453
return Some(strip_item(i));
5554
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
pub struct InlineOne<A> {
2-
pub inline: A
2+
pub inline: A,
3+
#[doc(hidden)]
4+
pub hidden: A,
35
}
46

57
pub type InlineU64 = InlineOne<u64>;
68

79
pub enum GenericEnum<T> {
810
Variant(T),
911
Variant2(T, T),
12+
#[doc(hidden)]
13+
Hidden(T),
1014
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/144969>.
2+
3+
//@ compile-flags: -Z unstable-options --document-hidden-items
4+
//@ aux-build:cross_crate_generic_typedef.rs
5+
6+
#![crate_name = "document_hidden_aliased_items"]
7+
8+
extern crate cross_crate_generic_typedef;
9+
10+
use std::collections::BTreeMap;
11+
12+
//@ has 'document_hidden_aliased_items/type.InlineU64.html'
13+
//@ count - '//*[@class="structfield section-header"]' 2
14+
//@ has - '//pre[@class="rust item-decl"]//code' 'pub hidden'
15+
//@ count - '//pre[@class="rust item-decl"]//code' '/* private fields */' 0
16+
pub type InlineU64 = cross_crate_generic_typedef::InlineOne<u64>;
17+
18+
//@ has 'document_hidden_aliased_items/type.InlineEnum.html'
19+
//@ count - '//*[@class="variant"]' 3
20+
//@ has - '//pre[@class="rust item-decl"]//code' 'Hidden'
21+
//@ count - '//pre[@class="rust item-decl"]//code' '// some variants omitted' 0
22+
pub type InlineEnum = cross_crate_generic_typedef::GenericEnum<i32>;
23+
24+
//@ has 'document_hidden_aliased_items/type.PrivateFields.html'
25+
//@ has - '//*[@class="rust item-decl"]/code' 'struct PrivateFields { /* private fields */ }'
26+
pub type PrivateFields = BTreeMap<u32, String>;

tests/rustdoc-html/typedef-inner-variants.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ pub type HighlyGenericAABB<A, B> = HighlyGenericStruct<A, A, B, B>;
116116
//@ count - '//*[@id="aliased-type"]' 1
117117
//@ count - '//*[@id="variants"]' 0
118118
//@ count - '//*[@id="fields"]' 1
119+
//@ has - '//pre[@class="rust item-decl"]//code' '/* private fields */'
119120
pub use cross_crate_generic_typedef::InlineU64;
120121

121122
//@ has 'inner_variants/type.InlineEnum.html'
122123
//@ count - '//*[@id="aliased-type"]' 1
123124
//@ count - '//*[@id="variants"]' 1
124125
//@ count - '//*[@id="fields"]' 0
125126
//@ count - '//*[@class="variant"]' 2
127+
//@ has - '//pre[@class="rust item-decl"]//code' '// some variants omitted'
126128
pub type InlineEnum = cross_crate_generic_typedef::GenericEnum<i32>;

0 commit comments

Comments
 (0)