Skip to content

Conversation

@folkertdev
Copy link
Contributor

@folkertdev folkertdev commented Dec 8, 2025

Stabilization report: rust-lang/rust#149783

@rustbot rustbot added S-waiting-on-review Status: The marked PR is awaiting review from a maintainer S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository labels Dec 8, 2025
Comment on lines 469 to 498
r[cfg.cfg_select]
### The `cfg_select` macro

The built-in `cfg_select` macro expands to the right-hand side of the first configuration predicate that evaluates to `true`.

For example:

```rust
cfg_select! {
unix => {
fn foo() { /* unix specific functionality */ }
}
target_pointer_width = "32" => {
fn foo() { /* non-unix, 32-bit functionality */ }
}
_ => {
fn foo() { /* fallback implementation */ }
}
}
```
The `cfg_select` macro can also be used in expression position:

```rust
let is_unix_str = cfg_select! {
unix => "unix",
_ => "not unix",
};
```

A `_` can be used to write a configuration predicate that always evaluates to `true`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the Reference PR. It'd be worth filling in the details you provided in rust-lang/rust#149783 (comment), e.g. with the grammar, the removal of one level of braces, the compile error on fallthrough, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can discuss as well how the bodies of each branch must be able to parse.

Copy link
Contributor Author

@folkertdev folkertdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all the raw information is here now, but it probably needs some editing/clarification.

Also should the lint on branches that come after a wildcard be mentioned?

Comment on lines +485 to +486
r[cfg.cfg_select.general]
The built-in `cfg_select` macro expands to the `TokenTree` on the right-hand side of the first configuration predicate that evaluates to `true`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it clear enough from the grammer and the language here that the { /* ... */ } are dropped?

Comment on lines +518 to +527
r[cfg.cfg_select.positions]
The `cfg_select!` macro is accepted in the following macro expansion positions

- items
- statements
- expression
- impl items
- trait impl items
- trait items
- foreign items
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find the positions in which macro expansion is allowed in the reference, actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: The marked PR is awaiting review from a maintainer S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants