@@ -285,13 +285,7 @@ fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment {
285
285
deserialize_struct ( params, fields, & cont. attrs , StructForm :: Struct )
286
286
}
287
287
Data :: Struct ( Style :: Tuple , fields) | Data :: Struct ( Style :: Newtype , fields) => {
288
- deserialize_tuple (
289
- params,
290
- fields,
291
- & cont. attrs ,
292
- cont. attrs . has_flatten ( ) ,
293
- TupleForm :: Tuple ,
294
- )
288
+ deserialize_tuple ( params, fields, & cont. attrs , TupleForm :: Tuple )
295
289
}
296
290
Data :: Struct ( Style :: Unit , _) => deserialize_unit_struct ( params, & cont. attrs ) ,
297
291
}
@@ -465,11 +459,10 @@ fn deserialize_tuple(
465
459
params : & Parameters ,
466
460
fields : & [ Field ] ,
467
461
cattrs : & attr:: Container ,
468
- has_flatten : bool ,
469
462
form : TupleForm ,
470
463
) -> Fragment {
471
464
assert ! (
472
- !has_flatten,
465
+ !has_flatten( fields ) ,
473
466
"tuples and tuple variants cannot have flatten fields"
474
467
) ;
475
468
@@ -590,7 +583,7 @@ fn deserialize_tuple_in_place(
590
583
cattrs : & attr:: Container ,
591
584
) -> Fragment {
592
585
assert ! (
593
- !cattrs . has_flatten( ) ,
586
+ !has_flatten( fields ) ,
594
587
"tuples and tuple variants cannot have flatten fields"
595
588
) ;
596
589
@@ -972,9 +965,7 @@ fn deserialize_struct(
972
965
} )
973
966
. collect ( ) ;
974
967
975
- let has_flatten = fields
976
- . iter ( )
977
- . any ( |field| field. attrs . flatten ( ) && !field. attrs . skip_deserializing ( ) ) ;
968
+ let has_flatten = has_flatten ( fields) ;
978
969
let field_visitor = deserialize_field_identifier ( & field_names_idents, cattrs, has_flatten) ;
979
970
980
971
// untagged struct variants do not get a visit_seq method. The same applies to
@@ -1114,7 +1105,7 @@ fn deserialize_struct_in_place(
1114
1105
) -> Option < Fragment > {
1115
1106
// for now we do not support in_place deserialization for structs that
1116
1107
// are represented as map.
1117
- if cattrs . has_flatten ( ) {
1108
+ if has_flatten ( fields ) {
1118
1109
return None ;
1119
1110
}
1120
1111
@@ -1830,7 +1821,6 @@ fn deserialize_externally_tagged_variant(
1830
1821
params,
1831
1822
& variant. fields ,
1832
1823
cattrs,
1833
- variant. attrs . has_flatten ( ) ,
1834
1824
TupleForm :: ExternallyTagged ( variant_ident) ,
1835
1825
) ,
1836
1826
Style :: Struct => deserialize_struct (
@@ -1930,7 +1920,6 @@ fn deserialize_untagged_variant(
1930
1920
params,
1931
1921
& variant. fields ,
1932
1922
cattrs,
1933
- variant. attrs . has_flatten ( ) ,
1934
1923
TupleForm :: Untagged ( variant_ident, deserializer) ,
1935
1924
) ,
1936
1925
Style :: Struct => deserialize_struct (
@@ -2703,7 +2692,7 @@ fn deserialize_map_in_place(
2703
2692
cattrs : & attr:: Container ,
2704
2693
) -> Fragment {
2705
2694
assert ! (
2706
- !cattrs . has_flatten( ) ,
2695
+ !has_flatten( fields ) ,
2707
2696
"inplace deserialization of maps does not support flatten fields"
2708
2697
) ;
2709
2698
@@ -3038,6 +3027,13 @@ fn effective_style(variant: &Variant) -> Style {
3038
3027
}
3039
3028
}
3040
3029
3030
+ /// True if there are fields that is not skipped and has a `#[serde(flatten)]` attribute.
3031
+ fn has_flatten ( fields : & [ Field ] ) -> bool {
3032
+ fields
3033
+ . iter ( )
3034
+ . any ( |field| field. attrs . flatten ( ) && !field. attrs . skip_deserializing ( ) )
3035
+ }
3036
+
3041
3037
struct DeImplGenerics < ' a > ( & ' a Parameters ) ;
3042
3038
#[ cfg( feature = "deserialize_in_place" ) ]
3043
3039
struct InPlaceImplGenerics < ' a > ( & ' a Parameters ) ;
0 commit comments