- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-cfg_select`#![feature(cfg_select)]``#![feature(cfg_select)]`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.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
Provides a native way to easily manage multiple conditional flags without having to rewrite each clause multiple times.
Public API
cfg_select! {
    unix => {
        fn foo() { /* unix specific functionality */ }
    }
    target_pointer_width = "32" => {
        fn foo() { /* non-unix, 32-bit functionality */ }
    }
    _ => {
        fn foo() { /* fallback implementation */ }
    }
}
let is_unix_str = cfg_select! {
    unix => "unix",
    _ => "not unix",
};
println!("{is_unix_str}");Steps / History
-  Implementation (Add the cfg_match!macro #115416)-  Rename from cfg_matchtocfg_selectRenamecfg_match!tocfg_select!#137198
- Support unbraced expressions: cfg_select: Support unbraced expressions #145233
 
-  Rename from 
- Final comment period
- Stabilization PR
Unresolved Questions
- What should the final syntax be? A match-like syntax feels more natural in the sense that each macro fragment resembles an arm.
- Should the macro be supported directly by a language feature?
- What should the feature name be?- cfg_matchconflicts with the already existing- cfg_matchcrate.
- How can we support usage in both expression-position and item position?
- Support trailing commas to have similar grammar as(cfg_select: Support unbraced expressions #145233)- matchstatements.
References
- https://crates.io/crates/cfg-match
- https://crates.io/crates/cfg-if
- Tracking issue for cfg_if#59442
- https://internals.rust-lang.org/t/is-cfg-if-going-to-be-pulled-into-std/13316
Implementation history
- Initiate the inner usage of cfg_match(Compiler) #116312
- Turn cfg_matchinto a builtin #116323
- Initiate the inner usage of cfg_match(Library) #116342
- Remove cfg_matchfrom the prelude #117162
- [cfg_match] Generalize inputs #130313
- [cfg_match] Adjust syntax #133720
- [cfg_match] Document the use of expressions. #135625
- [cfg_match] Library edition #136261
- Rename cfg_match!tocfg_select!#137198
- Make cfg_match!a semitransparent macro #138993
- Use cfg_match!in core #138996
- update cfg_select!documentation #143941
- cfg_select: Support unbraced expressions #145233
Tooling support
madsmtm, Skgland, Nilsen84, nanoqsh, MaxVerevkin and 24 moremarcospb19, vE5li, grant0417, Kobzol, bjoernager and 5 more
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-cfg_select`#![feature(cfg_select)]``#![feature(cfg_select)]`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.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.