Improve handling of trait bounds when deriving fmap-like traits

This commit is contained in:
Anthony Ramine 2017-08-26 12:40:28 +02:00
parent 8101887d31
commit efc852f6e3
12 changed files with 229 additions and 136 deletions

View file

@ -30,14 +30,16 @@ pub fn derive(input: syn::DeriveInput) -> quote::Tokens {
computations.append_all(iter.map(|(result, (this, other))| {
let field_attrs = cg::parse_field_attrs::<AnimateFieldAttrs>(&result.field);
if field_attrs.constant {
if cg::is_parameterized(&result.field.ty, where_clause.params) {
if cg::is_parameterized(&result.field.ty, where_clause.params, None) {
where_clause.inner.predicates.push(cg::where_predicate(
result.field.ty.clone(),
&["std", "cmp", "PartialEq"],
None,
));
where_clause.inner.predicates.push(cg::where_predicate(
result.field.ty.clone(),
&["std", "clone", "Clone"],
None,
));
}
quote! {
@ -47,7 +49,7 @@ pub fn derive(input: syn::DeriveInput) -> quote::Tokens {
let #result = ::std::clone::Clone::clone(#this);
}
} else {
where_clause.add_trait_bound(result.field.ty.clone());
where_clause.add_trait_bound(&result.field.ty);
quote! {
let #result =
::values::animated::Animate::animate(#this, #other, procedure)?;