about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTimo <30553356+y21@users.noreply.github.com>2025-05-26 10:13:33 +0000
committerGitHub <noreply@github.com>2025-05-26 10:13:33 +0000
commit32a3744efc15f5bb3024cefbb2641fe238f319f2 (patch)
tree6d23bd4ec0b3cfd4d54be1ac9293a97cd5d95fae
parent954034b4973fca154a346b39c8a8e628e31a146b (diff)
parentc256bcc0573fc9ffe254d1ce298a6aef9d4305d0 (diff)
downloadrust-32a3744efc15f5bb3024cefbb2641fe238f319f2.tar.gz
rust-32a3744efc15f5bb3024cefbb2641fe238f319f2.zip
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
-rw-r--r--clippy_lints/src/mut_reference.rs32
1 files changed, 13 insertions, 19 deletions
diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs
index 2fd1049f42e..2f1ab3d2652 100644
--- a/clippy_lints/src/mut_reference.rs
+++ b/clippy_lints/src/mut_reference.rs
@@ -79,25 +79,19 @@ fn check_arguments<'tcx>(
     name: &str,
     fn_kind: &str,
 ) {
-    match type_definition.kind() {
-        ty::FnDef(..) | ty::FnPtr(..) => {
-            let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
-            for (argument, parameter) in iter::zip(arguments, parameters) {
-                match parameter.kind() {
-                    ty::Ref(_, _, Mutability::Not) | ty::RawPtr(_, Mutability::Not) => {
-                        if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) = argument.kind {
-                            span_lint(
-                                cx,
-                                UNNECESSARY_MUT_PASSED,
-                                argument.span,
-                                format!("the {fn_kind} `{name}` doesn't need a mutable reference"),
-                            );
-                        }
-                    },
-                    _ => (),
-                }
+    if let ty::FnDef(..) | ty::FnPtr(..) = type_definition.kind() {
+        let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
+        for (argument, parameter) in iter::zip(arguments, parameters) {
+            if let ty::Ref(_, _, Mutability::Not) | ty::RawPtr(_, Mutability::Not) = parameter.kind()
+                && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) = argument.kind
+            {
+                span_lint(
+                    cx,
+                    UNNECESSARY_MUT_PASSED,
+                    argument.span,
+                    format!("the {fn_kind} `{name}` doesn't need a mutable reference"),
+                );
             }
-        },
-        _ => (),
+        }
     }
 }