]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0605.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0605.md
CommitLineData
60c5eb7d
XL
1An invalid cast was attempted.
2
3Erroneous code examples:
4
5```compile_fail,E0605
6let x = 0u8;
7x as Vec<u8>; // error: non-primitive cast: `u8` as `std::vec::Vec<u8>`
8
9// Another example
10
11let v = core::ptr::null::<u8>(); // So here, `v` is a `*const u8`.
12v as &u8; // error: non-primitive cast: `*const u8` as `&u8`
13```
14
15Only primitive types can be cast into each other. Examples:
16
17```
18let x = 0u8;
19x as u32; // ok!
20
21let v = core::ptr::null::<u8>();
22v as *const i8; // ok!
23```
24
25For more information about casts, take a look at the Type cast section in
26[The Reference Book][1].
27
28[1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions