about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/nonterminal.rs
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2021-03-25 18:05:49 -0400
committerAaron Hill <aa1ronham@gmail.com>2021-03-25 18:05:49 -0400
commit7504b9bb96236a340c41c95f95cf3c4a09341afc (patch)
tree54573f6a3e8b9a56c92e10925fab978fe48e06bb /compiler/rustc_parse/src/parser/nonterminal.rs
parentfe60f19f7e98af78526364563fa6b40825fa97a8 (diff)
downloadrust-7504b9bb96236a340c41c95f95cf3c4a09341afc.tar.gz
rust-7504b9bb96236a340c41c95f95cf3c4a09341afc.zip
Avoid double-collection for expression nonterminals
Diffstat (limited to 'compiler/rustc_parse/src/parser/nonterminal.rs')
-rw-r--r--compiler/rustc_parse/src/parser/nonterminal.rs17
1 files changed, 1 insertions, 16 deletions
diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs
index fc25e883666..0c49d103583 100644
--- a/compiler/rustc_parse/src/parser/nonterminal.rs
+++ b/compiler/rustc_parse/src/parser/nonterminal.rs
@@ -128,22 +128,7 @@ impl<'a> Parser<'a> {
                 })?)
             }
 
-            // If there are attributes present, then `parse_expr` will end up collecting tokens,
-            // turning the outer `collect_tokens_no_attrs` into a no-op due to the already present
-            // tokens. If there are *not* attributes present, then the outer
-            // `collect_tokens_no_attrs` will ensure that we will end up collecting tokens for the
-            // expressions.
-            //
-            // This is less efficient than it could be, since the outer `collect_tokens_no_attrs`
-            // still needs to snapshot the `TokenCursor` before calling `parse_expr`, even when
-            // `parse_expr` will end up collecting tokens. Ideally, this would work more like
-            // `parse_item`, and take in a `ForceCollect` parameter. However, this would require
-            // adding a `ForceCollect` parameter in a bunch of places in expression parsing
-            // for little gain. If the perf impact from this turns out to be noticeable, we should
-            // revisit this apporach.
-            NonterminalKind::Expr => {
-                token::NtExpr(self.collect_tokens_no_attrs(|this| this.parse_expr())?)
-            }
+            NonterminalKind::Expr => token::NtExpr(self.parse_expr_force_collect()?),
             NonterminalKind::Literal => {
                 // The `:literal` matcher does not support attributes
                 token::NtLiteral(