Rollup merge of #80344 - matthiaskrgr:matches, r=Dylan-DPC
use matches!() macro in more places
This commit is contained in:
commit
c51172f38a
33 changed files with 137 additions and 266 deletions
|
@ -167,10 +167,7 @@ pub enum GenericArgs {
|
|||
|
||||
impl GenericArgs {
|
||||
pub fn is_angle_bracketed(&self) -> bool {
|
||||
match *self {
|
||||
AngleBracketed(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, AngleBracketed(..))
|
||||
}
|
||||
|
||||
pub fn span(&self) -> Span {
|
||||
|
@ -629,10 +626,7 @@ impl Pat {
|
|||
|
||||
/// Is this a `..` pattern?
|
||||
pub fn is_rest(&self) -> bool {
|
||||
match self.kind {
|
||||
PatKind::Rest => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind, PatKind::Rest)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -852,10 +846,7 @@ impl BinOpKind {
|
|||
}
|
||||
}
|
||||
pub fn lazy(&self) -> bool {
|
||||
match *self {
|
||||
BinOpKind::And | BinOpKind::Or => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, BinOpKind::And | BinOpKind::Or)
|
||||
}
|
||||
|
||||
pub fn is_comparison(&self) -> bool {
|
||||
|
@ -963,17 +954,11 @@ impl Stmt {
|
|||
}
|
||||
|
||||
pub fn is_item(&self) -> bool {
|
||||
match self.kind {
|
||||
StmtKind::Item(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind, StmtKind::Item(_))
|
||||
}
|
||||
|
||||
pub fn is_expr(&self) -> bool {
|
||||
match self.kind {
|
||||
StmtKind::Expr(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind, StmtKind::Expr(_))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1652,26 +1637,17 @@ pub enum LitKind {
|
|||
impl LitKind {
|
||||
/// Returns `true` if this literal is a string.
|
||||
pub fn is_str(&self) -> bool {
|
||||
match *self {
|
||||
LitKind::Str(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, LitKind::Str(..))
|
||||
}
|
||||
|
||||
/// Returns `true` if this literal is byte literal string.
|
||||
pub fn is_bytestr(&self) -> bool {
|
||||
match self {
|
||||
LitKind::ByteStr(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, LitKind::ByteStr(_))
|
||||
}
|
||||
|
||||
/// Returns `true` if this is a numeric literal.
|
||||
pub fn is_numeric(&self) -> bool {
|
||||
match *self {
|
||||
LitKind::Int(..) | LitKind::Float(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, LitKind::Int(..) | LitKind::Float(..))
|
||||
}
|
||||
|
||||
/// Returns `true` if this literal has no suffix.
|
||||
|
@ -2237,10 +2213,7 @@ impl FnDecl {
|
|||
self.inputs.get(0).map_or(false, Param::is_self)
|
||||
}
|
||||
pub fn c_variadic(&self) -> bool {
|
||||
self.inputs.last().map_or(false, |arg| match arg.ty.kind {
|
||||
TyKind::CVarArgs => true,
|
||||
_ => false,
|
||||
})
|
||||
self.inputs.last().map_or(false, |arg| matches!(arg.ty.kind, TyKind::CVarArgs))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -234,10 +234,7 @@ impl MetaItem {
|
|||
}
|
||||
|
||||
pub fn is_word(&self) -> bool {
|
||||
match self.kind {
|
||||
MetaItemKind::Word => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind, MetaItemKind::Word)
|
||||
}
|
||||
|
||||
pub fn has_name(&self, name: Symbol) -> bool {
|
||||
|
|
|
@ -130,10 +130,7 @@ impl LitKind {
|
|||
}
|
||||
|
||||
crate fn may_have_suffix(self) -> bool {
|
||||
match self {
|
||||
Integer | Float | Err => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Integer | Float | Err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -305,10 +302,7 @@ impl TokenKind {
|
|||
}
|
||||
|
||||
pub fn should_end_const_arg(&self) -> bool {
|
||||
match self {
|
||||
Gt | Ge | BinOp(Shr) | BinOpEq(Shr) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Gt | Ge | BinOp(Shr) | BinOpEq(Shr))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -346,18 +340,21 @@ impl Token {
|
|||
}
|
||||
|
||||
pub fn is_op(&self) -> bool {
|
||||
match self.kind {
|
||||
OpenDelim(..) | CloseDelim(..) | Literal(..) | DocComment(..) | Ident(..)
|
||||
| Lifetime(..) | Interpolated(..) | Eof => false,
|
||||
_ => true,
|
||||
}
|
||||
!matches!(
|
||||
self.kind,
|
||||
OpenDelim(..)
|
||||
| CloseDelim(..)
|
||||
| Literal(..)
|
||||
| DocComment(..)
|
||||
| Ident(..)
|
||||
| Lifetime(..)
|
||||
| Interpolated(..)
|
||||
| Eof
|
||||
)
|
||||
}
|
||||
|
||||
pub fn is_like_plus(&self) -> bool {
|
||||
match self.kind {
|
||||
BinOp(Plus) | BinOpEq(Plus) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind, BinOp(Plus) | BinOpEq(Plus))
|
||||
}
|
||||
|
||||
/// Returns `true` if the token can appear at the start of an expression.
|
||||
|
@ -379,13 +376,10 @@ impl Token {
|
|||
ModSep | // global path
|
||||
Lifetime(..) | // labeled loop
|
||||
Pound => true, // expression attributes
|
||||
Interpolated(ref nt) => match **nt {
|
||||
NtLiteral(..) |
|
||||
Interpolated(ref nt) => matches!(**nt, NtLiteral(..) |
|
||||
NtExpr(..) |
|
||||
NtBlock(..) |
|
||||
NtPath(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
NtPath(..)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -405,10 +399,7 @@ impl Token {
|
|||
Lifetime(..) | // lifetime bound in trait object
|
||||
Lt | BinOp(Shl) | // associated path
|
||||
ModSep => true, // global path
|
||||
Interpolated(ref nt) => match **nt {
|
||||
NtTy(..) | NtPath(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
Interpolated(ref nt) => matches!(**nt, NtTy(..) | NtPath(..)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -417,10 +408,7 @@ impl Token {
|
|||
pub fn can_begin_const_arg(&self) -> bool {
|
||||
match self.kind {
|
||||
OpenDelim(Brace) => true,
|
||||
Interpolated(ref nt) => match **nt {
|
||||
NtExpr(..) | NtBlock(..) | NtLiteral(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
Interpolated(ref nt) => matches!(**nt, NtExpr(..) | NtBlock(..) | NtLiteral(..)),
|
||||
_ => self.can_begin_literal_maybe_minus(),
|
||||
}
|
||||
}
|
||||
|
@ -436,10 +424,7 @@ impl Token {
|
|||
|
||||
/// Returns `true` if the token is any literal.
|
||||
pub fn is_lit(&self) -> bool {
|
||||
match self.kind {
|
||||
Literal(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind, Literal(..))
|
||||
}
|
||||
|
||||
/// Returns `true` if the token is any literal, a minus (which can prefix a literal,
|
||||
|
|
|
@ -12,14 +12,14 @@ use crate::ast;
|
|||
/// |x| 5
|
||||
/// isn't parsed as (if true {...} else {...} | x) | 5
|
||||
pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
|
||||
match e.kind {
|
||||
!matches!(
|
||||
e.kind,
|
||||
ast::ExprKind::If(..)
|
||||
| ast::ExprKind::Match(..)
|
||||
| ast::ExprKind::Block(..)
|
||||
| ast::ExprKind::While(..)
|
||||
| ast::ExprKind::Loop(..)
|
||||
| ast::ExprKind::ForLoop(..)
|
||||
| ast::ExprKind::TryBlock(..) => false,
|
||||
_ => true,
|
||||
}
|
||||
| ast::ExprKind::Match(..)
|
||||
| ast::ExprKind::Block(..)
|
||||
| ast::ExprKind::While(..)
|
||||
| ast::ExprKind::Loop(..)
|
||||
| ast::ExprKind::ForLoop(..)
|
||||
| ast::ExprKind::TryBlock(..)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -180,10 +180,8 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme
|
|||
}
|
||||
rustc_lexer::TokenKind::BlockComment { doc_style, .. } => {
|
||||
if doc_style.is_none() {
|
||||
let code_to_the_right = match text[pos + token.len..].chars().next() {
|
||||
Some('\r' | '\n') => false,
|
||||
_ => true,
|
||||
};
|
||||
let code_to_the_right =
|
||||
!matches!(text[pos + token.len..].chars().next(), Some('\r' | '\n'));
|
||||
let style = match (code_to_the_left, code_to_the_right) {
|
||||
(_, true) => CommentStyle::Mixed,
|
||||
(false, false) => CommentStyle::Isolated,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue