Skip to content

Commit 6135549

Browse files
committed
fix tuple indentation
1 parent 811b171 commit 6135549

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/std/Build/Step/Options.zig

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn printTypeDefinition(options: *Options, out: Writer, comptime T: type) !void {
7777
if (@"struct".is_tuple) return;
7878

7979
try out.print("pub const {} = ", .{std.zig.fmtId(@typeName(T))});
80-
try printStructDefinition(options, out, T);
80+
try printStructDefinition(options, out, T, 0);
8181
try out.writeAll(";\n\n");
8282
},
8383
.@"union" => |@"union"| {
@@ -114,36 +114,38 @@ fn printEnumDefinition(options: *Options, out: Writer, comptime T: type) !void {
114114
try out.writeAll("}");
115115
}
116116
117-
fn printStructDefinition(options: *Options, out: Writer, comptime T: type) !void {
117+
fn printStructDefinition(options: *Options, out: Writer, comptime T: type, indent: u8) !void {
118118
const @"struct" = @typeInfo(T).@"struct";
119119
120120
switch (@"struct".layout) {
121121
.auto => try out.writeAll("struct"),
122122
.@"extern" => try out.writeAll("extern struct"),
123123
.@"packed" => {
124124
try out.writeAll("packed struct(");
125-
try printTypeName(options, out, @"struct".backing_integer.?, indent_width);
125+
try printTypeName(options, out, @"struct".backing_integer.?, indent);
126126
try out.writeAll(")");
127127
},
128128
}
129129
if (@"struct".fields.len == 0) return out.writeAll(" {}");
130130
try out.writeAll(" {\n");
131131
132132
inline for (@"struct".fields) |field| {
133-
try out.writeAll(" " ** indent_width);
133+
const field_indent = indent +| indent_width;
134+
try out.writeByteNTimes(' ', field_indent);
134135
if (field.is_comptime) try out.writeAll("comptime ");
135136
if (!@"struct".is_tuple) try out.print("{p_}: ", .{std.zig.fmtId(field.name)});
136-
try printTypeName(options, out, field.type, indent_width);
137+
try printTypeName(options, out, field.type, field_indent);
137138
if (!@"struct".is_tuple and @"struct".layout != .@"packed" and field.alignment != @alignOf(field.type)) {
138139
try out.print(" align({})", .{field.alignment});
139140
}
140141
if (field.defaultValue()) |default_value| {
141142
try out.writeAll(" = ");
142-
try printValue(options, out, field.type, default_value, indent_width);
143+
try printValue(options, out, field.type, default_value, field_indent);
143144
}
144145
try out.writeAll(",\n");
145146
}
146147
148+
try out.writeByteNTimes(' ', indent);
147149
try out.writeAll("}");
148150
}
149151
@@ -216,7 +218,7 @@ fn printTypeName(options: *Options, out: Writer, comptime T: type, indent: u8) !
216218
.@"enum" => try out.print("{}", .{std.zig.fmtId(@typeName(T))}),
217219
.@"struct" => |@"struct"| {
218220
if (@"struct".is_tuple) {
219-
try printStructDefinition(options, out, T);
221+
try printStructDefinition(options, out, T, indent);
220222
} else {
221223
try out.print("{}", .{std.zig.fmtId(@typeName(T))});
222224
}
@@ -276,10 +278,10 @@ fn printValue(options: *Options, out: Writer, comptime T: type, value: T, indent
276278

277279
try out.writeAll(".{\n");
278280
inline for (@"struct".fields) |field| {
279-
const elem_indent = indent +| indent_width;
280-
try out.writeByteNTimes(' ', elem_indent);
281+
const field_indent = indent +| indent_width;
282+
try out.writeByteNTimes(' ', field_indent);
281283
if (!@"struct".is_tuple) try out.print(".{p_} = ", .{std.zig.fmtId(field.name)});
282-
try printValue(options, out, field.type, @field(value, field.name), elem_indent);
284+
try printValue(options, out, field.type, @field(value, field.name), field_indent);
283285
try out.writeAll(",\n");
284286
}
285287
try out.writeByteNTimes(' ', indent);

0 commit comments

Comments
 (0)