Open
Description
If a struct has some public fields and some non-public fields, // some fields omitted
is displayed at the end of the declaration shown by rustdoc. Rustdoc also shows attributes on the declaration, such as #[repr(C)]
.
This is actively misleading for #[repr(C)]
types. If a private type is before any public types, then the struct as displayed suggests that the public fields are at the prefix of the struct, and thus have defined offsets smaller than where they actually are.
Example:
#[repr(C)]
#[derive(Debug, Eq, PartialEq, Hash)]
pub struct ThinData<Head, SliceItem> {
length: usize,
pub head: Head,
pub slice: [SliceItem],
}
There are two obvious potential solutions:
- Put
// some fields omitted
in the correct place(s) among public fields for#[repr(C)]
types, or - Don't display
#[repr(C)]
for types with some fields omitted.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
#[repr(transparent)]
where the field is non-public #90435unaligned_references
#82523RwLockReadGuard<T: ?Sized>
. #101081dtolnay commentedon Feb 5, 2023
Workaround:
#[cfg_attr(not(doc), repr(C))]
can be used to manually hide the attribute from documentation.I agree rustdoc is incorrect by showing repr(C) on structs with a nonpublic field.
Rollup merge of rust-lang#107680 - dtolnay:docrepr, r=Amanieu
repr
of the aliased type #140739