Struct field initialized with a variable of the same name

ID

rust.maintainability.redundant_field_names

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Redundant Code

Language

Rust

Description

Reports a struct literal field written as name: name, where the initializer is a variable with exactly the field’s name. Field-init shorthand covers that case with the name alone.

Rationale

Repeating the name doubles the length of every field and buries the fields that are actually computed among the ones that are not, so the interesting part of a literal is harder to find. In a wide literal it also means a rename has to be applied twice per field.

The following code illustrates the pattern detected by this rule:

pub struct Point {
    x: i32,
    y: i32,
}

pub fn make_point(x: i32, y: i32) -> Point {
    // FLAGGED: Struct field initialized with a variable of the same name
    Point { x: x, y: y }
}

Remediation

Use field-init shorthand: Point { x: x, y: y } becomes Point { x, y }. Fields whose value is computed keep the long form, which is what makes them stand out.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved