-
Notifications
You must be signed in to change notification settings - Fork 18
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
Use derive macro instead of attribute macro #37
Comments
Earlier versions did use a derive macro. The advantage of the attribute macro is that it can automatically assign subsequent powers of two to the variants if the user so desires - before I switched to an attribute macro, you had to manually specify How about I detect this situation in the macro and emit a friendlier error telling you to put the derives above the bitflags attribute? |
If I read you post correctly you always have to specify a value to each enum variant? That would be a pita and I would see why you switched to the attribute macro.
Is that possible? If so, I really would like to see it, yes. I mean, at some time in the future the feature may become stable. I don't know if the meaning of
differs to
Do you know that? |
The difference is that, if an attribute macro comes first, the tokens of the derive attribute are passed through the macro together with the definition of the enum itself, and the attribute macro is free to do whatever it wants with them before sending off its output through the rest of the compiler. The error you getting is saying that, even if the derive attribute passed through |
I see. Thanks for the explanation! What about this statement?
|
Yeah, you understood correctly — you always had to do that when the
derive macro was in use. This is because derive macros can only add code
(usually `impl`), but not change what you've written, so the compiler
would assign sequential integers instead.
|
Alright, I played with it and I see, that you can't replace or extend the variants of an enum with the derive. Thank you for your patience and I'm looking forward for a better error message :) |
Ah. Now that I've looked into it more, I realize I've misunderstood the problem. It's not that attributes cannot output a The bottom line is, I can't control this error — I'll file an issue with rustc itself. |
This now works on stable, so I'm closing the issue. |
Using a Derive Macro has the "advantage" that it plays nicely with the
#[derive]
attribute, whereas in the current form if you use#[bitflags]
in the wrong order you get the following error message:You can still can have an attribute
#[bitflags(default = B | C)]
with the help of the attributes argument inside of theproc_macro_derive
macro (https://doc.rust-lang.org/reference/procedural-macros.html#derive-macro-helper-attributes)Was there a specific reason for not using
#[derive(Bitflags)]
in the first place?Would you concider upgrading to the derive attribute? Would you accept a PR that does that?
The text was updated successfully, but these errors were encountered: