Rust E0004 "non-exhaustive patterns" in CI
A match does not cover all possible values of its scrutinee. rustc requires exhaustive matches, so an unhandled enum variant (or range) is a hard error -- frequently triggered when a dependency adds a variant.
What this error means
The compiler reports error[E0004]: non-exhaustive patterns: Variant not covered and lists the missing cases. It is deterministic for a given enum.
error[E0004]: non-exhaustive patterns: `Status::Cancelled` not covered
--> src/state.rs:6:11
|
6 | match status {
| ^^^^^^ pattern `Status::Cancelled` not covered
|
= help: ensure that all possible cases are being handledCommon causes
Unhandled enum variant
A new variant was added to the enum (yours or a dependency's) and the match was never updated to handle it.
Missing range or wildcard
Matching on an integer or non-enum type without a final _ arm leaves values uncovered.
How to fix it
Handle the missing case explicitly
Add an arm for each variant the compiler lists; prefer explicit arms over a blanket wildcard so future additions are caught.
match status {
Status::Ok => ok(),
Status::Failed => fail(),
Status::Cancelled => cancel(),
}Add a wildcard only where appropriate
For open-ended types a final arm covers the rest.
match code {
0 => "ok",
_ => "other",
}How to prevent it
- Prefer explicit arms over
_so adding a variant breaks the build deliberately. - Re-run
cargo checkafter bumping dependencies that expose enums. - Treat exhaustiveness errors as a prompt to review every match on that type.