forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
/
issue-miri-1112.rs
42 lines (36 loc) · 927 Bytes
/
issue-miri-1112.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
trait Empty {}
#[repr(transparent)]
pub struct FunnyPointer(dyn Empty);
#[repr(C)]
pub struct Meta {
drop_fn: fn(&mut ()),
size: usize,
align: usize,
}
impl Meta {
pub fn new() -> Self {
Meta { drop_fn: |_| {}, size: 0, align: 1 }
}
}
#[repr(C)]
pub struct FatPointer {
pub data: *const (),
pub vtable: *const (),
}
impl FunnyPointer {
pub unsafe fn from_data_ptr(data: &String, ptr: *const Meta) -> &Self {
let obj = FatPointer {
data: data as *const _ as *const (),
vtable: ptr as *const _ as *const (),
};
let obj = std::mem::transmute::<FatPointer, *mut FunnyPointer>(obj); //~ ERROR: expected a vtable pointer
&*obj
}
}
fn main() {
unsafe {
let meta = Meta::new();
let hello = "hello".to_string();
let _raw: &FunnyPointer = FunnyPointer::from_data_ptr(&hello, &meta as *const _);
}
}