Auto merge of #5397 - pmk21:macro-single-match, r=flip1995

Avoid single_match lint in macro rules

changelog: none
fixes #5359
This commit is contained in:
bors 2020-03-31 11:45:43 +00:00
commit 09fe163c92
3 changed files with 32 additions and 2 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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);
}