From a21d7713db7c19d126cc4dd38abd56ed73bdb729 Mon Sep 17 00:00:00 2001 From: Kyuuhachi Date: Thu, 23 Nov 2023 01:56:09 +0100 Subject: [PATCH] Don't print "private fields" on empty tuple structs Test for presence rather than absence Remove redundant tests Issues in those parts will likely be caught by other parts of the test suite. --- src/librustdoc/html/render/print_item.rs | 14 +++++++++----- tests/rustdoc/issue-118180-empty-tuple-struct.rs | 9 +++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 tests/rustdoc/issue-118180-empty-tuple-struct.rs diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 8fdbef65135c1..927bec4251e57 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1501,8 +1501,10 @@ 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(..)))) + if !s.is_empty() + && s.iter().all(|field| { + matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))) + }) { return f.write_str("/* private fields */"); } @@ -2275,9 +2277,11 @@ fn render_struct_fields( } Some(CtorKind::Fn) => { w.write_str("("); - if fields.iter().all(|field| { - matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))) - }) { + if !fields.is_empty() + && fields.iter().all(|field| { + matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))) + }) + { write!(w, "/* private fields */"); } else { for (i, field) in fields.iter().enumerate() { diff --git a/tests/rustdoc/issue-118180-empty-tuple-struct.rs b/tests/rustdoc/issue-118180-empty-tuple-struct.rs new file mode 100644 index 0000000000000..bc6ddbe5defad --- /dev/null +++ b/tests/rustdoc/issue-118180-empty-tuple-struct.rs @@ -0,0 +1,9 @@ +// @has issue_118180_empty_tuple_struct/enum.Enum.html +pub enum Enum { + // @has - '//*[@id="variant.Empty"]//h3' 'Empty()' + Empty(), +} + +// @has issue_118180_empty_tuple_struct/struct.Empty.html +// @has - '//pre/code' 'Empty()' +pub struct Empty();