-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
suggest replacing if comparison chain with cmp
match
#4531
Comments
I can take a stab at this issue |
Thanks! Let us know if you have any questions. Also make sure to take a look at https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md. That's a really good introduction on writing lints. |
Add a new lint for comparison chains changelog: Adds a new lint: `comparison_chain`. `comparison_chain` lints all `if` conditional chains where all the conditions are binary comparisons on the same two operands and will suggest a rewrite with `match`. Closes #4531.
This requires an additional import and is harder to read. Why is this a default lint? |
I don't think it's harder to read. imo this is much clearer what's going on, because you have the three cases very explicitly. Also I don't consider additional or fewer imports to be relevant for whether a lint is useful or not |
In my book Why would I import more traits and enums from std if I can achieve the same thing without? e.g. I don't import FWIW this lint also triggers for code that does not intend to handle all three cases: getsentry/symbolic@f928869#diff-526c79c0b4fc6984353f21705ba99a12R396 and it also triggers for code that wants to partialcmp instead of cmp. |
In the case of symbolic in particular it’s especially weird because the type doesn’t even implement |
That looks also fine to me. I think it should be warn by default. Since some situations require To me this lint is a clear improvement (especially since it does help catch bugs). |
FWIW, I dislike this lint, and find the direct comparisons easier to read. As a result, linebender/druid#406 is adding |
@raphlinus that's OK. Readability is not something that can be decided in the general case, but must be approached on a case-by-case basis. |
Cool, so you agree such a general lint in defaults is wrong? |
A check for
This is a
See #4725 |
If one writes
one should instead be writing
The text was updated successfully, but these errors were encountered: