]> git.lizzy.rs Git - rust.git/blob - src/docs/transmute_ptr_to_ref.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / transmute_ptr_to_ref.txt
1 ### What it does
2 Checks for transmutes from a pointer to a reference.
3
4 ### Why is this bad?
5 This can always be rewritten with `&` and `*`.
6
7 ### Known problems
8 - `mem::transmute` in statics and constants is stable from Rust 1.46.0,
9 while dereferencing raw pointer is not stable yet.
10 If you need to do this in those places,
11 you would have to use `transmute` instead.
12
13 ### Example
14 ```
15 unsafe {
16     let _: &T = std::mem::transmute(p); // where p: *const T
17 }
18
19 // can be written:
20 let _: &T = &*p;
21 ```