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

Confusing diagnostic suggesting to remove .await in attribute macro #94877

Open
TimJentzsch opened this issue Mar 12, 2022 · 1 comment
Open
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

@TimJentzsch
Copy link

TimJentzsch commented Mar 12, 2022

Given the following code, using wasm_bindgen combined with tokio:

#[wasm_bindgen]
#[tokio::main]
pub async fn main() {
    let stdin = tokio::io::stdin();
    let stdout = tokio::io::stdout();

    let (service, socket) = LspService::new(|client| Backend { client });
    Server::new(stdin, stdout, socket).serve(service).await;
}

One of the given errors is:

error[E0277]: `()` is not a future
  --> src\lib.rs:36:1
   |
36 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ `()` is not a future
   |
   = 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`
   |
36 - #[wasm_bindgen]
36 + #[wasm_bindgen]
   | 

While I'm sure that what I implemented doesn't make sense, the particular suggestion

help: remove the `.await`
   |
36 - #[wasm_bindgen]
36 + #[wasm_bindgen]
   | 

is very confusing to me.

More info

rustc --version --verbose:

rustc 1.61.0-nightly (335ffbfa5 2022-03-11)
binary: rustc
commit-hash: 335ffbfa547df94ac236f5c56130cecf99c8d82b
commit-date: 2022-03-11
host: x86_64-pc-windows-msvc
release: 1.61.0-nightly
LLVM version: 14.0.0

If you want to reproduce, you can use commit 5acb4d7 of https://github.com/TimJentzsch/tower-lsp-wasm, which is a rather small project.

Full `cargo check` output

error: the `async` keyword is missing from the function declaration
  --> src\lib.rs:36:1
   |
36 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^
   |
   = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared crate or module `wasm_bindgen_futures`
  --> src\lib.rs:36:1
   |
36 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ use of undeclared crate or module `wasm_bindgen_futures`
   |
   = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: `()` is not a future
  --> src\lib.rs:36:1
   |
36 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ `()` is not a future
   |
   = 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`
   |
36 - #[wasm_bindgen]
36 + #[wasm_bindgen]
   | 

Some errors have detailed explanations: E0277, E0433.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `tower-lsp-wasm` due to 3 previous errors

@TimJentzsch TimJentzsch 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 Mar 12, 2022
@TimJentzsch
Copy link
Author

Swapping the #[wasm_bindgen] and #[tokio::main] removes the errors. My guess is that the code generated by #[tokio::main] created the error. It would probably be fine to somehow detect that the help suggestion is useless and to just remove it in that case.

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

No branches or pull requests

1 participant