Repository navigation
Tracking issue for release notes of #149783: stabilize cfg_select! #152944
Description
This issue tracks the release notes text for #149783.
cc @folkertdev, @traviscross -- original issue/PR authors and assignees for drafting text
See the forge.rust-lang.org chapter about release notes for an overview of how the release team makes use of these tracking issues.
Release notes text
This section should be edited to specify the correct category(s) for the change, with succinct description(s) of what changed. Some things worth considering:
- Does this need an additional compat notes section?
- Was this a libs stabilization that should have additional headers to list new APIs under
Stabilized APIsandConst Stabilized APIs?
# Stabilized APIs
- [`cfg_select!`](https://doc.rust-lang.org/stable/std/macro.cfg_select.html)Tip
Use the previous releases for inspiration on how to write the release notes text and which categories to pick.
Release blog section
If this change is notable enough for inclusion in the blog post then this section should be edited to contain a draft for the blog post. Otherwise leave it empty.
The built-in `cfg_select!` macro can be used to select code at compile-time based on multiple configuration predicates.
It expands to the right-hand side of the first arm whose configuration predicate evaluates to `true`.
```rust
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",
};
```
Note
If a blog post section is required the release-blog-post label should be added (@rustbot label +release-blog-post) to this issue as otherwise it may be missed by the release team.
Activity
vlovich commentedon Apr 5, 2026
One small suggestion for the release notes. Make it clear whether this allows for invalid code like #cfg or requires always valid code on every branch like the if cfg! macro. I think it's the former since it's covering function definitions which cfg! can't do if I recall correctly but it would help to make that even clearer.