1 // compile-flags: --test
3 #![warn(clippy::eq_op)]
4 #![allow(clippy::double_parens, clippy::identity_op, clippy::nonminimal_bool)]
5 #![allow(clippy::suspicious_xor_used_as_pow)]
8 // simple values and comparisons
11 // even though I agree that no means no ;-)
12 let _ = false != false;
16 // casts, methods, parentheses
17 let _ = (1u32 as u64) & (1u32 as u64);
20 let _ = 1 ^ ((((((1))))));
23 // unary and binary operators
24 let _ = (-(2) < -(2));
25 let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
26 let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
28 // various other things
30 let _ = ((1, 2) != (1, 2));
31 let _ = vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros
46 let _ = a == b && b == a;
47 let _ = a != b && b != a;
48 let _ = a < b && b > a;
49 let _ = a <= b && b >= a;
53 let _ = 2 * a.len() == 2 * a.len(); // ok, functions
54 let _ = a.pop() == a.pop(); // ok, functions
61 const C: u32 = A / B; // ok, different named constants
65 macro_rules! check_if_named_foo {
66 ($expression:expr) => {
67 if stringify!($expression) == "foo" {
75 macro_rules! bool_macro {
76 ($expression:expr) => {
81 fn check_ignore_macro() {
82 check_if_named_foo!(foo);
83 // checks if the lint ignores macros with `!` operator
84 let _ = !bool_macro!(1) && !bool_macro!("");
88 inner: ((i32,), (i32,), (i32,)),
91 fn check_nested(n1: &Nested, n2: &Nested) -> bool {
92 // `n2.inner.0.0` mistyped as `n1.inner.0.0`
93 (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0
97 fn eq_op_shouldnt_trigger_in_tests() {
99 let result = a + 1 == 1 + a;
104 fn eq_op_macros_shouldnt_trigger_in_tests() {
108 assert_eq!(a + b, b + a);