@@ -44,20 +44,50 @@ declare_clippy_lint! {
4444}
4545
4646declare_clippy_lint ! {
47- /// **What it does:**
47+ /// **What it does:** Checks for deriving `Ord` but implementing `PartialOrd`
48+ /// explicitly or vice versa.
49+ ///
50+ /// **Why is this bad?** The implementation of these traits must agree (for
51+ /// example for use with `sort`) so it’s probably a bad idea to use a
52+ /// default-generated `Ord` implementation with an explicitly defined
53+ /// `PartialOrd`. In particular, the following must hold for any type
54+ /// implementing `Ord`:
4855 ///
49- /// **Why is this bad?**
56+ /// ```text
57+ /// k1.cmp(&k2) == k1.partial_cmp(&k2).unwrap()
58+ /// ```
5059 ///
5160 /// **Known problems:** None.
5261 ///
5362 /// **Example:**
5463 ///
55- /// ```rust
56- /// // example code where clippy issues a warning
64+ /// ```rust,ignore
65+ /// #[derive(Ord, PartialEq, Eq)]
66+ /// struct Foo;
67+ ///
68+ /// impl PartialOrd for Foo {
69+ /// ...
70+ /// }
5771 /// ```
5872 /// Use instead:
59- /// ```rust
60- /// // example code which does not raise clippy warning
73+ /// ```rust,ignore
74+ /// #[derive(PartialEq, Eq)]
75+ /// struct Foo;
76+ ///
77+ /// impl PartialOrd for Foo {
78+ /// fn partial_cmp(&self, other: &Foo) -> Option<Ordering> {
79+ /// Some(self.cmp(other))
80+ /// }
81+ /// }
82+ ///
83+ /// impl Ord for Foo {
84+ /// ...
85+ /// }
86+ /// ```
87+ /// or, if you don't need a custom ordering:
88+ /// ```rust,ignore
89+ /// #[derive(Ord, PartialOrd, PartialEq, Eq)]
90+ /// struct Foo;
6191 /// ```
6292 pub DERIVE_ORD_XOR_PARTIAL_ORD ,
6393 correctness,
0 commit comments