Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sciguy16 opened this issue Apr 29, 2022 · 2 comments · Fixed by #96617
Closed

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

sciguy16 opened this issue Apr 29, 2022 · 2 comments · Fixed by #96617
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@sciguy16
Copy link

sciguy16 commented Apr 29, 2022

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

@sciguy16 sciguy16 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 29, 2022
@sciguy16
Copy link
Author

This looks like the section of code responsible for the message:

err.span_suggestion_verbose(
span.shrink_to_lo(),
&format!(
"alternatively, consider making `fn {}` asynchronous",
ident
),
"async ".to_string(),
Applicability::MaybeIncorrect,
);

@ken-matsui
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants