From 5d4a04d6749a78778bf2e342788ed359cba8268e Mon Sep 17 00:00:00 2001 From: Mingun Date: Sun, 17 Sep 2023 19:28:05 +0500 Subject: [PATCH] Because https://github.com/serde-rs/serde/issues/2371 and https://github.com/serde-rs/serde/issues/1904 are fixed, remove workarounds for them --- Cargo.toml | 4 +- tests/serde-se.rs | 131 +++++++++++++++------------------------------- 2 files changed, 44 insertions(+), 91 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d512c9ee..fcd6494f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,9 +30,9 @@ arbitrary = { version = "1", features = ["derive"], optional = true } criterion = "0.4" pretty_assertions = "1.4" regex = "1" -# #[serde(other)] allowed not only inside field_identifier since 1.0.79 +# https://github.com/serde-rs/serde/issues/1904 is fixed since 1.0.206 # serde does not follow semver in numbering and their dependencies, so we specifying patch here -serde_derive = { version = "1.0.79" } +serde_derive = { version = "1.0.206" } serde-value = "0.7" tokio = { version = "1.21", default-features = false, features = ["macros", "rt"] } tokio-test = "0.4" diff --git a/tests/serde-se.rs b/tests/serde-se.rs index 3c4f7d12..fc560628 100644 --- a/tests/serde-se.rs +++ b/tests/serde-se.rs @@ -67,6 +67,11 @@ enum ExternallyTagged { nested: Nested, string: &'static str, }, + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, /// `float` field serialized as textual content instead of a tag Text { #[serde(rename = "$text")] @@ -80,22 +85,6 @@ enum ExternallyTagged { }, } -/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to -/// incorrect code generation when deriving `Deserialize`. -/// -/// TODO: Merge into main enum after fixing -/// -/// Anyway, deserialization of that type in roundtrip suffers from -/// -#[derive(Debug, PartialEq, Deserialize, Serialize)] -enum ExternallyTaggedWorkaround { - Flatten { - #[serde(flatten)] - nested: Nested, - string: &'static str, - }, -} - #[derive(Debug, PartialEq, Deserialize, Serialize)] #[serde(tag = "tag")] enum InternallyTagged { @@ -111,6 +100,11 @@ enum InternallyTagged { nested: Nested, string: &'static str, }, + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, /// `float` field serialized as textual content instead of a tag Text { #[serde(rename = "$text")] @@ -124,23 +118,6 @@ enum InternallyTagged { }, } -/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to -/// incorrect code generation when deriving `Deserialize`. -/// -/// TODO: Merge into main enum after fixing -/// -/// Anyway, deserialization of that type in roundtrip suffers from -/// -#[derive(Debug, PartialEq, Serialize)] -#[serde(tag = "tag")] -enum InternallyTaggedWorkaround { - Flatten { - #[serde(flatten)] - nested: Nested, - string: &'static str, - }, -} - #[derive(Debug, PartialEq, Deserialize, Serialize)] #[serde(tag = "tag", content = "content")] enum AdjacentlyTagged { @@ -155,6 +132,11 @@ enum AdjacentlyTagged { nested: Nested, string: &'static str, }, + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, /// `float` field serialized as textual content instead of a tag Text { #[serde(rename = "$text")] @@ -168,23 +150,6 @@ enum AdjacentlyTagged { }, } -/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to -/// incorrect code generation when deriving `Deserialize`. -/// -/// TODO: Merge into main enum after fixing -/// -/// Anyway, deserialization of that type in roundtrip suffers from -/// -#[derive(Serialize)] -#[serde(tag = "tag", content = "content")] -enum AdjacentlyTaggedWorkaround { - Flatten { - #[serde(flatten)] - nested: Nested, - string: &'static str, - }, -} - #[derive(Debug, PartialEq, Deserialize, Serialize)] #[serde(untagged)] enum Untagged { @@ -199,6 +164,11 @@ enum Untagged { nested: Nested, string: &'static str, }, + Flatten { + #[serde(flatten)] + nested: Nested, + string: &'static str, + }, /// `float` field serialized as textual content instead of a tag Text { #[serde(rename = "$text")] @@ -212,23 +182,6 @@ enum Untagged { }, } -/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to -/// incorrect code generation when deriving `Deserialize`. -/// -/// TODO: Merge into main enum after fixing -/// -/// Anyway, deserialization of that type in roundtrip suffers from -/// -#[derive(Serialize)] -#[serde(untagged)] -enum UntaggedWorkaround { - Flatten { - #[serde(flatten)] - nested: Nested, - string: &'static str, - }, -} - mod without_root { use super::*; use pretty_assertions::assert_eq; @@ -443,7 +396,7 @@ mod without_root { // NOTE: Cannot be deserialized in roundtrip due to // https://github.com/serde-rs/serde/issues/1183 serialize_as_only!(flatten_struct: - ExternallyTaggedWorkaround::Flatten { + ExternallyTagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", } @@ -822,7 +775,7 @@ mod without_root { // NOTE: Cannot be deserialized in roundtrip due to // https://github.com/serde-rs/serde/issues/1183 serialize_as_only!(flatten_struct: - Root { field: ExternallyTaggedWorkaround::Flatten { + Root { field: ExternallyTagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", }} @@ -914,7 +867,7 @@ mod without_root { // NOTE: Cannot be deserialized in roundtrip due to // https://github.com/serde-rs/serde/issues/1183 serialize_as_only!(flatten_struct: - Root { field: Inner { inner: ExternallyTaggedWorkaround::Flatten { + Root { field: Inner { inner: ExternallyTagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", }}} @@ -996,12 +949,12 @@ mod without_root { => Unsupported("cannot serialize enum struct variant `ExternallyTagged::Holder` as text content value"), " Unsupported("cannot serialize enum newtype variant `ExternallyTaggedWorkaround::Flatten` as text content value"), + => Unsupported("cannot serialize enum newtype variant `ExternallyTagged::Flatten` as text content value"), " Unsupported("cannot serialize enum struct variant `ExternallyTagged::Holder` as text content value"), " Unsupported("cannot serialize enum newtype variant `ExternallyTaggedWorkaround::Flatten` as text content value"), + => Unsupported("cannot serialize enum newtype variant `ExternallyTagged::Flatten` as text content value"), " "\ + => "\ Flatten\ \ 42\ answer\ \ - "); + "); serialize_as!(empty_struct: AdjacentlyTagged::Empty {} => "\ @@ -1272,7 +1225,7 @@ mod without_root { // serde serializes flatten structs as maps, and we do not support // serialization of maps without root tag err!(flatten_struct: - UntaggedWorkaround::Flatten { + Untagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", } @@ -1470,7 +1423,7 @@ mod without_root { answer\n\ "); serialize_as!(flatten_struct: - ExternallyTaggedWorkaround::Flatten { + ExternallyTagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", } @@ -1575,7 +1528,7 @@ mod without_root { // serde serializes flatten structs as maps, and we do not support // serialization of maps without root tag err!(flatten_struct: - InternallyTaggedWorkaround::Flatten { + InternallyTagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", } @@ -1647,17 +1600,17 @@ mod without_root { \n\ "); serialize_as!(flatten_struct: - AdjacentlyTaggedWorkaround::Flatten { + AdjacentlyTagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", } - => "\n \ + => "\n \ Flatten\n \ \n \ 42\n \ answer\n \ \n\ - "); + "); serialize_as!(empty_struct: AdjacentlyTagged::Empty {} => "\n \ @@ -1710,7 +1663,7 @@ mod without_root { answer\n\ "); err!(flatten_struct: - UntaggedWorkaround::Flatten { + Untagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", } @@ -2053,7 +2006,7 @@ mod with_root { // NOTE: Cannot be deserialized in roundtrip due to // https://github.com/serde-rs/serde/issues/1183 serialize_as_only!(flatten_struct: - ExternallyTaggedWorkaround::Flatten { + ExternallyTagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", } @@ -2167,7 +2120,7 @@ mod with_root { // NOTE: Cannot be deserialized in roundtrip due to // https://github.com/serde-rs/serde/issues/1183 serialize_as_only!(flatten_struct: - InternallyTaggedWorkaround::Flatten { + InternallyTagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", } @@ -2247,7 +2200,7 @@ mod with_root { // NOTE: Cannot be deserialized in roundtrip due to // https://github.com/serde-rs/serde/issues/1183 serialize_as_only!(flatten_struct: - AdjacentlyTaggedWorkaround::Flatten { + AdjacentlyTagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", } @@ -2326,7 +2279,7 @@ mod with_root { // NOTE: Cannot be deserialized in roundtrip due to // https://github.com/serde-rs/serde/issues/1183 serialize_as_only!(flatten_struct: - UntaggedWorkaround::Flatten { + Untagged::Flatten { nested: Nested { float: 42.0 }, string: "answer", }