Skip to content

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

Open
@CAD97

Description

@CAD97
Contributor

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.

Activity

added
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
on Nov 14, 2019
dtolnay

dtolnay commented on Feb 5, 2023

@dtolnay
Member

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.

added a commit that references this issue on May 16, 2023

Rollup merge of rust-lang#107680 - dtolnay:docrepr, r=Amanieu

8d162fb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @jonas-schievink@dtolnay@CAD97@JohnTitor

        Issue actions

          Rustdoc: maybe don't display #[repr(C)] sometimes · Issue #66401 · rust-lang/rust