Skip to content

"Expected type, found {x}" message could be more helpful #41928

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

Closed
wesleywiser opened this issue May 12, 2017 · 1 comment
Closed

"Expected type, found {x}" message could be more helpful #41928

wesleywiser opened this issue May 12, 2017 · 1 comment

Comments

@wesleywiser
Copy link
Member

wesleywiser commented May 12, 2017

I mistyped a ; as a : because it was following a ) which requires holding the shift key on American keyboards. It would be nice if the error message mentioned why it was expecting a type.

Sample code:

fn main() {
    println!("test"):
    0;
}

Current error:

rustc 1.17.0 (56124baa9 2017-04-24)
error: expected type, found `0`
 --> <anon>:3:5
  |
3 |     0;
  |     ^

error: aborting due to previous error

It would be nice if it said something like this:

rustc 1.17.0 (56124baa9 2017-04-24)
error: expected type, found `0`
 --> <anon>:3:5
  |
3 |     0;
  |     ^

error: aborting due to previous error

--> <anon>:2:21
  |
2 |   println!("test"):
  |                   ^

hint: expecting a type because of type ascription here
@Mark-Simulacrum
Copy link
Member

There's lots of similar issues to this one, and I believe #42057 tracks the unique part of this issue, closing.

bors added a commit that referenced this issue Jul 23, 2017
Point at `:` when using it instead of `;`

When triggering type ascription in such a way that we can infer a
statement end was intended, add a suggestion for the change. Always
point out the reason for the expectation of a type is due to type
ascription.

Fix #42057, #41928.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants