E0084 rejects every `#[repr]` on zero-variant enums, including representations the language allows
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 47/100
Direzione di ricerca
The issue points to the zero-variant enum #[repr] validation in rustc but names no source files or tests. Start by tracing the E0084 diagnostic and its UI tests, then compare the checks for primitive and C representations with the allowed Rust and align cases described here. Done means the permitted forms compile, the forbidden forms still produce errors, and regression tests cover the distinctions.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Split out from #139703, where @hanna-kruppe and @fmease pointed out that #[repr(align(N))] and #[repr(Rust)] are rejected on empty enums.
What the language says
The Reference only forbids two kinds of representation on zero-variant enums:
- layout.repr.primitive.constraint: "It is an error for zero-variant enums to have a primitive representation."
- layout.repr.c.constraint: the
Crepresentation is an error for zero-variant enums.
Nothing else is forbidden. The Reference even assumes other representations exist for them: "Enums (without a primitive representation) with no variants are zero sized." layout.repr.alignment.enum also allows align on any enum, and defines it as equivalent to wrapping the enum in a newtype struct with the same align modifier.
What rustc does
rustc enforces a stricter rule: a zero-variant enum can't have any #[repr] attribute at all.
Attribute on enum E {} |
Reference | rustc |
|---|---|---|
#[repr(u8)], #[repr(isize)], … |
error | E0084 |
#[repr(C)] |
error | E0084 |
#[repr(Rust)] |
allowed | E0084 |
#[repr(align(8))] |
allowed | E0084 |
#[repr(C, align(8))] |
error (because of C) |
E0084 |
#[repr()] |
allowed (no effect) | E0084, plus an "unused attribute" warning |
History
The original check (2014) only rejected representations that set the discriminant type, which matches the Reference. It was broadened to "any #[repr] attribute" in ba11640179b (#40008, 2017), during a refactor that doesn't appear to have intended a language change. Representations stabilized after that, such as align on enums and explicit Rust, were rejected on zero-variant enums from the start.
@rustbot label +A-enum +A-repr +A-uninhabited-types +C-bug +T-compiler +T-lang
- Lingua principale
- Rust
- Stelle
- 123k
- Fork
- 16.6k
- Merge medio
- 2g 17h
- PR unite (30g)
- 532
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-lang/rust
-
C-bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
rust-lang/rust#166722 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
A-attributes relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-lang
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
A-run-make C-bug T-bootstrap
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Tracking issue for release notes of #161531: Remove `T: Send + Sync` bound from `Arc::downcast`Apertarelnotes relnotes-tracking-issue T-libs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
A-str A-Unicode relnotes relnotes-tracking-issue T-libs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rust-lang/rust
Issue simili
-
bug P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
bug core-lang
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Windows microphone listing treats words in a device name as DirectShow labelsForse già presa @Sujal-chaudhary l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
clipy-recorder/clipy#447 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
nightly-cleanup
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
max-sixty/worktrunk#4939 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno