about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2018-07-21 20:59:44 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2018-08-19 16:53:05 -0700
commit9e64ce179903e610197e1d201a53471e9feb69f2 (patch)
tree54c5857eb12273f67b7b92d03dff6cf3f5cfb4e2 /src/libsyntax/parse
parent1c906093f93ca55994bded24fa0f9c99b8d1a681 (diff)
downloadrust-9e64ce179903e610197e1d201a53471e9feb69f2.tar.gz
rust-9e64ce179903e610197e1d201a53471e9feb69f2.zip
Parse try blocks with the try keyword instead of do catch placeholder
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index fdb9f80b7c6..2b0cfd14a3d 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2386,11 +2386,10 @@ impl<'a> Parser<'a> {
                         BlockCheckMode::Unsafe(ast::UserProvided),
                         attrs);
                 }
-                if self.is_catch_expr() {
+                if self.is_try_block() {
                     let lo = self.span;
-                    assert!(self.eat_keyword(keywords::Do));
-                    assert!(self.eat_keyword(keywords::Catch));
-                    return self.parse_catch_expr(lo, attrs);
+                    assert!(self.eat_keyword(keywords::Try));
+                    return self.parse_try_block(lo, attrs);
                 }
                 if self.eat_keyword(keywords::Return) {
                     if self.token.can_begin_expr() {
@@ -3452,8 +3451,8 @@ impl<'a> Parser<'a> {
             ExprKind::Async(capture_clause, ast::DUMMY_NODE_ID, body), attrs))
     }
 
-    /// Parse a `do catch {...}` expression (`do catch` token already eaten)
-    fn parse_catch_expr(&mut self, span_lo: Span, mut attrs: ThinVec<Attribute>)
+    /// Parse a `try {...}` expression (`try` token already eaten)
+    fn parse_try_block(&mut self, span_lo: Span, mut attrs: ThinVec<Attribute>)
         -> PResult<'a, P<Expr>>
     {
         let (iattrs, body) = self.parse_inner_attrs_and_block()?;
@@ -4407,12 +4406,13 @@ impl<'a> Parser<'a> {
         )
     }
 
-    fn is_catch_expr(&mut self) -> bool {
-        self.token.is_keyword(keywords::Do) &&
-        self.look_ahead(1, |t| t.is_keyword(keywords::Catch)) &&
-        self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace)) &&
+    fn is_try_block(&mut self) -> bool {
+        self.token.is_keyword(keywords::Try) &&
+        self.look_ahead(1, |t| *t == token::OpenDelim(token::Brace)) &&
 
-        // prevent `while catch {} {}`, `if catch {} {} else {}`, etc.
+        self.span.edition() >= Edition::Edition2018 &&
+
+        // prevent `while try {} {}`, `if try {} {} else {}`, etc.
         !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL)
     }