| author | |
| committer | |
| log | 7e16bb36d82cf45cd5f6f4da38fba512554f66ed |
| tree | 72a943205528ec58a80d6939670cb3b2a1695fe0 |
| parent | 0d09b87c1409660a9d541e7f2972480b4be137a5 |
Changes the return type of `ArgIterator.next()` from
`?(NextError![:0]u8)` to `NextError!?[:0]u8`.4 files changed, 20 insertions(+), 23 deletions(-)
doc/docgen.zig+5-5| ... | @@ -27,18 +27,18 @@ pub fn main() !void { | ... | @@ -27,18 +27,18 @@ pub fn main() !void { |
| 27 | 27 | ||
| 28 | if (!args_it.skip()) @panic("expected self arg"); | 28 | if (!args_it.skip()) @panic("expected self arg"); |
| 29 | 29 | ||
| 30 | const zig_exe = try (args_it.next(allocator) orelse @panic("expected zig exe arg")); | 30 | const zig_exe = (try args_it.next(allocator)) orelse @panic("expected zig exe arg"); |
| 31 | defer allocator.free(zig_exe); | 31 | defer allocator.free(zig_exe); |
| 32 | 32 | ||
| 33 | const in_file_name = try (args_it.next(allocator) orelse @panic("expected input arg")); | 33 | const in_file_name = (try args_it.next(allocator)) orelse @panic("expected input arg"); |
| 34 | defer allocator.free(in_file_name); | 34 | defer allocator.free(in_file_name); |
| 35 | 35 | ||
| 36 | const out_file_name = try (args_it.next(allocator) orelse @panic("expected output arg")); | 36 | const out_file_name = (try args_it.next(allocator)) orelse @panic("expected output arg"); |
| 37 | defer allocator.free(out_file_name); | 37 | defer allocator.free(out_file_name); |
| 38 | 38 | ||
| 39 | var do_code_tests = true; | 39 | var do_code_tests = true; |
| 40 | if (args_it.next(allocator)) |arg| { | 40 | if (try args_it.next(allocator)) |arg| { |
| 41 | if (mem.eql(u8, try arg, "--skip-code-tests")) { | 41 | if (mem.eql(u8, arg, "--skip-code-tests")) { |
| 42 | do_code_tests = false; | 42 | do_code_tests = false; |
| 43 | } else { | 43 | } else { |
| 44 | @panic("unrecognized arg"); | 44 | @panic("unrecognized arg"); |
lib/std/process.zig+9-10| ... | @@ -325,7 +325,7 @@ pub const ArgIteratorWindows = struct { | ... | @@ -325,7 +325,7 @@ pub const ArgIteratorWindows = struct { |
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | /// You must free the returned memory when done. | 327 | /// You must free the returned memory when done. |
| 328 | pub fn next(self: *ArgIteratorWindows, allocator: Allocator) ?(NextError![:0]u8) { | 328 | pub fn next(self: *ArgIteratorWindows, allocator: Allocator) NextError!?[:0]u8 { |
| 329 | // march forward over whitespace | 329 | // march forward over whitespace |
| 330 | while (true) : (self.index += 1) { | 330 | while (true) : (self.index += 1) { |
| 331 | const character = self.getPointAtIndex(); | 331 | const character = self.getPointAtIndex(); |
| ... | @@ -336,7 +336,7 @@ pub const ArgIteratorWindows = struct { | ... | @@ -336,7 +336,7 @@ pub const ArgIteratorWindows = struct { |
| 336 | } | 336 | } |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | return self.internalNext(allocator); | 339 | return try self.internalNext(allocator); |
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | pub fn skip(self: *ArgIteratorWindows) bool { | 342 | pub fn skip(self: *ArgIteratorWindows) bool { |
| ... | @@ -474,11 +474,11 @@ pub const ArgIterator = struct { | ... | @@ -474,11 +474,11 @@ pub const ArgIterator = struct { |
| 474 | pub const NextError = ArgIteratorWindows.NextError; | 474 | pub const NextError = ArgIteratorWindows.NextError; |
| 475 | 475 | ||
| 476 | /// You must free the returned memory when done. | 476 | /// You must free the returned memory when done. |
| 477 | pub fn next(self: *ArgIterator, allocator: Allocator) ?(NextError![:0]u8) { | 477 | pub fn next(self: *ArgIterator, allocator: Allocator) NextError!?[:0]u8 { |
| 478 | if (builtin.os.tag == .windows) { | 478 | if (builtin.os.tag == .windows) { |
| 479 | return self.inner.next(allocator); | 479 | return self.inner.next(allocator); |
| 480 | } else { | 480 | } else { |
| 481 | return allocator.dupeZ(u8, self.inner.next() orelse return null); | 481 | return try allocator.dupeZ(u8, self.inner.next() orelse return null); |
| 482 | } | 482 | } |
| 483 | } | 483 | } |
| 484 | 484 | ||
| ... | @@ -522,7 +522,7 @@ test "args iterator" { | ... | @@ -522,7 +522,7 @@ test "args iterator" { |
| 522 | var it = if (builtin.os.tag == .wasi) try argsWithAllocator(ga) else args(); | 522 | var it = if (builtin.os.tag == .wasi) try argsWithAllocator(ga) else args(); |
| 523 | defer it.deinit(); // no-op unless WASI | 523 | defer it.deinit(); // no-op unless WASI |
| 524 | 524 | ||
| 525 | const prog_name = try it.next(ga) orelse unreachable; | 525 | const prog_name = (try it.next(ga)) orelse unreachable; |
| 526 | defer ga.free(prog_name); | 526 | defer ga.free(prog_name); |
| 527 | 527 | ||
| 528 | const expected_suffix = switch (builtin.os.tag) { | 528 | const expected_suffix = switch (builtin.os.tag) { |
| ... | @@ -534,7 +534,7 @@ test "args iterator" { | ... | @@ -534,7 +534,7 @@ test "args iterator" { |
| 534 | 534 | ||
| 535 | try testing.expect(mem.eql(u8, expected_suffix, given_suffix)); | 535 | try testing.expect(mem.eql(u8, expected_suffix, given_suffix)); |
| 536 | try testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner | 536 | try testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner |
| 537 | try testing.expect(it.next(ga) == null); | 537 | try testing.expect((try it.next(ga)) == null); |
| 538 | try testing.expect(!it.skip()); | 538 | try testing.expect(!it.skip()); |
| 539 | } | 539 | } |
| 540 | 540 | ||
| ... | @@ -550,8 +550,7 @@ pub fn argsAlloc(allocator: mem.Allocator) ![][:0]u8 { | ... | @@ -550,8 +550,7 @@ pub fn argsAlloc(allocator: mem.Allocator) ![][:0]u8 { |
| 550 | var slice_list = std.ArrayList(usize).init(allocator); | 550 | var slice_list = std.ArrayList(usize).init(allocator); |
| 551 | defer slice_list.deinit(); | 551 | defer slice_list.deinit(); |
| 552 | 552 | ||
| 553 | while (it.next(allocator)) |arg_or_err| { | 553 | while (try it.next(allocator)) |arg| { |
| 554 | const arg = try arg_or_err; | ||
| 555 | defer allocator.free(arg); | 554 | defer allocator.free(arg); |
| 556 | try contents.appendSlice(arg[0 .. arg.len + 1]); | 555 | try contents.appendSlice(arg[0 .. arg.len + 1]); |
| 557 | try slice_list.append(arg.len); | 556 | try slice_list.append(arg.len); |
| ... | @@ -610,11 +609,11 @@ test "windows arg parsing" { | ... | @@ -610,11 +609,11 @@ test "windows arg parsing" { |
| 610 | fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) !void { | 609 | fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) !void { |
| 611 | var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line); | 610 | var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line); |
| 612 | for (expected_args) |expected_arg| { | 611 | for (expected_args) |expected_arg| { |
| 613 | const arg = it.next(std.testing.allocator).? catch unreachable; | 612 | const arg = (it.next(std.testing.allocator) catch unreachable).?; |
| 614 | defer std.testing.allocator.free(arg); | 613 | defer std.testing.allocator.free(arg); |
| 615 | try testing.expectEqualStrings(expected_arg, arg); | 614 | try testing.expectEqualStrings(expected_arg, arg); |
| 616 | } | 615 | } |
| 617 | try testing.expect(it.next(std.testing.allocator) == null); | 616 | try testing.expect((try it.next(std.testing.allocator)) == null); |
| 618 | } | 617 | } |
| 619 | 618 | ||
| 620 | pub const UserInfo = struct { | 619 | pub const UserInfo = struct { |
test/cli.zig+4-4| ... | @@ -18,14 +18,14 @@ pub fn main() !void { | ... | @@ -18,14 +18,14 @@ pub fn main() !void { |
| 18 | 18 | ||
| 19 | a = arena.allocator(); | 19 | a = arena.allocator(); |
| 20 | 20 | ||
| 21 | const zig_exe_rel = try (arg_it.next(a) orelse { | 21 | const zig_exe_rel = (try arg_it.next(a)) orelse { |
| 22 | std.debug.print("Expected first argument to be path to zig compiler\n", .{}); | 22 | std.debug.print("Expected first argument to be path to zig compiler\n", .{}); |
| 23 | return error.InvalidArgs; | 23 | return error.InvalidArgs; |
| 24 | }); | 24 | }; |
| 25 | const cache_root = try (arg_it.next(a) orelse { | 25 | const cache_root = (try arg_it.next(a)) orelse { |
| 26 | std.debug.print("Expected second argument to be cache root directory path\n", .{}); | 26 | std.debug.print("Expected second argument to be cache root directory path\n", .{}); |
| 27 | return error.InvalidArgs; | 27 | return error.InvalidArgs; |
| 28 | }); | 28 | }; |
| 29 | const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel}); | 29 | const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel}); |
| 30 | 30 | ||
| 31 | const dir_path = try fs.path.join(a, &[_][]const u8{ cache_root, "clitest" }); | 31 | const dir_path = try fs.path.join(a, &[_][]const u8{ cache_root, "clitest" }); |
test/compare_output.zig+2-4| ... | @@ -362,8 +362,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -362,8 +362,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 362 | \\ const stdout = io.getStdOut().writer(); | 362 | \\ const stdout = io.getStdOut().writer(); |
| 363 | \\ var index: usize = 0; | 363 | \\ var index: usize = 0; |
| 364 | \\ _ = args_it.skip(); | 364 | \\ _ = args_it.skip(); |
| 365 | \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) { | 365 | \\ while (try args_it.next(allocator)) |arg| : (index += 1) { |
| 366 | \\ const arg = try arg_or_err; | ||
| 367 | \\ try stdout.print("{}: {s}\n", .{index, arg}); | 366 | \\ try stdout.print("{}: {s}\n", .{index, arg}); |
| 368 | \\ } | 367 | \\ } |
| 369 | \\} | 368 | \\} |
| ... | @@ -401,8 +400,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -401,8 +400,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 401 | \\ const stdout = io.getStdOut().writer(); | 400 | \\ const stdout = io.getStdOut().writer(); |
| 402 | \\ var index: usize = 0; | 401 | \\ var index: usize = 0; |
| 403 | \\ _ = args_it.skip(); | 402 | \\ _ = args_it.skip(); |
| 404 | \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) { | 403 | \\ while (try args_it.next(allocator)) |arg| : (index += 1) { |
| 405 | \\ const arg = try arg_or_err; | ||
| 406 | \\ try stdout.print("{}: {s}\n", .{index, arg}); | 404 | \\ try stdout.print("{}: {s}\n", .{index, arg}); |
| 407 | \\ } | 405 | \\ } |
| 408 | \\} | 406 | \\} |