Skip to content

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

Open
@TimJentzsch

Description

@TimJentzsch

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

Metadata

Metadata

Assignees

No one assigned

    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