Make #[serde(alias)] works in #[serde(flatten)] context

fix #1504
This commit is contained in:
bebecue 2023-03-05 15:14:51 +08:00
parent a13c6382b6
commit f5e0fbcb14
2 changed files with 7 additions and 6 deletions

View File

@ -2400,7 +2400,8 @@ fn deserialize_struct_as_struct_visitor(
.collect();
let fields_stmt = {
let field_names = field_names_idents.iter().map(|(name, _, _)| name);
let field_names = field_names_idents.iter().flat_map(|(_, _, aliases)| aliases);
quote_block! {
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
}

View File

@ -642,7 +642,7 @@ fn test_unknown_field_rename_struct() {
Token::Str("a4"),
Token::I32(3),
],
"unknown field `a4`, expected one of `a1`, `a2`, `a6`",
"unknown field `a4`, expected one of `a1`, `a3`, `a2`, `a5`, `a6`",
);
}
@ -780,7 +780,7 @@ fn test_rename_enum() {
Token::StructVariant {
name: "AliasEnum",
variant: "sailor_moon",
len: 3,
len: 5,
},
Token::Str("a"),
Token::I8(0),
@ -798,7 +798,7 @@ fn test_rename_enum() {
Token::StructVariant {
name: "AliasEnum",
variant: "usagi_tsukino",
len: 3,
len: 5,
},
Token::Str("a"),
Token::I8(0),
@ -827,7 +827,7 @@ fn test_unknown_field_rename_enum() {
Token::StructVariant {
name: "AliasEnum",
variant: "usagi_tsukino",
len: 3,
len: 5,
},
Token::Str("a"),
Token::I8(0),
@ -836,7 +836,7 @@ fn test_unknown_field_rename_enum() {
Token::Str("d"),
Token::I8(2),
],
"unknown field `d`, expected one of `a`, `b`, `f`",
"unknown field `d`, expected one of `a`, `c`, `b`, `e`, `f`",
);
}