diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 50735b0ec8b561df91a2460660c2101e8b2f4fcb..7b75aed28ecb0d46b632031b1de9421c8a3d4f22 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -7,6 +7,15 @@ test "zig fmt: trailing comma in container declaration" { \\const X = struct { foo: i32 align(4) = 1, bar: i32 align(4) = 2 }; \\ ); + try testTransform( + \\const X = struct { + \\ foo: i32, bar: i8 }; + , + \\const X = struct { + \\ foo: i32, bar: i8 + \\}; + \\ + ); } test "zig fmt: trailing comma in fn parameter list" { diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 993b30b0ee0952f3e4f9df4316ff33e55793c400..5fda700484174e570f9640411aee59e35d4cc792 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -1181,8 +1181,8 @@ fn renderExpression( // Check if the first declaration and the { are on the same line const src_has_newline = !tree.tokensOnSameLine( + container_decl.lbrace_token, container_decl.fields_and_decls.at(0).*.firstToken(), - container_decl.rbrace_token, ); // We can only print all the elements in-line if all the