-
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
False positive: nonminimal_bool
for types which implement PartialOrd
but not Ord
#2626
Comments
Can you create a small example that we can use for our test suite? I tried, but failed: https://play.rust-lang.org/?gist=2261653bc50d1ca6d8e0e0b7c1caf3e1&version=stable all assertions succeed, I would have expected one of them to fail. |
There seems to something weird with the derived If you exchange https://play.rust-lang.org/?gist=25c68ced5fa5fb0c2470f51490998d70&version=stable |
We should be able to bail out on those optimizations when the type does not impl If we just allow this pattern without a new lint it'll show up in the next underhanded rust competition |
I am totally with you and would encourage a related lint warning about this. This issue is only here to warn about the false positive. |
I would like to fix that issue and introduce the missing lint. |
Great! It's all yours |
The
nonminimal_bool
lint suggests to minimize the following expression!(a <= b)
intoa > b
. While this is a proper improvement for types implementingOrd
it doesn't fit for all types ofPartialOrd
and would actually change the result of the expression as it means 'greater or incomparable' and not just 'greater'.Maybe clippy should instead suggest to rewrite the expression using the
partial_cmp()
method and a match statement.Example:
https://play.rust-lang.org/?gist=25676640c1f106e733d008dc224a9d49&version=stable
The text was updated successfully, but these errors were encountered: