@@ -1833,7 +1833,7 @@ impl<'a> Parser<'a> {
18331833 Ok ( MutTy { ty : t, mutbl : mutbl } )
18341834 }
18351835
1836- fn is_named_argument ( & mut self ) -> bool {
1836+ fn is_named_argument ( & self ) -> bool {
18371837 let offset = match self . token {
18381838 token:: Interpolated ( ref nt) => match * * nt {
18391839 token:: NtPat ( ..) => return self . look_ahead ( 1 , |t| t == & token:: Colon ) ,
@@ -1881,8 +1881,6 @@ impl<'a> Parser<'a> {
18811881 /// This version of parse arg doesn't necessarily require identifier names.
18821882 fn parse_arg_general ( & mut self , require_name : bool , is_trait_item : bool ,
18831883 allow_c_variadic : bool ) -> PResult < ' a , Arg > {
1884- maybe_whole ! ( self , NtArg , |x| x) ;
1885-
18861884 if let Ok ( Some ( _) ) = self . parse_self_arg ( ) {
18871885 let mut err = self . struct_span_err ( self . prev_span ,
18881886 "unexpected `self` argument in function" ) ;
@@ -2345,27 +2343,27 @@ impl<'a> Parser<'a> {
23452343 } )
23462344 }
23472345
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 > {
23492347 P ( Expr { node, span, attrs, id : ast:: DUMMY_NODE_ID } )
23502348 }
23512349
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 {
23532351 ExprKind :: Unary ( unop, expr)
23542352 }
23552353
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 {
23572355 ExprKind :: Binary ( binop, lhs, rhs)
23582356 }
23592357
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 {
23612359 ExprKind :: Call ( f, args)
23622360 }
23632361
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 {
23652363 ExprKind :: Index ( expr, idx)
23662364 }
23672365
2368- fn mk_range ( & mut self ,
2366+ fn mk_range ( & self ,
23692367 start : Option < P < Expr > > ,
23702368 end : Option < P < Expr > > ,
23712369 limits : RangeLimits )
@@ -2377,7 +2375,7 @@ impl<'a> Parser<'a> {
23772375 }
23782376 }
23792377
2380- fn mk_assign_op ( & mut self , binop : ast:: BinOp ,
2378+ fn mk_assign_op ( & self , binop : ast:: BinOp ,
23812379 lhs : P < Expr > , rhs : P < Expr > ) -> ast:: ExprKind {
23822380 ExprKind :: AssignOp ( binop, lhs, rhs)
23832381 }
@@ -2517,13 +2515,12 @@ impl<'a> Parser<'a> {
25172515 hi = path. span ;
25182516 return Ok ( self . mk_expr ( lo. to ( hi) , ExprKind :: Path ( Some ( qself) , path) , attrs) ) ;
25192517 }
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)
25242521 } else {
2525- return self . parse_lambda_expr ( attrs) ;
2526- }
2522+ self . parse_lambda_expr ( attrs)
2523+ } ;
25272524 }
25282525 if self . check_keyword ( keywords:: Move ) || self . check_keyword ( keywords:: Static ) {
25292526 return self . parse_lambda_expr ( attrs) ;
@@ -3448,7 +3445,8 @@ impl<'a> Parser<'a> {
34483445 } else {
34493446 self . restrictions
34503447 } ;
3451- if op. precedence ( ) < min_prec {
3448+ let prec = op. precedence ( ) ;
3449+ if prec < min_prec {
34523450 break ;
34533451 }
34543452 // Check for deprecated `...` syntax
@@ -3489,8 +3487,7 @@ impl<'a> Parser<'a> {
34893487 // We have 2 alternatives here: `x..y`/`x..=y` and `x..`/`x..=` The other
34903488 // two variants are handled with `parse_prefix_range_expr` call above.
34913489 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 ) ?)
34943491 } else {
34953492 None
34963493 } ;
@@ -3510,28 +3507,18 @@ impl<'a> Parser<'a> {
35103507 break
35113508 }
35123509
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 ,
35263514 // We currently have no non-associative operators that are not handled above by
35273515 // 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+ ) ?;
35353522
35363523 // Make sure that the span of the parent node is larger than the span of lhs and rhs,
35373524 // including the attributes.
@@ -3577,7 +3564,7 @@ impl<'a> Parser<'a> {
35773564 }
35783565 } ;
35793566
3580- if op . fixity ( ) == Fixity :: None { break }
3567+ if let Fixity :: None = fixity { break }
35813568 }
35823569 Ok ( lhs)
35833570 }
@@ -3714,7 +3701,7 @@ impl<'a> Parser<'a> {
37143701 /// Produce an error if comparison operators are chained (RFC #558).
37153702 /// We only need to check lhs, not rhs, because all comparison ops
37163703 /// 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 ) {
37183705 debug_assert ! ( outer_op. is_comparison( ) ,
37193706 "check_no_chained_comparison: {:?} is not comparison" ,
37203707 outer_op) ;
@@ -4053,8 +4040,6 @@ impl<'a> Parser<'a> {
40534040 }
40544041
40554042 crate fn parse_arm ( & mut self ) -> PResult < ' a , Arm > {
4056- maybe_whole ! ( self , NtArm , |x| x) ;
4057-
40584043 let attrs = self . parse_outer_attributes ( ) ?;
40594044 let pats = self . parse_pats ( ) ?;
40604045 let guard = if self . eat_keyword ( keywords:: If ) {
@@ -5011,7 +4996,7 @@ impl<'a> Parser<'a> {
50114996 } )
50124997 }
50134998
5014- fn is_async_block ( & mut self ) -> bool {
4999+ fn is_async_block ( & self ) -> bool {
50155000 self . token . is_keyword ( keywords:: Async ) &&
50165001 (
50175002 ( // `async move {`
@@ -5023,19 +5008,19 @@ impl<'a> Parser<'a> {
50235008 )
50245009 }
50255010
5026- fn is_async_fn ( & mut self ) -> bool {
5011+ fn is_async_fn ( & self ) -> bool {
50275012 self . token . is_keyword ( keywords:: Async ) &&
50285013 self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Fn ) )
50295014 }
50305015
5031- fn is_do_catch_block ( & mut self ) -> bool {
5016+ fn is_do_catch_block ( & self ) -> bool {
50325017 self . token . is_keyword ( keywords:: Do ) &&
50335018 self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Catch ) ) &&
50345019 self . look_ahead ( 2 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
50355020 !self . restrictions . contains ( Restrictions :: NO_STRUCT_LITERAL )
50365021 }
50375022
5038- fn is_try_block ( & mut self ) -> bool {
5023+ fn is_try_block ( & self ) -> bool {
50395024 self . token . is_keyword ( keywords:: Try ) &&
50405025 self . look_ahead ( 1 , |t| * t == token:: OpenDelim ( token:: Brace ) ) &&
50415026 self . span . rust_2018 ( ) &&
@@ -5057,7 +5042,7 @@ impl<'a> Parser<'a> {
50575042 self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Type ) )
50585043 }
50595044
5060- fn is_auto_trait_item ( & mut self ) -> bool {
5045+ fn is_auto_trait_item ( & self ) -> bool {
50615046 // auto trait
50625047 ( self . token . is_keyword ( keywords:: Auto )
50635048 && self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Trait ) ) )
@@ -5319,7 +5304,7 @@ impl<'a> Parser<'a> {
53195304 }
53205305
53215306 /// 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 {
53235308 self . restrictions . contains ( Restrictions :: STMT_EXPR ) &&
53245309 !classify:: expr_requires_semi_to_be_stmt ( e)
53255310 }
@@ -5789,8 +5774,6 @@ impl<'a> Parser<'a> {
57895774 /// | ( < lifetimes , typaramseq ( , )? > )
57905775 /// where typaramseq = ( typaram ) | ( typaram , typaramseq )
57915776 fn parse_generics ( & mut self ) -> PResult < ' a , ast:: Generics > {
5792- maybe_whole ! ( self , NtGenerics , |x| x) ;
5793-
57945777 let span_lo = self . span ;
57955778 if self . eat_lt ( ) {
57965779 let params = self . parse_generic_params ( ) ?;
@@ -6043,8 +6026,6 @@ impl<'a> Parser<'a> {
60436026 /// where T : Trait<U, V> + 'b, 'a : 'b
60446027 /// ```
60456028 fn parse_where_clause ( & mut self ) -> PResult < ' a , WhereClause > {
6046- maybe_whole ! ( self , NtWhereClause , |x| x) ;
6047-
60486029 let mut where_clause = WhereClause {
60496030 id : ast:: DUMMY_NODE_ID ,
60506031 predicates : Vec :: new ( ) ,
@@ -6391,7 +6372,7 @@ impl<'a> Parser<'a> {
63916372 Ok ( ( id, generics) )
63926373 }
63936374
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 ,
63956376 attrs : Vec < Attribute > ) -> P < Item > {
63966377 P ( Item {
63976378 ident,
@@ -6423,7 +6404,7 @@ impl<'a> Parser<'a> {
64236404
64246405 /// Returns `true` if we are looking at `const ID`
64256406 /// (returns `false` for things like `const fn`, etc.).
6426- fn is_const_item ( & mut self ) -> bool {
6407+ fn is_const_item ( & self ) -> bool {
64276408 self . token . is_keyword ( keywords:: Const ) &&
64286409 !self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Fn ) ) &&
64296410 !self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Unsafe ) )
@@ -6531,7 +6512,7 @@ impl<'a> Parser<'a> {
65316512 } )
65326513 }
65336514
6534- fn complain_if_pub_macro ( & mut self , vis : & VisibilityKind , sp : Span ) {
6515+ fn complain_if_pub_macro ( & self , vis : & VisibilityKind , sp : Span ) {
65356516 match * vis {
65366517 VisibilityKind :: Inherited => { }
65376518 _ => {
@@ -6560,7 +6541,7 @@ impl<'a> Parser<'a> {
65606541 }
65616542 }
65626543
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 )
65646545 -> DiagnosticBuilder < ' a >
65656546 {
65666547 let expected_kinds = if item_type == "extern" {
0 commit comments