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

Regression in return type error quality with impl trait #50652

Closed
sophiajt opened this issue May 11, 2018 · 3 comments
Closed

Regression in return type error quality with impl trait #50652

sophiajt opened this issue May 11, 2018 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. 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

@sophiajt
Copy link
Contributor

In playing with impl trait this morning, I noticed that if you do the classic "oops, I left a ; after my return value" error, instead of the helpful message asking if you meant to have the semi-colon, you get this:

screen shot 2018-05-11 at 5 20 58 am

We should definitely try to cover this case too with the same improved error messages we have for other return types.

@sophiajt
Copy link
Contributor Author

Test case

trait Bar {}
impl Bar for bool {}

fn baz() -> impl Bar {
    true;
}

fn main() {
    baz();
}

@oli-obk oli-obk added the A-diagnostics Area: Messages for errors, warnings, and lints label May 11, 2018
@larsluthman
Copy link

The same error message appears if your function body consists of 'unimplemented!()' or 'panic!()'. In that case it should probably say something like 'Failed to infer return type' instead.

@XAMPPRocky XAMPPRocky added 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. A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. labels Oct 2, 2018
@estebank
Copy link
Contributor

Current output:

error[E0277]: the trait bound `(): Bar` is not satisfied
 --> src/main.rs:4:13
  |
4 | fn baz() -> impl Bar {
  |             ^^^^^^^^ the trait `Bar` is not implemented for `()`
5 |     true;
  |         - consider removing this semicolon
  |
  = note: the return type of a function must have a statically known size

It does not check wether the type actually impl Bar.

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 A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. 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

No branches or pull requests

5 participants