diff options
| author | bors <bors@rust-lang.org> | 2024-03-05 14:34:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-05 14:34:56 +0000 |
| commit | 2d9d404448cd818735eaa2803d24de219667abf8 (patch) | |
| tree | fe66b55da92745163386128d0d99c33ea755ba4e | |
| parent | 21efd39b04b731ad1ae189334bc39c37e7dc0b6f (diff) | |
| parent | 3c5008e8de394b7bdab715704b4bbb0fb7c4d37b (diff) | |
| download | rust-2d9d404448cd818735eaa2803d24de219667abf8.tar.gz rust-2d9d404448cd818735eaa2803d24de219667abf8.zip | |
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
| -rw-r--r-- | clippy_lints/src/operators/misrefactored_assign_op.rs | 5 | ||||
| -rw-r--r-- | tests/ui/assign_ops2.rs | 2 | ||||
| -rw-r--r-- | tests/ui/assign_ops2.stderr | 20 |
3 files changed, 12 insertions, 15 deletions
diff --git a/clippy_lints/src/operators/misrefactored_assign_op.rs b/clippy_lints/src/operators/misrefactored_assign_op.rs index fecc5a8578e..311cbd050a1 100644 --- a/clippy_lints/src/operators/misrefactored_assign_op.rs +++ b/clippy_lints/src/operators/misrefactored_assign_op.rs @@ -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); - } - // lhs op= l commutative_op r - if is_commutative(op) && eq_expr_value(cx, lhs, r) { + } else if is_commutative(op) && eq_expr_value(cx, lhs, r) { + // lhs op= l commutative_op r lint_misrefactored_assign_op(cx, expr, op, rhs, lhs, l); } } diff --git a/tests/ui/assign_ops2.rs b/tests/ui/assign_ops2.rs index 8379159a27d..a5355642584 100644 --- a/tests/ui/assign_ops2.rs +++ b/tests/ui/assign_ops2.rs @@ -1,6 +1,4 @@ //@no-rustfix: overlapping suggestions -//@compile-flags: -Zdeduplicate-diagnostics=yes - #![allow(clippy::uninlined_format_args)] #[allow(unused_assignments)] diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr index ed86459eb53..ddeba2b2ff8 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -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()` |
