Skip to content

Commit c9dbde9

Browse files
Rollup merge of rust-lang#143941 - folkertdev:cfg-select-docs, r=traviscross
update `cfg_select!` documentation tracking issue: rust-lang#115585 After rust-lang#143461, and with an eye on a soon(ish) stabilization, I think the docs need some work. The existing text read more like a motivation for the feature existing to me, so I've tried to now be a bit more descriptive. Still, suggestions are very welcome. I also added a test for an empty `select! {}` because it's just the sort of thing that might break. r? ``@traviscross``
2 parents a34b496 + 0229b44 commit c9dbde9

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

core/src/macros/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,14 @@ pub macro assert_matches {
196196
},
197197
}
198198

199-
/// A macro for defining `#[cfg]` match-like statements.
199+
/// Selects code at compile-time based on `cfg` predicates.
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+
/// This macro evaluates, at compile-time, a series of `cfg` predicates,
202+
/// selects the first that is true, and emits the code guarded by that
203+
/// predicate. The code guarded by other predicates is not emitted.
203204
///
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.
205+
/// An optional trailing `_` wildcard can be used to specify a fallback. If
206+
/// none of the predicates are true, a [`compile_error`] is emitted.
209207
///
210208
/// # Example
211209
///
@@ -225,7 +223,7 @@ pub macro assert_matches {
225223
/// }
226224
/// ```
227225
///
228-
/// If desired, it is possible to return expressions through the use of surrounding braces:
226+
/// The `cfg_select!` macro can also be used in expression position:
229227
///
230228
/// ```
231229
/// #![feature(cfg_select)]

0 commit comments

Comments
 (0)