Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

match arm without tail expression diverging type error has non-ideal spans #75418

Closed
2 tasks
estebank opened this issue Aug 11, 2020 · 3 comments · Fixed by #75656
Closed
2 tasks

match arm without tail expression diverging type error has non-ideal spans #75418

estebank opened this issue Aug 11, 2020 · 3 comments · Fixed by #75656
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

Given:

    let _ = match Some(42) {
        Some(x) => {
            x
        }
        None => {
            0;
        }
    };

we emit

error[E0308]: `match` arms have incompatible types
 --> src/main.rs:6:17
  |
2 |        let _ = match Some(42) {
  |   _____________-
3 |  |         Some(x) => {
4 |  |             x
  |  |             - this is found to be of type `{integer}`
5 |  |         }
6 |  |         None => {
  |  |_________________^
7 | ||             0;
8 | ||         }
  | ||_________^ expected integer, found `()`
9 |  |     };
  |  |_____- `match` arms have incompatible types

We should be

  • checking that removing the ; in the incompatible arm would solve the issue and suggest it
  • point at the last statement in the incompatible arm instead of the whole arm
@estebank estebank 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. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Aug 11, 2020
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Aug 12, 2020
@tirr-c
Copy link
Contributor

tirr-c commented Aug 17, 2020

I'd like to work on this. I've found a similar logic on reporting if-else type mismatch, maybe this could be done in that way.

@estebank
Copy link
Contributor Author

@tirr-c that would be great! That code would probably work with very little modification. If it does, please extract it to a method called from both places :)

@tirr-c
Copy link
Contributor

tirr-c commented Aug 22, 2020

@estebank I've made a PR a few days ago, could you take a look at it?

@bors bors closed this as completed in 5180f3d Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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. D-papercut Diagnostics: An error or lint that needs small tweaks. 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.

3 participants