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