Merge pull request #1450 from motu42/master

Bug fix to support the tag attribute on braced structs with zero fields
This commit is contained in:
David Tolnay 2018-12-27 21:48:14 -05:00 committed by GitHub
commit 7e5066b878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -319,7 +319,8 @@ fn serialize_struct_as_struct(
.filter(|&field| !field.attrs.skip_serializing())
.peekable();
let let_mut = mut_if(serialized_fields.peek().is_some());
let let_mut = mut_if(serialized_fields.peek().is_some() ||
additional_field_count > 0);
let len = serialized_fields
.map(|field| match field.attrs.skip_serializing_if() {

View File

@ -1413,6 +1413,26 @@ fn test_internally_tagged_struct() {
);
}
#[test]
fn test_internally_tagged_braced_struct_with_zero_fields() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
struct S {}
assert_tokens(
&S{ },
&[
Token::Struct {
name: "S",
len: 1,
},
Token::Str("type"),
Token::Str("S"),
Token::StructEnd,
],
);
}
#[test]
fn test_enum_in_untagged_enum() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]