]> git.lizzy.rs Git - rust.git/blob - tests/ui/neg_cmp_op_on_partial_ord.rs
Fixed spelling and indentation issues in neg_cmp_op_on_partial_ord related files.
[rust.git] / tests / ui / neg_cmp_op_on_partial_ord.rs
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`.
4
5 use std::cmp::Ordering;
6
7 #[allow(nonminimal_bool)]
8 #[warn(neg_cmp_op_on_partial_ord)]
9 fn main() {
10
11     let a_value = 1.0;
12     let another_value = 7.0;
13
14     // --- Bad ---
15
16
17     // Not Less but potentially Greater, Equal or Uncomparable.
18     let _not_less = !(a_value < another_value);
19     
20     // Not Less or Equal but potentially Greater or Uncomparable.
21     let _not_less_or_equal = !(a_value <= another_value);
22
23     // Not Greater but potentially Less, Equal or Uncomparable.
24     let _not_greater = !(a_value > another_value);
25
26     // Not Greater or Equal but potentially Less or Uncomparable.
27     let _not_greater_or_equal = !(a_value >= another_value);
28
29
30     // --- Good ---
31
32
33     let _not_less = match a_value.partial_cmp(&another_value) {
34         None | Some(Ordering::Greater) | Some(Ordering::Equal)  => true,
35         _ => false,
36     };
37     let _not_less_or_equal = match a_value.partial_cmp(&another_value) {
38         None | Some(Ordering::Greater) => true,
39         _ => false,
40     };
41     let _not_greater = match a_value.partial_cmp(&another_value) {
42         None | Some(Ordering::Less) | Some(Ordering::Equal) => true,
43         _ => false,
44     };
45     let _not_greater_or_equal = match a_value.partial_cmp(&another_value) {
46         None | Some(Ordering::Less) => true,
47         _ => false,
48     };
49
50
51     // --- Should not trigger ---
52
53
54     let _ = a_value < another_value;
55     let _ = a_value <= another_value;
56     let _ = a_value > another_value;
57     let _ = a_value >= another_value;
58 }
59