New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add #[serde(rename_all_fields = "foo")] attribute #1695
Conversation
r? @dtolnay |
I'll try again since Triagebot Notifications are now a thing: r? @dtolnay I've opened this PR because you wrote over at #1061 (comment) that you'd accept a PR for this. If your opinion has changed, I won't be upset if this is closed without further reasoning. |
@dtolnay it looks like this was approved a few months back but not merged in. |
@kjeremy The person who left the review doesn't seem to be associated with serde in any way. |
3b7f72b
to
0dd37a7
Compare
Rebased to trigger new CI runs, the old ones had been stuck for months. |
CI fixed, no merge conflics. Ping @dtolnay |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Would love this! |
Any update on this? Would love to have this merged as well. |
0dd37a7
to
f41c21b
Compare
Rebased to fix conflicts with the syn 2.0 upgrade. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
serde_derive/src/internals/attr.rs
Outdated
syn::Data::Union(syn::DataUnion { union_token, .. }) => { | ||
let msg = "#[serde(rename_all_fields)] can only be used on enums"; | ||
cx.error_spanned_by(union_token, msg); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using the struct
/union
token for the span of this error is not a good choice. The problem is not that the user wrote a struct. The problem is that the user wrote a rename_all_fields
attribute on their struct. The fix is not for the user to turn their struct into an enum. The fix is to change the attribute. So the error should point to the attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. When I just updated this, I noticed the (container-level) #[serde(default)]
does the same thing of pointing to the enum / struct token. Should I send another PR to change that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, let's fix that too. Good catch.
f41c21b
to
56be1c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thank you.
fixes #1061
If you don't like the style change in the second commit, I can remove it from this PR (or you can just cherry-pick the first commit).