Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't print "private fields" on empty tuple structs #118192

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 */");
}
Expand Down Expand Up @@ -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() {
Expand Down
9 changes: 9 additions & 0 deletions tests/rustdoc/issue-118180-empty-tuple-struct.rs
Original file line number Diff line number Diff line change
@@ -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();
Loading