Skip to content

Commit c5067fe

Browse files
folkertdevtraviscross
authored andcommitted
more detail
1 parent a57c184 commit c5067fe

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

src/conditional-compilation.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,21 @@ println!("I'm running on a {} machine!", machine_kind);
469469
r[cfg.cfg_select]
470470
### The `cfg_select` macro
471471

472-
The built-in `cfg_select` macro expands to the right-hand side of the first configuration predicate that evaluates to `true`.
472+
r[cfg.cfg_select.syntax]
473+
```grammar,configuration
474+
CfgSelect ->
475+
cfg_select! `{` CfgSelectBranch* `}`
476+
477+
CfgSelectConfigurationPredicate ->
478+
ConfigurationPredicate | `_`
479+
480+
CfgSelectBranch ->
481+
CfgSelectConfigurationPredicate `=>` `{` TokenTree `}`
482+
| CfgSelectConfigurationPredicate `=>` TokenTree `,`
483+
```
484+
485+
r[cfg.cfg_select.general]
486+
The built-in `cfg_select` macro expands to the `TokenTree` on the right-hand side of the first configuration predicate that evaluates to `true`.
473487

474488
For example:
475489

@@ -495,8 +509,26 @@ let is_unix_str = cfg_select! {
495509
};
496510
```
497511

512+
r[cfg.cfg_select.wildcard]
498513
A `_` can be used to write a configuration predicate that always evaluates to `true`.
499514

515+
r[cfg.cfg_select.fallthrough]
516+
If none of the predicates evaluates to `true`, a compiler error is emitted.
517+
518+
r[cfg.cfg_select.positions]
519+
The `cfg_select!` macro is accepted in the following macro expansion positions
520+
521+
- items
522+
- statements
523+
- expression
524+
- impl items
525+
- trait impl items
526+
- trait items
527+
- foreign items
528+
529+
r[cfg.cfg_select.well-formed]
530+
Each right-hand side must syntactically be valid expansion for the position that the macro is invoked in.
531+
500532
[Testing]: attributes/testing.md
501533
[`--cfg`]: ../rustc/command-line-arguments.html#--cfg-configure-the-compilation-environment
502534
[`--test`]: ../rustc/command-line-arguments.html#--test-build-a-test-harness

0 commit comments

Comments
 (0)