-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lint against overlapping pattern ranges and pattern ranges with small holes caught by _
#63987
Comments
cc @varkor |
I poked at the code for a bit and there's already code in |
But do you really want a lint for something that is actually ok-ish to do? I'm not sure about that :/ |
@hellow554 but is it ok? We currently don't lint the following:
It seems to me like a reasonable warn by default lint. Silencing them in the scope close to it is reasonable. For the common case I would prefer to spell out the (one or two) holes in the pattern. In the std there were only two cases this lint triggered and both were checking for unicode ranges ignoring |
I think the better question is: does the lint prevent something harmful? I could see this lint being problematic when coupled with pattern aliases if we added those because there might be partial overlap when you use an or-pattern in combination with two pattern aliases. |
Yes, indeed. Rust doesn't emit a warning, but clippy does:
There are many lints that rustc doesn't cover, but clippy will do. |
The existence of the clippy lint is encouraging, although I'd make the argument that this lint deserves to be in I will say, though, that the output of the clippy lint could be improved slightly by using labels instead of notes and being more explicit on how the ranges overlap:
I think the clear cut case is off-by-one errors when writing That being said, I'd leave it to the lang team to decide whether this lint should be in |
And now we might also get a lint for the case of a small gap: #118879 |
For both exclusive(nightly) and inclusive range patterns, we don't have any lint about overlapping ranges. We probably should complain about
100..=500
being partially covered already. This would minimize the likelihood of the following off-by-one error going unnoticed:It would also be interesting to have a 1 or 2 value wide holes detection in the presence of a
_
pattern to detect confusion between exclusive and inclusive ranges:We already have range coverage checks when not using
_
:We might want to just lint against
_
and instead ask to be explicit to handle the "small holes" case.CC #37854 for the
exclusive_range_pattern
case.The text was updated successfully, but these errors were encountered: