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
Silent wrong arm: match on a u8-repr discriminant enum picks the first arm for in-range values #1444
match on a u8-repr discriminant enum selects the wrong arm for in-range values — silent wrong code. i32 repr is correct. (Distinct from #1003, which is about out-of-range discriminant values.)
enum Kind: u8:
Red = 1
Blue = 2
fn kname(k: Kind) -> i32:
match k:
.Red => 10
.Blue => 20
fn main:
print(f"{kname(Kind.Blue)} {kname(Kind.Red)}")
Prints 10 10; expected 20 10. With str arms (.Red => "red", .Blue => "blue") kname(Kind.Blue) returns an empty string; the qualified pattern spelling Kind.Red => behaves the same. enum Kind: i32: prints 20 10. An if k == Kind.Red comparison on the u8 enum is correct, so the fault is in match lowering of a sub-i32 repr.
Activity
MIR/codegen: a discriminant enum's discriminant is a value of its rep…
MIR: a generic receiver reached through a reference is borrowed at th…
MIR/codegen: a discriminant enum's discriminant is a value of its rep…
MIR: a generic receiver reached through a reference is borrowed at th…