Skip to content

Commit 231727d

Browse files
authored
Rollup merge of #80467 - LingMan:more_matches, r=oli-obk
More uses of the matches! macro `@rustbot` modify labels +C-cleanup +T-compiler
2 parents b050261 + 7a41532 commit 231727d

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,15 +1092,9 @@ impl Expr {
10921092
if let ExprKind::Block(ref block, _) = self.kind {
10931093
match block.stmts.last().map(|last_stmt| &last_stmt.kind) {
10941094
// Implicit return
1095-
Some(&StmtKind::Expr(_)) => true,
1096-
Some(&StmtKind::Semi(ref expr)) => {
1097-
if let ExprKind::Ret(_) = expr.kind {
1098-
// Last statement is explicit return.
1099-
true
1100-
} else {
1101-
false
1102-
}
1103-
}
1095+
Some(StmtKind::Expr(_)) => true,
1096+
// Last statement is an explicit return?
1097+
Some(StmtKind::Semi(expr)) => matches!(expr.kind, ExprKind::Ret(_)),
11041098
// This is a block that doesn't end in either an implicit or explicit return.
11051099
_ => false,
11061100
}
@@ -1950,7 +1944,7 @@ impl TyKind {
19501944
}
19511945

19521946
pub fn is_unit(&self) -> bool {
1953-
if let TyKind::Tup(ref tys) = *self { tys.is_empty() } else { false }
1947+
matches!(self, TyKind::Tup(tys) if tys.is_empty())
19541948
}
19551949
}
19561950

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,12 +1806,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18061806
output,
18071807
c_variadic,
18081808
implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
1809-
let is_mutable_pat = match arg.pat.kind {
1810-
PatKind::Ident(BindingMode::ByValue(mt) | BindingMode::ByRef(mt), _, _) => {
1811-
mt == Mutability::Mut
1812-
}
1813-
_ => false,
1814-
};
1809+
use BindingMode::{ByRef, ByValue};
1810+
let is_mutable_pat = matches!(
1811+
arg.pat.kind,
1812+
PatKind::Ident(ByValue(Mutability::Mut) | ByRef(Mutability::Mut), ..)
1813+
);
18151814

18161815
match arg.ty.kind {
18171816
TyKind::ImplicitSelf if is_mutable_pat => hir::ImplicitSelfKind::Mut,

0 commit comments

Comments
 (0)