mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 03:11:02 +00:00
Limit type bounds to associated types
This commit is contained in:
@@ -64,13 +64,18 @@ where
|
|||||||
let predicates = cont.data
|
let predicates = cont.data
|
||||||
.all_fields()
|
.all_fields()
|
||||||
.flat_map(|field| {
|
.flat_map(|field| {
|
||||||
let field_bound: Option<syn::WherePredicate> = match gen_bound_where(&field.attrs) {
|
let field_ty = field.ty;
|
||||||
true => {
|
let field_bound: Option<syn::WherePredicate> = match (field_ty, gen_bound_where(&field.attrs)) {
|
||||||
let field_ty = field.ty;
|
(&syn::Type::Path(ref ty_path), true) => match (ty_path.path.segments.first(), generics.params.first()) {
|
||||||
let predicate: syn::WherePredicate = parse_quote!(#field_ty: #trait_bound);
|
(Some(syn::punctuated::Pair::Punctuated(ref t, _)), Some(syn::punctuated::Pair::End(&syn::GenericParam::Type(ref generic_ty))))
|
||||||
Some(predicate)
|
if generic_ty.ident == t.ident =>
|
||||||
|
{
|
||||||
|
let predicate: syn::WherePredicate = parse_quote!(#field_ty: #trait_bound);
|
||||||
|
Some(predicate)
|
||||||
|
},
|
||||||
|
_ => None
|
||||||
},
|
},
|
||||||
false => None
|
(_, _) => None
|
||||||
};
|
};
|
||||||
field_bound.into_iter().chain(from_field(&field.attrs).into_iter().flat_map(|predicates| predicates.to_vec()))
|
field_bound.into_iter().chain(from_field(&field.attrs).into_iter().flat_map(|predicates| predicates.to_vec()))
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user