Skip to content

Commit

Permalink
do not trigger MATCH_LIKE_MATCHES_MACRO lint with attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-700 committed Nov 5, 2020
1 parent 0d2f1ae commit b8fc060
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 b8fc060

Please sign in to comment.