From b8fc06084de7057e69b8286db1607ce2afc94201 Mon Sep 17 00:00:00 2001 From: Aleksei Latyshev Date: Wed, 4 Nov 2020 21:16:25 +0300 Subject: [PATCH] do not trigger MATCH_LIKE_MATCHES_MACRO lint with attrs --- clippy_lints/src/matches.rs | 3 ++- tests/ui/match_expr_like_matches_macro.fixed | 10 ++++++++++ tests/ui/match_expr_like_matches_macro.rs | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index c6dca54e2509..a69b3609a1f7 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -1134,10 +1134,11 @@ fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr if b0 != b1; let if_guard = &b0_arms[0].guard; if if_guard.is_none() || b0_arms.len() == 1; + if b0_arms[0].attrs.is_empty(); if b0_arms[1..].iter() .all(|arm| { find_bool_lit(&arm.body.kind, desugared).map_or(false, |b| b == b0) && - arm.guard.is_none() + arm.guard.is_none() && arm.attrs.is_empty() }); then { let mut applicability = Applicability::MachineApplicable; diff --git a/tests/ui/match_expr_like_matches_macro.fixed b/tests/ui/match_expr_like_matches_macro.fixed index 7f4ebf566733..390aa5d5a497 100644 --- a/tests/ui/match_expr_like_matches_macro.fixed +++ b/tests/ui/match_expr_like_matches_macro.fixed @@ -99,4 +99,14 @@ fn main() { _ => false, }; } + { + // issue6289 + // no lint + let _ans = match x { + E::A(_) => true, + #[cfg(target_os = "linux")] + E::B(_) => true, + _ => false, + }; + } } diff --git a/tests/ui/match_expr_like_matches_macro.rs b/tests/ui/match_expr_like_matches_macro.rs index aee56dd4a5ef..ed71047b3911 100644 --- a/tests/ui/match_expr_like_matches_macro.rs +++ b/tests/ui/match_expr_like_matches_macro.rs @@ -119,4 +119,14 @@ fn main() { _ => false, }; } + { + // issue6289 + // no lint + let _ans = match x { + E::A(_) => true, + #[cfg(target_os = "linux")] + E::B(_) => true, + _ => false, + }; + } }