Skip to content

Eliminate use of #[cfg_attr(not(doc), repr(...))] - #116743

Closed
dtolnay wants to merge 1 commit into
rust-lang:masterfrom
dtolnay:notdoctransparent
Closed

Eliminate use of #[cfg_attr(not(doc), repr(...))]#116743
dtolnay wants to merge 1 commit into
rust-lang:masterfrom
dtolnay:notdoctransparent

Conversation

@dtolnay

@dtolnaydtolnay commented Oct 14, 2023

Copy link
Copy Markdown
Member

This PR reverts #107680 and some pre-existing occurrences of the same pattern.

The issue that prompted the workaround, #90435, has since been fixed by #115439.

Tested by running x.py doc --stage 1 library/std and confirming that std/path/struct.PathBuf.html contains no visible #[repr(transparent)]. Note that x.py doc library/std runs using stage0 rustdoc (maybe depending on config.toml?) and will continue to render a #[repr(transparent)], but that's okay and shouldn't make it into official documentation of the 1.75.0 release.

Blocked on #116882

@rustbot

Copy link
Copy Markdown
Collaborator

r? @m-ou-se

(rustbot has picked a reviewer for you, use r? to override)

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 14, 2023
@rustbot

Copy link
Copy Markdown
Collaborator

Portable SIMD is developed in its own repository. If possible, consider making this change to rust-lang/portable-simd instead.

cc @calebzulawski, @programmerjake

@dtolnay

Copy link
Copy Markdown
MemberAuthor

library/portable-simd/crates/core_simd/src/masks.rs change extracted to rust-lang/portable-simd#370.

@fmeasefmease left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can't land as is, I'm afraid. My PR only affects the transparent representation. I've totally overlooked non-transparent reprs but in my defense nobody has mentioned this either over at the issue and the PR.

It does make sense though to extend this behavior to other reprs 🤦. I will open a PR as soon as possible.

CC @RalfJung

#[doc = include_str!("c_void.md")]
#[lang = "c_void"]
#[cfg_attr(not(doc), repr(u8))] // work around https://github.com/rust-lang/rust/issues/90435
#[repr(u8)]

@fmeasefmeaseOct 14, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unfortunately, this will still show up in the docs, my PR only affects repr(transparent). Further, it doesn't take into account #[doc(hidden)] (in this case on variants). Arguably, rustdoc should hide #[repr(u8)] and respect doc(hidden). I can send a PR right away.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we keep non-transparent reprs for enums though? It's useful, especially repr(c) ones for FFI.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For sure, but in this case both variants are doc(hidden). I plan on hiding those reprs if all variants are hidden.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good idea!

not(windows),
))]
#[cfg_attr(not(doc), repr(C))] // work around https://github.com/rust-lang/rust/issues/66401
#[repr(C)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similarly, repr(C) is still going to show up in the docs :| Let me update rustdoc to handle that as well.

@dtolnaydtolnay added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 15, 2023
fmease added a commit to fmease/rust that referenced this pull request Nov 25, 2023
…rk-Simulacrum
Request that rust-analyzer changes are sent upstream first if possible
This automates `@lnicola's` comment rust-lang#118253 (comment).
Rustbot will write a comment similar to rust-lang#116743 (comment).
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 25, 2023
Rollup merge of rust-lang#118255 - dtolnay:mentionsrustanalyzer, r=Mark-Simulacrum
Request that rust-analyzer changes are sent upstream first if possible
This automates `@lnicola's` comment rust-lang#118253 (comment).
Rustbot will write a comment similar to rust-lang#116743 (comment).
@dtolnay

Copy link
Copy Markdown
MemberAuthor

I'll rebase and reopen if #116882 makes progress.

