Skip to content

Fn(a: u8) should get a clear diagnostic #140169

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

Open
cyrgani opened this issue Apr 22, 2025 · 2 comments · May be fixed by #140671
Open

Fn(a: u8) should get a clear diagnostic #140169

cyrgani opened this issue Apr 22, 2025 · 2 comments · May be fixed by #140671
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cyrgani
Copy link
Contributor

cyrgani commented Apr 22, 2025

Code

fn f(_: impl Fn(a: u8)) {}

Current output

error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`
 --> src/lib.rs:1:18
  |
1 | fn f(_: impl Fn(a: u8)) {}
  |                  ^ expected one of 7 possible tokens

Desired output

error: `Fn`-trait syntax does not allow named arguments

Rationale and extra context

fn f(_: fn(a: u8)) {} is valid syntax, so the difference should get better diagnostics

Other cases

Rust Version

rustc 1.88.0-nightly (d6c1e454a 2025-04-21)
binary: rustc
commit-hash: d6c1e454aa8af5e7e59fbf5c4e7d3128d2f99582
commit-date: 2025-04-21
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Anything else?

No response

@cyrgani cyrgani added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 22, 2025
@petrochenkov
Copy link
Contributor

There's an RFC issue for actually making this legal (rust-lang/rfcs#2812), but implementing parsing recovery for this would be a good first step.

@fmease fmease added A-parser Area: The lexing & parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Apr 22, 2025
@xizheyin
Copy link
Contributor

xizheyin commented May 3, 2025

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants