Skip to content

Commit 48d6ef5

Browse files
committed
Auto merge of #4558 - Manishearth:suggestions, r=phansch
Make more tests rustfixable changelog: Fix various lint suggestions Progress towards #3630 r? @phansch
2 parents ca9e4ad + 33f1415 commit 48d6ef5

22 files changed

+675
-224
lines changed

clippy_lints/src/assign_ops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,13 @@ fn lint_misrefactored_assign_op(
216216
long
217217
),
218218
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
219-
Applicability::MachineApplicable,
219+
Applicability::MaybeIncorrect,
220220
);
221221
db.span_suggestion(
222222
expr.span,
223223
"or",
224224
long,
225-
Applicability::MachineApplicable, // snippet
225+
Applicability::MaybeIncorrect, // snippet
226226
);
227227
}
228228
},

clippy_lints/src/loops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx
12721272
let start_snippet = snippet(cx, start.span, "_");
12731273
let end_snippet = snippet(cx, end.span, "_");
12741274
let dots = if limits == ast::RangeLimits::Closed {
1275-
"..."
1275+
"..="
12761276
} else {
12771277
".."
12781278
};

tests/ui/deref_addrof_double_trigger.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// This test can't work with run-rustfix because it needs two passes of test+fix
2+
13
#[warn(clippy::deref_addrof)]
2-
#[allow(unused_variables)]
4+
#[allow(unused_variables, unused_mut)]
35
fn main() {
46
let a = 10;
57

tests/ui/deref_addrof_double_trigger.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error: immediately dereferencing a reference
2-
--> $DIR/deref_addrof_double_trigger.rs:8:14
2+
--> $DIR/deref_addrof_double_trigger.rs:10:14
33
|
44
LL | let b = **&&a;
55
| ^^^^ help: try this: `&a`
66
|
77
= note: `-D clippy::deref-addrof` implied by `-D warnings`
88

99
error: immediately dereferencing a reference
10-
--> $DIR/deref_addrof_double_trigger.rs:12:17
10+
--> $DIR/deref_addrof_double_trigger.rs:14:17
1111
|
1212
LL | let y = *&mut x;
1313
| ^^^^^^^ help: try this: `x`
1414

1515
error: immediately dereferencing a reference
16-
--> $DIR/deref_addrof_double_trigger.rs:19:18
16+
--> $DIR/deref_addrof_double_trigger.rs:21:18
1717
|
1818
LL | let y = **&mut &mut x;
1919
| ^^^^^^^^^^^^ help: try this: `&mut x`

tests/ui/eq_op.rs

+2-37
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#[warn(clippy::eq_op)]
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)]
5-
#[warn(clippy::nonminimal_bool)]
5+
#[allow(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

+28-76
Original file line numberDiff line numberDiff line change
@@ -1,214 +1,166 @@
1-
error: this boolean expression can be simplified
2-
--> $DIR/eq_op.rs:35:5
3-
|
4-
LL | true && true;
5-
| ^^^^^^^^^^^^ help: try: `true`
6-
|
7-
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
8-
9-
error: this boolean expression can be simplified
10-
--> $DIR/eq_op.rs:37:5
11-
|
12-
LL | true || true;
13-
| ^^^^^^^^^^^^ help: try: `true`
14-
15-
error: this boolean expression can be simplified
16-
--> $DIR/eq_op.rs:43:5
17-
|
18-
LL | a == b && b == a;
19-
| ^^^^^^^^^^^^^^^^ help: try: `a == b`
20-
21-
error: this boolean expression can be simplified
22-
--> $DIR/eq_op.rs:44:5
23-
|
24-
LL | a != b && b != a;
25-
| ^^^^^^^^^^^^^^^^ help: try: `a != b`
26-
27-
error: this boolean expression can be simplified
28-
--> $DIR/eq_op.rs:45:5
29-
|
30-
LL | a < b && b > a;
31-
| ^^^^^^^^^^^^^^ help: try: `a < b`
32-
33-
error: this boolean expression can be simplified
34-
--> $DIR/eq_op.rs:46:5
35-
|
36-
LL | a <= b && b >= a;
37-
| ^^^^^^^^^^^^^^^^ help: try: `a <= b`
38-
391
error: equal expressions as operands to `==`
40-
--> $DIR/eq_op.rs:8:5
2+
--> $DIR/eq_op.rs:9:5
413
|
424
LL | 1 == 1;
435
| ^^^^^^
446
|
457
= note: `-D clippy::eq-op` implied by `-D warnings`
468

479
error: equal expressions as operands to `==`
48-
--> $DIR/eq_op.rs:9:5
10+
--> $DIR/eq_op.rs:10:5
4911
|
5012
LL | "no" == "no";
5113
| ^^^^^^^^^^^^
5214

5315
error: equal expressions as operands to `!=`
54-
--> $DIR/eq_op.rs:11:5
16+
--> $DIR/eq_op.rs:12:5
5517
|
5618
LL | false != false;
5719
| ^^^^^^^^^^^^^^
5820

5921
error: equal expressions as operands to `<`
60-
--> $DIR/eq_op.rs:12:5
22+
--> $DIR/eq_op.rs:13:5
6123
|
6224
LL | 1.5 < 1.5;
6325
| ^^^^^^^^^
6426

6527
error: equal expressions as operands to `>=`
66-
--> $DIR/eq_op.rs:13:5
28+
--> $DIR/eq_op.rs:14:5
6729
|
6830
LL | 1u64 >= 1u64;
6931
| ^^^^^^^^^^^^
7032

7133
error: equal expressions as operands to `&`
72-
--> $DIR/eq_op.rs:16:5
34+
--> $DIR/eq_op.rs:17:5
7335
|
7436
LL | (1 as u64) & (1 as u64);
7537
| ^^^^^^^^^^^^^^^^^^^^^^^
7638

7739
error: equal expressions as operands to `^`
78-
--> $DIR/eq_op.rs:17:5
40+
--> $DIR/eq_op.rs:18:5
7941
|
8042
LL | 1 ^ ((((((1))))));
8143
| ^^^^^^^^^^^^^^^^^
8244

8345
error: equal expressions as operands to `<`
84-
--> $DIR/eq_op.rs:20:5
46+
--> $DIR/eq_op.rs:21:5
8547
|
8648
LL | (-(2) < -(2));
8749
| ^^^^^^^^^^^^^
8850

8951
error: equal expressions as operands to `==`
90-
--> $DIR/eq_op.rs:21:5
52+
--> $DIR/eq_op.rs:22:5
9153
|
9254
LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
9355
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9456

9557
error: equal expressions as operands to `&`
96-
--> $DIR/eq_op.rs:21:6
58+
--> $DIR/eq_op.rs:22:6
9759
|
9860
LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
9961
| ^^^^^^^^^^^^^^^^^
10062

10163
error: equal expressions as operands to `&`
102-
--> $DIR/eq_op.rs:21:27
64+
--> $DIR/eq_op.rs:22:27
10365
|
10466
LL | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
10567
| ^^^^^^^^^^^^^^^^^
10668

10769
error: equal expressions as operands to `==`
108-
--> $DIR/eq_op.rs:22:5
70+
--> $DIR/eq_op.rs:23:5
10971
|
11072
LL | (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
11173
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11274

11375
error: equal expressions as operands to `!=`
114-
--> $DIR/eq_op.rs:25:5
76+
--> $DIR/eq_op.rs:26:5
11577
|
11678
LL | ([1] != [1]);
11779
| ^^^^^^^^^^^^
11880

11981
error: equal expressions as operands to `!=`
120-
--> $DIR/eq_op.rs:26:5
82+
--> $DIR/eq_op.rs:27:5
12183
|
12284
LL | ((1, 2) != (1, 2));
12385
| ^^^^^^^^^^^^^^^^^^
12486

12587
error: equal expressions as operands to `==`
126-
--> $DIR/eq_op.rs:30:5
88+
--> $DIR/eq_op.rs:31:5
12789
|
12890
LL | 1 + 1 == 2;
12991
| ^^^^^^^^^^
13092

13193
error: equal expressions as operands to `==`
132-
--> $DIR/eq_op.rs:31:5
94+
--> $DIR/eq_op.rs:32:5
13395
|
13496
LL | 1 - 1 == 0;
13597
| ^^^^^^^^^^
13698

13799
error: equal expressions as operands to `-`
138-
--> $DIR/eq_op.rs:31:5
100+
--> $DIR/eq_op.rs:32:5
139101
|
140102
LL | 1 - 1 == 0;
141103
| ^^^^^
142104

143105
error: equal expressions as operands to `-`
144-
--> $DIR/eq_op.rs:33:5
106+
--> $DIR/eq_op.rs:34:5
145107
|
146108
LL | 1 - 1;
147109
| ^^^^^
148110

149111
error: equal expressions as operands to `/`
150-
--> $DIR/eq_op.rs:34:5
112+
--> $DIR/eq_op.rs:35:5
151113
|
152114
LL | 1 / 1;
153115
| ^^^^^
154116

155117
error: equal expressions as operands to `&&`
156-
--> $DIR/eq_op.rs:35:5
118+
--> $DIR/eq_op.rs:36:5
157119
|
158120
LL | true && true;
159121
| ^^^^^^^^^^^^
160122

161123
error: equal expressions as operands to `||`
162-
--> $DIR/eq_op.rs:37:5
124+
--> $DIR/eq_op.rs:38:5
163125
|
164126
LL | true || true;
165127
| ^^^^^^^^^^^^
166128

167129
error: equal expressions as operands to `&&`
168-
--> $DIR/eq_op.rs:43:5
130+
--> $DIR/eq_op.rs:44:5
169131
|
170132
LL | a == b && b == a;
171133
| ^^^^^^^^^^^^^^^^
172134

173135
error: equal expressions as operands to `&&`
174-
--> $DIR/eq_op.rs:44:5
136+
--> $DIR/eq_op.rs:45:5
175137
|
176138
LL | a != b && b != a;
177139
| ^^^^^^^^^^^^^^^^
178140

179141
error: equal expressions as operands to `&&`
180-
--> $DIR/eq_op.rs:45:5
142+
--> $DIR/eq_op.rs:46:5
181143
|
182144
LL | a < b && b > a;
183145
| ^^^^^^^^^^^^^^
184146

185147
error: equal expressions as operands to `&&`
186-
--> $DIR/eq_op.rs:46:5
148+
--> $DIR/eq_op.rs:47:5
187149
|
188150
LL | a <= b && b >= a;
189151
| ^^^^^^^^^^^^^^^^
190152

191153
error: equal expressions as operands to `==`
192-
--> $DIR/eq_op.rs:49:5
154+
--> $DIR/eq_op.rs:50:5
193155
|
194156
LL | a == a;
195157
| ^^^^^^
196158

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-
207159
error: equal expressions as operands to `/`
208-
--> $DIR/eq_op.rs:95:20
160+
--> $DIR/eq_op.rs:60:20
209161
|
210162
LL | const D: u32 = A / A;
211163
| ^^^^^
212164

213-
error: aborting due to 34 previous errors
165+
error: aborting due to 27 previous errors
214166

0 commit comments

Comments
 (0)