Update error span for attribute / data kind mismatches
This commit is contained in:
parent
74fe70855f
commit
31a0e73489
@ -386,11 +386,11 @@ impl Container {
|
||||
}
|
||||
syn::Data::Struct(_) => {
|
||||
let msg = "#[serde(rename_all_fields)] can only be used on enums";
|
||||
cx.error_spanned_by(&meta.path, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
syn::Data::Union(_) => {
|
||||
let msg = "#[serde(rename_all_fields)] can only be used on enums";
|
||||
cx.error_spanned_by(&meta.path, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
}
|
||||
} else if meta.path == TRANSPARENT {
|
||||
@ -410,16 +410,16 @@ impl Container {
|
||||
}
|
||||
syn::Fields::Unnamed(_) | syn::Fields::Unit => {
|
||||
let msg = "#[serde(default = \"...\")] can only be used on structs with named fields";
|
||||
cx.error_spanned_by(fields, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
},
|
||||
syn::Data::Enum(syn::DataEnum { enum_token, .. }) => {
|
||||
syn::Data::Enum(_) => {
|
||||
let msg = "#[serde(default = \"...\")] can only be used on structs with named fields";
|
||||
cx.error_spanned_by(enum_token, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
|
||||
syn::Data::Union(_) => {
|
||||
let msg = "#[serde(default = \"...\")] can only be used on structs with named fields";
|
||||
cx.error_spanned_by(union_token, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -435,13 +435,13 @@ impl Container {
|
||||
cx.error_spanned_by(fields, msg);
|
||||
}
|
||||
},
|
||||
syn::Data::Enum(syn::DataEnum { enum_token, .. }) => {
|
||||
syn::Data::Enum(_) => {
|
||||
let msg = "#[serde(default)] can only be used on structs with named fields";
|
||||
cx.error_spanned_by(enum_token, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
|
||||
syn::Data::Union(_) => {
|
||||
let msg = "#[serde(default)] can only be used on structs with named fields";
|
||||
cx.error_spanned_by(union_token, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -457,13 +457,13 @@ impl Container {
|
||||
syn::Data::Enum(_) => {
|
||||
untagged.set_true(&meta.path);
|
||||
}
|
||||
syn::Data::Struct(syn::DataStruct { struct_token, .. }) => {
|
||||
syn::Data::Struct(_) => {
|
||||
let msg = "#[serde(untagged)] can only be used on enums";
|
||||
cx.error_spanned_by(struct_token, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
|
||||
syn::Data::Union(_) => {
|
||||
let msg = "#[serde(untagged)] can only be used on enums";
|
||||
cx.error_spanned_by(union_token, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
}
|
||||
} else if meta.path == TAG {
|
||||
@ -479,12 +479,12 @@ impl Container {
|
||||
}
|
||||
syn::Fields::Unnamed(_) | syn::Fields::Unit => {
|
||||
let msg = "#[serde(tag = \"...\")] can only be used on enums and structs with named fields";
|
||||
cx.error_spanned_by(fields, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
},
|
||||
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
|
||||
syn::Data::Union(_) => {
|
||||
let msg = "#[serde(tag = \"...\")] can only be used on enums and structs with named fields";
|
||||
cx.error_spanned_by(union_token, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -495,13 +495,13 @@ impl Container {
|
||||
syn::Data::Enum(_) => {
|
||||
content.set(&meta.path, s.value());
|
||||
}
|
||||
syn::Data::Struct(syn::DataStruct { struct_token, .. }) => {
|
||||
syn::Data::Struct(_) => {
|
||||
let msg = "#[serde(content = \"...\")] can only be used on enums";
|
||||
cx.error_spanned_by(struct_token, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
|
||||
syn::Data::Union(_) => {
|
||||
let msg = "#[serde(content = \"...\")] can only be used on enums";
|
||||
cx.error_spanned_by(union_token, msg);
|
||||
cx.syn_error(meta.error(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: #[serde(default)] can only be used on structs with named fields
|
||||
--> tests/ui/default-attribute/enum.rs:5:1
|
||||
--> tests/ui/default-attribute/enum.rs:4:9
|
||||
|
|
||||
5 | enum E {
|
||||
| ^^^^
|
||||
4 | #[serde(default)]
|
||||
| ^^^^^^^
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: #[serde(default = "...")] can only be used on structs with named fields
|
||||
--> tests/ui/default-attribute/enum_path.rs:5:1
|
||||
--> tests/ui/default-attribute/enum_path.rs:4:9
|
||||
|
|
||||
5 | enum E {
|
||||
| ^^^^
|
||||
4 | #[serde(default = "default_e")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: #[serde(default = "...")] can only be used on structs with named fields
|
||||
--> tests/ui/default-attribute/nameless_struct_fields_path.rs:5:9
|
||||
--> tests/ui/default-attribute/nameless_struct_fields_path.rs:4:9
|
||||
|
|
||||
5 | struct T(u8, u8);
|
||||
| ^^^^^^^^
|
||||
4 | #[serde(default = "default_t")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: #[serde(untagged)] can only be used on enums
|
||||
--> tests/ui/enum-representation/untagged-struct.rs:5:1
|
||||
--> tests/ui/enum-representation/untagged-struct.rs:4:9
|
||||
|
|
||||
5 | struct S;
|
||||
| ^^^^^^
|
||||
4 | #[serde(untagged)]
|
||||
| ^^^^^^^^
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: #[serde(tag = "...")] can only be used on enums and structs with named fields
|
||||
--> tests/ui/struct-representation/internally-tagged-tuple.rs:5:9
|
||||
--> tests/ui/struct-representation/internally-tagged-tuple.rs:4:9
|
||||
|
|
||||
5 | struct S(u8, u8);
|
||||
| ^^^^^^^^
|
||||
4 | #[serde(tag = "type")]
|
||||
| ^^^^^^^^^^^^
|
||||
|
@ -1,7 +1,5 @@
|
||||
error: #[serde(tag = "...")] can only be used on enums and structs with named fields
|
||||
--> tests/ui/struct-representation/internally-tagged-unit.rs:3:10
|
||||
--> tests/ui/struct-representation/internally-tagged-unit.rs:4:9
|
||||
|
|
||||
3 | #[derive(Serialize)]
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in the derive macro `Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
4 | #[serde(tag = "type")]
|
||||
| ^^^^^^^^^^^^
|
||||
|
Loading…
Reference in New Issue
Block a user