Description
Describe the Bug
js-sys
fails to build with rustc
nightlies on and after nightly-2020-05-25
.
error: return value of constructor must be a bare path
--> <snipped>/.cargo/registry/src/github.com-1ecc6299db9ec823/js-sys-0.3.39/src/lib.rs:4795:13
|
4795 | / /// The
4796 | | #[doc = $ctor]
4797 | | /// constructor creates an array of unsigned 8-bit integers.
4798 | | ///
... |
4802 | | #[wasm_bindgen(constructor)]
4803 | | pub fn new(constructor_arg: &JsValue) -> $name;
| |___________________________________________________________^
...
4999 | / arrays! {
5000 | | /// `Int8Array()`
5001 | | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
5002 | | Int8Array: i8,
... |
5034 | | Float64Array: f64,
5035 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: return value of constructor must be a bare path
--> <snipped>/.cargo/registry/src/github.com-1ecc6299db9ec823/js-sys-0.3.39/src/lib.rs:4805:13
|
4805 | / /// An
4806 | | #[doc = $ctor]
4807 | | /// which creates an array with an internal buffer large
4808 | | /// enough for `length` elements.
... |
4813 | | #[wasm_bindgen(constructor)]
4814 | | pub fn new_with_length(length: u32) -> $name;
| |_________________________________________________________^
Steps to Reproduce
- Build
js-sys
with a toolchain newer thannightly-2020-05-24
:
rustup install nightly-2020-05-25
cargo +nightly-2020-05-25 build -p js-sys
Expected Behavior
The build succeeds!
Actual Behavior
The build does not succeed.
Additional Context
Running cargo-bisect-rustc pins it down to this rollup and from there it's fairly straightforward to pick out rust-lang/rust#72388.
Here's the output from cargo-bisect-rustc
if it helps:
bisected with cargo-bisect-rustc v0.5.1
searched nightlies: from nightly-2020-05-24 to nightly-2020-05-26
regressed nightly: nightly-2020-05-25
searched commits: from rust-lang/rust@8970e8b to rust-lang/rust@46e85b4
regressed commit: rust-lang/rust@7726070
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
cargo bisect-rustc -- check --target x86_64-unknown-linux-gnu
The cause of this error, as best as I can tell, is that $name
in this macro goes from being passed to #[wasm_bindgen]
as a syn::Type::Path
to being passed in as a syn::Group
containing the syn::Type::Path
that the macro wants (as in the span that $name
is in isn't discarded). wasm_bindgen
's parser doesn't know to handle this (here and here) and so we get the errors above.
There's already an issue open in rust-lang/rust for this: rust-lang/rust#72545. For that specific issue the crate in question was using proc-macro-hack
but as shown the same change can also break proc macros that don't use it.