Skip to content

redundant_clone could also fire when the containing object will be dropped #15858

@sourcefrog

Description

@sourcefrog

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions