]> git.lizzy.rs Git - rust.git/blob - src/docs/cast_abs_to_unsigned.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / cast_abs_to_unsigned.txt
1 ### What it does
2 Checks for uses of the `abs()` method that cast the result to unsigned.
3
4 ### Why is this bad?
5 The `unsigned_abs()` method avoids panic when called on the MIN value.
6
7 ### Example
8 ```
9 let x: i32 = -42;
10 let y: u32 = x.abs() as u32;
11 ```
12 Use instead:
13 ```
14 let x: i32 = -42;
15 let y: u32 = x.unsigned_abs();
16 ```