Render missing fields in tuple struct/enum as /* private fields */

This commit is contained in:
Michael Goulet 2023-04-24 17:42:39 +00:00 committed by Guillaume Gomez
parent 3767e315ac
commit 1abbd4cd4f
7 changed files with 38 additions and 22 deletions

View file

@ -1315,6 +1315,12 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>(
s: &'a [clean::Item],
) -> impl fmt::Display + 'a + Captures<'cx> {
display_fn(|f| {
if s.iter()
.all(|field| matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))))
{
return f.write_str("/* private fields */");
}
for (i, ty) in s.iter().enumerate() {
if i > 0 {
f.write_str(", ")?;
@ -1936,21 +1942,31 @@ fn render_struct(
}
Some(CtorKind::Fn) => {
w.write_str("(");
for (i, field) in fields.iter().enumerate() {
if i > 0 {
w.write_str(", ");
}
match *field.kind {
clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"),
clean::StructFieldItem(ref ty) => {
write!(
w,
"{}{}",
visibility_print_with_space(field.visibility(tcx), field.item_id, cx),
ty.print(cx),
)
if fields.iter().all(|field| {
matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))
}) {
write!(w, "/* private fields */");
} else {
for (i, field) in fields.iter().enumerate() {
if i > 0 {
w.write_str(", ");
}
match *field.kind {
clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"),
clean::StructFieldItem(ref ty) => {
write!(
w,
"{}{}",
visibility_print_with_space(
field.visibility(tcx),
field.item_id,
cx
),
ty.print(cx),
)
}
_ => unreachable!(),
}
_ => unreachable!(),
}
}
w.write_str(")");

View file

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

View file

@ -33,7 +33,7 @@ impl Trait<{1 + 2}> for u8 {}
// @has foo/struct.Foo.html '//pre[@class="rust item-decl"]' \
// 'pub struct Foo<const N: usize> where u8: Trait<N>'
pub struct Foo<const N: usize> where u8: Trait<N>;
// @has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar<T, const N: usize>(_)'
// @has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar<T, const N: usize>('
pub struct Bar<T, const N: usize>([T; N]);
// @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 {
}
// @has foo/struct.Foz.html '//pre[@class="rust item-decl"]' \
// 'pub struct Foz<const N: usize>(_);'
// 'pub struct Foz<const N: usize>(/* private fields */);'
define_me!(Foz<N>);
trait Q {

View file

@ -8,10 +8,10 @@
// @has issue_88600/enum.FooEnum.html
pub enum FooEnum {
// @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(_)'
// @has - '//*[@id="variant.HiddenTupleItem"]//h3' 'HiddenTupleItem(/* private fields */)'
// @count - '//*[@id="variant.HiddenTupleItem.field.0"]' 0
HiddenTupleItem(#[doc(hidden)] H),
// @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(_, _)'
// @has - '//*[@id="variant.MultipleHidden"]//h3' 'MultipleHidden(/* private fields */)'
// @count - '//*[@id="variant.MultipleHidden.field.0"]' 0
// @count - '//*[@id="variant.MultipleHidden.field.1"]' 0
MultipleHidden(#[doc(hidden)] H, #[doc(hidden)] H),

View file

@ -1,3 +1,3 @@
<pre class="rust item-decl"><code>pub struct Simd&lt;T&gt;(_)
<pre class="rust item-decl"><code>pub struct Simd&lt;T&gt;(/* private fields */)
<span class="where">where
T: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code></pre>

View file

@ -1,3 +1,3 @@
<code>pub struct Alpha&lt;A&gt;(_)
<code>pub struct Alpha&lt;A&gt;(/* private fields */)
<span class="where">where
A: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code>

View file

@ -4,7 +4,7 @@
pub trait MyTrait { fn dummy(&self) { } }
// @has foo/struct.Alpha.html '//pre' "pub struct Alpha<A>(_) where A: MyTrait"
// @has foo/struct.Alpha.html '//pre' "pub struct Alpha<A>(/* private fields */) where A: MyTrait"
// @snapshot alpha_trait_decl - '//*[@class="rust item-decl"]/code'
pub struct Alpha<A>(A) where A: MyTrait;
// @has foo/trait.Bravo.html '//pre' "pub trait Bravo<B>where B: MyTrait"