Skip to content

redundant_clone false positive #4633

@ehuss

Description

@ehuss

Clippy version: clippy 0.0.212 (648e5b9 2019-10-01)

I'm getting a false-positive for redundant_clone on this line. Here is a semi-reduced example:

#![allow(unused)]
#![warn(clippy::redundant_clone)]

#[derive(Clone)]
struct Version;

struct PackageId {
    inner: &'static PackageIdInner,
}

struct PackageIdInner {
    name: &'static str,
    version: Version,
}

impl PackageId {
    fn foo(name: &'static str, version: Version) {}

    fn bar(self) {
        PackageId::foo(self.inner.name, self.inner.version.clone());
        //                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ redundant clone
        // Removing clone causes:
        // ERR: cannot move out of `self.inner.version` which is behind a shared reference
    }
}

Some more examples:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions