Rust

Rust

Made by DeepSource

Found unnecessary destructure in assignment RS-W1130

Anti-pattern
Minor

In Rust, destructuring a non-copyable struct to build a new struct from it is useful because if the fields of the struct can be copied, then it would be possible to create a copy of the struct without needing to move or clone the struct itself.

On the contrary, trying to destructure a copyable struct to create a new struct is redundant as the struct itself can be directly copied.

Bad practice

#[derive(Clone, Copy)]
struct Foo { bar: String }

fn baz() {
    let a = Foo { bar: String::from("Hello, world!") };
    let b = Foo { ..a };
}

Recommended

#[derive(Clone, Copy)]
struct Foo { bar: String }

fn baz() {
    let a = Foo { bar: String::from("Hello, world!") };
    let b = a;
}