Merge pull request #1205 from mitsuhiko/bugfix/tuple-struct-flatten

Produce error message for use of flatten in tuple structs
This commit is contained in:
David Tolnay
2018-04-02 07:09:39 +02:00
committed by GitHub
3 changed files with 42 additions and 1 deletions
+10 -1
View File
@@ -49,11 +49,20 @@ fn check_flatten(cx: &Ctxt, cont: &Container) {
cx.error("#[serde(flatten)] cannot be used within enums");
}
}
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 \