Skip to content

Commit 2d9d404

Browse files
committed
Auto merge of #12413 - high-cloud:fix_assign_ops2, r=flip1995
[`misrefactored_assign_op`]: Fix duplicate diagnostics Relate to #12379 The following diagnostics appear twice ``` --> tests/ui/assign_ops2.rs:26:5 | LL | a *= a * a; | ^^^^^^^^^^ | help: did you mean `a = a * a` or `a = a * a * a`? Consider replacing it with ``` because `a` (lhs) appears in both left operand and right operand in the right hand side. This PR fixes the issue so that if a diagnostic is created for an operand, the check of the other operand will be skipped. It's fine because the result is always the same in the affected operators. changelog: [`misrefactored_assign_op`]: Fix duplicate diagnostics
2 parents 21efd39 + 3c5008e commit 2d9d404

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

clippy_lints/src/operators/misrefactored_assign_op.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ pub(super) fn check<'tcx>(
2121
// lhs op= l op r
2222
if eq_expr_value(cx, lhs, l) {
2323
lint_misrefactored_assign_op(cx, expr, op, rhs, lhs, r);
24-
}
25-
// lhs op= l commutative_op r
26-
if is_commutative(op) && eq_expr_value(cx, lhs, r) {
24+
} else if is_commutative(op) && eq_expr_value(cx, lhs, r) {
25+
// lhs op= l commutative_op r
2726
lint_misrefactored_assign_op(cx, expr, op, rhs, lhs, l);
2827
}
2928
}

tests/ui/assign_ops2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//@no-rustfix: overlapping suggestions
2-
//@compile-flags: -Zdeduplicate-diagnostics=yes
3-
42
#![allow(clippy::uninlined_format_args)]
53

64
#[allow(unused_assignments)]

tests/ui/assign_ops2.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: variable appears on both sides of an assignment operation
2-
--> tests/ui/assign_ops2.rs:10:5
2+
--> tests/ui/assign_ops2.rs:8:5
33
|
44
LL | a += a + 1;
55
| ^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | a = a + a + 1;
1616
| ~~~~~~~~~~~~~
1717

1818
error: variable appears on both sides of an assignment operation
19-
--> tests/ui/assign_ops2.rs:13:5
19+
--> tests/ui/assign_ops2.rs:11:5
2020
|
2121
LL | a += 1 + a;
2222
| ^^^^^^^^^^
@@ -31,7 +31,7 @@ LL | a = a + 1 + a;
3131
| ~~~~~~~~~~~~~
3232

3333
error: variable appears on both sides of an assignment operation
34-
--> tests/ui/assign_ops2.rs:15:5
34+
--> tests/ui/assign_ops2.rs:13:5
3535
|
3636
LL | a -= a - 1;
3737
| ^^^^^^^^^^
@@ -46,7 +46,7 @@ LL | a = a - (a - 1);
4646
| ~~~~~~~~~~~~~~~
4747

4848
error: variable appears on both sides of an assignment operation
49-
--> tests/ui/assign_ops2.rs:17:5
49+
--> tests/ui/assign_ops2.rs:15:5
5050
|
5151
LL | a *= a * 99;
5252
| ^^^^^^^^^^^
@@ -61,7 +61,7 @@ LL | a = a * a * 99;
6161
| ~~~~~~~~~~~~~~
6262

6363
error: variable appears on both sides of an assignment operation
64-
--> tests/ui/assign_ops2.rs:19:5
64+
--> tests/ui/assign_ops2.rs:17:5
6565
|
6666
LL | a *= 42 * a;
6767
| ^^^^^^^^^^^
@@ -76,7 +76,7 @@ LL | a = a * 42 * a;
7676
| ~~~~~~~~~~~~~~
7777

7878
error: variable appears on both sides of an assignment operation
79-
--> tests/ui/assign_ops2.rs:21:5
79+
--> tests/ui/assign_ops2.rs:19:5
8080
|
8181
LL | a /= a / 2;
8282
| ^^^^^^^^^^
@@ -91,7 +91,7 @@ LL | a = a / (a / 2);
9191
| ~~~~~~~~~~~~~~~
9292

9393
error: variable appears on both sides of an assignment operation
94-
--> tests/ui/assign_ops2.rs:23:5
94+
--> tests/ui/assign_ops2.rs:21:5
9595
|
9696
LL | a %= a % 5;
9797
| ^^^^^^^^^^
@@ -106,7 +106,7 @@ LL | a = a % (a % 5);
106106
| ~~~~~~~~~~~~~~~
107107

108108
error: variable appears on both sides of an assignment operation
109-
--> tests/ui/assign_ops2.rs:25:5
109+
--> tests/ui/assign_ops2.rs:23:5
110110
|
111111
LL | a &= a & 1;
112112
| ^^^^^^^^^^
@@ -121,7 +121,7 @@ LL | a = a & a & 1;
121121
| ~~~~~~~~~~~~~
122122

123123
error: variable appears on both sides of an assignment operation
124-
--> tests/ui/assign_ops2.rs:27:5
124+
--> tests/ui/assign_ops2.rs:25:5
125125
|
126126
LL | a *= a * a;
127127
| ^^^^^^^^^^
@@ -136,7 +136,7 @@ LL | a = a * a * a;
136136
| ~~~~~~~~~~~~~
137137

138138
error: manual implementation of an assign operation
139-
--> tests/ui/assign_ops2.rs:65:5
139+
--> tests/ui/assign_ops2.rs:63:5
140140
|
141141
LL | buf = buf + cows.clone();
142142
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()`

0 commit comments

Comments
 (0)