rust-lang / rust-lang/rust-clippy
`redundant_clone` could also fire when the containing object will be dropped
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Consider this code from Zed:
pub fn append(&mut self, rope: Rope) {
// ....
self.chunks.append(rope.chunks.clone(), ());
self.check_invariants();
}
rope is passed by value and dropped at the end of the function. I think we can eliminate the clone and just consume rope.chunks.
Clippy doesn't warn about this even with clippy::redundant_clones turned on, I think because it's a more complex situation of consuming one field from a struct.
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 with the redundant_clones lint entry point and its existing tests, using the Rust example in Zed's crates/rope/src/rope.rs as the behavioral case. Determine how the lint handles consuming a field from a by-value parameter, then add coverage showing that the clone is unnecessary when the containing object is dropped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100