Skip to content

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

Closed
@brson

Description

@brson

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     }

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)A-type-systemArea: Type system

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions