Skip to content

Commit a21d771

Browse files
committed
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.
1 parent 1e9dda7 commit a21d771

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/librustdoc/html/render/print_item.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1501,8 +1501,10 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>(
15011501
s: &'a [clean::Item],
15021502
) -> impl fmt::Display + 'a + Captures<'cx> {
15031503
display_fn(|f| {
1504-
if s.iter()
1505-
.all(|field| matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))))
1504+
if !s.is_empty()
1505+
&& s.iter().all(|field| {
1506+
matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))
1507+
})
15061508
{
15071509
return f.write_str("/* private fields */");
15081510
}
@@ -2275,9 +2277,11 @@ fn render_struct_fields(
22752277
}
22762278
Some(CtorKind::Fn) => {
22772279
w.write_str("(");
2278-
if fields.iter().all(|field| {
2279-
matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))
2280-
}) {
2280+
if !fields.is_empty()
2281+
&& fields.iter().all(|field| {
2282+
matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))
2283+
})
2284+
{
22812285
write!(w, "/* private fields */");
22822286
} else {
22832287
for (i, field) in fields.iter().enumerate() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @has issue_118180_empty_tuple_struct/enum.Enum.html
2+
pub enum Enum {
3+
// @has - '//*[@id="variant.Empty"]//h3' 'Empty()'
4+
Empty(),
5+
}
6+
7+
// @has issue_118180_empty_tuple_struct/struct.Empty.html
8+
// @has - '//pre/code' 'Empty()'
9+
pub struct Empty();

0 commit comments

Comments
 (0)