about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-05-20 09:20:49 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2024-05-23 06:00:57 +1000
commit3fc8f8998c45fbc211b98b5bae04cc87f8eb1619 (patch)
treec222344544f532f17b3e913481f3f242ff929323
parentc8844dfdc00fbfe4b5e7839635214b744410312f (diff)
downloadrust-3fc8f8998c45fbc211b98b5bae04cc87f8eb1619.tar.gz
rust-3fc8f8998c45fbc211b98b5bae04cc87f8eb1619.zip
Clarify `parse` a little.
- Name the colon span as `colon_span` to distinguish it from the other
  `span` local variable.
- Just use basic pattern matching, which is easier to read than `map_or`.
-rw-r--r--compiler/rustc_expand/src/mbe/quoted.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs
index 2e37fd70df9..8ad7cb15c92 100644
--- a/compiler/rustc_expand/src/mbe/quoted.rs
+++ b/compiler/rustc_expand/src/mbe/quoted.rs
@@ -62,7 +62,10 @@ pub(super) fn parse(
         match tree {
             TokenTree::MetaVar(start_sp, ident) if parsing_patterns => {
                 let span = match trees.next() {
-                    Some(&tokenstream::TokenTree::Token(Token { kind: token::Colon, span }, _)) => {
+                    Some(&tokenstream::TokenTree::Token(
+                        Token { kind: token::Colon, span: colon_span },
+                        _,
+                    )) => {
                         match trees.next() {
                             Some(tokenstream::TokenTree::Token(token, _)) => match token.ident() {
                                 Some((fragment, _)) => {
@@ -126,10 +129,12 @@ pub(super) fn parse(
                                 }
                                 _ => token.span,
                             },
-                            tree => tree.map_or(span, tokenstream::TokenTree::span),
+                            Some(tree) => tree.span(),
+                            None => colon_span,
                         }
                     }
-                    tree => tree.map_or(start_sp, tokenstream::TokenTree::span),
+                    Some(tree) => tree.span(),
+                    None => start_sp,
                 };
 
                 result.push(TokenTree::MetaVarDecl(span, ident, None));