From 6588b0ad3777f7ad930d68ab4b9ec5b9c25398e0 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 17 Aug 2024 15:26:59 +0500 Subject: [PATCH] Cover Content::Seq case in VariantRefDeserializer::struct_variant --- serde/src/private/de.rs | 2 ++ test_suite/tests/test_enum_untagged.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/serde/src/private/de.rs b/serde/src/private/de.rs index 864f93b0..0c6f4d3a 100644 --- a/serde/src/private/de.rs +++ b/serde/src/private/de.rs @@ -2217,6 +2217,8 @@ mod content { Some(Content::Map(v)) => { de::Deserializer::deserialize_any(MapRefDeserializer::new(v), visitor) } + // Covered by tests/test_enum_untagged.rs + // newtype_enum::struct_from_seq Some(Content::Seq(v)) => { de::Deserializer::deserialize_any(SeqRefDeserializer::new(v), visitor) } diff --git a/test_suite/tests/test_enum_untagged.rs b/test_suite/tests/test_enum_untagged.rs index 8c212a97..01ecae9c 100644 --- a/test_suite/tests/test_enum_untagged.rs +++ b/test_suite/tests/test_enum_untagged.rs @@ -214,6 +214,25 @@ mod newtype_enum { ], ); } + + // Reaches crate::private::de::content::VariantRefDeserializer::struct_variant + // Content::Seq case + #[test] + fn struct_from_seq() { + assert_de_tokens( + &Outer::Inner(Inner::Struct { f: 1 }), + &[ + Token::Map { len: Some(1) }, + // tag + Token::Str("Struct"), + // content + Token::Seq { len: Some(1) }, + Token::U8(1), + Token::SeqEnd, + Token::MapEnd, + ], + ); + } } // Reaches crate::private::de::content::ContentRefDeserializer::deserialize_option