-
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
detect if comparison chain that could be a tuple comparison instead #1111
Comments
Isn't that |
I wasn't aware comparing tuples worked like that, thanks. |
We should be detecting this pattern and suggesting the tuple comparison |
Also when chain if ... else if ... blocks the "if_same_then_else" is inapplicable, because "else if" has one more condition, that means that if and else branches are not the same. My particular sample is here. Should I create another issue to detect "else if"? |
My view on that is that the lint catches what is most of the time a copy-and-paste error and reports it as wanted. For the few cases where that behavior is actually wanted, explicitly |
I'm sorry, but I just don't understand. When I say I'm not asking why false positives are possible. I'm asking for an example when ...else if... looks suspicious. Can you come up with any counter example? |
|
I understand you position now, though it is not correct about Would you at least consider making it 2 different lints so that we could keep disagreeing? one that says "if and else branches are the same" and the other one "there are 2 identical branches in a chain of else-ifs"? |
I think that the lint should be silent for: if a {
X
} else if b {
Y
} else {
X
} The use case is that |
The if_same_then_else lint triggered on the following code I use to sort some stuff:
I'm not sure if Clippy could reason about this or if it's even worth the trouble thinking about that but perhaps this is worthy of a footnote in the wiki?
The text was updated successfully, but these errors were encountered: