Fix all clippy warnings in style_derive

This commit is contained in:
Bastien Orivel 2018-12-12 21:32:52 +01:00
parent d5c1690cb4
commit dd301c084d
4 changed files with 12 additions and 14 deletions

View file

@ -29,7 +29,7 @@ where
}); });
s.each_variant(|variant| { s.each_variant(|variant| {
let (mapped, mapped_fields) = value(variant, "mapped"); 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!(); let mut computations = quote!();
computations.append_all(fields_pairs.map(|(field, mapped_field)| { computations.append_all(fields_pairs.map(|(field, mapped_field)| {
let expr = f(field.clone()); let expr = f(field.clone());
@ -237,7 +237,7 @@ pub fn ref_pattern<'a>(
v.bindings_mut().iter_mut().for_each(|b| { v.bindings_mut().iter_mut().for_each(|b| {
b.binding = Ident::new(&format!("{}_{}", b.binding, prefix), Span::call_site()) 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>>) { pub fn value<'a>(variant: &'a VariantInfo, prefix: &str) -> (TokenStream, Vec<BindingInfo<'a>>) {
@ -246,7 +246,7 @@ pub fn value<'a>(variant: &'a VariantInfo, prefix: &str) -> (TokenStream, Vec<Bi
b.binding = Ident::new(&format!("{}_{}", b.binding, prefix), Span::call_site()) b.binding = Ident::new(&format!("{}_{}", b.binding, prefix), Span::call_site())
}); });
v.bind_with(|_| BindStyle::Move); v.bind_with(|_| BindStyle::Move);
(v.pat(), v.bindings().iter().cloned().collect()) (v.pat(), v.bindings().to_vec())
} }
/// Transforms "FooBar" to "foo-bar". /// Transforms "FooBar" to "foo-bar".

View file

@ -36,7 +36,7 @@ pub fn derive(input: DeriveInput) -> TokenStream {
let identifier = cg::to_css_identifier( let identifier = cg::to_css_identifier(
&css_variant_attrs &css_variant_attrs
.keyword .keyword
.unwrap_or(variant.ast().ident.to_string()), .unwrap_or_else(|| variant.ast().ident.to_string()),
); );
let ident = &variant.ast().ident; let ident = &variant.ast().ident;
@ -56,7 +56,7 @@ pub fn derive(input: DeriveInput) -> TokenStream {
None => return body, None => return body,
}; };
for alias in aliases.split(",") { for alias in aliases.split(',') {
body = quote! { body = quote! {
#body #body
#alias #condition => Ok(#name::#ident), #alias #condition => Ok(#name::#ident),

View file

@ -40,12 +40,12 @@ pub fn derive(mut input: DeriveInput) -> TokenStream {
continue; continue;
} }
if let Some(aliases) = parse_attrs.aliases { if let Some(aliases) = parse_attrs.aliases {
for alias in aliases.split(",") { for alias in aliases.split(',') {
values.push(alias.to_string()); values.push(alias.to_string());
} }
} }
if let Some(other_values) = info_attrs.other_values { 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()); values.push(value.to_string());
} }
} }
@ -61,12 +61,10 @@ pub fn derive(mut input: DeriveInput) -> TokenStream {
} }
if let Some(function) = css_attrs.function { if let Some(function) = css_attrs.function {
values.push(function.explicit().unwrap_or_else(variant_name)); values.push(function.explicit().unwrap_or_else(variant_name));
} else { } else if !derive_struct_fields(&v.fields, &mut types, &mut values) {
if !derive_struct_fields(&v.fields, &mut types, &mut values) {
values.push(variant_name()); values.push(variant_name());
} }
} }
}
}, },
Data::Struct(ref s) => { Data::Struct(ref s) => {
if !derive_struct_fields(&s.fields, &mut types, &mut values) { if !derive_struct_fields(&s.fields, &mut types, &mut values) {
@ -79,7 +77,7 @@ pub fn derive(mut input: DeriveInput) -> TokenStream {
let info_attrs = cg::parse_input_attrs::<ValueInfoInputAttrs>(&input); let info_attrs = cg::parse_input_attrs::<ValueInfoInputAttrs>(&input);
if let Some(other_values) = info_attrs.other_values { 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()); values.push(value.to_string());
} }
} }
@ -143,7 +141,7 @@ fn derive_struct_fields<'a>(
types.extend(fields.filter_map(|field| { types.extend(fields.filter_map(|field| {
let info_attrs = cg::parse_field_attrs::<ValueInfoFieldAttrs>(field); let info_attrs = cg::parse_field_attrs::<ValueInfoFieldAttrs>(field);
if let Some(other_values) = info_attrs.other_values { 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()); values.push(value.to_string());
} }
} }

View file

@ -28,7 +28,7 @@ pub fn derive(mut input: syn::DeriveInput) -> TokenStream {
return Some(quote! { Err(()) }); return Some(quote! { Err(()) });
} }
let (mapped, mapped_bindings) = cg::value(variant, "mapped"); 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!(); let mut computations = quote!();
computations.append_all(bindings_pairs.map(|(binding, mapped_binding)| { computations.append_all(bindings_pairs.map(|(binding, mapped_binding)| {
let field_attrs = cg::parse_field_attrs::<AnimationFieldAttrs>(&binding.ast()); let field_attrs = cg::parse_field_attrs::<AnimationFieldAttrs>(&binding.ast());