-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
Summary
In addition to the correct Some(self.cmp(other)), the lint will accept the probably incorrect Some(other.cmp(self)) (and probably other forms of Some(_.cmp(_))) as the canonical implementation of PartialOrd::partial_cmp().
Lint Name
non_canonical_partial_ord_impl
Reproducer
I tried this code:
#![deny(clippy::non_canonical_partial_ord_impl)]
fn main() {
#[derive(Eq, PartialEq)]
struct S(i32);
impl Ord for S {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
todo!()
}
}
impl PartialOrd for S {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(other.cmp(self)) // Note inversion of receiver and argument
}
}
}I expected to see this happen: partial_cmp() should warn about a non-canonical implementation
Instead, this happened: nothing
Version
rustc 1.88.0-nightly (d5b4c2e4f 2025-04-02)
binary: rustc
commit-hash: d5b4c2e4f19b6d7037371cdaecc3cc2c701c68df
commit-date: 2025-04-02
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.1
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't