rustc_parse
: remove ref
patterns
This commit is contained in:
parent
0f7d81754d
commit
616df0f03b
8 changed files with 39 additions and 39 deletions
|
@ -245,9 +245,9 @@ impl<'a> Parser<'a> {
|
||||||
/// PATH `=` UNSUFFIXED_LIT
|
/// PATH `=` UNSUFFIXED_LIT
|
||||||
/// The delimiters or `=` are still put into the resulting token stream.
|
/// The delimiters or `=` are still put into the resulting token stream.
|
||||||
pub fn parse_attr_item(&mut self, capture_tokens: bool) -> PResult<'a, ast::AttrItem> {
|
pub fn parse_attr_item(&mut self, capture_tokens: bool) -> PResult<'a, ast::AttrItem> {
|
||||||
let item = match self.token.kind {
|
let item = match &self.token.kind {
|
||||||
token::Interpolated(ref nt) => match **nt {
|
token::Interpolated(nt) => match &**nt {
|
||||||
Nonterminal::NtMeta(ref item) => Some(item.clone().into_inner()),
|
Nonterminal::NtMeta(item) => Some(item.clone().into_inner()),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -364,9 +364,9 @@ impl<'a> Parser<'a> {
|
||||||
/// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
|
/// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
|
||||||
/// ```
|
/// ```
|
||||||
pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> {
|
pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> {
|
||||||
let nt_meta = match self.token.kind {
|
let nt_meta = match &self.token.kind {
|
||||||
token::Interpolated(ref nt) => match **nt {
|
token::Interpolated(nt) => match &**nt {
|
||||||
token::NtMeta(ref e) => Some(e.clone()),
|
token::NtMeta(e) => Some(e.clone()),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
@ -973,7 +973,7 @@ impl<'a> Parser<'a> {
|
||||||
inner_op: &Expr,
|
inner_op: &Expr,
|
||||||
outer_op: &Spanned<AssocOp>,
|
outer_op: &Spanned<AssocOp>,
|
||||||
) -> bool /* advanced the cursor */ {
|
) -> bool /* advanced the cursor */ {
|
||||||
if let ExprKind::Binary(op, ref l1, ref r1) = inner_op.kind {
|
if let ExprKind::Binary(op, l1, r1) = &inner_op.kind {
|
||||||
if let ExprKind::Field(_, ident) = l1.kind
|
if let ExprKind::Field(_, ident) = l1.kind
|
||||||
&& ident.as_str().parse::<i32>().is_err()
|
&& ident.as_str().parse::<i32>().is_err()
|
||||||
&& !matches!(r1.kind, ExprKind::Lit(_))
|
&& !matches!(r1.kind, ExprKind::Lit(_))
|
||||||
|
@ -1079,8 +1079,8 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
let mk_err_expr = |this: &Self, span| Ok(Some(this.mk_expr(span, ExprKind::Err)));
|
let mk_err_expr = |this: &Self, span| Ok(Some(this.mk_expr(span, ExprKind::Err)));
|
||||||
|
|
||||||
match inner_op.kind {
|
match &inner_op.kind {
|
||||||
ExprKind::Binary(op, ref l1, ref r1) if op.node.is_comparison() => {
|
ExprKind::Binary(op, l1, r1) if op.node.is_comparison() => {
|
||||||
let mut err = ComparisonOperatorsCannotBeChained {
|
let mut err = ComparisonOperatorsCannotBeChained {
|
||||||
span: vec![op.span, self.prev_token.span],
|
span: vec![op.span, self.prev_token.span],
|
||||||
suggest_turbofish: None,
|
suggest_turbofish: None,
|
||||||
|
@ -1237,8 +1237,8 @@ impl<'a> Parser<'a> {
|
||||||
let bounds = self.parse_generic_bounds(None)?;
|
let bounds = self.parse_generic_bounds(None)?;
|
||||||
let sum_span = ty.span.to(self.prev_token.span);
|
let sum_span = ty.span.to(self.prev_token.span);
|
||||||
|
|
||||||
let sub = match ty.kind {
|
let sub = match &ty.kind {
|
||||||
TyKind::Rptr(ref lifetime, ref mut_ty) => {
|
TyKind::Rptr(lifetime, mut_ty) => {
|
||||||
let sum_with_parens = pprust::to_string(|s| {
|
let sum_with_parens = pprust::to_string(|s| {
|
||||||
s.s.word("&");
|
s.s.word("&");
|
||||||
s.print_opt_lifetime(lifetime);
|
s.print_opt_lifetime(lifetime);
|
||||||
|
|
|
@ -414,7 +414,7 @@ impl<'a> Parser<'a> {
|
||||||
self.sess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
|
self.sess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
(true, Some(ref op)) if !op.can_continue_expr_unambiguously() => false,
|
(true, Some(op)) if !op.can_continue_expr_unambiguously() => false,
|
||||||
(true, Some(_)) => {
|
(true, Some(_)) => {
|
||||||
self.error_found_expr_would_be_stmt(lhs);
|
self.error_found_expr_would_be_stmt(lhs);
|
||||||
true
|
true
|
||||||
|
@ -1728,7 +1728,7 @@ impl<'a> Parser<'a> {
|
||||||
|| !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL)
|
|| !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL)
|
||||||
{
|
{
|
||||||
let expr = self.parse_expr_opt()?;
|
let expr = self.parse_expr_opt()?;
|
||||||
if let Some(ref expr) = expr {
|
if let Some(expr) = &expr {
|
||||||
if label.is_some()
|
if label.is_some()
|
||||||
&& matches!(
|
&& matches!(
|
||||||
expr.kind,
|
expr.kind,
|
||||||
|
@ -2590,8 +2590,8 @@ impl<'a> Parser<'a> {
|
||||||
// Used to check the `let_chains` and `if_let_guard` features mostly by scanning
|
// Used to check the `let_chains` and `if_let_guard` features mostly by scanning
|
||||||
// `&&` tokens.
|
// `&&` tokens.
|
||||||
fn check_let_expr(expr: &Expr) -> (bool, bool) {
|
fn check_let_expr(expr: &Expr) -> (bool, bool) {
|
||||||
match expr.kind {
|
match &expr.kind {
|
||||||
ExprKind::Binary(BinOp { node: BinOpKind::And, .. }, ref lhs, ref rhs) => {
|
ExprKind::Binary(BinOp { node: BinOpKind::And, .. }, lhs, rhs) => {
|
||||||
let lhs_rslt = check_let_expr(lhs);
|
let lhs_rslt = check_let_expr(lhs);
|
||||||
let rhs_rslt = check_let_expr(rhs);
|
let rhs_rslt = check_let_expr(rhs);
|
||||||
(lhs_rslt.0 || rhs_rslt.0, false)
|
(lhs_rslt.0 || rhs_rslt.0, false)
|
||||||
|
|
|
@ -1255,8 +1255,8 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match impl_info.1 {
|
match &mut impl_info.1 {
|
||||||
ItemKind::Impl(box Impl { of_trait: Some(ref trai), ref mut constness, .. }) => {
|
ItemKind::Impl(box Impl { of_trait: Some(trai), constness, .. }) => {
|
||||||
*constness = Const::Yes(const_span);
|
*constness = Const::Yes(const_span);
|
||||||
|
|
||||||
let before_trait = trai.path.span.shrink_to_lo();
|
let before_trait = trai.path.span.shrink_to_lo();
|
||||||
|
@ -2585,8 +2585,8 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_named_param(&self) -> bool {
|
fn is_named_param(&self) -> bool {
|
||||||
let offset = match self.token.kind {
|
let offset = match &self.token.kind {
|
||||||
token::Interpolated(ref nt) => match **nt {
|
token::Interpolated(nt) => match **nt {
|
||||||
token::NtPat(..) => return self.look_ahead(1, |t| t == &token::Colon),
|
token::NtPat(..) => return self.look_ahead(1, |t| t == &token::Colon),
|
||||||
_ => 0,
|
_ => 0,
|
||||||
},
|
},
|
||||||
|
|
|
@ -384,8 +384,8 @@ enum TokenType {
|
||||||
|
|
||||||
impl TokenType {
|
impl TokenType {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
match *self {
|
match self {
|
||||||
TokenType::Token(ref t) => format!("`{}`", pprust::token_kind_to_string(t)),
|
TokenType::Token(t) => format!("`{}`", pprust::token_kind_to_string(t)),
|
||||||
TokenType::Keyword(kw) => format!("`{}`", kw),
|
TokenType::Keyword(kw) => format!("`{}`", kw),
|
||||||
TokenType::Operator => "an operator".to_string(),
|
TokenType::Operator => "an operator".to_string(),
|
||||||
TokenType::Lifetime => "lifetime".to_string(),
|
TokenType::Lifetime => "lifetime".to_string(),
|
||||||
|
@ -738,8 +738,8 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
fn check_inline_const(&self, dist: usize) -> bool {
|
fn check_inline_const(&self, dist: usize) -> bool {
|
||||||
self.is_keyword_ahead(dist, &[kw::Const])
|
self.is_keyword_ahead(dist, &[kw::Const])
|
||||||
&& self.look_ahead(dist + 1, |t| match t.kind {
|
&& self.look_ahead(dist + 1, |t| match &t.kind {
|
||||||
token::Interpolated(ref nt) => matches!(**nt, token::NtBlock(..)),
|
token::Interpolated(nt) => matches!(**nt, token::NtBlock(..)),
|
||||||
token::OpenDelim(Delimiter::Brace) => true,
|
token::OpenDelim(Delimiter::Brace) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
})
|
})
|
||||||
|
@ -860,7 +860,7 @@ impl<'a> Parser<'a> {
|
||||||
if let token::CloseDelim(..) | token::Eof = self.token.kind {
|
if let token::CloseDelim(..) | token::Eof = self.token.kind {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if let Some(ref t) = sep.sep {
|
if let Some(t) = &sep.sep {
|
||||||
if first {
|
if first {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -895,7 +895,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
// Attempt to keep parsing if it was a similar separator.
|
// Attempt to keep parsing if it was a similar separator.
|
||||||
if let Some(ref tokens) = t.similar_tokens() {
|
if let Some(tokens) = t.similar_tokens() {
|
||||||
if tokens.contains(&self.token.kind) && !unclosed_delims {
|
if tokens.contains(&self.token.kind) && !unclosed_delims {
|
||||||
self.bump();
|
self.bump();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,9 +42,9 @@ impl<'a> Parser<'a> {
|
||||||
token::Comma | token::Ident(..) | token::Interpolated(..) => true,
|
token::Comma | token::Ident(..) | token::Interpolated(..) => true,
|
||||||
_ => token.can_begin_type(),
|
_ => token.can_begin_type(),
|
||||||
},
|
},
|
||||||
NonterminalKind::Block => match token.kind {
|
NonterminalKind::Block => match &token.kind {
|
||||||
token::OpenDelim(Delimiter::Brace) => true,
|
token::OpenDelim(Delimiter::Brace) => true,
|
||||||
token::Interpolated(ref nt) => !matches!(
|
token::Interpolated(nt) => !matches!(
|
||||||
**nt,
|
**nt,
|
||||||
token::NtItem(_)
|
token::NtItem(_)
|
||||||
| token::NtPat(_)
|
| token::NtPat(_)
|
||||||
|
@ -56,16 +56,16 @@ impl<'a> Parser<'a> {
|
||||||
),
|
),
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
NonterminalKind::Path | NonterminalKind::Meta => match token.kind {
|
NonterminalKind::Path | NonterminalKind::Meta => match &token.kind {
|
||||||
token::ModSep | token::Ident(..) => true,
|
token::ModSep | token::Ident(..) => true,
|
||||||
token::Interpolated(ref nt) => match **nt {
|
token::Interpolated(nt) => match **nt {
|
||||||
token::NtPath(_) | token::NtMeta(_) => true,
|
token::NtPath(_) | token::NtMeta(_) => true,
|
||||||
_ => may_be_ident(&nt),
|
_ => may_be_ident(&nt),
|
||||||
},
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr { .. } => {
|
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr { .. } => {
|
||||||
match token.kind {
|
match &token.kind {
|
||||||
token::Ident(..) | // box, ref, mut, and other identifiers (can stricten)
|
token::Ident(..) | // box, ref, mut, and other identifiers (can stricten)
|
||||||
token::OpenDelim(Delimiter::Parenthesis) | // tuple pattern
|
token::OpenDelim(Delimiter::Parenthesis) | // tuple pattern
|
||||||
token::OpenDelim(Delimiter::Bracket) | // slice pattern
|
token::OpenDelim(Delimiter::Bracket) | // slice pattern
|
||||||
|
@ -80,13 +80,13 @@ impl<'a> Parser<'a> {
|
||||||
token::BinOp(token::Shl) => true, // path (double UFCS)
|
token::BinOp(token::Shl) => true, // path (double UFCS)
|
||||||
// leading vert `|` or-pattern
|
// leading vert `|` or-pattern
|
||||||
token::BinOp(token::Or) => matches!(kind, NonterminalKind::PatWithOr {..}),
|
token::BinOp(token::Or) => matches!(kind, NonterminalKind::PatWithOr {..}),
|
||||||
token::Interpolated(ref nt) => may_be_ident(nt),
|
token::Interpolated(nt) => may_be_ident(nt),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NonterminalKind::Lifetime => match token.kind {
|
NonterminalKind::Lifetime => match &token.kind {
|
||||||
token::Lifetime(_) => true,
|
token::Lifetime(_) => true,
|
||||||
token::Interpolated(ref nt) => {
|
token::Interpolated(nt) => {
|
||||||
matches!(**nt, token::NtLifetime(_))
|
matches!(**nt, token::NtLifetime(_))
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
|
@ -485,7 +485,7 @@ impl<'a> Parser<'a> {
|
||||||
let mut rhs = self.parse_pat_no_top_alt(None)?;
|
let mut rhs = self.parse_pat_no_top_alt(None)?;
|
||||||
let sp = lhs.span.to(rhs.span);
|
let sp = lhs.span.to(rhs.span);
|
||||||
|
|
||||||
if let PatKind::Ident(_, _, ref mut sub @ None) = rhs.kind {
|
if let PatKind::Ident(_, _, sub @ None) = &mut rhs.kind {
|
||||||
// The user inverted the order, so help them fix that.
|
// The user inverted the order, so help them fix that.
|
||||||
let mut applicability = Applicability::MachineApplicable;
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
// FIXME(bindings_after_at): Remove this code when stabilizing the feature.
|
// FIXME(bindings_after_at): Remove this code when stabilizing the feature.
|
||||||
|
@ -595,7 +595,7 @@ impl<'a> Parser<'a> {
|
||||||
self.recover_additional_muts();
|
self.recover_additional_muts();
|
||||||
|
|
||||||
// Make sure we don't allow e.g. `let mut $p;` where `$p:pat`.
|
// Make sure we don't allow e.g. `let mut $p;` where `$p:pat`.
|
||||||
if let token::Interpolated(ref nt) = self.token.kind {
|
if let token::Interpolated(nt) = &self.token.kind {
|
||||||
if let token::NtPat(_) = **nt {
|
if let token::NtPat(_) = **nt {
|
||||||
self.expected_ident_found().emit();
|
self.expected_ident_found().emit();
|
||||||
}
|
}
|
||||||
|
@ -796,7 +796,7 @@ impl<'a> Parser<'a> {
|
||||||
/// expression syntax `...expr` for splatting in expressions.
|
/// expression syntax `...expr` for splatting in expressions.
|
||||||
fn parse_pat_range_to(&mut self, mut re: Spanned<RangeEnd>) -> PResult<'a, PatKind> {
|
fn parse_pat_range_to(&mut self, mut re: Spanned<RangeEnd>) -> PResult<'a, PatKind> {
|
||||||
let end = self.parse_pat_range_end()?;
|
let end = self.parse_pat_range_end()?;
|
||||||
if let RangeEnd::Included(ref mut syn @ RangeSyntax::DotDotDot) = &mut re.node {
|
if let RangeEnd::Included(syn @ RangeSyntax::DotDotDot) = &mut re.node {
|
||||||
*syn = RangeSyntax::DotDotEq;
|
*syn = RangeSyntax::DotDotEq;
|
||||||
self.struct_span_err(re.span, "range-to patterns with `...` are not allowed")
|
self.struct_span_err(re.span, "range-to patterns with `...` are not allowed")
|
||||||
.span_suggestion_short(
|
.span_suggestion_short(
|
||||||
|
|
|
@ -563,9 +563,9 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut eat_semi = true;
|
let mut eat_semi = true;
|
||||||
match stmt.kind {
|
match &mut stmt.kind {
|
||||||
// Expression without semicolon.
|
// Expression without semicolon.
|
||||||
StmtKind::Expr(ref mut expr)
|
StmtKind::Expr(expr)
|
||||||
if self.token != token::Eof && classify::expr_requires_semi_to_be_stmt(expr) => {
|
if self.token != token::Eof && classify::expr_requires_semi_to_be_stmt(expr) => {
|
||||||
// Just check for errors and recover; do not eat semicolon yet.
|
// Just check for errors and recover; do not eat semicolon yet.
|
||||||
// `expect_one_of` returns PResult<'a, bool /* recovered */>
|
// `expect_one_of` returns PResult<'a, bool /* recovered */>
|
||||||
|
@ -611,7 +611,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StmtKind::Expr(_) | StmtKind::MacCall(_) => {}
|
StmtKind::Expr(_) | StmtKind::MacCall(_) => {}
|
||||||
StmtKind::Local(ref mut local) if let Err(e) = self.expect_semi() => {
|
StmtKind::Local(local) if let Err(e) = self.expect_semi() => {
|
||||||
// We might be at the `,` in `let x = foo<bar, baz>;`. Try to recover.
|
// We might be at the `,` in `let x = foo<bar, baz>;`. Try to recover.
|
||||||
match &mut local.kind {
|
match &mut local.kind {
|
||||||
LocalKind::Init(expr) | LocalKind::InitElse(expr, _) => {
|
LocalKind::Init(expr) | LocalKind::InitElse(expr, _) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue