Skip to content

Incorrect syntax on suggestion to make pub function async with E0277 #96555

Closed
@sciguy16

Description

@sciguy16

Given the following code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=0db76b4ce2ff53636126640d313e2b91

fn main() {
   bar();
}

async fn bar() {
    a_mod::foo().await;
}

mod a_mod {
    pub fn foo() {}
}

The current output is:

error[E0277]: `()` is not a future
 --> a.rs:6:17
  |
6 |     a_mod::foo().await;
  |     ------------^^^^^^ `()` is not a future
  |     |
  |     this call returns `()`
  |
  = help: the trait `Future` is not implemented for `()`
  = note: () must be a future or must implement `IntoFuture` to be awaited
  = note: required because of the requirements on the impl of `IntoFuture` for `()`
help: remove the `.await`
  |
6 -     a_mod::foo().await;
6 +     a_mod::foo();
  |
help: alternatively, consider making `fn foo` asynchronous
  |
10|     async pub fn foo() {}
  |     +++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

Ideally the output should look like:

...
10|     pub async fn foo() {}
  |         +++++
...

Tested on rustc 1.60.0 stable and nightly-2022-04-29

Metadata

Metadata

Assignees

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