mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-10-26 05:25:09 +00:00
Produce error message for use of flatten in tuple structs
This commit is contained in:
1 parent
9c659d9d86
commit
77376f39ea
3 files changed
+42
-1
No files matched your search
@@ -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