-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-mir-optArea: MIR optimizationsArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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
}Metadata
Metadata
Assignees
Labels
A-mir-optArea: MIR optimizationsArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.