Skip to content

Commit 32a3744

Browse files
authored
refactor(mut_reference): replace match with if-let to reduce nesting (#14890)
One downside to this is that, since the patterns matched against (on the left) are quite long, it's a bit difficult to see what's even getting matched. Using `matches!()` could help with that changelog: none
2 parents 954034b + c256bcc commit 32a3744

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

clippy_lints/src/mut_reference.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,19 @@ fn check_arguments<'tcx>(
7979
name: &str,
8080
fn_kind: &str,
8181
) {
82-
match type_definition.kind() {
83-
ty::FnDef(..) | ty::FnPtr(..) => {
84-
let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
85-
for (argument, parameter) in iter::zip(arguments, parameters) {
86-
match parameter.kind() {
87-
ty::Ref(_, _, Mutability::Not) | ty::RawPtr(_, Mutability::Not) => {
88-
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) = argument.kind {
89-
span_lint(
90-
cx,
91-
UNNECESSARY_MUT_PASSED,
92-
argument.span,
93-
format!("the {fn_kind} `{name}` doesn't need a mutable reference"),
94-
);
95-
}
96-
},
97-
_ => (),
98-
}
82+
if let ty::FnDef(..) | ty::FnPtr(..) = type_definition.kind() {
83+
let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
84+
for (argument, parameter) in iter::zip(arguments, parameters) {
85+
if let ty::Ref(_, _, Mutability::Not) | ty::RawPtr(_, Mutability::Not) = parameter.kind()
86+
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) = argument.kind
87+
{
88+
span_lint(
89+
cx,
90+
UNNECESSARY_MUT_PASSED,
91+
argument.span,
92+
format!("the {fn_kind} `{name}` doesn't need a mutable reference"),
93+
);
9994
}
100-
},
101-
_ => (),
95+
}
10296
}
10397
}

0 commit comments

Comments
 (0)