Skip to content

Commit

Permalink
cfail test for rust-lang#31886
Browse files Browse the repository at this point in the history
  • Loading branch information
durka committed Mar 18, 2016
1 parent ee4b607 commit 9d0748f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
20 changes: 20 additions & 0 deletions src/test/compile-fail/enum-discrim-autosizing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// With no repr attribute the discriminant will default to isize.
// On 32-bit architectures this is equivalent to i32 so the variants
// collide. On other architectures we need compilation to fail anyway,
// so force the repr.
#[cfg_attr(not(target_pointer_width = "32"), repr(i32))]
enum Eu64 {
Au64 = 0,
Bu64 = 0x8000_0000_0000_0000 //~ERROR already exists
}

10 changes: 0 additions & 10 deletions src/test/run-pass/enum-discrim-autosizing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ enum Ei64 {
Bi64 = 0x8000_0000
}

#[derive(PartialEq)]
enum Eu64 {
Au64 = 0,
Bu64 = 0x8000_0000_0000_0000
}

pub fn main() {
assert_eq!(size_of::<Ei8>(), 1);
assert_eq!(size_of::<Eu8>(), 1);
Expand All @@ -64,8 +58,4 @@ pub fn main() {
assert_eq!(size_of::<Ei64>(), 8);
#[cfg(target_pointer_width = "32")]
assert_eq!(size_of::<Ei64>(), 4);
assert_eq!(size_of::<Eu64>(), 8);

// ensure no i32 collisions
assert!(Eu64::Au64 != Eu64::Bu64);
}

0 comments on commit 9d0748f

Please sign in to comment.