Skip to content

Additional suggestion for returning async closure Future is wrong #150701

Closed

Description

async fn f(c: impl Future<Output = ()>) {
    c.await
}
#[tokio::main]
async fn main() {
    f(async || {}()).await
}

Cargo clippy said:

error[E0618]: expected function, found `()`
 --> src/main.rs:6:16
  |
6 |     f(async || {}()).await
  |                ^^--                                   |                |
  |                call expression requires function
  |                                                     help: if you meant to create this closure and immediately call it, surround the closure with parentheses          |
6 |     f((async || {})()).await
  |       +           +

error[E0277]: `{async closure@src/main.rs:6:7: 6:15}` is not a future
 --> src/main.rs:6:7
  |
6 |     f(async || {}()).await
  |     - ^^^^^^^^^^^^^ `{async closure@src/main.rs:6:7: 6:15}` is not a future
  |     |
  |     required by a bound introduced by this call
  |
  = help: the trait `std::future::Future` is not implemented for `{async closure@src/main.rs:6:7: 6:15}`
note: required by a bound in `f`
 --> src/main.rs:1:20
  |
1 | async fn f(c: impl Future<Output = ()>) {
  |                    ^^^^^^^^^^^^^^^^^^^ required by this bound in `f`
help: use parentheses to call this closure
  |
6 |     f(async || {}()()).await
  |                    ++

error[E0277]: `{async closure@src/main.rs:6:7: 6:15}` is not a future
 --> src/main.rs:6:5
  |
6 |     f(async || {}()).await
  |     ^^--------^^^^^^
  |     | |
  |     | consider calling this closure
  |     `{async closure@src/main.rs:6:7: 6:15}` is not a future
  |
  = help: the trait `std::future::Future` is not implemented for `{async closure@src/main.rs:6:7: 6:15}`
note: required by a bound in `f`
 --> src/main.rs:1:20
  |
1 | async fn f(c: impl Future<Output = ()>) {
  |                    ^^^^^^^^^^^^^^^^^^^ required by this bound in `f`

error[E0277]: `{async closure@src/main.rs:6:7: 6:15}` is not a future
 --> src/main.rs:6:22
  |
6 |     f(async || {}()).await
  |       --------       ^^^^^ `{async closure@src/main.rs:6:7: 6:15}` is not a future
  |       |
  |       consider calling this closure
  |
  = help: the trait `std::future::Future` is not implemented for `{async closure@src/main.rs:6:7: 6:15}`
note: required by a bound in `f`
 --> src/main.rs:1:20
  |
1 | async fn f(c: impl Future<Output = ()>) {
  |                    ^^^^^^^^^^^^^^^^^^^ required by this bound in `f`

The 2nd suggestion is wrong, according to the 2nd suggestion to add parentheses after async closure can't fix the error. And the 1st suggestion will change to

error[E0618]: expected function, found `()`
 --> src/main.rs:6:16
  |
6 |     f(async || {}()()).await                          |                ^^--
  |                |
  |                call expression requires function

Only surrounding async closure

async fn f(c: impl Future<Output = ()>) {
    c.await
}
#[tokio::main]
async fn main() {
    f((async || {})()).await
}

fixes the error. But after fixing the error, clippy suggests

warning: try not to call a closure in the expression where it is declared                                        --> src/main.rs:6:7
  |                                                     6 |     f((async || {})()).await
  |       ^^^^^^^^^^^^^^^ help: try doing something like: `async {}`

Activity

  1. transferred this issue fromrust-lang/cargoon Jan 5, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jan 5, 2026
  3. reddevilmidzy commented on Jan 5, 2026

    @reddevilmidzy
    Member

    reduce:

    #![allow(unused)]
    fn f(c: impl Future) {
    }
    
    fn main() {
        f(async || {}());
    }

    output

    error[E0618]: expected function, found `()`
     --> src/main.rs:6:16
      |
    6 |     f(async || {}());
      |                ^^--
      |                |
      |                call expression requires function
      |
    help: if you meant to create this closure and immediately call it, surround the closure with parentheses
      |
    6 |     f((async || {})());
      |       +           +
    
    error[E0277]: `{async closure@src/main.rs:6:7: 6:15}` is not a future
     --> src/main.rs:6:7
      |
    6 |     f(async || {}());
      |     - ^^^^^^^^^^^^^ `{async closure@src/main.rs:6:7: 6:15}` is not a future
      |     |
      |     required by a bound introduced by this call
      |
      = help: the trait `Future` is not implemented for `{async closure@src/main.rs:6:7: 6:15}`
    note: required by a bound in `f`
     --> src/main.rs:2:14
      |
    2 | fn f(c: impl Future) {
      |              ^^^^^^ required by this bound in `f`
    help: use parentheses to call this closure
      |
    6 |     f(async || {}()());
      |                    ++
    
    Some errors have detailed explanations: E0277, E0618.
    For more information about an error, try `rustc --explain E0277`.
  4. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
    A-diagnosticsArea: Messages for errors, warnings, and lints
    on Jan 5, 2026
  5. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jan 5, 2026
  6. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jan 12, 2026
  7. added
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    and removed
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    on Jan 16, 2026
  8. added a commit that references this issue on Mar 12, 2026
    cea42a6
  9. added a commit that references this issue on Apr 21, 2026
    6e9a1c5
  10. added a commit that references this issue on Apr 21, 2026
    55b415b
  11. added 2 commits that reference this issue on Apr 21, 2026
    3b5e423
    545e7dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-async-closures`async || {}`A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`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.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions