Preserve original tokens of Signature

This commit is contained in:
David Tolnay 2020-03-18 20:07:46 -07:00
parent 33d3029780
commit d95b119931
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
4 changed files with 11 additions and 4 deletions

View File

@ -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);

View File

@ -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<Var>,
pub ret: Option<Type>,
pub throws: bool,
pub tokens: TokenStream,
}
#[derive(Eq, PartialEq, Hash)]

View File

@ -205,7 +205,11 @@ fn parse_extern_fn(foreign_fn: &ForeignItemFn, lang: Lang) -> Result<ExternFn> {
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<ExternFn> {
args,
ret,
throws,
tokens,
},
semi_token,
})

View File

@ -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);
}
}