Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing case of the one-tuple-struct-inside-unwrapped-newtype-variant bug #516

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ While data structures with any of these attributes should generally roundtrip th
- zero-length arrays / tuples / tuple structs / structs / tuple variants / struct variants
- `Option`s with `#[enable(implicit_some)]` must not contain any of these or a unit, unit struct, or an untagged unit variant
- externally tagged tuple variants with just one field (that are not newtype variants)
- tuples or arrays with just one element are not supported inside newtype variants with `#[enable(unwrap_variant_newtypes)]`
- tuples or arrays or tuple structs with just one element are not supported inside newtype variants with `#[enable(unwrap_variant_newtypes)]` (including `Some`)
- a `ron::value::RawValue`
- untagged tuple / struct variants with no fields are not supported
- untagged tuple variants with just one field (that are not newtype variants) are not supported when the `#![enable(unwrap_variant_newtypes)]` extension is enabled
Expand Down
10 changes: 10 additions & 0 deletions fuzz/fuzz_targets/bench/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5398,6 +5398,16 @@ impl<'a> SerdeDataType<'a> {
return false;
}

if fields.len() == 1
&& inside_newtype_variant
&& pretty
.extensions
.contains(Extensions::UNWRAP_VARIANT_NEWTYPES)
{
// BUG: a one-length tuple struct inside an unwrapped variant newtype will be swallowed
return false;
}

fields
.iter()
.all(|field| field.supported_inside_untagged(pretty, false, false))
Expand Down
10 changes: 4 additions & 6 deletions tests/502_known_bugs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,21 +736,19 @@ fn one_tuple_inside_unwrapped_newtype_variant_inside_adjacently_tagged() {
#[test]
fn one_tuple_inside_unwrapped_newtype_variant_inside_untagged() {
#[derive(PartialEq, Debug, Serialize, Deserialize)]
enum A {
Newtype((i32,)),
}
struct OneTuple(i32, #[serde(skip)] ());

#[derive(PartialEq, Debug, Serialize, Deserialize)]
#[serde(untagged)]
enum Untagged {
B { ho: i32, a: A },
B { ho: i32, a: Option<OneTuple> },
}

assert_eq!(
check_roundtrip(
&Untagged::B {
ho: 24,
a: A::Newtype((42,))
a: Some(OneTuple(42, ()))
},
PrettyConfig::default()
),
Expand All @@ -760,7 +758,7 @@ fn one_tuple_inside_unwrapped_newtype_variant_inside_untagged() {
check_roundtrip(
&Untagged::B {
ho: 24,
a: A::Newtype((42,))
a: Some(OneTuple(42, ()))
},
PrettyConfig::default().extensions(Extensions::UNWRAP_VARIANT_NEWTYPES)
),
Expand Down
Loading