RS.CLIPPY.UNNECESSARY_STRUCT_INITIALIZATION

Struct built from a base that can be written mode concisely

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: unnecessary_struct_initialization. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for initialization of an identical struct from another instance of the type, either by copying a base without setting any field or by moving all fields individually.

Why is this bad?

Readability suffers from unnecessary struct building.

Example

struct S { s: String }

let a = S { s: String::from("Hello, world!") };
let b = S { ..a };

Use instead:

struct S { s: String }

let a = S { s: String::from("Hello, world!") };
let b = a;

The struct literal S { ..a } in the assignment to b could be replaced with just a.

Known Problems

Has false positives when the base is a place expression that cannot be moved out of, see #10547.

Empty structs are ignored by the lint.