about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/matches.rs5
-rw-r--r--tests/ui/single_match.rs13
-rw-r--r--tests/ui/single_match_else.rs16
3 files changed, 32 insertions, 2 deletions
diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs
index a124bf8b8db..20b793f95de 100644
--- a/clippy_lints/src/matches.rs
+++ b/clippy_lints/src/matches.rs
@@ -447,6 +447,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
 #[rustfmt::skip]
 fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
     if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() {
+        if in_macro(expr.span) {
+            // Don't lint match expressions present in
+            // macro_rules! block
+            return;
+        }
         if let PatKind::Or(..) = arms[0].pat.kind {
             // don't lint for or patterns for now, this makes
             // the lint noisy in unnecessary situations
diff --git a/tests/ui/single_match.rs b/tests/ui/single_match.rs
index 980ce9a0fab..1c55af5dfb6 100644
--- a/tests/ui/single_match.rs
+++ b/tests/ui/single_match.rs
@@ -81,4 +81,15 @@ fn single_match_know_enum() {
     }
 }
 
-fn main() {}
+macro_rules! single_match {
+    ($num:literal) => {
+        match $num {
+            15 => println!("15"),
+            _ => (),
+        }
+    };
+}
+
+fn main() {
+    single_match!(5);
+}
diff --git a/tests/ui/single_match_else.rs b/tests/ui/single_match_else.rs
index 37a99de8832..34193be0b75 100644
--- a/tests/ui/single_match_else.rs
+++ b/tests/ui/single_match_else.rs
@@ -18,4 +18,18 @@ fn unwrap_addr() -> Option<&'static ExprNode> {
     }
 }
 
-fn main() {}
+macro_rules! unwrap_addr {
+    ($expression:expr) => {
+        match $expression {
+            ExprNode::ExprAddrOf => Some(&NODE),
+            _ => {
+                let x = 5;
+                None
+            },
+        }
+    };
+}
+
+fn main() {
+    unwrap_addr!(ExprNode::Unicorns);
+}