Now that we’ve gotten some experience with having both a nightly and a beta channel, there have been a number of requests to be able to detect the nightly channel from Rust code. This would serve the purpose of allowing crates to automatically detect if they are being built with a nightly compiler and consequently enable or disable #![feature]
directives as appropriate.
I would specifically like to proposed that the #[cfg]
directive nightly
is set by default by only the nightly compiler (not the beta or stable channels). This would allow code that looks like:
#![cfg_attr(nightly, feature(foo))]
#[cfg(nightly)]
pub fn awesome_function_that_uses_feature_foo() {
// ...
}
There is a downside that any code using #[cfg(nightly)]
will likely still require quite a bit of maintenance to keep up with the actual nightly compiler and/or implementation, but that’s also an inherent artifact of using the nightly channel itself.
What do others think of a scheme such as this? Are there other desires for nightly-detection which would not be solved by this? Curious to hear your thoughts!
cc @carllerche, @reem