Skip to content

Provide type on non-exhaustive pattern matching errors #67259

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Centril opened this issue Dec 12, 2019 · 0 comments · Fixed by #70457
Closed

Provide type on non-exhaustive pattern matching errors #67259

Centril opened this issue Dec 12, 2019 · 0 comments · Fixed by #70457
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Centril
Copy link
Contributor

Centril commented Dec 12, 2019

Context & discussion #67026 (comment).

Given e.g.

fn main() {
    match Some(0) {
        None => {}
    }
}

we now get an error:

error[E0004]: non-exhaustive patterns: `Some(_)` not covered
 --> src/main.rs:2:11
  |
2 |     match Some(0) {
  |           ^^^^^^^ pattern `Some(_)` not covered
  |
  = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

but we should change this into:

error[E0004]: non-exhaustive patterns: `Some(_)` not covered
 --> src/main.rs:2:11
  |
2 |     match Some(0) {
  |           ^^^^^^^ pattern `Some(_)` 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 `std::option::Option<i32>`

cc @estebank @varkor @Nadrieril

@Centril Centril added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 12, 2019
@Centril Centril added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Dec 12, 2019
Centril added a commit to Centril/rust that referenced this issue Mar 27, 2020
…pe, r=estebank

non-exhastive diagnostic: add note re. scrutinee type

This fixes rust-lang#67259 by adding a note:
```
    = note: the matched value is of type &[i32]
```
to non-exhaustive pattern matching errors.

r? @varkor @estebank
@bors bors closed this as completed in 23d3fa2 Mar 28, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant