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

variant macro for blocks #26

Closed
Lokathor opened this issue Sep 20, 2019 · 5 comments
Closed

variant macro for blocks #26

Lokathor opened this issue Sep 20, 2019 · 5 comments

Comments

@Lokathor
Copy link
Contributor

I often want to cfg some code, but I want to do it on blocks inside a function instead of at the item level.

Would you be open to adding a second macro such as cfg_if_block (or other name) that does all the same stuff but working on :block instead of :item? I can do the PR if you're interested in the idea.

@gnzlbg
Copy link

gnzlbg commented Sep 21, 2019

Possibly dup of #8 .

@Lokathor
Copy link
Contributor Author

I already have a PR waiting for the docs related issues.

@Lokathor
Copy link
Contributor Author

Lokathor commented Sep 22, 2019

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f26008f95e5aebf5e8276fa804940a51

demo attempt. It works in some examples, but may have missed some sort of edge case.

EDIT: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=eee7c706369e151473dfbd79ca69d02d has some test usages, and seems to work in all four cases.

@alexcrichton
Copy link
Member

Given @ogoffart's implementation I think it would be easy enough to switch to :tt lists and use the same macro for supporting items/expressions/etc, probably even methods!

@alexcrichton
Copy link
Member

Fixed in #28 I believe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants