1 #![warn(clippy::derive_ord_xor_partial_ord)]
2 #![allow(clippy::unnecessary_wraps)]
3
4 use std::cmp::Ordering;
5
6 #[derive(PartialOrd, Ord, PartialEq, Eq)]
7 struct DeriveBoth;
8
9 impl PartialEq<u64> for DeriveBoth {
eq(&self, _: &u64) -> bool10 fn eq(&self, _: &u64) -> bool {
11 true
12 }
13 }
14
15 impl PartialOrd<u64> for DeriveBoth {
partial_cmp(&self, _: &u64) -> Option<Ordering>16 fn partial_cmp(&self, _: &u64) -> Option<Ordering> {
17 Some(Ordering::Equal)
18 }
19 }
20
21 #[derive(Ord, PartialEq, Eq)]
22 struct DeriveOrd;
23
24 impl PartialOrd for DeriveOrd {
partial_cmp(&self, other: &Self) -> Option<Ordering>25 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
26 Some(other.cmp(self))
27 }
28 }
29
30 #[derive(Ord, PartialEq, Eq)]
31 struct DeriveOrdWithExplicitTypeVariable;
32
33 impl PartialOrd<DeriveOrdWithExplicitTypeVariable> for DeriveOrdWithExplicitTypeVariable {
partial_cmp(&self, other: &Self) -> Option<Ordering>34 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
35 Some(other.cmp(self))
36 }
37 }
38
39 #[derive(PartialOrd, PartialEq, Eq)]
40 struct DerivePartialOrd;
41
42 impl std::cmp::Ord for DerivePartialOrd {
cmp(&self, other: &Self) -> Ordering43 fn cmp(&self, other: &Self) -> Ordering {
44 Ordering::Less
45 }
46 }
47
48 #[derive(PartialOrd, PartialEq, Eq)]
49 struct ImplUserOrd;
50
51 trait Ord {}
52
53 // We don't want to lint on user-defined traits called `Ord`
54 impl Ord for ImplUserOrd {}
55
56 mod use_ord {
57 use std::cmp::{Ord, Ordering};
58
59 #[derive(PartialOrd, PartialEq, Eq)]
60 struct DerivePartialOrdInUseOrd;
61
62 impl Ord for DerivePartialOrdInUseOrd {
cmp(&self, other: &Self) -> Ordering63 fn cmp(&self, other: &Self) -> Ordering {
64 Ordering::Less
65 }
66 }
67 }
68
main()69 fn main() {}
70