Only allow #[serde(default)]` on structs

This commit is contained in:
Thomas de Zeeuw
2017-02-21 00:15:00 +01:00
parent 9444db5f19
commit 7bee779514
3 changed files with 24 additions and 1 deletions
+8 -1
View File
@@ -167,7 +167,14 @@ impl Item {
// Parse `#[serde(default)]`
MetaItem(Word(ref name)) if name == "default" => {
default.set_true();
match item.body {
syn::Body::Struct(_) => {
default.set_true();
}
_ => {
cx.error("#[serde(default)] can only be used on structs")
}
}
}
// Parse `#[serde(bound="D: Serialize")]`