diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-09-26 18:11:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-26 18:11:14 +0200 |
| commit | 978c960ed628e55e6c9d261eb7f15d593c69688e (patch) | |
| tree | d9987aa62955d943c76bf9f8b1e8f29aeabacc73 | |
| parent | 67d88f93cd193312ca7f5258b6aac3f4365f1d5e (diff) | |
| parent | 9e3f7487e9e572aee95381688bda52525d79b005 (diff) | |
| download | rust-978c960ed628e55e6c9d261eb7f15d593c69688e.tar.gz rust-978c960ed628e55e6c9d261eb7f15d593c69688e.zip | |
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.
| -rw-r--r-- | compiler/rustc_expand/src/mbe/macro_rules.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 9ed4c56efb3..d4504ba720e 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -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 `)?`", |
