@@ -602,12 +602,6 @@ impl<'a> Parser<'a> {
602602 }
603603 }
604604
605- pub fn error_if_typename_is_catch ( & mut self , ident : ast:: Ident ) {
606- if ident. name == keywords:: Catch . name ( ) {
607- self . span_err ( self . span , "cannot use `catch` as the name of a type" ) ;
608- }
609- }
610-
611605 /// Check if the next token is `tok`, and return `true` if so.
612606 ///
613607 /// This method will automatically add `tok` to `expected_tokens` if `tok` is not
@@ -2280,6 +2274,7 @@ impl<'a> Parser<'a> {
22802274 attrs) ;
22812275 }
22822276 if self . is_catch_expr ( ) {
2277+ assert ! ( self . eat_keyword( keywords:: Do ) ) ;
22832278 assert ! ( self . eat_keyword( keywords:: Catch ) ) ;
22842279 let lo = self . prev_span . lo ;
22852280 return self . parse_catch_expr ( lo, attrs) ;
@@ -3103,7 +3098,7 @@ impl<'a> Parser<'a> {
31033098 Ok ( self . mk_expr ( span_lo, hi, ExprKind :: Loop ( body, opt_ident) , attrs) )
31043099 }
31053100
3106- /// Parse a `catch {...}` expression (`catch` token already eaten)
3101+ /// Parse a `do catch {...}` expression (`do catch` token already eaten)
31073102 pub fn parse_catch_expr ( & mut self , span_lo : BytePos , mut attrs : ThinVec < Attribute > )
31083103 -> PResult < ' a , P < Expr > >
31093104 {
@@ -3721,8 +3716,9 @@ impl<'a> Parser<'a> {
37213716 }
37223717
37233718 fn is_catch_expr ( & mut self ) -> bool {
3724- self . token . is_keyword ( keywords:: Catch ) &&
3725- self . look_ahead ( 1 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
3719+ self . token . is_keyword ( keywords:: Do ) &&
3720+ self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Catch ) ) &&
3721+ self . look_ahead ( 2 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
37263722
37273723 // prevent `while catch {} {}`, `if catch {} {} else {}`, etc.
37283724 !self . restrictions . contains ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL )
@@ -4904,7 +4900,6 @@ impl<'a> Parser<'a> {
49044900 /// Parse struct Foo { ... }
49054901 fn parse_item_struct ( & mut self ) -> PResult < ' a , ItemInfo > {
49064902 let class_name = self . parse_ident ( ) ?;
4907- self . error_if_typename_is_catch ( class_name) ;
49084903
49094904 let mut generics = self . parse_generics ( ) ?;
49104905
@@ -4955,7 +4950,6 @@ impl<'a> Parser<'a> {
49554950 /// Parse union Foo { ... }
49564951 fn parse_item_union ( & mut self ) -> PResult < ' a , ItemInfo > {
49574952 let class_name = self . parse_ident ( ) ?;
4958- self . error_if_typename_is_catch ( class_name) ;
49594953
49604954 let mut generics = self . parse_generics ( ) ?;
49614955
@@ -5473,7 +5467,6 @@ impl<'a> Parser<'a> {
54735467 let struct_def;
54745468 let mut disr_expr = None ;
54755469 let ident = self . parse_ident ( ) ?;
5476- self . error_if_typename_is_catch ( ident) ;
54775470 if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
54785471 // Parse a struct variant.
54795472 all_nullary = false ;
@@ -5515,7 +5508,6 @@ impl<'a> Parser<'a> {
55155508 /// Parse an "enum" declaration
55165509 fn parse_item_enum ( & mut self ) -> PResult < ' a , ItemInfo > {
55175510 let id = self . parse_ident ( ) ?;
5518- self . error_if_typename_is_catch ( id) ;
55195511 let mut generics = self . parse_generics ( ) ?;
55205512 generics. where_clause = self . parse_where_clause ( ) ?;
55215513 self . expect ( & token:: OpenDelim ( token:: Brace ) ) ?;
0 commit comments