diff --git a/components/style/values/generics/basic_shape.rs b/components/style/values/generics/basic_shape.rs index ef9eac14ec7..27185ef8be6 100644 --- a/components/style/values/generics/basic_shape.rs +++ b/components/style/values/generics/basic_shape.rs @@ -43,6 +43,7 @@ pub enum ShapeBox { /// A shape source, for some reference box. #[allow(missing_docs)] +#[animate(no_bound(ImageOrUrl))] #[derive(Animate, Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] pub enum ShapeSource { #[animation(error)] diff --git a/components/style/values/generics/svg.rs b/components/style/values/generics/svg.rs index 6d9928ec1af..06ce911d473 100644 --- a/components/style/values/generics/svg.rs +++ b/components/style/values/generics/svg.rs @@ -15,6 +15,7 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance}; /// An SVG paint value /// /// +#[animate(no_bound(UrlPaintServer))] #[derive(Animate, Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)] #[derive(ToAnimatedValue, ToComputedValue, ToCss)] pub struct SVGPaint { @@ -29,6 +30,7 @@ pub struct SVGPaint { /// Whereas the spec only allows PaintServer /// to have a fallback, Gecko lets the context /// properties have a fallback as well. +#[animate(no_bound(UrlPaintServer))] #[derive(Animate, Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)] #[derive(ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)] pub enum SVGPaintKind { diff --git a/components/style_derive/animate.rs b/components/style_derive/animate.rs index 912f7dbc9f2..06767000383 100644 --- a/components/style_derive/animate.rs +++ b/components/style_derive/animate.rs @@ -2,23 +2,31 @@ * 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/. */ -use cg::{self, WhereClause}; +use cg; +use darling::util::IdentList; use quote::Tokens; use syn::{DeriveInput, Path}; use synstructure::{Structure, VariantInfo}; -pub fn derive(input: DeriveInput) -> Tokens { - let name = &input.ident; - let trait_path = parse_quote!(values::animated::Animate); - let (impl_generics, ty_generics, mut where_clause) = - cg::trait_parts(&input, &trait_path); - +pub fn derive(mut input: DeriveInput) -> Tokens { let input_attrs = cg::parse_input_attrs::(&input); + let no_bound = input_attrs.no_bound.unwrap_or_default(); + let mut where_clause = input.generics.where_clause.take(); + for param in input.generics.type_params() { + if !no_bound.contains(¶m.ident) { + cg::add_predicate( + &mut where_clause, + parse_quote!(#param: ::values::animated::Animate), + ); + } + } + input.generics.where_clause = where_clause; + let s = Structure::new(&input); let mut append_error_clause = s.variants().len() > 1; let mut match_body = s.variants().iter().fold(quote!(), |body, variant| { - let arm = match derive_variant_arm(variant, &mut where_clause) { + let arm = match derive_variant_arm(variant) { Ok(arm) => arm, Err(()) => { append_error_clause = true; @@ -38,6 +46,9 @@ pub fn derive(input: DeriveInput) -> Tokens { } } + let name = &input.ident; + let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); + quote! { impl #impl_generics ::values::animated::Animate for #name #ty_generics #where_clause { #[allow(unused_variables, unused_imports)] @@ -55,10 +66,7 @@ pub fn derive(input: DeriveInput) -> Tokens { } } -fn derive_variant_arm( - variant: &VariantInfo, - where_clause: &mut WhereClause, -) -> Result { +fn derive_variant_arm(variant: &VariantInfo) -> Result { let variant_attrs = cg::parse_variant_attrs::(&variant.ast()); if variant_attrs.error { return Err(()); @@ -78,7 +86,6 @@ fn derive_variant_arm( let #result = ::std::clone::Clone::clone(#this); } } else { - where_clause.add_trait_bound(&result.ast().ty); quote! { let #result = ::values::animated::Animate::animate(#this, #other, procedure)?; @@ -97,6 +104,7 @@ fn derive_variant_arm( #[derive(Default, FromDeriveInput)] struct AnimateInputAttrs { fallback: Option, + no_bound: Option, } #[darling(attributes(animation), default)]