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.
11 #![feature(tool_lints)]
13 //! This test case utilizes `f64` an easy example for `PartialOrd` only types
14 //! but the lint itself actually validates any expression where the left
15 //! operand implements `PartialOrd` but not `Ord`.
17 use std::cmp::Ordering;
19 #[warn(clippy::neg_cmp_op_on_partial_ord)]
23 let another_value = 7.0;
28 // Not Less but potentially Greater, Equal or Uncomparable.
29 let _not_less = !(a_value < another_value);
31 // Not Less or Equal but potentially Greater or Uncomparable.
32 let _not_less_or_equal = !(a_value <= another_value);
34 // Not Greater but potentially Less, Equal or Uncomparable.
35 let _not_greater = !(a_value > another_value);
37 // Not Greater or Equal but potentially Less or Uncomparable.
38 let _not_greater_or_equal = !(a_value >= another_value);
44 let _not_less = match a_value.partial_cmp(&another_value) {
45 None | Some(Ordering::Greater) | Some(Ordering::Equal) => true,
48 let _not_less_or_equal = match a_value.partial_cmp(&another_value) {
49 None | Some(Ordering::Greater) => true,
52 let _not_greater = match a_value.partial_cmp(&another_value) {
53 None | Some(Ordering::Less) | Some(Ordering::Equal) => true,
56 let _not_greater_or_equal = match a_value.partial_cmp(&another_value) {
57 None | Some(Ordering::Less) => true,
62 // --- Should not trigger ---
65 let _ = a_value < another_value;
66 let _ = a_value <= another_value;
67 let _ = a_value > another_value;
68 let _ = a_value >= another_value;
70 // --- regression tests ---
72 // Issue 2856: False positive on assert!()
74 // The macro always negates the result of the given comparison in its
75 // internal check which automatically triggered the lint. As it's an
76 // external macro there was no chance to do anything about it which led
77 // to a whitelisting of all external macros.
78 assert!(a_value < another_value);