diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index a124bf8b8db9..20b793f95ded 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 980ce9a0fabe..1c55af5dfb67 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 37a99de8832c..34193be0b75e 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); +}