rust-lang / rust-lang/rust

Avoid using bare Fn* trait syntax in error messages

Open
#148,092 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
fn foo(_: impl FnOnce(&())) {}

fn main() {
    foo(std::mem::drop);
}

Available at this playground.

Current output
Compiling playground v0.0.1 (/playground)
error: implementation of `FnOnce` is not general enough
 --> src/main.rs:6:5
  |
6 |     foo(std::mem::drop);
  |     ^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
  |
  = note: `fn(&'2 ()) {std::mem::drop::<&'2 ()>}` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`...
  = note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2`
Desired output
Compiling playground v0.0.1 (/playground)
error: implementation of `FnOnce` is not general enough
 --> src/main.rs:6:5
  |
6 |     foo(std::mem::drop);
  |     ^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
  |
  = note: `fn(&'2 ()) {std::mem::drop::<&'2 ()>}` must implement `FnOnce(&'1 ())`, for any lifetime `'1`...
  = note: ...but it actually implements `FnOnce(&'2 ())`, for some specific lifetime `'2`
Rationale and extra context

Would generally rather not see FnOnce<(T,)> syntax in user-facing messages, especially since it's unstable.

Rust Version
rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-unknown-linux-gnu
release: 1.90.0
LLVM version: 20.1.8
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported Rust example from the issue and inspect the compiler diagnostic path that formats the FnOnce bounds. Compare the current and desired messages, then add coverage for avoiding bare Fn* trait syntax while preserving the lifetime details.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.