Suggest removing unnecessary prefix let in patterns
This commit is contained in:
parent
8c6ce6b91b
commit
91674cc56c
6 changed files with 74 additions and 1 deletions
|
@ -398,6 +398,30 @@ impl Token {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the token can appear at the start of an pattern.
|
||||
///
|
||||
/// Shamelessly borrowed from `can_begin_expr`, only used for diagnostics right now.
|
||||
pub fn can_begin_pattern(&self) -> bool {
|
||||
match self.uninterpolate().kind {
|
||||
Ident(name, is_raw) =>
|
||||
ident_can_begin_expr(name, self.span, is_raw), // value name or keyword
|
||||
| OpenDelim(Delimiter::Bracket | Delimiter::Parenthesis) // tuple or array
|
||||
| Literal(..) // literal
|
||||
| BinOp(Minus) // unary minus
|
||||
| BinOp(And) // reference
|
||||
| AndAnd // double reference
|
||||
// DotDotDot is no longer supported
|
||||
| DotDot | DotDotDot | DotDotEq // ranges
|
||||
| Lt | BinOp(Shl) // associated path
|
||||
| ModSep => true, // global path
|
||||
Interpolated(ref nt) => matches!(**nt, NtLiteral(..) |
|
||||
NtPat(..) |
|
||||
NtBlock(..) |
|
||||
NtPath(..)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the token can appear at the start of a type.
|
||||
pub fn can_begin_type(&self) -> bool {
|
||||
match self.uninterpolate().kind {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue