@@ -2386,11 +2386,10 @@ impl<'a> Parser<'a> {
23862386 BlockCheckMode :: Unsafe ( ast:: UserProvided ) ,
23872387 attrs) ;
23882388 }
2389- if self . is_catch_expr ( ) {
2389+ if self . is_try_block ( ) {
23902390 let lo = self . span ;
2391- assert ! ( self . eat_keyword( keywords:: Do ) ) ;
2392- assert ! ( self . eat_keyword( keywords:: Catch ) ) ;
2393- return self . parse_catch_expr ( lo, attrs) ;
2391+ assert ! ( self . eat_keyword( keywords:: Try ) ) ;
2392+ return self . parse_try_block ( lo, attrs) ;
23942393 }
23952394 if self . eat_keyword ( keywords:: Return ) {
23962395 if self . token . can_begin_expr ( ) {
@@ -3452,8 +3451,8 @@ impl<'a> Parser<'a> {
34523451 ExprKind :: Async ( capture_clause, ast:: DUMMY_NODE_ID , body) , attrs) )
34533452 }
34543453
3455- /// Parse a `do catch {...}` expression (`do catch ` token already eaten)
3456- fn parse_catch_expr ( & mut self , span_lo : Span , mut attrs : ThinVec < Attribute > )
3454+ /// Parse a `try {...}` expression (`try ` token already eaten)
3455+ fn parse_try_block ( & mut self , span_lo : Span , mut attrs : ThinVec < Attribute > )
34573456 -> PResult < ' a , P < Expr > >
34583457 {
34593458 let ( iattrs, body) = self . parse_inner_attrs_and_block ( ) ?;
@@ -4407,12 +4406,13 @@ impl<'a> Parser<'a> {
44074406 )
44084407 }
44094408
4410- fn is_catch_expr ( & mut self ) -> bool {
4411- self . token . is_keyword ( keywords:: Do ) &&
4412- self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Catch ) ) &&
4413- self . look_ahead ( 2 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
4409+ fn is_try_block ( & mut self ) -> bool {
4410+ self . token . is_keyword ( keywords:: Try ) &&
4411+ self . look_ahead ( 1 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
44144412
4415- // prevent `while catch {} {}`, `if catch {} {} else {}`, etc.
4413+ self . span . edition ( ) >= Edition :: Edition2018 &&
4414+
4415+ // prevent `while try {} {}`, `if try {} {} else {}`, etc.
44164416 !self . restrictions . contains ( Restrictions :: NO_STRUCT_LITERAL )
44174417 }
44184418
0 commit comments