summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/borrow_as_ptr.txt
blob: 0be865abd578095f3ec4c54651d234eb40d382ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
### What it does
Checks for the usage of `&expr as *const T` or
`&mut expr as *mut T`, and suggest using `ptr::addr_of` or
`ptr::addr_of_mut` instead.

### Why is this bad?
This would improve readability and avoid creating a reference
that points to an uninitialized value or unaligned place.
Read the `ptr::addr_of` docs for more information.

### Example
```
let val = 1;
let p = &val as *const i32;

let mut val_mut = 1;
let p_mut = &mut val_mut as *mut i32;
```
Use instead:
```
let val = 1;
let p = std::ptr::addr_of!(val);

let mut val_mut = 1;
let p_mut = std::ptr::addr_of_mut!(val_mut);
```