aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2023-06-07 14:03:41 +0200
committerOriol Brufau <obrufau@igalia.com>2023-06-09 10:22:17 +0200
commit327812e3ebc2b46e566f536df24020d1cb27eaae (patch)
treec650696d39b00b888647af6931d537f610b47dac
parent155fbf8804a675d5d851d194cc5de0e217d9ebd5 (diff)
downloadservo-327812e3ebc2b46e566f536df24020d1cb27eaae.tar.gz
servo-327812e3ebc2b46e566f536df24020d1cb27eaae.zip
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
-rw-r--r--components/style_derive/to_css.rs16
-rw-r--r--components/style_traits/owned_slice.rs16
2 files changed, 22 insertions, 10 deletions
diff --git a/components/style_derive/to_css.rs b/components/style_derive/to_css.rs
index 19c7c1ac2bc..40e219c374b 100644
--- a/components/style_derive/to_css.rs
+++ b/components/style_derive/to_css.rs
@@ -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! {
diff --git a/components/style_traits/owned_slice.rs b/components/style_traits/owned_slice.rs
index f6068365360..36ba3162e59 100644
--- a/components/style_traits/owned_slice.rs
+++ b/components/style_traits/owned_slice.rs
@@ -93,12 +93,6 @@ impl<T: Sized> OwnedSlice<T> {
ret
}
- /// Iterate over all the elements in the slice taking ownership of them.
- #[inline]
- pub fn into_iter(self) -> impl Iterator<Item = T> + ExactSizeIterator {
- self.into_vec().into_iter()
- }
-
/// Convert the regular slice into an owned slice.
#[inline]
pub fn from_slice(s: &[T]) -> Self
@@ -109,6 +103,16 @@ impl<T: Sized> OwnedSlice<T> {
}
}
+impl<T> IntoIterator for OwnedSlice<T> {
+ type Item = T;
+ type IntoIter = <Vec<T> as IntoIterator>::IntoIter;
+
+ #[inline]
+ fn into_iter(self) -> Self::IntoIter {
+ self.into_vec().into_iter()
+ }
+}
+
impl<T> Deref for OwnedSlice<T> {
type Target = [T];