Closed
Description
Given the following code:
fn map(f: impl fn()) {}
The current output is:
error: expected identifier, found keyword `fn`
--> src/lib.rs:1:16
|
1 | fn map(f: impl fn()) {}
| ^^ expected identifier, found keyword
|
help: you can escape reserved keywords to use them as identifiers
|
1 | fn map(f: impl r#fn()) {}
| ^^^^
error: expected one of `:` or `|`, found `)`
--> src/lib.rs:1:20
|
1 | fn map(f: impl fn()) {}
| ^ expected one of `:` or `|`
error: expected one of `!`, `(`, `)`, `,`, `?`, `for`, lifetime, or path, found keyword `fn`
--> src/lib.rs:1:16
|
1 | fn map(f: impl fn()) {}
| -^^ expected one of 8 possible tokens
| |
| help: missing `,`
error: at least one trait must be specified
--> src/lib.rs:1:11
|
1 | fn map(f: impl fn()) {}
| ^^^^
error: aborting due to 4 previous errors
error: could not compile `playground`
Ideally the output should look like:
error[E0405]: cannot find trait `fn` in this scope
--> src/lib.rs:2:16
|
1 | fn map(f: impl fn()) {}
| ^^^^ help: a trait with a similar name exists (notice the capitalization): `Fn`
note: `fn` is the type of a function pointer, and cannot be used as a trait
help: <maybe something brief about the Fn{Mut, Once} traits>
This is based on the error generated by
fn foo(v: impl send) {}
Related diagnostics
The issue also affects return-position impls, where more helpful guidance could be given
fn g() -> impl fn() {}
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: The lexing & parsing of Rust source code to an ASTCategory: An issue proposing an enhancement or a PR with one.Diagnostics: Too much output caused by a single piece of incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.