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