diff --git a/syntax/impls.rs b/syntax/impls.rs index 57b42d11..27aa43ac 100644 --- a/syntax/impls.rs +++ b/syntax/impls.rs @@ -116,6 +116,7 @@ impl PartialEq for Signature { args, ret, throws, + tokens: _, } = self; let Signature { fn_token: _, @@ -123,6 +124,7 @@ impl PartialEq for Signature { args: args2, ret: ret2, throws: throws2, + tokens: _, } = other; receiver == receiver2 && args == args2 && ret == ret2 && throws == throws2 } @@ -136,6 +138,7 @@ impl Hash for Signature { args, ret, throws, + tokens: _, } = self; receiver.hash(state); args.hash(state); diff --git a/syntax/mod.rs b/syntax/mod.rs index 6274cf1a..7d2ca19d 100644 --- a/syntax/mod.rs +++ b/syntax/mod.rs @@ -12,7 +12,7 @@ pub mod set; mod tokens; pub mod types; -use proc_macro2::{Ident, Span}; +use proc_macro2::{Ident, Span, TokenStream}; use syn::{LitStr, Token}; pub use self::atom::Atom; @@ -57,6 +57,7 @@ pub struct Signature { pub args: Vec, pub ret: Option, pub throws: bool, + pub tokens: TokenStream, } #[derive(Eq, PartialEq, Hash)] diff --git a/syntax/parse.rs b/syntax/parse.rs index 10db16ea..58237f34 100644 --- a/syntax/parse.rs +++ b/syntax/parse.rs @@ -205,7 +205,11 @@ fn parse_extern_fn(foreign_fn: &ForeignItemFn, lang: Lang) -> Result { let doc = attrs::parse_doc(&foreign_fn.attrs)?; let fn_token = foreign_fn.sig.fn_token; let ident = foreign_fn.sig.ident.clone(); + let mut foreign_fn2 = foreign_fn.clone(); + foreign_fn2.attrs.clear(); + let tokens = quote!(#foreign_fn2); let semi_token = foreign_fn.semi_token; + Ok(ExternFn { lang, doc, @@ -216,6 +220,7 @@ fn parse_extern_fn(foreign_fn: &ForeignItemFn, lang: Lang) -> Result { args, ret, throws, + tokens, }, semi_token, }) diff --git a/syntax/tokens.rs b/syntax/tokens.rs index 3bbe872a..ed5b3156 100644 --- a/syntax/tokens.rs +++ b/syntax/tokens.rs @@ -77,8 +77,6 @@ impl ToTokens for Derive { impl ToTokens for ExternFn { fn to_tokens(&self, tokens: &mut TokenStream) { - self.fn_token.to_tokens(tokens); - self.ident.to_tokens(tokens); - self.semi_token.to_tokens(tokens); + self.sig.tokens.to_tokens(tokens); } }