about summary refs log tree commit diff
path: root/src/libsyntax
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
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')
-rw-r--r--src/libsyntax/feature_gate.rs4
-rw-r--r--src/libsyntax/parse/parser.rs22
-rw-r--r--src/libsyntax/print/pprust.rs2
3 files changed, 14 insertions, 14 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 32769130940..f796c0e2e53 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -330,7 +330,7 @@ declare_features! (
     // `extern "x86-interrupt" fn()`
     (active, abi_x86_interrupt, "1.17.0", Some(40180), None),
 
-    // Allows the `catch {...}` expression
+    // Allows the `try {...}` expression
     (active, catch_expr, "1.17.0", Some(31436), None),
 
     // Used to preserve symbols (see llvm.used)
@@ -1735,7 +1735,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
                                   "yield syntax is experimental");
             }
             ast::ExprKind::TryBlock(_) => {
-                gate_feature_post!(&self, catch_expr, e.span, "`catch` expression is experimental");
+                gate_feature_post!(&self, catch_expr, e.span, "`try` expression is experimental");
             }
             ast::ExprKind::IfLet(ref pats, ..) | ast::ExprKind::WhileLet(ref pats, ..) => {
                 if pats.len() > 1 {
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)
     }
 
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index f8d01fee950..14e7b08172b 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -2380,7 +2380,7 @@ impl<'a> State<'a> {
                 self.s.word("?")?
             }
             ast::ExprKind::TryBlock(ref blk) => {
-                self.head("do catch")?;
+                self.head("try")?;
                 self.s.space()?;
                 self.print_block_with_attrs(blk, attrs)?
             }