Skip to content

Commit 5d4a04d

Browse files
committed
Because serde-rs/serde#2371 and serde-rs/serde#1904 are fixed, remove workarounds for them
1 parent e93181c commit 5d4a04d

File tree

2 files changed

+44
-91
lines changed

2 files changed

+44
-91
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ arbitrary = { version = "1", features = ["derive"], optional = true }
3030
criterion = "0.4"
3131
pretty_assertions = "1.4"
3232
regex = "1"
33-
# #[serde(other)] allowed not only inside field_identifier since 1.0.79
33+
# https://github.com/serde-rs/serde/issues/1904 is fixed since 1.0.206
3434
# serde does not follow semver in numbering and their dependencies, so we specifying patch here
35-
serde_derive = { version = "1.0.79" }
35+
serde_derive = { version = "1.0.206" }
3636
serde-value = "0.7"
3737
tokio = { version = "1.21", default-features = false, features = ["macros", "rt"] }
3838
tokio-test = "0.4"

tests/serde-se.rs

Lines changed: 42 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ enum ExternallyTagged {
6767
nested: Nested,
6868
string: &'static str,
6969
},
70+
Flatten {
71+
#[serde(flatten)]
72+
nested: Nested,
73+
string: &'static str,
74+
},
7075
/// `float` field serialized as textual content instead of a tag
7176
Text {
7277
#[serde(rename = "$text")]
@@ -80,22 +85,6 @@ enum ExternallyTagged {
8085
},
8186
}
8287

83-
/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
84-
/// incorrect code generation when deriving `Deserialize`.
85-
///
86-
/// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
87-
///
88-
/// Anyway, deserialization of that type in roundtrip suffers from
89-
/// <https://github.com/serde-rs/serde/issues/1183>
90-
#[derive(Debug, PartialEq, Deserialize, Serialize)]
91-
enum ExternallyTaggedWorkaround {
92-
Flatten {
93-
#[serde(flatten)]
94-
nested: Nested,
95-
string: &'static str,
96-
},
97-
}
98-
9988
#[derive(Debug, PartialEq, Deserialize, Serialize)]
10089
#[serde(tag = "tag")]
10190
enum InternallyTagged {
@@ -111,6 +100,11 @@ enum InternallyTagged {
111100
nested: Nested,
112101
string: &'static str,
113102
},
103+
Flatten {
104+
#[serde(flatten)]
105+
nested: Nested,
106+
string: &'static str,
107+
},
114108
/// `float` field serialized as textual content instead of a tag
115109
Text {
116110
#[serde(rename = "$text")]
@@ -124,23 +118,6 @@ enum InternallyTagged {
124118
},
125119
}
126120

127-
/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
128-
/// incorrect code generation when deriving `Deserialize`.
129-
///
130-
/// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
131-
///
132-
/// Anyway, deserialization of that type in roundtrip suffers from
133-
/// <https://github.com/serde-rs/serde/issues/1183>
134-
#[derive(Debug, PartialEq, Serialize)]
135-
#[serde(tag = "tag")]
136-
enum InternallyTaggedWorkaround {
137-
Flatten {
138-
#[serde(flatten)]
139-
nested: Nested,
140-
string: &'static str,
141-
},
142-
}
143-
144121
#[derive(Debug, PartialEq, Deserialize, Serialize)]
145122
#[serde(tag = "tag", content = "content")]
146123
enum AdjacentlyTagged {
@@ -155,6 +132,11 @@ enum AdjacentlyTagged {
155132
nested: Nested,
156133
string: &'static str,
157134
},
135+
Flatten {
136+
#[serde(flatten)]
137+
nested: Nested,
138+
string: &'static str,
139+
},
158140
/// `float` field serialized as textual content instead of a tag
159141
Text {
160142
#[serde(rename = "$text")]
@@ -168,23 +150,6 @@ enum AdjacentlyTagged {
168150
},
169151
}
170152

171-
/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
172-
/// incorrect code generation when deriving `Deserialize`.
173-
///
174-
/// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
175-
///
176-
/// Anyway, deserialization of that type in roundtrip suffers from
177-
/// <https://github.com/serde-rs/serde/issues/1183>
178-
#[derive(Serialize)]
179-
#[serde(tag = "tag", content = "content")]
180-
enum AdjacentlyTaggedWorkaround {
181-
Flatten {
182-
#[serde(flatten)]
183-
nested: Nested,
184-
string: &'static str,
185-
},
186-
}
187-
188153
#[derive(Debug, PartialEq, Deserialize, Serialize)]
189154
#[serde(untagged)]
190155
enum Untagged {
@@ -199,6 +164,11 @@ enum Untagged {
199164
nested: Nested,
200165
string: &'static str,
201166
},
167+
Flatten {
168+
#[serde(flatten)]
169+
nested: Nested,
170+
string: &'static str,
171+
},
202172
/// `float` field serialized as textual content instead of a tag
203173
Text {
204174
#[serde(rename = "$text")]
@@ -212,23 +182,6 @@ enum Untagged {
212182
},
213183
}
214184

215-
/// Having both `#[serde(flatten)]` and `'static` fields in one struct leads to
216-
/// incorrect code generation when deriving `Deserialize`.
217-
///
218-
/// TODO: Merge into main enum after fixing <https://github.com/serde-rs/serde/issues/2371>
219-
///
220-
/// Anyway, deserialization of that type in roundtrip suffers from
221-
/// <https://github.com/serde-rs/serde/issues/1183>
222-
#[derive(Serialize)]
223-
#[serde(untagged)]
224-
enum UntaggedWorkaround {
225-
Flatten {
226-
#[serde(flatten)]
227-
nested: Nested,
228-
string: &'static str,
229-
},
230-
}
231-
232185
mod without_root {
233186
use super::*;
234187
use pretty_assertions::assert_eq;
@@ -443,7 +396,7 @@ mod without_root {
443396
// NOTE: Cannot be deserialized in roundtrip due to
444397
// https://github.com/serde-rs/serde/issues/1183
445398
serialize_as_only!(flatten_struct:
446-
ExternallyTaggedWorkaround::Flatten {
399+
ExternallyTagged::Flatten {
447400
nested: Nested { float: 42.0 },
448401
string: "answer",
449402
}
@@ -822,7 +775,7 @@ mod without_root {
822775
// NOTE: Cannot be deserialized in roundtrip due to
823776
// https://github.com/serde-rs/serde/issues/1183
824777
serialize_as_only!(flatten_struct:
825-
Root { field: ExternallyTaggedWorkaround::Flatten {
778+
Root { field: ExternallyTagged::Flatten {
826779
nested: Nested { float: 42.0 },
827780
string: "answer",
828781
}}
@@ -914,7 +867,7 @@ mod without_root {
914867
// NOTE: Cannot be deserialized in roundtrip due to
915868
// https://github.com/serde-rs/serde/issues/1183
916869
serialize_as_only!(flatten_struct:
917-
Root { field: Inner { inner: ExternallyTaggedWorkaround::Flatten {
870+
Root { field: Inner { inner: ExternallyTagged::Flatten {
918871
nested: Nested { float: 42.0 },
919872
string: "answer",
920873
}}}
@@ -996,12 +949,12 @@ mod without_root {
996949
=> Unsupported("cannot serialize enum struct variant `ExternallyTagged::Holder` as text content value"),
997950
"<Root");
998951
err!(flatten_struct:
999-
Root { field: ExternallyTaggedWorkaround::Flatten {
952+
Root { field: ExternallyTagged::Flatten {
1000953
nested: Nested { float: 42.0 },
1001954
string: "answer",
1002955
}}
1003956
// Flatten enum struct variants represented as newtype variants containing maps
1004-
=> Unsupported("cannot serialize enum newtype variant `ExternallyTaggedWorkaround::Flatten` as text content value"),
957+
=> Unsupported("cannot serialize enum newtype variant `ExternallyTagged::Flatten` as text content value"),
1005958
"<Root");
1006959
err!(empty_struct:
1007960
Root { field: ExternallyTagged::Empty {} }
@@ -1055,12 +1008,12 @@ mod without_root {
10551008
=> Unsupported("cannot serialize enum struct variant `ExternallyTagged::Holder` as text content value"),
10561009
"<Root");
10571010
err!(flatten_struct:
1058-
Root { field: Inner { inner: ExternallyTaggedWorkaround::Flatten {
1011+
Root { field: Inner { inner: ExternallyTagged::Flatten {
10591012
nested: Nested { float: 42.0 },
10601013
string: "answer",
10611014
}}}
10621015
// Flatten enum struct variants represented as newtype variants containing maps
1063-
=> Unsupported("cannot serialize enum newtype variant `ExternallyTaggedWorkaround::Flatten` as text content value"),
1016+
=> Unsupported("cannot serialize enum newtype variant `ExternallyTagged::Flatten` as text content value"),
10641017
"<Root");
10651018
err!(empty_struct:
10661019
Root { field: Inner { inner: ExternallyTagged::Empty {} } }
@@ -1125,7 +1078,7 @@ mod without_root {
11251078
// serde serializes flatten structs as maps, and we do not support
11261079
// serialization of maps without root tag
11271080
err!(flatten_struct:
1128-
InternallyTaggedWorkaround::Flatten {
1081+
InternallyTagged::Flatten {
11291082
nested: Nested { float: 42.0 },
11301083
string: "answer",
11311084
}
@@ -1201,17 +1154,17 @@ mod without_root {
12011154
// NOTE: Cannot be deserialized in roundtrip due to
12021155
// https://github.com/serde-rs/serde/issues/1183
12031156
serialize_as_only!(flatten_struct:
1204-
AdjacentlyTaggedWorkaround::Flatten {
1157+
AdjacentlyTagged::Flatten {
12051158
nested: Nested { float: 42.0 },
12061159
string: "answer",
12071160
}
1208-
=> "<AdjacentlyTaggedWorkaround>\
1161+
=> "<AdjacentlyTagged>\
12091162
<tag>Flatten</tag>\
12101163
<content>\
12111164
<float>42</float>\
12121165
<string>answer</string>\
12131166
</content>\
1214-
</AdjacentlyTaggedWorkaround>");
1167+
</AdjacentlyTagged>");
12151168
serialize_as!(empty_struct:
12161169
AdjacentlyTagged::Empty {}
12171170
=> "<AdjacentlyTagged>\
@@ -1272,7 +1225,7 @@ mod without_root {
12721225
// serde serializes flatten structs as maps, and we do not support
12731226
// serialization of maps without root tag
12741227
err!(flatten_struct:
1275-
UntaggedWorkaround::Flatten {
1228+
Untagged::Flatten {
12761229
nested: Nested { float: 42.0 },
12771230
string: "answer",
12781231
}
@@ -1470,7 +1423,7 @@ mod without_root {
14701423
<string>answer</string>\n\
14711424
</Holder>");
14721425
serialize_as!(flatten_struct:
1473-
ExternallyTaggedWorkaround::Flatten {
1426+
ExternallyTagged::Flatten {
14741427
nested: Nested { float: 42.0 },
14751428
string: "answer",
14761429
}
@@ -1575,7 +1528,7 @@ mod without_root {
15751528
// serde serializes flatten structs as maps, and we do not support
15761529
// serialization of maps without root tag
15771530
err!(flatten_struct:
1578-
InternallyTaggedWorkaround::Flatten {
1531+
InternallyTagged::Flatten {
15791532
nested: Nested { float: 42.0 },
15801533
string: "answer",
15811534
}
@@ -1647,17 +1600,17 @@ mod without_root {
16471600
</content>\n\
16481601
</AdjacentlyTagged>");
16491602
serialize_as!(flatten_struct:
1650-
AdjacentlyTaggedWorkaround::Flatten {
1603+
AdjacentlyTagged::Flatten {
16511604
nested: Nested { float: 42.0 },
16521605
string: "answer",
16531606
}
1654-
=> "<AdjacentlyTaggedWorkaround>\n \
1607+
=> "<AdjacentlyTagged>\n \
16551608
<tag>Flatten</tag>\n \
16561609
<content>\n \
16571610
<float>42</float>\n \
16581611
<string>answer</string>\n \
16591612
</content>\n\
1660-
</AdjacentlyTaggedWorkaround>");
1613+
</AdjacentlyTagged>");
16611614
serialize_as!(empty_struct:
16621615
AdjacentlyTagged::Empty {}
16631616
=> "<AdjacentlyTagged>\n \
@@ -1710,7 +1663,7 @@ mod without_root {
17101663
<string>answer</string>\n\
17111664
</Untagged>");
17121665
err!(flatten_struct:
1713-
UntaggedWorkaround::Flatten {
1666+
Untagged::Flatten {
17141667
nested: Nested { float: 42.0 },
17151668
string: "answer",
17161669
}
@@ -2053,7 +2006,7 @@ mod with_root {
20532006
// NOTE: Cannot be deserialized in roundtrip due to
20542007
// https://github.com/serde-rs/serde/issues/1183
20552008
serialize_as_only!(flatten_struct:
2056-
ExternallyTaggedWorkaround::Flatten {
2009+
ExternallyTagged::Flatten {
20572010
nested: Nested { float: 42.0 },
20582011
string: "answer",
20592012
}
@@ -2167,7 +2120,7 @@ mod with_root {
21672120
// NOTE: Cannot be deserialized in roundtrip due to
21682121
// https://github.com/serde-rs/serde/issues/1183
21692122
serialize_as_only!(flatten_struct:
2170-
InternallyTaggedWorkaround::Flatten {
2123+
InternallyTagged::Flatten {
21712124
nested: Nested { float: 42.0 },
21722125
string: "answer",
21732126
}
@@ -2247,7 +2200,7 @@ mod with_root {
22472200
// NOTE: Cannot be deserialized in roundtrip due to
22482201
// https://github.com/serde-rs/serde/issues/1183
22492202
serialize_as_only!(flatten_struct:
2250-
AdjacentlyTaggedWorkaround::Flatten {
2203+
AdjacentlyTagged::Flatten {
22512204
nested: Nested { float: 42.0 },
22522205
string: "answer",
22532206
}
@@ -2326,7 +2279,7 @@ mod with_root {
23262279
// NOTE: Cannot be deserialized in roundtrip due to
23272280
// https://github.com/serde-rs/serde/issues/1183
23282281
serialize_as_only!(flatten_struct:
2329-
UntaggedWorkaround::Flatten {
2282+
Untagged::Flatten {
23302283
nested: Nested { float: 42.0 },
23312284
string: "answer",
23322285
}

0 commit comments

Comments
 (0)