Skip to content

Commit b627731

Browse files
committed
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
2 parents e42ba48 + 84cdb0a commit b627731

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

clippy_lints/src/matches.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ declare_clippy_lint! {
459459
///
460460
/// **Why is this bad?** Readability and needless complexity.
461461
///
462-
/// **Known problems:** None
462+
/// **Known problems:** This lint falsely triggers, if there are arms with
463+
/// `cfg` attributes that remove an arm evaluating to `false`.
463464
///
464465
/// **Example:**
465466
/// ```rust
@@ -1167,13 +1168,16 @@ fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr
11671168
if b0 != b1;
11681169
let if_guard = &b0_arms[0].guard;
11691170
if if_guard.is_none() || b0_arms.len() == 1;
1171+
if b0_arms[0].attrs.is_empty();
11701172
if b0_arms[1..].iter()
11711173
.all(|arm| {
11721174
find_bool_lit(&arm.body.kind, desugared).map_or(false, |b| b == b0) &&
1173-
arm.guard.is_none()
1175+
arm.guard.is_none() && arm.attrs.is_empty()
11741176
});
11751177
then {
1176-
let mut applicability = Applicability::MachineApplicable;
1178+
// The suggestion may be incorrect, because some arms can have `cfg` attributes
1179+
// evaluated into `false` and so such arms will be stripped before.
1180+
let mut applicability = Applicability::MaybeIncorrect;
11771181
let pat = {
11781182
use itertools::Itertools as _;
11791183
b0_arms.iter()

0 commit comments

Comments
 (0)