Z010: Prefer anonymous init when type is known
When returning or passing a struct/enum value where a concrete type is already known from context, use anonymous initialization (.{} or .value) instead of explicit type initialization (Type{} or Type.value).
Examples
Bad
// expect: Z010
fn getPoint() Point {
return Point{ .x = 0, .y = 0 };
}// expect: Z010
fn getStatus() Status {
return Status.ok;
}Good
fn getPoint() Point {
return .{ .x = 0, .y = 0 };
}fn getStatus() Status {
return .ok;
}
Also applies to function arguments:
fn process(point: Point) void {
_ = point;
}
fn run() void {
process(.{ .x = 0, .y = 0 });
}
Explicit initialization is preserved for anytype, generic, and unresolved parameters because replacing the named type could change the argument's type or behavior.
Rationale
When the type is known from context (return type, parameter type), repeating it is redundant. Anonymous initialization is more concise and idiomatic Zig. This is especially valuable when types are renamed—the anonymous form doesn't need updating.