mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Make #[css(field_bound)] and #[css(iterable)] work properly
For now, use IntoIterator to figure the right type to add the bound. If we need this on types that are iterable but don't provide IntoIterator, we can add another attribute field or something. Differential Revision: https://phabricator.services.mozilla.com/D129962
This commit is contained in:
parent
155fbf8804
commit
327812e3eb
2 changed files with 22 additions and 10 deletions
|
@ -140,11 +140,19 @@ fn derive_variant_fields_expr(
|
|||
Some(pair) => pair,
|
||||
None => return quote! { Ok(()) },
|
||||
};
|
||||
if attrs.field_bound {
|
||||
let ty = &first.ast().ty;
|
||||
// TODO(emilio): IntoIterator might not be enough for every type of
|
||||
// iterable thing (like ArcSlice<> or what not). We might want to expose
|
||||
// an `item = "T"` attribute to handle that in the future.
|
||||
let predicate = if attrs.iterable {
|
||||
parse_quote!(<#ty as IntoIterator>::Item: style_traits::ToCss)
|
||||
} else {
|
||||
parse_quote!(#ty: style_traits::ToCss)
|
||||
};
|
||||
cg::add_predicate(where_clause, predicate);
|
||||
}
|
||||
if !attrs.iterable && iter.peek().is_none() {
|
||||
if attrs.field_bound {
|
||||
let ty = &first.ast().ty;
|
||||
cg::add_predicate(where_clause, parse_quote!(#ty: style_traits::ToCss));
|
||||
}
|
||||
let mut expr = quote! { style_traits::ToCss::to_css(#first, dest) };
|
||||
if let Some(condition) = attrs.skip_if {
|
||||
expr = quote! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue