Fix issue with mismatched parens in suggestion
This commit is contained in:
parent
78f7e3745f
commit
257f09776a
@ -296,10 +296,15 @@ fn check_possible_range_contains(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the LHS is the same operator, we have to recurse to get the "real" RHS, since they have
|
// If the LHS is the same operator, we have to recurse to get the "real" RHS, since they have
|
||||||
// the same operator precedence.
|
// the same operator precedence
|
||||||
if let ExprKind::Binary(ref lhs_op, _left, new_lhs) = left.kind {
|
if_chain! {
|
||||||
if op == lhs_op.node {
|
if let ExprKind::Binary(ref lhs_op, _left, new_lhs) = left.kind;
|
||||||
|
if op == lhs_op.node;
|
||||||
let new_span = Span::new(new_lhs.span.lo(), right.span.hi(), expr.span.ctxt(), expr.span.parent());
|
let new_span = Span::new(new_lhs.span.lo(), right.span.hi(), expr.span.ctxt(), expr.span.parent());
|
||||||
|
if let Some(snip) = &snippet_opt(cx, new_span);
|
||||||
|
// Do not continue if we have mismatched number of parens, otherwise the suggestion is wrong
|
||||||
|
if snip.matches('(').count() == snip.matches(')').count();
|
||||||
|
then {
|
||||||
check_possible_range_contains(cx, op, new_lhs, right, expr, new_span);
|
check_possible_range_contains(cx, op, new_lhs, right, expr, new_span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,8 @@ fn main() {
|
|||||||
let z = 42;
|
let z = 42;
|
||||||
(0..=10).contains(&x) && (0..=10).contains(&z);
|
(0..=10).contains(&x) && (0..=10).contains(&z);
|
||||||
!(0..10).contains(&x) || !(0..10).contains(&z);
|
!(0..10).contains(&x) || !(0..10).contains(&z);
|
||||||
|
// Make sure operators in parens don't give a breaking suggestion
|
||||||
|
((x % 2 == 0) || (x < 0)) || (x >= 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix #6373
|
// Fix #6373
|
||||||
|
@ -54,6 +54,8 @@ fn main() {
|
|||||||
let z = 42;
|
let z = 42;
|
||||||
(x >= 0) && (x <= 10) && (z >= 0) && (z <= 10);
|
(x >= 0) && (x <= 10) && (z >= 0) && (z <= 10);
|
||||||
(x < 0) || (x >= 10) || (z < 0) || (z >= 10);
|
(x < 0) || (x >= 10) || (z < 0) || (z >= 10);
|
||||||
|
// Make sure operators in parens don't give a breaking suggestion
|
||||||
|
((x % 2 == 0) || (x < 0)) || (x >= 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix #6373
|
// Fix #6373
|
||||||
|
Loading…
x
Reference in New Issue
Block a user