about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/matches/mod.rs5
-rw-r--r--tests/ui/single_match.fixed14
-rw-r--r--tests/ui/single_match.rs14
3 files changed, 33 insertions, 0 deletions
diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs
index 3fbd0867ea9..00fa3eb9bfe 100644
--- a/clippy_lints/src/matches/mod.rs
+++ b/clippy_lints/src/matches/mod.rs
@@ -38,6 +38,11 @@ declare_clippy_lint! {
     /// Checks for matches with a single arm where an `if let`
     /// will usually suffice.
     ///
+    /// This intentionally does not lint if there are comments
+    /// inside of the other arm, so as to allow the user to document
+    /// why having another explicit pattern with an empty body is necessary,
+    /// or because the comments need to be preserved for other reasons.
+    ///
     /// ### Why is this bad?
     /// Just readability – `if let` nests less than a `match`.
     ///
diff --git a/tests/ui/single_match.fixed b/tests/ui/single_match.fixed
index 0da59a53320..e7b1fd6a85f 100644
--- a/tests/ui/single_match.fixed
+++ b/tests/ui/single_match.fixed
@@ -237,4 +237,18 @@ mod issue8634 {
             },
         }
     }
+
+    fn block_comment(x: Result<i32, SomeError>) {
+        match x {
+            Ok(y) => {
+                println!("Yay! {y}");
+            },
+            Err(_) => {
+                /*
+                let's make sure that this also
+                does not lint block comments.
+                */
+            },
+        }
+    }
 }
diff --git a/tests/ui/single_match.rs b/tests/ui/single_match.rs
index 7afadececbf..1515a7053e5 100644
--- a/tests/ui/single_match.rs
+++ b/tests/ui/single_match.rs
@@ -295,4 +295,18 @@ mod issue8634 {
             },
         }
     }
+
+    fn block_comment(x: Result<i32, SomeError>) {
+        match x {
+            Ok(y) => {
+                println!("Yay! {y}");
+            },
+            Err(_) => {
+                /*
+                let's make sure that this also
+                does not lint block comments.
+                */
+            },
+        }
+    }
 }