Merge pull request #1669 from H2CO3/master

Allow untagged unit variants to deserialize from `Visitor::visit_none()`
This commit is contained in:
David Tolnay 2019-11-24 16:13:37 -08:00 committed by GitHub
commit ff70409215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -2510,6 +2510,13 @@ mod content {
{
Ok(())
}
fn visit_none<E>(self) -> Result<(), E>
where
E: de::Error,
{
Ok(())
}
}
}

View File

@ -637,7 +637,10 @@ fn test_untagged_enum() {
],
);
// Serializes to unit, deserializes from either depending on format's
// preference.
assert_tokens(&Untagged::C, &[Token::Unit]);
assert_de_tokens(&Untagged::C, &[Token::None]);
assert_tokens(&Untagged::D(4), &[Token::U8(4)]);
assert_tokens(&Untagged::E("e".to_owned()), &[Token::Str("e")]);
@ -652,11 +655,6 @@ fn test_untagged_enum() {
],
);
assert_de_tokens_error::<Untagged>(
&[Token::None],
"data did not match any variant of untagged enum Untagged",
);
assert_de_tokens_error::<Untagged>(
&[Token::Tuple { len: 1 }, Token::U8(1), Token::TupleEnd],
"data did not match any variant of untagged enum Untagged",