mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-21 16:51:33 +00:00
Disallow both structural
and host_binding
This commit is contained in:
@ -150,11 +150,11 @@ impl BindgenAttrs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the `host_binding` attribute is present
|
/// Whether the `host_binding` attribute is present
|
||||||
fn host_binding(&self) -> bool {
|
fn host_binding(&self) -> Option<&Ident> {
|
||||||
self.attrs.iter().any(|a| match *a {
|
self.attrs.iter().filter_map(|a| match a {
|
||||||
BindgenAttr::HostBinding => true,
|
BindgenAttr::HostBinding(i) => Some(i),
|
||||||
_ => false,
|
_ => None,
|
||||||
})
|
}).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the readonly attributes is present
|
/// Whether the readonly attributes is present
|
||||||
@ -237,7 +237,7 @@ pub enum BindgenAttr {
|
|||||||
IndexingSetter,
|
IndexingSetter,
|
||||||
IndexingDeleter,
|
IndexingDeleter,
|
||||||
Structural,
|
Structural,
|
||||||
HostBinding,
|
HostBinding(Ident),
|
||||||
Readonly,
|
Readonly,
|
||||||
JsName(String, Span),
|
JsName(String, Span),
|
||||||
JsClass(String),
|
JsClass(String),
|
||||||
@ -272,7 +272,7 @@ impl Parse for BindgenAttr {
|
|||||||
return Ok(BindgenAttr::Structural);
|
return Ok(BindgenAttr::Structural);
|
||||||
}
|
}
|
||||||
if attr == "host_binding" {
|
if attr == "host_binding" {
|
||||||
return Ok(BindgenAttr::HostBinding);
|
return Ok(BindgenAttr::HostBinding(attr))
|
||||||
}
|
}
|
||||||
if attr == "readonly" {
|
if attr == "readonly" {
|
||||||
return Ok(BindgenAttr::Readonly);
|
return Ok(BindgenAttr::Readonly);
|
||||||
@ -555,13 +555,18 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
|
|||||||
ShortHash(data)
|
ShortHash(data)
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
if let Some(ident) = opts.host_binding() {
|
||||||
|
if opts.structural() {
|
||||||
|
bail_span!(ident, "cannot specify both `structural` and `host_binding`");
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(ast::ImportKind::Function(ast::ImportFunction {
|
Ok(ast::ImportKind::Function(ast::ImportFunction {
|
||||||
function: wasm,
|
function: wasm,
|
||||||
kind,
|
kind,
|
||||||
js_ret,
|
js_ret,
|
||||||
catch,
|
catch,
|
||||||
variadic,
|
variadic,
|
||||||
structural: opts.structural() || !opts.host_binding(),
|
structural: opts.structural() || opts.host_binding().is_none(),
|
||||||
rust_name: self.ident.clone(),
|
rust_name: self.ident.clone(),
|
||||||
shim: Ident::new(&shim, Span::call_site()),
|
shim: Ident::new(&shim, Span::call_site()),
|
||||||
doc_comment: None,
|
doc_comment: None,
|
||||||
|
11
crates/macro/ui-tests/structural-and-host-binding.rs
Normal file
11
crates/macro/ui-tests/structural-and-host-binding.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
extern crate wasm_bindgen;
|
||||||
|
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
|
type Foo;
|
||||||
|
|
||||||
|
#[wasm_bindgen(method, structural, host_binding)]
|
||||||
|
fn bar(this: &Foo);
|
||||||
|
}
|
8
crates/macro/ui-tests/structural-and-host-binding.stderr
Normal file
8
crates/macro/ui-tests/structural-and-host-binding.stderr
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
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
|
||||||
|
|
Reference in New Issue
Block a user