]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #61612 - nnethercote:improve-parse_bottom_expr, r=petrochenkov
authorbors <bors@rust-lang.org>
Wed, 12 Jun 2019 16:30:05 +0000 (16:30 +0000)
committerbors <bors@rust-lang.org>
Wed, 12 Jun 2019 16:30:05 +0000 (16:30 +0000)
Special-case literals in `parse_bottom_expr`.

This makes parsing faster, particularly for code with large constants,
for two reasons:
- it skips all the keyword comparisons for literals;
- it skips the allocation done by the `mk_expr` call in
  `parse_literal_maybe_minus`.

r? @petrochenkov

1  2 
src/libsyntax/parse/parser.rs

index b6388f08e73d5f8d842ecaa535008aa4cf3a3fa3,9b9954859be4949005e7577ac4c5c255cd9eb36e..78eeb51220662f1ff2d677cfd03d6b6727ab2013
@@@ -2239,18 -2268,9 +2260,9 @@@ impl<'a> Parser<'a> 
                          //   |             ^ expected expression
                          // ```
                          self.bump();
 -                        return Ok(self.mk_expr(self.span, ExprKind::Err, ThinVec::new()));
 +                        return Ok(self.mk_expr(self.token.span, ExprKind::Err, ThinVec::new()));
                      }
-                     match self.parse_literal_maybe_minus() {
-                         Ok(expr) => {
-                             hi = expr.span;
-                             ex = expr.node.clone();
-                         }
-                         Err(mut err) => {
-                             self.cancel(&mut err);
-                             return Err(self.expected_expression_found());
-                         }
-                     }
+                     parse_lit!()
                  }
              }
          }