Skip to content

Commit

Permalink
test more variants of enum-int-casting
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jun 9, 2019
1 parent 400b409 commit 2e9931f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/test/run-pass/consts/const-enum-cast.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// run-pass
#![allow(dead_code)]
#![allow(non_upper_case_globals)]

enum A { A1, A2 }
enum B { B1=0, B2=2 }
enum B { B1=4, B2=2 }

pub fn main () {
static c1: isize = A::A2 as isize;
Expand All @@ -14,4 +13,14 @@ pub fn main () {
assert_eq!(c2, 2);
assert_eq!(a1, 1);
assert_eq!(a2, 2);

// Turns out that adding a let-binding generates totally different MIR.
static c1_2: isize = { let v = A::A1; v as isize };
static c2_2: isize = { let v = B::B1; v as isize };
let a1_2 = { let v = A::A1; v as isize };
let a2_2 = { let v = B::B1; v as isize };
assert_eq!(c1_2, 0);
assert_eq!(c2_2, 4);
assert_eq!(a1_2, 0);
assert_eq!(a2_2, 4);
}

0 comments on commit 2e9931f

Please sign in to comment.