-
Notifications
You must be signed in to change notification settings - Fork 154
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
More attribute refactoring #134
More attribute refactoring #134
Conversation
This should improve both readability of the code and the quality of error messages.
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 really great! Thanks for putting all this work in. Couple of minor points, and the TryFrom
back-compat issue, but otherwise not much.
@@ -130,7 +126,7 @@ pub fn enum_discriminants_inner(ast: &DeriveInput) -> syn::Result<TokenStream> { | |||
Ok(quote! { | |||
/// Auto-generated discriminant enum variants | |||
#derives | |||
#(#pass_though_attributes)* | |||
#(#[ #pass_though_attributes ])* |
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.
Could you help me understand the difference here?
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.
#()
interpolations can contain arbitrary extra tokens in addition to an iterable of impl ToTokens
. So instead of
let values = vec![1, 2, 3];
let push_values = values.into_iter().map(|v| quote! { vec.push(#v); });
quote! {
let vec = Vec::new();
#(#push_values)
}
you can just write
let values = vec![1, 2, 3];
quote! {
let vec = Vec::new();
#( vec.push(#values); )
}
I did the same kind of simplification here (context).
I don't think |
Sorry, not getting notifications about Travis CI failure. Should be fixed now :) |
Everything looks good. Thanks for all the changes! Do you have more coming? |
Yeah, still planning to replace |
This has two effects that may not be obvious from the commit messages / on first sight:
strum(default = "true")
andstrum(disabled = "true")
no longer produce a dedicated "deprecation" compiler errorstrum_discriminants
"passthrough" of other attributes now supports attributes that don't parse assyn::Meta
, e.g.foo(key = some::Path)
, since syn only supports literals in the value position ofMetaList
s but the compiler allows arbitrary token streams in attributesI'll probably work on converting all of the panics to
syn::Error
s next :)