Skip to content

Misleading error message when using wrong type of function in for #2255

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
brson opened this issue Apr 19, 2012 · 0 comments
Closed

Misleading error message when using wrong type of function in for #2255

brson opened this issue Apr 19, 2012 · 0 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-type-system Area: Type system

Comments

@brson
Copy link
Contributor

brson commented Apr 19, 2012

In this error keys is not a function that can be iterated with for, and I stared at this error message for a long time before realizing that.

It's not clear here what types are mismatched and why. It seems like maybe the expected and actual are reversed. Even so, it would be nice to have some for-specific error.

../src/librustsyntax/parse/token.rs:226:37: 228:5 error: mismatched types: expected `()` but found `bool` (() vs bool)
../src/librustsyntax/parse/token.rs:226     for bad_expr_word_table().keys() {|word|
../src/librustsyntax/parse/token.rs:227         keywords.insert(word, ());
../src/librustsyntax/parse/token.rs:228     }
../src/librustsyntax/parse/token.rs:226:37: 228:5 error: mismatched types: expected `fn(&&str)` but found `fn(&&str) -> bool` (() vs bool)
../src/librustsyntax/parse/token.rs:226     for bad_expr_word_table().keys() {|word|
../src/librustsyntax/parse/token.rs:227         keywords.insert(word, ());
../src/librustsyntax/parse/token.rs:228     }
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Format tests with rustfmt (288-299 of 299)

Extracted from rust-lang#2097.

I'll make a separate PR to enable checking the `tests` directory's formatting in CI. I'll need to rebase that after both this and rust-lang#2254 have landed, and if any new non-rustfmt-formatted files appear in the meantime, we can include formatting those in the same PR that enables the CI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

2 participants