Skip to content

Commit 0d96f1f

Browse files
authored
zig fmt: remove trailing comma at the end of assembly clobber
1 parent 36f4f32 commit 0d96f1f

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

lib/std/zig/parser_test.zig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ test "zig fmt: preserves clobbers in inline asm with stray comma" {
1616
);
1717
}
1818

19+
test "zig fmt: remove trailing comma at the end of assembly clobber" {
20+
try testTransform(
21+
\\fn foo() void {
22+
\\ asm volatile (""
23+
\\ : [_] "" (-> type),
24+
\\ :
25+
\\ : "clobber1", "clobber2",
26+
\\ );
27+
\\}
28+
\\
29+
,
30+
\\fn foo() void {
31+
\\ asm volatile (""
32+
\\ : [_] "" (-> type),
33+
\\ :
34+
\\ : "clobber1", "clobber2"
35+
\\ );
36+
\\}
37+
\\
38+
);
39+
}
40+
1941
test "zig fmt: respect line breaks in struct field value declaration" {
2042
try testCanonical(
2143
\\const Foo = struct {

lib/std/zig/render.zig

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,9 +2114,19 @@ fn renderAsm(
21142114
return renderToken(ais, tree, tok_i + 1, space);
21152115
},
21162116
.comma => {
2117-
try renderToken(ais, tree, tok_i, .none);
2118-
try renderToken(ais, tree, tok_i + 1, .space);
2119-
tok_i += 2;
2117+
switch (token_tags[tok_i + 2]) {
2118+
.r_paren => {
2119+
ais.setIndentDelta(indent_delta);
2120+
ais.popIndent();
2121+
try renderToken(ais, tree, tok_i, .newline);
2122+
return renderToken(ais, tree, tok_i + 2, space);
2123+
},
2124+
else => {
2125+
try renderToken(ais, tree, tok_i, .none);
2126+
try renderToken(ais, tree, tok_i + 1, .space);
2127+
tok_i += 2;
2128+
},
2129+
}
21202130
},
21212131
else => unreachable,
21222132
}

0 commit comments

Comments
 (0)