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
Unsigned-repr discriminant enum sign-extends in 'as' casts (u8 200 as i32 is -56) #1454
Spec: §4.4a ("Casting:value as i32 extracts the underlying integer (identity cast)"; the representation type is one of i8 … u64).
An enum whose repr is unsigned sign-extends when cast to a wider integer:
enum Kind: u8:
Red = 1
Hi = 200
enum W: u16:
A = 1
B = 40000
fn main:
print(Kind.Hi as i32)
print(Kind.Hi as i64)
print(Kind.Hi as u32)
print(W.B as i32)
Prints -56, -56, 200, -25536; expected 200, 200, 200, 40000. The cast treats the repr as signed; as u32 happens to be right.
Found while exhausting the #1444 matrix (stage1 of origin/main 1c76062 and of the #1444 branch; the cast path is not the match path #1444 fixes).
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…
Codegen: a discriminant enum with an unsigned repr widens unsigned in…
Discriminants are i64 end to end: Sema computes them from the literal…
Codegen: a discriminant enum with an unsigned repr widens unsigned in…
Discriminants are i64 end to end: Sema computes them from the literal…
Codegen: a discriminant enum with an unsigned repr widens unsigned in…
ehartford commentedon Sep 26, 2026
Verified fixed on main 55739d4 (release binary): u8 200 as i32 is 200.