From 9e64ce179903e610197e1d201a53471e9feb69f2 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 21 Jul 2018 20:59:44 -0700 Subject: Parse try blocks with the try keyword instead of do catch placeholder --- src/libsyntax/parse/parser.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/libsyntax/parse') 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) + /// Parse a `try {...}` expression (`try` token already eaten) + fn parse_try_block(&mut self, span_lo: Span, mut attrs: ThinVec) -> PResult<'a, P> { 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) } -- cgit 1.4.1-3-g733a5