diagnostic codes / Types
E0206 non-exhaustive-match
A `match` over an enum does not cover every variant.
E0206non-exhaustive-matchmatch must cover every enum variant or add a deliberate _ arm
| severity | error |
|---|---|
| band | Types |
| in the v0 bootstrap | emitted |
| explain | ralt explain E0206 |
Enums are closed: the variants are known at the declaration, so a `match` can be checked against the full set. A missing variant is reported with its name. A `_` arm is accepted and is treated as deliberate coverage of everything not listed.
What it looks like
e0206.tp
use tier core; enum E { A, B, C } fn main() -> i32 { let e = E::A; match e { E::A => { print_str("a"); } E::B => { print_str("b"); } } return 0; }
ralt check e0206.tp e0206.tp:7:5: error: match over 'E' misses variant 'C' [E0206 non-exhaustive-match] match must cover every enum variant or add a deliberate _ arm
What to do
- Add the missing variant arm, even if its body is empty.
- Or add `_ => { }` if new variants should not force a change here. That is a decision, and the syntax records it.
Why the code exists
Adding a variant should break every `match` that needs to think about it, at compile time. That is the whole reason the enum is closed.
What ralt explain says
ralt explain E0206 E0206 severity: error name: non-exhaustive-match hint: match must cover every enum variant or add a deliberate _ arm
Related
- Structs, enums, match /docs/language/data