Skip to content

Commit

Permalink
Extend test_internally_tagged_newtype_variant_containing_unit_struct …
Browse files Browse the repository at this point in the history
…to cover structs and seqs
  • Loading branch information
Mingun committed Feb 2, 2021
1 parent 3257851 commit b60c03e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion serde/src/private/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,8 +1287,9 @@ mod content {
// }
//
// We want {"topic":"Info"} to deserialize even though
// ordinarily unit structs do not deserialize from empty map.
// ordinarily unit structs do not deserialize from empty map/seq.
Content::Map(ref v) if v.is_empty() => visitor.visit_unit(),
Content::Seq(ref v) if v.is_empty() => visitor.visit_unit(),
_ => self.deserialize_any(visitor),
}
}
Expand Down
19 changes: 19 additions & 0 deletions test_suite/tests/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,25 @@ fn test_internally_tagged_newtype_variant_containing_unit_struct() {
Token::MapEnd,
],
);

assert_de_tokens(
&Message::Info(Info),
&[
Token::Struct { name: "Message", len: 1 },
Token::Str("topic"),
Token::Str("Info"),
Token::StructEnd,
],
);

assert_de_tokens(
&Message::Info(Info),
&[
Token::Seq { len: Some(1) },
Token::Str("Info"),
Token::SeqEnd,
],
);
}

#[deny(safe_packed_borrows)]
Expand Down

0 comments on commit b60c03e

Please sign in to comment.