about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/mbe/macro_parser.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-03-19 13:33:33 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-03-21 10:18:34 +1100
commita94bb2a0136b72d177fcd1c49d50227ded195133 (patch)
tree3a6ee999823c866ccd51c84a5df366811e7eb774 /compiler/rustc_expand/src/mbe/macro_parser.rs
parentb7f3b714da1b9f72ae16f37ff6e2def306e85f69 (diff)
downloadrust-a94bb2a0136b72d177fcd1c49d50227ded195133.tar.gz
rust-a94bb2a0136b72d177fcd1c49d50227ded195133.zip
Streamline `NamedMatch`.
This commit combines `MatchedTokenTree` and `MatchedNonterminal`, which
are often considered together, into a single `MatchedSingle`. It shares
a representation with the newly-parameterized `ParseNtResult`.

This will also make things much simpler if/when variants from
`Interpolated` start being moved to `ParseNtResult`.
Diffstat (limited to 'compiler/rustc_expand/src/mbe/macro_parser.rs')
-rw-r--r--compiler/rustc_expand/src/mbe/macro_parser.rs17
1 files changed, 6 insertions, 11 deletions
diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs
index ac5136539c3..a31be05ccc4 100644
--- a/compiler/rustc_expand/src/mbe/macro_parser.rs
+++ b/compiler/rustc_expand/src/mbe/macro_parser.rs
@@ -392,12 +392,7 @@ pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize {
 #[derive(Debug, Clone)]
 pub(crate) enum NamedMatch {
     MatchedSeq(Vec<NamedMatch>),
-
-    // A metavar match of type `tt`.
-    MatchedTokenTree(rustc_ast::tokenstream::TokenTree),
-
-    // A metavar match of any type other than `tt`.
-    MatchedNonterminal(Lrc<(Nonterminal, rustc_span::Span)>),
+    MatchedSingle(ParseNtResult<Lrc<(Nonterminal, Span)>>),
 }
 
 /// Performs a token equality check, ignoring syntax context (that is, an unhygienic comparison)
@@ -691,11 +686,11 @@ impl TtParser {
                             }
                             Ok(nt) => nt,
                         };
-                        let m = match nt {
-                            ParseNtResult::Nt(nt) => MatchedNonterminal(Lrc::new((nt, span))),
-                            ParseNtResult::Tt(tt) => MatchedTokenTree(tt),
-                        };
-                        mp.push_match(next_metavar, seq_depth, m);
+                        mp.push_match(
+                            next_metavar,
+                            seq_depth,
+                            MatchedSingle(nt.map_nt(|nt| (Lrc::new((nt, span))))),
+                        );
                         mp.idx += 1;
                     } else {
                         unreachable!()