fn consumer(v: MyClonableType) { ... }
fn foo() {
let val = MyClonableType::new();
consumer(val.clone());
consumer(val.clone());
consumer(val.clone());
consumer(val.clone());
consumer(val); // val is not returned, we may just use it
}
After a round of refactoring, I removed the last two consumer() invocations, and didn't notice that I may also remove the last clone. In the real-world there were a lot of code around, I simply overlooked that.
My question: is it possible to detect such cases, when we may return the original value, rather its clone? I run clippy, but it didn't suggest anything.