RS.CLIPPY.ASSIGN_OP_PATTERN
Assigning the result of an operation on a variable to that same variable
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: assign_op_pattern. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for a = a op b or a = b commutative_op a
patterns.
Why is this bad?
These can be written as the shorter a op= b.
Known problems
While forbidden by the spec, OpAssign traits may have
implementations that differ from the regular Op impl.
Example
let mut a = 5;
let b = 0;
// ...
a = a + b;
Use instead:
let mut a = 5;
let b = 0;
// ...
a += b;