Bump syn/quote in jstraceable_derive

This commit is contained in:
Bastien Orivel 2018-02-12 16:39:23 +01:00
parent c18137b4ea
commit 3670d4d3e5
3 changed files with 20 additions and 35 deletions

6
Cargo.lock generated
View file

@ -1304,9 +1304,9 @@ dependencies = [
name = "jstraceable_derive" name = "jstraceable_derive"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.12.12 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]

View file

@ -10,6 +10,6 @@ path = "lib.rs"
proc-macro = true proc-macro = true
[dependencies] [dependencies]
quote = "0.3.15" quote = "0.4.2"
syn = "0.11" syn = "0.12.12"
synstructure = "0.5" synstructure = "0.7"

View file

@ -2,39 +2,24 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
extern crate proc_macro;
#[macro_use] extern crate quote; #[macro_use] extern crate quote;
extern crate syn; #[macro_use] extern crate syn;
extern crate synstructure; #[macro_use] extern crate synstructure;
#[proc_macro_derive(JSTraceable)] decl_derive!([JSTraceable] => js_traceable_derive);
pub fn expand_token_stream(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
expand_string(&input.to_string()).parse().unwrap()
}
fn expand_string(input: &str) -> String { fn js_traceable_derive(s: synstructure::Structure) -> quote::Tokens {
let mut type_ = syn::parse_macro_input(input).unwrap(); let match_body = s.each(|binding| {
Some(quote!(#binding.trace(tracer);))
let style = synstructure::BindStyle::Ref.into();
let match_body = synstructure::each_field(&mut type_, &style, |binding| {
Some(quote! { #binding.trace(tracer); })
}); });
let name = &type_.ident; let ast = s.ast();
let (impl_generics, ty_generics, where_clause) = type_.generics.split_for_impl(); let name = ast.ident;
let mut where_clause = where_clause.clone(); let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
for param in &type_.generics.ty_params { let mut where_clause = where_clause.unwrap_or(&parse_quote!(where)).clone();
where_clause.predicates.push(syn::WherePredicate::BoundPredicate(syn::WhereBoundPredicate { for param in ast.generics.type_params() {
bound_lifetimes: Vec::new(), let ident = param.ident;
bounded_ty: syn::Ty::Path(None, param.ident.clone().into()), where_clause.predicates.push(parse_quote!(#ident: ::dom::bindings::trace::JSTraceable))
bounds: vec![syn::TyParamBound::Trait(
syn::PolyTraitRef {
bound_lifetimes: Vec::new(),
trait_ref: syn::parse_path("::dom::bindings::trace::JSTraceable").unwrap(),
},
syn::TraitBoundModifier::None
)],
}))
} }
let tokens = quote! { let tokens = quote! {
@ -51,5 +36,5 @@ fn expand_string(input: &str) -> String {
} }
}; };
tokens.to_string() tokens
} }