@@ -1877,7 +1877,7 @@ impl<'a> Parser<'a> {
1877
1877
Ok(MutTy { ty: t, mutbl: mutbl })
1878
1878
}
1879
1879
1880
- fn is_named_argument(&mut self) -> bool {
1880
+ fn is_named_argument(&self) -> bool {
1881
1881
let offset = match self.token {
1882
1882
token::Interpolated(ref nt) => match **nt {
1883
1883
token::NtPat(..) => return self.look_ahead(1, |t| t == &token::Colon),
@@ -2469,27 +2469,27 @@ impl<'a> Parser<'a> {
2469
2469
})
2470
2470
}
2471
2471
2472
- fn mk_expr(&mut self, span: Span, node: ExprKind, attrs: ThinVec<Attribute>) -> P<Expr> {
2472
+ fn mk_expr(&self, span: Span, node: ExprKind, attrs: ThinVec<Attribute>) -> P<Expr> {
2473
2473
P(Expr { node, span, attrs, id: ast::DUMMY_NODE_ID })
2474
2474
}
2475
2475
2476
- fn mk_unary(&mut self, unop: ast::UnOp, expr: P<Expr>) -> ast::ExprKind {
2476
+ fn mk_unary(&self, unop: ast::UnOp, expr: P<Expr>) -> ast::ExprKind {
2477
2477
ExprKind::Unary(unop, expr)
2478
2478
}
2479
2479
2480
- fn mk_binary(&mut self, binop: ast::BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ast::ExprKind {
2480
+ fn mk_binary(&self, binop: ast::BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ast::ExprKind {
2481
2481
ExprKind::Binary(binop, lhs, rhs)
2482
2482
}
2483
2483
2484
- fn mk_call(&mut self, f: P<Expr>, args: Vec<P<Expr>>) -> ast::ExprKind {
2484
+ fn mk_call(&self, f: P<Expr>, args: Vec<P<Expr>>) -> ast::ExprKind {
2485
2485
ExprKind::Call(f, args)
2486
2486
}
2487
2487
2488
- fn mk_index(&mut self, expr: P<Expr>, idx: P<Expr>) -> ast::ExprKind {
2488
+ fn mk_index(&self, expr: P<Expr>, idx: P<Expr>) -> ast::ExprKind {
2489
2489
ExprKind::Index(expr, idx)
2490
2490
}
2491
2491
2492
- fn mk_range(&mut self,
2492
+ fn mk_range(&self,
2493
2493
start: Option<P<Expr>>,
2494
2494
end: Option<P<Expr>>,
2495
2495
limits: RangeLimits)
@@ -2501,7 +2501,7 @@ impl<'a> Parser<'a> {
2501
2501
}
2502
2502
}
2503
2503
2504
- fn mk_assign_op(&mut self, binop: ast::BinOp,
2504
+ fn mk_assign_op(&self, binop: ast::BinOp,
2505
2505
lhs: P<Expr>, rhs: P<Expr>) -> ast::ExprKind {
2506
2506
ExprKind::AssignOp(binop, lhs, rhs)
2507
2507
}
@@ -2641,13 +2641,12 @@ impl<'a> Parser<'a> {
2641
2641
hi = path.span;
2642
2642
return Ok(self.mk_expr(lo.to(hi), ExprKind::Path(Some(qself), path), attrs));
2643
2643
}
2644
- if self.span.rust_2018() && self.check_keyword(keywords::Async)
2645
- {
2646
- if self.is_async_block() { // check for `async {` and `async move {`
2647
- return self.parse_async_block(attrs);
2644
+ if self.span.rust_2018() && self.check_keyword(keywords::Async) {
2645
+ return if self.is_async_block() { // check for `async {` and `async move {`
2646
+ self.parse_async_block(attrs)
2648
2647
} else {
2649
- return self.parse_lambda_expr(attrs);
2650
- }
2648
+ self.parse_lambda_expr(attrs)
2649
+ };
2651
2650
}
2652
2651
if self.check_keyword(keywords::Move) || self.check_keyword(keywords::Static) {
2653
2652
return self.parse_lambda_expr(attrs);
@@ -3572,7 +3571,8 @@ impl<'a> Parser<'a> {
3572
3571
} else {
3573
3572
self.restrictions
3574
3573
};
3575
- if op.precedence() < min_prec {
3574
+ let prec = op.precedence();
3575
+ if prec < min_prec {
3576
3576
break;
3577
3577
}
3578
3578
// Check for deprecated `...` syntax
@@ -3613,8 +3613,7 @@ impl<'a> Parser<'a> {
3613
3613
// We have 2 alternatives here: `x..y`/`x..=y` and `x..`/`x..=` The other
3614
3614
// two variants are handled with `parse_prefix_range_expr` call above.
3615
3615
let rhs = if self.is_at_start_of_range_notation_rhs() {
3616
- Some(self.parse_assoc_expr_with(op.precedence() + 1,
3617
- LhsExpr::NotYetParsed)?)
3616
+ Some(self.parse_assoc_expr_with(prec + 1, LhsExpr::NotYetParsed)?)
3618
3617
} else {
3619
3618
None
3620
3619
};
@@ -3634,28 +3633,18 @@ impl<'a> Parser<'a> {
3634
3633
break
3635
3634
}
3636
3635
3637
- let rhs = match op.fixity() {
3638
- Fixity::Right => self.with_res(
3639
- restrictions - Restrictions::STMT_EXPR,
3640
- |this| {
3641
- this.parse_assoc_expr_with(op.precedence(),
3642
- LhsExpr::NotYetParsed)
3643
- }),
3644
- Fixity::Left => self.with_res(
3645
- restrictions - Restrictions::STMT_EXPR,
3646
- |this| {
3647
- this.parse_assoc_expr_with(op.precedence() + 1,
3648
- LhsExpr::NotYetParsed)
3649
- }),
3636
+ let fixity = op.fixity();
3637
+ let prec_adjustment = match fixity {
3638
+ Fixity::Right => 0,
3639
+ Fixity::Left => 1,
3650
3640
// We currently have no non-associative operators that are not handled above by
3651
3641
// the special cases. The code is here only for future convenience.
3652
- Fixity::None => self.with_res(
3653
- restrictions - Restrictions::STMT_EXPR,
3654
- |this| {
3655
- this.parse_assoc_expr_with(op.precedence() + 1,
3656
- LhsExpr::NotYetParsed)
3657
- }),
3658
- }?;
3642
+ Fixity::None => 1,
3643
+ };
3644
+ let rhs = self.with_res(
3645
+ restrictions - Restrictions::STMT_EXPR,
3646
+ |this| this.parse_assoc_expr_with(prec + prec_adjustment, LhsExpr::NotYetParsed)
3647
+ )?;
3659
3648
3660
3649
// Make sure that the span of the parent node is larger than the span of lhs and rhs,
3661
3650
// including the attributes.
@@ -3701,7 +3690,7 @@ impl<'a> Parser<'a> {
3701
3690
}
3702
3691
};
3703
3692
3704
- if op.fixity() == Fixity::None { break }
3693
+ if let Fixity::None = fixity { break }
3705
3694
}
3706
3695
Ok(lhs)
3707
3696
}
@@ -3838,7 +3827,7 @@ impl<'a> Parser<'a> {
3838
3827
/// Produce an error if comparison operators are chained (RFC #558).
3839
3828
/// We only need to check lhs, not rhs, because all comparison ops
3840
3829
/// have same precedence and are left-associative
3841
- fn check_no_chained_comparison(&mut self, lhs: &Expr, outer_op: &AssocOp) {
3830
+ fn check_no_chained_comparison(&self, lhs: &Expr, outer_op: &AssocOp) {
3842
3831
debug_assert!(outer_op.is_comparison(),
3843
3832
"check_no_chained_comparison: {:?} is not comparison",
3844
3833
outer_op);
@@ -5133,7 +5122,7 @@ impl<'a> Parser<'a> {
5133
5122
})
5134
5123
}
5135
5124
5136
- fn is_async_block(&mut self) -> bool {
5125
+ fn is_async_block(&self) -> bool {
5137
5126
self.token.is_keyword(keywords::Async) &&
5138
5127
(
5139
5128
( // `async move {`
@@ -5145,19 +5134,19 @@ impl<'a> Parser<'a> {
5145
5134
)
5146
5135
}
5147
5136
5148
- fn is_async_fn(&mut self) -> bool {
5137
+ fn is_async_fn(&self) -> bool {
5149
5138
self.token.is_keyword(keywords::Async) &&
5150
5139
self.look_ahead(1, |t| t.is_keyword(keywords::Fn))
5151
5140
}
5152
5141
5153
- fn is_do_catch_block(&mut self) -> bool {
5142
+ fn is_do_catch_block(&self) -> bool {
5154
5143
self.token.is_keyword(keywords::Do) &&
5155
5144
self.look_ahead(1, |t| t.is_keyword(keywords::Catch)) &&
5156
5145
self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace)) &&
5157
5146
!self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL)
5158
5147
}
5159
5148
5160
- fn is_try_block(&mut self) -> bool {
5149
+ fn is_try_block(&self) -> bool {
5161
5150
self.token.is_keyword(keywords::Try) &&
5162
5151
self.look_ahead(1, |t| *t == token::OpenDelim(token::Brace)) &&
5163
5152
self.span.rust_2018() &&
@@ -5179,7 +5168,7 @@ impl<'a> Parser<'a> {
5179
5168
self.look_ahead(1, |t| t.is_keyword(keywords::Type))
5180
5169
}
5181
5170
5182
- fn is_auto_trait_item(&mut self) -> bool {
5171
+ fn is_auto_trait_item(&self) -> bool {
5183
5172
// auto trait
5184
5173
(self.token.is_keyword(keywords::Auto)
5185
5174
&& self.look_ahead(1, |t| t.is_keyword(keywords::Trait)))
@@ -5441,7 +5430,7 @@ impl<'a> Parser<'a> {
5441
5430
}
5442
5431
5443
5432
/// Checks if this expression is a successfully parsed statement.
5444
- fn expr_is_complete(&mut self, e: &Expr) -> bool {
5433
+ fn expr_is_complete(&self, e: &Expr) -> bool {
5445
5434
self.restrictions.contains(Restrictions::STMT_EXPR) &&
5446
5435
!classify::expr_requires_semi_to_be_stmt(e)
5447
5436
}
@@ -6509,7 +6498,7 @@ impl<'a> Parser<'a> {
6509
6498
Ok((id, generics))
6510
6499
}
6511
6500
6512
- fn mk_item(&mut self, span: Span, ident: Ident, node: ItemKind, vis: Visibility,
6501
+ fn mk_item(&self, span: Span, ident: Ident, node: ItemKind, vis: Visibility,
6513
6502
attrs: Vec<Attribute>) -> P<Item> {
6514
6503
P(Item {
6515
6504
ident,
@@ -6541,7 +6530,7 @@ impl<'a> Parser<'a> {
6541
6530
6542
6531
/// Returns `true` if we are looking at `const ID`
6543
6532
/// (returns `false` for things like `const fn`, etc.).
6544
- fn is_const_item(&mut self) -> bool {
6533
+ fn is_const_item(&self) -> bool {
6545
6534
self.token.is_keyword(keywords::Const) &&
6546
6535
!self.look_ahead(1, |t| t.is_keyword(keywords::Fn)) &&
6547
6536
!self.look_ahead(1, |t| t.is_keyword(keywords::Unsafe))
@@ -6649,7 +6638,7 @@ impl<'a> Parser<'a> {
6649
6638
})
6650
6639
}
6651
6640
6652
- fn complain_if_pub_macro(&mut self, vis: &VisibilityKind, sp: Span) {
6641
+ fn complain_if_pub_macro(&self, vis: &VisibilityKind, sp: Span) {
6653
6642
match *vis {
6654
6643
VisibilityKind::Inherited => {}
6655
6644
_ => {
@@ -6678,7 +6667,7 @@ impl<'a> Parser<'a> {
6678
6667
}
6679
6668
}
6680
6669
6681
- fn missing_assoc_item_kind_err(&mut self, item_type: &str, prev_span: Span)
6670
+ fn missing_assoc_item_kind_err(&self, item_type: &str, prev_span: Span)
6682
6671
-> DiagnosticBuilder<'a>
6683
6672
{
6684
6673
let expected_kinds = if item_type == "extern" {
0 commit comments