-
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
incorrect_partial_ord_impl_on_ord_type false positive: Some(Ord::cmp(self, other))
#11178
Comments
This sort of thing was already brought up: #10788 (comment) It's a bit unfortunate but there's many, many variations of |
It should definitely be noted as a known issue however; not having that was an oversight on my part |
I think there is a degree of difference between |
Yeah it could handle both |
Allow `Self::cmp(self, other)` as a correct impl Fixes #11178 Also no longer checks if the method name is *just* cmp, but the path. That was an oversight on my part ^^ r? `@xFrednet` (and `@blyxyas` too!) changelog: [`incorrect_partial_ord_impl_on_ord_type`]: Now allows non-method calls to `cmp` like `Self::cmp(self, other)`
Summary
Clippy flags the following as an incorrect PartialOrd impl, with a deny-by-default correctness lint:
in favor of preferring:
But there is no correctness difference between these impl, only a stylistic difference.
Lint Name
incorrect_partial_ord_impl_on_ord_type
Reproducer
I consider this a false positive for this lint. If there is a compelling stylistic argument in favor of
self.cmp(other)
overOrd::cmp(self, other)
, that should be at most a warn-by-default style lint, not a deny-by-default correctness lint.I think neither
Some(Ord::cmp(self, other))
norSome(T::cmp(self, other))
should trigger a lint.Currently on GitHub, there are 1.6k search results for "::cmp(self" and 26k search results for "self.cmp(". Clearly there is a preference for
self.cmp(other)
but that is still a significant proportion of users who prefer to write the other, especially in macro-generated code whereself.cmp(other)
might not compile (as is the case above).Version
Additional Labels
@rustbot label +I-suggestion-causes-error
The text was updated successfully, but these errors were encountered: