summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/neg_cmp_op_on_partial_ord.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/src/docs/neg_cmp_op_on_partial_ord.txt')
-rw-r--r--src/tools/clippy/src/docs/neg_cmp_op_on_partial_ord.txt26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/neg_cmp_op_on_partial_ord.txt b/src/tools/clippy/src/docs/neg_cmp_op_on_partial_ord.txt
new file mode 100644
index 000000000..fa55c6cfd
--- /dev/null
+++ b/src/tools/clippy/src/docs/neg_cmp_op_on_partial_ord.txt
@@ -0,0 +1,26 @@
+### What it does
+Checks for the usage of negated comparison operators on types which only implement
+`PartialOrd` (e.g., `f64`).
+
+### Why is this bad?
+These operators make it easy to forget that the underlying types actually allow not only three
+potential Orderings (Less, Equal, Greater) but also a fourth one (Uncomparable). This is
+especially easy to miss if the operator based comparison result is negated.
+
+### Example
+```
+let a = 1.0;
+let b = f64::NAN;
+
+let not_less_or_equal = !(a <= b);
+```
+
+Use instead:
+```
+use std::cmp::Ordering;
+
+let _not_less_or_equal = match a.partial_cmp(&b) {
+ None | Some(Ordering::Greater) => true,
+ _ => false,
+};
+``` \ No newline at end of file