]> git.lizzy.rs Git - rust.git/blob - tests/ui/derive_ord_xor_partial_ord.rs
Auto merge of #6070 - matsujika:unnecessary_wrap, r=flip1995
[rust.git] / tests / ui / derive_ord_xor_partial_ord.rs
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 {
10     fn eq(&self, _: &u64) -> bool {
11         true
12     }
13 }
14
15 impl PartialOrd<u64> for DeriveBoth {
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 {
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 {
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 {
43     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 {
63         fn cmp(&self, other: &Self) -> Ordering {
64             Ordering::Less
65         }
66     }
67 }
68
69 fn main() {}