summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.rs
blob: 1fb3d51c46dc774e3b1f80a262ec5cc47f816a87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#![warn(clippy::derive_ord_xor_partial_ord)]
#![allow(clippy::unnecessary_wraps)]
#![allow(clippy::incorrect_partial_ord_impl_on_ord_type)]

use std::cmp::Ordering;

#[derive(PartialOrd, Ord, PartialEq, Eq)]
struct DeriveBoth;

impl PartialEq<u64> for DeriveBoth {
    fn eq(&self, _: &u64) -> bool {
        true
    }
}

impl PartialOrd<u64> for DeriveBoth {
    fn partial_cmp(&self, _: &u64) -> Option<Ordering> {
        Some(Ordering::Equal)
    }
}

#[derive(Ord, PartialEq, Eq)]
struct DeriveOrd;

impl PartialOrd for DeriveOrd {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(other.cmp(self))
    }
}

#[derive(Ord, PartialEq, Eq)]
struct DeriveOrdWithExplicitTypeVariable;

impl PartialOrd<DeriveOrdWithExplicitTypeVariable> for DeriveOrdWithExplicitTypeVariable {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(other.cmp(self))
    }
}

#[derive(PartialOrd, PartialEq, Eq)]
struct DerivePartialOrd;

impl std::cmp::Ord for DerivePartialOrd {
    fn cmp(&self, other: &Self) -> Ordering {
        Ordering::Less
    }
}

#[derive(PartialOrd, PartialEq, Eq)]
struct ImplUserOrd;

trait Ord {}

// We don't want to lint on user-defined traits called `Ord`
impl Ord for ImplUserOrd {}

mod use_ord {
    use std::cmp::{Ord, Ordering};

    #[derive(PartialOrd, PartialEq, Eq)]
    struct DerivePartialOrdInUseOrd;

    impl Ord for DerivePartialOrdInUseOrd {
        fn cmp(&self, other: &Self) -> Ordering {
            Ordering::Less
        }
    }
}

fn main() {}