@@ -44,20 +44,50 @@ declare_clippy_lint! {
44
44
}
45
45
46
46
declare_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`:
48
55
///
49
- /// **Why is this bad?**
56
+ /// ```text
57
+ /// k1.cmp(&k2) == k1.partial_cmp(&k2).unwrap()
58
+ /// ```
50
59
///
51
60
/// **Known problems:** None.
52
61
///
53
62
/// **Example:**
54
63
///
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
+ /// }
57
71
/// ```
58
72
/// 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;
61
91
/// ```
62
92
pub DERIVE_ORD_XOR_PARTIAL_ORD ,
63
93
correctness,
0 commit comments