]>
Commit | Line | Data |
---|---|---|
416331ca XL |
1 | // run-pass |
2 | ||
136023e0 | 3 | #![feature(ptr_metadata)] |
d9579d0f AL |
4 | |
5 | trait Foo { | |
6 | fn foo(&self) {} | |
7 | } | |
8 | ||
9 | struct Bar; | |
10 | ||
11 | impl Foo for Bar {} | |
12 | ||
13 | fn main() { | |
14 | // Test we can turn a fat pointer to array back into a thin pointer. | |
15 | let a: *const [i32] = &[1, 2, 3]; | |
16 | let b = a as *const [i32; 2]; | |
17 | unsafe { | |
62682a34 | 18 | assert_eq!(*b, [1, 2]); |
d9579d0f AL |
19 | } |
20 | ||
21 | // Test conversion to an address (usize). | |
22 | let a: *const [i32; 3] = &[1, 2, 3]; | |
23 | let b: *const [i32] = a; | |
62682a34 | 24 | assert_eq!(a as usize, b as *const () as usize); |
d9579d0f AL |
25 | |
26 | // And conversion to a void pointer/address for trait objects too. | |
dc9dc135 | 27 | let a: *mut dyn Foo = &mut Bar; |
136023e0 | 28 | let b = a as *mut () as usize; |
62682a34 | 29 | let c = a as *const () as usize; |
136023e0 | 30 | let d = a.to_raw_parts().0 as usize; |
d9579d0f | 31 | |
62682a34 | 32 | assert_eq!(b, d); |
136023e0 | 33 | assert_eq!(c, d); |
d9579d0f | 34 | } |