aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorShritesh Bhattarai <shritesh@shritesh.com>2019-03-31 21:28:28 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-03-31 22:33:32 -0400
commitd6455008830eff433a14c5eff6094f2f5ba9991d (patch)
tree4ea2109b54cc4a0800e6aa685913d1ad78001c2f /std
parent0563e8e1d4181a2707a1898941ccf59d974bc835 (diff)
downloadzig-d6455008830eff433a14c5eff6094f2f5ba9991d.tar.gz
zig-d6455008830eff433a14c5eff6094f2f5ba9991d.zip
fmt: fix first line comment indent in struct init
Diffstat (limited to 'std')
-rw-r--r--std/zig/parser_test.zig13
-rw-r--r--std/zig/render.zig6
2 files changed, 16 insertions, 3 deletions
diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig
index 85bb3d5f86..0b521f5eaa 100644
--- a/std/zig/parser_test.zig
+++ b/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 {
diff --git a/std/zig/render.zig b/std/zig/render.zig
index 245505b311..fb4e372a05 100644
--- a/std/zig/render.zig
+++ b/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);