Rollup merge of #143941 - folkertdev:cfg-select-docs, r=traviscross

update `cfg_select!` documentation

tracking issue: https://github.com/rust-lang/rust/issues/115585

After rust-lang/rust#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``
This commit is contained in:
Samuel Tardieu
2025-07-15 12:52:44 +02:00
committed by GitHub
6 changed files with 39 additions and 30 deletions

View File

@@ -7,7 +7,7 @@ use rustc_span::Span;
use crate::exp;
use crate::parser::Parser;
pub enum CfgSelectRule {
pub enum CfgSelectPredicate {
Cfg(MetaItemInner),
Wildcard(Token),
}
@@ -20,7 +20,7 @@ pub struct CfgSelectBranches {
pub wildcard: Option<(Token, TokenStream, Span)>,
/// All branches after the first wildcard, including further wildcards.
/// These branches are kept for formatting.
pub unreachable: Vec<(CfgSelectRule, TokenStream, Span)>,
pub unreachable: Vec<(CfgSelectPredicate, TokenStream, Span)>,
}
/// Parses a `TokenTree` that must be of the form `{ /* ... */ }`, and returns a `TokenStream` where
@@ -52,7 +52,7 @@ pub fn parse_cfg_select<'a>(p: &mut Parser<'a>) -> PResult<'a, CfgSelectBranches
match branches.wildcard {
None => branches.wildcard = Some((underscore, tts, span)),
Some(_) => {
branches.unreachable.push((CfgSelectRule::Wildcard(underscore), tts, span))
branches.unreachable.push((CfgSelectPredicate::Wildcard(underscore), tts, span))
}
}
} else {
@@ -64,7 +64,9 @@ pub fn parse_cfg_select<'a>(p: &mut Parser<'a>) -> PResult<'a, CfgSelectBranches
match branches.wildcard {
None => branches.reachable.push((meta_item, tts, span)),
Some(_) => branches.unreachable.push((CfgSelectRule::Cfg(meta_item), tts, span)),
Some(_) => {
branches.unreachable.push((CfgSelectPredicate::Cfg(meta_item), tts, span))
}
}
}
}