Skip to content

Commit

Permalink
Remove generation of unused components of tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Aug 10, 2023
1 parent c2f995c commit f8912c3
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions serde_derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,17 +953,9 @@ fn deserialize_struct(

let field_names_idents: Vec<_> = fields
.iter()
.enumerate()
// Skip fields that shouldn't be deserialized or that were flattened,
// so they don't appear in the storage in their literal form
.filter(|&(_, field)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
.map(|(i, field)| {
(
field.attrs.name().deserialize_name(),
field_i(i),
field.attrs.aliases(),
)
})
.filter(|field| !field.attrs.skip_deserializing() && !field.attrs.flatten())
.collect();
let (consts, field, field_seed) = deserialize_field_identifier(&field_names_idents, cattrs);

Expand Down Expand Up @@ -1019,7 +1011,7 @@ fn deserialize_struct(
} else {
let field_names = field_names_idents
.iter()
.flat_map(|&(_, _, aliases)| aliases);
.flat_map(|field| field.attrs.aliases());

Some(quote! {
#[doc(hidden)]
Expand Down Expand Up @@ -1113,15 +1105,7 @@ fn deserialize_struct_in_place(

let field_names_idents: Vec<_> = fields
.iter()
.enumerate()
.filter(|&(_, field)| !field.attrs.skip_deserializing())
.map(|(i, field)| {
(
field.attrs.name().deserialize_name(),
field_i(i),
field.attrs.aliases(),
)
})
.filter(|field| !field.attrs.skip_deserializing())
.collect();

let (consts, field, field_seed) = deserialize_field_identifier(&field_names_idents, cattrs);
Expand All @@ -1137,7 +1121,7 @@ fn deserialize_struct_in_place(
));
let field_names = field_names_idents
.iter()
.flat_map(|&(_, _, aliases)| aliases);
.flat_map(|field| field.attrs.aliases());
let type_name = cattrs.name().deserialize_name();

let in_place_impl_generics = de_impl_generics.in_place();
Expand Down Expand Up @@ -2038,7 +2022,7 @@ fn deserialize_generated_identifier(
/// Generates enum and its `Deserialize` implementation that represents each
/// non-skipped field of the struct
fn deserialize_field_identifier(
fields: &[(&str, Ident, &BTreeSet<String>)],
fields: &[&Field],
cattrs: &attr::Container,
) -> (TokenStream, TokenStream, TokenStream) {
let (field, field_seed) = if cattrs.has_flatten() {
Expand All @@ -2058,10 +2042,11 @@ fn deserialize_field_identifier(
)
};

// `aliases` also contains a main name
let aliases = fields
.iter()
.map(|(_, _, aliases)| quote!(&[ #(#aliases),* ]));
let aliases = fields.iter().map(|field| {
// `aliases` also contains a main name
let aliases = field.attrs.aliases();
quote!(&[ #(#aliases),* ])
});
let consts = quote! {
#[doc(hidden)]
const ALIASES: &[&[&str]] = &[ #(#aliases),* ];
Expand Down

0 comments on commit f8912c3

Please sign in to comment.