@@ -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) ;
@@ -2735,7 +2735,7 @@ impl<'a> Parser<'a> {
2735
2735
token:: Ident ( ..) if self . token . is_keyword ( keywords:: In ) => {
2736
2736
self . bump ( ) ;
2737
2737
let place = self . parse_expr_res (
2738
- Restrictions :: RESTRICTION_NO_STRUCT_LITERAL ,
2738
+ RESTRICTION_NO_STRUCT_LITERAL ,
2739
2739
None ,
2740
2740
) ?;
2741
2741
let blk = self . parse_block ( ) ?;
@@ -2798,7 +2798,7 @@ impl<'a> Parser<'a> {
2798
2798
2799
2799
let cur_op_span = self . span ;
2800
2800
let restrictions = if op. is_assign_like ( ) {
2801
- self . restrictions & Restrictions :: RESTRICTION_NO_STRUCT_LITERAL
2801
+ self . restrictions & RESTRICTION_NO_STRUCT_LITERAL
2802
2802
} else {
2803
2803
self . restrictions
2804
2804
} ;
@@ -2848,21 +2848,21 @@ impl<'a> Parser<'a> {
2848
2848
2849
2849
let rhs = match op. fixity ( ) {
2850
2850
Fixity :: Right => self . with_res (
2851
- restrictions - Restrictions :: RESTRICTION_STMT_EXPR ,
2851
+ restrictions - RESTRICTION_STMT_EXPR ,
2852
2852
|this| {
2853
2853
this. parse_assoc_expr_with ( op. precedence ( ) ,
2854
2854
LhsExpr :: NotYetParsed )
2855
2855
} ) ,
2856
2856
Fixity :: Left => self . with_res (
2857
- restrictions - Restrictions :: RESTRICTION_STMT_EXPR ,
2857
+ restrictions - RESTRICTION_STMT_EXPR ,
2858
2858
|this| {
2859
2859
this. parse_assoc_expr_with ( op. precedence ( ) + 1 ,
2860
2860
LhsExpr :: NotYetParsed )
2861
2861
} ) ,
2862
2862
// We currently have no non-associative operators that are not handled above by
2863
2863
// the special cases. The code is here only for future convenience.
2864
2864
Fixity :: None => self . with_res (
2865
- restrictions - Restrictions :: RESTRICTION_STMT_EXPR ,
2865
+ restrictions - RESTRICTION_STMT_EXPR ,
2866
2866
|this| {
2867
2867
this. parse_assoc_expr_with ( op. precedence ( ) + 1 ,
2868
2868
LhsExpr :: NotYetParsed )
@@ -2972,7 +2972,7 @@ impl<'a> Parser<'a> {
2972
2972
if self . token . can_begin_expr ( ) {
2973
2973
// parse `for i in 1.. { }` as infinite loop, not as `for i in (1..{})`.
2974
2974
if self . token == token:: OpenDelim ( token:: Brace ) {
2975
- return !self . restrictions . contains ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL ) ;
2975
+ return !self . restrictions . contains ( RESTRICTION_NO_STRUCT_LITERAL ) ;
2976
2976
}
2977
2977
true
2978
2978
} else {
@@ -2986,7 +2986,7 @@ impl<'a> Parser<'a> {
2986
2986
return self . parse_if_let_expr ( attrs) ;
2987
2987
}
2988
2988
let lo = self . prev_span ;
2989
- let cond = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
2989
+ let cond = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
2990
2990
let thn = self . parse_block ( ) ?;
2991
2991
let mut els: Option < P < Expr > > = None ;
2992
2992
let mut hi = thn. span ;
@@ -3005,7 +3005,7 @@ impl<'a> Parser<'a> {
3005
3005
self . expect_keyword ( keywords:: Let ) ?;
3006
3006
let pat = self . parse_pat ( ) ?;
3007
3007
self . expect ( & token:: Eq ) ?;
3008
- let expr = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3008
+ let expr = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3009
3009
let thn = self . parse_block ( ) ?;
3010
3010
let ( hi, els) = if self . eat_keyword ( keywords:: Else ) {
3011
3011
let expr = self . parse_else_expr ( ) ?;
@@ -3059,7 +3059,7 @@ impl<'a> Parser<'a> {
3059
3059
3060
3060
let pat = self . parse_pat ( ) ?;
3061
3061
self . expect_keyword ( keywords:: In ) ?;
3062
- let expr = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3062
+ let expr = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3063
3063
let ( iattrs, loop_block) = self . parse_inner_attrs_and_block ( ) ?;
3064
3064
attrs. extend ( iattrs) ;
3065
3065
@@ -3074,7 +3074,7 @@ impl<'a> Parser<'a> {
3074
3074
if self . token . is_keyword ( keywords:: Let ) {
3075
3075
return self . parse_while_let_expr ( opt_ident, span_lo, attrs) ;
3076
3076
}
3077
- let cond = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3077
+ let cond = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3078
3078
let ( iattrs, body) = self . parse_inner_attrs_and_block ( ) ?;
3079
3079
attrs. extend ( iattrs) ;
3080
3080
let span = span_lo. to ( body. span ) ;
@@ -3088,7 +3088,7 @@ impl<'a> Parser<'a> {
3088
3088
self . expect_keyword ( keywords:: Let ) ?;
3089
3089
let pat = self . parse_pat ( ) ?;
3090
3090
self . expect ( & token:: Eq ) ?;
3091
- let expr = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3091
+ let expr = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL , None ) ?;
3092
3092
let ( iattrs, body) = self . parse_inner_attrs_and_block ( ) ?;
3093
3093
attrs. extend ( iattrs) ;
3094
3094
let span = span_lo. to ( body. span ) ;
@@ -3118,7 +3118,7 @@ impl<'a> Parser<'a> {
3118
3118
fn parse_match_expr ( & mut self , mut attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
3119
3119
let match_span = self . prev_span ;
3120
3120
let lo = self . prev_span ;
3121
- let discriminant = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL ,
3121
+ let discriminant = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL ,
3122
3122
None ) ?;
3123
3123
if let Err ( mut e) = self . expect ( & token:: OpenDelim ( token:: Brace ) ) {
3124
3124
if self . token == token:: Token :: Semi {
@@ -3159,7 +3159,7 @@ impl<'a> Parser<'a> {
3159
3159
guard = Some ( self . parse_expr ( ) ?) ;
3160
3160
}
3161
3161
self . expect ( & token:: FatArrow ) ?;
3162
- let expr = self . parse_expr_res ( Restrictions :: RESTRICTION_STMT_EXPR , None ) ?;
3162
+ let expr = self . parse_expr_res ( RESTRICTION_STMT_EXPR , None ) ?;
3163
3163
3164
3164
let require_comma =
3165
3165
!classify:: expr_is_simple_block ( & expr)
@@ -3740,7 +3740,7 @@ impl<'a> Parser<'a> {
3740
3740
self . look_ahead ( 2 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
3741
3741
3742
3742
// prevent `while catch {} {}`, `if catch {} {} else {}`, etc.
3743
- !self . restrictions . contains ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL )
3743
+ !self . restrictions . contains ( RESTRICTION_NO_STRUCT_LITERAL )
3744
3744
}
3745
3745
3746
3746
fn is_union_item ( & self ) -> bool {
@@ -3812,7 +3812,7 @@ impl<'a> Parser<'a> {
3812
3812
self . mk_expr ( lo. to ( hi) , ExprKind :: Path ( None , pth) , ThinVec :: new ( ) )
3813
3813
} ;
3814
3814
3815
- let expr = self . with_res ( Restrictions :: RESTRICTION_STMT_EXPR , |this| {
3815
+ let expr = self . with_res ( RESTRICTION_STMT_EXPR , |this| {
3816
3816
let expr = this. parse_dot_or_call_expr_with ( expr, lo, attrs. into ( ) ) ?;
3817
3817
this. parse_assoc_expr_with ( 0 , LhsExpr :: AlreadyParsed ( expr) )
3818
3818
} ) ?;
@@ -3952,7 +3952,7 @@ impl<'a> Parser<'a> {
3952
3952
3953
3953
// Remainder are line-expr stmts.
3954
3954
let e = self . parse_expr_res (
3955
- Restrictions :: RESTRICTION_STMT_EXPR , Some ( attrs. into ( ) ) ) ?;
3955
+ RESTRICTION_STMT_EXPR , Some ( attrs. into ( ) ) ) ?;
3956
3956
Stmt {
3957
3957
id : ast:: DUMMY_NODE_ID ,
3958
3958
span : lo. to ( e. span ) ,
@@ -3965,7 +3965,7 @@ impl<'a> Parser<'a> {
3965
3965
3966
3966
/// Is this expression a successfully-parsed statement?
3967
3967
fn expr_is_complete ( & mut self , e : & Expr ) -> bool {
3968
- self . restrictions . contains ( Restrictions :: RESTRICTION_STMT_EXPR ) &&
3968
+ self . restrictions . contains ( RESTRICTION_STMT_EXPR ) &&
3969
3969
!classify:: expr_requires_semi_to_be_stmt ( e)
3970
3970
}
3971
3971
0 commit comments