E0084 rejects every `#[repr]` on zero-variant enums, including representations the language allows

Aperta
#166,659 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

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
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
compilers

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

A-enum A-repr A-uninhabited-types C-bug needs-triage T-compiler T-lang

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:

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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/rust

Tutte le issue di rust-lang/rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.