diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2020-02-05 15:09:24 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2020-02-06 16:42:58 +1100 |
| commit | 2a13b24d369b8619f0197993cd5dc60f7217ed72 (patch) | |
| tree | 66d99d4bdf1eb5ed8146554a29c5400c33473c00 | |
| parent | f840a955bd449810e75d8320b4c46482d6dbdec1 (diff) | |
| download | rust-2a13b24d369b8619f0197993cd5dc60f7217ed72.tar.gz rust-2a13b24d369b8619f0197993cd5dc60f7217ed72.zip | |
Change condition ordering in `parse_tt`.
This is a small win, because `Failure` is much more common than `Success`.
| -rw-r--r-- | src/librustc_expand/mbe/macro_parser.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/librustc_expand/mbe/macro_parser.rs b/src/librustc_expand/mbe/macro_parser.rs index 78f22f3e443..5bf7602ea6e 100644 --- a/src/librustc_expand/mbe/macro_parser.rs +++ b/src/librustc_expand/mbe/macro_parser.rs @@ -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 |
