rust-lang / rust-lang/rust-clippy

`redundant_clone` could also fire when the containing object will be dropped

Open
#15,858 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement I-false-negative
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.