- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.