]> git.lizzy.rs Git - rust.git/commitdiff
break enum variant discriminant inference in case of 32-bit
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 10 Mar 2016 13:20:53 +0000 (14:20 +0100)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 10 Mar 2016 13:20:53 +0000 (14:20 +0100)
`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
}
```

src/test/run-pass/enum-discrim-autosizing.rs

index 99e44735d0f03a11a25a9517d08c8480bdb089b6..53c44f2bb24b5f16ce3eae5d008182fa2ebaba30 100644 (file)
@@ -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;
 
@@ -46,11 +47,6 @@ 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);
@@ -58,6 +54,8 @@ pub fn main() {
     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);
 }