-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Unable to see derive attributes anymore #40574
Comments
Just to pile on, I also was planning to take advantage of the ability to see other derives, which was possible when the feature was stabilized. #39572 (comment) seems like a much more flexible (and backwards compatible) solution. |
@sgrif I don't quite understand what does this comment say. Could you re-explain it to me please? |
@sgrif Well, it was only possible to see other builtin derives reliably, but point taken. @vityafx As described in #39572 (comment), the input to a derive procedural macro never has any The rationale here is that a derive procedural macro sees the item after it is expanded, so that e.g. #[derive(MyProcMacro)]
struct S(#[cfg(any())] i32);
//^ The input to `MyProcMacro` here is `struct S();` That being said, I personally don't have a strong preference between the current behavior and the alternative described in #39572 (comment). |
@jseyfried okay, so how do I generate different code for structs/enums based on condition does it derive |
@vityafx You can't, since:
In particular, this: #[derive(Clone)]
#[derive(MyProcMacro)]
struct S; always behaves exactly the same as this: #[derive(MyProcMacro)]
struct S;
impl S {
fn clone(&self) -> Self { /* appropriate manual implementation here */ }
} I actually think this is a benefit of the current behavior, since it means you can always refactor |
That's correct and good. But if I remember correctly I also do not have an ability to check what trait implementation the struct/enum has, am I right? |
@vityafx
Right, the compiler doesn't know what traits the struct/enum implements until long after procedural macros are expanded. It might be feasible for the compiler to compute this information earlier and make it available to procedural macros, but that would entail major architectural changes. |
@jseyfried So, finalizing the discussion, - how can I generate the code for struct/enums then? If I can not know does it |
@vityafx |
I have made a procedural macro which implements a trait with some functions for a enums. This the whole code:
This code worked perfectly like 2 weeks ago but now I have tried to compile it and it can't find any attribute on this struct! As you can see, I try to see what derives does the enum have but now this list is empty! What happened?
Original issue was posted here
@dtolnay told that is was changed here
So how do I fix this?
The text was updated successfully, but these errors were encountered: