More uses of the matches! macro

This commit is contained in:
LingMan 2020-12-29 01:20:06 +01:00
parent 2987785df3
commit 7a41532ef9
2 changed files with 9 additions and 16 deletions

View file

@ -1092,15 +1092,9 @@ impl Expr {
if let ExprKind::Block(ref block, _) = self.kind { if let ExprKind::Block(ref block, _) = self.kind {
match block.stmts.last().map(|last_stmt| &last_stmt.kind) { match block.stmts.last().map(|last_stmt| &last_stmt.kind) {
// Implicit return // Implicit return
Some(&StmtKind::Expr(_)) => true, Some(StmtKind::Expr(_)) => true,
Some(&StmtKind::Semi(ref expr)) => { // Last statement is an explicit return?
if let ExprKind::Ret(_) = expr.kind { Some(StmtKind::Semi(expr)) => matches!(expr.kind, ExprKind::Ret(_)),
// Last statement is explicit return.
true
} else {
false
}
}
// This is a block that doesn't end in either an implicit or explicit return. // This is a block that doesn't end in either an implicit or explicit return.
_ => false, _ => false,
} }
@ -1950,7 +1944,7 @@ impl TyKind {
} }
pub fn is_unit(&self) -> bool { pub fn is_unit(&self) -> bool {
if let TyKind::Tup(ref tys) = *self { tys.is_empty() } else { false } matches!(self, TyKind::Tup(tys) if tys.is_empty())
} }
} }

View file

@ -1806,12 +1806,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
output, output,
c_variadic, c_variadic,
implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| { implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
let is_mutable_pat = match arg.pat.kind { use BindingMode::{ByRef, ByValue};
PatKind::Ident(BindingMode::ByValue(mt) | BindingMode::ByRef(mt), _, _) => { let is_mutable_pat = matches!(
mt == Mutability::Mut arg.pat.kind,
} PatKind::Ident(ByValue(Mutability::Mut) | ByRef(Mutability::Mut), ..)
_ => false, );
};
match arg.ty.kind { match arg.ty.kind {
TyKind::ImplicitSelf if is_mutable_pat => hir::ImplicitSelfKind::Mut, TyKind::ImplicitSelf if is_mutable_pat => hir::ImplicitSelfKind::Mut,