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