Skip to content

Commit 09fe163

Browse files
committed
Auto merge of rust-lang#5397 - pmk21:macro-single-match, r=flip1995
Avoid single_match lint in macro rules changelog: none fixes rust-lang#5359
2 parents 1cac2f9 + 79ab054 commit 09fe163

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

Diff for: clippy_lints/src/matches.rs

+5
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
447447
#[rustfmt::skip]
448448
fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
449449
if arms.len() == 2 && arms[0].guard.is_none() && arms[1].guard.is_none() {
450+
if in_macro(expr.span) {
451+
// Don't lint match expressions present in
452+
// macro_rules! block
453+
return;
454+
}
450455
if let PatKind::Or(..) = arms[0].pat.kind {
451456
// don't lint for or patterns for now, this makes
452457
// the lint noisy in unnecessary situations

Diff for: tests/ui/single_match.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,15 @@ fn single_match_know_enum() {
8181
}
8282
}
8383

84-
fn main() {}
84+
macro_rules! single_match {
85+
($num:literal) => {
86+
match $num {
87+
15 => println!("15"),
88+
_ => (),
89+
}
90+
};
91+
}
92+
93+
fn main() {
94+
single_match!(5);
95+
}

Diff for: tests/ui/single_match_else.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,18 @@ fn unwrap_addr() -> Option<&'static ExprNode> {
1818
}
1919
}
2020

21-
fn main() {}
21+
macro_rules! unwrap_addr {
22+
($expression:expr) => {
23+
match $expression {
24+
ExprNode::ExprAddrOf => Some(&NODE),
25+
_ => {
26+
let x = 5;
27+
None
28+
},
29+
}
30+
};
31+
}
32+
33+
fn main() {
34+
unwrap_addr!(ExprNode::Unicorns);
35+
}

0 commit comments

Comments
 (0)