]> git.lizzy.rs Git - rust.git/commit
Auto merge of #64271 - Centril:non-exhaustive-peel-refs, r=estebank
authorbors <bors@rust-lang.org>
Wed, 11 Sep 2019 18:46:18 +0000 (18:46 +0000)
committerbors <bors@rust-lang.org>
Wed, 11 Sep 2019 18:46:18 +0000 (18:46 +0000)
commitf0b58fcf03391a91f74224fe38a696d5a5b789d9
treefcfed11712e1af5cad16ef353352914ccfef69d5
parentfe6d05a8b32f5c66c427ca524dbcce5a7145f87e
parent20a26055b7afa500e1b00c6e5a3d03a1208c1d00
Auto merge of #64271 - Centril:non-exhaustive-peel-refs, r=estebank

check_match: refactor + improve non-exhaustive diagnostics for default binding modes

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:

```rust
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
src/librustc_mir/hair/pattern/check_match.rs