zig fmt: remove trailing comma at the end of assembly clobber

This commit is contained in:
riChar 2022-09-02 17:52:33 +08:00 committed by GitHub
parent 36f4f32fad
commit 0d96f1f4fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 3 deletions

View File

@ -16,6 +16,28 @@ test "zig fmt: preserves clobbers in inline asm with stray comma" {
);
}
test "zig fmt: remove trailing comma at the end of assembly clobber" {
try testTransform(
\\fn foo() void {
\\ asm volatile (""
\\ : [_] "" (-> type),
\\ :
\\ : "clobber1", "clobber2",
\\ );
\\}
\\
,
\\fn foo() void {
\\ asm volatile (""
\\ : [_] "" (-> type),
\\ :
\\ : "clobber1", "clobber2"
\\ );
\\}
\\
);
}
test "zig fmt: respect line breaks in struct field value declaration" {
try testCanonical(
\\const Foo = struct {

View File

@ -2114,9 +2114,19 @@ fn renderAsm(
return renderToken(ais, tree, tok_i + 1, space);
},
.comma => {
try renderToken(ais, tree, tok_i, .none);
try renderToken(ais, tree, tok_i + 1, .space);
tok_i += 2;
switch (token_tags[tok_i + 2]) {
.r_paren => {
ais.setIndentDelta(indent_delta);
ais.popIndent();
try renderToken(ais, tree, tok_i, .newline);
return renderToken(ais, tree, tok_i + 2, space);
},
else => {
try renderToken(ais, tree, tok_i, .none);
try renderToken(ais, tree, tok_i + 1, .space);
tok_i += 2;
},
}
},
else => unreachable,
}