Skip to content

Commit 49adc99

Browse files
committed
op_ref: Move tests out of eq_op file
1 parent d513a0b commit 49adc99

File tree

4 files changed

+84
-84
lines changed

4 files changed

+84
-84
lines changed

tests/ui/eq_op.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#[allow(clippy::identity_op, clippy::double_parens, clippy::many_single_char_names)]
44
#[allow(clippy::no_effect, unused_variables, clippy::unnecessary_operation, clippy::short_circuit_statement)]
55
#[warn(clippy::nonminimal_bool)]
6+
#[allow(unused)]
67
fn main() {
78
// simple values and comparisons
89
1 == 1;
@@ -50,42 +51,6 @@ fn main() {
5051
2*a.len() == 2*a.len(); // ok, functions
5152
a.pop() == a.pop(); // ok, functions
5253

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-
8954
check_ignore_macro();
9055

9156
// named constants

tests/ui/eq_op.stderr

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,214 +1,204 @@
11
error: this boolean expression can be simplified
2-
--> $DIR/eq_op.rs:35:5
2+
--> $DIR/eq_op.rs:36:5
33
|
44
LL | true && true;
55
| ^^^^^^^^^^^^ help: try: `true`
66
|
77
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
88

99
error: this boolean expression can be simplified
10-
--> $DIR/eq_op.rs:37:5
10+
--> $DIR/eq_op.rs:38:5
1111
|
1212
LL | true || true;
1313
| ^^^^^^^^^^^^ help: try: `true`
1414

1515
error: this boolean expression can be simplified
16-
--> $DIR/eq_op.rs:43:5
16+
--> $DIR/eq_op.rs:44:5
1717
|
1818
LL | a == b && b == a;
1919
| ^^^^^^^^^^^^^^^^ help: try: `a == b`
2020

2121
error: this boolean expression can be simplified
22-
--> $DIR/eq_op.rs:44:5
22+
--> $DIR/eq_op.rs:45:5
2323
|
2424
LL | a != b && b != a;
2525
| ^^^^^^^^^^^^^^^^ help: try: `a != b`
2626

2727
error: this boolean expression can be simplified
28-
--> $DIR/eq_op.rs:45:5
28+
--> $DIR/eq_op.rs:46:5
2929
|
3030
LL | a < b && b > a;
3131
| ^^^^^^^^^^^^^^ help: try: `a < b`
3232

3333
error: this boolean expression can be simplified
34-
--> $DIR/eq_op.rs:46:5
34+
--> $DIR/eq_op.rs:47:5
3535
|
3636
LL | a <= b && b >= a;
3737
| ^^^^^^^^^^^^^^^^ help: try: `a <= b`
3838

3939
error: equal expressions as operands to `==`
40-
--> $DIR/eq_op.rs:8:5
40+
--> $DIR/eq_op.rs:9:5
4141
|
4242
LL | 1 == 1;
4343
| ^^^^^^
4444
|
4545
= note: `-D clippy::eq-op` implied by `-D warnings`
4646

4747
error: equal expressions as operands to `==`
48-
--> $DIR/eq_op.rs:9:5
48+
--> $DIR/eq_op.rs:10:5
4949
|
5050
LL | "no" == "no";
5151
| ^^^^^^^^^^^^
5252

5353
error: equal expressions as operands to `!=`
54-
--> $DIR/eq_op.rs:11:5
54+
--> $DIR/eq_op.rs:12:5
5555
|
5656
LL | false != false;
5757
| ^^^^^^^^^^^^^^
5858

5959
error: equal expressions as operands to `<`
60-
--> $DIR/eq_op.rs:12:5
60+
--> $DIR/eq_op.rs:13:5
6161
|
6262
LL | 1.5 < 1.5;
6363
| ^^^^^^^^^
6464

6565
error: equal expressions as operands to `>=`
66-
--> $DIR/eq_op.rs:13:5
66+
--> $DIR/eq_op.rs:14:5
6767
|
6868
LL | 1u64 >= 1u64;
6969
| ^^^^^^^^^^^^
7070

7171
error: equal expressions as operands to `&`
72-
--> $DIR/eq_op.rs:16:5
72+
--> $DIR/eq_op.rs:17:5
7373
|
7474
LL | (1 as u64) & (1 as u64);
7575
| ^^^^^^^^^^^^^^^^^^^^^^^
7676

7777
error: equal expressions as operands to `^`
78-
--> $DIR/eq_op.rs:17:5
78+
--> $DIR/eq_op.rs:18:5
7979
|
8080
LL | 1 ^ ((((((1))))));
8181
| ^^^^^^^^^^^^^^^^^
8282

8383
error: equal expressions as operands to `<`
84-
--> $DIR/eq_op.rs:20:5
84+
--> $DIR/eq_op.rs:21:5
8585
|
8686
LL | (-(2) < -(2));
8787
| ^^^^^^^^^^^^^
8888

8989
error: equal expressions as operands to `==`
90-
--> $DIR/eq_op.rs:21:5
90+
--> $DIR/eq_op.rs:22:5
9191
|
9292
LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
9393
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9494

9595
error: equal expressions as operands to `&`
96-
--> $DIR/eq_op.rs:21:6
96+
--> $DIR/eq_op.rs:22:6
9797
|
9898
LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
9999
| ^^^^^^^^^^^^^^^^^
100100

101101
error: equal expressions as operands to `&`
102-
--> $DIR/eq_op.rs:21:27
102+
--> $DIR/eq_op.rs:22:27
103103
|
104104
LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
105105
| ^^^^^^^^^^^^^^^^^
106106

107107
error: equal expressions as operands to `==`
108-
--> $DIR/eq_op.rs:22:5
108+
--> $DIR/eq_op.rs:23:5
109109
|
110110
LL | (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
111111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112112

113113
error: equal expressions as operands to `!=`
114-
--> $DIR/eq_op.rs:25:5
114+
--> $DIR/eq_op.rs:26:5
115115
|
116116
LL | ([1] != [1]);
117117
| ^^^^^^^^^^^^
118118

119119
error: equal expressions as operands to `!=`
120-
--> $DIR/eq_op.rs:26:5
120+
--> $DIR/eq_op.rs:27:5
121121
|
122122
LL | ((1, 2) != (1, 2));
123123
| ^^^^^^^^^^^^^^^^^^
124124

125125
error: equal expressions as operands to `==`
126-
--> $DIR/eq_op.rs:30:5
126+
--> $DIR/eq_op.rs:31:5
127127
|
128128
LL | 1 + 1 == 2;
129129
| ^^^^^^^^^^
130130

131131
error: equal expressions as operands to `==`
132-
--> $DIR/eq_op.rs:31:5
132+
--> $DIR/eq_op.rs:32:5
133133
|
134134
LL | 1 - 1 == 0;
135135
| ^^^^^^^^^^
136136

137137
error: equal expressions as operands to `-`
138-
--> $DIR/eq_op.rs:31:5
138+
--> $DIR/eq_op.rs:32:5
139139
|
140140
LL | 1 - 1 == 0;
141141
| ^^^^^
142142

143143
error: equal expressions as operands to `-`
144-
--> $DIR/eq_op.rs:33:5
144+
--> $DIR/eq_op.rs:34:5
145145
|
146146
LL | 1 - 1;
147147
| ^^^^^
148148

149149
error: equal expressions as operands to `/`
150-
--> $DIR/eq_op.rs:34:5
150+
--> $DIR/eq_op.rs:35:5
151151
|
152152
LL | 1 / 1;
153153
| ^^^^^
154154

155155
error: equal expressions as operands to `&&`
156-
--> $DIR/eq_op.rs:35:5
156+
--> $DIR/eq_op.rs:36:5
157157
|
158158
LL | true && true;
159159
| ^^^^^^^^^^^^
160160

161161
error: equal expressions as operands to `||`
162-
--> $DIR/eq_op.rs:37:5
162+
--> $DIR/eq_op.rs:38:5
163163
|
164164
LL | true || true;
165165
| ^^^^^^^^^^^^
166166

167167
error: equal expressions as operands to `&&`
168-
--> $DIR/eq_op.rs:43:5
168+
--> $DIR/eq_op.rs:44:5
169169
|
170170
LL | a == b && b == a;
171171
| ^^^^^^^^^^^^^^^^
172172

173173
error: equal expressions as operands to `&&`
174-
--> $DIR/eq_op.rs:44:5
174+
--> $DIR/eq_op.rs:45:5
175175
|
176176
LL | a != b && b != a;
177177
| ^^^^^^^^^^^^^^^^
178178

179179
error: equal expressions as operands to `&&`
180-
--> $DIR/eq_op.rs:45:5
180+
--> $DIR/eq_op.rs:46:5
181181
|
182182
LL | a < b && b > a;
183183
| ^^^^^^^^^^^^^^
184184

185185
error: equal expressions as operands to `&&`
186-
--> $DIR/eq_op.rs:46:5
186+
--> $DIR/eq_op.rs:47:5
187187
|
188188
LL | a <= b && b >= a;
189189
| ^^^^^^^^^^^^^^^^
190190

191191
error: equal expressions as operands to `==`
192-
--> $DIR/eq_op.rs:49:5
192+
--> $DIR/eq_op.rs:50:5
193193
|
194194
LL | a == a;
195195
| ^^^^^^
196196

197-
error: taken reference of right operand
198-
--> $DIR/eq_op.rs:87:13
199-
|
200-
LL | let z = x & &y;
201-
| ^^^^--
202-
| |
203-
| help: use the right value directly: `y`
204-
|
205-
= note: `-D clippy::op-ref` implied by `-D warnings`
206-
207197
error: equal expressions as operands to `/`
208-
--> $DIR/eq_op.rs:95:20
198+
--> $DIR/eq_op.rs:60:20
209199
|
210200
LL | const D: u32 = A / A;
211201
| ^^^^^
212202

213-
error: aborting due to 34 previous errors
203+
error: aborting due to 33 previous errors
214204

tests/ui/op_ref.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![allow(unused_variables, clippy::blacklisted_name)]
2-
2+
#![warn(clippy::op_ref)]
3+
#![allow(clippy::many_single_char_names)]
34
use std::collections::HashSet;
5+
use std::ops::BitAnd;
46

57
fn main() {
68
let tracked_fds: HashSet<i32> = HashSet::new();
@@ -18,4 +20,39 @@ fn main() {
1820
if b < &a {
1921
println!("OK");
2022
}
23+
24+
struct X(i32);
25+
impl BitAnd for X {
26+
type Output = X;
27+
fn bitand(self, rhs: X) -> X {
28+
X(self.0 & rhs.0)
29+
}
30+
}
31+
impl<'a> BitAnd<&'a X> for X {
32+
type Output = X;
33+
fn bitand(self, rhs: &'a X) -> X {
34+
X(self.0 & rhs.0)
35+
}
36+
}
37+
let x = X(1);
38+
let y = X(2);
39+
let z = x & &y;
40+
41+
#[derive(Copy, Clone)]
42+
struct Y(i32);
43+
impl BitAnd for Y {
44+
type Output = Y;
45+
fn bitand(self, rhs: Y) -> Y {
46+
Y(self.0 & rhs.0)
47+
}
48+
}
49+
impl<'a> BitAnd<&'a Y> for Y {
50+
type Output = Y;
51+
fn bitand(self, rhs: &'a Y) -> Y {
52+
Y(self.0 & rhs.0)
53+
}
54+
}
55+
let x = Y(1);
56+
let y = Y(2);
57+
let z = x & &y;
2158
}

tests/ui/op_ref.stderr

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: needlessly taken reference of both operands
2-
--> $DIR/op_ref.rs:10:15
2+
--> $DIR/op_ref.rs:12:15
33
|
44
LL | let foo = &5 - &6;
55
| ^^^^^^^
@@ -11,12 +11,20 @@ LL | let foo = 5 - 6;
1111
| ^ ^
1212

1313
error: taken reference of right operand
14-
--> $DIR/op_ref.rs:18:8
14+
--> $DIR/op_ref.rs:20:8
1515
|
1616
LL | if b < &a {
1717
| ^^^^--
1818
| |
1919
| help: use the right value directly: `a`
2020

21-
error: aborting due to 2 previous errors
21+
error: taken reference of right operand
22+
--> $DIR/op_ref.rs:57:13
23+
|
24+
LL | let z = x & &y;
25+
| ^^^^--
26+
| |
27+
| help: use the right value directly: `y`
28+
29+
error: aborting due to 3 previous errors
2230

0 commit comments

Comments
 (0)