]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0607.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0607.md
1 A cast between a thin and a fat pointer was attempted.
2
3 Erroneous code example:
4
5 ```compile_fail,E0607
6 let v = core::ptr::null::<u8>();
7 v as *const [u8];
8 ```
9
10 First: what are thin and fat pointers?
11
12 Thin pointers are "simple" pointers: they are purely a reference to a memory
13 address.
14
15 Fat pointers are pointers referencing Dynamically Sized Types (also called
16 DSTs). DSTs don't have a statically known size, therefore they can only exist
17 behind some kind of pointer that contains additional information. For example,
18 slices and trait objects are DSTs. In the case of slices, the additional
19 information the fat pointer holds is their size.
20
21 To fix this error, don't try to cast directly between thin and fat pointers.
22
23 For more information about type casts, take a look at the section of the
24 [The Rust Reference][1] on type cast expressions.
25
26 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions