Skip to content

Commit

Permalink
Correct test for enum representation with explicit #[repr]
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrik Sverdrup committed May 27, 2015
1 parent 46e935d commit 42e29fa
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/test/run-pass/enum-discrim-manual-sizing-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,22 @@ pub fn main() {
assert_eq!(size_of::<Eint<()>>(), size_of::<isize>());
assert_eq!(size_of::<Euint<()>>(), size_of::<usize>());

assert!(size_of::<Ei8<&i32>>() > 1);
assert!(size_of::<Eu8<&i32>>() > 1);
assert!(size_of::<Ei16<&i32>>() > 2);
assert!(size_of::<Eu16<&i32>>() > 2);
assert!(size_of::<Ei32<&i32>>() > 4);
assert!(size_of::<Eu32<&i32>>() > 4);
assert!(size_of::<Ei64<&i32>>() > 8);
assert!(size_of::<Eu64<&i32>>() > 8);
assert!(size_of::<Eint<&i32>>() > size_of::<isize>());
assert!(size_of::<Euint<&i32>>() > size_of::<usize>());

assert!(size_of::<EC<&i32>>() > size_of::<EC<()>>());

// check that the non-nullable pointer optimization is absent
let ptrsize = size_of::<&i32>();
assert!(size_of::<Ei8<&i32>>() > ptrsize);
assert!(size_of::<Eu8<&i32>>() > ptrsize);
assert!(size_of::<Ei16<&i32>>() > ptrsize);
assert!(size_of::<Eu16<&i32>>() > ptrsize);
assert!(size_of::<Ei32<&i32>>() > ptrsize);
assert!(size_of::<Eu32<&i32>>() > ptrsize);
assert!(size_of::<Ei64<&i32>>() > ptrsize);
assert!(size_of::<Eu64<&i32>>() > ptrsize);
assert!(size_of::<Eint<&i32>>() > ptrsize);
assert!(size_of::<Euint<&i32>>() > ptrsize);

assert!(size_of::<EC<&i32>>() > ptrsize);

// test that a zero payload does not influence the discriminant
let zero: &i32 = unsafe { zeroed() };
assert!(match Eu8::_Some(zero) {
Eu8::_Some(_) => true,
Expand Down

0 comments on commit 42e29fa

Please sign in to comment.