Skip to content

Commit

Permalink
Auto merge of #6290 - alex-700:fix-match-like-matches, r=matthiaskrgr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Nov 6, 2020
2 parents 2ea08e1 + c6efae9 commit b7715f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/match_expr_like_matches_macro.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
}
10 changes: 10 additions & 0 deletions tests/ui/match_expr_like_matches_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
}

0 comments on commit b7715f2

Please sign in to comment.