diff options
Diffstat (limited to 'tests/mir-opt/building/enum_cast.rs')
-rw-r--r-- | tests/mir-opt/building/enum_cast.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/mir-opt/building/enum_cast.rs b/tests/mir-opt/building/enum_cast.rs index 98fd5acfb..431b5c708 100644 --- a/tests/mir-opt/building/enum_cast.rs +++ b/tests/mir-opt/building/enum_cast.rs @@ -1,6 +1,7 @@ // EMIT_MIR enum_cast.foo.built.after.mir // EMIT_MIR enum_cast.bar.built.after.mir // EMIT_MIR enum_cast.boo.built.after.mir +// EMIT_MIR enum_cast.far.built.after.mir enum Foo { A @@ -15,6 +16,11 @@ enum Boo { A, B } +#[repr(i16)] +enum Far { + A, B +} + fn foo(foo: Foo) -> usize { foo as usize } @@ -27,6 +33,10 @@ fn boo(boo: Boo) -> usize { boo as usize } +fn far(far: Far) -> isize { + far as isize +} + // EMIT_MIR enum_cast.droppy.built.after.mir enum Droppy { A, B, C @@ -46,5 +56,37 @@ fn droppy() { let z = Droppy::B; } +#[repr(i16)] +enum SignedAroundZero { + A = -2, + B = 0, + C = 2, +} + +#[repr(u16)] +enum UnsignedAroundZero { + A = 65535, + B = 0, + C = 1, +} + +// EMIT_MIR enum_cast.signy.built.after.mir +fn signy(x: SignedAroundZero) -> i16 { + x as i16 +} + +// EMIT_MIR enum_cast.unsigny.built.after.mir +fn unsigny(x: UnsignedAroundZero) -> u16 { + // FIXME: This doesn't get an around-the-end range today, sadly. + x as u16 +} + +enum NotStartingAtZero { A = 4, B = 6, C = 8 } + +// EMIT_MIR enum_cast.offsetty.built.after.mir +fn offsetty(x: NotStartingAtZero) -> u32 { + x as u32 +} + fn main() { } |