-
Notifications
You must be signed in to change notification settings - Fork 697
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 support for custom attributes #2866
Conversation
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.
Hi @mkroening sorry for the delay with the review.
I only have two requests for you because otherwise this looks great:
- It is better to use
String
instead ofTokenStream
as the latter leaksproc_macro2
into our public API, meaning that we would have to do releases from time to time just to keep up to date withproc_macro2
. - There should be a test for the CLI args and also some documentation explaining the syntax of the attributes as right now.
Edit: I also have an additional question for you that is non-blocking and can be addressed later (even by someone else). Would it be possible to re-implement the custom derives functionality using the custom attributes machinery instead?
Thanks for the review!
✅
✅
Where would I put that? I did not find anything similar for
That should be possible! Would you like me to tackle this in this PR or in a separate one? I have also implemented support for annotations, but error reporting is difficult there. It currently panics, if the attribute is not parsable as |
This would go in
I'd do it on a separate one so it is easier to review and track. Thanks! |
Ah, that's what you mean. I wondered, since I had already done that when opening this PR. Perhaps you overlooked it? I have also fixed the formatting for CI. |
Oh my bad, it seems my head just skipped that section of code 🤣. It seems there are some compilation errors due to the change from |
fd1409c
to
8881246
Compare
Signed-off-by: Martin Kröning <[email protected]>
The CI is green now. :) |
This adds support for custom attributes:
ParseCallbacks::add_attributes(&self, info: &AttributeInfo<'_>) -> Vec<TokenStream>
--with-attribute-custom <CUSTOM>
--with-attribute-custom-struct <CUSTOM>
--with-attribute-custom-enum <CUSTOM>
--with-attribute-custom-union <CUSTOM>
The implementation is very similar to the custom derives functionality. One thing I am not sure about is returning
Vec<TokenStream>
instead ofVec<String>
, but that seemed natural to me.Fixes #2520