about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-03-31 11:45:43 +0000
committerbors <bors@rust-lang.org>2020-03-31 11:45:43 +0000
commit09fe163c9290b8aa573decb25d5b4b02f33e481e (patch)
tree28cb312b81b4845e4362fd31bd5b430c4c98c2c0
parent1cac2f9e8601a952afa1c90c7b61c143108c3542 (diff)
parent79ab05458fb8eea29f1ebf9c15e73de9326eb0d5 (diff)
downloadrust-09fe163c9290b8aa573decb25d5b4b02f33e481e.tar.gz
rust-09fe163c9290b8aa573decb25d5b4b02f33e481e.zip
Auto merge of #5397 - pmk21:macro-single-match, r=flip1995
Avoid single_match lint in macro rules

changelog: none
fixes #5359
-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);
+}