Skip to content

Invalid suggestion when attempting to call async closure #62386

@Aaron1011

Description

@Aaron1011

The following snippet:

#![feature(async_await)]

fn main() {
    async || ({
    })();
}

produces the following error:

error[E0618]: expected function, found `()`
 --> src/main.rs:4:14
  |
4 |        async || ({
  |   ______________^
  |  |______________|
  | ||
5 | ||     })();
  | ||______^_- call expression requires function
  | |_______|
  | 
help: if you meant to create this closure and immediately call it, surround the closure with parenthesis
  |
4 |     async || (({
5 |     }))();
  |

However, applying this suggestion doesn't actually fix the error. Instead, it simply causes a new suggestion to be produced - this time with three parentheses (e.g. ((() instead of two.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-async-closures`async || {}`A-closuresArea: Closures (`|…| { … }`)A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions