Enable "Checking conditional compilation value at compile time" when it is stable?
SteveLauC opened this issue · comments
This will check invalid conditions, which would be quite useful for us, see the following demo:
#[cfg(target_os = "linxu")] // NOTE this typo!
fn foo_for_linux() { }
fn main() { }
$ cargo +nightly check -Z unstable-options -Z check-cfg
Checking rust v0.1.0 (/home/steve/Documents/workspace/playground/rust)
warning: unexpected `cfg` condition value: `linxu`
--> src/main.rs:1:7
|
1 | #[cfg(target_os = "linxu")]
| ^^^^^^^^^^^^-------
| |
| help: there is a expected value with a similar name: `"linux"`
|
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
Our aliases defined in build.rs
are also invalid, to allow them, we can:
// build.rs
fn main() {
println!("cargo:rustc-check-cfg=cfg(apple_targets)");
println!("cargo:rustc-check-cfg=cfg(bsd)");
println!("cargo:rustc-check-cfg=cfg(linux_android)");
println!("cargo:rustc-check-cfg=cfg(freebsdlike)");
println!("cargo:rustc-check-cfg=cfg(netbsdlike)");
println!("cargo:rustc-check-cfg=cfg(solarish)");
...
}
It is still unstable and only available in nightly, maybe we can enable this check when it is in stable.