From d24a67e6bb39912af8c47d60f7614d875bd71307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Florkiewicz?= Date: Wed, 11 Dec 2024 07:44:31 +0100 Subject: [PATCH 1/6] fix: Fix cfg_attr in struct declaration --- crates/macro-support/src/lib.rs | 52 +++++++++++++++++++++++++++++- crates/macro-support/src/parser.rs | 26 ++++++--------- crates/macro/src/lib.rs | 13 ++++++++ src/lib.rs | 1 + tests/wasm/classes.rs | 10 ++++++ 5 files changed, 85 insertions(+), 17 deletions(-) diff --git a/crates/macro-support/src/lib.rs b/crates/macro-support/src/lib.rs index dd609f42260..3c7fda2d37f 100644 --- a/crates/macro-support/src/lib.rs +++ b/crates/macro-support/src/lib.rs @@ -12,7 +12,7 @@ extern crate wasm_bindgen_backend as backend; extern crate wasm_bindgen_shared as shared; pub use crate::parser::BindgenAttrs; -use crate::parser::MacroParse; +use crate::parser::{ConvertToAst, MacroParse}; use backend::{Diagnostic, TryToTokens}; use proc_macro2::TokenStream; use quote::ToTokens; @@ -24,7 +24,41 @@ mod parser; /// Takes the parsed input from a `#[wasm_bindgen]` macro and returns the generated bindings pub fn expand(attr: TokenStream, input: TokenStream) -> Result { parser::reset_attrs_used(); + // if struct is encountered, add `derive` attribute and let everything happen there (workaround + // to help parsing cfg_attr correctly). let item = syn::parse2::(input)?; + if let syn::Item::Struct(mut s) = item { + s.attrs.insert( + 0, + syn::Attribute { + pound_token: Default::default(), + style: syn::AttrStyle::Outer, + bracket_token: Default::default(), + meta: syn::parse_quote! { + derive(wasm_bindgen::prelude::BindgenedStruct) + }, + }, + ); + if !attr.is_empty() { + let meta: syn::Meta = syn::parse2(attr)?; + s.attrs.insert( + 1, + syn::Attribute { + pound_token: Default::default(), + style: syn::AttrStyle::Outer, + bracket_token: Default::default(), + meta: syn::parse_quote! { + wasm_bindgen(#meta) + }, + }, + ); + } + + let mut tokens = proc_macro2::TokenStream::new(); + s.to_tokens(&mut tokens); + return Ok(tokens); + } + let opts = syn::parse2(attr)?; let mut tokens = proc_macro2::TokenStream::new(); @@ -168,3 +202,19 @@ impl Parse for ClassMarker { }) } } + +pub fn expand_struct_marker(item: TokenStream) -> Result { + parser::reset_attrs_used(); + + let mut s: syn::ItemStruct = syn::parse2(item)?; + + let mut program = backend::ast::Program::default(); + program.structs.push((&mut s).convert(&program)?); + + let mut tokens = proc_macro2::TokenStream::new(); + program.try_to_tokens(&mut tokens)?; + + parser::check_unused_attrs(&mut tokens); + + Ok(tokens) +} diff --git a/crates/macro-support/src/parser.rs b/crates/macro-support/src/parser.rs index 46c76a1ef21..03f74f77e7d 100644 --- a/crates/macro-support/src/parser.rs +++ b/crates/macro-support/src/parser.rs @@ -493,7 +493,7 @@ impl Parse for AnyIdent { /// /// Used to convert syn tokens into an AST, that we can then use to generate glue code. The context /// (`Ctx`) is used to pass in the attributes from the `#[wasm_bindgen]`, if needed. -trait ConvertToAst { +pub(crate) trait ConvertToAst { /// What we are converting to. type Target; /// Convert into our target. @@ -502,13 +502,10 @@ trait ConvertToAst { fn convert(self, context: Ctx) -> Result; } -impl ConvertToAst<(&ast::Program, BindgenAttrs)> for &mut syn::ItemStruct { +impl ConvertToAst<&ast::Program> for &mut syn::ItemStruct { type Target = ast::Struct; - fn convert( - self, - (program, attrs): (&ast::Program, BindgenAttrs), - ) -> Result { + fn convert(self, program: &ast::Program) -> Result { if !self.generics.params.is_empty() { bail_span!( self.generics, @@ -516,8 +513,10 @@ impl ConvertToAst<(&ast::Program, BindgenAttrs)> for &mut syn::ItemStruct { type parameters currently" ); } + let struct_attrs = BindgenAttrs::find(&mut self.attrs)?; + let mut fields = Vec::new(); - let js_name = attrs + let js_name = struct_attrs .js_name() .map(|s| s.0.to_string()) .unwrap_or(self.ident.unraw().to_string()); @@ -529,8 +528,8 @@ impl ConvertToAst<(&ast::Program, BindgenAttrs)> for &mut syn::ItemStruct { ); } - let is_inspectable = attrs.inspectable().is_some(); - let getter_with_clone = attrs.getter_with_clone(); + let is_inspectable = struct_attrs.inspectable().is_some(); + let getter_with_clone = struct_attrs.getter_with_clone(); for (i, field) in self.fields.iter_mut().enumerate() { match field.vis { syn::Visibility::Public(..) => {} @@ -572,9 +571,9 @@ impl ConvertToAst<(&ast::Program, BindgenAttrs)> for &mut syn::ItemStruct { }); attrs.check_used(); } - let generate_typescript = attrs.skip_typescript().is_none(); + let generate_typescript = struct_attrs.skip_typescript().is_none(); let comments: Vec = extract_doc_comments(&self.attrs); - attrs.check_used(); + struct_attrs.check_used(); Ok(ast::Struct { rust_name: self.ident.clone(), js_name, @@ -1231,11 +1230,6 @@ impl<'a> MacroParse<(Option, &'a mut TokenStream)> for syn::Item { wasm_bindgen_futures: program.wasm_bindgen_futures.clone(), }); } - syn::Item::Struct(mut s) => { - let opts = opts.unwrap_or_default(); - program.structs.push((&mut s).convert((program, opts))?); - s.to_tokens(tokens); - } syn::Item::Impl(mut i) => { let opts = opts.unwrap_or_default(); (&mut i).macro_parse(program, opts)?; diff --git a/crates/macro/src/lib.rs b/crates/macro/src/lib.rs index 85ef2f6c2a8..51656f335ee 100644 --- a/crates/macro/src/lib.rs +++ b/crates/macro/src/lib.rs @@ -60,3 +60,16 @@ pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> Tok Err(diagnostic) => (quote! { #diagnostic }).into(), } } + +#[proc_macro_derive(BindgenedStruct, attributes(wasm_bindgen))] +pub fn __wasm_bindgen_struct_marker(item: TokenStream) -> TokenStream { + match wasm_bindgen_macro_support::expand_struct_marker(item.into()) { + Ok(tokens) => { + if cfg!(feature = "xxx_debug_only_print_generated_code") { + println!("{}", tokens); + } + tokens.into() + } + Err(diagnostic) => (quote! { #diagnostic }).into(), + } +} diff --git a/src/lib.rs b/src/lib.rs index 0c81941bc39..6532964b4ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,6 +101,7 @@ pub mod prelude { pub use crate::JsCast; pub use crate::JsValue; pub use crate::UnwrapThrowExt; + pub use wasm_bindgen_macro::BindgenedStruct; #[doc(hidden)] pub use wasm_bindgen_macro::__wasm_bindgen_class_marker; pub use wasm_bindgen_macro::wasm_bindgen; diff --git a/tests/wasm/classes.rs b/tests/wasm/classes.rs index d701e2088ed..20930cda7f3 100644 --- a/tests/wasm/classes.rs +++ b/tests/wasm/classes.rs @@ -480,6 +480,16 @@ fn renamed_field() { js_renamed_field(); } +#[cfg_attr(target_arch = "wasm32", wasm_bindgen)] +pub struct ConditionalSkip { + #[cfg_attr(target_arch = "wasm32", wasm_bindgen(skip))] + pub skipped_field: [u8; 8], + + /// cfg_attr annotated field + #[cfg_attr(target_arch = "wasm32", wasm_bindgen(getter_with_clone))] + pub needs_clone: String, +} + #[cfg_attr(target_arch = "wasm32", wasm_bindgen)] pub struct ConditionalBindings {} From 76383aed4d93687f75f604b79cd7788345efd1f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Florkiewicz?= Date: Wed, 11 Dec 2024 10:14:31 +0100 Subject: [PATCH 2/6] Update ui-tests expected results. --- crates/macro/ui-tests/import-keyword.stderr | 14 ++++++++++++++ crates/macro/ui-tests/pub-not-copy.stderr | 6 +++--- crates/macro/ui-tests/struct-fields.stderr | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/macro/ui-tests/import-keyword.stderr b/crates/macro/ui-tests/import-keyword.stderr index ecc9f087ded..b2c3d8e3fd3 100644 --- a/crates/macro/ui-tests/import-keyword.stderr +++ b/crates/macro/ui-tests/import-keyword.stderr @@ -57,3 +57,17 @@ error: enum cannot use the JS keyword `switch` as its name | 63 | pub enum switch { | ^^^^^^ + +warning: type `class` should have an upper camel case name + --> ui-tests/import-keyword.rs:59:12 + | +59 | pub struct class; + | ^^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Class` + | + = note: `#[warn(non_camel_case_types)]` on by default + +warning: type `true` should have an upper camel case name + --> ui-tests/import-keyword.rs:61:12 + | +61 | pub struct r#true; // forbid value-like keywords + | ^^^^^^ help: convert the identifier to upper camel case: `True` diff --git a/crates/macro/ui-tests/pub-not-copy.stderr b/crates/macro/ui-tests/pub-not-copy.stderr index e8f1c2c820f..2e35ee0b25c 100644 --- a/crates/macro/ui-tests/pub-not-copy.stderr +++ b/crates/macro/ui-tests/pub-not-copy.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `String: std::marker::Copy` is not satisfied - --> $DIR/pub-not-copy.rs:5:16 + --> ui-tests/pub-not-copy.rs:5:16 | 3 | #[wasm_bindgen] | --------------- in this procedural macro expansion @@ -8,8 +8,8 @@ error[E0277]: the trait bound `String: std::marker::Copy` is not satisfied | ^^^^^^ the trait `std::marker::Copy` is not implemented for `String` | note: required by a bound in `assert_copy` - --> $DIR/pub-not-copy.rs:3:1 + --> ui-tests/pub-not-copy.rs:3:1 | 3 | #[wasm_bindgen] | ^^^^^^^^^^^^^^^ required by this bound in `assert_copy` - = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `wasm_bindgen::prelude::BindgenedStruct` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/macro/ui-tests/struct-fields.stderr b/crates/macro/ui-tests/struct-fields.stderr index f38391b27d8..c963044160e 100644 --- a/crates/macro/ui-tests/struct-fields.stderr +++ b/crates/macro/ui-tests/struct-fields.stderr @@ -12,7 +12,7 @@ note: required by a bound in `__wbg_get_bar_a::assert_copy` | 8 | #[wasm_bindgen] | ^^^^^^^^^^^^^^^ required by this bound in `assert_copy` - = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `wasm_bindgen::prelude::BindgenedStruct` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Foo: Clone` is not satisfied --> ui-tests/struct-fields.rs:12:12 From e2b2b33aba82bc8f9d0eaef2cf3fb0023464caa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Florkiewicz?= Date: Wed, 11 Dec 2024 18:08:09 +0100 Subject: [PATCH 3/6] Fix multiplle params in class attribute --- crates/macro-support/src/lib.rs | 3 +-- tests/wasm/classes.rs | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/macro-support/src/lib.rs b/crates/macro-support/src/lib.rs index 3c7fda2d37f..0c51985e3dc 100644 --- a/crates/macro-support/src/lib.rs +++ b/crates/macro-support/src/lib.rs @@ -40,7 +40,6 @@ pub fn expand(attr: TokenStream, input: TokenStream) -> Result Result Date: Fri, 10 Jan 2025 15:37:34 +0100 Subject: [PATCH 4/6] Add PR review updates --- crates/macro-support/src/lib.rs | 44 +++++++--------------- crates/macro-support/src/parser.rs | 20 +++++----- crates/macro/ui-tests/pub-not-copy.stderr | 2 +- crates/macro/ui-tests/struct-fields.stderr | 2 +- src/lib.rs | 1 - src/rt/mod.rs | 2 + tests/wasm/classes.js | 7 ++++ tests/wasm/classes.rs | 25 +++++++++++- 8 files changed, 59 insertions(+), 44 deletions(-) diff --git a/crates/macro-support/src/lib.rs b/crates/macro-support/src/lib.rs index 0c51985e3dc..3070be02807 100644 --- a/crates/macro-support/src/lib.rs +++ b/crates/macro-support/src/lib.rs @@ -15,6 +15,7 @@ pub use crate::parser::BindgenAttrs; use crate::parser::{ConvertToAst, MacroParse}; use backend::{Diagnostic, TryToTokens}; use proc_macro2::TokenStream; +use quote::quote; use quote::ToTokens; use quote::TokenStreamExt; use syn::parse::{Parse, ParseStream, Result as SynResult}; @@ -27,39 +28,22 @@ pub fn expand(attr: TokenStream, input: TokenStream) -> Result(input)?; - if let syn::Item::Struct(mut s) = item { - s.attrs.insert( - 0, - syn::Attribute { - pound_token: Default::default(), - style: syn::AttrStyle::Outer, - bracket_token: Default::default(), - meta: syn::parse_quote! { - derive(wasm_bindgen::prelude::BindgenedStruct) - }, - }, - ); - if !attr.is_empty() { - s.attrs.insert( - 1, - syn::Attribute { - pound_token: Default::default(), - style: syn::AttrStyle::Outer, - bracket_token: Default::default(), - meta: syn::parse_quote! { - wasm_bindgen(#attr) - }, - }, - ); - } - - let mut tokens = proc_macro2::TokenStream::new(); - s.to_tokens(&mut tokens); - return Ok(tokens); + if let syn::Item::Struct(s) = item { + let opts: BindgenAttrs = syn::parse2(attr.clone())?; + let wasm_bindgen = opts + .wasm_bindgen() + .cloned() + .unwrap_or_else(|| syn::parse_quote! { wasm_bindgen }); + + let item = quote! { + #[derive(#wasm_bindgen::__rt::BindgenedStruct)] + #[wasm_bindgen(#attr)] + #s + }; + return Ok(item); } let opts = syn::parse2(attr)?; - let mut tokens = proc_macro2::TokenStream::new(); let mut program = backend::ast::Program::default(); item.macro_parse(&mut program, (Some(opts), &mut tokens))?; diff --git a/crates/macro-support/src/parser.rs b/crates/macro-support/src/parser.rs index 03f74f77e7d..083d06bf966 100644 --- a/crates/macro-support/src/parser.rs +++ b/crates/macro-support/src/parser.rs @@ -216,7 +216,7 @@ macro_rules! methods { }; (@method $name:ident, $variant:ident(Span, String, Span)) => { - fn $name(&self) -> Option<(&str, Span)> { + pub(crate) fn $name(&self) -> Option<(&str, Span)> { self.attrs .iter() .find_map(|a| match &a.1 { @@ -230,7 +230,7 @@ macro_rules! methods { }; (@method $name:ident, $variant:ident(Span, JsNamespace, Vec)) => { - fn $name(&self) -> Option<(JsNamespace, &[Span])> { + pub(crate) fn $name(&self) -> Option<(JsNamespace, &[Span])> { self.attrs .iter() .find_map(|a| match &a.1 { @@ -245,7 +245,7 @@ macro_rules! methods { (@method $name:ident, $variant:ident(Span, $($other:tt)*)) => { #[allow(unused)] - fn $name(&self) -> Option<&$($other)*> { + pub(crate) fn $name(&self) -> Option<&$($other)*> { self.attrs .iter() .find_map(|a| match &a.1 { @@ -260,7 +260,7 @@ macro_rules! methods { (@method $name:ident, $variant:ident($($other:tt)*)) => { #[allow(unused)] - fn $name(&self) -> Option<&$($other)*> { + pub(crate) fn $name(&self) -> Option<&$($other)*> { self.attrs .iter() .find_map(|a| match &a.1 { @@ -513,10 +513,10 @@ impl ConvertToAst<&ast::Program> for &mut syn::ItemStruct { type parameters currently" ); } - let struct_attrs = BindgenAttrs::find(&mut self.attrs)?; + let attrs = BindgenAttrs::find(&mut self.attrs)?; let mut fields = Vec::new(); - let js_name = struct_attrs + let js_name = attrs .js_name() .map(|s| s.0.to_string()) .unwrap_or(self.ident.unraw().to_string()); @@ -528,8 +528,8 @@ impl ConvertToAst<&ast::Program> for &mut syn::ItemStruct { ); } - let is_inspectable = struct_attrs.inspectable().is_some(); - let getter_with_clone = struct_attrs.getter_with_clone(); + let is_inspectable = attrs.inspectable().is_some(); + let getter_with_clone = attrs.getter_with_clone(); for (i, field) in self.fields.iter_mut().enumerate() { match field.vis { syn::Visibility::Public(..) => {} @@ -571,9 +571,9 @@ impl ConvertToAst<&ast::Program> for &mut syn::ItemStruct { }); attrs.check_used(); } - let generate_typescript = struct_attrs.skip_typescript().is_none(); + let generate_typescript = attrs.skip_typescript().is_none(); let comments: Vec = extract_doc_comments(&self.attrs); - struct_attrs.check_used(); + attrs.check_used(); Ok(ast::Struct { rust_name: self.ident.clone(), js_name, diff --git a/crates/macro/ui-tests/pub-not-copy.stderr b/crates/macro/ui-tests/pub-not-copy.stderr index 2e35ee0b25c..665f38c2bfd 100644 --- a/crates/macro/ui-tests/pub-not-copy.stderr +++ b/crates/macro/ui-tests/pub-not-copy.stderr @@ -12,4 +12,4 @@ note: required by a bound in `assert_copy` | 3 | #[wasm_bindgen] | ^^^^^^^^^^^^^^^ required by this bound in `assert_copy` - = note: this error originates in the derive macro `wasm_bindgen::prelude::BindgenedStruct` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `wasm_bindgen::__rt::BindgenedStruct` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/macro/ui-tests/struct-fields.stderr b/crates/macro/ui-tests/struct-fields.stderr index c963044160e..0005e6740eb 100644 --- a/crates/macro/ui-tests/struct-fields.stderr +++ b/crates/macro/ui-tests/struct-fields.stderr @@ -12,7 +12,7 @@ note: required by a bound in `__wbg_get_bar_a::assert_copy` | 8 | #[wasm_bindgen] | ^^^^^^^^^^^^^^^ required by this bound in `assert_copy` - = note: this error originates in the derive macro `wasm_bindgen::prelude::BindgenedStruct` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `wasm_bindgen::__rt::BindgenedStruct` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Foo: Clone` is not satisfied --> ui-tests/struct-fields.rs:12:12 diff --git a/src/lib.rs b/src/lib.rs index 6532964b4ee..0c81941bc39 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,7 +101,6 @@ pub mod prelude { pub use crate::JsCast; pub use crate::JsValue; pub use crate::UnwrapThrowExt; - pub use wasm_bindgen_macro::BindgenedStruct; #[doc(hidden)] pub use wasm_bindgen_macro::__wasm_bindgen_class_marker; pub use wasm_bindgen_macro::wasm_bindgen; diff --git a/src/rt/mod.rs b/src/rt/mod.rs index c4b104abf4d..2f5d1b06adb 100644 --- a/src/rt/mod.rs +++ b/src/rt/mod.rs @@ -19,6 +19,8 @@ pub extern crate std; pub mod marker; +pub use wasm_bindgen_macro::BindgenedStruct; + /// Wrapper around [`Lazy`] adding `Send + Sync` when `atomics` is not enabled. pub struct LazyCell T>(Wrapper>); diff --git a/tests/wasm/classes.js b/tests/wasm/classes.js index 5317dbb0137..08960722c8c 100644 --- a/tests/wasm/classes.js +++ b/tests/wasm/classes.js @@ -170,6 +170,13 @@ exports.js_renamed_field = () => { x.foo(); } +exports.js_conditional_skip = () => { + const x = new wasm.ConditionalSkipClass(); + assert.strictEqual(x.skipped_field, undefined); + assert.ok(x.not_skipped_field === 42); + assert.strictEqual(x.needs_clone, 'foo'); +} + exports.js_conditional_bindings = () => { const x = new wasm.ConditionalBindings(); x.free(); diff --git a/tests/wasm/classes.rs b/tests/wasm/classes.rs index 67d1df82534..80acca1a837 100644 --- a/tests/wasm/classes.rs +++ b/tests/wasm/classes.rs @@ -24,6 +24,7 @@ extern "C" { fn js_access_fields(); fn js_renamed_export(); fn js_renamed_field(); + fn js_conditional_skip(); fn js_conditional_bindings(); fn js_assert_none(a: Option); @@ -485,14 +486,36 @@ fn renamed_field() { wasm_bindgen(inspectable, js_name = "ConditionalSkipClass") )] pub struct ConditionalSkip { + /// [u8; 8] cannot be passed to JS, so this won't compile without `skip` #[cfg_attr(target_arch = "wasm32", wasm_bindgen(skip))] pub skipped_field: [u8; 8], - /// cfg_attr annotated field + /// this field shouldn't be skipped as predicate is false + #[cfg_attr(all(target_arch = "wasm32", target_arch = "x86"), wasm_bindgen(skip))] + pub not_skipped_field: u32, + + /// String struct field requires `getter_with_clone` to compile #[cfg_attr(target_arch = "wasm32", wasm_bindgen(getter_with_clone))] pub needs_clone: String, } +#[wasm_bindgen(js_class = "ConditionalSkipClass")] +impl ConditionalSkip { + #[wasm_bindgen(constructor)] + pub fn new() -> ConditionalSkip { + ConditionalSkip { + skipped_field: [0u8; 8], + not_skipped_field: 42, + needs_clone: "foo".to_string(), + } + } +} + +#[wasm_bindgen_test] +fn conditional_skip() { + js_conditional_skip(); +} + #[cfg_attr(target_arch = "wasm32", wasm_bindgen)] pub struct ConditionalBindings {} From 5ca69863f58e081c39c9a93c6ed69d2e52b1aa2b Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sat, 11 Jan 2025 21:27:28 +0100 Subject: [PATCH 5/6] Revert some unrelated changes --- crates/macro/ui-tests/pub-not-copy.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/macro/ui-tests/pub-not-copy.stderr b/crates/macro/ui-tests/pub-not-copy.stderr index 665f38c2bfd..a7d2930b854 100644 --- a/crates/macro/ui-tests/pub-not-copy.stderr +++ b/crates/macro/ui-tests/pub-not-copy.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `String: std::marker::Copy` is not satisfied - --> ui-tests/pub-not-copy.rs:5:16 + --> $DIR/pub-not-copy.rs:5:16 | 3 | #[wasm_bindgen] | --------------- in this procedural macro expansion @@ -8,7 +8,7 @@ error[E0277]: the trait bound `String: std::marker::Copy` is not satisfied | ^^^^^^ the trait `std::marker::Copy` is not implemented for `String` | note: required by a bound in `assert_copy` - --> ui-tests/pub-not-copy.rs:3:1 + --> $DIR/pub-not-copy.rs:3:1 | 3 | #[wasm_bindgen] | ^^^^^^^^^^^^^^^ required by this bound in `assert_copy` From dc4ed504ed50baa91a16871fbaf4bc5e48c7d4e9 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sat, 11 Jan 2025 21:29:45 +0100 Subject: [PATCH 6/6] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f144ab366c6..e12bd4560de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ * Add bindings to `Date.to_locale_time_string_with_options`. [#4384](https://github.com/rustwasm/wasm-bindgen/pull/4384) +* `#[wasm_bindgen]` now correctly applies `#[cfg(...)]`s in `struct`s. + [#4351](https://github.com/rustwasm/wasm-bindgen/pull/4351) + + ### Changed * Optional parameters are now typed as `T | undefined | null` to reflect the actual JS behavior.