]> git.lizzy.rs Git - rust.git/commitdiff
Change condition ordering in `parse_tt`.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 5 Feb 2020 04:09:24 +0000 (15:09 +1100)
committerNicholas Nethercote <nnethercote@mozilla.com>
Thu, 6 Feb 2020 05:42:58 +0000 (16:42 +1100)
This is a small win, because `Failure` is much more common than
`Success`.

src/librustc_expand/mbe/macro_parser.rs

index 78f22f3e443b1206703c3f8e5b1f697a88f26538..5bf7602ea6e8f7a37e98fa372e85391b8de4167e 100644 (file)
@@ -689,9 +689,14 @@ pub(super) fn parse_tt(parser: &mut Cow<'_, Parser<'_>>, ms: &[TokenTree]) -> Na
         // unnecessary implicit clone later in Rc::make_mut.
         drop(eof_items);
 
+        // If there are no possible next positions AND we aren't waiting for the black-box parser,
+        // then there is a syntax error.
+        if bb_items.is_empty() && next_items.is_empty() {
+            return Failure(parser.token.clone(), "no rules expected this token in macro call");
+        }
         // Another possibility is that we need to call out to parse some rust nonterminal
         // (black-box) parser. However, if there is not EXACTLY ONE of these, something is wrong.
-        if (!bb_items.is_empty() && !next_items.is_empty()) || bb_items.len() > 1 {
+        else if (!bb_items.is_empty() && !next_items.is_empty()) || bb_items.len() > 1 {
             let nts = bb_items
                 .iter()
                 .map(|item| match item.top_elts.get_tt(item.idx) {
@@ -713,11 +718,6 @@ pub(super) fn parse_tt(parser: &mut Cow<'_, Parser<'_>>, ms: &[TokenTree]) -> Na
                 ),
             );
         }
-        // If there are no possible next positions AND we aren't waiting for the black-box parser,
-        // then there is a syntax error.
-        else if bb_items.is_empty() && next_items.is_empty() {
-            return Failure(parser.token.clone(), "no rules expected this token in macro call");
-        }
         // Dump all possible `next_items` into `cur_items` for the next iteration.
         else if !next_items.is_empty() {
             // Now process the next token