-
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
#[proc_macro_attribute] doesn't work on trait methods #42493
Comments
cc @abonander |
I saw this earlier and I've been thinking about it. I don't remember anything special in the invocation collector concerning trait methods though. Isn't there some codepath that strips attributes from trait methods, stuff like |
Not that I know of -- I'll do some debugging to figure out where the issue is ( |
Ok I've debugged this a bit and I think I've narrowed it down to resolve. The attribute is first resolved as |
In attempting to debug further I think I'm pretty far out of my league here. I think what's happening is that resolution is attempting to resolve Does that ring any bells @jseyfried or @abonander? Or maybe this is all a red herring? |
Haven't looked into this yet, but this explanation makes sense.
I believe the issue here is that That is, mod foo {
fn f() {}
mod bar {
fn g() { f() } // `f` doesn't resolve here
}
} However, due to hygiene, the following resolves: mod foo {
fn f() {}
m!(f); // Due to hygiene, this `f` reliably resolves to the above `f` ...
}
macro m($f:ident) {
mod bar {
fn g() { $f } // ... no matter where it ends up being used in the macro definition.
// fn $f() {} // (unless the macro definition explicitly shadows it like this)
}
} If this issue is as I expect, I can fix quickly tomorrow. |
Ah ok, I'll leave you to it as I suspect you'll find it much more quickly than I will! If you run out of time though just let me know and I will resume digging! |
This commit fixes procedural macro attributes being attached to trait methods, ensuring that they get resolved and expanded as other procedural macro attributes. The bug here was that `current_module` on the resolver was accidentally set to be a trait when it's otherwise only ever expecting a `mod`/block module. The actual fix here came from @jseyfried, I'm just helping to land it in the compiler! Closes rust-lang#42493
rustc: Fix proc_macro expansions on trait methods This commit fixes procedural macro attributes being attached to trait methods, ensuring that they get resolved and expanded as other procedural macro attributes. The bug here was that `current_module` on the resolver was accidentally set to be a trait when it's otherwise only ever expecting a `mod`/block module. The actual fix here came from @jseyfried, I'm just helping to land it in the compiler! Closes rust-lang#42493
Given this procedural macro:
and this crate:
Building:
I saw no output :(
I find that
#[foo]
is resolved, it just doesn't seem to get expanded!The text was updated successfully, but these errors were encountered: