Skip to content

Rustdoc: maybe don't display #[repr(C)] sometimes #66401

Open
@CAD97

Description

@CAD97

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],
}

image

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

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions