]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-15523.rs
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
[rust.git] / src / test / run-pass / issue-15523.rs
1 // Copyright 2015 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 // Issue 15523: derive(PartialOrd) should use the provided
12 // discriminant values for the derived ordering.
13 //
14 // This is checking the basic functionality.
15
16 #[derive(PartialEq, PartialOrd)]
17 enum E1 {
18     Pos2 = 2,
19     Neg1 = -1,
20     Pos1 = 1,
21 }
22
23 #[derive(PartialEq, PartialOrd)]
24 #[repr(u8)]
25 enum E2 {
26     Pos2 = 2,
27     PosMax = !0 as u8,
28     Pos1 = 1,
29 }
30
31 #[derive(PartialEq, PartialOrd)]
32 #[repr(i8)]
33 enum E3 {
34     Pos2 = 2,
35     Neg1 = -1_i8,
36     Pos1 = 1,
37 }
38
39 fn main() {
40     assert!(E1::Pos2 > E1::Pos1);
41     assert!(E1::Pos1 > E1::Neg1);
42     assert!(E1::Pos2 > E1::Neg1);
43
44     assert!(E2::Pos2 > E2::Pos1);
45     assert!(E2::Pos1 < E2::PosMax);
46     assert!(E2::Pos2 < E2::PosMax);
47
48     assert!(E3::Pos2 > E3::Pos1);
49     assert!(E3::Pos1 > E3::Neg1);
50     assert!(E3::Pos2 > E3::Neg1);
51 }