-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-cfg_select`#![feature(cfg_select)]``#![feature(cfg_select)]`I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.P-lang-drag-1Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-langLang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-langT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Description
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);
}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)
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-cfg_select`#![feature(cfg_select)]``#![feature(cfg_select)]`I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.P-lang-drag-1Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-langLang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-langT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team