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

Closure error messages should explain how the return type got inferred #78193

Closed
Aaron1011 opened this issue Oct 21, 2020 · 0 comments · Fixed by #78235
Closed

Closure error messages should explain how the return type got inferred #78193

Aaron1011 opened this issue Oct 21, 2020 · 0 comments · Fixed by #78235
Labels
A-closures Area: Closures (`|…| { … }`) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

The following code:

fn main() {
    || {
        if false {
            return 1;
        }
    };
}

produces the following error message:

error[E0308]: mismatched types
 --> src/main.rs:3:9
  |
3 | /         if false {
4 | |             return 1;
5 | |         }
  | |_________^ expected integer, found `()`

The message doesn't explain why an integer was expected here. If the user doesn't explicitly annotate the return type of the closure, we should point to the expression that caused the return type to get inferred to begin with.

@Aaron1011 Aaron1011 added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints A-closures Area: Closures (`|…| { … }`) D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Oct 21, 2020
@JohnTitor JohnTitor added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 21, 2020
JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 23, 2020
Explain where the closure return type was inferred

Fixes rust-lang#78193
@bors bors closed this as completed in 36a5244 Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. 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.

2 participants