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

specify how #![cfg(...)] works differently in the crate root versus anywhere else #103

Open
QuietMisdreavus opened this issue Aug 30, 2017 · 0 comments
Labels
A-attributes Area: Attributes Easy We believe this would not be difficult to actually fix New Content Missing features or aspects of language not currently documented.

Comments

@QuietMisdreavus
Copy link
Member

This is a port of rust-lang/rust#34968.

Spawned off of rust-lang/rust#34932 (comment)

If you put the inner attribute #![cfg(..)] at a crate root, this (apparently) causes an empty crate to be generated. I.e., it is as if the crate itself still exists, but all of its contents have disappeared.

This is slightly different than the behavior of #![cfg(..)] elsewhere (e.g. in a mod item), where such an inner attribute will cause the whole item to be omitted from the AST, rather than just causing the contents of the item to be omitted.

I don't see any mention of this corner case in the Rust documentation for Conditional Compilation, here: https://doc.rust-lang.org/book/first-edition/conditional-compilation.html

Since the second edition of the book doesn't have a dedicated section to conditional compilation, it would be worth elaborating on it here. Whether or not that includes porting some of that discussion out is another matter. This issue was more about how an inner cfg attribute creates an empty crate when used in the crate root, but removes the item entirely if used anywhere else. (This is what winapi does to only build on windows, for example.)

@Havvy Havvy added Enhancement Improvement in a non-prose section of the book Easy We believe this would not be difficult to actually fix New Content Missing features or aspects of language not currently documented. labels Sep 24, 2017
@alercah alercah removed the Enhancement Improvement in a non-prose section of the book label Jul 25, 2018
@ehuss ehuss added the A-attributes Area: Attributes label Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes Easy We believe this would not be difficult to actually fix New Content Missing features or aspects of language not currently documented.
Projects
None yet
Development

No branches or pull requests

4 participants