Skip to content

Commit

Permalink
break enum variant discriminant inference in case of 32-bit
Browse files Browse the repository at this point in the history
`assert_eq!(-9223372036854775808isize as u64, 0x8000000000000000);`

fails on 32 bit and succeeds on 64 bit. These commits don't change that behavior.

The following worked before my changes, because the discriminant was
always processed as `u64`.
Now it fails, because the discriminant of `Bu64` is now `0` instead of `-9223372036854775808`. This is more in line with the above assertion's code, since
`-9223372036854775808isize as u64` on 32 bit yielded `0`.

```rust
enum Eu64 {
    Au64 = 0,
    Bu64 = 0x8000_0000_0000_0000
}
```
  • Loading branch information
oli-obk committed Mar 10, 2016
1 parent d4d6260 commit fcee002
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/test/run-pass/enum-discrim-autosizing.rs
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(stmt_expr_attributes)]

use std::mem::size_of;

Expand Down Expand Up @@ -46,18 +47,15 @@ enum Ei64 {
Bi64 = 0x8000_0000
}

enum Eu64 {
Au64 = 0,
Bu64 = 0x8000_0000_0000_0000
}

pub fn main() {
assert_eq!(size_of::<Ei8>(), 1);
assert_eq!(size_of::<Eu8>(), 1);
assert_eq!(size_of::<Ei16>(), 2);
assert_eq!(size_of::<Eu16>(), 2);
assert_eq!(size_of::<Ei32>(), 4);
assert_eq!(size_of::<Eu32>(), 4);
#[cfg(target_pointer_width = "64")]
assert_eq!(size_of::<Ei64>(), 8);
assert_eq!(size_of::<Eu64>(), 8);
#[cfg(target_pointer_width = "32")]
assert_eq!(size_of::<Ei64>(), 4);
}

0 comments on commit fcee002

Please sign in to comment.