1 #![feature(tool_lints)]
3 //! This test case utilizes `f64` an easy example for `PartialOrd` only types
4 //! but the lint itself actually validates any expression where the left
5 //! operand implements `PartialOrd` but not `Ord`.
7 use std::cmp::Ordering;
9 #[warn(clippy::neg_cmp_op_on_partial_ord)]
13 let another_value = 7.0;
18 // Not Less but potentially Greater, Equal or Uncomparable.
19 let _not_less = !(a_value < another_value);
21 // Not Less or Equal but potentially Greater or Uncomparable.
22 let _not_less_or_equal = !(a_value <= another_value);
24 // Not Greater but potentially Less, Equal or Uncomparable.
25 let _not_greater = !(a_value > another_value);
27 // Not Greater or Equal but potentially Less or Uncomparable.
28 let _not_greater_or_equal = !(a_value >= another_value);
34 let _not_less = match a_value.partial_cmp(&another_value) {
35 None | Some(Ordering::Greater) | Some(Ordering::Equal) => true,
38 let _not_less_or_equal = match a_value.partial_cmp(&another_value) {
39 None | Some(Ordering::Greater) => true,
42 let _not_greater = match a_value.partial_cmp(&another_value) {
43 None | Some(Ordering::Less) | Some(Ordering::Equal) => true,
46 let _not_greater_or_equal = match a_value.partial_cmp(&another_value) {
47 None | Some(Ordering::Less) => true,
52 // --- Should not trigger ---
55 let _ = a_value < another_value;
56 let _ = a_value <= another_value;
57 let _ = a_value > another_value;
58 let _ = a_value >= another_value;
60 // --- regression tests ---
62 // Issue 2856: False positive on assert!()
64 // The macro always negates the result of the given comparison in its
65 // internal check which automatically triggered the lint. As it's an
66 // external macro there was no chance to do anything about it which led
67 // to a whitelisting of all external macros.
68 assert!(a_value < another_value);