Skip to content

Non-Exhaustive Patterns: Matching Error (E0004) #2311

@MahadMuhammad

Description

@MahadMuhammad

I tried this code to test error code E0004(Matching Error) on godbolt:

#![allow(unused)]
fn main() {
enum Terminator {
    HastaLaVistaBaby,
    TalkToMyHand,
}

let x = Terminator::HastaLaVistaBaby;

match x { // error: non-exhaustive patterns: `HastaLaVistaBaby` not covered
    Terminator::TalkToMyHand => {}
}
}

I expected to see this happen:

error[E0004]: non-exhaustive patterns: `HastaLaVistaBaby` not covered
  --> <source>:10:7
   |
3  | / enum Terminator {
4  | |     HastaLaVistaBaby,
   | |     ---------------- not covered
5  | |     TalkToMyHand,
6  | | }
   | |_- `Terminator` defined here
...
10 |   match x { // error: non-exhaustive patterns: `HastaLaVistaBaby` not covered
   |         ^ pattern `HastaLaVistaBaby` not covered
   |
   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
   = note: the matched value is of type `Terminator`

Instead, this happened:

Compiler returned: 0

Meta

  • What version of Rust GCC were you using, git sha 6c63150
    • gccrs (Compiler-Explorer-Build-gcc-7671253eda836193313586013e92dde3d14f5ebe-binutils-2.40) 13.0.1 20230417 (experimental)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions