-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 extern functions #48747
Comments
I'm guessing that it's more like proc_macro_attribute doesn't work inside
But not on other item types inside
My guess is that cc #38356 |
Yep, this @petrochenkov @nrc I can fix this one but it seems like a good mentoring bug since it might be that trivial or it might not be. I'm willing to mentor someone on it. |
If you're willing to mentor, I'm willing to take this one and be the mentee. I've been wanting to contribute to Rust but the compiler is so big and complex that I haven't been sure how to break into it. |
Sure, I've been wanting to mentor for a while now. I don't have a great grasp on the overall compiler architecture but I like to think I know my way around this bit of the frontend. The If you need more active help we can meet up on IRC or something, I guess. |
In fact it should be much simpler than |
Thanks for those tips. I've been fiddling with this code for the past few days, trying to better understand how it works and what's needed. Unfortunately, with the long build times and my complete lack of experience in the Rust codebase, this is proving to be a bigger time commitment than I'm currently able to embrace. I'll let someone else take this issue. |
@nrc Working on this, would we consider this a discrepancy in where macro attributes are allowed (insta-stable) or a new unstable usage? |
After doing more digging, my concern right now is that it appears |
@petrochenkov perhaps you'd like to weigh in |
I think this should be behind a flag since I'm sure it's the kind of thing with unforeseen bugs that crop up. Ideally we can just put it behind the proc_macro feature, rather than creating a new one. Why are extern blocks different to other blocks? I'd really hope that that sort of thing Just Works :-( |
Presumably because they only support a subset of all item kinds. In the process of enabling proc_macros here it wouldn't be a stretch to enable other macros as well, maybe all behind a |
@petrochenkov What do you think of the previous comment? Let me know if there's anyone else I should pull in on issues like this, I'm looking to knock out a bunch of them in quick succession. |
If I suspect it's not implemented yet just because the demand wasn't high enough. |
So if I do enable all macros in |
Citing nikomatsakis, "Basically every time I've skipped a feature gate I've
This is equivalent to something that already exist: macro make_struct() {
struct S;
}
trait Tr {
make_struct!(); // ERROR expected one of `const`, `extern`, `fn`, `type`, or `unsafe`, found `struct`
}
fn main() {} |
Also see #48137 about how treatment of module/trait/impl/foreign items in macros can be made more uniform. |
…chenkov Expand macros in `extern {}` blocks This permits macro and proc-macro and attribute invocations (the latter only with the `proc_macro` feature of course) in `extern {}` blocks, gated behind a new `macros_in_extern` feature. A tracking issue is now open at rust-lang#49476 closes rust-lang#48747
Given a
proc-macro
crate named demo_macros, which contains a singlenop_attribute
procedural macro:Given a lib crate named demo, which attempts to use the
nop_attribute
procedural macro on a function within anextern
block:Attempting to
cargo +nightly build
this results in the following error:If I delete the
extern
block and change the code to just be#[nop_attribute] pub fn fabs(_: f64) -> f64 { 0.0 }
then it compiles just fine. For some reason, attempting to apply a procedural macro attribute to anextern
function doesn't work.My
rustc --version
:You can fully reproduce the issue by executing the following sequence of shell commands:
The text was updated successfully, but these errors were encountered: