]> git.lizzy.rs Git - rust.git/blob - src/test/ui/cmp-default.rs
Rollup merge of #61207 - taiki-e:arbitrary_self_types-lifetime-elision-2, r=Centril
[rust.git] / src / test / ui / cmp-default.rs
1 // run-pass
2
3 use std::cmp::Ordering;
4
5 // Test default methods in PartialOrd and PartialEq
6 //
7 #[derive(Debug)]
8 struct Fool(bool);
9
10 impl PartialEq for Fool {
11     fn eq(&self, other: &Fool) -> bool {
12         let Fool(this) = *self;
13         let Fool(other) = *other;
14         this != other
15     }
16 }
17
18 struct Int(isize);
19
20 impl PartialEq for Int {
21     fn eq(&self, other: &Int) -> bool {
22         let Int(this) = *self;
23         let Int(other) = *other;
24         this == other
25     }
26 }
27
28 impl PartialOrd for Int {
29     fn partial_cmp(&self, other: &Int) -> Option<Ordering> {
30         let Int(this) = *self;
31         let Int(other) = *other;
32         this.partial_cmp(&other)
33     }
34 }
35
36 struct RevInt(isize);
37
38 impl PartialEq for RevInt {
39     fn eq(&self, other: &RevInt) -> bool {
40         let RevInt(this) = *self;
41         let RevInt(other) = *other;
42         this == other
43     }
44 }
45
46 impl PartialOrd for RevInt {
47     fn partial_cmp(&self, other: &RevInt) -> Option<Ordering> {
48         let RevInt(this) = *self;
49         let RevInt(other) = *other;
50         other.partial_cmp(&this)
51     }
52 }
53
54 pub fn main() {
55     assert!(Int(2) >  Int(1));
56     assert!(Int(2) >= Int(1));
57     assert!(Int(1) >= Int(1));
58     assert!(Int(1) <  Int(2));
59     assert!(Int(1) <= Int(2));
60     assert!(Int(1) <= Int(1));
61
62     assert!(RevInt(2) <  RevInt(1));
63     assert!(RevInt(2) <= RevInt(1));
64     assert!(RevInt(1) <= RevInt(1));
65     assert!(RevInt(1) >  RevInt(2));
66     assert!(RevInt(1) >= RevInt(2));
67     assert!(RevInt(1) >= RevInt(1));
68
69     assert_eq!(Fool(true), Fool(false));
70     assert!(Fool(true)  != Fool(true));
71     assert!(Fool(false) != Fool(false));
72     assert_eq!(Fool(false), Fool(true));
73 }