Fix internally tagged struct variant containing unit variant containing borrowed string

This commit is contained in:
David Tolnay 2017-05-14 12:21:00 -07:00
parent c68b959696
commit cda1fc46b0
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 31 additions and 2 deletions

View File

@ -1082,7 +1082,7 @@ mod content {
} }
(variant, Some(value)) (variant, Some(value))
} }
Content::String(variant) => (Content::String(variant), None), s @ Content::String(_) | s @ Content::Str(_) => (s, None),
other => { other => {
return Err(de::Error::invalid_type(other.unexpected(), &"string or map"),); return Err(de::Error::invalid_type(other.unexpected(), &"string or map"),);
} }
@ -1476,7 +1476,7 @@ mod content {
} }
(variant, Some(value)) (variant, Some(value))
} }
ref s @ Content::String(_) => (s, None), ref s @ Content::String(_) | ref s @ Content::Str(_) => (s, None),
ref other => { ref other => {
return Err(de::Error::invalid_type(other.unexpected(), &"string or map"),); return Err(de::Error::invalid_type(other.unexpected(), &"string or map"),);
} }

View File

@ -695,6 +695,35 @@ fn test_internally_tagged_enum() {
); );
} }
#[test]
fn test_internally_tagged_struct_variant_containing_unit_variant() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub enum Level {
Info,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "action")]
pub enum Message {
Log { level: Level },
}
assert_de_tokens(
&Message::Log { level: Level::Info },
&[
Token::Struct { name: "Message", len: 2 },
Token::Str("action"),
Token::Str("Log"),
Token::Str("level"),
Token::BorrowedStr("Info"),
Token::StructEnd,
],
);
}
#[test] #[test]
fn test_internally_tagged_borrow() { fn test_internally_tagged_borrow() {
#[derive(Debug, PartialEq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Serialize, Deserialize)]