]>
Commit | Line | Data |
---|---|---|
ba9703b0 XL |
1 | Transmute with two differently sized types was attempted. |
2 | ||
3 | Erroneous code example: | |
60c5eb7d XL |
4 | |
5 | ```compile_fail,E0512 | |
6 | fn takes_u8(_: u8) {} | |
7 | ||
8 | fn main() { | |
9 | unsafe { takes_u8(::std::mem::transmute(0u16)); } | |
10 | // error: cannot transmute between types of different sizes, | |
11 | // or dependently-sized types | |
12 | } | |
13 | ``` | |
14 | ||
15 | Please use types with same size or use the expected type directly. Example: | |
16 | ||
17 | ``` | |
18 | fn takes_u8(_: u8) {} | |
19 | ||
20 | fn main() { | |
21 | unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok! | |
22 | // or: | |
23 | unsafe { takes_u8(0u8); } // ok! | |
24 | } | |
25 | ``` |