Skip to content

Use of a = b.clone() instead of a.clone_from(&b) #9512

Closed
@laralove143

Description

@laralove143

What it does

Catches the places where clone_from could be used instead

Lint Name

clone_from_candidate

Category

pedantic

Advantage

From the docs

  • a.clone_from(&b) is equivalent to a = b.clone() in functionality, but can be overridden to reuse the resources of a to avoid unnecessary allocations.

Drawbacks

I can't think of any

Example

let mut a = "a".to_owned();
let b = "b".to_owned();
a = b.clone();
drop(b);

Could be written as:

let mut a = "a".to_owned();
let b = "b".to_owned();
a.clone_from(&b);
drop(b);

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions