summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/manual_swap.txt
blob: bd9526288e35b14bb806238a1a2163f6d672efe9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
### What it does
Checks for manual swapping.

### Why is this bad?
The `std::mem::swap` function exposes the intent better
without deinitializing or copying either variable.

### Example
```
let mut a = 42;
let mut b = 1337;

let t = b;
b = a;
a = t;
```
Use std::mem::swap():
```
let mut a = 1;
let mut b = 2;
std::mem::swap(&mut a, &mut b);
```