about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorTaylor Cramer <cramertaylorj@gmail.com>2017-03-03 14:41:07 -0800
committerTaylor Cramer <cramertaylorj@gmail.com>2017-03-11 22:26:57 -0800
commitea4e8b0a81171d4d6c28a61fa0d1c4d74837bb65 (patch)
tree36847af56a1a93aab1bc9d472c44db14ab6bafe4 /src/libsyntax/parse
parentd95c5437222fd63d7b12676bc7916dbeb720f131 (diff)
downloadrust-ea4e8b0a81171d4d6c28a61fa0d1c4d74837bb65.tar.gz
rust-ea4e8b0a81171d4d6c28a61fa0d1c4d74837bb65.zip
Temporarily prefix catch block with do keyword
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs18
-rw-r--r--src/libsyntax/parse/token.rs1
2 files changed, 6 insertions, 13 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index c0ee778b7ee..252b4ec4660 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -602,12 +602,6 @@ impl<'a> Parser<'a> {
         }
     }
 
-    pub fn error_if_typename_is_catch(&mut self, ident: ast::Ident) {
-        if ident.name == keywords::Catch.name() {
-            self.span_err(self.span, "cannot use `catch` as the name of a type");
-        }
-    }
-
     /// Check if the next token is `tok`, and return `true` if so.
     ///
     /// This method will automatically add `tok` to `expected_tokens` if `tok` is not
@@ -2280,6 +2274,7 @@ impl<'a> Parser<'a> {
                         attrs);
                 }
                 if self.is_catch_expr() {
+                    assert!(self.eat_keyword(keywords::Do));
                     assert!(self.eat_keyword(keywords::Catch));
                     let lo = self.prev_span.lo;
                     return self.parse_catch_expr(lo, attrs);
@@ -3103,7 +3098,7 @@ impl<'a> Parser<'a> {
         Ok(self.mk_expr(span_lo, hi, ExprKind::Loop(body, opt_ident), attrs))
     }
 
-    /// Parse a `catch {...}` expression (`catch` token already eaten)
+    /// Parse a `do catch {...}` expression (`do catch` token already eaten)
     pub fn parse_catch_expr(&mut self, span_lo: BytePos, mut attrs: ThinVec<Attribute>)
         -> PResult<'a, P<Expr>>
     {
@@ -3721,8 +3716,9 @@ impl<'a> Parser<'a> {
     }
 
     fn is_catch_expr(&mut self) -> bool {
-        self.token.is_keyword(keywords::Catch) &&
-        self.look_ahead(1, |t| *t == token::OpenDelim(token::Brace)) &&
+        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)) &&
 
         // prevent `while catch {} {}`, `if catch {} {} else {}`, etc.
         !self.restrictions.contains(Restrictions::RESTRICTION_NO_STRUCT_LITERAL)
@@ -4904,7 +4900,6 @@ impl<'a> Parser<'a> {
     /// Parse struct Foo { ... }
     fn parse_item_struct(&mut self) -> PResult<'a, ItemInfo> {
         let class_name = self.parse_ident()?;
-        self.error_if_typename_is_catch(class_name);
 
         let mut generics = self.parse_generics()?;
 
@@ -4955,7 +4950,6 @@ impl<'a> Parser<'a> {
     /// Parse union Foo { ... }
     fn parse_item_union(&mut self) -> PResult<'a, ItemInfo> {
         let class_name = self.parse_ident()?;
-        self.error_if_typename_is_catch(class_name);
 
         let mut generics = self.parse_generics()?;
 
@@ -5473,7 +5467,6 @@ impl<'a> Parser<'a> {
             let struct_def;
             let mut disr_expr = None;
             let ident = self.parse_ident()?;
-            self.error_if_typename_is_catch(ident);
             if self.check(&token::OpenDelim(token::Brace)) {
                 // Parse a struct variant.
                 all_nullary = false;
@@ -5515,7 +5508,6 @@ impl<'a> Parser<'a> {
     /// Parse an "enum" declaration
     fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> {
         let id = self.parse_ident()?;
-        self.error_if_typename_is_catch(id);
         let mut generics = self.parse_generics()?;
         generics.where_clause = self.parse_where_clause()?;
         self.expect(&token::OpenDelim(token::Brace))?;
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 5b65aac92b8..25601f2420e 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -86,6 +86,7 @@ fn ident_can_begin_expr(ident: ast::Ident) -> bool {
     !ident_token.is_any_keyword() ||
     ident_token.is_path_segment_keyword() ||
     [
+        keywords::Do.name(),
         keywords::Box.name(),
         keywords::Break.name(),
         keywords::Continue.name(),