about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-04-04 15:47:53 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2022-04-04 17:03:36 +1000
commit0bd47e8a393d8a670d2770d35e9158adfa1f813e (patch)
tree68386837693c6f660b5b5a0a74d90f5328f095b5
parent88f8fbcce07f74b26e308ae5b2156d75ec03e35e (diff)
downloadrust-0bd47e8a393d8a670d2770d35e9158adfa1f813e.tar.gz
rust-0bd47e8a393d8a670d2770d35e9158adfa1f813e.zip
Reorder match arms in `parse_tt_inner`.
To match the order the variants are declared in.
-rw-r--r--compiler/rustc_expand/src/mbe/macro_parser.rs62
1 files changed, 31 insertions, 31 deletions
diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs
index c1bf8f8816a..522989c6454 100644
--- a/compiler/rustc_expand/src/mbe/macro_parser.rs
+++ b/compiler/rustc_expand/src/mbe/macro_parser.rs
@@ -443,6 +443,29 @@ impl<'tt> TtParser<'tt> {
 
         while let Some(mut mp) = self.cur_mps.pop() {
             match &self.locs[mp.idx] {
+                MatcherLoc::Token { token: t } => {
+                    // If it's a doc comment, we just ignore it and move on to the next tt in the
+                    // matcher. This is a bug, but #95267 showed that existing programs rely on
+                    // this behaviour, and changing it would require some care and a transition
+                    // period.
+                    //
+                    // If the token matches, we can just advance the parser.
+                    //
+                    // Otherwise, this match has failed, there is nothing to do, and hopefully
+                    // another mp in `cur_mps` will match.
+                    if matches!(t, Token { kind: DocComment(..), .. }) {
+                        mp.idx += 1;
+                        self.cur_mps.push(mp);
+                    } else if token_name_eq(&t, token) {
+                        mp.idx += 1;
+                        self.next_mps.push(mp);
+                    }
+                }
+                MatcherLoc::Delimited => {
+                    // Entering the delimeter is trivial.
+                    mp.idx += 1;
+                    self.cur_mps.push(mp);
+                }
                 &MatcherLoc::Sequence {
                     op,
                     num_metavar_decls,
@@ -471,37 +494,6 @@ impl<'tt> TtParser<'tt> {
                     mp.idx += 1;
                     self.cur_mps.push(mp);
                 }
-                MatcherLoc::MetaVarDecl { kind, .. } => {
-                    // Built-in nonterminals never start with these tokens, so we can eliminate
-                    // them from consideration. We use the span of the metavariable declaration
-                    // to determine any edition-specific matching behavior for non-terminals.
-                    if Parser::nonterminal_may_begin_with(*kind, token) {
-                        self.bb_mps.push(mp);
-                    }
-                }
-                MatcherLoc::Delimited => {
-                    // Entering the delimeter is trivial.
-                    mp.idx += 1;
-                    self.cur_mps.push(mp);
-                }
-                MatcherLoc::Token { token: t } => {
-                    // If it's a doc comment, we just ignore it and move on to the next tt in the
-                    // matcher. This is a bug, but #95267 showed that existing programs rely on
-                    // this behaviour, and changing it would require some care and a transition
-                    // period.
-                    //
-                    // If the token matches, we can just advance the parser.
-                    //
-                    // Otherwise, this match has failed, there is nothing to do, and hopefully
-                    // another mp in `cur_mps` will match.
-                    if matches!(t, Token { kind: DocComment(..), .. }) {
-                        mp.idx += 1;
-                        self.cur_mps.push(mp);
-                    } else if token_name_eq(&t, token) {
-                        mp.idx += 1;
-                        self.next_mps.push(mp);
-                    }
-                }
                 &MatcherLoc::SequenceKleeneOpNoSep { op, idx_first } => {
                     // We are past the end of a sequence with no separator. Try ending the
                     // sequence. If that's not possible, `ending_mp` will fail quietly when it is
@@ -540,6 +532,14 @@ impl<'tt> TtParser<'tt> {
                     mp.idx = idx_first;
                     self.cur_mps.push(mp);
                 }
+                MatcherLoc::MetaVarDecl { kind, .. } => {
+                    // Built-in nonterminals never start with these tokens, so we can eliminate
+                    // them from consideration. We use the span of the metavariable declaration
+                    // to determine any edition-specific matching behavior for non-terminals.
+                    if Parser::nonterminal_may_begin_with(*kind, token) {
+                        self.bb_mps.push(mp);
+                    }
+                }
                 MatcherLoc::Eof => {
                     // We are past the matcher's end, and not in a sequence. Try to end things.
                     debug_assert_eq!(mp.idx, self.locs.len() - 1);