Skip to content

Commit

Permalink
Merge pull request #2266 from flisky/master
Browse files Browse the repository at this point in the history
fix: don't check skipped variant with internal tag
  • Loading branch information
dtolnay authored Jul 26, 2023
2 parents a6a8a33 + 9833474 commit b789286
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
6 changes: 4 additions & 2 deletions serde_derive/src/internals/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
match variant.style {
Style::Struct => {
for field in &variant.fields {
let check_ser = !field.attrs.skip_serializing();
let check_de = !field.attrs.skip_deserializing();
let check_ser =
!(field.attrs.skip_serializing() || variant.attrs.skip_serializing());
let check_de =
!(field.attrs.skip_deserializing() || variant.attrs.skip_deserializing());
let name = field.attrs.name();
let ser_name = name.serialize_name();

Expand Down
31 changes: 31 additions & 0 deletions test_suite/tests/test_annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2260,6 +2260,37 @@ fn test_externally_tagged_enum_containing_flatten() {
);
}

#[test]
fn test_internally_tagged_enum_with_skipped_conflict() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[serde(tag = "t")]
enum Data {
A,
#[serde(skip)]
B {
t: String
},
C {
#[serde(default, skip)]
t: String
},
}

let _data = Data::B { t: "".to_string() };

let data = Data::C { t: "".to_string() };

assert_tokens(
&data,
&[
Token::Struct { name: "Data", len: 1 },
Token::Str("t"),
Token::Str("C"),
Token::StructEnd,
],
);
}

#[test]
fn test_internally_tagged_enum_containing_flatten() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
Expand Down

0 comments on commit b789286

Please sign in to comment.