LYR-SEM0112
a match arm no value can reach
An arm of a 'match' stands after an arm that already matches every value, or tests the same variant or literal as an unguarded arm above it.
Explanation
Arms are tried top to bottom, and the first that matches wins. An arm after a catch-all (_, a plain binding) or after an unguarded arm with the same exact pattern never runs. The program is still correct, so this is a warning; but the dead arm is usually a mistake in the order or in the pattern.
Remove the arm, reorder the arms, or correct the pattern it was meant to have.
Wrong
enum Signal { Red, Yellow, Green }
fn code(s: Signal): int {
return match (s) {
.Red => 0,
.Red => 1,
_ => 2,
};
}
fn main(): void {
let _ = code(Signal.Green);
}
Right
enum Signal { Red, Yellow, Green }
fn code(s: Signal): int {
return match (s) {
.Red => 0,
.Yellow => 1,
_ => 2,
};
}
fn main(): void {
let _ = code(Signal.Green);
}