-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rustdoc: Report Layout of enum variants #86263
Rustdoc: Report Layout of enum variants #86263
Conversation
r? @ollie27 (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
a6747c4
to
7c87a39
Compare
This comment has been minimized.
This comment has been minimized.
7c87a39
to
4a2e8ad
Compare
4a2e8ad
to
1ab9596
Compare
@@ -1571,6 +1573,38 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) { | |||
pl = if bytes == 1 { "" } else { "s" }, | |||
); | |||
} | |||
if let Variants::Multiple { variants, .. } = &ty_layout.layout.variants { | |||
if !variants.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test what happens for the empty case? Does it show 0 bytes or unsized? I think ideally it would show "uninhabited" or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shows 0 bytes. I think it would be more suitable for a separate PR as a followup of the original PR.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with the test case updated
w.write_str("<p><strong>Size:</strong> "); | ||
write_size_of_layout(w, ty_layout.layout); | ||
writeln!(w, "</p>"); | ||
if let Variants::Multiple { variants, .. } = &ty_layout.layout.variants { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Variants::Single
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it wouldn't matter because its size is already reported previously.
@fee1-dead Do you have a sample screenshot on how it looks like? |
@rustbot label -S-waiting-on-author S-waiting-on-review |
@fee1-dead hmm, that doesn't seem super helpful - I assume those are all 0 because they don't have fields? Could we avoid showing the size in that case and only report it for fields? Actually at that point I'm not really sure how much purpose this serves - why wouldn't the user just look at the size shown for the type in the field? |
@camelid do you have opinions on #86263 (comment) ? |
I find it annoying to have to click on each field's type to try to manually compute its size, especially if the type is something like I think it'd be useful to have a summary of the sizes of each variant. Is that what you were asking about, or was it something else? |
👍 makes sense, I hadn't thought about anonymous types. Ok, I think this makes sense then. |
ae9e562
to
5f1505e
Compare
// @has type_layout/enum.Variants.html 'Size: ' | ||
// @has - '2 bytes' | ||
// @has - '<code>A</code>: 0 bytes' | ||
// @has - '<code>B</code>: 1 byte' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm: this checks that this "text" is in the raw HTML directly, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's odd is I tried @has - '<strong>Size:</strong> 8 bytes
on master on an existing test case, but it failed. I'm not sure why these tests are passing.
5065be6
to
c0451f7
Compare
Thanks! @bors r+ rollup |
📌 Commit c0451f7 has been approved by |
Rollup of 9 pull requests Successful merges: - rust-lang#86263 (Rustdoc: Report Layout of enum variants) - rust-lang#88541 (Add regression test for rust-lang#74400) - rust-lang#88553 (Improve diagnostics for unary plus operators (rust-lang#88276)) - rust-lang#88594 (More symbolic doc aliases) - rust-lang#88648 (Correct “copies” to “moves” in `<Option<T> as From<T>>::from` doc, and other copyediting) - rust-lang#88691 (Add a regression test for rust-lang#88649) - rust-lang#88694 (Drop 1.56 stabilizations from 1.55 release notes) - rust-lang#88712 (Fix docs for `uX::checked_next_multiple_of`) - rust-lang#88726 (Fix typo in `const_generics` replaced with `adt_const_params` note) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Add layout info for enum variant and locals The size of enum variant is what rustdoc shows (rust-lang/rust#86263). I also added layout info for locals since it helps finding size of unnameable types like closures inside other structs or impl traits.
Followup of #83501, Fixes #86253.
cc @camelid
@rustbot label A-rustdoc