本頁尚未翻譯,以下為英文原文。
#E0098: non-exhaustive match
A match must cover every value. Add arms for the cases the message lists, or a _ arm; an enum marked #[non_exhaustive] in another package always needs _.
nabi
enum Light { Red, Yellow, Green }
fn next(l: Light) -> Light {
match l {
Light::Red => Light::Green,
Light::Green => Light::Yellow,
}
}
error[E0098]: non-exhaustive match on `Light`: `Light::Yellow` not covered --> main.nabi:4:5 | 4 | match l { | ^^^^^^^^^ | = help: add `Light::Yellow => ..`
Add an arm for the missing case:
nabi
#[derive(PartialEq)]
enum Light { Red, Yellow, Green }
fn next(l: Light) -> Light {
match l {
Light::Red => Light::Green,
Light::Green => Light::Yellow,
Light::Yellow => Light::Red,
}
}
println(f"{next(Light::Yellow) == Light::Red}");
true
See 3.12.5 Exhaustiveness checking.
Related: E0099 unreachable match arm, E0103 binding looks like a variant
Found a mistake? Edit this page on GitHub. Last updated