Fn(a: u8) should get a clear diagnostic · Issue #140169 · rust-lang/rust (original) (raw)

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