@dtolnaydtolnay closed this Jan 21, 2024
@dtolnay
dtolnay deleted the notdoctransparent branch January 21, 2024 04:17
@dtolnaydtolnay added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-repr Area: the `#[repr(stuff)]` attribute and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Jan 14, 2025
rust-borsBot added a commit that referenced this pull request Jun 16, 2025
…c, r=<try>
rustdoc: hide `#[repr]` if it isn't part of the public ABI
Follow-up to #115439.
Unblocks #116743, CC `@dtolnay.`
Fixes#128364.
Fixes#137440.
Only display the representation `#[repr(REPR)]` (where `REPR` is not `Rust` or `transparent`) of a given type if the type is not `#[non_exhaustive]`, if none of its variants (incl. the synthetic variants of structs) are `#[doc(hidden)]` or `#[non_exhaustive]` and if all of its fields are public and not `#[doc(hidden)]` since it's likely not meant to be considered part of the public ABI otherwise. `--document-{private,hidden}-items` works as expected in this context, too.
Moreover, we now also factor in the presence of `#[doc(hidden)]` and of `#[non_exhaustive]` when checking whether to show `repr(transparent)` or not.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 25, 2025
…pr-heuristic, r=rustdoc
rustdoc: hide `#[repr]` if it isn't part of the public ABI
> [!IMPORTANT]
> Temporarily stacked on top of PR rust-lang#146527; only the last commit is relevant!
Follow-up to rust-lang#115439.
Unblocks rust-lang#116743, CC `@dtolnay.`
Fixesrust-lang#66401.
Fixesrust-lang#128364.
Fixesrust-lang#137440.
Only display the representation `#[repr(REPR)]` (where `REPR` is not `Rust` or `transparent`) of a given type if none of its variants (incl. the synthetic variants of structs) are `#[doc(hidden)]` and all of its fields are public and not `#[doc(hidden)]` since it's likely not meant to be considered part of the public ABI otherwise.
`--document-{private,hidden}-items` works as expected in this context, too.
Moreover, we now also factor in the presence of `#[doc(hidden)]` when checking whether to show `repr(transparent)` or not.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 25, 2025
…pr-heuristic, r=rustdoc
rustdoc: hide `#[repr]` if it isn't part of the public ABI
> [!IMPORTANT]
> Temporarily stacked on top of PR rust-lang#146527; only the last commit is relevant!
Follow-up to rust-lang#115439.
Unblocks rust-lang#116743, CC ``@dtolnay.``
Fixesrust-lang#66401.
Fixesrust-lang#128364.
Fixesrust-lang#137440.
Only display the representation `#[repr(REPR)]` (where `REPR` is not `Rust` or `transparent`) of a given type if none of its variants (incl. the synthetic variants of structs) are `#[doc(hidden)]` and all of its fields are public and not `#[doc(hidden)]` since it's likely not meant to be considered part of the public ABI otherwise.
`--document-{private,hidden}-items` works as expected in this context, too.
Moreover, we now also factor in the presence of `#[doc(hidden)]` when checking whether to show `repr(transparent)` or not.
rust-timer added a commit that referenced this pull request Sep 25, 2025
Rollup merge of #116882 - fmease:rustdoc-generalized-priv-repr-heuristic, r=rustdoc
rustdoc: hide `#[repr]` if it isn't part of the public ABI
> [!IMPORTANT]
> Temporarily stacked on top of PR #146527; only the last commit is relevant!
Follow-up to #115439.
Unblocks #116743, CC ``@dtolnay.``
Fixes#66401.
Fixes#128364.
Fixes#137440.
Only display the representation `#[repr(REPR)]` (where `REPR` is not `Rust` or `transparent`) of a given type if none of its variants (incl. the synthetic variants of structs) are `#[doc(hidden)]` and all of its fields are public and not `#[doc(hidden)]` since it's likely not meant to be considered part of the public ABI otherwise.
`--document-{private,hidden}-items` works as expected in this context, too.
Moreover, we now also factor in the presence of `#[doc(hidden)]` when checking whether to show `repr(transparent)` or not.
github-actionsBot pushed a commit to rust-lang/miri that referenced this pull request Sep 26, 2025
…tic, r=rustdoc
rustdoc: hide `#[repr]` if it isn't part of the public ABI
> [!IMPORTANT]
> Temporarily stacked on top of PR rust-lang/rust#146527; only the last commit is relevant!
Follow-up to rust-lang/rust#115439.
Unblocks rust-lang/rust#116743, CC ``@dtolnay.``
Fixesrust-lang/rust#66401.
Fixesrust-lang/rust#128364.
Fixesrust-lang/rust#137440.
Only display the representation `#[repr(REPR)]` (where `REPR` is not `Rust` or `transparent`) of a given type if none of its variants (incl. the synthetic variants of structs) are `#[doc(hidden)]` and all of its fields are public and not `#[doc(hidden)]` since it's likely not meant to be considered part of the public ABI otherwise.
`--document-{private,hidden}-items` works as expected in this context, too.
Moreover, we now also factor in the presence of `#[doc(hidden)]` when checking whether to show `repr(transparent)` or not.
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 28, 2025
Library: Remove remaining private `#[repr]` workarounds
With rust-lang#116882 finally merged, gating these `repr`s behind cfg `not(doc)` is no longer necessary to achieve a private repr.
Follow up to rust-lang#128046 (that was enabled via rust-lang#115439). With that, rust-lang#116743 is now fully realized at long last.
cc `@dtolnay`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 28, 2025
Library: Remove remaining private `#[repr]` workarounds
With rust-lang#116882 finally merged, gating these `repr`s behind cfg `not(doc)` is no longer necessary to achieve a private repr.
Follow up to rust-lang#128046 (that was enabled via rust-lang#115439). With that, rust-lang#116743 is now fully realized at long last.
cc ``@dtolnay``
rust-timer added a commit that referenced this pull request Sep 28, 2025
Rollup merge of #147095 - fmease:libprivrepr, r=dtolnay
Library: Remove remaining private `#[repr]` workarounds
With #116882 finally merged, gating these `repr`s behind cfg `not(doc)` is no longer necessary to achieve a private repr.
Follow up to #128046 (that was enabled via #115439). With that, #116743 is now fully realized at long last.
cc ``@dtolnay``
github-actionsBot pushed a commit to model-checking/verify-rust-std that referenced this pull request Oct 9, 2025
Library: Remove remaining private `#[repr]` workarounds
With rust-lang#116882 finally merged, gating these `repr`s behind cfg `not(doc)` is no longer necessary to achieve a private repr.
Follow up to rust-lang#128046 (that was enabled via rust-lang#115439). With that, rust-lang#116743 is now fully realized at long last.
cc ``@dtolnay``
Kobzol pushed a commit to Kobzol/rustc_codegen_gcc that referenced this pull request Dec 21, 2025
…tic, r=rustdoc
rustdoc: hide `#[repr]` if it isn't part of the public ABI
> [!IMPORTANT]
> Temporarily stacked on top of PR rust-lang/rust#146527; only the last commit is relevant!
Follow-up to rust-lang/rust#115439.
Unblocks rust-lang/rust#116743, CC ``@dtolnay.``
Fixesrust-lang/rust#66401.
Fixesrust-lang/rust#128364.
Fixesrust-lang/rust#137440.
Only display the representation `#[repr(REPR)]` (where `REPR` is not `Rust` or `transparent`) of a given type if none of its variants (incl. the synthetic variants of structs) are `#[doc(hidden)]` and all of its fields are public and not `#[doc(hidden)]` since it's likely not meant to be considered part of the public ABI otherwise.
`--document-{private,hidden}-items` works as expected in this context, too.
Moreover, we now also factor in the presence of `#[doc(hidden)]` when checking whether to show `repr(transparent)` or not.
Kobzol pushed a commit to Kobzol/rustc_codegen_cranelift that referenced this pull request Dec 29, 2025
…tic, r=rustdoc
rustdoc: hide `#[repr]` if it isn't part of the public ABI
> [!IMPORTANT]
> Temporarily stacked on top of PR rust-lang/rust#146527; only the last commit is relevant!
Follow-up to rust-lang/rust#115439.
Unblocks rust-lang/rust#116743, CC ``@dtolnay.``
Fixesrust-lang/rust#66401.
Fixesrust-lang/rust#128364.
Fixesrust-lang/rust#137440.
Only display the representation `#[repr(REPR)]` (where `REPR` is not `Rust` or `transparent`) of a given type if none of its variants (incl. the synthetic variants of structs) are `#[doc(hidden)]` and all of its fields are public and not `#[doc(hidden)]` since it's likely not meant to be considered part of the public ABI otherwise.
`--document-{private,hidden}-items` works as expected in this context, too.
Moreover, we now also factor in the presence of `#[doc(hidden)]` when checking whether to show `repr(transparent)` or not.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-reprArea: the `#[repr(stuff)]` attributeT-libsRelevant to the library 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

@dtolnay@rustbot@GuillaumeGomez@fmease@m-ou-se