rust/tests/run-pass/ptr_int_casts.rs

16 lines
320 B
Rust
Raw Normal View History

2017-06-05 17:18:40 -05:00
fn eq_ref<T>(x: &T, y: &T) -> bool {
x as *const _ == y as *const _
}
2017-06-04 12:42:02 -05:00
fn main() {
// int-ptr-int
assert_eq!(1 as *const i32 as usize, 1);
2017-06-05 17:18:40 -05:00
{ // ptr-int-ptr
let x = 13;
let y = &x as *const _ as usize;
let y = y as *const _;
assert!(eq_ref(&x, unsafe { &*y }));
}
2017-06-04 12:42:02 -05:00
}