Forward attributes on type declaration to definition

This'll allow things like `#[derive(Clone)]` or `#[derive(Debug)]` to control
traits for these types.
This commit is contained in:
Alex Crichton 2018-07-05 20:28:52 -07:00
parent bc2eab1434
commit 5a776c16b2
3 changed files with 6 additions and 0 deletions

View File

@ -84,6 +84,7 @@ pub struct ImportStatic {
pub struct ImportType {
pub vis: syn::Visibility,
pub name: Ident,
pub attrs: Vec<syn::Attribute>,
}
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
@ -469,6 +470,7 @@ impl Program {
ImportKind::Type(ImportType {
vis: f.vis,
name: f.ident,
attrs: f.attrs,
})
}

View File

@ -505,8 +505,10 @@ impl ToTokens for ast::ImportType {
fn to_tokens(&self, tokens: &mut TokenStream) {
let vis = &self.vis;
let name = &self.name;
let attrs = &self.attrs;
(quote! {
#[allow(bad_style)]
#(#attrs)*
#vis struct #name {
obj: ::wasm_bindgen::JsValue,
}

View File

@ -112,6 +112,7 @@ fn construct() {
#[wasm_bindgen(module = "./another")]
extern {
#[derive(Clone)]
type Foo;
#[wasm_bindgen(js_namespace = Foo)]
fn create() -> Foo;
@ -127,6 +128,7 @@ fn construct() {
pub fn run() {
let f = Foo::create();
assert_eq!(f.get_internal_string(), "this");
assert_eq!(f.clone().get_internal_string(), "this");
f.append_to_internal_string(" foo");
f.assert_internal_string("this foo");
}