Skip to content

Tracking issue for cfg_select (formerly cfg_match) #115585

@c410-f3r

Description

@c410-f3r

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

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_match conflicts with the already existing cfg_match crate.
  • How can we support usage in both expression-position and item position?
  • Support trailing commas to have similar grammar as match statements. (cfg_select: Support unbraced expressions #145233)

References

Implementation history

Tooling support

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-cfg_select`#![feature(cfg_select)]`I-lang-radarItems that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions