1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 
11 // no-pretty-expanded FIXME #15189
12 
13 #[cfg(feature = "use_core")]
14 extern crate core;
15 
16 #[macro_use]
17 extern crate derivative;
18 
19 #[derive(Derivative)]
20 #[derivative(
21     PartialEq = "feature_allow_slow_enum",
22     Eq,
23     PartialOrd = "feature_allow_slow_enum",
24     Ord = "feature_allow_slow_enum"
25 )]
26 enum ES<T> {
27     ES1 { x: T },
28     ES2 { x: T, y: T },
29 }
30 
31 
main()32 pub fn main() {
33     let (es11, es12, es21, es22) = (
34         ES::ES1 { x: 1 },
35         ES::ES1 { x: 2 },
36         ES::ES2 { x: 1, y: 1 },
37         ES::ES2 { x: 1, y: 2 },
38     );
39 
40     // in order for both PartialOrd and Ord
41     let ess = [es11, es12, es21, es22];
42 
43     for (i, es1) in ess.iter().enumerate() {
44         for (j, es2) in ess.iter().enumerate() {
45             let ord = i.cmp(&j);
46 
47             let eq = i == j;
48             let (lt, le) = (i < j, i <= j);
49             let (gt, ge) = (i > j, i >= j);
50 
51             // PartialEq
52             assert_eq!(*es1 == *es2, eq);
53             assert_eq!(*es1 != *es2, !eq);
54 
55             // PartialOrd
56             assert_eq!(*es1 < *es2, lt);
57             assert_eq!(*es1 > *es2, gt);
58 
59             assert_eq!(*es1 <= *es2, le);
60             assert_eq!(*es1 >= *es2, ge);
61 
62             // Ord
63             assert_eq!(es1.cmp(es2), ord);
64         }
65     }
66 }
67