diff --git a/serde/src/de/ignored_any.rs b/serde/src/de/ignored_any.rs index 9810f057c..01555a29f 100644 --- a/serde/src/de/ignored_any.rs +++ b/serde/src/de/ignored_any.rs @@ -107,7 +107,7 @@ use de::{ /// # Ok(()) /// # } /// ``` -#[derive(Copy, Clone, Debug, Default)] +#[derive(Copy, Clone, Debug, Default, PartialEq)] pub struct IgnoredAny; impl<'de> Visitor<'de> for IgnoredAny { diff --git a/serde/src/private/de.rs b/serde/src/private/de.rs index a1a30fb0f..8eea2890c 100644 --- a/serde/src/private/de.rs +++ b/serde/src/private/de.rs @@ -2794,6 +2794,13 @@ where visitor.visit_unit() } + fn deserialize_ignored_any(self, visitor: V) -> Result + where + V: Visitor<'de>, + { + visitor.visit_unit() + } + forward_to_deserialize_other! { deserialize_bool() deserialize_i8() @@ -2816,7 +2823,6 @@ where deserialize_tuple(usize) deserialize_tuple_struct(&'static str, usize) deserialize_identifier() - deserialize_ignored_any() } } diff --git a/test_suite/tests/test_annotations.rs b/test_suite/tests/test_annotations.rs index 698be4ed1..82a98c36a 100644 --- a/test_suite/tests/test_annotations.rs +++ b/test_suite/tests/test_annotations.rs @@ -10,7 +10,7 @@ clippy::uninlined_format_args, )] -use serde::de::{self, MapAccess, Unexpected, Visitor}; +use serde::de::{self, IgnoredAny, MapAccess, Unexpected, Visitor}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::collections::{BTreeMap, HashMap}; @@ -2697,6 +2697,31 @@ fn test_flatten_option() { ); } +#[test] +fn test_flatten_ignored_any() { + #[derive(Deserialize, PartialEq, Debug)] + struct Outer { + #[serde(flatten)] + inner: IgnoredAny, + } + + assert_de_tokens( + &Outer { inner: IgnoredAny }, + &[Token::Map { len: None }, Token::MapEnd], + ); + + assert_de_tokens( + &Outer { inner: IgnoredAny }, + &[ + Token::Struct { + name: "DoNotMatter", + len: 0, + }, + Token::StructEnd, + ], + ); +} + #[test] fn test_transparent_struct() { #[derive(Serialize, Deserialize, PartialEq, Debug)]