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 #[allow(clippy::unnested_or_patterns, clippy::match_like_matches_macro)]
8 #[warn(clippy::neg_cmp_op_on_partial_ord)]
11 let another_value = 7.0;
15 // Not Less but potentially Greater, Equal or Uncomparable.
16 let _not_less = !(a_value < another_value);
18 // Not Less or Equal but potentially Greater or Uncomparable.
19 let _not_less_or_equal = !(a_value <= another_value);
21 // Not Greater but potentially Less, Equal or Uncomparable.
22 let _not_greater = !(a_value > another_value);
24 // Not Greater or Equal but potentially Less or Uncomparable.
25 let _not_greater_or_equal = !(a_value >= another_value);
29 let _not_less = match a_value.partial_cmp(&another_value) {
30 None | Some(Ordering::Greater) | Some(Ordering::Equal) => true,
33 let _not_less_or_equal = match a_value.partial_cmp(&another_value) {
34 None | Some(Ordering::Greater) => true,
37 let _not_greater = match a_value.partial_cmp(&another_value) {
38 None | Some(Ordering::Less) | Some(Ordering::Equal) => true,
41 let _not_greater_or_equal = match a_value.partial_cmp(&another_value) {
42 None | Some(Ordering::Less) => true,
46 // --- Should not trigger ---
48 let _ = a_value < another_value;
49 let _ = a_value <= another_value;
50 let _ = a_value > another_value;
51 let _ = a_value >= another_value;
53 // --- regression tests ---
55 // Issue 2856: False positive on assert!()
57 // The macro always negates the result of the given comparison in its
58 // internal check which automatically triggered the lint. As it's an
59 // external macro there was no chance to do anything about it which led
60 // to an exempting of all external macros.
61 assert!(a_value < another_value);