Format with rustfmt 2018-12-10

This commit is contained in:
David Tolnay 2018-12-27 19:49:08 -05:00
parent 807a097387
commit 32728d2f1d
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
6 changed files with 22 additions and 23 deletions

View File

@ -410,11 +410,11 @@ impl Container {
syn::Data::Enum(_) => {
internal_tag.set(&m.ident, s.value());
}
syn::Data::Struct(syn::DataStruct{ref fields, ..}) => {
syn::Data::Struct(syn::DataStruct { ref fields, .. }) => {
match *fields {
syn::Fields::Named(_) => {
internal_tag.set(&m.ident, s.value());
},
}
syn::Fields::Unnamed(_) | syn::Fields::Unit => {
cx.error_spanned_by(
fields,
@ -430,7 +430,7 @@ impl Container {
cx.error_spanned_by(
union_token,
"#[serde(tag = \"...\")] can only be used on enums \
and structs with named fields",
and structs with named fields",
);
}
}

View File

@ -1,5 +1,5 @@
use internals::ast::{Container, Data, Field, Style};
use internals::attr::{TagType, Identifier};
use internals::attr::{Identifier, TagType};
use internals::{Ctxt, Derive};
use syn::{Member, Type};

View File

@ -300,15 +300,18 @@ fn serialize_struct_as_struct(
let type_name = cattrs.name().serialize_name();
let additional_field_count: usize = match cattrs.tag() {
&attr::TagType::Internal{ref tag} => {
&attr::TagType::Internal { ref tag } => {
let func = StructTrait::SerializeStruct.serialize_field(Span::call_site());
serialize_fields.insert(0, quote! {
try!(#func(&mut __serde_state, #tag, #type_name));
});
serialize_fields.insert(
0,
quote! {
try!(#func(&mut __serde_state, #tag, #type_name));
},
);
1
}
_ => 0
_ => 0,
};
let mut serialized_fields = fields
@ -326,7 +329,10 @@ fn serialize_struct_as_struct(
quote!(if #path(#field_expr) { 0 } else { 1 })
}
})
.fold(quote!(#additional_field_count), |sum, expr| quote!(#sum + #expr));
.fold(
quote!(#additional_field_count),
|sum, expr| quote!(#sum + #expr),
);
quote_block! {
let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct(__serializer, #type_name, #len));

View File

@ -1379,13 +1379,13 @@ fn test_enum_in_internally_tagged_enum() {
#[test]
fn test_internally_tagged_struct() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag="type")]
#[serde(tag = "type")]
pub struct Struct {
a: u8,
}
assert_tokens(
&Struct{ a: 1 },
&Struct { a: 1 },
&[
Token::Struct {
name: "Struct",

View File

@ -3,9 +3,6 @@ extern crate serde_derive;
#[derive(Serialize)]
#[serde(tag = "type")]
struct S (
u8,
u8
);
struct S(u8, u8);
fn main() {}

View File

@ -1,12 +1,8 @@
error: #[serde(tag = "...")] can only be used on enums and structs with named fields
--> $DIR/internally-tagged-tuple.rs:6:10
--> $DIR/internally-tagged-tuple.rs:6:9
|
6 | struct S (
| __________^
7 | | u8,
8 | | u8
9 | | );
| |_^
6 | struct S(u8, u8);
| ^^^^^^^^
error: aborting due to previous error