Commit d645500883
Changed files (2)
std
std/zig/parser_test.zig
@@ -1027,6 +1027,19 @@ test "zig fmt: line comments in struct initializer" {
);
}
+test "zig fmt: first line comment in struct initializer" {
+ try testCanonical(
+ \\pub async fn acquire(self: *Self) HeldLock {
+ \\ return HeldLock{
+ \\ // TODO guaranteed allocation elision
+ \\ .held = await (async self.lock.acquire() catch unreachable),
+ \\ .value = &self.private_data,
+ \\ };
+ \\}
+ \\
+ );
+}
+
test "zig fmt: doc comments before struct field" {
try testCanonical(
\\pub const Allocator = struct {
std/zig/render.zig
@@ -658,11 +658,11 @@ fn renderExpression(
return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space);
}
- try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
- try renderToken(tree, stream, lbrace, indent, start_col, Space.Newline);
-
const new_indent = indent + indent_delta;
+ try renderExpression(allocator, stream, tree, new_indent, start_col, suffix_op.lhs, Space.None);
+ try renderToken(tree, stream, lbrace, new_indent, start_col, Space.Newline);
+
var it = field_inits.iterator(0);
while (it.next()) |field_init| {
try stream.writeByteNTimes(' ', new_indent);