Variable or field assigned to itself
ID |
rust.correctness.self_assignment |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Logic |
Language |
Rust |
Description
Assigning a value to itself has no effect and usually means the wrong name was typed on one side. Check which value was meant to be written here.
Rationale
Assigning a value to itself has no effect and usually means the wrong name was typed on one side. Check which value was meant to be written here.
The following code illustrates the pattern detected by this rule:
struct Counter {
count: usize,
}
impl Counter {
fn reset(&mut self) {
// FLAGGED: Variable or field assigned to itself
self.count = self.count;
}
}
Remediation
Follow secure coding practices and review the references below for detailed remediation guidance.