Skip to content

Commit

Permalink
Make most of prepare_enum_variant_enum independent of variant_names_i…
Browse files Browse the repository at this point in the history
…dents item type
  • Loading branch information
dtolnay committed Oct 22, 2024
1 parent 830309f commit 3393ad6
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions serde_derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,33 +1225,33 @@ fn deserialize_homogeneous_enum(
}

fn prepare_enum_variant_enum(variants: &[Variant]) -> (TokenStream, Stmts) {
let mut deserialized_variants = variants
let deserialized_variants = variants
.iter()
.enumerate()
.filter(|&(_, variant)| !variant.attrs.skip_deserializing());

let variant_names_idents: Vec<_> = deserialized_variants
.clone()
.map(|(i, variant)| (field_i(i), variant.attrs.aliases()))
.collect();
.filter(|&(_i, variant)| !variant.attrs.skip_deserializing());

let fallthrough = deserialized_variants
.position(|(_, variant)| variant.attrs.other())
.map(|other_idx| {
let ignore_variant = variant_names_idents[other_idx].0.clone();
.clone()
.find(|(_i, variant)| variant.attrs.other())
.map(|(i, _variant)| {
let ignore_variant = field_i(i);
quote!(_serde::__private::Ok(__Field::#ignore_variant))
});

let variants_stmt = {
let variant_names = variant_names_idents
.iter()
.flat_map(|&(_, aliases)| aliases);
let variant_names = deserialized_variants
.clone()
.flat_map(|(_i, variant)| variant.attrs.aliases());
quote! {
#[doc(hidden)]
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
}
};

let variant_names_idents: Vec<_> = deserialized_variants
.map(|(i, variant)| (field_i(i), variant.attrs.aliases()))
.collect();

let variant_visitor = Stmts(deserialize_generated_identifier(
&variant_names_idents,
false, // variant identifiers do not depend on the presence of flatten fields
Expand Down

0 comments on commit 3393ad6

Please sign in to comment.