Bug 1518045 - Fix all clippy warnings in style_derive. r=emilio
authorBastien Orivel <eijebong@bananium.fr>
Wed, 12 Dec 2018 21:32:52 +0100
changeset 509774 123ac731210fea368ff7bd4db93889e0faf390f2
parent 509773 c62ba89a005dc61b5bc627c6779dd780609eadab
child 509775 91e7ea77c846ae753fb3a28ab81598d2dc7ac865
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1518045, 22439
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1518045 - Fix all clippy warnings in style_derive. r=emilio This cherry-picks https://github.com/servo/servo/pull/22439.
servo/components/style_derive/cg.rs
servo/components/style_derive/parse.rs
servo/components/style_derive/specified_value_info.rs
servo/components/style_derive/to_animated_zero.rs
--- a/servo/components/style_derive/cg.rs
+++ b/servo/components/style_derive/cg.rs
@@ -24,17 +24,17 @@ where
     F: FnMut(BindingInfo) -> TokenStream,
 {
     let mut s = synstructure::Structure::new(input);
     s.variants_mut().iter_mut().for_each(|v| {
         v.bind_with(|_| bind_style);
     });
     s.each_variant(|variant| {
         let (mapped, mapped_fields) = value(variant, "mapped");
-        let fields_pairs = variant.bindings().into_iter().zip(mapped_fields);
+        let fields_pairs = variant.bindings().iter().zip(mapped_fields);
         let mut computations = quote!();
         computations.append_all(fields_pairs.map(|(field, mapped_field)| {
             let expr = f(field.clone());
             quote! { let #mapped_field = #expr; }
         }));
         computations.append_all(mapped);
         Some(computations)
     })
@@ -230,26 +230,26 @@ pub fn ref_pattern<'a>(
     variant: &'a VariantInfo,
     prefix: &str,
 ) -> (TokenStream, Vec<BindingInfo<'a>>) {
     let mut v = variant.clone();
     v.bind_with(|_| BindStyle::Ref);
     v.bindings_mut().iter_mut().for_each(|b| {
         b.binding = Ident::new(&format!("{}_{}", b.binding, prefix), Span::call_site())
     });
-    (v.pat(), v.bindings().iter().cloned().collect())
+    (v.pat(), v.bindings().to_vec())
 }
 
 pub fn value<'a>(variant: &'a VariantInfo, prefix: &str) -> (TokenStream, Vec<BindingInfo<'a>>) {
     let mut v = variant.clone();
     v.bindings_mut().iter_mut().for_each(|b| {
         b.binding = Ident::new(&format!("{}_{}", b.binding, prefix), Span::call_site())
     });
     v.bind_with(|_| BindStyle::Move);
-    (v.pat(), v.bindings().iter().cloned().collect())
+    (v.pat(), v.bindings().to_vec())
 }
 
 /// Transforms "FooBar" to "foo-bar".
 ///
 /// If the first Camel segment is "Moz", "Webkit", or "Servo", the result string
 /// is prepended with "-".
 pub fn to_css_identifier(mut camel_case: &str) -> String {
     camel_case = camel_case.trim_end_matches('_');
--- a/servo/components/style_derive/parse.rs
+++ b/servo/components/style_derive/parse.rs
@@ -31,17 +31,17 @@ pub fn derive(input: DeriveInput) -> Tok
         let parse_attrs = cg::parse_variant_attrs_from_ast::<ParseVariantAttrs>(&variant.ast());
         if css_variant_attrs.skip {
             return match_body;
         }
 
         let identifier = cg::to_css_identifier(
             &css_variant_attrs
                 .keyword
-                .unwrap_or(variant.ast().ident.to_string()),
+                .unwrap_or_else(|| variant.ast().ident.to_string()),
         );
         let ident = &variant.ast().ident;
 
         saw_condition |= parse_attrs.condition.is_some();
         let condition = match parse_attrs.condition {
             Some(ref p) => quote! { if #p(context) },
             None => quote! {},
         };
@@ -51,17 +51,17 @@ pub fn derive(input: DeriveInput) -> Tok
             #identifier #condition => Ok(#name::#ident),
         };
 
         let aliases = match parse_attrs.aliases {
             Some(aliases) => aliases,
             None => return body,
         };
 
-        for alias in aliases.split(",") {
+        for alias in aliases.split(',') {
             body = quote! {
                 #body
                 #alias #condition => Ok(#name::#ident),
             };
         }
 
         body
     });
