diff --git a/serde_derive/src/bound.rs b/serde_derive/src/bound.rs index 5a65b70f..58e9ba02 100644 --- a/serde_derive/src/bound.rs +++ b/serde_derive/src/bound.rs @@ -32,8 +32,7 @@ pub fn without_defaults(generics: &syn::Generics) -> syn::Generics { ..param.clone() }), _ => param.clone(), - }) - .collect(), + }).collect(), ..generics.clone() } } @@ -193,8 +192,7 @@ pub fn with_bound( .map(|id| syn::TypePath { qself: None, path: id.into(), - }) - .chain(associated_type_usage.into_iter().cloned()) + }).chain(associated_type_usage.into_iter().cloned()) .map(|bounded_ty| { syn::WherePredicate::Type(syn::PredicateType { lifetimes: None, @@ -208,7 +206,7 @@ pub fn with_bound( lifetimes: None, path: bound.clone(), })].into_iter() - .collect(), + .collect(), }) }); @@ -241,7 +239,7 @@ pub fn with_self_bound( lifetimes: None, path: bound.clone(), })].into_iter() - .collect(), + .collect(), })); generics } @@ -270,8 +268,7 @@ pub fn with_lifetime_bound(generics: &syn::Generics, lifetime: &str) -> syn::Gen syn::GenericParam::Const(_) => {} } param - })) - .collect(); + })).collect(); syn::Generics { params: params, @@ -307,13 +304,12 @@ fn type_of_item(cont: &Container) -> syn::Type { syn::GenericParam::Const(_) => { panic!("Serde does not support const generics yet"); } - }) - .collect(), + }).collect(), gt_token: ]>::default(), }, ), }].into_iter() - .collect(), + .collect(), }, }) } diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index 10177a85..20fa5a7f 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -204,7 +204,9 @@ fn build_generics(cont: &Container, borrowed: &BorrowedLifetimes) -> syn::Generi // All other fields may need a `T: Deserialize` bound where T is the type of the // field. fn needs_deserialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -> bool { - !field.skip_deserializing() && field.deserialize_with().is_none() && field.de_bound().is_none() + !field.skip_deserializing() + && field.deserialize_with().is_none() + && field.de_bound().is_none() && variant.map_or(true, |variant| { !variant.skip_deserializing() && variant.deserialize_with().is_none() @@ -1350,8 +1352,7 @@ fn deserialize_adjacently_tagged_enum( quote! { __Field::#variant_index => #block } - }) - .collect(); + }).collect(); let expecting = format!("adjacently tagged enum {}", params.type_name()); let type_name = cattrs.name().deserialize_name(); @@ -1939,8 +1940,7 @@ fn deserialize_custom_identifier( variant.attrs.name().deserialize_name(), variant.ident.clone(), ) - }) - .collect(); + }).collect(); let names = names_idents.iter().map(|&(ref name, _)| name); diff --git a/serde_derive/src/internals/ast.rs b/serde_derive/src/internals/ast.rs index ce1d3197..f780db2f 100644 --- a/serde_derive/src/internals/ast.rs +++ b/serde_derive/src/internals/ast.rs @@ -129,8 +129,7 @@ fn enum_from_ast<'a>( style: style, fields: fields, } - }) - .collect() + }).collect() } fn struct_from_ast<'a>( @@ -173,6 +172,5 @@ fn fields_from_ast<'a>( attrs: attr::Field::from_ast(cx, i, field, attrs, container_default), ty: &field.ty, original: field, - }) - .collect() + }).collect() } diff --git a/serde_derive/src/pretend.rs b/serde_derive/src/pretend.rs index c4ffe12d..86c45de3 100644 --- a/serde_derive/src/pretend.rs +++ b/serde_derive/src/pretend.rs @@ -62,8 +62,7 @@ fn pretend_fields_used(cont: &Container) -> TokenStream { Some(quote!(#type_ident::#variant_ident #pat)) } _ => None, - }) - .collect::>(), + }).collect::>(), Data::Struct(Style::Struct, ref fields) => { let pat = struct_pattern(fields); vec![quote!(#type_ident #pat)] diff --git a/serde_derive/src/ser.rs b/serde_derive/src/ser.rs index d6be8968..30c326d9 100644 --- a/serde_derive/src/ser.rs +++ b/serde_derive/src/ser.rs @@ -160,7 +160,9 @@ fn build_generics(cont: &Container) -> syn::Generics { // attribute specify their own bound so we do not generate one. All other fields // may need a `T: Serialize` bound where T is the type of the field. fn needs_serialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -> bool { - !field.skip_serializing() && field.serialize_with().is_none() && field.ser_bound().is_none() + !field.skip_serializing() + && field.serialize_with().is_none() + && field.ser_bound().is_none() && variant.map_or(true, |variant| { !variant.skip_serializing() && variant.serialize_with().is_none() @@ -282,8 +284,7 @@ fn serialize_tuple_struct( let field_expr = get_member(params, field, &Member::Unnamed(index)); quote!(if #path(#field_expr) { 0 } else { 1 }) } - }) - .fold(quote!(0), |sum, expr| quote!(#sum + #expr)); + }).fold(quote!(0), |sum, expr| quote!(#sum + #expr)); quote_block! { let #let_mut __serde_state = try!(_serde::Serializer::serialize_tuple_struct(__serializer, #type_name, #len)); @@ -326,8 +327,7 @@ fn serialize_struct_as_struct( let field_expr = get_member(params, field, &field.member); quote!(if #path(#field_expr) { 0 } else { 1 }) } - }) - .fold(quote!(0), |sum, expr| quote!(#sum + #expr)); + }).fold(quote!(0), |sum, expr| quote!(#sum + #expr)); quote_block! { let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct(__serializer, #type_name, #len)); @@ -361,8 +361,7 @@ fn serialize_struct_as_map( let field_expr = get_member(params, field, &field.member); quote!(if #path(#field_expr) { 0 } else { 1 }) } - }) - .fold(quote!(0), |sum, expr| quote!(#sum + #expr)); + }).fold(quote!(0), |sum, expr| quote!(#sum + #expr)); quote!(_serde::export::Some(#len)) }; @@ -383,8 +382,7 @@ fn serialize_enum(params: &Parameters, variants: &[Variant], cattrs: &attr::Cont .enumerate() .map(|(variant_index, variant)| { serialize_variant(params, variant, variant_index as u32, cattrs) - }) - .collect(); + }).collect(); quote_expr! { match *#self_var { @@ -788,8 +786,7 @@ fn serialize_tuple_variant( let field_expr = Ident::new(&format!("__field{}", i), Span::call_site()); quote!(if #path(#field_expr) { 0 } else { 1 }) } - }) - .fold(quote!(0), |sum, expr| quote!(#sum + #expr)); + }).fold(quote!(0), |sum, expr| quote!(#sum + #expr)); match context { TupleVariant::ExternallyTagged { @@ -866,8 +863,7 @@ fn serialize_struct_variant<'a>( Some(path) => quote!(if #path(#member) { 0 } else { 1 }), None => quote!(1), } - }) - .fold(quote!(0), |sum, expr| quote!(#sum + #expr)); + }).fold(quote!(0), |sum, expr| quote!(#sum + #expr)); match context { StructVariant::ExternallyTagged { @@ -1046,8 +1042,7 @@ fn serialize_tuple_struct_visitor( None => ser, Some(skip) => quote!(if !#skip { #ser }), } - }) - .collect() + }).collect() } fn serialize_struct_visitor( @@ -1141,8 +1136,7 @@ fn wrap_serialize_variant_with( } }; quote!(#id) - }) - .collect(); + }).collect(); wrap_serialize_with( params, serialize_with, diff --git a/test_suite/tests/test_de.rs b/test_suite/tests/test_de.rs index 22570fbd..95b419e2 100644 --- a/test_suite/tests/test_de.rs +++ b/test_suite/tests/test_de.rs @@ -218,9 +218,9 @@ fn assert_de_tokens_ignore(ignorable_tokens: &[Token]) { Token::I32(1), Token::Str("ignored"), ].into_iter() - .chain(ignorable_tokens.to_vec().into_iter()) - .chain(vec![Token::MapEnd].into_iter()) - .collect(); + .chain(ignorable_tokens.to_vec().into_iter()) + .chain(vec![Token::MapEnd].into_iter()) + .collect(); let mut de = serde_test::Deserializer::new(&concated_tokens); let base = IgnoreBase::deserialize(&mut de).unwrap();