Skip to content
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

Merged
merged 5 commits into from
Sep 8, 2021

Conversation

fee1-dead
Copy link
Member

@fee1-dead fee1-dead commented Jun 13, 2021

Followup of #83501, Fixes #86253.

cc @camelid

@rustbot label A-rustdoc

@rust-highfive
Copy link
Collaborator

r? @ollie27

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 13, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jun 21, 2021
@fee1-dead fee1-dead changed the title Report Layout of enum variants Rustdoc: Report Layout of enum variants Jun 23, 2021
@@ -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() {
Copy link
Member

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.

Copy link
Member Author

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.

src/librustdoc/html/render/print_item.rs Outdated Show resolved Hide resolved
src/librustdoc/html/render/print_item.rs Outdated Show resolved Hide resolved
@jyn514 jyn514 added the requires-nightly This issue requires a nightly compiler in some way. label Jul 8, 2021
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jyn514 jyn514 left a 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

src/test/rustdoc/type-layout.rs Outdated Show resolved Hide resolved
@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 9, 2021
@jyn514 jyn514 assigned jyn514 and unassigned ollie27 Jul 9, 2021
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about Variants::Single?

Copy link
Member Author

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.

@pickfire
Copy link
Contributor

@fee1-dead Do you have a sample screenshot on how it looks like?

@fee1-dead
Copy link
Member Author

@fee1-dead Do you have a sample screenshot on how it looks like?

image

@rustbot label -S-waiting-on-author S-waiting-on-review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 10, 2021
@jyn514
Copy link
Member

jyn514 commented Jul 10, 2021

@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?

@jyn514 jyn514 removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 11, 2021
@jyn514
Copy link
Member

jyn514 commented Aug 30, 2021

@camelid do you have opinions on #86263 (comment) ?

@camelid
Copy link
Member

camelid commented Aug 30, 2021

@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 Option<(DefId, Foo)>, where I have to manually add up its components, try to figure out what niches there are, and estimate alignment. And it gets especially bothersome for types with many variants like clean::Type.

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?

@jyn514
Copy link
Member

jyn514 commented Aug 30, 2021

especially if the type is something like Option<(DefId, Foo)>

👍 makes sense, I hadn't thought about anonymous types. Ok, I think this makes sense then.

@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 31, 2021
// @has type_layout/enum.Variants.html 'Size: '
// @has - '2 bytes'
// @has - '<code>A</code>: 0 bytes'
// @has - '<code>B</code>: 1 byte'
Copy link
Member

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?

Copy link
Member

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.

@camelid camelid added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 2, 2021
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 6, 2021
@camelid
Copy link
Member

camelid commented Sep 6, 2021

Thanks!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 6, 2021

📌 Commit c0451f7 has been approved by camelid

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 6, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 8, 2021
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
@bors bors merged commit 2f2aed1 into rust-lang:master Sep 8, 2021
@rustbot rustbot added this to the 1.57.0 milestone Sep 8, 2021
bors added a commit to rust-lang/rust-analyzer that referenced this pull request May 18, 2023
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.
@fee1-dead fee1-dead deleted the rustdoc-layout-variants branch July 19, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-layout Area: Memory layout of types requires-nightly This issue requires a nightly compiler in some way. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rustdoc: report layout of enum variants