--- a/servo/components/style_derive/specified_value_info.rs
+++ b/servo/components/style_derive/specified_value_info.rs
@@ -35,56 +35,54 @@ pub fn derive(mut input: DeriveInput) ->
                 for v in e.variants.iter() {
                     let css_attrs = cg::parse_variant_attrs::<CssVariantAttrs>(&v);
                     let info_attrs = cg::parse_variant_attrs::<ValueInfoVariantAttrs>(&v);
                     let parse_attrs = cg::parse_variant_attrs::<ParseVariantAttrs>(&v);
                     if css_attrs.skip {
                         continue;
                     }
                     if let Some(aliases) = parse_attrs.aliases {
-                        for alias in aliases.split(",") {
+                        for alias in aliases.split(',') {
                             values.push(alias.to_string());
                         }
                     }
                     if let Some(other_values) = info_attrs.other_values {
-                        for value in other_values.split(",") {
+                        for value in other_values.split(',') {
                             values.push(value.to_string());
                         }
                     }
                     let ident = &v.ident;
                     let variant_name = || cg::to_css_identifier(&ident.to_string());
                     if info_attrs.starts_with_keyword {
                         values.push(variant_name());
                         continue;
                     }
                     if let Some(keyword) = css_attrs.keyword {
                         values.push(keyword);
                         continue;
                     }
                     if let Some(function) = css_attrs.function {
                         values.push(function.explicit().unwrap_or_else(variant_name));
-                    } else {
-                        if !derive_struct_fields(&v.fields, &mut types, &mut values) {
-                            values.push(variant_name());
-                        }
+                    } else if !derive_struct_fields(&v.fields, &mut types, &mut values) {
+                        values.push(variant_name());
                     }
                 }
             },
             Data::Struct(ref s) => {
                 if !derive_struct_fields(&s.fields, &mut types, &mut values) {
                     values.push(input_name());
                 }
             },
             Data::Union(_) => unreachable!("union is not supported"),
         }
     }
 
     let info_attrs = cg::parse_input_attrs::<ValueInfoInputAttrs>(&input);
     if let Some(other_values) = info_attrs.other_values {
-        for value in other_values.split(",") {
+        for value in other_values.split(',') {
             values.push(value.to_string());
         }
     }
 
     let mut types_value = quote!(0);
     types_value.append_all(types.iter().map(|ty| {
         quote! {
             | <#ty as style_traits::SpecifiedValueInfo>::SUPPORTED_TYPES
@@ -138,17 +136,17 @@ fn derive_struct_fields<'a>(
     let fields = match *fields {
         Fields::Unit => return false,
         Fields::Named(ref fields) => fields.named.iter(),
         Fields::Unnamed(ref fields) => fields.unnamed.iter(),
     };
     types.extend(fields.filter_map(|field| {
         let info_attrs = cg::parse_field_attrs::<ValueInfoFieldAttrs>(field);
         if let Some(other_values) = info_attrs.other_values {
-            for value in other_values.split(",") {
+            for value in other_values.split(',') {
                 values.push(value.to_string());
             }
         }
         let css_attrs = cg::parse_field_attrs::<CssFieldAttrs>(field);
         if css_attrs.represents_keyword {
             let ident = field
                 .ident
                 .as_ref()
--- a/servo/components/style_derive/to_animated_zero.rs
+++ b/servo/components/style_derive/to_animated_zero.rs
@@ -23,17 +23,17 @@ pub fn derive(mut input: syn::DeriveInpu
     }
 
     let to_body = synstructure::Structure::new(&input).each_variant(|variant| {
         let attrs = cg::parse_variant_attrs_from_ast::<AnimationVariantAttrs>(&variant.ast());
         if attrs.error {
             return Some(quote! { Err(()) });
         }
         let (mapped, mapped_bindings) = cg::value(variant, "mapped");
-        let bindings_pairs = variant.bindings().into_iter().zip(mapped_bindings);
+        let bindings_pairs = variant.bindings().iter().zip(mapped_bindings);
         let mut computations = quote!();
         computations.append_all(bindings_pairs.map(|(binding, mapped_binding)| {
             let field_attrs = cg::parse_field_attrs::<AnimationFieldAttrs>(&binding.ast());
             if field_attrs.constant {
                 quote! {
                     let #mapped_binding = std::clone::Clone::clone(#binding);
                 }
             } else {