From bbf5a4d7c5726baf933e303e6c61c6bba38b694b Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 15 Feb 2021 13:54:48 +0100 Subject: [PATCH] zig fmt: fix inferred error union return types --- lib/std/zig/parser_test.zig | 78 ++++++++++++++++++------------------- lib/std/zig/render.zig | 2 +- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 11bb4d8ceb..e4778b35e1 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -442,23 +442,23 @@ test "zig fmt: array types last token" { ); } -//test "zig fmt: sentinel-terminated array type" { -// try testCanonical( -// \\pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 { -// \\ return sliceToPrefixedFileW(mem.toSliceConst(u8, s)); -// \\} -// \\ -// ); -//} -// -//test "zig fmt: sentinel-terminated slice type" { -// try testCanonical( -// \\pub fn toSlice(self: Buffer) [:0]u8 { -// \\ return self.list.toSlice()[0..self.len()]; -// \\} -// \\ -// ); -//} +test "zig fmt: sentinel-terminated array type" { + try testCanonical( + \\pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 { + \\ return sliceToPrefixedFileW(mem.toSliceConst(u8, s)); + \\} + \\ + ); +} + +test "zig fmt: sentinel-terminated slice type" { + try testCanonical( + \\pub fn toSlice(self: Buffer) [:0]u8 { + \\ return self.list.toSlice()[0..self.len()]; + \\} + \\ + ); +} test "zig fmt: pointer-to-one with modifiers" { try testCanonical( @@ -2669,28 +2669,28 @@ test "zig fmt: call expression" { // \\ // ); //} -// -//test "zig fmt: functions" { -// try testCanonical( -// \\extern fn puts(s: *const u8) c_int; -// \\extern "c" fn puts(s: *const u8) c_int; -// \\export fn puts(s: *const u8) c_int; -// \\fn puts(s: *const u8) callconv(.Inline) c_int; -// \\noinline fn puts(s: *const u8) c_int; -// \\pub extern fn puts(s: *const u8) c_int; -// \\pub extern "c" fn puts(s: *const u8) c_int; -// \\pub export fn puts(s: *const u8) c_int; -// \\pub fn puts(s: *const u8) callconv(.Inline) c_int; -// \\pub noinline fn puts(s: *const u8) c_int; -// \\pub extern fn puts(s: *const u8) align(2 + 2) c_int; -// \\pub extern "c" fn puts(s: *const u8) align(2 + 2) c_int; -// \\pub export fn puts(s: *const u8) align(2 + 2) c_int; -// \\pub fn puts(s: *const u8) align(2 + 2) callconv(.Inline) c_int; -// \\pub noinline fn puts(s: *const u8) align(2 + 2) c_int; -// \\ -// ); -//} -// + +test "zig fmt: functions" { + try testCanonical( + \\extern fn puts(s: *const u8) c_int; + \\extern "c" fn puts(s: *const u8) c_int; + \\export fn puts(s: *const u8) c_int; + \\fn puts(s: *const u8) callconv(.Inline) c_int; + \\noinline fn puts(s: *const u8) c_int; + \\pub extern fn puts(s: *const u8) c_int; + \\pub extern "c" fn puts(s: *const u8) c_int; + \\pub export fn puts(s: *const u8) c_int; + \\pub fn puts(s: *const u8) callconv(.Inline) c_int; + \\pub noinline fn puts(s: *const u8) c_int; + \\pub extern fn puts(s: *const u8) align(2 + 2) c_int; + \\pub extern "c" fn puts(s: *const u8) align(2 + 2) c_int; + \\pub export fn puts(s: *const u8) align(2 + 2) c_int; + \\pub fn puts(s: *const u8) align(2 + 2) callconv(.Inline) c_int; + \\pub noinline fn puts(s: *const u8) align(2 + 2) c_int; + \\ + ); +} + //test "zig fmt: multiline string" { // try testCanonical( // \\test "" { diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 4aea213d2a..2d9c2ae9a9 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -1250,7 +1250,7 @@ fn renderFnProto(ais: *Ais, tree: ast.Tree, fn_proto: ast.full.FnProto, space: S const rparen = blk: { // These may appear in any order, so we have to check the token_starts array // to find out which is first. - var rparen: ast.TokenIndex = maybe_bang; + var rparen = if (token_tags[maybe_bang] == .bang) maybe_bang - 1 else maybe_bang; var smallest_start = token_starts[maybe_bang]; if (fn_proto.ast.align_expr != 0) { const tok = tree.firstToken(fn_proto.ast.align_expr) - 3;