check_match: refactor + improve non-exhaustive diagnostics for default binding modes by Centril · Pull Request #64271 · rust-lang/rust (original) (raw)

Refactor check_match a bit with more code-reuse and improve the diagnostics for a non-exhaustive pattern match by peeling off any references from the scrutinee type so that the "defined here" label is added in more cases. For example:

error[E0004]: non-exhaustive patterns: &mut &B not covered --> foo.rs:4:11 |

1 | enum E { A, B } | --------------- | | | | | not covered | E defined here ... 4 | match x { | ^ pattern &mut &B not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

Moreover, wrt. "defined here", we give irrefutable pattern matching (i.e. in let, for, and fn parameters) a more consistent treatment in line with match.

r? @estebank