Wasm-bindgen: `js-sys` fails to build with nightlies on and after 2020-05-25

Created on 26 May 2020  路  5Comments  路  Source: rustwasm/wasm-bindgen

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

  1. Build js-sys with a toolchain newer than nightly-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 https://github.com/rust-lang/rust/commit/8970e8bcf6153d1ead2283f1a0ed7b192230eca6 to https://github.com/rust-lang/rust/commit/46e85b4328fe18492894093c1092dfe509df4370
regressed commit: https://github.com/rust-lang/rust/commit/7726070fa755f660b5da3f82f46e07d9c6866f69

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.

bug

All 5 comments

Not actually fixed yet, opened https://github.com/rustwasm/wasm-bindgen/pull/2161 to track the errors after #2159 landed.

I opened an issue on syn for the last error: dtolnay/syn#833.

@alexcrichton the issue was fixed by dtolnay/syn#834; with syn 1.0.27 I no longer get the error (locally).

I think if the CI jobs on #2161 run again things should Just Work.

Awesome, thanks so much for your help here @rrbutani!

(Nice sleuthing by the way)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bantic picture bantic  路  4Comments

derekdreery picture derekdreery  路  3Comments

MarcAntoine-Arnaud picture MarcAntoine-Arnaud  路  3Comments

pauldorehill picture pauldorehill  路  3Comments

fitzgen picture fitzgen  路  4Comments