mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
style: Drop fallback attribute from animate and distance.
Still keep the discriminant checks to avoid generating terrible code. Differential Revision: https://phabricator.services.mozilla.com/D62329
This commit is contained in:
parent
239302b1ed
commit
ef2d934dac
4 changed files with 4 additions and 34 deletions
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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() {
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue