Code:
#![feature(cfg_select)]
fn main() {
let demo1 = cfg_select! {
true => "valid",
invalid_cfg1 => "invalid",
_ => "fallback"
};
let demo2 = cfg_select! {
invalid_cfg2 => "invalid",
true => "valid",
_ => "fallback"
};
dbg!(demo1, demo2);
}
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=170a24120aafa2dcf4d941fd1b189a56
Output:
Compiling playground v0.0.1 (/playground)
warning: unexpected `cfg` condition name: `invalid_cfg2`
--> src/main.rs:10:9
|
10 | invalid_cfg2 => "invalid",
| ^^^^^^^^^^^^
|
= help: expected names are: `docsrs`, `feature`, and `test` and 31 more
= help: consider using a Cargo feature instead
= help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(invalid_cfg2)'] }
= help: or consider adding `println!("cargo::rustc-check-cfg=cfg(invalid_cfg2)");` to the top of the `build.rs`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
warning: `playground` (bin "playground") generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.60s
Running `target/debug/playground`
[src/main.rs:14:5] demo1 = "valid"
[src/main.rs:14:5] demo2 = "valid"
Here we get a warning on invalid_cfg2 since the invalid arm for demo2 comes before the matched arm (true). Ideally we should get the same warning for invalid_cfg1 because it also isn't a valid configuration: however, since true is hit first in the demo2 case, the rest of the arms don't currently get checked.
Version: 1.93.0-nightly (2025-11-18 3d461af)
Code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=170a24120aafa2dcf4d941fd1b189a56
Output:
Here we get a warning on
invalid_cfg2since the invalid arm fordemo2comes before the matched arm (true). Ideally we should get the same warning forinvalid_cfg1because it also isn't a valid configuration: however, sincetrueis hit first in thedemo2case, the rest of the arms don't currently get checked.Version: 1.93.0-nightly (2025-11-18 3d461af)