Skip to content

Incorrect help: suggestion for immediately called async_closures #98023

Closed
@danielhenrymantilla

Description

@danielhenrymantilla

Given the following code:

async || {}()

The current output is:

error[[E0618]](https://doc.rust-lang.org/nightly/error-index.html#E0618): expected function, found `()`
 --> src/main.rs:3:25
  |
3 |     let _fut = async || {}();
  |                         ^^--
  |                         |
  |                         call expression requires function
  |
help: if you meant to create this closure and immediately call it, surround the closure with parentheses
  |
3 |     let _fut = async || ({})();
  |                         +  +

Ideally the output should look like:

error[[E0618]](https://doc.rust-lang.org/nightly/error-index.html#E0618): expected function, found `()`
 --> src/main.rs:3:25
  |
3 |     let _fut = async || {}();
  |                         ^^--
  |                         |
  |                         call expression requires function
  |
help: if you meant to create this closure and immediately call it, surround the closure with parentheses
  |
3 |     let _fut = (async || {})();
  |                +           +

@rustbot modify labels +F-async_closure +requires-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    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