Skip to content

Why does serde_as remove its own attribute/annotation? #260

Answered by jonasbb
Lehona asked this question in Q&A
Discussion options

You must be logged in to vote

Short answer: If the attributes are kept rustc will not compile the programs and will error with expected an inert attribute, found an attribute macro.

Longer answer:
Currently, the serde_as system is implemented as a proc-macro attribute, which do not have the luxury of declaring additional attribute names which it will consume. Derive macros can do that, and they do not have to remove the field attributes. In fact, they cannot remove them.
Field attributes are still required though, so either they re-use the serde_as attribute name or an unknown attribute name. Unknown attributes would also cause compiler errors. Since serde_as is re-used it causes the error message above, since you are…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@Lehona
Comment options

Answer selected by Lehona
Comment options

You must be logged in to vote
4 replies
@jonasbb
Comment options

@dtolnay
Comment options

@jonasbb
Comment options

@jonasbb
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants