Skip to content

Commit

Permalink
Update error span for attribute / data kind mismatches
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Jul 27, 2023
1 parent 74fe708 commit 115f96a
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions serde_derive/src/internals/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.error_spanned_by(&meta.path, 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.error_spanned_by(&meta.path, 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.error_spanned_by(&meta.path, msg);
}
}
}
Expand All @@ -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.error_spanned_by(&meta.path, 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.error_spanned_by(&meta.path, msg);
}
}
}
Expand All @@ -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.error_spanned_by(&meta.path, 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.error_spanned_by(&meta.path, msg);
}
}
} else if meta.path == TAG {
Expand All @@ -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.error_spanned_by(&meta.path, 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.error_spanned_by(&meta.path, msg);
}
}
}
Expand All @@ -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.error_spanned_by(&meta.path, 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.error_spanned_by(&meta.path, msg);
}
}
}
Expand Down

0 comments on commit 115f96a

Please sign in to comment.