about summary refs log tree commit diff
diff options
context:
space:
mode:
authory21 <30553356+y21@users.noreply.github.com>2023-06-19 20:07:31 +0200
committery21 <30553356+y21@users.noreply.github.com>2023-06-19 20:07:31 +0200
commit2e856fa99bc2c7f03c65fd89e44ef22509708e0d (patch)
tree814b1ec9dc3eeac5bb067a5b6fbbc9e6ba2d6bdd
parentd7e723441ed8747e6e280808abd0e99da40d2100 (diff)
downloadrust-2e856fa99bc2c7f03c65fd89e44ef22509708e0d.tar.gz
rust-2e856fa99bc2c7f03c65fd89e44ef22509708e0d.zip
add test for block comment and add note to description
-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.
+                */
+            },
+        }
+    }
 }