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

Functions and closures with incorrect return types should have better diagnostics #41897

Closed
Mark-Simulacrum opened this issue May 10, 2017 · 2 comments · Fixed by #43484
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@Mark-Simulacrum
Copy link
Member

We should do better on the diagnostic in this case, since presumably the author of the code meant to return the 10, so we should suggest that the function needs a return type, somewhat as we currently give the "remove ;" suggestion.

fn foo() {
   10
}
error[E0308]: mismatched types
 --> test.rs:2:5
  |
2 |     10
  |     ^^ expected (), found integral variable
  |
  = note: expected type `()`
             found type `{integer}`

error: aborting due to previous error

Filing this to close out #35478, #21838, #22216, #18595 as duplicates of this.

@estebank
Copy link
Contributor

Previous stab at this: #39231.

@estebank
Copy link
Contributor

We do this now.

estebank added a commit to estebank/rust that referenced this issue Jul 26, 2017
Before this, the diagnostic errors would only point at the return type
when changing it would be a possible solution to a type error. Add a
label to the return type without a suggestion to change in order to make
the source of the expected type obvious.

Follow up to rust-lang#42850, fixes rust-lang#25133, fixes rust-lang#41897.
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
bors added a commit that referenced this issue Aug 9, 2017
Point at return type always when type mismatch against it

Before this, the diagnostic errors would only point at the return type
when changing it would be a possible solution to a type error. Add a
label to the return type without a suggestion to change in order to make
the source of the expected type obvious.

Follow up to #42850, fixes #25133, fixes #41897.
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants