Fix manual_range_contains
false negative with chains of &&
and ||
#8884
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #8745
Since the precedence for
&&
is the same as itself the HIR for a chain of&&
ends up with a right skewed tree like:So only the leftmost
&&
was actually "fully" checked, the top level was justc2
and&&
so themanual_range_contains
lint won't apply. This change makes it also checkc2
withc1
.There's a bit of a hacky solution in the second commit to check if the number of open/closing parens in the snippet match. This is to prevent a case like
((x % 2 == 0) || (x < 0)) || (x >= 10)
from offering a suggestion like((x % 2 == 0) || !(0..10).contains(&x)
which now won't compile.Any suggestions for that paren hack welcome, kinda new to working on this so not too sure about possible solutions :) it's weird because I don't know how else to check for parens in HIR considering they're removed when lowering AST.
changelog: Fix [
manual_range_contains
] false negative with chains of&&
and||