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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
use std::mem;
unsafe fn foo() -> (i8, *const (), Option<fn()>) {
let i = mem::transmute(bar);
//~^ ERROR cannot transmute between types of different sizes, or dependently-sized types
let p = mem::transmute(foo);
//~^ ERROR can't transmute zero-sized type
let of = mem::transmute(main);
//~^ ERROR can't transmute zero-sized type
(i, p, of)
}
unsafe fn bar() {
// Error as usual if the resulting type is not pointer-sized.
mem::transmute::<_, u8>(main);
//~^ ERROR cannot transmute between types of different sizes, or dependently-sized types
mem::transmute::<_, *mut ()>(foo);
//~^ ERROR can't transmute zero-sized type
mem::transmute::<_, fn()>(bar);
//~^ ERROR can't transmute zero-sized type
// No error if a coercion would otherwise occur.
mem::transmute::<fn(), usize>(main);
}
unsafe fn baz() {
mem::transmute::<_, *mut ()>(Some(foo));
//~^ ERROR can't transmute zero-sized type
mem::transmute::<_, fn()>(Some(bar));
//~^ ERROR can't transmute zero-sized type
mem::transmute::<_, Option<fn()>>(Some(baz));
//~^ ERROR can't transmute zero-sized type
// No error if a coercion would otherwise occur.
mem::transmute::<Option<fn()>, usize>(Some(main));
}
fn main() {
unsafe {
foo();
bar();
baz();
}
}
|