-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-rustdoc-type-layoutArea: `rustdoc --show-type-layout` (nightly-only)Area: `rustdoc --show-type-layout` (nightly-only)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.Relevant to the rustdoc team, which will review and decide on the PR/issue.
Description
#83501 introduced a basic section on layout information, with only one piece of information: the total size of the type. I think one useful but easy extension to this is reporting the size of each variant for an enum.
cc @camelid
Implementation hints
The "Layout" section is rendered in
rust/src/librustdoc/html/render/print_item.rs
Lines 1553 to 1574 in da7ada5
| Ok(ty_layout) => { | |
| writeln!( | |
| w, | |
| "<div class=\"warning\"><p><strong>Note:</strong> Most layout information is \ | |
| completely unstable and may be different between compiler versions and platforms. \ | |
| The only exception is types with certain <code>repr(...)</code> attributes. \ | |
| Please see the Rust Reference’s \ | |
| <a href=\"https://doc.rust-lang.org/reference/type-layout.html\">“Type Layout”</a> \ | |
| chapter for details on type layout guarantees.</p></div>" | |
| ); | |
| if ty_layout.layout.abi.is_unsized() { | |
| writeln!(w, "<p><strong>Size:</strong> (unsized)</p>"); | |
| } else { | |
| let bytes = ty_layout.layout.size.bytes(); | |
| writeln!( | |
| w, | |
| "<p><strong>Size:</strong> {size} byte{pl}</p>", | |
| size = bytes, | |
| pl = if bytes == 1 { "" } else { "s" }, | |
| ); | |
| } | |
| } |
The ty_layout variable is a TyAndLayout. We want to handle the case where ty_layout.layout.variants is Variants::Multiple.In that case we have access to an IndexVec<VariantIdx, Layout>.
- The
Layoutpart will give us the size of the variant - To get the name of the variant, we'll need the
AdtDefstored inTyKind::Adt, which we can hopefully get fromty_layout.ty.kind.
Metadata
Metadata
Assignees
Labels
A-rustdoc-type-layoutArea: `rustdoc --show-type-layout` (nightly-only)Area: `rustdoc --show-type-layout` (nightly-only)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.Relevant to the rustdoc team, which will review and decide on the PR/issue.