diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-12-09 10:51:47 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-09 10:51:47 -0500 |
| commit | 640e09183d3100c477a26c6cdc26f1eae31472a1 (patch) | |
| tree | 0bddf7eb99d6daaaa2e5ee80b51a6766aefb7d9c /lib/std | |
| parent | 5874cb04bd544ca155d1489bb0bdf9397fa3b41c (diff) | |
| parent | 8b3c0bbeeef080b77d0cb7999682abc52de437e3 (diff) | |
| download | zig-640e09183d3100c477a26c6cdc26f1eae31472a1.tar.gz zig-640e09183d3100c477a26c6cdc26f1eae31472a1.zip | |
Merge pull request #3873 from ziglang/format-no-var-args
std.fmt.format: tuple parameter instead of var args
Diffstat (limited to 'lib/std')
38 files changed, 444 insertions, 693 deletions
diff --git a/lib/std/atomic/queue.zig b/lib/std/atomic/queue.zig index 53f1d99f13..63bacb4fb5 100644 --- a/lib/std/atomic/queue.zig +++ b/lib/std/atomic/queue.zig @@ -116,19 +116,19 @@ pub fn Queue(comptime T: type) type { fn dumpRecursive(s: *std.io.OutStream(Error), optional_node: ?*Node, indent: usize) Error!void { try s.writeByteNTimes(' ', indent); if (optional_node) |node| { - try s.print("0x{x}={}\n", @ptrToInt(node), node.data); + try s.print("0x{x}={}\n", .{ @ptrToInt(node), node.data }); try dumpRecursive(s, node.next, indent + 1); } else { - try s.print("(null)\n"); + try s.print("(null)\n", .{}); } } }; const held = self.mutex.acquire(); defer held.release(); - try stream.print("head: "); + try stream.print("head: ", .{}); try S.dumpRecursive(stream, self.head, 0); - try stream.print("tail: "); + try stream.print("tail: ", .{}); try S.dumpRecursive(stream, self.tail, 0); } }; @@ -207,16 +207,15 @@ test "std.atomic.Queue" { } if (context.put_sum != context.get_sum) { - std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum); + std.debug.panic("failure\nput_sum:{} != get_sum:{}", .{ context.put_sum, context.get_sum }); } if (context.get_count != puts_per_thread * put_thread_count) { - std.debug.panic( - "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", + std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{ context.get_count, @as(u32, puts_per_thread), @as(u32, put_thread_count), - ); + }); } } @@ -351,7 +350,7 @@ test "std.atomic.Queue dump" { \\tail: 0x{x}=1 \\ (null) \\ - , @ptrToInt(queue.head), @ptrToInt(queue.tail)); + , .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) }); expect(mem.eql(u8, buffer[0..sos.pos], expected)); // Test a stream with two elements @@ -372,6 +371,6 @@ test "std.atomic.Queue dump" { \\tail: 0x{x}=2 \\ (null) \\ - , @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail)); + , .{ @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail) }); expect(mem.eql(u8, buffer[0..sos.pos], expected)); } diff --git a/lib/std/atomic/stack.zig b/lib/std/atomic/stack.zig index 2636b20528..9de8e36f87 100644 --- a/lib/std/atomic/stack.zig +++ b/lib/std/atomic/stack.zig @@ -134,16 +134,15 @@ test "std.atomic.stack" { } if (context.put_sum != context.get_sum) { - std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum); + std.debug.panic("failure\nput_sum:{} != get_sum:{}", .{ context.put_sum, context.get_sum }); } if (context.get_count != puts_per_thread * put_thread_count) { - std.debug.panic( - "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", + std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{ context.get_count, @as(u32, puts_per_thread), @as(u32, put_thread_count), - ); + }); } } diff --git a/lib/std/buffer.zig b/lib/std/buffer.zig index 46c55a32b8..55a5a890d6 100644 --- a/lib/std/buffer.zig +++ b/lib/std/buffer.zig @@ -16,7 +16,7 @@ pub const Buffer = struct { mem.copy(u8, self.list.items, m); return self; } - + /// Initialize memory to size bytes of undefined values. /// Must deinitialize with deinit. pub fn initSize(allocator: *Allocator, size: usize) !Buffer { @@ -24,7 +24,7 @@ pub const Buffer = struct { try self.resize(size); return self; } - + /// Initialize with capacity to hold at least num bytes. /// Must deinitialize with deinit. pub fn initCapacity(allocator: *Allocator, num: usize) !Buffer { @@ -64,7 +64,7 @@ pub const Buffer = struct { return result; } - pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: ...) !Buffer { + pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Buffer { const countSize = struct { fn countSize(size: *usize, bytes: []const u8) (error{}!void) { size.* += bytes.len; @@ -107,7 +107,7 @@ pub const Buffer = struct { pub fn len(self: Buffer) usize { return self.list.len - 1; } - + pub fn capacity(self: Buffer) usize { return if (self.list.items.len > 0) self.list.items.len - 1 diff --git a/lib/std/build.zig b/lib/std/build.zig index bfde2f52d7..82681e3069 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -232,7 +232,7 @@ pub const Builder = struct { /// To run an executable built with zig build, see `LibExeObjStep.run`. pub fn addSystemCommand(self: *Builder, argv: []const []const u8) *RunStep { assert(argv.len >= 1); - const run_step = RunStep.create(self, self.fmt("run {}", argv[0])); + const run_step = RunStep.create(self, self.fmt("run {}", .{argv[0]})); run_step.addArgs(argv); return run_step; } @@ -258,7 +258,7 @@ pub const Builder = struct { return write_file_step; } - pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep { + pub fn addLog(self: *Builder, comptime format: []const u8, args: var) *LogStep { const data = self.fmt(format, args); const log_step = self.allocator.create(LogStep) catch unreachable; log_step.* = LogStep.init(self, data); @@ -330,7 +330,7 @@ pub const Builder = struct { for (self.installed_files.toSliceConst()) |installed_file| { const full_path = self.getInstallPath(installed_file.dir, installed_file.path); if (self.verbose) { - warn("rm {}\n", full_path); + warn("rm {}\n", .{full_path}); } fs.deleteTree(full_path) catch {}; } @@ -340,7 +340,7 @@ pub const Builder = struct { fn makeOneStep(self: *Builder, s: *Step) anyerror!void { if (s.loop_flag) { - warn("Dependency loop detected:\n {}\n", s.name); + warn("Dependency loop detected:\n {}\n", .{s.name}); return error.DependencyLoopDetected; } s.loop_flag = true; @@ -348,7 +348,7 @@ pub const Builder = struct { for (s.dependencies.toSlice()) |dep| { self.makeOneStep(dep) catch |err| { if (err == error.DependencyLoopDetected) { - warn(" {}\n", s.name); + warn(" {}\n", .{s.name}); } return err; }; @@ -365,7 +365,7 @@ pub const Builder = struct { return &top_level_step.step; } } - warn("Cannot run step '{}' because it does not exist\n", name); + warn("Cannot run step '{}' because it does not exist\n", .{name}); return error.InvalidStepName; } @@ -378,12 +378,12 @@ pub const Builder = struct { const word = it.next() orelse break; if (mem.eql(u8, word, "-isystem")) { const include_path = it.next() orelse { - warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n"); + warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n", .{}); break; }; self.addNativeSystemIncludeDir(include_path); } else { - warn("Unrecognized C flag from NIX_CFLAGS_COMPILE: {}\n", word); + warn("Unrecognized C flag from NIX_CFLAGS_COMPILE: {}\n", .{word}); break; } } @@ -397,7 +397,7 @@ pub const Builder = struct { const word = it.next() orelse break; if (mem.eql(u8, word, "-rpath")) { const rpath = it.next() orelse { - warn("Expected argument after -rpath in NIX_LDFLAGS\n"); + warn("Expected argument after -rpath in NIX_LDFLAGS\n", .{}); break; }; self.addNativeSystemRPath(rpath); @@ -405,7 +405,7 @@ pub const Builder = struct { const lib_path = word[2..]; self.addNativeSystemLibPath(lib_path); } else { - warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", word); + warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", .{word}); break; } } @@ -431,8 +431,8 @@ pub const Builder = struct { self.addNativeSystemIncludeDir("/usr/local/include"); self.addNativeSystemLibPath("/usr/local/lib"); - self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", triple)); - self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", triple)); + self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", .{triple})); + self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", .{triple})); self.addNativeSystemIncludeDir("/usr/include"); self.addNativeSystemLibPath("/usr/lib"); @@ -440,7 +440,7 @@ pub const Builder = struct { // example: on a 64-bit debian-based linux distro, with zlib installed from apt: // zlib.h is in /usr/include (added above) // libz.so.1 is in /lib/x86_64-linux-gnu (added here) - self.addNativeSystemLibPath(self.fmt("/lib/{}", triple)); + self.addNativeSystemLibPath(self.fmt("/lib/{}", .{triple})); }, } } @@ -453,7 +453,7 @@ pub const Builder = struct { .description = description, }; if ((self.available_options_map.put(name, available_option) catch unreachable) != null) { - panic("Option '{}' declared twice", name); + panic("Option '{}' declared twice", .{name}); } self.available_options_list.append(available_option) catch unreachable; @@ -468,33 +468,33 @@ pub const Builder = struct { } else if (mem.eql(u8, s, "false")) { return false; } else { - warn("Expected -D{} to be a boolean, but received '{}'\n", name, s); + warn("Expected -D{} to be a boolean, but received '{}'\n", .{ name, s }); self.markInvalidUserInput(); return null; } }, UserValue.List => { - warn("Expected -D{} to be a boolean, but received a list.\n", name); + warn("Expected -D{} to be a boolean, but received a list.\n", .{name}); self.markInvalidUserInput(); return null; }, }, - TypeId.Int => panic("TODO integer options to build script"), - TypeId.Float => panic("TODO float options to build script"), + TypeId.Int => panic("TODO integer options to build script", .{}), + TypeId.Float => panic("TODO float options to build script", .{}), TypeId.String => switch (entry.value.value) { UserValue.Flag => { - warn("Expected -D{} to be a string, but received a boolean.\n", name); + warn("Expected -D{} to be a string, but received a boolean.\n", .{name}); self.markInvalidUserInput(); return null; }, UserValue.List => { - warn("Expected -D{} to be a string, but received a list.\n", name); + warn("Expected -D{} to be a string, but received a list.\n", .{name}); self.markInvalidUserInput(); return null; }, UserValue.Scalar => |s| return s, }, - TypeId.List => panic("TODO list options to build script"), + TypeId.List => panic("TODO list options to build script", .{}), } } @@ -513,7 +513,7 @@ pub const Builder = struct { if (self.release_mode != null) { @panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice"); } - const description = self.fmt("create a release build ({})", @tagName(mode)); + const description = self.fmt("create a release build ({})", .{@tagName(mode)}); self.is_release = self.option(bool, "release", description) orelse false; self.release_mode = if (self.is_release) mode else builtin.Mode.Debug; } @@ -536,7 +536,7 @@ pub const Builder = struct { else if (!release_fast and !release_safe and !release_small) builtin.Mode.Debug else x: { - warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)"); + warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)", .{}); self.markInvalidUserInput(); break :x builtin.Mode.Debug; }; @@ -599,7 +599,7 @@ pub const Builder = struct { }) catch unreachable; }, UserValue.Flag => { - warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", name, value, name); + warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", .{ name, value, name }); return true; }, } @@ -620,11 +620,11 @@ pub const Builder = struct { // option already exists switch (gop.kv.value.value) { UserValue.Scalar => |s| { - warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", name, name, s); + warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", .{ name, name, s }); return true; }, UserValue.List => { - warn("Flag '-D{}' conflicts with multiple options of the same name.\n", name); + warn("Flag '-D{}' conflicts with multiple options of the same name.\n", .{name}); return true; }, UserValue.Flag => {}, @@ -665,7 +665,7 @@ pub const Builder = struct { while (true) { const entry = it.next() orelse break; if (!entry.value.used) { - warn("Invalid option: -D{}\n\n", entry.key); + warn("Invalid option: -D{}\n\n", .{entry.key}); self.markInvalidUserInput(); } } @@ -678,11 +678,11 @@ pub const Builder = struct { } fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void { - if (cwd) |yes_cwd| warn("cd {} && ", yes_cwd); + if (cwd) |yes_cwd| warn("cd {} && ", .{yes_cwd}); for (argv) |arg| { - warn("{} ", arg); + warn("{} ", .{arg}); } - warn("\n"); + warn("\n", .{}); } fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) !void { @@ -697,20 +697,20 @@ pub const Builder = struct { child.env_map = env_map; const term = child.spawnAndWait() catch |err| { - warn("Unable to spawn {}: {}\n", argv[0], @errorName(err)); + warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) }); return err; }; switch (term) { .Exited => |code| { if (code != 0) { - warn("The following command exited with error code {}:\n", code); + warn("The following command exited with error code {}:\n", .{code}); printCmd(cwd, argv); return error.UncleanExit; } }, else => { - warn("The following command terminated unexpectedly:\n"); + warn("The following command terminated unexpectedly:\n", .{}); printCmd(cwd, argv); return error.UncleanExit; @@ -720,7 +720,7 @@ pub const Builder = struct { pub fn makePath(self: *Builder, path: []const u8) !void { fs.makePath(self.allocator, self.pathFromRoot(path)) catch |err| { - warn("Unable to create path {}: {}\n", path, @errorName(err)); + warn("Unable to create path {}: {}\n", .{ path, @errorName(err) }); return err; }; } @@ -793,12 +793,12 @@ pub const Builder = struct { fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void { if (self.verbose) { - warn("cp {} {} ", source_path, dest_path); + warn("cp {} {} ", .{ source_path, dest_path }); } const prev_status = try fs.updateFile(source_path, dest_path); if (self.verbose) switch (prev_status) { - .stale => warn("# installed\n"), - .fresh => warn("# up-to-date\n"), + .stale => warn("# installed\n", .{}), + .fresh => warn("# up-to-date\n", .{}), }; } @@ -806,7 +806,7 @@ pub const Builder = struct { return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable; } - pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 { + pub fn fmt(self: *Builder, comptime format: []const u8, args: var) []u8 { return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable; } @@ -818,7 +818,11 @@ pub const Builder = struct { if (fs.path.isAbsolute(name)) { return name; } - const full_path = try fs.path.join(self.allocator, &[_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) }); + const full_path = try fs.path.join(self.allocator, &[_][]const u8{ + search_prefix, + "bin", + self.fmt("{}{}", .{ name, exe_extension }), + }); return fs.realpathAlloc(self.allocator, full_path) catch continue; } } @@ -829,7 +833,10 @@ pub const Builder = struct { } var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter}); while (it.next()) |path| { - const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); + const full_path = try fs.path.join(self.allocator, &[_][]const u8{ + path, + self.fmt("{}{}", .{ name, exe_extension }), + }); return fs.realpathAlloc(self.allocator, full_path) catch continue; } } @@ -839,7 +846,10 @@ pub const Builder = struct { return name; } for (paths) |path| { - const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); + const full_path = try fs.path.join(self.allocator, &[_][]const u8{ + path, + self.fmt("{}{}", .{ name, exe_extension }), + }); return fs.realpathAlloc(self.allocator, full_path) catch continue; } } @@ -896,17 +906,17 @@ pub const Builder = struct { var code: u8 = undefined; return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) { error.FileNotFound => { - warn("Unable to spawn the following command: file not found\n"); + warn("Unable to spawn the following command: file not found\n", .{}); printCmd(null, argv); std.os.exit(@truncate(u8, code)); }, error.ExitCodeFailure => { - warn("The following command exited with error code {}:\n", code); + warn("The following command exited with error code {}:\n", .{code}); printCmd(null, argv); std.os.exit(@truncate(u8, code)); }, error.ProcessTerminated => { - warn("The following command terminated unexpectedly:\n"); + warn("The following command terminated unexpectedly:\n", .{}); printCmd(null, argv); std.os.exit(@truncate(u8, code)); }, @@ -1133,7 +1143,7 @@ pub const LibExeObjStep = struct { fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep { if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) { - panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", name); + panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", .{name}); } var self = LibExeObjStep{ .strip = false, @@ -1150,9 +1160,9 @@ pub const LibExeObjStep = struct { .step = Step.init(name, builder.allocator, make), .version = ver, .out_filename = undefined, - .out_h_filename = builder.fmt("{}.h", name), + .out_h_filename = builder.fmt("{}.h", .{name}), .out_lib_filename = undefined, - .out_pdb_filename = builder.fmt("{}.pdb", name), + .out_pdb_filename = builder.fmt("{}.pdb", .{name}), .major_only_filename = undefined, .name_only_filename = undefined, .packages = ArrayList(Pkg).init(builder.allocator), @@ -1186,36 +1196,48 @@ pub const LibExeObjStep = struct { fn computeOutFileNames(self: *LibExeObjStep) void { switch (self.kind) { .Obj => { - self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt()); + self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.oFileExt() }); }, .Exe => { - self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt()); + self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.exeFileExt() }); }, .Test => { - self.out_filename = self.builder.fmt("test{}", self.target.exeFileExt()); + self.out_filename = self.builder.fmt("test{}", .{self.target.exeFileExt()}); }, .Lib => { if (!self.is_dynamic) { - self.out_filename = self.builder.fmt( - "{}{}{}", + self.out_filename = self.builder.fmt("{}{}{}", .{ self.target.libPrefix(), self.name, self.target.staticLibSuffix(), - ); + }); self.out_lib_filename = self.out_filename; } else { if (self.target.isDarwin()) { - self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", self.name, self.version.major, self.version.minor, self.version.patch); - self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major); - self.name_only_filename = self.builder.fmt("lib{}.dylib", self.name); + self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", .{ + self.name, + self.version.major, + self.version.minor, + self.version.patch, + }); + self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", .{ + self.name, + self.version.major, + }); + self.name_only_filename = self.builder.fmt("lib{}.dylib", .{self.name}); self.out_lib_filename = self.out_filename; } else if (self.target.isWindows()) { - self.out_filename = self.builder.fmt("{}.dll", self.name); - self.out_lib_filename = self.builder.fmt("{}.lib", self.name); + self.out_filename = self.builder.fmt("{}.dll", .{self.name}); + self.out_lib_filename = self.builder.fmt("{}.lib", .{self.name}); } else { - self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", self.name, self.version.major, self.version.minor, self.version.patch); - self.major_only_filename = self.builder.fmt("lib{}.so.{d}", self.name, self.version.major); - self.name_only_filename = self.builder.fmt("lib{}.so", self.name); + self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", .{ + self.name, + self.version.major, + self.version.minor, + self.version.patch, + }); + self.major_only_filename = self.builder.fmt("lib{}.so.{d}", .{ self.name, self.version.major }); + self.name_only_filename = self.builder.fmt("lib{}.so", .{self.name}); self.out_lib_filename = self.out_filename; } } @@ -1268,7 +1290,7 @@ pub const LibExeObjStep = struct { // It doesn't have to be native. We catch that if you actually try to run it. // Consider that this is declarative; the run step may not be run unless a user // option is supplied. - const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", exe.step.name)); + const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", .{exe.step.name})); run_step.addArtifactArg(exe); if (exe.vcpkg_bin_path) |path| { @@ -1420,7 +1442,7 @@ pub const LibExeObjStep = struct { } else if (mem.eql(u8, tok, "-pthread")) { self.linkLibC(); } else if (self.builder.verbose) { - warn("Ignoring pkg-config flag '{}'\n", tok); + warn("Ignoring pkg-config flag '{}'\n", .{tok}); } } } @@ -1653,7 +1675,7 @@ pub const LibExeObjStep = struct { const builder = self.builder; if (self.root_src == null and self.link_objects.len == 0) { - warn("{}: linker needs 1 or more objects to link\n", self.step.name); + warn("{}: linker needs 1 or more objects to link\n", .{self.step.name}); return error.NeedAnObject; } @@ -1725,7 +1747,7 @@ pub const LibExeObjStep = struct { if (self.build_options_contents.len() > 0) { const build_options_file = try fs.path.join( builder.allocator, - &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) }, + &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) }, ); try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst()); try zig_args.append("--pkg-begin"); @@ -1780,13 +1802,13 @@ pub const LibExeObjStep = struct { if (self.kind == Kind.Lib and self.is_dynamic) { zig_args.append("--ver-major") catch unreachable; - zig_args.append(builder.fmt("{}", self.version.major)) catch unreachable; + zig_args.append(builder.fmt("{}", .{self.version.major})) catch unreachable; zig_args.append("--ver-minor") catch unreachable; - zig_args.append(builder.fmt("{}", self.version.minor)) catch unreachable; + zig_args.append(builder.fmt("{}", .{self.version.minor})) catch unreachable; zig_args.append("--ver-patch") catch unreachable; - zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable; + zig_args.append(builder.fmt("{}", .{self.version.patch})) catch unreachable; } if (self.is_dynamic) { try zig_args.append("-dynamic"); @@ -1811,7 +1833,7 @@ pub const LibExeObjStep = struct { if (self.target_glibc) |ver| { try zig_args.append("-target-glibc"); - try zig_args.append(builder.fmt("{}.{}.{}", ver.major, ver.minor, ver.patch)); + try zig_args.append(builder.fmt("{}.{}.{}", .{ ver.major, ver.minor, ver.patch })); } if (self.linker_script) |linker_script| { @@ -2079,7 +2101,7 @@ pub const RunStep = struct { } if (prev_path) |pp| { - const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", pp, search_path); + const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", .{ pp, search_path }); env_map.set(key, new_path) catch unreachable; } else { env_map.set(key, search_path) catch unreachable; @@ -2153,7 +2175,7 @@ const InstallArtifactStep = struct { const self = builder.allocator.create(Self) catch unreachable; self.* = Self{ .builder = builder, - .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make), + .step = Step.init(builder.fmt("install {}", .{artifact.step.name}), builder.allocator, make), .artifact = artifact, .dest_dir = switch (artifact.kind) { .Obj => unreachable, @@ -2219,7 +2241,7 @@ pub const InstallFileStep = struct { builder.pushInstalledFile(dir, dest_rel_path); return InstallFileStep{ .builder = builder, - .step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make), + .step = Step.init(builder.fmt("install {}", .{src_path}), builder.allocator, make), .src_path = src_path, .dir = dir, .dest_rel_path = dest_rel_path, @@ -2253,7 +2275,7 @@ pub const InstallDirStep = struct { builder.pushInstalledFile(options.install_dir, options.install_subdir); return InstallDirStep{ .builder = builder, - .step = Step.init(builder.fmt("install {}/", options.source_dir), builder.allocator, make), + .step = Step.init(builder.fmt("install {}/", .{options.source_dir}), builder.allocator, make), .options = options, }; } @@ -2290,7 +2312,7 @@ pub const WriteFileStep = struct { pub fn init(builder: *Builder, file_path: []const u8, data: []const u8) WriteFileStep { return WriteFileStep{ .builder = builder, - .step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make), + .step = Step.init(builder.fmt("writefile {}", .{file_path}), builder.allocator, make), .file_path = file_path, .data = data, }; @@ -2301,11 +2323,11 @@ pub const WriteFileStep = struct { const full_path = self.builder.pathFromRoot(self.file_path); const full_path_dir = fs.path.dirname(full_path) orelse "."; fs.makePath(self.builder.allocator, full_path_dir) catch |err| { - warn("unable to make path {}: {}\n", full_path_dir, @errorName(err)); + warn("unable to make path {}: {}\n", .{ full_path_dir, @errorName(err) }); return err; }; io.writeFile(full_path, self.data) catch |err| { - warn("unable to write {}: {}\n", full_path, @errorName(err)); + warn("unable to write {}: {}\n", .{ full_path, @errorName(err) }); return err; }; } @@ -2319,14 +2341,14 @@ pub const LogStep = struct { pub fn init(builder: *Builder, data: []const u8) LogStep { return LogStep{ .builder = builder, - .step = Step.init(builder.fmt("log {}", data), builder.allocator, make), + .step = Step.init(builder.fmt("log {}", .{data}), builder.allocator, make), .data = data, }; } fn make(step: *Step) anyerror!void { const self = @fieldParentPtr(LogStep, "step", step); - warn("{}", self.data); + warn("{}", .{self.data}); } }; @@ -2338,7 +2360,7 @@ pub const RemoveDirStep = struct { pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep { return RemoveDirStep{ .builder = builder, - .step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make), + .step = Step.init(builder.fmt("RemoveDir {}", .{dir_path}), builder.allocator, make), .dir_path = dir_path, }; } @@ -2348,7 +2370,7 @@ pub const RemoveDirStep = struct { const full_path = self.builder.pathFromRoot(self.dir_path); fs.deleteTree(full_path) catch |err| { - warn("Unable to remove {}: {}\n", full_path, @errorName(err)); + warn("Unable to remove {}: {}\n", .{ full_path, @errorName(err) }); return err; }; } @@ -2397,7 +2419,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj &[_][]const u8{ out_dir, filename_major_only }, ) catch unreachable; fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| { - warn("Unable to symlink {} -> {}\n", major_only_path, out_basename); + warn("Unable to symlink {} -> {}\n", .{ major_only_path, out_basename }); return err; }; // sym link for libfoo.so to libfoo.so.1 @@ -2406,7 +2428,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj &[_][]const u8{ out_dir, filename_name_only }, ) catch unreachable; fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| { - warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only); + warn("Unable to symlink {} -> {}\n", .{ name_only_path, filename_major_only }); return err; }; } diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 35188b61e3..b3a80dc317 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -429,7 +429,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn } }, .wasi => { - std.debug.warn("{}", msg); + std.debug.warn("{}", .{msg}); _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT); unreachable; }, @@ -439,7 +439,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn }, else => { const first_trace_addr = @returnAddress(); - std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg); + std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", .{msg}); }, } } diff --git a/lib/std/crypto/benchmark.zig b/lib/std/crypto/benchmark.zig index 80615fd5c5..95761b7ba6 100644 --- a/lib/std/crypto/benchmark.zig +++ b/lib/std/crypto/benchmark.zig @@ -114,7 +114,7 @@ fn usage() void { \\ --seed [int] \\ --help \\ - ); + , .{}); } fn mode(comptime x: comptime_int) comptime_int { diff --git a/lib/std/debug.zig b/lib/std/debug.zig index e31f847d79..04a83c39f3 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -46,7 +46,7 @@ var stderr_file_out_stream: File.OutStream = undefined; var stderr_stream: ?*io.OutStream(File.WriteError) = null; var stderr_mutex = std.Mutex.init(); -pub fn warn(comptime fmt: []const u8, args: ...) void { +pub fn warn(comptime fmt: []const u8, args: var) void { const held = stderr_mutex.acquire(); defer held.release(); const stderr = getStderrStream(); @@ -92,15 +92,15 @@ fn wantTtyColor() bool { pub fn dumpCurrentStackTrace(start_addr: ?usize) void { const stderr = getStderrStream(); if (builtin.strip_debug_info) { - stderr.print("Unable to dump stack trace: debug info stripped\n") catch return; + stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return; return; } const debug_info = getSelfDebugInfo() catch |err| { - stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return; + stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return; return; }; writeCurrentStackTrace(stderr, debug_info, wantTtyColor(), start_addr) catch |err| { - stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return; + stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return; return; }; } @@ -111,11 +111,11 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void { pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void { const stderr = getStderrStream(); if (builtin.strip_debug_info) { - stderr.print("Unable to dump stack trace: debug info stripped\n") catch return; + stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return; return; } const debug_info = getSelfDebugInfo() catch |err| { - stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return; + stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return; return; }; const tty_color = wantTtyColor(); @@ -184,15 +184,15 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void { const stderr = getStderrStream(); if (builtin.strip_debug_info) { - stderr.print("Unable to dump stack trace: debug info stripped\n") catch return; + stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return; return; } const debug_info = getSelfDebugInfo() catch |err| { - stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return; + stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return; return; }; writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, wantTtyColor()) catch |err| { - stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return; + stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return; return; }; } @@ -211,7 +211,7 @@ pub fn assert(ok: bool) void { if (!ok) unreachable; // assertion failure } -pub fn panic(comptime format: []const u8, args: ...) noreturn { +pub fn panic(comptime format: []const u8, args: var) noreturn { @setCold(true); // TODO: remove conditional once wasi / LLVM defines __builtin_return_address const first_trace_addr = if (builtin.os == .wasi) null else @returnAddress(); @@ -221,7 +221,7 @@ pub fn panic(comptime format: []const u8, args: ...) noreturn { /// TODO multithreaded awareness var panicking: u8 = 0; // TODO make this a bool -pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: ...) noreturn { +pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: var) noreturn { @setCold(true); if (enable_segfault_handler) { @@ -376,13 +376,13 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres } else { // we have no information to add to the address if (tty_color) { - try out_stream.print("???:?:?: "); + try out_stream.print("???:?:?: ", .{}); setTtyColor(TtyColor.Dim); - try out_stream.print("0x{x} in ??? (???)", relocated_address); + try out_stream.print("0x{x} in ??? (???)", .{relocated_address}); setTtyColor(TtyColor.Reset); - try out_stream.print("\n\n\n"); + try out_stream.print("\n\n\n", .{}); } else { - try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", relocated_address); + try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{relocated_address}); } return; }; @@ -509,18 +509,18 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres if (tty_color) { setTtyColor(TtyColor.White); if (opt_line_info) |li| { - try out_stream.print("{}:{}:{}", li.file_name, li.line, li.column); + try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column }); } else { - try out_stream.print("???:?:?"); + try out_stream.print("???:?:?", .{}); } setTtyColor(TtyColor.Reset); - try out_stream.print(": "); + try out_stream.print(": ", .{}); setTtyColor(TtyColor.Dim); - try out_stream.print("0x{x} in {} ({})", relocated_address, symbol_name, obj_basename); + try out_stream.print("0x{x} in {} ({})", .{ relocated_address, symbol_name, obj_basename }); setTtyColor(TtyColor.Reset); if (opt_line_info) |line_info| { - try out_stream.print("\n"); + try out_stream.print("\n", .{}); if (printLineFromFileAnyOs(out_stream, line_info)) { if (line_info.column == 0) { try out_stream.write("\n"); @@ -546,13 +546,24 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres else => return err, } } else { - try out_stream.print("\n\n\n"); + try out_stream.print("\n\n\n", .{}); } } else { if (opt_line_info) |li| { - try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", li.file_name, li.line, li.column, relocated_address, symbol_name, obj_basename); + try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", .{ + li.file_name, + li.line, + li.column, + relocated_address, + symbol_name, + obj_basename, + }); } else { - try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", relocated_address, symbol_name, obj_basename); + try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{ + relocated_address, + symbol_name, + obj_basename, + }); } } } @@ -697,9 +708,9 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse { if (tty_color) { - try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", address); + try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address}); } else { - try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", address); + try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address}); } return; }; @@ -723,9 +734,11 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt } else |err| switch (err) { error.MissingDebugInfo, error.InvalidDebugInfo => { if (tty_color) { - try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", address, symbol_name, compile_unit_name); + try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", .{ + address, symbol_name, compile_unit_name, + }); } else { - try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", address, symbol_name, compile_unit_name); + try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{ address, symbol_name, compile_unit_name }); } }, else => return err, @@ -746,15 +759,14 @@ fn printLineInfo( comptime printLineFromFile: var, ) !void { if (tty_color) { - try out_stream.print( - WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", + try out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", .{ line_info.file_name, line_info.line, line_info.column, address, symbol_name, compile_unit_name, - ); + }); if (printLineFromFile(out_stream, line_info)) { if (line_info.column == 0) { try out_stream.write("\n"); @@ -772,15 +784,14 @@ fn printLineInfo( else => return err, } } else { - try out_stream.print( - "{}:{}:{}: 0x{x} in {} ({})\n", + try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n", .{ line_info.file_name, line_info.line, line_info.column, address, symbol_name, compile_unit_name, - ); + }); } } @@ -1226,9 +1237,9 @@ pub const DwarfInfo = struct { ) !void { const compile_unit = self.findCompileUnit(address) catch { if (tty_color) { - try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", address); + try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address}); } else { - try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", address); + try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address}); } return; }; @@ -1248,9 +1259,11 @@ pub const DwarfInfo = struct { } else |err| switch (err) { error.MissingDebugInfo, error.InvalidDebugInfo => { if (tty_color) { - try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", address, compile_unit_name); + try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", .{ + address, compile_unit_name, + }); } else { - try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", address, compile_unit_name); + try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", .{ address, compile_unit_name }); } }, else => return err, @@ -2416,7 +2429,7 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con resetSegfaultHandler(); const addr = @ptrToInt(info.fields.sigfault.addr); - std.debug.warn("Segmentation fault at address 0x{x}\n", addr); + std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr}); switch (builtin.arch) { .i386 => { @@ -2456,10 +2469,10 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con stdcallcc fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) c_long { const exception_address = @ptrToInt(info.ExceptionRecord.ExceptionAddress); switch (info.ExceptionRecord.ExceptionCode) { - windows.EXCEPTION_DATATYPE_MISALIGNMENT => panicExtra(null, exception_address, "Unaligned Memory Access"), - windows.EXCEPTION_ACCESS_VIOLATION => panicExtra(null, exception_address, "Segmentation fault at address 0x{x}", info.ExceptionRecord.ExceptionInformation[1]), - windows.EXCEPTION_ILLEGAL_INSTRUCTION => panicExtra(null, exception_address, "Illegal Instruction"), - windows.EXCEPTION_STACK_OVERFLOW => panicExtra(null, exception_address, "Stack Overflow"), + windows.EXCEPTION_DATATYPE_MISALIGNMENT => panicExtra(null, exception_address, "Unaligned Memory Access", .{}), + windows.EXCEPTION_ACCESS_VIOLATION => panicExtra(null, exception_address, "Segmentation fault at address 0x{x}", .{info.ExceptionRecord.ExceptionInformation[1]}), + windows.EXCEPTION_ILLEGAL_INSTRUCTION => panicExtra(null, exception_address, "Illegal Instruction", .{}), + windows.EXCEPTION_STACK_OVERFLOW => panicExtra(null, exception_address, "Stack Overflow", .{}), else => return windows.EXCEPTION_CONTINUE_SEARCH, } } @@ -2468,7 +2481,7 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void { const sp = asm ("" : [argc] "={rsp}" (-> usize) ); - std.debug.warn("{} sp = 0x{x}\n", prefix, sp); + std.debug.warn("{} sp = 0x{x}\n", .{ prefix, sp }); } // Reference everything so it gets tested. diff --git a/lib/std/event/channel.zig b/lib/std/event/channel.zig index 96cfd706be..2bcf6a4c50 100644 --- a/lib/std/event/channel.zig +++ b/lib/std/event/channel.zig @@ -294,14 +294,14 @@ test "std.event.Channel wraparound" { const channel_size = 2; - var buf : [channel_size]i32 = undefined; + var buf: [channel_size]i32 = undefined; var channel: Channel(i32) = undefined; channel.init(&buf); defer channel.deinit(); // add items to channel and pull them out until // the buffer wraps around, make sure it doesn't crash. - var result : i32 = undefined; + var result: i32 = undefined; channel.put(5); testing.expectEqual(@as(i32, 5), channel.get()); channel.put(6); diff --git a/lib/std/fifo.zig b/lib/std/fifo.zig index fdd746dfcc..7870979abb 100644 --- a/lib/std/fifo.zig +++ b/lib/std/fifo.zig @@ -293,7 +293,7 @@ pub fn LinearFifo( pub usingnamespace if (T == u8) struct { - pub fn print(self: *Self, comptime format: []const u8, args: ...) !void { + pub fn print(self: *Self, comptime format: []const u8, args: var) !void { return std.fmt.format(self, error{OutOfMemory}, Self.write, format, args); } } @@ -407,7 +407,7 @@ test "LinearFifo(u8, .Dynamic)" { fifo.shrink(0); { - try fifo.print("{}, {}!", "Hello", "World"); + try fifo.print("{}, {}!", .{ "Hello", "World" }); var result: [30]u8 = undefined; testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]); testing.expectEqual(@as(usize, 0), fifo.readableLength()); diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index da0cfd4318..a0871d52a6 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -91,10 +91,12 @@ pub fn format( comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void, comptime fmt: []const u8, - args: ..., + args: var, ) Errors!void { const ArgSetType = @IntType(false, 32); - if (args.len > ArgSetType.bit_count) { + const args_fields = std.meta.fields(@typeOf(args)); + const args_len = args_fields.len; + if (args_len > ArgSetType.bit_count) { @compileError("32 arguments max are supported per format call"); } @@ -158,14 +160,14 @@ pub fn format( maybe_pos_arg.? += c - '0'; specifier_start = i + 1; - if (maybe_pos_arg.? >= args.len) { + if (maybe_pos_arg.? >= args_len) { @compileError("Positional value refers to non-existent argument"); } }, '}' => { const arg_to_print = comptime nextArg(&used_pos_args, maybe_pos_arg, &next_arg); - if (arg_to_print >= args.len) { + if (arg_to_print >= args_len) { @compileError("Too few arguments"); } @@ -302,7 +304,7 @@ pub fn format( used_pos_args |= 1 << i; } - if (@popCount(ArgSetType, used_pos_args) != args.len) { + if (@popCount(ArgSetType, used_pos_args) != args_len) { @compileError("Unused arguments"); } if (state != State.Start) { @@ -389,7 +391,7 @@ pub fn formatType( } try output(context, " }"); } else { - try format(context, Errors, output, "@{x}", @ptrToInt(&value)); + try format(context, Errors, output, "@{x}", .{@ptrToInt(&value)}); } }, .Struct => { @@ -421,12 +423,12 @@ pub fn formatType( if (info.child == u8) { return formatText(value, fmt, options, context, Errors, output); } - return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)); + return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }); }, builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => { return formatType(value.*, fmt, options, context, Errors, output, max_depth); }, - else => return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)), + else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }), }, .Many => { if (ptr_info.child == u8) { @@ -435,7 +437,7 @@ pub fn formatType( return formatText(value[0..len], fmt, options, context, Errors, output); } } - return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)); + return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }); }, .Slice => { if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) { @@ -444,10 +446,10 @@ pub fn formatType( if (ptr_info.child == u8) { return formatText(value, fmt, options, context, Errors, output); } - return format(context, Errors, output, "{}@{x}", @typeName(ptr_info.child), @ptrToInt(value.ptr)); + return format(context, Errors, output, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) }); }, .C => { - return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)); + return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }); }, }, .Array => |info| { @@ -465,7 +467,7 @@ pub fn formatType( return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth); }, .Fn => { - return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value)); + return format(context, Errors, output, "{}@{x}", .{ @typeName(T), @ptrToInt(value) }); }, else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"), } @@ -1113,7 +1115,7 @@ pub const BufPrintError = error{ /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes. BufferTooSmall, }; -pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![]u8 { +pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: var) BufPrintError![]u8 { var context = BufPrintContext{ .remaining = buf }; try format(&context, BufPrintError, bufPrintWrite, fmt, args); return buf[0 .. buf.len - context.remaining.len]; @@ -1121,7 +1123,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![] pub const AllocPrintError = error{OutOfMemory}; -pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: ...) AllocPrintError![]u8 { +pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![]u8 { var size: usize = 0; format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {}; const buf = try allocator.alloc(u8, size); @@ -1173,46 +1175,46 @@ test "parse unsigned comptime" { test "optional" { { const value: ?i32 = 1234; - try testFmt("optional: 1234\n", "optional: {}\n", value); + try testFmt("optional: 1234\n", "optional: {}\n", .{value}); } { const value: ?i32 = null; - try testFmt("optional: null\n", "optional: {}\n", value); + try testFmt("optional: null\n", "optional: {}\n", .{value}); } } test "error" { { const value: anyerror!i32 = 1234; - try testFmt("error union: 1234\n", "error union: {}\n", value); + try testFmt("error union: 1234\n", "error union: {}\n", .{value}); } { const value: anyerror!i32 = error.InvalidChar; - try testFmt("error union: error.InvalidChar\n", "error union: {}\n", value); + try testFmt("error union: error.InvalidChar\n", "error union: {}\n", .{value}); } } test "int.small" { { const value: u3 = 0b101; - try testFmt("u3: 5\n", "u3: {}\n", value); + try testFmt("u3: 5\n", "u3: {}\n", .{value}); } } test "int.specifier" { { const value: u8 = 'a'; - try testFmt("u8: a\n", "u8: {c}\n", value); + try testFmt("u8: a\n", "u8: {c}\n", .{value}); } { const value: u8 = 0b1100; - try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", value); + try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", .{value}); } } test "int.padded" { - try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1)); - try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1)); + try testFmt("u8: ' 1'", "u8: '{:4}'", .{@as(u8, 1)}); + try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", .{@as(u8, 1)}); } test "buffer" { @@ -1238,14 +1240,14 @@ test "buffer" { test "array" { { const value: [3]u8 = "abc".*; - try testFmt("array: abc\n", "array: {}\n", value); - try testFmt("array: abc\n", "array: {}\n", &value); + try testFmt("array: abc\n", "array: {}\n", .{value}); + try testFmt("array: abc\n", "array: {}\n", .{&value}); var buf: [100]u8 = undefined; try testFmt( - try bufPrint(buf[0..], "array: [3]u8@{x}\n", @ptrToInt(&value)), + try bufPrint(buf[0..], "array: [3]u8@{x}\n", .{@ptrToInt(&value)}), "array: {*}\n", - &value, + .{&value}, ); } } @@ -1253,36 +1255,36 @@ test "array" { test "slice" { { const value: []const u8 = "abc"; - try testFmt("slice: abc\n", "slice: {}\n", value); + try testFmt("slice: abc\n", "slice: {}\n", .{value}); } { const value = @intToPtr([*]const []const u8, 0xdeadbeef)[0..0]; - try testFmt("slice: []const u8@deadbeef\n", "slice: {}\n", value); + try testFmt("slice: []const u8@deadbeef\n", "slice: {}\n", .{value}); } - try testFmt("buf: Test \n", "buf: {s:5}\n", "Test"); - try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", "Test"); + try testFmt("buf: Test \n", "buf: {s:5}\n", .{"Test"}); + try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", .{"Test"}); } test "pointer" { { const value = @intToPtr(*i32, 0xdeadbeef); - try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", value); - try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", value); + try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", .{value}); + try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", .{value}); } { const value = @intToPtr(fn () void, 0xdeadbeef); - try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value); + try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value}); } { const value = @intToPtr(fn () void, 0xdeadbeef); - try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value); + try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value}); } } test "cstr" { - try testFmt("cstr: Test C\n", "cstr: {s}\n", "Test C"); - try testFmt("cstr: Test C \n", "cstr: {s:10}\n", "Test C"); + try testFmt("cstr: Test C\n", "cstr: {s}\n", .{"Test C"}); + try testFmt("cstr: Test C \n", "cstr: {s:10}\n", .{"Test C"}); } test "filesize" { @@ -1290,8 +1292,8 @@ test "filesize" { // TODO https://github.com/ziglang/zig/issues/3289 return error.SkipZigTest; } - try testFmt("file size: 63MiB\n", "file size: {Bi}\n", @as(usize, 63 * 1024 * 1024)); - try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", @as(usize, 63 * 1024 * 1024)); + try testFmt("file size: 63MiB\n", "file size: {Bi}\n", .{@as(usize, 63 * 1024 * 1024)}); + try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", .{@as(usize, 63 * 1024 * 1024)}); } test "struct" { @@ -1300,8 +1302,8 @@ test "struct" { field: u8, }; const value = Struct{ .field = 42 }; - try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", value); - try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", &value); + try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{value}); + try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{&value}); } { const Struct = struct { @@ -1309,7 +1311,7 @@ test "struct" { b: u1, }; const value = Struct{ .a = 0, .b = 1 }; - try testFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", value); + try testFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", .{value}); } } @@ -1319,8 +1321,8 @@ test "enum" { Two, }; const value = Enum.Two; - try testFmt("enum: Enum.Two\n", "enum: {}\n", value); - try testFmt("enum: Enum.Two\n", "enum: {}\n", &value); + try testFmt("enum: Enum.Two\n", "enum: {}\n", .{value}); + try testFmt("enum: Enum.Two\n", "enum: {}\n", .{&value}); } test "float.scientific" { @@ -1328,10 +1330,10 @@ test "float.scientific" { // TODO https://github.com/ziglang/zig/issues/3289 return error.SkipZigTest; } - try testFmt("f32: 1.34000003e+00", "f32: {e}", @as(f32, 1.34)); - try testFmt("f32: 1.23400001e+01", "f32: {e}", @as(f32, 12.34)); - try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10)); - try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40)); + try testFmt("f32: 1.34000003e+00", "f32: {e}", .{@as(f32, 1.34)}); + try testFmt("f32: 1.23400001e+01", "f32: {e}", .{@as(f32, 12.34)}); + try testFmt("f64: -1.234e+11", "f64: {e}", .{@as(f64, -12.34e10)}); + try testFmt("f64: 9.99996e-40", "f64: {e}", .{@as(f64, 9.999960e-40)}); } test "float.scientific.precision" { @@ -1339,12 +1341,12 @@ test "float.scientific.precision" { // TODO https://github.com/ziglang/zig/issues/3289 return error.SkipZigTest; } - try testFmt("f64: 1.40971e-42", "f64: {e:.5}", @as(f64, 1.409706e-42)); - try testFmt("f64: 1.00000e-09", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 814313563)))); - try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960)))); + try testFmt("f64: 1.40971e-42", "f64: {e:.5}", .{@as(f64, 1.409706e-42)}); + try testFmt("f64: 1.00000e-09", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 814313563)))}); + try testFmt("f64: 7.81250e-03", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1006632960)))}); // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05. // In fact, libc doesn't round a lot of 5 cases up when one past the precision point. - try testFmt("f64: 1.00001e+05", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1203982400)))); + try testFmt("f64: 1.00001e+05", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1203982400)))}); } test "float.special" { @@ -1352,14 +1354,14 @@ test "float.special" { // TODO https://github.com/ziglang/zig/issues/3289 return error.SkipZigTest; } - try testFmt("f64: nan", "f64: {}", math.nan_f64); + try testFmt("f64: nan", "f64: {}", .{math.nan_f64}); // negative nan is not defined by IEE 754, // and ARM thus normalizes it to positive nan if (builtin.arch != builtin.Arch.arm) { - try testFmt("f64: -nan", "f64: {}", -math.nan_f64); + try testFmt("f64: -nan", "f64: {}", .{-math.nan_f64}); } - try testFmt("f64: inf", "f64: {}", math.inf_f64); - try testFmt("f64: -inf", "f64: {}", -math.inf_f64); + try testFmt("f64: inf", "f64: {}", .{math.inf_f64}); + try testFmt("f64: -inf", "f64: {}", .{-math.inf_f64}); } test "float.decimal" { @@ -1367,21 +1369,21 @@ test "float.decimal" { // TODO https://github.com/ziglang/zig/issues/3289 return error.SkipZigTest; } - try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29)); - try testFmt("f32: 1.1", "f32: {d:.1}", @as(f32, 1.1234)); - try testFmt("f32: 1234.57", "f32: {d:.2}", @as(f32, 1234.567)); + try testFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)}); + try testFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)}); + try testFmt("f32: 1234.57", "f32: {d:.2}", .{@as(f32, 1234.567)}); // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64). // -11.12339... is rounded back up to -11.1234 - try testFmt("f32: -11.1234", "f32: {d:.4}", @as(f32, -11.1234)); - try testFmt("f32: 91.12345", "f32: {d:.5}", @as(f32, 91.12345)); - try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235)); - try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0)); - try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700)); - try testFmt("f64: 10.0", "f64: {d:.1}", @as(f64, 9.999)); - try testFmt("f64: 1.000", "f64: {d:.3}", @as(f64, 1.0)); - try testFmt("f64: 0.00030000", "f64: {d:.8}", @as(f64, 0.0003)); - try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 1.40130e-45)); - try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40)); + try testFmt("f32: -11.1234", "f32: {d:.4}", .{@as(f32, -11.1234)}); + try testFmt("f32: 91.12345", "f32: {d:.5}", .{@as(f32, 91.12345)}); + try testFmt("f64: 91.1234567890", "f64: {d:.10}", .{@as(f64, 91.12345678901235)}); + try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 0.0)}); + try testFmt("f64: 6", "f64: {d:.0}", .{@as(f64, 5.700)}); + try testFmt("f64: 10.0", "f64: {d:.1}", .{@as(f64, 9.999)}); + try testFmt("f64: 1.000", "f64: {d:.3}", .{@as(f64, 1.0)}); + try testFmt("f64: 0.00030000", "f64: {d:.8}", .{@as(f64, 0.0003)}); + try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 1.40130e-45)}); + try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 9.999960e-40)}); } test "float.libc.sanity" { @@ -1389,22 +1391,22 @@ test "float.libc.sanity" { // TODO https://github.com/ziglang/zig/issues/3289 return error.SkipZigTest; } - try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 916964781)))); - try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 925353389)))); - try testFmt("f64: 0.10000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1036831278)))); - try testFmt("f64: 1.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1065353133)))); - try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192)))); + try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 916964781)))}); + try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 925353389)))}); + try testFmt("f64: 0.10000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1036831278)))}); + try testFmt("f64: 1.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1065353133)))}); + try testFmt("f64: 10.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1092616192)))}); // libc differences // // This is 0.015625 exactly according to gdb. We thus round down, // however glibc rounds up for some reason. This occurs for all // floats of the form x.yyyy25 on a precision point. - try testFmt("f64: 0.01563", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1015021568)))); + try testFmt("f64: 0.01563", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1015021568)))}); // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3 // also rounds to 630 so I'm inclined to believe libc is not // optimal here. - try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1518338049)))); + try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1518338049)))}); } test "custom" { @@ -1422,9 +1424,9 @@ test "custom" { output: fn (@typeOf(context), []const u8) Errors!void, ) Errors!void { if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) { - return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", self.x, self.y); + return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y }); } else if (comptime std.mem.eql(u8, fmt, "d")) { - return std.fmt.format(context, Errors, output, "{d:.3}x{d:.3}", self.x, self.y); + return std.fmt.format(context, Errors, output, "{d:.3}x{d:.3}", .{ self.x, self.y }); } else { @compileError("Unknown format character: '" ++ fmt ++ "'"); } @@ -1436,12 +1438,12 @@ test "custom" { .x = 10.2, .y = 2.22, }; - try testFmt("point: (10.200,2.220)\n", "point: {}\n", &value); - try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", &value); + try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{&value}); + try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{&value}); // same thing but not passing a pointer - try testFmt("point: (10.200,2.220)\n", "point: {}\n", value); - try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", value); + try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{value}); + try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{value}); } test "struct" { @@ -1455,7 +1457,7 @@ test "struct" { .b = error.Unused, }; - try testFmt("S{ .a = 456, .b = error.Unused }", "{}", inst); + try testFmt("S{ .a = 456, .b = error.Unused }", "{}", .{inst}); } test "union" { @@ -1478,13 +1480,13 @@ test "union" { const uu_inst = UU{ .int = 456 }; const eu_inst = EU{ .float = 321.123 }; - try testFmt("TU{ .int = 123 }", "{}", tu_inst); + try testFmt("TU{ .int = 123 }", "{}", .{tu_inst}); var buf: [100]u8 = undefined; - const uu_result = try bufPrint(buf[0..], "{}", uu_inst); + const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst}); std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@")); - const eu_result = try bufPrint(buf[0..], "{}", eu_inst); + const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst}); std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@")); } @@ -1497,7 +1499,7 @@ test "enum" { const inst = E.Two; - try testFmt("E.Two", "{}", inst); + try testFmt("E.Two", "{}", .{inst}); } test "struct.self-referential" { @@ -1511,7 +1513,7 @@ test "struct.self-referential" { }; inst.a = &inst; - try testFmt("S{ .a = S{ .a = S{ .a = S{ ... } } } }", "{}", inst); + try testFmt("S{ .a = S{ .a = S{ .a = S{ ... } } } }", "{}", .{inst}); } test "struct.zero-size" { @@ -1526,30 +1528,30 @@ test "struct.zero-size" { const a = A{}; const b = B{ .a = a, .c = 0 }; - try testFmt("B{ .a = A{ }, .c = 0 }", "{}", b); + try testFmt("B{ .a = A{ }, .c = 0 }", "{}", .{b}); } test "bytes.hex" { const some_bytes = "\xCA\xFE\xBA\xBE"; - try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", some_bytes); - try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", some_bytes); + try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", .{some_bytes}); + try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", .{some_bytes}); //Test Slices - try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", some_bytes[0..2]); - try testFmt("lowercase: babe\n", "lowercase: {x}\n", some_bytes[2..]); + try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", .{some_bytes[0..2]}); + try testFmt("lowercase: babe\n", "lowercase: {x}\n", .{some_bytes[2..]}); const bytes_with_zeros = "\x00\x0E\xBA\xBE"; - try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", bytes_with_zeros); + try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros}); } -fn testFmt(expected: []const u8, comptime template: []const u8, args: ...) !void { +fn testFmt(expected: []const u8, comptime template: []const u8, args: var) !void { var buf: [100]u8 = undefined; const result = try bufPrint(buf[0..], template, args); if (mem.eql(u8, result, expected)) return; - std.debug.warn("\n====== expected this output: =========\n"); - std.debug.warn("{}", expected); - std.debug.warn("\n======== instead found this: =========\n"); - std.debug.warn("{}", result); - std.debug.warn("\n======================================\n"); + std.debug.warn("\n====== expected this output: =========\n", .{}); + std.debug.warn("{}", .{expected}); + std.debug.warn("\n======== instead found this: =========\n", .{}); + std.debug.warn("{}", .{result}); + std.debug.warn("\n======================================\n", .{}); return error.TestFailed; } @@ -1602,7 +1604,7 @@ test "hexToBytes" { const test_hex_str = "909A312BB12ED1F819B3521AC4C1E896F2160507FFC1C8381E3B07BB16BD1706"; var pb: [32]u8 = undefined; try hexToBytes(pb[0..], test_hex_str); - try testFmt(test_hex_str, "{X}", pb); + try testFmt(test_hex_str, "{X}", .{pb}); } test "formatIntValue with comptime_int" { @@ -1628,7 +1630,7 @@ test "formatType max_depth" { output: fn (@typeOf(context), []const u8) Errors!void, ) Errors!void { if (fmt.len == 0) { - return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", self.x, self.y); + return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y }); } else { @compileError("Unknown format string: '" ++ fmt ++ "'"); } @@ -1680,17 +1682,17 @@ test "formatType max_depth" { } test "positional" { - try testFmt("2 1 0", "{2} {1} {0}", @as(usize, 0), @as(usize, 1), @as(usize, 2)); - try testFmt("2 1 0", "{2} {1} {}", @as(usize, 0), @as(usize, 1), @as(usize, 2)); - try testFmt("0 0", "{0} {0}", @as(usize, 0)); - try testFmt("0 1", "{} {1}", @as(usize, 0), @as(usize, 1)); - try testFmt("1 0 0 1", "{1} {} {0} {}", @as(usize, 0), @as(usize, 1)); + try testFmt("2 1 0", "{2} {1} {0}", .{ @as(usize, 0), @as(usize, 1), @as(usize, 2) }); + try testFmt("2 1 0", "{2} {1} {}", .{ @as(usize, 0), @as(usize, 1), @as(usize, 2) }); + try testFmt("0 0", "{0} {0}", .{@as(usize, 0)}); + try testFmt("0 1", "{} {1}", .{ @as(usize, 0), @as(usize, 1) }); + try testFmt("1 0 0 1", "{1} {} {0} {}", .{ @as(usize, 0), @as(usize, 1) }); } test "positional with specifier" { - try testFmt("10.0", "{0d:.1}", @as(f64, 9.999)); + try testFmt("10.0", "{0d:.1}", .{@as(f64, 9.999)}); } test "positional/alignment/width/precision" { - try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999)); + try testFmt("10.0", "{0d: >3.1}", .{@as(f64, 9.999)}); } diff --git a/lib/std/hash/benchmark.zig b/lib/std/hash/benchmark.zig index 4553d928ec..f1b39bff64 100644 --- a/lib/std/hash/benchmark.zig +++ b/lib/std/hash/benchmark.zig @@ -164,7 +164,7 @@ fn usage() void { \\ --iterative-only \\ --help \\ - ); + , .{}); } fn mode(comptime x: comptime_int) comptime_int { diff --git a/lib/std/http/headers.zig b/lib/std/http/headers.zig index 1d573aebc0..7cac6648de 100644 --- a/lib/std/http/headers.zig +++ b/lib/std/http/headers.zig @@ -610,5 +610,5 @@ test "Headers.format" { \\foo: bar \\cookie: somevalue \\ - , try std.fmt.bufPrint(buf[0..], "{}", h)); + , try std.fmt.bufPrint(buf[0..], "{}", .{h})); } diff --git a/lib/std/io.zig b/lib/std/io.zig index 238f7eb0f0..68c147a33c 100644 --- a/lib/std/io.zig +++ b/lib/std/io.zig @@ -492,7 +492,7 @@ test "io.SliceOutStream" { var slice_stream = SliceOutStream.init(buf[0..]); const stream = &slice_stream.stream; - try stream.print("{}{}!", "Hello", "World"); + try stream.print("{}{}!", .{ "Hello", "World" }); testing.expectEqualSlices(u8, "HelloWorld!", slice_stream.getWritten()); } diff --git a/lib/std/io/out_stream.zig b/lib/std/io/out_stream.zig index 77698b333c..b8f5db6fff 100644 --- a/lib/std/io/out_stream.zig +++ b/lib/std/io/out_stream.zig @@ -35,7 +35,7 @@ pub fn OutStream(comptime WriteError: type) type { } } - pub fn print(self: *Self, comptime format: []const u8, args: ...) Error!void { + pub fn print(self: *Self, comptime format: []const u8, args: var) Error!void { return std.fmt.format(self, Error, self.writeFn, format, args); } diff --git a/lib/std/io/test.zig b/lib/std/io/test.zig index 5b189cbe5a..92259fd6e9 100644 --- a/lib/std/io/test.zig +++ b/lib/std/io/test.zig @@ -27,9 +27,9 @@ test "write a file, read it, then delete it" { var file_out_stream = file.outStream(); var buf_stream = io.BufferedOutStream(File.WriteError).init(&file_out_stream.stream); const st = &buf_stream.stream; - try st.print("begin"); + try st.print("begin", .{}); try st.write(data[0..]); - try st.print("end"); + try st.print("end", .{}); try buf_stream.flush(); } @@ -72,7 +72,7 @@ test "BufferOutStream" { const x: i32 = 42; const y: i32 = 1234; - try buf_stream.print("x: {}\ny: {}\n", x, y); + try buf_stream.print("x: {}\ny: {}\n", .{ x, y }); expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n")); } @@ -605,7 +605,7 @@ test "c out stream" { } const out_stream = &io.COutStream.init(out_file).stream; - try out_stream.print("hi: {}\n", @as(i32, 123)); + try out_stream.print("hi: {}\n", .{@as(i32, 123)}); } test "File seek ops" { diff --git a/lib/std/json/write_stream.zig b/lib/std/json/write_stream.zig index fbf860965f..7cff613dad 100644 --- a/lib/std/json/write_stream.zig +++ b/lib/std/json/write_stream.zig @@ -158,24 +158,24 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { switch (@typeInfo(@typeOf(value))) { .Int => |info| { if (info.bits < 53) { - try self.stream.print("{}", value); + try self.stream.print("{}", .{value}); self.popState(); return; } if (value < 4503599627370496 and (!info.is_signed or value > -4503599627370496)) { - try self.stream.print("{}", value); + try self.stream.print("{}", .{value}); self.popState(); return; } }, .Float => if (@floatCast(f64, value) == value) { - try self.stream.print("{}", value); + try self.stream.print("{}", .{value}); self.popState(); return; }, else => {}, } - try self.stream.print("\"{}\"", value); + try self.stream.print("\"{}\"", .{value}); self.popState(); } diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index 5c84dc462b..0d0b186332 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -180,9 +180,9 @@ pub const Int = struct { pub fn dump(self: Int) void { for (self.limbs) |limb| { - debug.warn("{x} ", limb); + debug.warn("{x} ", .{limb}); } - debug.warn("\n"); + debug.warn("\n", .{}); } /// Negate the sign of an Int. diff --git a/lib/std/net.zig b/lib/std/net.zig index 6091564a93..a3f9c1c6d1 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -277,32 +277,24 @@ pub const Address = extern union { os.AF_INET => { const port = mem.bigToNative(u16, self.in.port); const bytes = @ptrCast(*const [4]u8, &self.in.addr); - try std.fmt.format( - context, - Errors, - output, - "{}.{}.{}.{}:{}", + try std.fmt.format(context, Errors, output, "{}.{}.{}.{}:{}", .{ bytes[0], bytes[1], bytes[2], bytes[3], port, - ); + }); }, os.AF_INET6 => { const port = mem.bigToNative(u16, self.in6.port); if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) { - try std.fmt.format( - context, - Errors, - output, - "[::ffff:{}.{}.{}.{}]:{}", + try std.fmt.format(context, Errors, output, "[::ffff:{}.{}.{}.{}]:{}", .{ self.in6.addr[12], self.in6.addr[13], self.in6.addr[14], self.in6.addr[15], port, - ); + }); return; } const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.in6.addr); @@ -327,19 +319,19 @@ pub const Address = extern union { } continue; } - try std.fmt.format(context, Errors, output, "{x}", native_endian_parts[i]); + try std.fmt.format(context, Errors, output, "{x}", .{native_endian_parts[i]}); if (i != native_endian_parts.len - 1) { try output(context, ":"); } } - try std.fmt.format(context, Errors, output, "]:{}", port); + try std.fmt.format(context, Errors, output, "]:{}", .{port}); }, os.AF_UNIX => { if (!has_unix_sockets) { unreachable; } - try std.fmt.format(context, Errors, output, "{}", &self.un.path); + try std.fmt.format(context, Errors, output, "{}", .{&self.un.path}); }, else => unreachable, } @@ -445,7 +437,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !* const name_c = try std.cstr.addNullByte(allocator, name); defer allocator.free(name_c); - const port_c = try std.fmt.allocPrint(allocator, "{}\x00", port); + const port_c = try std.fmt.allocPrint(allocator, "{}\x00", .{port}); defer allocator.free(port_c); const hints = os.addrinfo{ diff --git a/lib/std/net/test.zig b/lib/std/net/test.zig index 6400b022c6..2dd11b391e 100644 --- a/lib/std/net/test.zig +++ b/lib/std/net/test.zig @@ -29,7 +29,7 @@ test "parse and render IPv6 addresses" { }; for (ips) |ip, i| { var addr = net.Address.parseIp6(ip, 0) catch unreachable; - var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable; + var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3])); } @@ -51,7 +51,7 @@ test "parse and render IPv4 addresses" { "127.0.0.1", }) |ip| { var addr = net.Address.parseIp4(ip, 0) catch unreachable; - var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable; + var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2])); } @@ -118,5 +118,5 @@ fn testServer(server: *net.StreamServer) anyerror!void { var client = try server.accept(); const stream = &client.file.outStream().stream; - try stream.print("hello from server\n"); + try stream.print("hello from server\n", .{}); } diff --git a/lib/std/os.zig b/lib/std/os.zig index 5d3bb705a9..8d6c7dd05e 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -2603,7 +2603,7 @@ pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP defer close(fd); var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined; - const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", fd) catch unreachable; + const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", .{fd}) catch unreachable; return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer); } @@ -2832,7 +2832,7 @@ pub const UnexpectedError = error{ /// and you get an unexpected error. pub fn unexpectedErrno(err: usize) UnexpectedError { if (unexpected_error_tracing) { - std.debug.warn("unexpected errno: {}\n", err); + std.debug.warn("unexpected errno: {}\n", .{err}); std.debug.dumpCurrentStackTrace(null); } return error.Unexpected; diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index e832f66254..b7b1edeb89 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -323,7 +323,7 @@ pub fn GetQueuedCompletionStatus( ERROR.HANDLE_EOF => return GetQueuedCompletionStatusResult.EOF, else => |err| { if (std.debug.runtime_safety) { - std.debug.panic("unexpected error: {}\n", err); + std.debug.panic("unexpected error: {}\n", .{err}); } }, } @@ -1039,7 +1039,7 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError { var buf_u8: [614]u8 = undefined; var len = kernel32.FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT), buf_u16[0..].ptr, buf_u16.len / @sizeOf(TCHAR), null); _ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable; - std.debug.warn("error.Unexpected: GetLastError({}): {}\n", err, buf_u8[0..len]); + std.debug.warn("error.Unexpected: GetLastError({}): {}\n", .{ err, buf_u8[0..len] }); std.debug.dumpCurrentStackTrace(null); } return error.Unexpected; @@ -1053,7 +1053,7 @@ pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError { /// and you get an unexpected status. pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError { if (std.os.unexpected_error_tracing) { - std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", status); + std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", .{status}); std.debug.dumpCurrentStackTrace(null); } return error.Unexpected; diff --git a/lib/std/os/zen.zig b/lib/std/os/zen.zig deleted file mode 100644 index 190b7ffe08..0000000000 --- a/lib/std/os/zen.zig +++ /dev/null @@ -1,260 +0,0 @@ -const std = @import("../std.zig"); -const assert = std.debug.assert; - -////////////////////////// -//// IPC structures //// -////////////////////////// - -pub const Message = struct { - sender: MailboxId, - receiver: MailboxId, - code: usize, - args: [5]usize, - payload: ?[]const u8, - - pub fn from(mailbox_id: MailboxId) Message { - return Message{ - .sender = MailboxId.Undefined, - .receiver = mailbox_id, - .code = undefined, - .args = undefined, - .payload = null, - }; - } - - pub fn to(mailbox_id: MailboxId, msg_code: usize, args: ...) Message { - var message = Message{ - .sender = MailboxId.This, - .receiver = mailbox_id, - .code = msg_code, - .args = undefined, - .payload = null, - }; - - assert(args.len <= message.args.len); - comptime var i = 0; - inline while (i < args.len) : (i += 1) { - message.args[i] = args[i]; - } - - return message; - } - - pub fn as(self: Message, sender: MailboxId) Message { - var message = self; - message.sender = sender; - return message; - } - - pub fn withPayload(self: Message, payload: []const u8) Message { - var message = self; - message.payload = payload; - return message; - } -}; - -pub const MailboxId = union(enum) { - Undefined, - This, - Kernel, - Port: u16, - Thread: u16, -}; - -////////////////////////////////////// -//// Ports reserved for servers //// -////////////////////////////////////// - -pub const Server = struct { - pub const Keyboard = MailboxId{ .Port = 0 }; - pub const Terminal = MailboxId{ .Port = 1 }; -}; - -//////////////////////// -//// POSIX things //// -//////////////////////// - -// Standard streams. -pub const STDIN_FILENO = 0; -pub const STDOUT_FILENO = 1; -pub const STDERR_FILENO = 2; - -// FIXME: let's borrow Linux's error numbers for now. -usingnamespace @import("bits/linux/errno-generic.zig"); -// Get the errno from a syscall return value, or 0 for no error. -pub fn getErrno(r: usize) usize { - const signed_r = @bitCast(isize, r); - return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; -} - -// TODO: implement this correctly. -pub fn read(fd: i32, buf: [*]u8, count: usize) usize { - switch (fd) { - STDIN_FILENO => { - var i: usize = 0; - while (i < count) : (i += 1) { - send(&Message.to(Server.Keyboard, 0)); - - // FIXME: we should be certain that we are receiving from Keyboard. - var message = Message.from(MailboxId.This); - receive(&message); - - buf[i] = @intCast(u8, message.args[0]); - } - }, - else => unreachable, - } - return count; -} - -// TODO: implement this correctly. -pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { - switch (fd) { - STDOUT_FILENO, STDERR_FILENO => { - send(&Message.to(Server.Terminal, 1).withPayload(buf[0..count])); - }, - else => unreachable, - } - return count; -} - -/////////////////////////// -//// Syscall numbers //// -/////////////////////////// - -pub const Syscall = enum(usize) { - exit = 0, - send = 1, - receive = 2, - subscribeIRQ = 3, - inb = 4, - outb = 5, - map = 6, - createThread = 7, -}; - -//////////////////// -//// Syscalls //// -//////////////////// - -pub fn exit(status: i32) noreturn { - _ = syscall1(Syscall.exit, @bitCast(usize, @as(isize, status))); - unreachable; -} - -pub fn send(message: *const Message) void { - _ = syscall1(Syscall.send, @ptrToInt(message)); -} - -pub fn receive(destination: *Message) void { - _ = syscall1(Syscall.receive, @ptrToInt(destination)); -} - -pub fn subscribeIRQ(irq: u8, mailbox_id: *const MailboxId) void { - _ = syscall2(Syscall.subscribeIRQ, irq, @ptrToInt(mailbox_id)); -} - -pub fn inb(port: u16) u8 { - return @intCast(u8, syscall1(Syscall.inb, port)); -} - -pub fn outb(port: u16, value: u8) void { - _ = syscall2(Syscall.outb, port, value); -} - -pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool { - return syscall4(Syscall.map, v_addr, p_addr, size, @boolToInt(writable)) != 0; -} - -pub fn createThread(function: fn () void) u16 { - return @as(u16, syscall1(Syscall.createThread, @ptrToInt(function))); -} - -///////////////////////// -//// Syscall stubs //// -///////////////////////// - -inline fn syscall0(number: Syscall) usize { - return asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number) - ); -} - -inline fn syscall1(number: Syscall, arg1: usize) usize { - return asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ecx}" (arg1) - ); -} - -inline fn syscall2(number: Syscall, arg1: usize, arg2: usize) usize { - return asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ecx}" (arg1), - [arg2] "{edx}" (arg2) - ); -} - -inline fn syscall3(number: Syscall, arg1: usize, arg2: usize, arg3: usize) usize { - return asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ecx}" (arg1), - [arg2] "{edx}" (arg2), - [arg3] "{ebx}" (arg3) - ); -} - -inline fn syscall4(number: Syscall, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { - return asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ecx}" (arg1), - [arg2] "{edx}" (arg2), - [arg3] "{ebx}" (arg3), - [arg4] "{esi}" (arg4) - ); -} - -inline fn syscall5( - number: Syscall, - arg1: usize, - arg2: usize, - arg3: usize, - arg4: usize, - arg5: usize, -) usize { - return asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ecx}" (arg1), - [arg2] "{edx}" (arg2), - [arg3] "{ebx}" (arg3), - [arg4] "{esi}" (arg4), - [arg5] "{edi}" (arg5) - ); -} - -inline fn syscall6( - number: Syscall, - arg1: usize, - arg2: usize, - arg3: usize, - arg4: usize, - arg5: usize, - arg6: usize, -) usize { - return asm volatile ("int $0x80" - : [ret] "={eax}" (-> usize) - : [number] "{eax}" (number), - [arg1] "{ecx}" (arg1), - [arg2] "{edx}" (arg2), - [arg3] "{ebx}" (arg3), - [arg4] "{esi}" (arg4), - [arg5] "{edi}" (arg5), - [arg6] "{ebp}" (arg6) - ); -} diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig index 3351ac994b..77c76e4a70 100644 --- a/lib/std/priority_queue.zig +++ b/lib/std/priority_queue.zig @@ -199,19 +199,19 @@ pub fn PriorityQueue(comptime T: type) type { } fn dump(self: *Self) void { - warn("{{ "); - warn("items: "); + warn("{{ ", .{}); + warn("items: ", .{}); for (self.items) |e, i| { if (i >= self.len) break; - warn("{}, ", e); + warn("{}, ", .{e}); } - warn("array: "); + warn("array: ", .{}); for (self.items) |e, i| { - warn("{}, ", e); + warn("{}, ", .{e}); } - warn("len: {} ", self.len); - warn("capacity: {}", self.capacity()); - warn(" }}\n"); + warn("len: {} ", .{self.len}); + warn("capacity: {}", .{self.capacity()}); + warn(" }}\n", .{}); } }; } diff --git a/lib/std/progress.zig b/lib/std/progress.zig index 034d7ade26..1c5ecd261a 100644 --- a/lib/std/progress.zig +++ b/lib/std/progress.zig @@ -130,11 +130,11 @@ pub const Progress = struct { var end: usize = 0; if (self.columns_written > 0) { // restore cursor position - end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", self.columns_written) catch unreachable).len; + end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", .{self.columns_written}) catch unreachable).len; self.columns_written = 0; // clear rest of line - end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K") catch unreachable).len; + end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len; } if (!self.done) { @@ -142,28 +142,28 @@ pub const Progress = struct { var maybe_node: ?*Node = &self.root; while (maybe_node) |node| { if (need_ellipse) { - self.bufWrite(&end, "..."); + self.bufWrite(&end, "...", .{}); } need_ellipse = false; if (node.name.len != 0 or node.estimated_total_items != null) { if (node.name.len != 0) { - self.bufWrite(&end, "{}", node.name); + self.bufWrite(&end, "{}", .{node.name}); need_ellipse = true; } if (node.estimated_total_items) |total| { - if (need_ellipse) self.bufWrite(&end, " "); - self.bufWrite(&end, "[{}/{}] ", node.completed_items + 1, total); + if (need_ellipse) self.bufWrite(&end, " ", .{}); + self.bufWrite(&end, "[{}/{}] ", .{ node.completed_items + 1, total }); need_ellipse = false; } else if (node.completed_items != 0) { - if (need_ellipse) self.bufWrite(&end, " "); - self.bufWrite(&end, "[{}] ", node.completed_items + 1); + if (need_ellipse) self.bufWrite(&end, " ", .{}); + self.bufWrite(&end, "[{}] ", .{node.completed_items + 1}); need_ellipse = false; } } maybe_node = node.recently_updated_child; } if (need_ellipse) { - self.bufWrite(&end, "..."); + self.bufWrite(&end, "...", .{}); } } @@ -174,7 +174,7 @@ pub const Progress = struct { self.prev_refresh_timestamp = self.timer.read(); } - pub fn log(self: *Progress, comptime format: []const u8, args: ...) void { + pub fn log(self: *Progress, comptime format: []const u8, args: var) void { const file = self.terminal orelse return; self.refresh(); file.outStream().stream.print(format, args) catch { @@ -184,7 +184,7 @@ pub const Progress = struct { self.columns_written = 0; } - fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: ...) void { + fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: var) void { if (std.fmt.bufPrint(self.output_buffer[end.*..], format, args)) |written| { const amt = written.len; end.* += amt; diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig index 27d3283a3c..03d1e8fe1d 100644 --- a/lib/std/special/build_runner.zig +++ b/lib/std/special/build_runner.zig @@ -26,15 +26,15 @@ pub fn main() !void { _ = arg_it.skip(); const zig_exe = try unwrapArg(arg_it.next(allocator) orelse { - warn("Expected first argument to be path to zig compiler\n"); + warn("Expected first argument to be path to zig compiler\n", .{}); return error.InvalidArgs; }); const build_root = try unwrapArg(arg_it.next(allocator) orelse { - warn("Expected second argument to be build root directory path\n"); + warn("Expected second argument to be build root directory path\n", .{}); return error.InvalidArgs; }); const cache_root = try unwrapArg(arg_it.next(allocator) orelse { - warn("Expected third argument to be cache root directory path\n"); + warn("Expected third argument to be cache root directory path\n", .{}); return error.InvalidArgs; }); @@ -51,7 +51,7 @@ pub fn main() !void { if (mem.startsWith(u8, arg, "-D")) { const option_contents = arg[2..]; if (option_contents.len == 0) { - warn("Expected option name after '-D'\n\n"); + warn("Expected option name after '-D'\n\n", .{}); return usageAndErr(builder, false, stderr_stream); } if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| { @@ -70,18 +70,18 @@ pub fn main() !void { return usage(builder, false, stdout_stream); } else if (mem.eql(u8, arg, "--prefix")) { builder.install_prefix = try unwrapArg(arg_it.next(allocator) orelse { - warn("Expected argument after --prefix\n\n"); + warn("Expected argument after --prefix\n\n", .{}); return usageAndErr(builder, false, stderr_stream); }); } else if (mem.eql(u8, arg, "--search-prefix")) { const search_prefix = try unwrapArg(arg_it.next(allocator) orelse { - warn("Expected argument after --search-prefix\n\n"); + warn("Expected argument after --search-prefix\n\n", .{}); return usageAndErr(builder, false, stderr_stream); }); builder.addSearchPrefix(search_prefix); } else if (mem.eql(u8, arg, "--override-lib-dir")) { builder.override_lib_dir = try unwrapArg(arg_it.next(allocator) orelse { - warn("Expected argument after --override-lib-dir\n\n"); + warn("Expected argument after --override-lib-dir\n\n", .{}); return usageAndErr(builder, false, stderr_stream); }); } else if (mem.eql(u8, arg, "--verbose-tokenize")) { @@ -99,7 +99,7 @@ pub fn main() !void { } else if (mem.eql(u8, arg, "--verbose-cc")) { builder.verbose_cc = true; } else { - warn("Unrecognized argument: {}\n\n", arg); + warn("Unrecognized argument: {}\n\n", .{arg}); return usageAndErr(builder, false, stderr_stream); } } else { @@ -145,15 +145,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { \\ \\Steps: \\ - , builder.zig_exe); + , .{builder.zig_exe}); const allocator = builder.allocator; for (builder.top_level_steps.toSliceConst()) |top_level_step| { const name = if (&top_level_step.step == builder.default_step) - try fmt.allocPrint(allocator, "{} (default)", top_level_step.step.name) + try fmt.allocPrint(allocator, "{} (default)", .{top_level_step.step.name}) else top_level_step.step.name; - try out_stream.print(" {s:22} {}\n", name, top_level_step.description); + try out_stream.print(" {s:22} {}\n", .{ name, top_level_step.description }); } try out_stream.write( @@ -169,12 +169,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { ); if (builder.available_options_list.len == 0) { - try out_stream.print(" (none)\n"); + try out_stream.print(" (none)\n", .{}); } else { for (builder.available_options_list.toSliceConst()) |option| { - const name = try fmt.allocPrint(allocator, " -D{}=[{}]", option.name, Builder.typeIdName(option.type_id)); + const name = try fmt.allocPrint(allocator, " -D{}=[{}]", .{ + option.name, + Builder.typeIdName(option.type_id), + }); defer allocator.free(name); - try out_stream.print("{s:24} {}\n", name, option.description); + try out_stream.print("{s:24} {}\n", .{ name, option.description }); } } @@ -204,7 +207,7 @@ const UnwrapArgError = error{OutOfMemory}; fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 { return arg catch |err| { - warn("Unable to parse command line: {}\n", err); + warn("Unable to parse command line: {}\n", .{err}); return err; }; } diff --git a/lib/std/special/compiler_rt/truncXfYf2_test.zig b/lib/std/special/compiler_rt/truncXfYf2_test.zig index d1dd837ddc..baec2a4450 100644 --- a/lib/std/special/compiler_rt/truncXfYf2_test.zig +++ b/lib/std/special/compiler_rt/truncXfYf2_test.zig @@ -217,7 +217,7 @@ fn test__truncdfsf2(a: f64, expected: u32) void { } } - @import("std").debug.warn("got 0x{x} wanted 0x{x}\n", rep, expected); + @import("std").debug.warn("got 0x{x} wanted 0x{x}\n", .{ rep, expected }); @panic("__trunctfsf2 test failure"); } diff --git a/lib/std/special/init-exe/src/main.zig b/lib/std/special/init-exe/src/main.zig index 128820d3ee..5f35540dc0 100644 --- a/lib/std/special/init-exe/src/main.zig +++ b/lib/std/special/init-exe/src/main.zig @@ -1,5 +1,5 @@ const std = @import("std"); pub fn main() anyerror!void { - std.debug.warn("All your base are belong to us.\n"); + std.debug.warn("All your base are belong to us.\n", .{}); } diff --git a/lib/std/special/start.zig b/lib/std/special/start.zig index d6c6350ff4..b5e4e2edab 100644 --- a/lib/std/special/start.zig +++ b/lib/std/special/start.zig @@ -217,7 +217,7 @@ inline fn initEventLoopAndCallMain() u8 { if (std.event.Loop.instance) |loop| { if (!@hasDecl(root, "event_loop")) { loop.init() catch |err| { - std.debug.warn("error: {}\n", @errorName(err)); + std.debug.warn("error: {}\n", .{@errorName(err)}); if (@errorReturnTrace()) |trace| { std.debug.dumpStackTrace(trace.*); } @@ -264,7 +264,7 @@ fn callMain() u8 { }, .ErrorUnion => { const result = root.main() catch |err| { - std.debug.warn("error: {}\n", @errorName(err)); + std.debug.warn("error: {}\n", .{@errorName(err)}); if (@errorReturnTrace()) |trace| { std.debug.dumpStackTrace(trace.*); } diff --git a/lib/std/special/test_runner.zig b/lib/std/special/test_runner.zig index 4dc8be0fec..7bb53774d3 100644 --- a/lib/std/special/test_runner.zig +++ b/lib/std/special/test_runner.zig @@ -16,28 +16,28 @@ pub fn main() anyerror!void { var test_node = root_node.start(test_fn.name, null); test_node.activate(); progress.refresh(); - if (progress.terminal == null) std.debug.warn("{}/{} {}...", i + 1, test_fn_list.len, test_fn.name); + if (progress.terminal == null) std.debug.warn("{}/{} {}...", .{ i + 1, test_fn_list.len, test_fn.name }); if (test_fn.func()) |_| { ok_count += 1; test_node.end(); - if (progress.terminal == null) std.debug.warn("OK\n"); + if (progress.terminal == null) std.debug.warn("OK\n", .{}); } else |err| switch (err) { error.SkipZigTest => { skip_count += 1; test_node.end(); - progress.log("{}...SKIP\n", test_fn.name); - if (progress.terminal == null) std.debug.warn("SKIP\n"); + progress.log("{}...SKIP\n", .{test_fn.name}); + if (progress.terminal == null) std.debug.warn("SKIP\n", .{}); }, else => { - progress.log(""); + progress.log("", .{}); return err; }, } } root_node.end(); if (ok_count == test_fn_list.len) { - std.debug.warn("All {} tests passed.\n", ok_count); + std.debug.warn("All {} tests passed.\n", .{ok_count}); } else { - std.debug.warn("{} passed; {} skipped.\n", ok_count, skip_count); + std.debug.warn("{} passed; {} skipped.\n", .{ ok_count, skip_count }); } } diff --git a/lib/std/target.zig b/lib/std/target.zig index e4beea4552..aaa19ad609 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -321,14 +321,12 @@ pub const Target = union(enum) { pub const stack_align = 16; pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 { - return std.fmt.allocPrint( - allocator, - "{}{}-{}-{}", + return std.fmt.allocPrint(allocator, "{}{}-{}-{}", .{ @tagName(self.getArch()), Target.archSubArchName(self.getArch()), @tagName(self.getOs()), @tagName(self.getAbi()), - ); + }); } /// Returned slice must be freed by the caller. @@ -372,23 +370,19 @@ pub const Target = union(enum) { } pub fn zigTripleNoSubArch(self: Target, allocator: *mem.Allocator) ![]u8 { - return std.fmt.allocPrint( - allocator, - "{}-{}-{}", + return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ @tagName(self.getArch()), @tagName(self.getOs()), @tagName(self.getAbi()), - ); + }); } pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 { - return std.fmt.allocPrint( - allocator, - "{}-{}-{}", + return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ @tagName(self.getArch()), @tagName(self.getOs()), @tagName(self.getAbi()), - ); + }); } pub fn parse(text: []const u8) !Target { diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 2ed6c66fe6..e808930b60 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -8,13 +8,19 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void { if (actual_error_union) |actual_payload| { // TODO remove workaround here for https://github.com/ziglang/zig/issues/557 if (@sizeOf(@typeOf(actual_payload)) == 0) { - std.debug.panic("expected error.{}, found {} value", @errorName(expected_error), @typeName(@typeOf(actual_payload))); + std.debug.panic("expected error.{}, found {} value", .{ + @errorName(expected_error), + @typeName(@typeOf(actual_payload)), + }); } else { - std.debug.panic("expected error.{}, found {}", @errorName(expected_error), actual_payload); + std.debug.panic("expected error.{}, found {}", .{ @errorName(expected_error), actual_payload }); } } else |actual_error| { if (expected_error != actual_error) { - std.debug.panic("expected error.{}, found error.{}", @errorName(expected_error), @errorName(actual_error)); + std.debug.panic("expected error.{}, found error.{}", .{ + @errorName(expected_error), + @errorName(actual_error), + }); } } } @@ -51,7 +57,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { .ErrorSet, => { if (actual != expected) { - std.debug.panic("expected {}, found {}", expected, actual); + std.debug.panic("expected {}, found {}", .{ expected, actual }); } }, @@ -62,16 +68,16 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { builtin.TypeInfo.Pointer.Size.C, => { if (actual != expected) { - std.debug.panic("expected {*}, found {*}", expected, actual); + std.debug.panic("expected {*}, found {*}", .{ expected, actual }); } }, builtin.TypeInfo.Pointer.Size.Slice => { if (actual.ptr != expected.ptr) { - std.debug.panic("expected slice ptr {}, found {}", expected.ptr, actual.ptr); + std.debug.panic("expected slice ptr {}, found {}", .{ expected.ptr, actual.ptr }); } if (actual.len != expected.len) { - std.debug.panic("expected slice len {}, found {}", expected.len, actual.len); + std.debug.panic("expected slice len {}, found {}", .{ expected.len, actual.len }); } }, } @@ -106,7 +112,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { } // we iterate over *all* union fields - // => we should never get here as the loop above is + // => we should never get here as the loop above is // including all possible values. unreachable; }, @@ -116,11 +122,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { if (actual) |actual_payload| { expectEqual(expected_payload, actual_payload); } else { - std.debug.panic("expected {}, found null", expected_payload); + std.debug.panic("expected {}, found null", .{expected_payload}); } } else { if (actual) |actual_payload| { - std.debug.panic("expected null, found {}", actual_payload); + std.debug.panic("expected null, found {}", .{actual_payload}); } } }, @@ -130,11 +136,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { if (actual) |actual_payload| { expectEqual(expected_payload, actual_payload); } else |actual_err| { - std.debug.panic("expected {}, found {}", expected_payload, actual_err); + std.debug.panic("expected {}, found {}", .{ expected_payload, actual_err }); } } else |expected_err| { if (actual) |actual_payload| { - std.debug.panic("expected {}, found {}", expected_err, actual_payload); + std.debug.panic("expected {}, found {}", .{ expected_err, actual_payload }); } else |actual_err| { expectEqual(expected_err, actual_err); } @@ -143,15 +149,14 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { } } -test "expectEqual.union(enum)" -{ +test "expectEqual.union(enum)" { const T = union(enum) { a: i32, b: f32, }; - const a10 = T { .a = 10 }; - const a20 = T { .a = 20 }; + const a10 = T{ .a = 10 }; + const a20 = T{ .a = 20 }; expectEqual(a10, a10); } @@ -165,12 +170,12 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const // If the child type is u8 and no weird bytes, we could print it as strings // Even for the length difference, it would be useful to see the values of the slices probably. if (expected.len != actual.len) { - std.debug.panic("slice lengths differ. expected {}, found {}", expected.len, actual.len); + std.debug.panic("slice lengths differ. expected {}, found {}", .{ expected.len, actual.len }); } var i: usize = 0; while (i < expected.len) : (i += 1) { if (expected[i] != actual[i]) { - std.debug.panic("index {} incorrect. expected {}, found {}", i, expected[i], actual[i]); + std.debug.panic("index {} incorrect. expected {}, found {}", .{ i, expected[i], actual[i] }); } } } diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig index 4af1b63a69..0352c91f60 100644 --- a/lib/std/unicode.zig +++ b/lib/std/unicode.zig @@ -170,7 +170,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool { /// ``` /// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator(); /// while (utf8.nextCodepointSlice()) |codepoint| { -/// std.debug.warn("got codepoint {}\n", codepoint); +/// std.debug.warn("got codepoint {}\n", .{codepoint}); /// } /// ``` pub const Utf8View = struct { diff --git a/lib/std/unicode/throughput_test.zig b/lib/std/unicode/throughput_test.zig index f76f14b3ac..a9a211d24a 100644 --- a/lib/std/unicode/throughput_test.zig +++ b/lib/std/unicode/throughput_test.zig @@ -24,8 +24,12 @@ pub fn main() !void { const elapsed_ns_better = timer.lap(); @fence(.SeqCst); - std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_orig, elapsed_ns_orig / 1000000); - std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_better, elapsed_ns_better / 1000000); + std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", .{ + elapsed_ns_orig, elapsed_ns_orig / 1000000, + }); + std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", .{ + elapsed_ns_better, elapsed_ns_better / 1000000, + }); asm volatile ("nop" : : [a] "r" (&buffer1), diff --git a/lib/std/valgrind.zig b/lib/std/valgrind.zig index ffdce1b729..fe1eb65b7a 100644 --- a/lib/std/valgrind.zig +++ b/lib/std/valgrind.zig @@ -114,20 +114,6 @@ pub fn innerThreads(qzz: [*]u8) void { doClientRequestStmt(.InnerThreads, qzz, 0, 0, 0, 0); } -//pub fn printf(format: [*]const u8, args: ...) usize { -// return doClientRequestExpr(0, -// .PrintfValistByRef, -// @ptrToInt(format), @ptrToInt(args), -// 0, 0, 0); -//} - -//pub fn printfBacktrace(format: [*]const u8, args: ...) usize { -// return doClientRequestExpr(0, -// .PrintfBacktraceValistByRef, -// @ptrToInt(format), @ptrToInt(args), -// 0, 0, 0); -//} - pub fn nonSIMDCall0(func: fn (usize) usize) usize { return doClientRequestExpr(0, .ClientCall0, @ptrToInt(func), 0, 0, 0, 0); } diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index bedb980463..5fa519aa90 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -301,7 +301,9 @@ pub const Error = union(enum) { node: *Node, pub fn render(self: *const ExpectedCall, tokens: *Tree.TokenList, stream: var) !void { - return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", @tagName(self.node.id)); + return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", .{ + @tagName(self.node.id), + }); } }; @@ -309,7 +311,8 @@ pub const Error = union(enum) { node: *Node, pub fn render(self: *const ExpectedCallOrFnProto, tokens: *Tree.TokenList, stream: var) !void { - return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++ @tagName(Node.Id.FnProto) ++ ", found {}", @tagName(self.node.id)); + return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++ + @tagName(Node.Id.FnProto) ++ ", found {}", .{@tagName(self.node.id)}); } }; @@ -321,14 +324,14 @@ pub const Error = union(enum) { const found_token = tokens.at(self.token); switch (found_token.id) { .Invalid_ampersands => { - return stream.print("`&&` is invalid. Note that `and` is boolean AND."); + return stream.print("`&&` is invalid. Note that `and` is boolean AND.", .{}); }, .Invalid => { - return stream.print("expected '{}', found invalid bytes", self.expected_id.symbol()); + return stream.print("expected '{}', found invalid bytes", .{self.expected_id.symbol()}); }, else => { const token_name = found_token.id.symbol(); - return stream.print("expected '{}', found '{}'", self.expected_id.symbol(), token_name); + return stream.print("expected '{}', found '{}'", .{ self.expected_id.symbol(), token_name }); }, } } @@ -340,7 +343,10 @@ pub const Error = union(enum) { pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void { const actual_token = tokens.at(self.token); - return stream.print("expected ',' or '{}', found '{}'", self.end_id.symbol(), actual_token.id.symbol()); + return stream.print("expected ',' or '{}', found '{}'", .{ + self.end_id.symbol(), + actual_token.id.symbol(), + }); } }; @@ -352,7 +358,7 @@ pub const Error = union(enum) { pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void { const actual_token = tokens.at(self.token); - return stream.print(msg, actual_token.id.symbol()); + return stream.print(msg, .{actual_token.id.symbol()}); } }; } @@ -563,10 +569,10 @@ pub const Node = struct { { var i: usize = 0; while (i < indent) : (i += 1) { - std.debug.warn(" "); + std.debug.warn(" ", .{}); } } - std.debug.warn("{}\n", @tagName(self.id)); + std.debug.warn("{}\n", .{@tagName(self.id)}); var child_i: usize = 0; while (self.iterate(child_i)) |child| : (child_i += 1) { diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 7f3cc3694a..a47e2bdc7e 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -642,15 +642,6 @@ test "zig fmt: fn decl with trailing comma" { ); } -test "zig fmt: var_args with trailing comma" { - try testCanonical( - \\pub fn add( - \\ a: ..., - \\) void {} - \\ - ); -} - test "zig fmt: enum decl with no trailing comma" { try testTransform( \\const StrLitKind = enum {Normal, C}; @@ -1750,13 +1741,6 @@ test "zig fmt: call expression" { ); } -test "zig fmt: var args" { - try testCanonical( - \\fn print(args: ...) void {} - \\ - ); -} - test "zig fmt: var type" { try testCanonical( \\fn print(args: var) var {} @@ -2705,9 +2689,9 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b while (error_it.next()) |parse_error| { const token = tree.tokens.at(parse_error.loc()); const loc = tree.tokenLocation(0, parse_error.loc()); - try stderr.print("(memory buffer):{}:{}: error: ", loc.line + 1, loc.column + 1); + try stderr.print("(memory buffer):{}:{}: error: ", .{ loc.line + 1, loc.column + 1 }); try tree.renderError(parse_error, stderr); - try stderr.print("\n{}\n", source[loc.line_start..loc.line_end]); + try stderr.print("\n{}\n", .{source[loc.line_start..loc.line_end]}); { var i: usize = 0; while (i < loc.column) : (i += 1) { @@ -2743,16 +2727,16 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { var anything_changed: bool = undefined; const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed); if (!mem.eql(u8, result_source, expected_source)) { - warn("\n====== expected this output: =========\n"); - warn("{}", expected_source); - warn("\n======== instead found this: =========\n"); - warn("{}", result_source); - warn("\n======================================\n"); + warn("\n====== expected this output: =========\n", .{}); + warn("{}", .{expected_source}); + warn("\n======== instead found this: =========\n", .{}); + warn("{}", .{result_source}); + warn("\n======================================\n", .{}); return error.TestFailed; } const changes_expected = source.ptr != expected_source.ptr; if (anything_changed != changes_expected) { - warn("std.zig.render returned {} instead of {}\n", anything_changed, changes_expected); + warn("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected }); return error.TestFailed; } std.testing.expect(anything_changed == changes_expected); @@ -2772,12 +2756,14 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) { warn( "\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n", - fail_index, - needed_alloc_count, - failing_allocator.allocated_bytes, - failing_allocator.freed_bytes, - failing_allocator.allocations, - failing_allocator.deallocations, + .{ + fail_index, + needed_alloc_count, + failing_allocator.allocated_bytes, + failing_allocator.freed_bytes, + failing_allocator.allocations, + failing_allocator.deallocations, + }, ); return error.MemoryLeakDetected; } diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 8b0ce7ee1a..09482b5109 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -76,7 +76,7 @@ fn renderRoot( // render all the line comments at the beginning of the file while (tok_it.next()) |token| { if (token.id != .LineComment) break; - try stream.print("{}\n", mem.trimRight(u8, tree.tokenSlicePtr(token), " ")); + try stream.print("{}\n", .{mem.trimRight(u8, tree.tokenSlicePtr(token), " ")}); if (tok_it.peek()) |next_token| { const loc = tree.tokenLocationPtr(token.end, next_token); if (loc.line >= 2) { @@ -1226,7 +1226,7 @@ fn renderExpression( var skip_first_indent = true; if (tree.tokens.at(multiline_str_literal.firstToken() - 1).id != .LineComment) { - try stream.print("\n"); + try stream.print("\n", .{}); skip_first_indent = false; } @@ -2129,7 +2129,7 @@ fn renderTokenOffset( var loc = tree.tokenLocationPtr(token.end, next_token); if (loc.line == 0) { - try stream.print(" {}", mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ")); + try stream.print(" {}", .{mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ")}); offset = 2; token = next_token; next_token = tree.tokens.at(token_index + offset); diff --git a/lib/std/zig/tokenizer.zig b/lib/std/zig/tokenizer.zig index e7d2b41784..93fbfa18a7 100644 --- a/lib/std/zig/tokenizer.zig +++ b/lib/std/zig/tokenizer.zig @@ -330,7 +330,7 @@ pub const Tokenizer = struct { /// For debugging purposes pub fn dump(self: *Tokenizer, token: *const Token) void { - std.debug.warn("{} \"{}\"\n", @tagName(token.id), self.buffer[token.start..token.end]); + std.debug.warn("{} \"{}\"\n", .{ @tagName(token.id), self.buffer[token.start..token.end] }); } pub fn init(buffer: []const u8) Tokenizer { @@ -1576,7 +1576,7 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void { for (expected_tokens) |expected_token_id| { const token = tokenizer.next(); if (token.id != expected_token_id) { - std.debug.panic("expected {}, found {}\n", @tagName(expected_token_id), @tagName(token.id)); + std.debug.panic("expected {}, found {}\n", .{ @tagName(expected_token_id), @tagName(token.id) }); } } const last_token = tokenizer.next(); |
