]> git.lizzy.rs Git - rust.git/blob - src/docs/min_max.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / min_max.txt
1 ### What it does
2 Checks for expressions where `std::cmp::min` and `max` are
3 used to clamp values, but switched so that the result is constant.
4
5 ### Why is this bad?
6 This is in all probability not the intended outcome. At
7 the least it hurts readability of the code.
8
9 ### Example
10 ```
11 min(0, max(100, x))
12
13 // or
14
15 x.max(100).min(0)
16 ```
17 It will always be equal to `0`. Probably the author meant to clamp the value
18 between 0 and 100, but has erroneously swapped `min` and `max`.