|
| 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 | +} |
0 commit comments