Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False negative clone-on-copy #5436

Closed
p3s opened this issue Apr 8, 2020 · 0 comments · Fixed by #5441
Closed

False negative clone-on-copy #5436

p3s opened this issue Apr 8, 2020 · 0 comments · Fixed by #5441
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience.

Comments

@p3s
Copy link

p3s commented Apr 8, 2020

Hi folks,
I ran this code under Clippy:

fn foo() {
    let mut vec = Vec::new();
    let key = (0, 0);

    vec.push(key.clone());

    let _ = key.clone();
}

Clippy produced this error:

error: using `clone` on a `Copy` type
 --> src/lib.rs:7:13
  |
7 |     let _ = key.clone();
  |             ^^^^^^^^^^^ help: try removing the `clone` call: `key`
  |
  = note: `-D clippy::clone-on-copy` implied by `-D warnings`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

I expected to see same error in vec.push(key.clone()) but Clippy is silent about it. After removing .clone() in line 5 it does compile fine, so I assume it is redundant.

Can someone explain to me what is the difference here?

Output of cargo clippy -V
clippy 0.0.212 (4ee1206 2020-02-01)

@flip1995 flip1995 added C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. labels Apr 8, 2020
rabisg0 added a commit to rabisg0/rust-clippy that referenced this issue Apr 9, 2020
Earlier if arguments to method calls matched the above pattern they were
not reported. This patch ensures such arguments are checked as well.

Fixes rust-lang#5436
bors added a commit that referenced this issue Apr 10, 2020
Check for clone-on-copy in argument positions

Earlier if arguments to method calls matched the above pattern they were
not reported. This patch ensures such arguments are checked as well.

Fixes #5436

changelog: apply clone_on_copy lint to func args as well
@bors bors closed this as completed in 183c4ab Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants