Compiling Rust is NP-hard
The actual code that handles exhaustiveness checks has extensive explanations on how it works and what it was inspired by.https://github.com/rust-lang/rust/blob/master/compiler/rustc...