The following code (playground)
let max_column = 7;
edge = match current_column {
0 => Edge::Left,
max_column => Edge::Right,
_ => Edge::NotAnEdge
};
results in the following warning:
warning: unreachable pattern
--> src/main.rs:10:9
|
9 | max_column => Edge::Right,
| ---------- matches any value
10 | _ => Edge::NotAnEdge
| ^ unreachable pattern
|
= note: #[warn(unreachable_patterns)] on by default
Replacing the variable max_column
with the literal works fine:
let max_column = 7;
edge = match current_column {
0 => Edge::Left,
7 => Edge::Right,
_ => Edge::NotAnEdge
};
Why is _
unreachable in the first example when it can be reached for any values where current_column != max_column
?