]> git.lizzy.rs Git - rust.git/blob - tests/ui/eq_op.rs
Auto merge of #3645 - phansch:remove_copyright_headers, r=oli-obk
[rust.git] / tests / ui / eq_op.rs
1 #[rustfmt::skip]
2 #[warn(clippy::eq_op)]
3 #[allow(clippy::identity_op, clippy::double_parens, clippy::many_single_char_names)]
4 #[allow(clippy::no_effect, unused_variables, clippy::unnecessary_operation, clippy::short_circuit_statement)]
5 #[warn(clippy::nonminimal_bool)]
6 fn main() {
7     // simple values and comparisons
8     1 == 1;
9     "no" == "no";
10     // even though I agree that no means no ;-)
11     false != false;
12     1.5 < 1.5;
13     1u64 >= 1u64;
14
15     // casts, methods, parentheses
16     (1 as u64) & (1 as u64);
17     1 ^ ((((((1))))));
18
19     // unary and binary operators
20     (-(2) < -(2));
21     ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
22     (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
23
24     // various other things
25     ([1] != [1]);
26     ((1, 2) != (1, 2));
27     vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros
28
29     // const folding
30     1 + 1 == 2;
31     1 - 1 == 0;
32
33     1 - 1;
34     1 / 1;
35     true && true;
36
37     true || true;
38
39
40     let a: u32 = 0;
41     let b: u32 = 0;
42
43     a == b && b == a;
44     a != b && b != a;
45     a < b && b > a;
46     a <= b && b >= a;
47
48     let mut a = vec![1];
49     a == a;
50     2*a.len() == 2*a.len(); // ok, functions
51     a.pop() == a.pop(); // ok, functions
52
53     use std::ops::BitAnd;
54     struct X(i32);
55     impl BitAnd for X {
56         type Output = X;
57         fn bitand(self, rhs: X) -> X {
58             X(self.0 & rhs.0)
59         }
60     }
61     impl<'a> BitAnd<&'a X> for X {
62         type Output = X;
63         fn bitand(self, rhs: &'a X) -> X {
64             X(self.0 & rhs.0)
65         }
66     }
67     let x = X(1);
68     let y = X(2);
69     let z = x & &y;
70
71     #[derive(Copy, Clone)]
72     struct Y(i32);
73     impl BitAnd for Y {
74         type Output = Y;
75         fn bitand(self, rhs: Y) -> Y {
76             Y(self.0 & rhs.0)
77         }
78     }
79     impl<'a> BitAnd<&'a Y> for Y {
80         type Output = Y;
81         fn bitand(self, rhs: &'a Y) -> Y {
82             Y(self.0 & rhs.0)
83         }
84     }
85     let x = Y(1);
86     let y = Y(2);
87     let z = x & &y;
88
89     check_ignore_macro();
90
91     // named constants
92     const A: u32 = 10;
93     const B: u32 = 10;
94     const C: u32 = A / B; // ok, different named constants
95     const D: u32 = A / A;
96 }
97
98 #[rustfmt::skip]
99 macro_rules! check_if_named_foo {
100     ($expression:expr) => (
101         if stringify!($expression) == "foo" {
102             println!("foo!");
103         } else {
104             println!("not foo.");
105         }
106     )
107 }
108
109 fn check_ignore_macro() {
110     check_if_named_foo!(foo);
111 }