Support empty adjacently tagged enum

This commit is contained in:
David Tolnay 2018-05-07 21:02:42 -07:00
parent 7cd4f49c76
commit 12fe42ed45
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 20 additions and 7 deletions

View File

@ -1393,6 +1393,21 @@ fn deserialize_adjacently_tagged_enum(
}
};
let finish_content_then_tag = if variant_arms.is_empty() {
quote! {
match try!(_serde::de::MapAccess::next_value::<__Field>(&mut __map)) {}
}
} else {
quote! {
let __ret = try!(match try!(_serde::de::MapAccess::next_value(&mut __map)) {
// Deserialize the buffered content now that we know the variant.
#(#variant_arms)*
});
// Visit remaining keys, looking for duplicates.
#visit_remaining_keys
}
};
quote_block! {
#variant_visitor
@ -1469,13 +1484,7 @@ fn deserialize_adjacently_tagged_enum(
// Second key is the tag.
_serde::export::Some(_serde::private::de::TagOrContentField::Tag) => {
let __deserializer = _serde::private::de::ContentDeserializer::<__A::Error>::new(__content);
// Parse the tag.
let __ret = try!(match try!(_serde::de::MapAccess::next_value(&mut __map)) {
// Deserialize the buffered content now that we know the variant.
#(#variant_arms)*
});
// Visit remaining keys, looking for duplicates.
#visit_remaining_keys
#finish_content_then_tag
}
// Second key is a duplicate of the content.
_serde::export::Some(_serde::private::de::TagOrContentField::Content) => {

View File

@ -588,6 +588,10 @@ fn test_gen() {
}
}
}
#[derive(Deserialize)]
#[serde(tag = "t", content = "c")]
enum AdjacentlyTaggedVoid {}
}
//////////////////////////////////////////////////////////////////////////