Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: hide
#[repr]
if it isn't part of the public ABI #116882base: master
Are you sure you want to change the base?
rustdoc: hide
#[repr]
if it isn't part of the public ABI #116882Changes from all commits
dc27ca1
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I think I'd go for
any
in both cases.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.
@RalfJung, does it sound good to you as well to consider the
repr
public if there exists at least one struct field that is public (there might be private and hidden ones) (if we have a struct) or if there exists at least one non-hidden enum variant (if we have an enum)? (With the extra rule that empty structs and enums also render therepr
public).Or should all fields (current version of this PR) and enum variants be public for the
repr
to be public?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.
Usually for structs, if there is at least one private field then we say you can't rely on the struct staying how it is. For instance if your
repr(transparent)
relies on another type being a ZST and that type has at least one private field, we warn about that (and we eventually want to make that an error).So I'd say the same should go for the repr. If any field is private, then the repr is (by default) private.
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.
Thanks, that makes sense! What about enum variants? Can users still make certain assumptions about the repr of an enum if some but not all of its variants are
private orhidden?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.
There's no such things as private enum variants (unfortunately).
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.
Here is an example of what goes wrong if you show repr on a struct with doc(hidden) field.
Rustdoc purports a repr(C) struct in which the first byte is
first
, the second byte isthird
, and some other fields follow. Given the Rust-like syntax in which rustdoc shows #[repr(C)], this feels misleading. For a struct that is actually this:one would expect they can cast
&Struct
to&[u8; 2]
and readfirst
andthird
from it. If they do that in this case though, they get UB from looking at a padding byte.I think this would be a useful bar to keep in mind as a minimum desirable property; rustdoc should not show a repr in such a way that misleads reader about reality. That does not necessarily need to mean hiding such reprs, though that might be the most expedient path forward. Alternatively rustdoc could be more discerning about placing the /*private field*/ comment in between the correct fields when there is a repr.
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.
Hmm, do we already track this in a GitHub issue? With the introduction of
core::mem::offset_of
, it feels like we should up the priority of this issue. If I remember correctly, it'd need quite a bit of rewiring inside rustdoc to render/* private field */
in the correct order forrepr(C)
structs since those fields are stripped early at the moment.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.
RalfJung, re taking
doc(hidden)
on variants into account when computing the visibility of arepr
, I've included that in the heuristic to hide therepr(u8)
oncore::ffi::c_void
whichhasconsists of twodoc(hidden)
enum 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.
Sounds to me then like we'd want to hide the
repr
as soon as there is any hidden field (just like we hide it as soon as there is any private field) -- both for struct and enum (and union).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.
Seems like there is more to discuss. I'll add it to the next rustdoc team meeting agenda.