@@ -64,7 +64,7 @@ use std::path::{self, Path, PathBuf};
64
64
use std:: slice;
65
65
66
66
bitflags ! {
67
- flags Restrictions : u8 {
67
+ pub flags Restrictions : u8 {
68
68
const RESTRICTION_STMT_EXPR = 1 << 0 ,
69
69
const RESTRICTION_NO_STRUCT_LITERAL = 1 << 1 ,
70
70
}
@@ -2291,7 +2291,7 @@ impl<'a> Parser<'a> {
2291
2291
let e = if self . token . can_begin_expr ( )
2292
2292
&& !( self . token == token:: OpenDelim ( token:: Brace )
2293
2293
&& self . restrictions . contains (
2294
- Restrictions :: RESTRICTION_NO_STRUCT_LITERAL ) ) {
2294
+ RESTRICTION_NO_STRUCT_LITERAL ) ) {
2295
2295
Some ( self . parse_expr ( ) ?)
2296
2296
} else {
2297
2297
None
@@ -2318,7 +2318,7 @@ impl<'a> Parser<'a> {
2318
2318
// This is a struct literal, unless we're prohibited
2319
2319
// from parsing struct literals here.
2320
2320
let prohibited = self . restrictions . contains (
2321
- Restrictions :: RESTRICTION_NO_STRUCT_LITERAL
2321
+ RESTRICTION_NO_STRUCT_LITERAL
2322
2322
) ;
2323
2323
if !prohibited {
2324
2324
return self . parse_struct_expr ( lo, pth, attrs) ;
@@ -2722,7 +2722,7 @@ impl<'a> Parser<'a> {
2722
2722
token:: Ident ( ..) if self . token . is_keyword ( keywords:: In ) => {
2723
2723
self . bump ( ) ;
2724
2724
let place = self . parse_expr_res (
2725
- Restrictions :: RESTRICTION_NO_STRUCT_LITERAL ,
2725
+ RESTRICTION_NO_STRUCT_LITERAL ,
2726
2726
None ,
2727
2727
) ?;
2728
2728
let blk = self . parse_block ( ) ?;
@@ -2785,7 +2785,7 @@ impl<'a> Parser<'a> {
2785
2785
2786
2786
let cur_op_span = self . span ;
2787
2787
let restrictions = if op. is_assign_like ( ) {
2788
- self . restrictions & Restrictions :: RESTRICTION_NO_STRUCT_LITERAL
2788
+ self . restrictions & RESTRICTION_NO_STRUCT_LITERAL
2789
2789
} else {
2790
2790
self . restrictions
2791
2791
} ;
@@ -2835,21 +2835,21 @@ impl<'a> Parser<'a> {
2835
2835
2836
2836
let rhs = match op. fixity ( ) {
2837
2837
Fixity :: Right => self . with_res (
2838
- restrictions - Restrictions :: RESTRICTION_STMT_EXPR ,
2838
+ restrictions - RESTRICTION_STMT_EXPR ,
2839
2839
|this| {
2840
2840
this. parse_assoc_expr_with ( op. precedence ( ) ,
2841
2841
LhsExpr :: NotYetParsed )
2842
2842
} ) ,
2843
2843
Fixity :: Left => self . with_res (
2844
- restrictions - Restrictions :: RESTRICTION_STMT_EXPR ,
2844
+ restrictions - RESTRICTION_STMT_EXPR ,
2845
2845
|this| {
2846
2846
this. parse_assoc_expr_with ( op. precedence ( ) + 1 ,
2847
2847
LhsExpr :: NotYetParsed )
2848
2848
} ) ,
2849
2849
// We currently have no non-associative operators that are not handled above by
2850
2850
// the special cases. The code is here only for future convenience.
2851
2851
Fixity :: None => self . with_res (
2852
- restrictions - Restrictions :: RESTRICTION_STMT_EXPR ,
2852
+ restrictions - RESTRICTION_STMT_EXPR ,
2853
2853
|this| {
2854
2854
this. parse_assoc_expr_with ( op. precedence ( ) + 1 ,
2855
2855
LhsExpr :: NotYetParsed )
@@ -2959,7 +2959,7 @@ impl<'a> Parser<'a> {
2959
2959
if self . token . can_begin_expr ( ) {
2960
2960
// parse `for i in 1.. { }` as infinite loop, not as `for i in (1..{})`.
2961
2961
if self . token == token:: OpenDelim ( token:: Brace ) {
2962
- return !self . restrictions . contains ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL ) ;
2962
+ return !self . restrictions . contains ( RESTRICTION_NO_STRUCT_LITERAL ) ;
2963
2963
}
2964
2964
true
2965
2965
} else {
@@ -2973,7 +2973,7 @@ impl<'a> Parser<'a> {
2973
2973
return self . parse_if_let_expr ( attrs) ;
2974
2974
}
2975
2975
let lo = self . prev_span ;
2976
- let cond = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
2976
+ let cond = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
2977
2977
let thn = self . parse_block ( ) ?;
2978
2978
let mut els: Option < P < Expr > > = None ;
2979
2979
let mut hi = thn. span ;
@@ -2992,7 +2992,7 @@ impl<'a> Parser<'a> {
2992
2992
self . expect_keyword ( keywords:: Let ) ?;
2993
2993
let pat = self . parse_pat ( ) ?;
2994
2994
self . expect ( & token:: Eq ) ?;
2995
- let expr = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
2995
+ let expr = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
2996
2996
let thn = self . parse_block ( ) ?;
2997
2997
let ( hi, els) = if self . eat_keyword ( keywords:: Else ) {
2998
2998
let expr = self . parse_else_expr ( ) ?;
@@ -3046,7 +3046,7 @@ impl<'a> Parser<'a> {
3046
3046
3047
3047
let pat = self . parse_pat ( ) ?;
3048
3048
self . expect_keyword ( keywords:: In ) ?;
3049
- let expr = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3049
+ let expr = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3050
3050
let ( iattrs, loop_block) = self . parse_inner_attrs_and_block ( ) ?;
3051
3051
attrs. extend ( iattrs) ;
3052
3052
@@ -3061,7 +3061,7 @@ impl<'a> Parser<'a> {
3061
3061
if self . token . is_keyword ( keywords:: Let ) {
3062
3062
return self . parse_while_let_expr ( opt_ident, span_lo, attrs) ;
3063
3063
}
3064
- let cond = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3064
+ let cond = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3065
3065
let ( iattrs, body) = self . parse_inner_attrs_and_block ( ) ?;
3066
3066
attrs. extend ( iattrs) ;
3067
3067
let span = span_lo. to ( body. span ) ;
@@ -3075,7 +3075,7 @@ impl<'a> Parser<'a> {
3075
3075
self . expect_keyword ( keywords:: Let ) ?;
3076
3076
let pat = self . parse_pat ( ) ?;
3077
3077
self . expect ( & token:: Eq ) ?;
3078
- let expr = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3078
+ let expr = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3079
3079
let ( iattrs, body) = self . parse_inner_attrs_and_block ( ) ?;
3080
3080
attrs. extend ( iattrs) ;
3081
3081
let span = span_lo. to ( body. span ) ;
@@ -3105,7 +3105,7 @@ impl<'a> Parser<'a> {
3105
3105
fn parse_match_expr ( & mut self , mut attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
3106
3106
let match_span = self . prev_span ;
3107
3107
let lo = self . prev_span ;
3108
- let discriminant = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL ,
3108
+ let discriminant = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL ,
3109
3109
None ) ?;
3110
3110
if let Err ( mut e) = self . expect ( & token:: OpenDelim ( token:: Brace ) ) {
3111
3111
if self . token == token:: Token :: Semi {
@@ -3146,7 +3146,7 @@ impl<'a> Parser<'a> {
3146
3146
guard = Some ( self . parse_expr ( ) ?) ;
3147
3147
}
3148
3148
self . expect ( & token:: FatArrow ) ?;
3149
- let expr = self . parse_expr_res ( Restrictions :: RESTRICTION_STMT_EXPR , None ) ?;
3149
+ let expr = self . parse_expr_res ( RESTRICTION_STMT_EXPR , None ) ?;
3150
3150
3151
3151
let require_comma =
3152
3152
!classify:: expr_is_simple_block ( & expr)
@@ -3727,7 +3727,7 @@ impl<'a> Parser<'a> {
3727
3727
self . look_ahead ( 2 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
3728
3728
3729
3729
// prevent `while catch {} {}`, `if catch {} {} else {}`, etc.
3730
- !self . restrictions . contains ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL )
3730
+ !self . restrictions . contains ( RESTRICTION_NO_STRUCT_LITERAL )
3731
3731
}
3732
3732
3733
3733
fn is_union_item ( & self ) -> bool {
@@ -3799,7 +3799,7 @@ impl<'a> Parser<'a> {
3799
3799
self . mk_expr ( lo. to ( hi) , ExprKind :: Path ( None , pth) , ThinVec :: new ( ) )
3800
3800
} ;
3801
3801
3802
- let expr = self . with_res ( Restrictions :: RESTRICTION_STMT_EXPR , |this| {
3802
+ let expr = self . with_res ( RESTRICTION_STMT_EXPR , |this| {
3803
3803
let expr = this. parse_dot_or_call_expr_with ( expr, lo, attrs. into ( ) ) ?;
3804
3804
this. parse_assoc_expr_with ( 0 , LhsExpr :: AlreadyParsed ( expr) )
3805
3805
} ) ?;
@@ -3939,7 +3939,7 @@ impl<'a> Parser<'a> {
3939
3939
3940
3940
// Remainder are line-expr stmts.
3941
3941
let e = self . parse_expr_res (
3942
- Restrictions :: RESTRICTION_STMT_EXPR , Some ( attrs. into ( ) ) ) ?;
3942
+ RESTRICTION_STMT_EXPR , Some ( attrs. into ( ) ) ) ?;
3943
3943
Stmt {
3944
3944
id : ast:: DUMMY_NODE_ID ,
3945
3945
span : lo. to ( e. span ) ,
@@ -3952,7 +3952,7 @@ impl<'a> Parser<'a> {
3952
3952
3953
3953
/// Is this expression a successfully-parsed statement?
3954
3954
fn expr_is_complete ( & mut self , e : & Expr ) -> bool {
3955
- self . restrictions . contains ( Restrictions :: RESTRICTION_STMT_EXPR ) &&
3955
+ self . restrictions . contains ( RESTRICTION_STMT_EXPR ) &&
3956
3956
!classify:: expr_requires_semi_to_be_stmt ( e)
3957
3957
}
3958
3958
0 commit comments