rust-lang / rust-lang/rust-clippy
`.clone().takes_self_ref()` isn't caught by clippy::redundant_clone
Open
Nobody has claimed this yet.
C-bug
I-false-negative
L-nursery
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Code of the form .clone().method(), where method takes &self, has a redundant clone. Clippy should catch this
Lint Name
redundant_clone
Reproducer
I tried this code:
#[derive(Clone)]
struct Foo;
impl Foo {
fn method(&self) {}
}
fn example(foo: &Foo) {
foo.clone().method();
}
I expected to see this happen: a warning that the .clone() call is redundant
Instead, this happened: no such warning
Version
rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: x86_64-unknown-linux-gnu
release: 1.63.0
LLVM version: 14.0.5
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 locating the redundant_clone lint implementation and its tests, then reproduce the reported Foo example where clone() is followed by a method taking &self. Add coverage for this pattern and make the lint emit a redundant-clone warning, confirming the expected behavior with the Clippy test suite.
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
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100