gcc/testsuite/rust/execute/torture/transmute1.rs
raw| 1 | // { dg-additional-options "-w" } |
| 2 | #![feature(intrinsics)] |
| 3 | |
| 4 | extern "rust-intrinsic" { |
| 5 | fn transmute<T, U>(value: T) -> U; |
| 6 | } |
| 7 | |
| 8 | #[lang = "sized"] |
| 9 | pub trait Sized {} |
| 10 | |
| 11 | struct WrapI { |
| 12 | inner: i32, |
| 13 | } |
| 14 | |
| 15 | struct WrapF { |
| 16 | inner: f32, |
| 17 | } |
| 18 | |
| 19 | fn main() -> i32 { |
| 20 | let f = 15.4f32; |
| 21 | let f_wrap = WrapF { inner: f }; |
| 22 | |
| 23 | let fst = unsafe { transmute::<f32, i32>(f) }; |
| 24 | let snd = unsafe { transmute::<WrapF, WrapI>(f_wrap) }; |
| 25 | |
| 26 | fst - snd.inner |
| 27 | } |