-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add #![cfg_assert] #1563
Add #![cfg_assert] #1563
Conversation
|
||
#![cfg_assert(any(target_arch = "x86", target_arch = "x86_64"), "This library only works on x86")] | ||
|
||
#![cfg_assert(all(feature = "foo", feature = "bar"), "The `foo` and `bar` features can't both be enabled at once")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing not(...)
I agree that it would be nice to trigger build errors, but it might also be nice to be able to trigger warnings as well (without having to create a custom lint). Not sure how this would fit in with this design. |
This looks quite similar to |
with the |
@Amanieu will |
@pnkfelix That isn't part of the RFC, however I can see it being useful in some cases. |
We discussed this briefly in yesterday's @rust-lang/lang meeting. It seemed like, once we have even rudimentary plugins stabilized, we could make a specialized plugin that implements this functionality relatively easily. In the meantime, one could certainly achieve the same effect by having some code that fails to compile which is conditionally included: #[cfg(...)] const error: usize = "this configuration is not supported"; Inelegant, but it works. However, reading over the thread where this suggestion originated, we were wondering something that perhaps @Amanieu or @alexcrichton could clarify: is there some other use for this metadata beyond simply halting compilation? How frequent is the desire for this? In other words: is there a strong reason for this to be logic that the compiler itself understands, versus something supplied externally or achieved via hackery? |
I guess there isn't a very urgent need for this feature, so I'm ok with closing this RFC and waiting for compiler plugins or something similar. |
@nikomatsakis In the past I've used static assertions in C for just verifying sanity of various properties like size/alignment, but that's not covered by this definition of |
Personally, I'd be inclined to close and revisit once plugins stabilization has progressed a bit more. |
Triaging old RFCs: based on the last few comments, I'm going to go ahead and close. |
The idea came from this thread:
#![cfg_assert]
allows a user to place guards on his code to fail early on incompatible configurations.Rendered