Repository: serde-rs/serde
File: serde_derive/src/de.rs (Rust)

Code before:
                    #this::#variant_ident)
            }
        }
        Some(path) => {
            quote_block! {
                let __value: _serde::export::Result<#field_ty, _> = #path(#deserializer);
                _serde::export::Result::map(__value, #this::#variant_ident)
            }
        }
    }
}

fn deserialize_generated_identifier(
    fields: &[(String, Ident)],
    cattrs: &attr::Container,
    is_variant: bool,
    other_idx: Option<usize>
) -> Fragment {
    let this = quote!(__Field);
    let field_idents: &Vec<_> = &fields.iter().map(|&(_, ref ident)| ident).collect();

    let (ignore_variant, fallthrough) = if !is_variant && cattrs.has_flatten() {
        let ignore_variant = quote!(__other(_serde::private::de::Content<'de>),);
        let fallthrough = quote!(_serde::export::Ok(__Field::__other(__value)));
        (Some(ignore_variant), Some(fallthrough))
    } else if other_idx.is_some() {
        let ignore_variant = fields[other_idx.unwrap()].1.clone();
        let fallthrough = quote!(_serde::export::Ok(__Field::#ignore_variant));
        (None, Some(fallthrough))
    } else if is_variant || cattrs.deny_unknown_fields() {
        (None, None)
    } else {
        let ignore_variant = quote!(__ignore,);
        let fallthrough = quote!(_serde::export::Ok(__Field::__ignore));
        (Some(ignore_variant), Some(fallthrough))
    };

    let visitor_impl = Stmts(deserialize_identifier(
        &this,
        fields,
        is_variant,
        fallthrough,
        !is_variant && cattrs.has_flatten(),
    ));

    let lifetime = if !is_variant && cattrs.has_flatten() {
        Some(quote!(<'de>))
    } else {
        None
    };


Review comment (suggestion):
This should be written as `else if let Some(other_idx) = other_idx` to avoid the unwrap below.

Code after:
                    #this::#variant_ident)
            }
        }
        Some(path) => {
            quote_block! {
                let __value: _serde::export::Result<#field_ty, _> = #path(#deserializer);
                _serde::export::Result::map(__value, #this::#variant_ident)
            }
        }
    }
}

fn deserialize_generated_identifier(
    fields: &[(String, Ident)],
    cattrs: &attr::Container,
    is_variant: bool,
    other_idx: Option<usize>
) -> Fragment {
    let this = quote!(__Field);
    let field_idents: &Vec<_> = &fields.iter().map(|&(_, ref ident)| ident).collect();

    let (ignore_variant, fallthrough) = if !is_variant && cattrs.has_flatten() {
        let ignore_variant = quote!(__other(_serde::private::de::Content<'de>),);
        let fallthrough = quote!(_serde::export::Ok(__Field::__other(__value)));
        (Some(ignore_variant), Some(fallthrough))
    } else if let Some(other_idx) = other_idx {
        let ignore_variant = fields[other_idx].1.clone();
        let fallthrough = quote!(_serde::export::Ok(__Field::#ignore_variant));
        (None, Some(fallthrough))
    } else if is_variant || cattrs.deny_unknown_fields() {
        (None, None)
    } else {
        let ignore_variant = quote!(__ignore,);
        let fallthrough = quote!(_serde::export::Ok(__Field::__ignore));
        (Some(ignore_variant), Some(fallthrough))
    };

    let visitor_impl = Stmts(deserialize_identifier(
        &this,
        fields,
        is_variant,
        fallthrough,
        !is_variant && cattrs.has_flatten(),
    ));

    let lifetime = if !is_variant && cattrs.has_flatten() {
        Some(quote!(<'de>))
    } else {
        None
    };