]> git.lizzy.rs Git - rust.git/blob - tests/ui/eq_op.rs
Auto merge of #3635 - matthiaskrgr:revert_random_state_3603, r=xfix
[rust.git] / tests / ui / eq_op.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #[rustfmt::skip]
11 #[warn(clippy::eq_op)]
12 #[allow(clippy::identity_op, clippy::double_parens, clippy::many_single_char_names)]
13 #[allow(clippy::no_effect, unused_variables, clippy::unnecessary_operation, clippy::short_circuit_statement)]
14 #[warn(clippy::nonminimal_bool)]
15 fn main() {
16     // simple values and comparisons
17     1 == 1;
18     "no" == "no";
19     // even though I agree that no means no ;-)
20     false != false;
21     1.5 < 1.5;
22     1u64 >= 1u64;
23
24     // casts, methods, parentheses
25     (1 as u64) & (1 as u64);
26     1 ^ ((((((1))))));
27
28     // unary and binary operators
29     (-(2) < -(2));
30     ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
31     (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
32
33     // various other things
34     ([1] != [1]);
35     ((1, 2) != (1, 2));
36     vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros
37
38     // const folding
39     1 + 1 == 2;
40     1 - 1 == 0;
41
42     1 - 1;
43     1 / 1;
44     true && true;
45
46     true || true;
47
48
49     let a: u32 = 0;
50     let b: u32 = 0;
51
52     a == b && b == a;
53     a != b && b != a;
54     a < b && b > a;
55     a <= b && b >= a;
56
57     let mut a = vec![1];
58     a == a;
59     2*a.len() == 2*a.len(); // ok, functions
60     a.pop() == a.pop(); // ok, functions
61
62     use std::ops::BitAnd;
63     struct X(i32);
64     impl BitAnd for X {
65         type Output = X;
66         fn bitand(self, rhs: X) -> X {
67             X(self.0 & rhs.0)
68         }
69     }
70     impl<'a> BitAnd<&'a X> for X {
71         type Output = X;
72         fn bitand(self, rhs: &'a X) -> X {
73             X(self.0 & rhs.0)
74         }
75     }
76     let x = X(1);
77     let y = X(2);
78     let z = x & &y;
79
80     #[derive(Copy, Clone)]
81     struct Y(i32);
82     impl BitAnd for Y {
83         type Output = Y;
84         fn bitand(self, rhs: Y) -> Y {
85             Y(self.0 & rhs.0)
86         }
87     }
88     impl<'a> BitAnd<&'a Y> for Y {
89         type Output = Y;
90         fn bitand(self, rhs: &'a Y) -> Y {
91             Y(self.0 & rhs.0)
92         }
93     }
94     let x = Y(1);
95     let y = Y(2);
96     let z = x & &y;
97
98     check_ignore_macro();
99
100     // named constants
101     const A: u32 = 10;
102     const B: u32 = 10;
103     const C: u32 = A / B; // ok, different named constants
104     const D: u32 = A / A;
105 }
106
107 #[rustfmt::skip]
108 macro_rules! check_if_named_foo {
109     ($expression:expr) => (
110         if stringify!($expression) == "foo" {
111             println!("foo!");
112         } else {
113             println!("not foo.");
114         }
115     )
116 }
117
118 fn check_ignore_macro() {
119     check_if_named_foo!(foo);
120 }