diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 50735b0ec8..7b75aed28e 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 993b30b0ee..5fda700484 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