You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Compiler panics on a discriminant at the repr maximum (i32 auto-increment overflow) and on u64 discriminants above i64::MAX #1452
Spec: §4.4a Discriminant Enums (representation types i8 … u64; "each variant is assigned an explicit integer value with = N").
The compiler aborts (exit 134) on two valid declarations:
enum K: i32:
A = 1
B = 2147483647
fn main:
print(K.B as i32)
panic: integer overflow: i32 addition out of range
The parser auto-increments after every variant (current_disc = current_disc + 1), including the last one, so a last variant at the repr's maximum overflows the counter even though no variant needs the next value.
enum K: u64:
A = 1
B = 18446744073709551615
fn main:
print(K.B as u64)
panic: integer overflow: i64 multiplication out of range
A u64 discriminant above i64::MAX overflows the i64 literal accumulator.
Expected: both compile; the first prints 2147483647, the second 18446744073709551615. An auto-incremented variant that would need a value past the repr's range is a diagnostic naming the variant, not a panic.
Found while exhausting the #1444 matrix (installed nightly-20260922-local-1-8c859a7d0559).
Activity
MIR/codegen: a discriminant enum's discriminant is a value of its rep…
MIR/codegen: a discriminant enum's discriminant is a value of its rep…
Discriminants are i64 end to end: Sema computes them from the literal…
A discriminant at its repr's maximum and a u64 above i64::MAX compile…
Discriminants are i64 end to end: Sema computes them from the literal…
A discriminant at its repr's maximum and a u64 above i64::MAX compile…
Discriminants are i64 end to end: Sema computes them from the literal…
A discriminant at its repr's maximum and a u64 above i64::MAX compile…
ehartford commentedon Sep 26, 2026
Verified fixed on main 55739d4 (release binary): repr-max discriminants print, no panic.