Skip to content

Commit 9e49e13

Browse files
committed
update cfg_select! documentation
1 parent 9c3064e commit 9e49e13

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

library/core/src/macros/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,11 @@ pub macro assert_matches {
198198

199199
/// A macro for defining `#[cfg]` match-like statements.
200200
///
201-
/// It is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade of
202-
/// `#[cfg]` cases, emitting the implementation which matches first.
201+
/// The `cfg_select!` macro checks a series of `#[cfg]` conditions, and picks the branch that
202+
/// belongs to the first condition that evaluates to true.
203203
///
204-
/// This allows you to conveniently provide a long list `#[cfg]`'d blocks of code
205-
/// without having to rewrite each clause multiple times.
206-
///
207-
/// Trailing `_` wildcard match arms are **optional** and they indicate a fallback branch when
208-
/// all previous declarations do not evaluate to true.
204+
/// An optional trailing `_` wildcard match arm can be used to specify a fallback branch.
205+
/// If none of the conditions evaluate to `true`, a compile error is emitted.
209206
///
210207
/// # Example
211208
///
@@ -225,7 +222,7 @@ pub macro assert_matches {
225222
/// }
226223
/// ```
227224
///
228-
/// If desired, it is possible to return expressions through the use of surrounding braces:
225+
/// The `cfg_select!` macro can also be used in expression position:
229226
///
230227
/// ```
231228
/// #![feature(cfg_select)]

tests/ui/macros/cfg_select.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ cfg_select! {
2525
//~^ ERROR none of the rules in this `cfg_select` evaluated to true
2626
false => {}
2727
}
28+
29+
cfg_select! {}
30+
//~^ ERROR none of the rules in this `cfg_select` evaluated to true

tests/ui/macros/cfg_select.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ LL | | false => {}
2121
LL | | }
2222
| |_^
2323

24-
error: aborting due to 2 previous errors; 1 warning emitted
24+
error: none of the rules in this `cfg_select` evaluated to true
25+
--> $DIR/cfg_select.rs:29:1
26+
|
27+
LL | cfg_select! {}
28+
| ^^^^^^^^^^^^^^
29+
30+
error: aborting due to 3 previous errors; 1 warning emitted
2531

0 commit comments

Comments
 (0)