[misrefactored_assign_op]: Fix duplicate diagnostics

This commit is contained in:
Yaodong Yang 2024-03-04 22:53:59 +08:00
parent 1df2854ac3
commit 3c5008e8de
3 changed files with 12 additions and 15 deletions

View file

@ -21,9 +21,8 @@ pub(super) fn check<'tcx>(
// lhs op= l op r
if eq_expr_value(cx, lhs, l) {
lint_misrefactored_assign_op(cx, expr, op, rhs, lhs, r);
}
} else if is_commutative(op) && eq_expr_value(cx, lhs, r) {
// lhs op= l commutative_op r
if is_commutative(op) && eq_expr_value(cx, lhs, r) {
lint_misrefactored_assign_op(cx, expr, op, rhs, lhs, l);
}
}

View file

@ -1,6 +1,4 @@
//@no-rustfix: overlapping suggestions
//@compile-flags: -Zdeduplicate-diagnostics=yes
#![allow(clippy::uninlined_format_args)]
#[allow(unused_assignments)]

View file

@ -1,5 +1,5 @@
error: variable appears on both sides of an assignment operation
--> tests/ui/assign_ops2.rs:10:5
--> tests/ui/assign_ops2.rs:8:5
|
LL | a += a + 1;
| ^^^^^^^^^^
@ -16,7 +16,7 @@ LL | a = a + a + 1;
| ~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
--> tests/ui/assign_ops2.rs:13:5
--> tests/ui/assign_ops2.rs:11:5
|
LL | a += 1 + a;
| ^^^^^^^^^^
@ -31,7 +31,7 @@ LL | a = a + 1 + a;
| ~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
--> tests/ui/assign_ops2.rs:15:5
--> tests/ui/assign_ops2.rs:13:5
|
LL | a -= a - 1;
| ^^^^^^^^^^
@ -46,7 +46,7 @@ LL | a = a - (a - 1);
| ~~~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
--> tests/ui/assign_ops2.rs:17:5
--> tests/ui/assign_ops2.rs:15:5
|
LL | a *= a * 99;
| ^^^^^^^^^^^
@ -61,7 +61,7 @@ LL | a = a * a * 99;
| ~~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
--> tests/ui/assign_ops2.rs:19:5
--> tests/ui/assign_ops2.rs:17:5
|
LL | a *= 42 * a;
| ^^^^^^^^^^^
@ -76,7 +76,7 @@ LL | a = a * 42 * a;
| ~~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
--> tests/ui/assign_ops2.rs:21:5
--> tests/ui/assign_ops2.rs:19:5
|
LL | a /= a / 2;
| ^^^^^^^^^^
@ -91,7 +91,7 @@ LL | a = a / (a / 2);
| ~~~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
--> tests/ui/assign_ops2.rs:23:5
--> tests/ui/assign_ops2.rs:21:5
|
LL | a %= a % 5;
| ^^^^^^^^^^
@ -106,7 +106,7 @@ LL | a = a % (a % 5);
| ~~~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
--> tests/ui/assign_ops2.rs:25:5
--> tests/ui/assign_ops2.rs:23:5
|
LL | a &= a & 1;
| ^^^^^^^^^^
@ -121,7 +121,7 @@ LL | a = a & a & 1;
| ~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
--> tests/ui/assign_ops2.rs:27:5
--> tests/ui/assign_ops2.rs:25:5
|
LL | a *= a * a;
| ^^^^^^^^^^
@ -136,7 +136,7 @@ LL | a = a * a * a;
| ~~~~~~~~~~~~~
error: manual implementation of an assign operation
--> tests/ui/assign_ops2.rs:65:5
--> tests/ui/assign_ops2.rs:63:5
|
LL | buf = buf + cows.clone();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()`