mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-29 09:27:56 +00:00
Produce error message for use of flatten in tuple structs
This commit is contained in:
@@ -47,11 +47,20 @@ fn check_flatten(cx: &Ctxt, cont: &Container) {
|
||||
Data::Enum(_) => {
|
||||
assert!(!cont.attrs.has_flatten());
|
||||
}
|
||||
Data::Struct(_, _) => {
|
||||
Data::Struct(style, _) => {
|
||||
for field in cont.data.all_fields() {
|
||||
if !field.attrs.flatten() {
|
||||
continue;
|
||||
}
|
||||
match style {
|
||||
Style::Tuple => {
|
||||
cx.error("#[serde(flatten)] cannot be used on tuple structs");
|
||||
}
|
||||
Style::Newtype => {
|
||||
cx.error("#[serde(flatten)] cannot be used on newtype structs");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if field.attrs.skip_serializing() {
|
||||
cx.error(
|
||||
"#[serde(flatten] can not be combined with \
|
||||
|
||||
Reference in New Issue
Block a user