From d1908c9f661abebb2879b02c8ea3ac823fec27e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20L=C3=BChmann?= <47984692+luehmann@users.noreply.github.com> Date: Tue, 14 Sep 2021 11:36:26 +0200 Subject: [PATCH] zig fmt: Keep callconv(.Inline) on function pointer types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Philipp Lühmann --- lib/std/zig/parser_test.zig | 3 +++ lib/std/zig/render.zig | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 24992569b1..615648d1ad 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -2879,6 +2879,9 @@ test "zig fmt: functions" { \\pub export fn puts(s: *const u8) align(2 + 2) c_int; \\pub inline fn puts(s: *const u8) align(2 + 2) c_int; \\pub noinline fn puts(s: *const u8) align(2 + 2) c_int; + \\pub fn callInlineFn(func: fn () callconv(.Inline) void) void { + \\ func(); + \\} \\ ); } diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index bc1dc42855..265049e1f9 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -1417,9 +1417,9 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: Ast, fn_proto: Ast.full.FnPro try renderToken(ais, tree, section_rparen, .space); // ) } - if (fn_proto.ast.callconv_expr != 0 and - !mem.eql(u8, "Inline", tree.tokenSlice(tree.nodes.items(.main_token)[fn_proto.ast.callconv_expr]))) - { + const is_callconv_inline = mem.eql(u8, "Inline", tree.tokenSlice(tree.nodes.items(.main_token)[fn_proto.ast.callconv_expr])); + const is_declaration = fn_proto.name_token != null; + if (fn_proto.ast.callconv_expr != 0 and !(is_declaration and is_callconv_inline)) { const callconv_lparen = tree.firstToken(fn_proto.ast.callconv_expr) - 1; const callconv_rparen = tree.lastToken(fn_proto.ast.callconv_expr) + 1;