From 4d1362c16bc0769a83f50047ed4a257e6644f89c Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 8 Oct 2023 14:38:07 +0900 Subject: [PATCH] Fix clippy::non_canonical_partial_ord_impl warning in example ``` warning: non-canonical implementation of `partial_cmp` on an `Ord` type --> examples/with-metadata.rs:31:1 | 31 | / impl PartialOrd for ByDuration { 32 | | fn partial_cmp(&self, other: &Self) -> Option { | | _______________________________________________________________________- 33 | || self.duration() 34 | || .partial_cmp(&other.duration()) 35 | || .map(|ord| ord.reverse()) 36 | || } | ||_____- help: change this to: `{ Some(self.cmp(other)) }` 37 | | } | |__^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_canonical_partial_ord_impl = note: `#[warn(clippy::non_canonical_partial_ord_impl)]` on by default ``` --- examples/with-metadata.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/with-metadata.rs b/examples/with-metadata.rs index d7adb19..ed84e31 100644 --- a/examples/with-metadata.rs +++ b/examples/with-metadata.rs @@ -30,9 +30,7 @@ impl Eq for ByDuration {} impl PartialOrd for ByDuration { fn partial_cmp(&self, other: &Self) -> Option { - self.duration() - .partial_cmp(&other.duration()) - .map(|ord| ord.reverse()) + Some(self.cmp(other)) } }