summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/cast_abs_to_unsigned.txt
blob: c5d8ee034ce596d89a8ce62ae83d5962d7f892dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
### What it does
Checks for uses of the `abs()` method that cast the result to unsigned.

### Why is this bad?
The `unsigned_abs()` method avoids panic when called on the MIN value.

### Example
```
let x: i32 = -42;
let y: u32 = x.abs() as u32;
```
Use instead:
```
let x: i32 = -42;
let y: u32 = x.unsigned_abs();
```