Skip to content

Commit

Permalink
style: Drop fallback attribute from animate and distance.
Browse files Browse the repository at this point in the history
Still keep the discriminant checks to avoid generating terrible code.

Differential Revision: https://phabricator.services.mozilla.com/D62329
  • Loading branch information
BorisChiou authored and emilio committed Apr 16, 2020
1 parent 239302b commit ef2d934
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 34 deletions.
3 changes: 0 additions & 3 deletions components/style/values/animated/mod.rs
Expand Up @@ -109,9 +109,6 @@ pub fn animate_multiplicative_factor(
/// If a variant is annotated with `#[animation(error)]`, the corresponding
/// `match` arm returns an error.
///
/// If the two values are not similar, an error is returned unless a fallback
/// function has been specified through `#[animate(fallback)]`.
///
/// Trait bounds for type parameter `Foo` can be opted out of with
/// `#[animation(no_bound(Foo))]` on the type definition, trait bounds for
/// fields can be opted into with `#[animation(field_bound)]` on the field.
Expand Down
3 changes: 0 additions & 3 deletions components/style/values/distance.rs
Expand Up @@ -19,9 +19,6 @@ use std::ops::Add;
/// If a variant is annotated with `#[animation(error)]`, the corresponding
/// `match` arm returns an error.
///
/// If the two values are not similar, an error is returned unless a fallback
/// function has been specified through `#[distance(fallback)]`.
///
/// Trait bounds for type parameter `Foo` can be opted out of with
/// `#[animation(no_bound(Foo))]` on the type definition, trait bounds for
/// fields can be opted into with `#[distance(field_bound)]` on the field.
Expand Down
16 changes: 2 additions & 14 deletions components/style_derive/animate.rs
Expand Up @@ -6,12 +6,11 @@ use darling::util::PathList;
use derive_common::cg;
use proc_macro2::TokenStream;
use quote::TokenStreamExt;
use syn::{DeriveInput, Path, WhereClause};
use syn::{DeriveInput, WhereClause};
use synstructure::{Structure, VariantInfo};

pub fn derive(mut input: DeriveInput) -> TokenStream {
let animation_input_attrs = cg::parse_input_attrs::<AnimationInputAttrs>(&input);
let input_attrs = cg::parse_input_attrs::<AnimateInputAttrs>(&input);

let no_bound = animation_input_attrs.no_bound.unwrap_or_default();
let mut where_clause = input.generics.where_clause.take();
Expand Down Expand Up @@ -44,11 +43,6 @@ pub fn derive(mut input: DeriveInput) -> TokenStream {
let name = &input.ident;
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();

let fallback = match input_attrs.fallback {
Some(fallback) => quote! { #fallback(self, other, procedure) },
None => quote! { Err(()) },
};

quote! {
impl #impl_generics crate::values::animated::Animate for #name #ty_generics #where_clause {
#[allow(unused_variables, unused_imports)]
Expand All @@ -59,7 +53,7 @@ pub fn derive(mut input: DeriveInput) -> TokenStream {
procedure: crate::values::animated::Procedure,
) -> Result<Self, ()> {
if std::mem::discriminant(self) != std::mem::discriminant(other) {
return #fallback;
return Err(());
}
match (self, other) {
#match_body
Expand Down Expand Up @@ -118,12 +112,6 @@ fn derive_variant_arm(
}
}

#[darling(attributes(animate), default)]
#[derive(Default, FromDeriveInput)]
struct AnimateInputAttrs {
fallback: Option<Path>,
}

#[darling(attributes(animation), default)]
#[derive(Default, FromDeriveInput)]
pub struct AnimationInputAttrs {
Expand Down
16 changes: 2 additions & 14 deletions components/style_derive/compute_squared_distance.rs
Expand Up @@ -6,12 +6,11 @@ use crate::animate::{AnimationFieldAttrs, AnimationInputAttrs, AnimationVariantA
use derive_common::cg;
use proc_macro2::TokenStream;
use quote::TokenStreamExt;
use syn::{DeriveInput, Path, WhereClause};
use syn::{DeriveInput, WhereClause};
use synstructure;

pub fn derive(mut input: DeriveInput) -> TokenStream {
let animation_input_attrs = cg::parse_input_attrs::<AnimationInputAttrs>(&input);
let input_attrs = cg::parse_input_attrs::<DistanceInputAttrs>(&input);
let no_bound = animation_input_attrs.no_bound.unwrap_or_default();
let mut where_clause = input.generics.where_clause.take();
for param in input.generics.type_params() {
Expand Down Expand Up @@ -43,11 +42,6 @@ pub fn derive(mut input: DeriveInput) -> TokenStream {
match_body.append_all(quote! { _ => unsafe { debug_unreachable!() } });
}

let fallback = match input_attrs.fallback {
Some(fallback) => quote! { #fallback(self, other) },
None => quote! { Err(()) },
};

let name = &input.ident;
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();

Expand All @@ -60,7 +54,7 @@ pub fn derive(mut input: DeriveInput) -> TokenStream {
other: &Self,
) -> Result<crate::values::distance::SquaredDistance, ()> {
if std::mem::discriminant(self) != std::mem::discriminant(other) {
return #fallback;
return Err(());
}
match (self, other) {
#match_body
Expand Down Expand Up @@ -124,12 +118,6 @@ fn derive_variant_arm(
};
}

#[darling(attributes(distance), default)]
#[derive(Default, FromDeriveInput)]
struct DistanceInputAttrs {
fallback: Option<Path>,
}

#[darling(attributes(distance), default)]
#[derive(Default, FromField)]
struct DistanceFieldAttrs {
Expand Down

0 comments on commit ef2d934

Please sign in to comment.