Skip to content

Suggestion for incorrect repr use #61286

Closed

Description

@estebank

When encountering #[repr = "C"], suggest #[repr(C)] instead of the current #[repr(C, packed, ...)]. We need to detect specific cases like writing #[repr("packed")], where we should suggest #[repr(packed)], as otherwise provide a list of all the valid reprs.

(Follow up to #61140)

Activity

  1. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    A-diagnosticsArea: Messages for errors, warnings, and lints
    P-lowLow priority
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    on May 28, 2019
  2. added
    D-papercutDiagnostics: An error or lint that needs small tweaks.
    on Oct 5, 2019
  3. added a commit that references this issue on Nov 19, 2019
  4. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jan 21, 2020
  5. added
    A-attributesArea: Attributes (`#[…]`, `#![…]`)
    A-reprArea: the `#[repr(stuff)]` attribute
    and removed
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Dec 21, 2024
  6. estebank commented on Nov 3, 2025

    @estebank
    ContributorAuthor

    Current output:

    error[E0539]: malformed `repr` attribute input
    --> $DIR/repr.rs:4:1
    |
    LL | #[repr = "B"]
    | ^^^^^^^^^^^^^ expected this to be a list
    |
    = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html#representations>
    help: try changing it to one of the following valid forms of the attribute
    |
    LL - #[repr = "B"]
    LL + #[repr(<integer type>)]
    |
    LL - #[repr = "B"]
    LL + #[repr(C)]
    |
    LL - #[repr = "B"]
    LL + #[repr(Rust)]
    |
    LL - #[repr = "B"]
    LL + #[repr(align(...))]
    |
    = and 2 other candidates

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 (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-reprArea: the `#[repr(stuff)]` attributeA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-papercutDiagnostics: An error or lint that needs small tweaks.P-lowLow priorityT-compilerRelevant to the compiler 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