]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/eq_op.rs
Rollup merge of #78216 - workingjubilee:duration-zero, r=m-ou-se
[rust.git] / src / tools / clippy / tests / ui / eq_op.rs
1 // does not test any rustfixable lints
2
3 #[rustfmt::skip]
4 #[warn(clippy::eq_op)]
5 #[allow(clippy::identity_op, clippy::double_parens, clippy::many_single_char_names)]
6 #[allow(clippy::no_effect, unused_variables, clippy::unnecessary_operation, clippy::short_circuit_statement)]
7 #[allow(clippy::nonminimal_bool)]
8 #[allow(unused)]
9 #[allow(clippy::unnecessary_cast)]
10 fn main() {
11     // simple values and comparisons
12     1 == 1;
13     "no" == "no";
14     // even though I agree that no means no ;-)
15     false != false;
16     1.5 < 1.5;
17     1u64 >= 1u64;
18
19     // casts, methods, parentheses
20     (1 as u64) & (1 as u64);
21     1 ^ ((((((1))))));
22
23     // unary and binary operators
24     (-(2) < -(2));
25     ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
26     (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
27
28     // various other things
29     ([1] != [1]);
30     ((1, 2) != (1, 2));
31     vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros
32
33     // const folding
34     1 + 1 == 2;
35     1 - 1 == 0;
36
37     1 - 1;
38     1 / 1;
39     true && true;
40
41     true || true;
42
43
44     let a: u32 = 0;
45     let b: u32 = 0;
46
47     a == b && b == a;
48     a != b && b != a;
49     a < b && b > a;
50     a <= b && b >= a;
51
52     let mut a = vec![1];
53     a == a;
54     2*a.len() == 2*a.len(); // ok, functions
55     a.pop() == a.pop(); // ok, functions
56
57     check_ignore_macro();
58
59     // named constants
60     const A: u32 = 10;
61     const B: u32 = 10;
62     const C: u32 = A / B; // ok, different named constants
63     const D: u32 = A / A;
64 }
65
66 #[rustfmt::skip]
67 macro_rules! check_if_named_foo {
68     ($expression:expr) => (
69         if stringify!($expression) == "foo" {
70             println!("foo!");
71         } else {
72             println!("not foo.");
73         }
74     )
75 }
76
77 macro_rules! bool_macro {
78     ($expression:expr) => {
79         true
80     };
81 }
82
83 #[allow(clippy::short_circuit_statement)]
84 fn check_ignore_macro() {
85     check_if_named_foo!(foo);
86     // checks if the lint ignores macros with `!` operator
87     !bool_macro!(1) && !bool_macro!("");
88 }