Rollup merge of #123116 - chloekek:rustdoc-variant-swap-fields-doc, r=GuillaumeGomez

rustdoc: Swap fields and variant documentations

Previously, the documentation for a variant appeared after the documentation for each of its fields. This was inconsistent with structs and unions, and made little sense on its own; fields are subordinate to variants and should therefore appear later in the documentation.

Before:

![Screenshot of rendered documentation before this patch.](https://github.com/rust-lang/rust/assets/50083900/4c98258e-bdf7-4507-9cf1-fe601407ff11)

After:

![Screenshot of rendered documentation after this patch.](https://github.com/rust-lang/rust/assets/50083900/bd223f92-9b06-4b5a-820e-7a8501bdc0e2)
This commit is contained in:
Guillaume Gomez 2024-03-27 10:13:44 +01:00 committed by GitHub
commit c0945f0c9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1728,6 +1728,8 @@ fn item_variants(
}
w.write_str("</h3></section>");
write!(w, "{}", document(cx, variant, Some(it), HeadingOffset::H4));
let heading_and_fields = match &variant_data.kind {
clean::VariantKind::Struct(s) => {
// If there is no field to display, no need to add the heading.
@ -1789,8 +1791,6 @@ fn item_variants(
}
w.write_str("</div>");
}
write!(w, "{}", document(cx, variant, Some(it), HeadingOffset::H4));
}
write!(w, "</div>");
}