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: Feature request: Also render the alignment under --show-type-layout #137648

Open
solarretrace opened this issue Feb 26, 2025 · 4 comments
Labels
A-align Area: alignment control (`repr(align(N))` and so on) A-rustdoc-type-layout Area: `rustdoc --show-type-layout` (nightly-only) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@solarretrace
Copy link

Problem

It can be tedious to query the size/alignment of non-generic types (struct, enum, union), which one might want to do for many reasons. Currently, you have to do one of the following:

  1. Compile a crate that has access to the type in question and print the value.
  2. Print the value from the playground, if the crate is available there (which probably wont be the case for anything you're currently working on.)
  3. Inspect compiler output via -Zprint-type-sizes.

All of these have the problem of having to compile code to get an answer.

Proposed Solution

The ideal solution would be to display the size & alignment of types in the cargo doc generated output, so you wouldn't have to build a crate.

Notes

I have no idea how feasible this is, but given that cargo doc already compiles and runs doc tests, it doesn't seem unreasonable.

@solarretrace solarretrace added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Feb 26, 2025
@ehuss ehuss transferred this issue from rust-lang/cargo Feb 26, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 26, 2025
@ehuss
Copy link
Contributor

ehuss commented Feb 26, 2025

Does --show-type-layout work for you?

@fmease fmease added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. A-rustdoc-type-layout Area: `rustdoc --show-type-layout` (nightly-only) C-enhancement Category: An issue proposing an enhancement or a PR with one. C-feature-request Category: A feature request, i.e: not implemented / a PR. A-align Area: alignment control (`repr(align(N))` and so on) and removed C-feature-request Category: A feature request, i.e: not implemented / a PR. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 26, 2025
@fmease fmease changed the title Display size_of::<T>() value in generated docs rustdoc: Feature request: Also render the alignment under --show-type-layout Feb 26, 2025
@fmease
Copy link
Member

fmease commented Feb 26, 2025

Well, I guess --show-type-layout doesn't render alignments at the time of writing, only sizes.

@fmease fmease removed the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Feb 26, 2025
@solarretrace
Copy link
Author

It's certainly a step in the right direction. The only problem being that it's not a default option, so if docs weren't built with --show-type-layout, you still have to download the crate and generate the docs for it, (which is the tedium I am trying to avoid.)

@solarretrace
Copy link
Author

Thinking about it a bit more, and I'm realizing that this may actually be the best I can hope for, just because size & alignment don't depend only on the compiler version, but also the compile target -- which would preclude this from just being useful as only size + alignment. Tabulating size + alignment for different platforms seems like a much larger request, so I suppose I'll just have to take what we have...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-align Area: alignment control (`repr(align(N))` and so on) A-rustdoc-type-layout Area: `rustdoc --show-type-layout` (nightly-only) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants