]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/issue-miri-1112.rs
add a weak form of protection that justifies Box noalias
[rust.git] / src / tools / miri / tests / fail / issue-miri-1112.rs
1 trait Empty {}
2
3 #[repr(transparent)]
4 pub struct FunnyPointer(dyn Empty);
5
6 #[repr(C)]
7 pub struct Meta {
8     drop_fn: fn(&mut ()),
9     size: usize,
10     align: usize,
11 }
12
13 impl Meta {
14     pub fn new() -> Self {
15         Meta { drop_fn: |_| {}, size: 0, align: 1 }
16     }
17 }
18
19 #[repr(C)]
20 pub struct FatPointer {
21     pub data: *const (),
22     pub vtable: *const (),
23 }
24
25 impl FunnyPointer {
26     pub unsafe fn from_data_ptr(data: &String, ptr: *const Meta) -> &Self {
27         let obj = FatPointer {
28             data: data as *const _ as *const (),
29             vtable: ptr as *const _ as *const (),
30         };
31         let obj = std::mem::transmute::<FatPointer, *mut FunnyPointer>(obj); //~ ERROR: expected a vtable pointer
32         &*obj
33     }
34 }
35
36 fn main() {
37     unsafe {
38         let meta = Meta::new();
39         let hello = "hello".to_string();
40         let _raw: &FunnyPointer = FunnyPointer::from_data_ptr(&hello, &meta as *const _);
41     }
42 }