-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
"unnecessary negation" (if-not-else) is a bit annoying #859
Comments
We could treat if elseif else chains as ordered and not lint. |
So I see two possibilities:
Possibly both. |
👍 I’ve found that lint to be rather annoying myself. |
Make if_not_else lint Allow by default (fixes #859)
For anyone stumbling upon this in the future by browsing related issues to lints (as I am), this is how I personally would write this example, rather than considering it an exception to the lint: if some_error_condition {
return Err(some_error);
}
if some_other_error_condition {
return Err(some_other_error);
}
Ok(result) Independently of whether I use this lint, I usually use early This is just my preference, but figured it might be worth noting for the record. It's also worth noting this advice doesn't apply if the branch isn't meant to return (unless it happens to be practical to extract the #7895 covers this whole issue anyway. |
Suppose the following case:
If
some_other_error_condition
happens to bea != b
, the lint will trigger. However, I don't want to move the Ok case inbetween the Err cases.The text was updated successfully, but these errors were encountered: