]> git.lizzy.rs Git - rust.git/blob - src/test/ui/fat-ptr-cast-rpass.rs
Auto merge of #75406 - mati865:mingw-aslr, r=Mark-Simulacrum
[rust.git] / src / test / ui / fat-ptr-cast-rpass.rs
1 // run-pass
2
3 #![feature(raw)]
4
5 use std::mem;
6 use std::raw;
7
8 trait Foo {
9     fn foo(&self) {}
10 }
11
12 struct Bar;
13
14 impl Foo for Bar {}
15
16 fn main() {
17     // Test we can turn a fat pointer to array back into a thin pointer.
18     let a: *const [i32] = &[1, 2, 3];
19     let b = a as *const [i32; 2];
20     unsafe {
21         assert_eq!(*b, [1, 2]);
22     }
23
24     // Test conversion to an address (usize).
25     let a: *const [i32; 3] = &[1, 2, 3];
26     let b: *const [i32] = a;
27     assert_eq!(a as usize, b as *const () as usize);
28
29     // And conversion to a void pointer/address for trait objects too.
30     let a: *mut dyn Foo = &mut Bar;
31     let b = a as *mut ();
32     let c = a as *const () as usize;
33     let d = unsafe {
34         let r: raw::TraitObject = mem::transmute(a);
35         r.data
36     };
37
38     assert_eq!(b, d);
39     assert_eq!(c, d as usize);
40
41 }