Skip to content

#[repr] on zero-variant enums leaves the reader with questions #139703

Open
@Veykril

Description

@Veykril

Code

#[repr(isize)]
enum Uninhabited {}

Current output

error[E0084]: unsupported representation for zero-variant enum
 --> src/lib.rs:1:1
  |
1 | #[repr(isize)]
  | ^^^^^^^^^^^^^^
2 | enum Uninhabited {}
  | ---------------- zero-variant enum

Desired output

error[E0084]: zero-variant enums do not support `#[repr]`
 --> src/lib.rs:1:1
  |
1 | #[repr(isize)]
  | ^^^^^^^^^^^^^^
2 | enum Uninhabited {}
  | ---------------- zero-variant enum

Rationale and extra context

The current output leaves the user questioning whether there may be some valid repr while not being told which ones are valid options. The diagnostic should probably be more clear about the fact that the attribute is generally not supported on zero-variant enums

Other cases

Rust Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-pc-windows-msvc
release: 1.86.0
LLVM version: 19.1.7

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-enumArea: Enums (discriminated unions, or more generally ADTs (algebraic data types))A-reprArea: the `#[repr(stuff)]` attributeT-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