]> git.lizzy.rs Git - rust.git/blob - src/test/ui/cast/fat-ptr-cast-rpass.rs
Auto merge of #97191 - wesleywiser:main_thread_name, r=ChrisDenton
[rust.git] / src / test / ui / cast / fat-ptr-cast-rpass.rs
1 // run-pass
2
3 #![feature(ptr_metadata)]
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 {
18         assert_eq!(*b, [1, 2]);
19     }
20
21     // Test conversion to an address (usize).
22     let a: *const [i32; 3] = &[1, 2, 3];
23     let b: *const [i32] = a;
24     assert_eq!(a as usize, b as *const () as usize);
25
26     // And conversion to a void pointer/address for trait objects too.
27     let a: *mut dyn Foo = &mut Bar;
28     let b = a as *mut () as usize;
29     let c = a as *const () as usize;
30     let d = a.to_raw_parts().0 as usize;
31
32     assert_eq!(b, d);
33     assert_eq!(c, d);
34 }