Skip to content

Commit 5f5e6f1

Browse files
Render missing fields in tuple struct/enum as /* private fields */
1 parent b72460f commit 5f5e6f1

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

src/librustdoc/html/render/print_item.rs

+30-14
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,12 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>(
12261226
s: &'a [clean::Item],
12271227
) -> impl fmt::Display + 'a + Captures<'cx> {
12281228
display_fn(|f| {
1229+
if s.iter()
1230+
.all(|field| matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))))
1231+
{
1232+
return f.write_str("/* private fields */");
1233+
}
1234+
12291235
for (i, ty) in s.iter().enumerate() {
12301236
if i > 0 {
12311237
f.write_str(", ")?;
@@ -1838,21 +1844,31 @@ fn render_struct(
18381844
}
18391845
Some(CtorKind::Fn) => {
18401846
w.write_str("(");
1841-
for (i, field) in fields.iter().enumerate() {
1842-
if i > 0 {
1843-
w.write_str(", ");
1844-
}
1845-
match *field.kind {
1846-
clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"),
1847-
clean::StructFieldItem(ref ty) => {
1848-
write!(
1849-
w,
1850-
"{}{}",
1851-
visibility_print_with_space(field.visibility(tcx), field.item_id, cx),
1852-
ty.print(cx),
1853-
)
1847+
if fields.iter().all(|field| {
1848+
matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))
1849+
}) {
1850+
write!(w, "/* private fields */");
1851+
} else {
1852+
for (i, field) in fields.iter().enumerate() {
1853+
if i > 0 {
1854+
w.write_str(", ");
1855+
}
1856+
match *field.kind {
1857+
clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"),
1858+
clean::StructFieldItem(ref ty) => {
1859+
write!(
1860+
w,
1861+
"{}{}",
1862+
visibility_print_with_space(
1863+
field.visibility(tcx),
1864+
field.item_id,
1865+
cx
1866+
),
1867+
ty.print(cx),
1868+
)
1869+
}
1870+
_ => unreachable!(),
18541871
}
1855-
_ => unreachable!(),
18561872
}
18571873
}
18581874
w.write_str(")");
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![crate_name = "foo"]
22

33
// @has foo/struct.Foo.html '//pre[@class="rust item-decl"]' \
4-
// 'pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(_);'
4+
// 'pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>('
55
pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(T);

tests/rustdoc/const-generics/const-generics-docs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<const N: usize> Trait<N> for [u8; N] {}
3333
// @has foo/struct.Foo.html '//pre[@class="rust item-decl"]' \
3434
// 'pub struct Foo<const N: usize> where u8: Trait<N>'
3535
pub struct Foo<const N: usize> where u8: Trait<N>;
36-
// @has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar<T, const N: usize>(_)'
36+
// @has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar<T, const N: usize>('
3737
pub struct Bar<T, const N: usize>([T; N]);
3838

3939
// @has foo/struct.Foo.html '//*[@id="impl-Foo%3CM%3E"]/h3[@class="code-header"]' 'impl<const M: usize> Foo<M>where u8: Trait<M>'
@@ -92,7 +92,7 @@ macro_rules! define_me {
9292
}
9393

9494
// @has foo/struct.Foz.html '//pre[@class="rust item-decl"]' \
95-
// 'pub struct Foz<const N: usize>(_);'
95+
// 'pub struct Foz<const N: usize>(/* private fields */);'
9696
define_me!(Foz<N>);
9797

9898
trait Q {

tests/rustdoc/issue-88600.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ pub struct S;
88

99
// @has issue_88600/enum.FooEnum.html
1010
pub enum FooEnum {
11-
// @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(_)'
11+
// @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(/* private fields */)'
1212
// @count - '//*[@id="variant.HiddenTupleItem.field.0"]' 0
1313
HiddenTupleItem(#[doc(hidden)] H),
14-
// @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(_, _)'
14+
// @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(/* private fields */)'
1515
// @count - '//*[@id="variant.MultipleHidden.field.0"]' 0
1616
// @count - '//*[@id="variant.MultipleHidden.field.1"]' 0
1717
MultipleHidden(#[doc(hidden)] H, #[doc(hidden)] H),
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<pre class="rust item-decl"><code>pub struct Simd&lt;T&gt;(_)
1+
<pre class="rust item-decl"><code>pub struct Simd&lt;T&gt;(/* private fields */)
22
<span class="where">where
33
T: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code></pre>

tests/rustdoc/where.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::io::Lines;
44

55
pub trait MyTrait { fn dummy(&self) { } }
66

7-
// @has foo/struct.Alpha.html '//pre' "pub struct Alpha<A>(_) where A: MyTrait"
8-
pub struct Alpha<A>(A) where A: MyTrait;
7+
// @has foo/struct.Alpha.html '//pre' "pub struct Alpha<A>where A: MyTrait"
8+
pub struct Alpha<A> where A: MyTrait { a: A }
99
// @has foo/trait.Bravo.html '//pre' "pub trait Bravo<B>where B: MyTrait"
1010
pub trait Bravo<B> where B: MyTrait { fn get(&self, B: B); }
1111
// @has foo/fn.charlie.html '//pre' "pub fn charlie<C>()where C: MyTrait"

0 commit comments

Comments
 (0)