Skip to content

Commit

Permalink
Remove dead code - serialize_struct_as_map always called when cattrs.…
Browse files Browse the repository at this point in the history
…has_flatten()==true
  • Loading branch information
Mingun committed Aug 11, 2024
1 parent 005cb84 commit 547d843
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions serde_derive/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,26 +376,8 @@ fn serialize_struct_as_map(

let let_mut = mut_if(serialized_fields.peek().is_some() || tag_field_exists);

let len = if cattrs.has_flatten() {
quote!(_serde::__private::None)
} else {
let len = serialized_fields
.map(|field| match field.attrs.skip_serializing_if() {
None => quote!(1),
Some(path) => {
let field_expr = get_member(params, field, &field.member);
quote!(if #path(#field_expr) { 0 } else { 1 })
}
})
.fold(
quote!(#tag_field_exists as usize),
|sum, expr| quote!(#sum + #expr),
);
quote!(_serde::__private::Some(#len))
};

quote_block! {
let #let_mut __serde_state = _serde::Serializer::serialize_map(__serializer, #len)?;
let #let_mut __serde_state = _serde::Serializer::serialize_map(__serializer, _serde::__private::None)?;
#tag_field
#(#serialize_fields)*
_serde::ser::SerializeMap::end(__serde_state)
Expand Down

0 comments on commit 547d843

Please sign in to comment.