rust-lang / rust-lang/rust

async closure argument type inference error has wrong span

Open
#139,150 0 comments 0 reactions 1 assignee View on GitHub

@chenyukang is already working on this.

Since Sep 9, 2026.

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

Description

Code
fn main() {
    async |_| {};
}
Current output
error[E0282]: type annotations needed
 --> src/main.rs:2:15
  |
2 |     async |_| {};
  |               ^^ cannot infer type
Desired output
error[E0282]: type annotations needed
 --> src/main.rs:2:7
  |
2 |      async |_| {};
  |             ^
  |
help: consider giving this closure parameter an explicit type
  |
2 |      async |_: /* Type */| {};
  |              ++++++++++++
Rationale and extra context

diagnostics for non-async closures are better and already use this improved error

Other cases

Rust Version
1.88.0-nightly

(2025-03-29 1799887bb281d1ab4928)
Anything else?

@rustbot label A-async-closures

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.