Open
Description
I wonder if it is possible to have an optimization pass that removes redundant clones if we know that .clone()
does not do anything funky and that the original object would have been untouched and dropped in the same block where it was cloned.
There's a clippy lint which tries to warn about useless clones https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
The pass could optimize something like
#[derive(Clone)]
pub struct S {
inner: String,
}
pub fn a(a: S) -> S {
a.clone()
}
to
#[derive(Clone)]
pub struct S {
inner: String,
}
pub fn a(a: S) -> S {
a // just return the object
}