]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/transmute_ptr_to_ptr.txt
Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr
[rust.git] / src / tools / clippy / src / docs / transmute_ptr_to_ptr.txt
1 ### What it does
2 Checks for transmutes from a pointer to a pointer, or
3 from a reference to a reference.
4
5 ### Why is this bad?
6 Transmutes are dangerous, and these can instead be
7 written as casts.
8
9 ### Example
10 ```
11 let ptr = &1u32 as *const u32;
12 unsafe {
13     // pointer-to-pointer transmute
14     let _: *const f32 = std::mem::transmute(ptr);
15     // ref-ref transmute
16     let _: &f32 = std::mem::transmute(&1u32);
17 }
18 // These can be respectively written:
19 let _ = ptr as *const f32;
20 let _ = unsafe{ &*(&1u32 as *const u32 as *const f32) };
21 ```