Skip to content

Commit 2a13b24

Browse files
committed
Change condition ordering in parse_tt.
This is a small win, because `Failure` is much more common than `Success`.
1 parent f840a95 commit 2a13b24

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Diff for: src/librustc_expand/mbe/macro_parser.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,14 @@ pub(super) fn parse_tt(parser: &mut Cow<'_, Parser<'_>>, ms: &[TokenTree]) -> Na
689689
// unnecessary implicit clone later in Rc::make_mut.
690690
drop(eof_items);
691691

692+
// If there are no possible next positions AND we aren't waiting for the black-box parser,
693+
// then there is a syntax error.
694+
if bb_items.is_empty() && next_items.is_empty() {
695+
return Failure(parser.token.clone(), "no rules expected this token in macro call");
696+
}
692697
// Another possibility is that we need to call out to parse some rust nonterminal
693698
// (black-box) parser. However, if there is not EXACTLY ONE of these, something is wrong.
694-
if (!bb_items.is_empty() && !next_items.is_empty()) || bb_items.len() > 1 {
699+
else if (!bb_items.is_empty() && !next_items.is_empty()) || bb_items.len() > 1 {
695700
let nts = bb_items
696701
.iter()
697702
.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
713718
),
714719
);
715720
}
716-
// If there are no possible next positions AND we aren't waiting for the black-box parser,
717-
// then there is a syntax error.
718-
else if bb_items.is_empty() && next_items.is_empty() {
719-
return Failure(parser.token.clone(), "no rules expected this token in macro call");
720-
}
721721
// Dump all possible `next_items` into `cur_items` for the next iteration.
722722
else if !next_items.is_empty() {
723723
// Now process the next token

0 commit comments

Comments
 (0)