-
Notifications
You must be signed in to change notification settings - Fork 121
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
Fix generics tokenization in Error
derive macro
#238
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.
Thanks for the contribution and nice catch. We use split_for_impl for this exact reason in most other places, but it seems this one was missed. Changelog should indeed be under the Fixes section.
Thank you! I'll make corrections and re-request a review when I can. |
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.
@zohnannor thanks!
Synopsis
#[derive(Error)]
onenum
s orstruct
s that have bothconst
generics and generic types......panics:
Solution
For some reason, iterating over
syn::Generics::params
that consists of onlyconst
generics or only generic types, tokenizes them as identifiers only, but when we mix them,syn
decides to outputconst
generics like they were defined, withconst
keyword, type annotation, etc. So when we are rendering the traitimpl
, adding bounds for an item inwhere
clause, we get this:Use
syn
's built-inGenerics::split_for_impl
to obtain a type that properly tokenizes all generic parameters.As for the tests, I've added a "compile fail" tests for
Error
derive macro on genericenum
s andstruct
s with combinations of different generics. AFAIU, this happens only inError
macro, tell me if I should add tests for some others.This should be listed in the changelog under
Fixes
section, am I right?Checklist