Skip to content

Commit

Permalink
Make #[serde(alias)] works in #[serde(flatten)] context
Browse files Browse the repository at this point in the history
fix #1504
  • Loading branch information
bebecue committed Mar 5, 2023
1 parent a13c638 commit f5e0fbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion serde_derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),* ];
}
Expand Down
10 changes: 5 additions & 5 deletions test_suite/tests/test_annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
);
}

Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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`",
);
}

Expand Down

0 comments on commit f5e0fbc

Please sign in to comment.