Don't generate the "Fields" heading if there is no field displayed

This commit is contained in:
Guillaume Gomez 2023-12-04 12:12:13 +01:00
parent cf8d81213c
commit 1c556bbed4

View File

@ -1737,7 +1737,14 @@ fn item_variants(
w.write_str("</h3></section>"); w.write_str("</h3></section>");
let heading_and_fields = match &variant_data.kind { 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) => { clean::VariantKind::Tuple(fields) => {
// Documentation on tuple variant fields is rare, so to reduce noise we only emit // Documentation on tuple variant fields is rare, so to reduce noise we only emit
// the section if at least one field is documented. // the section if at least one field is documented.