Rollup merge of #147031 - joshtriplett:mbe-opt-collect, r=lcnr

mbe: Simplify check_redundant_vis_repetition

Eliminate a use of `map_or` in favor of a match.

Inline some variable definitions that don't add clarity, and that
prevent short-circuiting.
This commit is contained in:
Matthias Krüger 2025-09-26 18:11:14 +02:00 committed by GitHub
commit 978c960ed6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -894,12 +894,12 @@ fn check_redundant_vis_repetition(
seq: &SequenceRepetition,
span: &DelimSpan,
) {
let is_zero_or_one: bool = seq.kleene.op == KleeneOp::ZeroOrOne;
let is_vis = seq.tts.first().map_or(false, |tt| {
matches!(tt, mbe::TokenTree::MetaVarDecl { kind: NonterminalKind::Vis, .. })
});
if is_vis && is_zero_or_one {
if seq.kleene.op == KleeneOp::ZeroOrOne
&& matches!(
seq.tts.first(),
Some(mbe::TokenTree::MetaVarDecl { kind: NonterminalKind::Vis, .. })
)
{
err.note("a `vis` fragment can already be empty");
err.multipart_suggestion(
"remove the `$(` and `)?`",