rust-lang / rust-lang/rust-clippy
automatic fixing does not account for repeated clone() calls correctly
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
automatic fixing does not account for repeated clone() calls correctly
Reproducer
I tried this code and ran cargo clippy --fix:
fn eat<T>(_a: T) {}
fn x() {
let a = vec![1; 32];
eat(a.clone().clone());
eat(a);
}
I expected to see this happen: one clone call is removed
Instead, this happened: clippy tries to remove both clone calls, because it thinks both are redundant, which is true if you consider them in isolation, but it does not follow that if either is redundant that both together are also redundant.
Version
rustc 1.69.0-nightly (84c898d65 2023-04-16) (gentoo)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided Rust example and cargo clippy --fix, focusing on the repeated clone() calls. Trace the automatic-fix behavior for the two nested calls; done means the fix removes only one clone call rather than attempting to remove both.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100