Rust

Rust

Made by DeepSource

Found call to clone() on type that implements Copy RS-W1110

Anti-pattern
Minor

In Rust, it is generally considered bad practice to use the .clone() method on types that implement the Copy trait. This is because the Copy trait indicates that the type is a simple, immutable value that can be copied cheaply and efficiently.

Instead of explicitly calling clone(), it is better to use the Copy trait to automatically copy the value.

For example, if you have a variable x of type i32, which implements the Copy trait, you can simply assign x to another variable y like this:

let x = 5;
let y = x;

This will automatically copy the value of x into y, without the need to explicitly call clone().

If you are unsure whether a type implements the Copy trait, you can check its documentation or the source code to see if it is marked with the #[derive(Copy)] attribute. This indicates that the type automatically derives the Copy trait.

Hence, consider removing the call to clone().

Bad practice

let a : i32 = 10;
let b = a.clone();

Recommended

let a : i32 = 10;
let b = a;