1 //! This test case utilizes `f64` an easy example for `PartialOrd` only types
2 //! but the lint itself actually validates any expression where the left
3 //! operand implements `PartialOrd` but not `Ord`.
5 use std::cmp::Ordering;
7 #[warn(clippy::neg_cmp_op_on_partial_ord)]
10 let another_value = 7.0;
14 // Not Less but potentially Greater, Equal or Uncomparable.
15 let _not_less = !(a_value < another_value);
17 // Not Less or Equal but potentially Greater or Uncomparable.
18 let _not_less_or_equal = !(a_value <= another_value);
20 // Not Greater but potentially Less, Equal or Uncomparable.
21 let _not_greater = !(a_value > another_value);
23 // Not Greater or Equal but potentially Less or Uncomparable.
24 let _not_greater_or_equal = !(a_value >= another_value);
28 let _not_less = match a_value.partial_cmp(&another_value) {
29 None | Some(Ordering::Greater) | Some(Ordering::Equal) => true,
32 let _not_less_or_equal = match a_value.partial_cmp(&another_value) {
33 None | Some(Ordering::Greater) => true,
36 let _not_greater = match a_value.partial_cmp(&another_value) {
37 None | Some(Ordering::Less) | Some(Ordering::Equal) => true,
40 let _not_greater_or_equal = match a_value.partial_cmp(&another_value) {
41 None | Some(Ordering::Less) => true,
45 // --- Should not trigger ---
47 let _ = a_value < another_value;
48 let _ = a_value <= another_value;
49 let _ = a_value > another_value;
50 let _ = a_value >= another_value;
52 // --- regression tests ---
54 // Issue 2856: False positive on assert!()
56 // The macro always negates the result of the given comparison in its
57 // internal check which automatically triggered the lint. As it's an
58 // external macro there was no chance to do anything about it which led
59 // to a whitelisting of all external macros.
60 assert!(a_value < another_value);