Skip to content

Improve error message for "for x in [1,2,3] {" #17574

New issue

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

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

Already on GitHub? # to your account

Closed
kmcallister opened this issue Sep 26, 2014 · 3 comments · Fixed by #18984
Closed

Improve error message for "for x in [1,2,3] {" #17574

kmcallister opened this issue Sep 26, 2014 · 3 comments · Fixed by #18984
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@kmcallister
Copy link
Contributor

Beginners are often confused by the error message

error: `for` loop expression has type `[<generic integer #0>, .. 3]` which does not implement the `Iterator` trait

Perhaps if there's an iter() method we should suggest calling it. This involves hardcoding the name "iter", but only for the purposes of a hint that can be wrong sometimes.

@kmcallister kmcallister added A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Sep 27, 2014
@kmcallister
Copy link
Contributor Author

Or we just say "did you mean to call a method to get an iterator?" unconditionally. Or only when there's no method call in the expr?

@SiegeLord
Copy link
Contributor

Crazy idea... maybe make it possible to annotate types with error hints? E.g.

#[error_hint(E1234, "Use the `.iter()` method")]
struct Foo{}

sheroze1123 added a commit to sheroze1123/rust that referenced this issue Nov 15, 2014
@bstrie
Copy link
Contributor

bstrie commented Nov 20, 2014

@SiegeLord I'd suggest proposing that as its own issue so it doesn't get buried here forever.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants