From dafede93df8563495971f18d7fac0eb83a0ab09f Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 12 Aug 2023 15:33:04 +0500 Subject: [PATCH] Add support for internally tagged enums in non self-describing formats Deserializer methods are only hints which deserializer is not obliged to follow. Both TaggedContentVisitor and InternallyTaggedUnitVisitor accepts only visit_map and visit_seq and that is what derived implementation of Deserialize does for structs. Therefore it is fine to call deserialize_map here, as that already did in derived deserialize implementation --- serde_derive/src/de.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index aa3a7017d..e54be2120 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -1048,7 +1048,7 @@ fn deserialize_struct( _serde::de::VariantAccess::struct_variant(__variant, FIELDS, #visitor_expr) }, StructForm::InternallyTagged(_, deserializer) => quote! { - _serde::Deserializer::deserialize_any(#deserializer, #visitor_expr) + _serde::Deserializer::deserialize_map(#deserializer, #visitor_expr) }, StructForm::Untagged(_, deserializer) => quote! { _serde::Deserializer::deserialize_any(#deserializer, #visitor_expr) @@ -1392,7 +1392,7 @@ fn deserialize_internally_tagged_enum( #variants_stmt - let (__tag, __content) = _serde::Deserializer::deserialize_any( + let (__tag, __content) = _serde::Deserializer::deserialize_map( __deserializer, _serde::__private::de::TaggedContentVisitor::<__Field>::new(#tag, #expecting))?; let __deserializer = _serde::__private::de::ContentDeserializer::<__D::Error>::new(__content); @@ -1840,7 +1840,7 @@ fn deserialize_internally_tagged_variant( quote!((#default)) }); quote_block! { - _serde::Deserializer::deserialize_any(#deserializer, _serde::__private::de::InternallyTaggedUnitVisitor::new(#type_name, #variant_name))?; + _serde::Deserializer::deserialize_map(#deserializer, _serde::__private::de::InternallyTaggedUnitVisitor::new(#type_name, #variant_name))?; _serde::__private::Ok(#this_value::#variant_ident #default) } }