1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 //! This test case utilizes `f64` an easy example for `PartialOrd` only types
11 //! but the lint itself actually validates any expression where the left
12 //! operand implements `PartialOrd` but not `Ord`.
14 use std::cmp::Ordering;
16 #[warn(clippy::neg_cmp_op_on_partial_ord)]
19 let another_value = 7.0;
23 // Not Less but potentially Greater, Equal or Uncomparable.
24 let _not_less = !(a_value < another_value);
26 // Not Less or Equal but potentially Greater or Uncomparable.
27 let _not_less_or_equal = !(a_value <= another_value);
29 // Not Greater but potentially Less, Equal or Uncomparable.
30 let _not_greater = !(a_value > another_value);
32 // Not Greater or Equal but potentially Less or Uncomparable.
33 let _not_greater_or_equal = !(a_value >= another_value);
37 let _not_less = match a_value.partial_cmp(&another_value) {
38 None | Some(Ordering::Greater) | Some(Ordering::Equal) => true,
41 let _not_less_or_equal = match a_value.partial_cmp(&another_value) {
42 None | Some(Ordering::Greater) => true,
45 let _not_greater = match a_value.partial_cmp(&another_value) {
46 None | Some(Ordering::Less) | Some(Ordering::Equal) => true,
49 let _not_greater_or_equal = match a_value.partial_cmp(&another_value) {
50 None | Some(Ordering::Less) => true,
54 // --- Should not trigger ---
56 let _ = a_value < another_value;
57 let _ = a_value <= another_value;
58 let _ = a_value > another_value;
59 let _ = a_value >= another_value;
61 // --- regression tests ---
63 // Issue 2856: False positive on assert!()
65 // The macro always negates the result of the given comparison in its
66 // internal check which automatically triggered the lint. As it's an
67 // external macro there was no chance to do anything about it which led
68 // to a whitelisting of all external macros.
69 assert!(a_value < another_value);