Skip to content

Commit c44d40e

Browse files
committed
Test case for new derive(PartialOrd) expansion.
1 parent 6118795 commit c44d40e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/test/run-pass/issue-15523.rs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
#[derive(PartialEq, PartialOrd)]
15+
enum E1 {
16+
Pos2 = 2,
17+
Neg1 = -1,
18+
Pos1 = 1,
19+
}
20+
21+
#[derive(PartialEq, PartialOrd)]
22+
#[repr(u8)]
23+
enum E2 {
24+
Pos2 = 2,
25+
PosMax = !0 as u8,
26+
Pos1 = 1,
27+
}
28+
29+
#[derive(PartialEq, PartialOrd)]
30+
#[repr(i8)]
31+
enum E3 {
32+
Pos2 = 2,
33+
Neg1 = -1_i8,
34+
Pos1 = 1,
35+
}
36+
37+
fn main() {
38+
assert!(E1::Pos2 > E1::Pos1);
39+
assert!(E1::Pos1 > E1::Neg1);
40+
assert!(E1::Pos2 > E1::Neg1);
41+
42+
assert!(E2::Pos2 > E2::Pos1);
43+
assert!(E2::Pos1 < E2::PosMax);
44+
assert!(E2::Pos2 < E2::PosMax);
45+
46+
assert!(E3::Pos2 > E3::Pos1);
47+
assert!(E3::Pos1 > E3::Neg1);
48+
assert!(E3::Pos2 > E3::Neg1);
49+
}

0 commit comments

Comments
 (0)