From 817efc2489806b8188c2f5693fb3b0dcf9c76eb1 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Tue, 24 Jul 2018 17:55:36 -0700 Subject: Suggest `try` if someone uses `do catch` --- src/libsyntax/parse/parser.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2b0cfd14a3d..ad57530474c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2386,6 +2386,11 @@ impl<'a> Parser<'a> { BlockCheckMode::Unsafe(ast::UserProvided), attrs); } + if self.is_do_catch_block() { + let mut db = self.fatal("found removed `do catch` syntax"); + db.help("Following RFC #2388, the new non-placeholder syntax is `try`"); + return Err(db); + } if self.is_try_block() { let lo = self.span; assert!(self.eat_keyword(keywords::Try)); @@ -4406,6 +4411,13 @@ impl<'a> Parser<'a> { ) } + fn is_do_catch_block(&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)) && + !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL) + } + fn is_try_block(&mut self) -> bool { self.token.is_keyword(keywords::Try) && self.look_ahead(1, |t| *t == token::OpenDelim(token::Brace)) && -- cgit 1.4.1-3-g733a5