Skip to content

Commit cb246e3

Browse files
committed
Rename host_binding to final
1 parent 2c9084d commit cb246e3

File tree

10 files changed

+34
-32
lines changed

10 files changed

+34
-32
lines changed

crates/macro-support/src/parser.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ impl BindgenAttrs {
149149
})
150150
}
151151

152-
/// Whether the `host_binding` attribute is present
153-
fn host_binding(&self) -> Option<&Ident> {
152+
/// Whether the `final` attribute is present
153+
fn final_(&self) -> Option<&Ident> {
154154
self.attrs.iter().filter_map(|a| match a {
155-
BindgenAttr::HostBinding(i) => Some(i),
155+
BindgenAttr::Final(i) => Some(i),
156156
_ => None,
157157
}).next()
158158
}
@@ -237,7 +237,7 @@ pub enum BindgenAttr {
237237
IndexingSetter,
238238
IndexingDeleter,
239239
Structural,
240-
HostBinding(Ident),
240+
Final(Ident),
241241
Readonly,
242242
JsName(String, Span),
243243
JsClass(String),
@@ -249,7 +249,8 @@ pub enum BindgenAttr {
249249
impl Parse for BindgenAttr {
250250
fn parse(input: ParseStream) -> SynResult<Self> {
251251
let original = input.fork();
252-
let attr: Ident = input.parse()?;
252+
let attr: AnyIdent = input.parse()?;
253+
let attr = attr.0;
253254
if attr == "catch" {
254255
return Ok(BindgenAttr::Catch);
255256
}
@@ -271,8 +272,8 @@ impl Parse for BindgenAttr {
271272
if attr == "structural" {
272273
return Ok(BindgenAttr::Structural);
273274
}
274-
if attr == "host_binding" {
275-
return Ok(BindgenAttr::HostBinding(attr))
275+
if attr == "final" {
276+
return Ok(BindgenAttr::Final(attr))
276277
}
277278
if attr == "readonly" {
278279
return Ok(BindgenAttr::Readonly);
@@ -555,9 +556,9 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
555556
ShortHash(data)
556557
)
557558
};
558-
if let Some(ident) = opts.host_binding() {
559+
if let Some(ident) = opts.final_() {
559560
if opts.structural() {
560-
bail_span!(ident, "cannot specify both `structural` and `host_binding`");
561+
bail_span!(ident, "cannot specify both `structural` and `final`");
561562
}
562563
}
563564
Ok(ast::ImportKind::Function(ast::ImportFunction {
@@ -566,7 +567,7 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
566567
js_ret,
567568
catch,
568569
variadic,
569-
structural: opts.structural() || opts.host_binding().is_none(),
570+
structural: opts.structural() || opts.final_().is_none(),
570571
rust_name: self.ident.clone(),
571572
shim: Ident::new(&shim, Span::call_site()),
572573
doc_comment: None,

crates/macro/ui-tests/structural-and-host-binding.rs renamed to crates/macro/ui-tests/structural-and-final.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ use wasm_bindgen::prelude::*;
66
extern "C" {
77
type Foo;
88

9-
#[wasm_bindgen(method, structural, host_binding)]
9+
#[wasm_bindgen(method, structural, final)]
1010
fn bar(this: &Foo);
1111
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: cannot specify both `structural` and `final`
2+
--> $DIR/structural-and-final.rs:9:40
3+
|
4+
9 | #[wasm_bindgen(method, structural, final)]
5+
| ^^^^^
6+
7+
error: aborting due to previous error
8+

crates/macro/ui-tests/structural-and-host-binding.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

guide/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
- [`constructor`](./reference/attributes/on-js-imports/constructor.md)
6262
- [`extends`](./reference/attributes/on-js-imports/extends.md)
6363
- [`getter` and `setter`](./reference/attributes/on-js-imports/getter-and-setter.md)
64-
- [`host_binding`](./reference/attributes/on-js-imports/host_binding.md)
64+
- [`final`](./reference/attributes/on-js-imports/final.md)
6565
- [`indexing_getter`, `indexing_setter`, and `indexing_deleter`](./reference/attributes/on-js-imports/indexing-getter-setter-deleter.md)
6666
- [`js_class = "Blah"`](./reference/attributes/on-js-imports/js_class.md)
6767
- [`js_name`](./reference/attributes/on-js-imports/js_name.md)

guide/src/reference/attributes/on-js-imports/final.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ prototype chain of an object.
1212

1313
The `final` attribute is intended to be purely related to performance. It
1414
ideally has no user-visible effect, and `structural` imports (the default)
15-
should be able to transparently switch to `host_binding` eventually.
15+
should be able to transparently switch to `final` eventually.
1616

1717
The eventual performance aspect is that with the [host bindings
1818
proposal][host-bindings] then `wasm-bindgen` will need to generate far fewer JS
File renamed without changes.

tests/wasm/host_binding.rs renamed to tests/wasm/final.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ use wasm_bindgen_test::*;
44
#[wasm_bindgen]
55
extern "C" {
66
type Math;
7-
#[wasm_bindgen(static_method_of = Math, host_binding)]
7+
#[wasm_bindgen(static_method_of = Math, final)]
88
fn log(f: f32) -> f32;
99
}
1010

11-
#[wasm_bindgen(module = "tests/wasm/host_binding.js")]
11+
#[wasm_bindgen(module = "tests/wasm/final.js")]
1212
extern "C" {
1313
type MyType;
14-
#[wasm_bindgen(constructor, host_binding)]
14+
#[wasm_bindgen(constructor, final)]
1515
fn new(x: u32) -> MyType;
16-
#[wasm_bindgen(static_method_of = MyType, host_binding)]
16+
#[wasm_bindgen(static_method_of = MyType, final)]
1717
fn foo(a: &str) -> String;
18-
#[wasm_bindgen(method, host_binding)]
18+
#[wasm_bindgen(method, final)]
1919
fn bar(this: &MyType, arg: bool) -> f32;
2020

21-
#[wasm_bindgen(method, getter, host_binding)]
21+
#[wasm_bindgen(method, getter, final)]
2222
fn a(this: &MyType) -> u32;
23-
#[wasm_bindgen(method, setter, host_binding)]
23+
#[wasm_bindgen(method, setter, final)]
2424
fn set_a(this: &MyType, a: u32);
2525
}
2626

tests/wasm/import_class.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ extern "C" {
3232
fn switch_methods_a();
3333
fn switch_methods_b();
3434
type SwitchMethods;
35-
#[wasm_bindgen(constructor, host_binding)]
35+
#[wasm_bindgen(constructor, final)]
3636
fn new() -> SwitchMethods;
37-
#[wasm_bindgen(js_namespace = SwitchMethods, host_binding)]
37+
#[wasm_bindgen(js_namespace = SwitchMethods, final)]
3838
fn a();
3939
fn switch_methods_called() -> bool;
40-
#[wasm_bindgen(method, host_binding)]
40+
#[wasm_bindgen(method, final)]
4141
fn b(this: &SwitchMethods);
4242

4343
type Properties;

tests/wasm/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ pub mod comments;
1818
pub mod duplicate_deps;
1919
pub mod duplicates;
2020
pub mod enums;
21-
pub mod host_binding;
21+
#[path = "final.rs"]
22+
pub mod final_;
2223
pub mod import_class;
2324
pub mod imports;
2425
pub mod js_objects;

0 commit comments

Comments
 (0)