Skip to content

Commit 616df0f

Browse files
committed
rustc_parse: remove ref patterns
1 parent 0f7d817 commit 616df0f

File tree

8 files changed

+39
-39
lines changed

8 files changed

+39
-39
lines changed

compiler/rustc_parse/src/parser/attr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ impl<'a> Parser<'a> {
245245
/// PATH `=` UNSUFFIXED_LIT
246246
/// The delimiters or `=` are still put into the resulting token stream.
247247
pub fn parse_attr_item(&mut self, capture_tokens: bool) -> PResult<'a, ast::AttrItem> {
248-
let item = match self.token.kind {
249-
token::Interpolated(ref nt) => match **nt {
250-
Nonterminal::NtMeta(ref item) => Some(item.clone().into_inner()),
248+
let item = match &self.token.kind {
249+
token::Interpolated(nt) => match &**nt {
250+
Nonterminal::NtMeta(item) => Some(item.clone().into_inner()),
251251
_ => None,
252252
},
253253
_ => None,
@@ -364,9 +364,9 @@ impl<'a> Parser<'a> {
364364
/// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
365365
/// ```
366366
pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> {
367-
let nt_meta = match self.token.kind {
368-
token::Interpolated(ref nt) => match **nt {
369-
token::NtMeta(ref e) => Some(e.clone()),
367+
let nt_meta = match &self.token.kind {
368+
token::Interpolated(nt) => match &**nt {
369+
token::NtMeta(e) => Some(e.clone()),
370370
_ => None,
371371
},
372372
_ => None,

compiler/rustc_parse/src/parser/diagnostics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ impl<'a> Parser<'a> {
973973
inner_op: &Expr,
974974
outer_op: &Spanned<AssocOp>,
975975
) -> bool /* advanced the cursor */ {
976-
if let ExprKind::Binary(op, ref l1, ref r1) = inner_op.kind {
976+
if let ExprKind::Binary(op, l1, r1) = &inner_op.kind {
977977
if let ExprKind::Field(_, ident) = l1.kind
978978
&& ident.as_str().parse::<i32>().is_err()
979979
&& !matches!(r1.kind, ExprKind::Lit(_))
@@ -1079,8 +1079,8 @@ impl<'a> Parser<'a> {
10791079

10801080
let mk_err_expr = |this: &Self, span| Ok(Some(this.mk_expr(span, ExprKind::Err)));
10811081

1082-
match inner_op.kind {
1083-
ExprKind::Binary(op, ref l1, ref r1) if op.node.is_comparison() => {
1082+
match &inner_op.kind {
1083+
ExprKind::Binary(op, l1, r1) if op.node.is_comparison() => {
10841084
let mut err = ComparisonOperatorsCannotBeChained {
10851085
span: vec![op.span, self.prev_token.span],
10861086
suggest_turbofish: None,
@@ -1237,8 +1237,8 @@ impl<'a> Parser<'a> {
12371237
let bounds = self.parse_generic_bounds(None)?;
12381238
let sum_span = ty.span.to(self.prev_token.span);
12391239

1240-
let sub = match ty.kind {
1241-
TyKind::Rptr(ref lifetime, ref mut_ty) => {
1240+
let sub = match &ty.kind {
1241+
TyKind::Rptr(lifetime, mut_ty) => {
12421242
let sum_with_parens = pprust::to_string(|s| {
12431243
s.s.word("&");
12441244
s.print_opt_lifetime(lifetime);

compiler/rustc_parse/src/parser/expr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ impl<'a> Parser<'a> {
414414
self.sess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
415415
false
416416
}
417-
(true, Some(ref op)) if !op.can_continue_expr_unambiguously() => false,
417+
(true, Some(op)) if !op.can_continue_expr_unambiguously() => false,
418418
(true, Some(_)) => {
419419
self.error_found_expr_would_be_stmt(lhs);
420420
true
@@ -1728,7 +1728,7 @@ impl<'a> Parser<'a> {
17281728
|| !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL)
17291729
{
17301730
let expr = self.parse_expr_opt()?;
1731-
if let Some(ref expr) = expr {
1731+
if let Some(expr) = &expr {
17321732
if label.is_some()
17331733
&& matches!(
17341734
expr.kind,
@@ -2590,8 +2590,8 @@ impl<'a> Parser<'a> {
25902590
// Used to check the `let_chains` and `if_let_guard` features mostly by scanning
25912591
// `&&` tokens.
25922592
fn check_let_expr(expr: &Expr) -> (bool, bool) {
2593-
match expr.kind {
2594-
ExprKind::Binary(BinOp { node: BinOpKind::And, .. }, ref lhs, ref rhs) => {
2593+
match &expr.kind {
2594+
ExprKind::Binary(BinOp { node: BinOpKind::And, .. }, lhs, rhs) => {
25952595
let lhs_rslt = check_let_expr(lhs);
25962596
let rhs_rslt = check_let_expr(rhs);
25972597
(lhs_rslt.0 || rhs_rslt.0, false)

compiler/rustc_parse/src/parser/item.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,8 @@ impl<'a> Parser<'a> {
12551255
}
12561256
};
12571257

1258-
match impl_info.1 {
1259-
ItemKind::Impl(box Impl { of_trait: Some(ref trai), ref mut constness, .. }) => {
1258+
match &mut impl_info.1 {
1259+
ItemKind::Impl(box Impl { of_trait: Some(trai), constness, .. }) => {
12601260
*constness = Const::Yes(const_span);
12611261

12621262
let before_trait = trai.path.span.shrink_to_lo();
@@ -2585,8 +2585,8 @@ impl<'a> Parser<'a> {
25852585
}
25862586

25872587
fn is_named_param(&self) -> bool {
2588-
let offset = match self.token.kind {
2589-
token::Interpolated(ref nt) => match **nt {
2588+
let offset = match &self.token.kind {
2589+
token::Interpolated(nt) => match **nt {
25902590
token::NtPat(..) => return self.look_ahead(1, |t| t == &token::Colon),
25912591
_ => 0,
25922592
},

compiler/rustc_parse/src/parser/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ enum TokenType {
384384

385385
impl TokenType {
386386
fn to_string(&self) -> String {
387-
match *self {
388-
TokenType::Token(ref t) => format!("`{}`", pprust::token_kind_to_string(t)),
387+
match self {
388+
TokenType::Token(t) => format!("`{}`", pprust::token_kind_to_string(t)),
389389
TokenType::Keyword(kw) => format!("`{}`", kw),
390390
TokenType::Operator => "an operator".to_string(),
391391
TokenType::Lifetime => "lifetime".to_string(),
@@ -738,8 +738,8 @@ impl<'a> Parser<'a> {
738738

739739
fn check_inline_const(&self, dist: usize) -> bool {
740740
self.is_keyword_ahead(dist, &[kw::Const])
741-
&& self.look_ahead(dist + 1, |t| match t.kind {
742-
token::Interpolated(ref nt) => matches!(**nt, token::NtBlock(..)),
741+
&& self.look_ahead(dist + 1, |t| match &t.kind {
742+
token::Interpolated(nt) => matches!(**nt, token::NtBlock(..)),
743743
token::OpenDelim(Delimiter::Brace) => true,
744744
_ => false,
745745
})
@@ -860,7 +860,7 @@ impl<'a> Parser<'a> {
860860
if let token::CloseDelim(..) | token::Eof = self.token.kind {
861861
break;
862862
}
863-
if let Some(ref t) = sep.sep {
863+
if let Some(t) = &sep.sep {
864864
if first {
865865
first = false;
866866
} else {
@@ -895,7 +895,7 @@ impl<'a> Parser<'a> {
895895

896896
_ => {
897897
// Attempt to keep parsing if it was a similar separator.
898-
if let Some(ref tokens) = t.similar_tokens() {
898+
if let Some(tokens) = t.similar_tokens() {
899899
if tokens.contains(&self.token.kind) && !unclosed_delims {
900900
self.bump();
901901
}

compiler/rustc_parse/src/parser/nonterminal.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ impl<'a> Parser<'a> {
4242
token::Comma | token::Ident(..) | token::Interpolated(..) => true,
4343
_ => token.can_begin_type(),
4444
},
45-
NonterminalKind::Block => match token.kind {
45+
NonterminalKind::Block => match &token.kind {
4646
token::OpenDelim(Delimiter::Brace) => true,
47-
token::Interpolated(ref nt) => !matches!(
47+
token::Interpolated(nt) => !matches!(
4848
**nt,
4949
token::NtItem(_)
5050
| token::NtPat(_)
@@ -56,16 +56,16 @@ impl<'a> Parser<'a> {
5656
),
5757
_ => false,
5858
},
59-
NonterminalKind::Path | NonterminalKind::Meta => match token.kind {
59+
NonterminalKind::Path | NonterminalKind::Meta => match &token.kind {
6060
token::ModSep | token::Ident(..) => true,
61-
token::Interpolated(ref nt) => match **nt {
61+
token::Interpolated(nt) => match **nt {
6262
token::NtPath(_) | token::NtMeta(_) => true,
6363
_ => may_be_ident(&nt),
6464
},
6565
_ => false,
6666
},
6767
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr { .. } => {
68-
match token.kind {
68+
match &token.kind {
6969
token::Ident(..) | // box, ref, mut, and other identifiers (can stricten)
7070
token::OpenDelim(Delimiter::Parenthesis) | // tuple pattern
7171
token::OpenDelim(Delimiter::Bracket) | // slice pattern
@@ -80,13 +80,13 @@ impl<'a> Parser<'a> {
8080
token::BinOp(token::Shl) => true, // path (double UFCS)
8181
// leading vert `|` or-pattern
8282
token::BinOp(token::Or) => matches!(kind, NonterminalKind::PatWithOr {..}),
83-
token::Interpolated(ref nt) => may_be_ident(nt),
83+
token::Interpolated(nt) => may_be_ident(nt),
8484
_ => false,
8585
}
8686
}
87-
NonterminalKind::Lifetime => match token.kind {
87+
NonterminalKind::Lifetime => match &token.kind {
8888
token::Lifetime(_) => true,
89-
token::Interpolated(ref nt) => {
89+
token::Interpolated(nt) => {
9090
matches!(**nt, token::NtLifetime(_))
9191
}
9292
_ => false,

compiler/rustc_parse/src/parser/pat.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl<'a> Parser<'a> {
485485
let mut rhs = self.parse_pat_no_top_alt(None)?;
486486
let sp = lhs.span.to(rhs.span);
487487

488-
if let PatKind::Ident(_, _, ref mut sub @ None) = rhs.kind {
488+
if let PatKind::Ident(_, _, sub @ None) = &mut rhs.kind {
489489
// The user inverted the order, so help them fix that.
490490
let mut applicability = Applicability::MachineApplicable;
491491
// FIXME(bindings_after_at): Remove this code when stabilizing the feature.
@@ -595,7 +595,7 @@ impl<'a> Parser<'a> {
595595
self.recover_additional_muts();
596596

597597
// Make sure we don't allow e.g. `let mut $p;` where `$p:pat`.
598-
if let token::Interpolated(ref nt) = self.token.kind {
598+
if let token::Interpolated(nt) = &self.token.kind {
599599
if let token::NtPat(_) = **nt {
600600
self.expected_ident_found().emit();
601601
}
@@ -796,7 +796,7 @@ impl<'a> Parser<'a> {
796796
/// expression syntax `...expr` for splatting in expressions.
797797
fn parse_pat_range_to(&mut self, mut re: Spanned<RangeEnd>) -> PResult<'a, PatKind> {
798798
let end = self.parse_pat_range_end()?;
799-
if let RangeEnd::Included(ref mut syn @ RangeSyntax::DotDotDot) = &mut re.node {
799+
if let RangeEnd::Included(syn @ RangeSyntax::DotDotDot) = &mut re.node {
800800
*syn = RangeSyntax::DotDotEq;
801801
self.struct_span_err(re.span, "range-to patterns with `...` are not allowed")
802802
.span_suggestion_short(

compiler/rustc_parse/src/parser/stmt.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,9 @@ impl<'a> Parser<'a> {
563563
};
564564

565565
let mut eat_semi = true;
566-
match stmt.kind {
566+
match &mut stmt.kind {
567567
// Expression without semicolon.
568-
StmtKind::Expr(ref mut expr)
568+
StmtKind::Expr(expr)
569569
if self.token != token::Eof && classify::expr_requires_semi_to_be_stmt(expr) => {
570570
// Just check for errors and recover; do not eat semicolon yet.
571571
// `expect_one_of` returns PResult<'a, bool /* recovered */>
@@ -611,7 +611,7 @@ impl<'a> Parser<'a> {
611611
}
612612
}
613613
StmtKind::Expr(_) | StmtKind::MacCall(_) => {}
614-
StmtKind::Local(ref mut local) if let Err(e) = self.expect_semi() => {
614+
StmtKind::Local(local) if let Err(e) = self.expect_semi() => {
615615
// We might be at the `,` in `let x = foo<bar, baz>;`. Try to recover.
616616
match &mut local.kind {
617617
LocalKind::Init(expr) | LocalKind::InitElse(expr, _) => {

0 commit comments

Comments
 (0)