Fix false positive in MATCH_SAME_ARMS and guards

This commit is contained in:
mcarton 2016-03-29 01:39:35 +02:00
parent 9cbfa5dbc9
commit 0939f5a2ec
2 changed files with 15 additions and 2 deletions

View file

@ -132,13 +132,15 @@ fn lint_match_arms(cx: &LateContext, expr: &Expr) {
};
let eq = |lhs: &Arm, rhs: &Arm| -> bool {
SpanlessEq::new(cx).eq_expr(&lhs.body, &rhs.body) &&
// Arms with a guard are ignored, those cant always be merged together
lhs.guard.is_none() && rhs.guard.is_none() &&
SpanlessEq::new(cx).eq_expr(&lhs.body, &rhs.body) &&
// all patterns should have the same bindings
bindings(cx, &lhs.pats[0]) == bindings(cx, &rhs.pats[0])
};
if let ExprMatch(_, ref arms, MatchSource::Normal) = expr.node {
if let Some((i, j)) = search_same(&**arms, hash, eq) {
if let Some((i, j)) = search_same(&arms, hash, eq) {
span_note_and_lint(cx,
MATCH_SAME_ARMS,
j.body.span,