rust-lang / rust-lang/rust

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

Open
#139,703 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-enum A-repr T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic with the issue's zero-variant enum and #[repr(isize)] snippet. Find the compiler diagnostic entry for E0084, update the wording so it states that zero-variant enums do not support #[repr], and update or add the corresponding expected diagnostic test. Confirm the revised output matches the desired example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.