Skip to content

Commit d1908c9

Browse files
luehmannPhilipp Lühmann
and
Philipp Lühmann
authored
zig fmt: Keep callconv(.Inline) on function pointer types
Co-authored-by: Philipp Lühmann <[email protected]>
1 parent 264acfd commit d1908c9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/std/zig/parser_test.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,9 @@ test "zig fmt: functions" {
28792879
\\pub export fn puts(s: *const u8) align(2 + 2) c_int;
28802880
\\pub inline fn puts(s: *const u8) align(2 + 2) c_int;
28812881
\\pub noinline fn puts(s: *const u8) align(2 + 2) c_int;
2882+
\\pub fn callInlineFn(func: fn () callconv(.Inline) void) void {
2883+
\\ func();
2884+
\\}
28822885
\\
28832886
);
28842887
}

lib/std/zig/render.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,9 +1417,9 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: Ast, fn_proto: Ast.full.FnPro
14171417
try renderToken(ais, tree, section_rparen, .space); // )
14181418
}
14191419

1420-
if (fn_proto.ast.callconv_expr != 0 and
1421-
!mem.eql(u8, "Inline", tree.tokenSlice(tree.nodes.items(.main_token)[fn_proto.ast.callconv_expr])))
1422-
{
1420+
const is_callconv_inline = mem.eql(u8, "Inline", tree.tokenSlice(tree.nodes.items(.main_token)[fn_proto.ast.callconv_expr]));
1421+
const is_declaration = fn_proto.name_token != null;
1422+
if (fn_proto.ast.callconv_expr != 0 and !(is_declaration and is_callconv_inline)) {
14231423
const callconv_lparen = tree.firstToken(fn_proto.ast.callconv_expr) - 1;
14241424
const callconv_rparen = tree.lastToken(fn_proto.ast.callconv_expr) + 1;
14251425

0 commit comments

Comments
 (0)