RS.CLIPPY.MISREFACTORED_ASSIGN_OP

Having a variable on both sides of an assign op

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: misrefactored_assign_op. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for a op= a op b or a op= b op a patterns.

Why is this bad?

Most likely these are bugs where one meant to write a op= b.

Known problems

Clippy cannot know for sure if a op= a op b should have been a = a op a op b or a = a op b/a op= b. Therefore, it suggests both. If a op= a op b is really the correct behavior it should be written as a = a op a op b as it's less confusing.

Example

let mut a = 5;
let b = 2;
// ...
a += a + b;