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