Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Don't generate the "Fields" heading if there is no field displayed
  • Loading branch information
GuillaumeGomez committed Dec 4, 2023
commit 1c556bbed4a02a914c152c96c18c04835338ba83
9 changes: 8 additions & 1 deletion src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,14 @@ fn item_variants(
w.write_str("</h3></section>");

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.
Expand Down