about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-11-28 21:58:07 +0000
committerbors <bors@rust-lang.org>2020-11-28 21:58:07 +0000
commitb62773114b34e106201ad1633e45554c21882f4b (patch)
treec16ab55f79f8135a642ab722c78462c3ed95f208
parente42ba4829c02e8308ae142b5a2fd5efb6ccf0a7b (diff)
parent84cdb0a939cec1e13d6f464bb7b036ff3b92dfb0 (diff)
downloadrust-b62773114b34e106201ad1633e45554c21882f4b.tar.gz
rust-b62773114b34e106201ad1633e45554c21882f4b.zip
Auto merge of #6290 - alex-700:fix-match-like-matches, r=flip1995
do not trigger MATCH_LIKE_MATCHES_MACRO lint with attrs

fixed #6289
changelog: do not trigger MATCH_LIKE_MATCHES_MACRO lint for arms with attrs
-rw-r--r--clippy_lints/src/matches.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs
index d695af4de21..665c59d7093 100644
--- a/clippy_lints/src/matches.rs
+++ b/clippy_lints/src/matches.rs
@@ -459,7 +459,8 @@ declare_clippy_lint! {
     ///
     /// **Why is this bad?** Readability and needless complexity.
     ///
-    /// **Known problems:** None
+    /// **Known problems:** This lint falsely triggers, if there are arms with
+    /// `cfg` attributes that remove an arm evaluating to `false`.
     ///
     /// **Example:**
     /// ```rust
@@ -1167,13 +1168,16 @@ 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;
+            // The suggestion may be incorrect, because some arms can have `cfg` attributes
+            // evaluated into `false` and so such arms will be stripped before.
+            let mut applicability = Applicability::MaybeIncorrect;
             let pat = {
                 use itertools::Itertools as _;
                 b0_arms.iter()