1 // compile-flags: --test
3 #![warn(clippy::eq_op)]
4 #![allow(clippy::double_parens, clippy::identity_op, clippy::nonminimal_bool)]
7 // simple values and comparisons
10 // even though I agree that no means no ;-)
11 let _ = false != false;
15 // casts, methods, parentheses
16 let _ = (1u32 as u64) & (1u32 as u64);
19 let _ = 1 ^ ((((((1))))));
22 // unary and binary operators
23 let _ = (-(2) < -(2));
24 let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
25 let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
27 // various other things
29 let _ = ((1, 2) != (1, 2));
30 let _ = vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros
45 let _ = a == b && b == a;
46 let _ = a != b && b != a;
47 let _ = a < b && b > a;
48 let _ = a <= b && b >= a;
52 let _ = 2 * a.len() == 2 * a.len(); // ok, functions
53 let _ = a.pop() == a.pop(); // ok, functions
60 const C: u32 = A / B; // ok, different named constants
64 macro_rules! check_if_named_foo {
65 ($expression:expr) => {
66 if stringify!($expression) == "foo" {
74 macro_rules! bool_macro {
75 ($expression:expr) => {
80 fn check_ignore_macro() {
81 check_if_named_foo!(foo);
82 // checks if the lint ignores macros with `!` operator
83 let _ = !bool_macro!(1) && !bool_macro!("");
87 inner: ((i32,), (i32,), (i32,)),
90 fn check_nested(n1: &Nested, n2: &Nested) -> bool {
91 // `n2.inner.0.0` mistyped as `n1.inner.0.0`
92 (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0
96 fn eq_op_shouldnt_trigger_in_tests() {
98 let result = a + 1 == 1 + a;
103 fn eq_op_macros_shouldnt_trigger_in_tests() {
107 assert_eq!(a + b, b + a);