From 6167a79297592c28b838d89fe75bfa9aa87367a3 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Thu, 7 Sep 2023 15:56:47 +0200 Subject: [PATCH] Fix `wasm_bindgen_futures` not using custom path --- CHANGELOG.md | 11 +++++++++-- crates/backend/src/codegen.rs | 8 ++++---- crates/futures/src/lib.rs | 3 +++ crates/macro/ui-tests/async-errors.stderr | 8 ++++---- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cce1b9d2852..9f3b664e66a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,11 +14,13 @@ * Add bindings for `WebAssembly.Tag` and `WebAssembly.Exception`. [#3484](https://github.com/rustwasm/wasm-bindgen/pull/3484) -* Re-export `wasm-bindgen` from `js-sys` and `web-sys`. +* Re-export `wasm-bindgen` from `js-sys`, `web-sys` and `wasm-bindgen-futures`. [#3466](https://github.com/rustwasm/wasm-bindgen/pull/3466) + [#3601](https://github.com/rustwasm/wasm-bindgen/pull/3601) -* Re-export `js-sys` from `web-sys`. +* Re-export `js-sys` from `web-sys` and `wasm-bindgen-futures`. [#3466](https://github.com/rustwasm/wasm-bindgen/pull/3466) + [#3601](https://github.com/rustwasm/wasm-bindgen/pull/3601) * Add bindings for async variants of `Atomics.wait`. [#3504](https://github.com/rustwasm/wasm-bindgen/pull/3504) @@ -110,6 +112,11 @@ * Fixed optional parameters in JSDoc. [#3577](https://github.com/rustwasm/wasm-bindgen/pull/3577) +* Use re-exported `js-sys` from `wasm-bindgen-futures` to account for + non-default path specified by the `crate` attribute in `wasm_bindgen_futures` + proc-macro. + [#3601](https://github.com/rustwasm/wasm-bindgen/pull/3601) + ### Removed * Removed `ReadableStreamByobReader::read_with_u8_array()` because it doesn't work with Wasm. diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index 4e3d6ca8d9a..e45d4e50ba1 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -1190,11 +1190,11 @@ impl TryToTokens for ast::ImportFunction { Some(ref ty) => { if self.function.r#async { abi_ret = quote! { - #wasm_bindgen::convert::WasmRet<::Abi> + #wasm_bindgen::convert::WasmRet<<#wasm_bindgen_futures::js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi>::Abi> }; let future = quote! { #wasm_bindgen_futures::JsFuture::from( - + <#wasm_bindgen_futures::js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi> ::from_abi(#ret_ident.join()) ).await }; @@ -1216,11 +1216,11 @@ impl TryToTokens for ast::ImportFunction { None => { if self.function.r#async { abi_ret = quote! { - #wasm_bindgen::convert::WasmRet<::Abi> + #wasm_bindgen::convert::WasmRet<<#wasm_bindgen_futures::js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi>::Abi> }; let future = quote! { #wasm_bindgen_futures::JsFuture::from( - + <#wasm_bindgen_futures::js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi> ::from_abi(#ret_ident.join()) ).await }; diff --git a/crates/futures/src/lib.rs b/crates/futures/src/lib.rs index c2a59d76286..8a02a51bc39 100644 --- a/crates/futures/src/lib.rs +++ b/crates/futures/src/lib.rs @@ -46,6 +46,9 @@ mod queue; #[cfg(feature = "futures-core-03-stream")] pub mod stream; +pub use js_sys; +pub use wasm_bindgen; + mod task { use cfg_if::cfg_if; diff --git a/crates/macro/ui-tests/async-errors.stderr b/crates/macro/ui-tests/async-errors.stderr index 188192c5d87..a128c73c090 100644 --- a/crates/macro/ui-tests/async-errors.stderr +++ b/crates/macro/ui-tests/async-errors.stderr @@ -32,10 +32,10 @@ error[E0277]: the trait bound `wasm_bindgen::JsValue: From` is not sati > > > - > - > - >> - and 74 others + > + > + > + and $N others = note: required for `BadType` to implement `Into` = note: required for `BadType` to implement `IntoJsResult` = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)