]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/manual_saturating_arithmetic.txt
Rollup merge of #102470 - est31:stabilize_const_char_convert, r=joshtriplett
[rust.git] / src / tools / clippy / src / docs / manual_saturating_arithmetic.txt
1 ### What it does
2 Checks for `.checked_add/sub(x).unwrap_or(MAX/MIN)`.
3
4 ### Why is this bad?
5 These can be written simply with `saturating_add/sub` methods.
6
7 ### Example
8 ```
9 let add = x.checked_add(y).unwrap_or(u32::MAX);
10 let sub = x.checked_sub(y).unwrap_or(u32::MIN);
11 ```
12
13 can be written using dedicated methods for saturating addition/subtraction as:
14
15 ```
16 let add = x.saturating_add(y);
17 let sub = x.saturating_sub(y);
18 ```