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

Code before:
    for (i, variant) in variants.iter().filter(|variant| !variant.attrs.skip_deserializing()).enumerate() {
        let variant_name = aster::id(format!("__field{}", i));
        let variant_name = quote!(__Field::#variant_name);

        let block = deserialize_variant(
            type_ident,
            impl_generics,
            ty.clone(),
            variant,
            item_attrs,
        );

        let arm = quote! {
            #variant_name => #block
        };
        variant_arms.push(arm);
    }

    let match_variant = if variant_arms.is_empty() {
        // This is an empty enum like `enum Impossible {}` or an enum in which
        // all variants have `#[serde(skip_deserializing)]`.
        quote! {
            visitor.visit_variant::<__Field>().map(|impossible| match impossible {})
        }
    } else {
        quote! {
            match try!(visitor.visit_variant()) {
                #(#variant_arms)*
            }
        }
    };

    let (visitor_item, visitor_ty, visitor_expr) = deserialize_visitor(impl_generics);

    quote!({
        #variant_visitor

        #visitor_item

        impl #impl_generics _serde::de::Visitor for #visitor_ty #where_clause {
            type Value = #ty;

            fn visit_enum<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<#ty, __V::Error>
                where __V: _serde::de::VariantVisitor,
            {
                #match_variant
            }
        }

        #variants_stmt


Review comment (suggestion):
also add the `// FIXME: Replace once we drop support for Rust 1.15:` comment

Code after:
    for (i, variant) in variants.iter().filter(|variant| !variant.attrs.skip_deserializing()).enumerate() {
        let variant_name = aster::id(format!("__field{}", i));
        let variant_name = quote!(__Field::#variant_name);

        let block = deserialize_variant(
            type_ident,
            impl_generics,
            ty.clone(),
            variant,
            item_attrs,
        );

        let arm = quote! {
            #variant_name => #block
        };
        variant_arms.push(arm);
    }

    let match_variant = if variant_arms.is_empty() {
        // This is an empty enum like `enum Impossible {}` or an enum in which
        // all variants have `#[serde(skip_deserializing)]`.
        quote! {
            // FIXME: Once we drop support for Rust 1.15:
            // let Err(err) = visitor.visit_variant::<__Field>();
            // Err(err)
            visitor.visit_variant::<__Field>().map(|impossible| match impossible {})
        }
    } else {
        quote! {
            match try!(visitor.visit_variant()) {
                #(#variant_arms)*
            }
        }
    };

    let (visitor_item, visitor_ty, visitor_expr) = deserialize_visitor(impl_generics);

    quote!({
        #variant_visitor

        #visitor_item

        impl #impl_generics _serde::de::Visitor for #visitor_ty #where_clause {
            type Value = #ty;

            fn visit_enum<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<#ty, __V::Error>
                where __V: _serde::de::VariantVisitor,
            {
                #match_variant
            }
        }