Skip to content

Commit 47016f9

Browse files
committed
Test case for 64-bit corner cases where truncation occurred before prior commit.
1 parent 781fc90 commit 47016f9

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

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

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 test is checking corner cases that arise when you have
15+
// 64-bit values in the variants.
16+
17+
#[derive(PartialEq, PartialOrd)]
18+
#[repr(u64)]
19+
enum Eu64 {
20+
Pos2 = 2,
21+
PosMax = !0,
22+
Pos1 = 1,
23+
}
24+
25+
#[derive(PartialEq, PartialOrd)]
26+
#[repr(i64)]
27+
enum Ei64 {
28+
Pos2 = 2,
29+
Neg1 = -1,
30+
NegMin = 1 << 63,
31+
PosMax = !(1 << 63),
32+
Pos1 = 1,
33+
}
34+
35+
fn main() {
36+
assert!(Eu64::Pos2 > Eu64::Pos1);
37+
assert!(Eu64::Pos2 < Eu64::PosMax);
38+
assert!(Eu64::Pos1 < Eu64::PosMax);
39+
40+
41+
assert!(Ei64::Pos2 > Ei64::Pos1);
42+
assert!(Ei64::Pos2 > Ei64::Neg1);
43+
assert!(Ei64::Pos1 > Ei64::Neg1);
44+
assert!(Ei64::Pos2 > Ei64::NegMin);
45+
assert!(Ei64::Pos1 > Ei64::NegMin);
46+
assert!(Ei64::Pos2 < Ei64::PosMax);
47+
assert!(Ei64::Pos1 < Ei64::PosMax);
48+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// Issue 15523: derive(PartialOrd) should use the provided
1212
// discriminant values for the derived ordering.
13+
//
14+
// This is checking the basic functionality.
1315

1416
#[derive(PartialEq, PartialOrd)]
1517
enum E1 {

0 commit comments

Comments
 (0)