Skip to content

False negative clone-on-copy #5436

@p3s

Description

@p3s

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions