]> git.lizzy.rs Git - rust.git/blob - src/docs/assign_op_pattern.txt
Add iter_kv_map lint
[rust.git] / src / docs / assign_op_pattern.txt
1 ### What it does
2 Checks for `a = a op b` or `a = b commutative_op a`
3 patterns.
4
5 ### Why is this bad?
6 These can be written as the shorter `a op= b`.
7
8 ### Known problems
9 While forbidden by the spec, `OpAssign` traits may have
10 implementations that differ from the regular `Op` impl.
11
12 ### Example
13 ```
14 let mut a = 5;
15 let b = 0;
16 // ...
17
18 a = a + b;
19 ```
20
21 Use instead:
22 ```
23 let mut a = 5;
24 let b = 0;
25 // ...
26
27 a += b;
28 ```