Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to flatten IgnoredAny #2436

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion serde/src/de/ignored_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ use de::{
/// # Ok(())
/// # }
/// ```
#[derive(Copy, Clone, Debug, Default)]
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct IgnoredAny;

impl<'de> Visitor<'de> for IgnoredAny {
Expand Down
8 changes: 7 additions & 1 deletion serde/src/private/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,13 @@ where
visitor.visit_unit()
}

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
visitor.visit_unit()
}

forward_to_deserialize_other! {
deserialize_bool()
deserialize_i8()
Expand All @@ -2833,7 +2840,6 @@ where
deserialize_tuple(usize)
deserialize_tuple_struct(&'static str, usize)
deserialize_identifier()
deserialize_ignored_any()
}
}

Expand Down
27 changes: 26 additions & 1 deletion test_suite/tests/test_annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -2494,6 +2494,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)]
Expand Down