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

Document --show-type-layout in the rustdoc book #89164

Merged
merged 4 commits into from
Sep 22, 2021

Conversation

camelid
Copy link
Member

@camelid camelid commented Sep 22, 2021

I also made a few small, related changes as separate commits.

r? @jyn514

@camelid camelid added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. requires-nightly This issue requires a nightly compiler in some way. labels Sep 22, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 22, 2021
@camelid
Copy link
Member Author

camelid commented Sep 22, 2021

See also the discussion on Discord.

src/doc/rustdoc/src/unstable-features.md Show resolved Hide resolved
When this flag is passed, rustdoc will add a "Layout" section at the bottom of
each type's docs page that includes a summary of the type's memory layout as
computed by rustc. For example, rustdoc will show the size in bytes that a value
of that type will take in memory.
Copy link
Member

Choose a reason for hiding this comment

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

Why do you say "for example"? Isn't that the only part of the layout it shows?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it also shows the size of each variant. The things it displays could change later, so I'd rather not have an exhaustive list that needs to be updated.

@@ -1663,7 +1663,7 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
writeln!(
w,
"<div class=\"warning\"><p><strong>Note:</strong> Most layout information is \
completely unstable and may be different between compiler versions and platforms. \
completely unstable and may even differ between compilations. \
Copy link
Member

Choose a reason for hiding this comment

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

How can this be true? The compiler has to be able to depend on the ABI to create dynamic libraries.

Copy link
Member Author

Choose a reason for hiding this comment

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

From the Reference (emphasis mine):

Type layout can be changed with each compilation. Instead of trying to document exactly what is done, we only document what is guaranteed today.

I assume that means that the compiler is free to change layout if your crate is a static library or a binary. Also, there are (future) flags like -Z randomize-layout which would change layout between compilations.

@jyn514
Copy link
Member

jyn514 commented Sep 22, 2021

r=me with CI passing

Thanks for documenting this!

@camelid
Copy link
Member Author

camelid commented Sep 22, 2021

@bors r=jyn514 rollup

@bors
Copy link
Contributor

bors commented Sep 22, 2021

📌 Commit fcb837b has been approved by jyn514

@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 22, 2021
the8472 added a commit to the8472/rust that referenced this pull request Sep 22, 2021
…n514

Document `--show-type-layout` in the rustdoc book

I also made a few small, related changes as separate commits.

r? `@jyn514`
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 22, 2021
Rollup of 8 pull requests

Successful merges:

 - rust-lang#89036 (Fix missing `no_global_oom_handling` cfg-gating)
 - rust-lang#89041 (Work around invalid DWARF bugs for fat LTO)
 - rust-lang#89046 ("Fix" an overflow in byte position math)
 - rust-lang#89127 (Re-enable the `src/test/debuginfo/mutex.rs` test on Windows)
 - rust-lang#89133 (Fix ICE with `--cap-lints=allow` and `-Zfuel=...=0`)
 - rust-lang#89162 (rustc_index: Add some map-like APIs to `IndexVec`)
 - rust-lang#89164 (Document `--show-type-layout` in the rustdoc book)
 - rust-lang#89170 (Disable the leak sanitizer on Macos aarch64 for now)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3cb28de into rust-lang:master Sep 22, 2021
@rustbot rustbot added this to the 1.57.0 milestone Sep 22, 2021
@camelid camelid deleted the show-type-layout-docs branch September 22, 2021 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools 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.

5 participants