@@ -1833,7 +1833,7 @@ impl<'a> Parser<'a> {
1833
1833
Ok ( MutTy { ty : t, mutbl : mutbl } )
1834
1834
}
1835
1835
1836
- fn is_named_argument ( & mut self ) -> bool {
1836
+ fn is_named_argument ( & self ) -> bool {
1837
1837
let offset = match self . token {
1838
1838
token:: Interpolated ( ref nt) => match * * nt {
1839
1839
token:: NtPat ( ..) => return self . look_ahead ( 1 , |t| t == & token:: Colon ) ,
@@ -1881,8 +1881,6 @@ impl<'a> Parser<'a> {
1881
1881
/// This version of parse arg doesn't necessarily require identifier names.
1882
1882
fn parse_arg_general ( & mut self , require_name : bool , is_trait_item : bool ,
1883
1883
allow_c_variadic : bool ) -> PResult < ' a , Arg > {
1884
- maybe_whole ! ( self , NtArg , |x| x) ;
1885
-
1886
1884
if let Ok ( Some ( _) ) = self . parse_self_arg ( ) {
1887
1885
let mut err = self . struct_span_err ( self . prev_span ,
1888
1886
"unexpected `self` argument in function" ) ;
@@ -2345,27 +2343,27 @@ impl<'a> Parser<'a> {
2345
2343
} )
2346
2344
}
2347
2345
2348
- fn mk_expr ( & mut self , span : Span , node : ExprKind , attrs : ThinVec < Attribute > ) -> P < Expr > {
2346
+ fn mk_expr ( & self , span : Span , node : ExprKind , attrs : ThinVec < Attribute > ) -> P < Expr > {
2349
2347
P ( Expr { node, span, attrs, id : ast:: DUMMY_NODE_ID } )
2350
2348
}
2351
2349
2352
- fn mk_unary ( & mut self , unop : ast:: UnOp , expr : P < Expr > ) -> ast:: ExprKind {
2350
+ fn mk_unary ( & self , unop : ast:: UnOp , expr : P < Expr > ) -> ast:: ExprKind {
2353
2351
ExprKind :: Unary ( unop, expr)
2354
2352
}
2355
2353
2356
- fn mk_binary ( & mut self , binop : ast:: BinOp , lhs : P < Expr > , rhs : P < Expr > ) -> ast:: ExprKind {
2354
+ fn mk_binary ( & self , binop : ast:: BinOp , lhs : P < Expr > , rhs : P < Expr > ) -> ast:: ExprKind {
2357
2355
ExprKind :: Binary ( binop, lhs, rhs)
2358
2356
}
2359
2357
2360
- fn mk_call ( & mut self , f : P < Expr > , args : Vec < P < Expr > > ) -> ast:: ExprKind {
2358
+ fn mk_call ( & self , f : P < Expr > , args : Vec < P < Expr > > ) -> ast:: ExprKind {
2361
2359
ExprKind :: Call ( f, args)
2362
2360
}
2363
2361
2364
- fn mk_index ( & mut self , expr : P < Expr > , idx : P < Expr > ) -> ast:: ExprKind {
2362
+ fn mk_index ( & self , expr : P < Expr > , idx : P < Expr > ) -> ast:: ExprKind {
2365
2363
ExprKind :: Index ( expr, idx)
2366
2364
}
2367
2365
2368
- fn mk_range ( & mut self ,
2366
+ fn mk_range ( & self ,
2369
2367
start : Option < P < Expr > > ,
2370
2368
end : Option < P < Expr > > ,
2371
2369
limits : RangeLimits )
@@ -2377,7 +2375,7 @@ impl<'a> Parser<'a> {
2377
2375
}
2378
2376
}
2379
2377
2380
- fn mk_assign_op ( & mut self , binop : ast:: BinOp ,
2378
+ fn mk_assign_op ( & self , binop : ast:: BinOp ,
2381
2379
lhs : P < Expr > , rhs : P < Expr > ) -> ast:: ExprKind {
2382
2380
ExprKind :: AssignOp ( binop, lhs, rhs)
2383
2381
}
@@ -2517,13 +2515,12 @@ impl<'a> Parser<'a> {
2517
2515
hi = path. span ;
2518
2516
return Ok ( self . mk_expr ( lo. to ( hi) , ExprKind :: Path ( Some ( qself) , path) , attrs) ) ;
2519
2517
}
2520
- if self . span . rust_2018 ( ) && self . check_keyword ( keywords:: Async )
2521
- {
2522
- if self . is_async_block ( ) { // check for `async {` and `async move {`
2523
- return self . parse_async_block ( attrs) ;
2518
+ if self . span . rust_2018 ( ) && self . check_keyword ( keywords:: Async ) {
2519
+ return if self . is_async_block ( ) { // check for `async {` and `async move {`
2520
+ self . parse_async_block ( attrs)
2524
2521
} else {
2525
- return self . parse_lambda_expr ( attrs) ;
2526
- }
2522
+ self . parse_lambda_expr ( attrs)
2523
+ } ;
2527
2524
}
2528
2525
if self . check_keyword ( keywords:: Move ) || self . check_keyword ( keywords:: Static ) {
2529
2526
return self . parse_lambda_expr ( attrs) ;
@@ -3448,7 +3445,8 @@ impl<'a> Parser<'a> {
3448
3445
} else {
3449
3446
self . restrictions
3450
3447
} ;
3451
- if op. precedence ( ) < min_prec {
3448
+ let prec = op. precedence ( ) ;
3449
+ if prec < min_prec {
3452
3450
break ;
3453
3451
}
3454
3452
// Check for deprecated `...` syntax
@@ -3489,8 +3487,7 @@ impl<'a> Parser<'a> {
3489
3487
// We have 2 alternatives here: `x..y`/`x..=y` and `x..`/`x..=` The other
3490
3488
// two variants are handled with `parse_prefix_range_expr` call above.
3491
3489
let rhs = if self . is_at_start_of_range_notation_rhs ( ) {
3492
- Some ( self . parse_assoc_expr_with ( op. precedence ( ) + 1 ,
3493
- LhsExpr :: NotYetParsed ) ?)
3490
+ Some ( self . parse_assoc_expr_with ( prec + 1 , LhsExpr :: NotYetParsed ) ?)
3494
3491
} else {
3495
3492
None
3496
3493
} ;
@@ -3510,28 +3507,18 @@ impl<'a> Parser<'a> {
3510
3507
break
3511
3508
}
3512
3509
3513
- let rhs = match op. fixity ( ) {
3514
- Fixity :: Right => self . with_res (
3515
- restrictions - Restrictions :: STMT_EXPR ,
3516
- |this| {
3517
- this. parse_assoc_expr_with ( op. precedence ( ) ,
3518
- LhsExpr :: NotYetParsed )
3519
- } ) ,
3520
- Fixity :: Left => self . with_res (
3521
- restrictions - Restrictions :: STMT_EXPR ,
3522
- |this| {
3523
- this. parse_assoc_expr_with ( op. precedence ( ) + 1 ,
3524
- LhsExpr :: NotYetParsed )
3525
- } ) ,
3510
+ let fixity = op. fixity ( ) ;
3511
+ let prec_adjustment = match fixity {
3512
+ Fixity :: Right => 0 ,
3513
+ Fixity :: Left => 1 ,
3526
3514
// We currently have no non-associative operators that are not handled above by
3527
3515
// the special cases. The code is here only for future convenience.
3528
- Fixity :: None => self . with_res (
3529
- restrictions - Restrictions :: STMT_EXPR ,
3530
- |this| {
3531
- this. parse_assoc_expr_with ( op. precedence ( ) + 1 ,
3532
- LhsExpr :: NotYetParsed )
3533
- } ) ,
3534
- } ?;
3516
+ Fixity :: None => 1 ,
3517
+ } ;
3518
+ let rhs = self . with_res (
3519
+ restrictions - Restrictions :: STMT_EXPR ,
3520
+ |this| this. parse_assoc_expr_with ( prec + prec_adjustment, LhsExpr :: NotYetParsed )
3521
+ ) ?;
3535
3522
3536
3523
// Make sure that the span of the parent node is larger than the span of lhs and rhs,
3537
3524
// including the attributes.
@@ -3577,7 +3564,7 @@ impl<'a> Parser<'a> {
3577
3564
}
3578
3565
} ;
3579
3566
3580
- if op . fixity ( ) == Fixity :: None { break }
3567
+ if let Fixity :: None = fixity { break }
3581
3568
}
3582
3569
Ok ( lhs)
3583
3570
}
@@ -3714,7 +3701,7 @@ impl<'a> Parser<'a> {
3714
3701
/// Produce an error if comparison operators are chained (RFC #558).
3715
3702
/// We only need to check lhs, not rhs, because all comparison ops
3716
3703
/// have same precedence and are left-associative
3717
- fn check_no_chained_comparison ( & mut self , lhs : & Expr , outer_op : & AssocOp ) {
3704
+ fn check_no_chained_comparison ( & self , lhs : & Expr , outer_op : & AssocOp ) {
3718
3705
debug_assert ! ( outer_op. is_comparison( ) ,
3719
3706
"check_no_chained_comparison: {:?} is not comparison" ,
3720
3707
outer_op) ;
@@ -4053,8 +4040,6 @@ impl<'a> Parser<'a> {
4053
4040
}
4054
4041
4055
4042
crate fn parse_arm ( & mut self ) -> PResult < ' a , Arm > {
4056
- maybe_whole ! ( self , NtArm , |x| x) ;
4057
-
4058
4043
let attrs = self . parse_outer_attributes ( ) ?;
4059
4044
let pats = self . parse_pats ( ) ?;
4060
4045
let guard = if self . eat_keyword ( keywords:: If ) {
@@ -5011,7 +4996,7 @@ impl<'a> Parser<'a> {
5011
4996
} )
5012
4997
}
5013
4998
5014
- fn is_async_block ( & mut self ) -> bool {
4999
+ fn is_async_block ( & self ) -> bool {
5015
5000
self . token . is_keyword ( keywords:: Async ) &&
5016
5001
(
5017
5002
( // `async move {`
@@ -5023,19 +5008,19 @@ impl<'a> Parser<'a> {
5023
5008
)
5024
5009
}
5025
5010
5026
- fn is_async_fn ( & mut self ) -> bool {
5011
+ fn is_async_fn ( & self ) -> bool {
5027
5012
self . token . is_keyword ( keywords:: Async ) &&
5028
5013
self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Fn ) )
5029
5014
}
5030
5015
5031
- fn is_do_catch_block ( & mut self ) -> bool {
5016
+ fn is_do_catch_block ( & self ) -> bool {
5032
5017
self . token . is_keyword ( keywords:: Do ) &&
5033
5018
self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Catch ) ) &&
5034
5019
self . look_ahead ( 2 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
5035
5020
!self . restrictions . contains ( Restrictions :: NO_STRUCT_LITERAL )
5036
5021
}
5037
5022
5038
- fn is_try_block ( & mut self ) -> bool {
5023
+ fn is_try_block ( & self ) -> bool {
5039
5024
self . token . is_keyword ( keywords:: Try ) &&
5040
5025
self . look_ahead ( 1 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
5041
5026
self . span . rust_2018 ( ) &&
@@ -5057,7 +5042,7 @@ impl<'a> Parser<'a> {
5057
5042
self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Type ) )
5058
5043
}
5059
5044
5060
- fn is_auto_trait_item ( & mut self ) -> bool {
5045
+ fn is_auto_trait_item ( & self ) -> bool {
5061
5046
// auto trait
5062
5047
( self . token . is_keyword ( keywords:: Auto )
5063
5048
&& self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Trait ) ) )
@@ -5319,7 +5304,7 @@ impl<'a> Parser<'a> {
5319
5304
}
5320
5305
5321
5306
/// Checks if this expression is a successfully parsed statement.
5322
- fn expr_is_complete ( & mut self , e : & Expr ) -> bool {
5307
+ fn expr_is_complete ( & self , e : & Expr ) -> bool {
5323
5308
self . restrictions . contains ( Restrictions :: STMT_EXPR ) &&
5324
5309
!classify:: expr_requires_semi_to_be_stmt ( e)
5325
5310
}
@@ -5789,8 +5774,6 @@ impl<'a> Parser<'a> {
5789
5774
/// | ( < lifetimes , typaramseq ( , )? > )
5790
5775
/// where typaramseq = ( typaram ) | ( typaram , typaramseq )
5791
5776
fn parse_generics ( & mut self ) -> PResult < ' a , ast:: Generics > {
5792
- maybe_whole ! ( self , NtGenerics , |x| x) ;
5793
-
5794
5777
let span_lo = self . span ;
5795
5778
if self . eat_lt ( ) {
5796
5779
let params = self . parse_generic_params ( ) ?;
@@ -6043,8 +6026,6 @@ impl<'a> Parser<'a> {
6043
6026
/// where T : Trait<U, V> + 'b, 'a : 'b
6044
6027
/// ```
6045
6028
fn parse_where_clause ( & mut self ) -> PResult < ' a , WhereClause > {
6046
- maybe_whole ! ( self , NtWhereClause , |x| x) ;
6047
-
6048
6029
let mut where_clause = WhereClause {
6049
6030
id : ast:: DUMMY_NODE_ID ,
6050
6031
predicates : Vec :: new ( ) ,
@@ -6391,7 +6372,7 @@ impl<'a> Parser<'a> {
6391
6372
Ok ( ( id, generics) )
6392
6373
}
6393
6374
6394
- fn mk_item ( & mut self , span : Span , ident : Ident , node : ItemKind , vis : Visibility ,
6375
+ fn mk_item ( & self , span : Span , ident : Ident , node : ItemKind , vis : Visibility ,
6395
6376
attrs : Vec < Attribute > ) -> P < Item > {
6396
6377
P ( Item {
6397
6378
ident,
@@ -6423,7 +6404,7 @@ impl<'a> Parser<'a> {
6423
6404
6424
6405
/// Returns `true` if we are looking at `const ID`
6425
6406
/// (returns `false` for things like `const fn`, etc.).
6426
- fn is_const_item ( & mut self ) -> bool {
6407
+ fn is_const_item ( & self ) -> bool {
6427
6408
self . token . is_keyword ( keywords:: Const ) &&
6428
6409
!self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Fn ) ) &&
6429
6410
!self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Unsafe ) )
@@ -6531,7 +6512,7 @@ impl<'a> Parser<'a> {
6531
6512
} )
6532
6513
}
6533
6514
6534
- fn complain_if_pub_macro ( & mut self , vis : & VisibilityKind , sp : Span ) {
6515
+ fn complain_if_pub_macro ( & self , vis : & VisibilityKind , sp : Span ) {
6535
6516
match * vis {
6536
6517
VisibilityKind :: Inherited => { }
6537
6518
_ => {
@@ -6560,7 +6541,7 @@ impl<'a> Parser<'a> {
6560
6541
}
6561
6542
}
6562
6543
6563
- fn missing_assoc_item_kind_err ( & mut self , item_type : & str , prev_span : Span )
6544
+ fn missing_assoc_item_kind_err ( & self , item_type : & str , prev_span : Span )
6564
6545
-> DiagnosticBuilder < ' a >
6565
6546
{
6566
6547
let expected_kinds = if item_type == "extern" {
0 commit comments