RS.CLIPPY.SELF_ASSIGNMENT
Explicit self-assignment
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: self_assignment. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for explicit self-assignments.
Why is this bad?
Self-assignments are redundant and unlikely to be intentional.
Known problems
If expression contains any deref coercions or indexing operations they are assumed not to have any side effects.
Example
struct Event {
x: i32,
}
fn copy_position(a: &mut Event, b: &Event) {
a.x = a.x;
}
Should be:
struct Event {
x: i32,
}
fn copy_position(a: &mut Event, b: &Event) {
a.x = b.x;
}