From 1c556bbed4a02a914c152c96c18c04835338ba83 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 4 Dec 2023 12:12:13 +0100 Subject: [PATCH] Don't generate the "Fields" heading if there is no field displayed --- src/librustdoc/html/render/print_item.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 131b1d608e6..ff7ce01e807 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1737,7 +1737,14 @@ fn item_variants( w.write_str(""); let heading_and_fields = match &variant_data.kind { - clean::VariantKind::Struct(s) => Some(("Fields", &s.fields)), + clean::VariantKind::Struct(s) => { + // If there is no field to display, no need to add the heading. + if s.fields.iter().any(|f| !f.is_doc_hidden()) { + Some(("Fields", &s.fields)) + } else { + None + } + } clean::VariantKind::Tuple(fields) => { // Documentation on tuple variant fields is rare, so to reduce noise we only emit // the section if at least one field is documented.