diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-12-04 20:46:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-04 20:46:10 +0100 |
| commit | baa3f96b424efa3396d61abd997f74f2537fa530 (patch) | |
| tree | 11468bfeca2ab0a3d68a043321a4ade8fbc71a54 /src/librustdoc/html | |
| parent | 89ed7fc040928799ecd8f70a3a967e6799bf99dd (diff) | |
| parent | 8e53edb2ece6cc6ab6715fef5b3332ae8ffee8a2 (diff) | |
| download | rust-baa3f96b424efa3396d61abd997f74f2537fa530.tar.gz rust-baa3f96b424efa3396d61abd997f74f2537fa530.zip | |
Rollup merge of #118600 - GuillaumeGomez:fields-heading, r=notriddle
[rustdoc] Don't generate the "Fields" heading if there is no field displayed Fixes https://github.com/rust-lang/rust/issues/118195. If no field is displayed, we should not generate the `Fields` heading in enum struct variants. r? ``@notriddle``
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 9 |
1 files changed, 8 insertions, 1 deletions
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("</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. |
