Skip to content
Latchkey

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.

cargo
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 handled

Common 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.

src/state.rs
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.

src/state.rs
match code {
    0 => "ok",
    _ => "other",
}

How to prevent it

  • Prefer explicit arms over _ so adding a variant breaks the build deliberately.
  • Re-run cargo check after bumping dependencies that expose enums.
  • Treat exhaustiveness errors as a prompt to review every match on that type.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →