Skip to content

async closure argument type inference error has wrong span #139150

Open
@cyrgani

Description

@cyrgani

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-closures`async || {}`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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions