diff --git a/crates/macro-support/src/parser.rs b/crates/macro-support/src/parser.rs index 928ec8da3ed..776a7d4aab5 100644 --- a/crates/macro-support/src/parser.rs +++ b/crates/macro-support/src/parser.rs @@ -149,10 +149,10 @@ impl BindgenAttrs { }) } - /// Whether the `host_binding` attribute is present - fn host_binding(&self) -> Option<&Ident> { + /// Whether the `final` attribute is present + fn final_(&self) -> Option<&Ident> { self.attrs.iter().filter_map(|a| match a { - BindgenAttr::HostBinding(i) => Some(i), + BindgenAttr::Final(i) => Some(i), _ => None, }).next() } @@ -237,7 +237,7 @@ pub enum BindgenAttr { IndexingSetter, IndexingDeleter, Structural, - HostBinding(Ident), + Final(Ident), Readonly, JsName(String, Span), JsClass(String), @@ -249,7 +249,8 @@ pub enum BindgenAttr { impl Parse for BindgenAttr { fn parse(input: ParseStream) -> SynResult { let original = input.fork(); - let attr: Ident = input.parse()?; + let attr: AnyIdent = input.parse()?; + let attr = attr.0; if attr == "catch" { return Ok(BindgenAttr::Catch); } @@ -271,8 +272,8 @@ impl Parse for BindgenAttr { if attr == "structural" { return Ok(BindgenAttr::Structural); } - if attr == "host_binding" { - return Ok(BindgenAttr::HostBinding(attr)) + if attr == "final" { + return Ok(BindgenAttr::Final(attr)) } if attr == "readonly" { return Ok(BindgenAttr::Readonly); @@ -555,9 +556,9 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option)> for syn::ForeignItemFn ShortHash(data) ) }; - if let Some(ident) = opts.host_binding() { + if let Some(ident) = opts.final_() { if opts.structural() { - bail_span!(ident, "cannot specify both `structural` and `host_binding`"); + bail_span!(ident, "cannot specify both `structural` and `final`"); } } Ok(ast::ImportKind::Function(ast::ImportFunction { @@ -566,7 +567,7 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option)> for syn::ForeignItemFn js_ret, catch, variadic, - structural: opts.structural() || opts.host_binding().is_none(), + structural: opts.structural() || opts.final_().is_none(), rust_name: self.ident.clone(), shim: Ident::new(&shim, Span::call_site()), doc_comment: None, diff --git a/crates/macro/ui-tests/structural-and-host-binding.rs b/crates/macro/ui-tests/structural-and-final.rs similarity index 70% rename from crates/macro/ui-tests/structural-and-host-binding.rs rename to crates/macro/ui-tests/structural-and-final.rs index 68bfccb41a5..5eb65220f86 100644 --- a/crates/macro/ui-tests/structural-and-host-binding.rs +++ b/crates/macro/ui-tests/structural-and-final.rs @@ -6,6 +6,6 @@ use wasm_bindgen::prelude::*; extern "C" { type Foo; - #[wasm_bindgen(method, structural, host_binding)] + #[wasm_bindgen(method, structural, final)] fn bar(this: &Foo); } diff --git a/crates/macro/ui-tests/structural-and-final.stderr b/crates/macro/ui-tests/structural-and-final.stderr new file mode 100644 index 00000000000..405f65f1880 --- /dev/null +++ b/crates/macro/ui-tests/structural-and-final.stderr @@ -0,0 +1,8 @@ +error: cannot specify both `structural` and `final` + --> $DIR/structural-and-final.rs:9:40 + | +9 | #[wasm_bindgen(method, structural, final)] + | ^^^^^ + +error: aborting due to previous error + diff --git a/crates/macro/ui-tests/structural-and-host-binding.stderr b/crates/macro/ui-tests/structural-and-host-binding.stderr deleted file mode 100644 index 66e6ef670a6..00000000000 --- a/crates/macro/ui-tests/structural-and-host-binding.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: cannot specify both `structural` and `host_binding` - --> $DIR/structural-and-host-binding.rs:9:40 - | -9 | #[wasm_bindgen(method, structural, host_binding)] - | ^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/guide/src/SUMMARY.md b/guide/src/SUMMARY.md index 2db0c17f4e6..952f5b7743f 100644 --- a/guide/src/SUMMARY.md +++ b/guide/src/SUMMARY.md @@ -61,7 +61,7 @@ - [`constructor`](./reference/attributes/on-js-imports/constructor.md) - [`extends`](./reference/attributes/on-js-imports/extends.md) - [`getter` and `setter`](./reference/attributes/on-js-imports/getter-and-setter.md) - - [`host_binding`](./reference/attributes/on-js-imports/host_binding.md) + - [`final`](./reference/attributes/on-js-imports/final.md) - [`indexing_getter`, `indexing_setter`, and `indexing_deleter`](./reference/attributes/on-js-imports/indexing-getter-setter-deleter.md) - [`js_class = "Blah"`](./reference/attributes/on-js-imports/js_class.md) - [`js_name`](./reference/attributes/on-js-imports/js_name.md) diff --git a/guide/src/reference/attributes/on-js-imports/final.md b/guide/src/reference/attributes/on-js-imports/final.md index 0abfa95b5cd..8dc19975f18 100644 --- a/guide/src/reference/attributes/on-js-imports/final.md +++ b/guide/src/reference/attributes/on-js-imports/final.md @@ -12,7 +12,7 @@ prototype chain of an object. The `final` attribute is intended to be purely related to performance. It ideally has no user-visible effect, and `structural` imports (the default) -should be able to transparently switch to `host_binding` eventually. +should be able to transparently switch to `final` eventually. The eventual performance aspect is that with the [host bindings proposal][host-bindings] then `wasm-bindgen` will need to generate far fewer JS diff --git a/tests/wasm/host_binding.js b/tests/wasm/final.js similarity index 100% rename from tests/wasm/host_binding.js rename to tests/wasm/final.js diff --git a/tests/wasm/host_binding.rs b/tests/wasm/final.rs similarity index 63% rename from tests/wasm/host_binding.rs rename to tests/wasm/final.rs index 951cfb867a0..63aa661f596 100644 --- a/tests/wasm/host_binding.rs +++ b/tests/wasm/final.rs @@ -4,23 +4,23 @@ use wasm_bindgen_test::*; #[wasm_bindgen] extern "C" { type Math; - #[wasm_bindgen(static_method_of = Math, host_binding)] + #[wasm_bindgen(static_method_of = Math, final)] fn log(f: f32) -> f32; } -#[wasm_bindgen(module = "tests/wasm/host_binding.js")] +#[wasm_bindgen(module = "tests/wasm/final.js")] extern "C" { type MyType; - #[wasm_bindgen(constructor, host_binding)] + #[wasm_bindgen(constructor, final)] fn new(x: u32) -> MyType; - #[wasm_bindgen(static_method_of = MyType, host_binding)] + #[wasm_bindgen(static_method_of = MyType, final)] fn foo(a: &str) -> String; - #[wasm_bindgen(method, host_binding)] + #[wasm_bindgen(method, final)] fn bar(this: &MyType, arg: bool) -> f32; - #[wasm_bindgen(method, getter, host_binding)] + #[wasm_bindgen(method, getter, final)] fn a(this: &MyType) -> u32; - #[wasm_bindgen(method, setter, host_binding)] + #[wasm_bindgen(method, setter, final)] fn set_a(this: &MyType, a: u32); } diff --git a/tests/wasm/import_class.rs b/tests/wasm/import_class.rs index 34a301e51a9..10ce84cabb0 100644 --- a/tests/wasm/import_class.rs +++ b/tests/wasm/import_class.rs @@ -32,12 +32,12 @@ extern "C" { fn switch_methods_a(); fn switch_methods_b(); type SwitchMethods; - #[wasm_bindgen(constructor, host_binding)] + #[wasm_bindgen(constructor, final)] fn new() -> SwitchMethods; - #[wasm_bindgen(js_namespace = SwitchMethods, host_binding)] + #[wasm_bindgen(js_namespace = SwitchMethods, final)] fn a(); fn switch_methods_called() -> bool; - #[wasm_bindgen(method, host_binding)] + #[wasm_bindgen(method, final)] fn b(this: &SwitchMethods); type Properties; diff --git a/tests/wasm/main.rs b/tests/wasm/main.rs index 4c70f75e198..e0793a78b1f 100644 --- a/tests/wasm/main.rs +++ b/tests/wasm/main.rs @@ -18,7 +18,8 @@ pub mod comments; pub mod duplicate_deps; pub mod duplicates; pub mod enums; -pub mod host_binding; +#[path = "final.rs"] +pub mod final_; pub mod import_class; pub mod imports; pub mod js_objects;