Replace complex matches!(…, … if …) by if let chain

This commit is contained in:
Samuel Tardieu 2026-01-13 23:11:42 +01:00
parent c267b597d0
commit 6c4cdfaf42
No known key found for this signature in database
GPG key ID: BDDC3208C6FEAFA8
2 changed files with 9 additions and 2 deletions

View file

@ -150,7 +150,9 @@ impl SlowVectorInit {
&& func.ty_rel_def(cx).is_diag_item(cx, sym::vec_with_capacity)
{
Some(InitializedSize::Initialized(len_expr))
} else if matches!(expr.kind, ExprKind::Call(func, []) if func.ty_rel_def(cx).is_diag_item(cx, sym::vec_new)) {
} else if let ExprKind::Call(func, []) = expr.kind
&& func.ty_rel_def(cx).is_diag_item(cx, sym::vec_new)
{
Some(InitializedSize::Uninitialized)
} else {
None

View file

@ -152,7 +152,12 @@ fn insert_necessary_parens(pat: &mut Pat) {
walk_pat(self, pat);
let target = match &mut pat.kind {
// `i @ a | b`, `box a | b`, and `& mut? a | b`.
Ident(.., Some(p)) | Box(p) | Ref(p, _, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p,
Ident(.., Some(p)) | Box(p) | Ref(p, _, _)
if let Or(ps) = &p.kind
&& ps.len() > 1 =>
{
p
},
// `&(mut x)`
Ref(p, Pinnedness::Not, Mutability::Not) if matches!(p.kind, Ident(BindingMode::MUT, ..)) => p,
_ => return,