Skip to content

Incorrect closure signature in diagnostic when passing normal closure to AsyncFn argument #155636

@theemathas

Description

@theemathas

Code

fn foo(_: impl AsyncFn(&mut i32)) {}

fn main() {
    foo(|_: i32| async {});
}

Current output

error[E0631]: type mismatch in closure arguments
 --> src/main.rs:4:5
  |
4 |     foo(|_: i32| async {});
  |     ^^^^--------^^^^^^^^^^
  |     |   |
  |     |   found signature defined here
  |     expected due to this
  |
  = note: expected closure signature `for<'a> fn((&'a mut _,)) -> _`
             found closure signature `fn((_,)) -> _`
note: required by a bound in `foo`
 --> src/main.rs:1:16
  |
1 | fn foo(_: impl AsyncFn(&mut i32)) {}
  |                ^^^^^^^^^^^^^^^^^ required by this bound in `foo`

For more information about this error, try `rustc --explain E0631`.

Desired output

Rationale and extra context

I don't know why the argument is put into a tuple in the diagnostic.

Other cases

Rust Version

Reproducible on the playground with version 1.97.0-nightly (2026-04-21 9ec5d5f32e19d250c7fb)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions