Spurious non-exhaustive pattern error

This works:

enum X {
    A,
    B,
}

fn f(x: Option<X>) {
    match x {
        Some(X::A) => {}
        Some(X::B) => {}
        None => {}
    }
}

But this doesn't work:

enum X {
}

fn f(x: Option<X>) {
    match x {
        None => {}
    }
}
error[E0004]: non-exhaustive patterns: `Some(_)` not covered
   --> src/lib.rs:5:11
    |
5   |     match x {
    |           ^ pattern `Some(_)` not covered
    |

It has been solved in beta(1.82) : Rust Playground

10 Likes

On stable, the way to solve is as follows:

enum X {
}

fn f(x: Option<X>) {
    match x {
        Some(v) => match v {},
        None => {}
    }
}
5 Likes