Skip to content
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

macros: don't cfg-process items before applying attribute proc macros #39336

Closed
jseyfried opened this issue Jan 27, 2017 · 12 comments
Closed

macros: don't cfg-process items before applying attribute proc macros #39336

jseyfried opened this issue Jan 27, 2017 · 12 comments
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-feature-request Category: A feature request, i.e: not implemented / a PR. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@jseyfried
Copy link
Contributor

cc #38356

@jseyfried jseyfried changed the title macros: don't cfg-process items applying attribute proc macros macros: don't cfg-process items before applying attribute proc macros Jan 27, 2017
@jseyfried jseyfried self-assigned this Jan 27, 2017
@jseyfried jseyfried added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Jan 27, 2017
@jseyfried
Copy link
Contributor Author

cc @abonander @keeperofdakeys

@KalitaAlexey
Copy link
Contributor

@jseyfried,
I can't understand the title.
Can you make it clear please?

@jseyfried
Copy link
Contributor Author

Suppose we have an attribute proc macro attr:

#[proc_macro_attribute]
fn attr(input: TokenStream) -> TokenStream { ... }

and an invocation of attr:

#[attr] fn f() { #[cfg(any())] fn g() {} }

Today, we cfg-process fn f (resulting in fn f() {}) before we apply attr.
In other words, the input: TokenStream argument is fn f() {}.

Instead, we want the input to be fn f() { #[cfg(any())] fn g() {} }.

@KalitaAlexey
Copy link
Contributor

KalitaAlexey commented Jan 27, 2017

I got it.
cfg-process means processing #[cfg] attributes.
Thank you.

@jdhorwitz
Copy link
Contributor

Is this still available to be picked up with a Mentor?

@jseyfried
Copy link
Contributor Author

@jdhorwitz
Yeah, feel free to ping me (jseyfried) on IRC (#rustc/#rust-internals) or ask questions here.

@shioju
Copy link

shioju commented May 3, 2017

@jdhorwitz are you still working on this? If not, I'd like to take it up. Thx.

@jseyfried
Copy link
Contributor Author

@shioju feel free to pick it up :)

@Mark-Simulacrum Mark-Simulacrum added C-enhancement Category: An issue proposing an enhancement or a PR with one. C-feature-request Category: A feature request, i.e: not implemented / a PR. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jul 27, 2017
@tamird
Copy link
Contributor

tamird commented Aug 20, 2017

@shioju are you still working on this?

@tmnilsson
Copy link
Contributor

I have looked into this issue as a way to getting to know the rustc source code. I think I might be able to make a fix now, unless anyone is currently working on it?

@shioju
Copy link

shioju commented Sep 11, 2017

Hey all, sorry for holding this up. Not working on this now. Please go ahead.

bors added a commit that referenced this issue Sep 28, 2017
…ried

Apply attr proc macros before cfg processing

Fixes #39336.
r? @jseyfried
@kaimast
Copy link

kaimast commented May 18, 2020

Hey all,

I searched all over the web but cannot find an easy answer to this. If I want to process all cfg-attributes before applying my custom proc macro, how do I do that? Is there some function I can invoke on my TokenStream?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-feature-request Category: A feature request, i.e: not implemented / a PR. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

No branches or pull requests

9 participants