# How do I fix "non-exhaustive patterns" in a match (E0004)?
Source: https://ruststudio.org/community/t/147/how-do-i-fix-non-exhaustive-patterns-in-a-match-e0004
Author: Ruststudio Team (staff) | Published: 2026-12-05 | Updated: 2026-12-05 | Checked with: rustc 1.93.0, Windows 11
Category: Help and questions | Kind: FAQ | Tags: errors, enums, pattern-matching | Views: 0

## Short answer
A match must cover every possible value. The message names the case you left out. Add an arm for it, or end with a wildcard arm _ that covers the rest. Prefer listing the cases for your own enums, so the compiler reminds you when a new variant is added later.

## Answer
## Answer
`match` checks at compile time that no case can slip through, which is the reason enums are safe to extend: add a variant and every `match` on it that is not updated stops compiling.

```rust title=src/main.rs
enum Light {
    Red,
    Yellow,
    Green,
}

fn name(l: Light) -> &'static str {
    match l {
        Light::Red => "stop",
        Light::Green => "go",
    }
}

fn main() {
    println!("{}", name(Light::Yellow));
}
```

```text
error[E0004]: non-exhaustive patterns: `Light::Yellow` not covered
 --> src/main.rs:8:11
  |
8 |     match l {
  |           ^ pattern `Light::Yellow` not covered
  |
note: `Light` defined here
 --> src/main.rs:1:6
  |
1 | enum Light {
  |      ^^^^^
2 |     Red,
3 |     Yellow,
  |     ------ not covered
  = note: the matched value is of type `Light`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
  |
10~         Light::Green => "go",
11~         Light::Yellow => todo!(),
  |

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0004`.
```

The answers below are the two valid fixes.

## Answers (2)

### Answer 1 by Ruststudio Team (staff), 2026-12-05, 0 votes
## Approach 1: add the missing arm
Write out the case. This is the better choice for your own enums, because adding a variant later gives you a new error at every `match` that must decide what to do.

```rust title=src/main.rs
enum Light {
    Red,
    Yellow,
    Green,
}

fn name(l: Light) -> &'static str {
    match l {
        Light::Red => "stop",
        Light::Yellow => "slow down",
        Light::Green => "go",
    }
}

fn main() {
    println!("{}", name(Light::Yellow));
}
```

```text
slow down
```

### Answer 2 by Ruststudio Team (staff), 2026-12-05, 0 votes
## Approach 2: use a wildcard arm
`_ => ...` matches everything not named before it. It is the only choice for numbers and strings, which have too many values to list.

```rust
fn size(n: u32) -> &'static str {
    match n {
        0 => "empty",
        1..=9 => "small",
        _ => "large",
    }
}
```

Place `_` last: arms are tried in order, and anything after it is unreachable.

## Common mistakes
- Using `_` on your own enum "to make it compile". You lose the reminder that a new variant needs handling.
- Using `todo!()` as the arm body and forgetting it. It panics at run time when that case occurs.
- Reaching for `if let` when only one case matters. `if let Light::Red = l { ... }` needs no other arms.
