redundant_pattern_matching added support for more complex patterns
#16254
+165
−9
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.
changelog: [
redundant_pattern_matching]: Improved this lint by allowing to handle more complex patterns beyond just_Before, the lint would only activate when the pattern was an
_or if the constructor was a unit constructor (likeNone):But now it can also catch more complicated nested patterns
The only thing it doesn't support right now is if the redundancy happens because of an or pattern.
Edit:
I also made that the only slice patterns that are checked are
[..]and[]because in all the other cases we are constraining the size of what we are matching to be bigger:If we were to blindly apply the lint here we would get:
And the condition would (incorrectly) be true even if the slice was the less than length two.
For
[T: N]we could make it work and only activate the lint if for the pattern[x0, ... xn]N > n.fixes #16235