]> git.lizzy.rs Git - rust.git/blob - src/docs/neg_cmp_op_on_partial_ord.txt
fa55c6cfd74b3990aea2bfee110ab50e8bd69212
[rust.git] / src / docs / neg_cmp_op_on_partial_ord.txt
1 ### What it does
2 Checks for the usage of negated comparison operators on types which only implement
3 `PartialOrd` (e.g., `f64`).
4
5 ### Why is this bad?
6 These operators make it easy to forget that the underlying types actually allow not only three
7 potential Orderings (Less, Equal, Greater) but also a fourth one (Uncomparable). This is
8 especially easy to miss if the operator based comparison result is negated.
9
10 ### Example
11 ```
12 let a = 1.0;
13 let b = f64::NAN;
14
15 let not_less_or_equal = !(a <= b);
16 ```
17
18 Use instead:
19 ```
20 use std::cmp::Ordering;
21
22 let _not_less_or_equal = match a.partial_cmp(&b) {
23     None | Some(Ordering::Greater) => true,
24     _ => false,
25 };
26 ```