@@ -602,12 +602,6 @@ impl<'a> Parser<'a> {
602
602
}
603
603
}
604
604
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
-
611
605
/// Check if the next token is `tok`, and return `true` if so.
612
606
///
613
607
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
@@ -2280,6 +2274,7 @@ impl<'a> Parser<'a> {
2280
2274
attrs) ;
2281
2275
}
2282
2276
if self . is_catch_expr ( ) {
2277
+ assert ! ( self . eat_keyword( keywords:: Do ) ) ;
2283
2278
assert ! ( self . eat_keyword( keywords:: Catch ) ) ;
2284
2279
let lo = self . prev_span . lo ;
2285
2280
return self . parse_catch_expr ( lo, attrs) ;
@@ -3103,7 +3098,7 @@ impl<'a> Parser<'a> {
3103
3098
Ok ( self . mk_expr ( span_lo, hi, ExprKind :: Loop ( body, opt_ident) , attrs) )
3104
3099
}
3105
3100
3106
- /// Parse a `catch {...}` expression (`catch` token already eaten)
3101
+ /// Parse a `do catch {...}` expression (`do catch` token already eaten)
3107
3102
pub fn parse_catch_expr ( & mut self , span_lo : BytePos , mut attrs : ThinVec < Attribute > )
3108
3103
-> PResult < ' a , P < Expr > >
3109
3104
{
@@ -3721,8 +3716,9 @@ impl<'a> Parser<'a> {
3721
3716
}
3722
3717
3723
3718
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 ) ) &&
3726
3722
3727
3723
// prevent `while catch {} {}`, `if catch {} {} else {}`, etc.
3728
3724
!self . restrictions . contains ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL )
@@ -4904,7 +4900,6 @@ impl<'a> Parser<'a> {
4904
4900
/// Parse struct Foo { ... }
4905
4901
fn parse_item_struct ( & mut self ) -> PResult < ' a , ItemInfo > {
4906
4902
let class_name = self . parse_ident ( ) ?;
4907
- self . error_if_typename_is_catch ( class_name) ;
4908
4903
4909
4904
let mut generics = self . parse_generics ( ) ?;
4910
4905
@@ -4955,7 +4950,6 @@ impl<'a> Parser<'a> {
4955
4950
/// Parse union Foo { ... }
4956
4951
fn parse_item_union ( & mut self ) -> PResult < ' a , ItemInfo > {
4957
4952
let class_name = self . parse_ident ( ) ?;
4958
- self . error_if_typename_is_catch ( class_name) ;
4959
4953
4960
4954
let mut generics = self . parse_generics ( ) ?;
4961
4955
@@ -5473,7 +5467,6 @@ impl<'a> Parser<'a> {
5473
5467
let struct_def;
5474
5468
let mut disr_expr = None ;
5475
5469
let ident = self . parse_ident ( ) ?;
5476
- self . error_if_typename_is_catch ( ident) ;
5477
5470
if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
5478
5471
// Parse a struct variant.
5479
5472
all_nullary = false ;
@@ -5515,7 +5508,6 @@ impl<'a> Parser<'a> {
5515
5508
/// Parse an "enum" declaration
5516
5509
fn parse_item_enum ( & mut self ) -> PResult < ' a , ItemInfo > {
5517
5510
let id = self . parse_ident ( ) ?;
5518
- self . error_if_typename_is_catch ( id) ;
5519
5511
let mut generics = self . parse_generics ( ) ?;
5520
5512
generics. where_clause = self . parse_where_clause ( ) ?;
5521
5513
self . expect ( & token:: OpenDelim ( token:: Brace ) ) ?;
0 commit comments