]> git.proxmox.com Git - rustc.git/blame - src/test/ui/cmp-default.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / src / test / ui / cmp-default.rs
CommitLineData
416331ca
XL
1// run-pass
2
1a4d82fc
JJ
3use std::cmp::Ordering;
4
5// Test default methods in PartialOrd and PartialEq
6//
62682a34 7#[derive(Debug)]
1a4d82fc
JJ
8struct Fool(bool);
9
10impl 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
c34b1796 18struct Int(isize);
1a4d82fc
JJ
19
20impl 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
28impl 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
c34b1796 36struct RevInt(isize);
1a4d82fc
JJ
37
38impl 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
46impl 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
54pub 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
62682a34 69 assert_eq!(Fool(true), Fool(false));
1a4d82fc
JJ
70 assert!(Fool(true) != Fool(true));
71 assert!(Fool(false) != Fool(false));
62682a34 72 assert_eq!(Fool(false), Fool(true));
1a4d82fc 73}