authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-26 09:48:12+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-02 17:12:57-07:00
logdd973fb365dbbe11ce5beac8b4889bfab3fddc4d
treee82adf746186ec50e1aa11c5bd9f4a677e93046d
parent5a06fdfa5525920810005e73eaa1b6e79a6472ca

std: Use {s} instead of {} when printing strings


32 files changed, 771 insertions(+), 231 deletions(-)

lib/std/SemanticVersion.zig+4-4
......@@ -164,8 +164,8 @@ pub fn format(
164164) !void {
165165 if (fmt.len != 0) @compileError("Unknown format string: '" ++ fmt ++ "'");
166166 try std.fmt.format(out_stream, "{}.{}.{}", .{ self.major, self.minor, self.patch });
167 if (self.pre) |pre| try std.fmt.format(out_stream, "-{}", .{pre});
168 if (self.build) |build| try std.fmt.format(out_stream, "+{}", .{build});
167 if (self.pre) |pre| try std.fmt.format(out_stream, "-{s}", .{pre});
168 if (self.build) |build| try std.fmt.format(out_stream, "+{s}", .{build});
169169}
170170
171171const expect = std.testing.expect;
......@@ -287,9 +287,9 @@ fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) !
287287 if (std.mem.eql(u8, result, expected)) return;
288288
289289 std.debug.warn("\n====== expected this output: =========\n", .{});
290 std.debug.warn("{}", .{expected});
290 std.debug.warn("{s}", .{expected});
291291 std.debug.warn("\n======== instead found this: =========\n", .{});
292 std.debug.warn("{}", .{result});
292 std.debug.warn("{s}", .{result});
293293 std.debug.warn("\n======================================\n", .{});
294294 return error.TestFailed;
295295}
lib/std/array_list_sentineled.zig created+229
......@@ -0,0 +1,229 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2020 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6const std = @import("std.zig");
7const debug = std.debug;
8const mem = std.mem;
9const Allocator = mem.Allocator;
10const assert = debug.assert;
11const testing = std.testing;
12const ArrayList = std.ArrayList;
13
14/// A contiguous, growable list of items in memory, with a sentinel after them.
15/// The sentinel is maintained when appending, resizing, etc.
16/// If you do not need a sentinel, consider using `ArrayList` instead.
17pub fn ArrayListSentineled(comptime T: type, comptime sentinel: T) type {
18 return struct {
19 list: ArrayList(T),
20
21 const Self = @This();
22
23 /// Must deinitialize with deinit.
24 pub fn init(allocator: *Allocator, m: []const T) !Self {
25 var self = try initSize(allocator, m.len);
26 mem.copy(T, self.list.items, m);
27 return self;
28 }
29
30 /// Initialize memory to size bytes of undefined values.
31 /// Must deinitialize with deinit.
32 pub fn initSize(allocator: *Allocator, size: usize) !Self {
33 var self = initNull(allocator);
34 try self.resize(size);
35 return self;
36 }
37
38 /// Initialize with capacity to hold at least num bytes.
39 /// Must deinitialize with deinit.
40 pub fn initCapacity(allocator: *Allocator, num: usize) !Self {
41 var self = Self{ .list = try ArrayList(T).initCapacity(allocator, num + 1) };
42 self.list.appendAssumeCapacity(sentinel);
43 return self;
44 }
45
46 /// Must deinitialize with deinit.
47 /// None of the other operations are valid until you do one of these:
48 /// * `replaceContents`
49 /// * `resize`
50 pub fn initNull(allocator: *Allocator) Self {
51 return Self{ .list = ArrayList(T).init(allocator) };
52 }
53
54 /// Must deinitialize with deinit.
55 pub fn initFromBuffer(buffer: Self) !Self {
56 return Self.init(buffer.list.allocator, buffer.span());
57 }
58
59 /// Takes ownership of the passed in slice. The slice must have been
60 /// allocated with `allocator`.
61 /// Must deinitialize with deinit.
62 pub fn fromOwnedSlice(allocator: *Allocator, slice: []T) !Self {
63 var self = Self{ .list = ArrayList(T).fromOwnedSlice(allocator, slice) };
64 try self.list.append(sentinel);
65 return self;
66 }
67
68 /// The caller owns the returned memory. The list becomes null and is safe to `deinit`.
69 pub fn toOwnedSlice(self: *Self) [:sentinel]T {
70 const allocator = self.list.allocator;
71 const result = self.list.toOwnedSlice();
72 self.* = initNull(allocator);
73 return result[0 .. result.len - 1 :sentinel];
74 }
75
76 /// Only works when `T` is `u8`.
77 pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: anytype) !Self {
78 const size = std.math.cast(usize, std.fmt.count(format, args)) catch |err| switch (err) {
79 error.Overflow => return error.OutOfMemory,
80 };
81 var self = try Self.initSize(allocator, size);
82 assert((std.fmt.bufPrint(self.list.items, format, args) catch unreachable).len == size);
83 return self;
84 }
85
86 pub fn deinit(self: *Self) void {
87 self.list.deinit();
88 }
89
90 pub fn span(self: anytype) @TypeOf(self.list.items[0..:sentinel]) {
91 return self.list.items[0..self.len() :sentinel];
92 }
93
94 pub fn shrink(self: *Self, new_len: usize) void {
95 assert(new_len <= self.len());
96 self.list.shrink(new_len + 1);
97 self.list.items[self.len()] = sentinel;
98 }
99
100 pub fn resize(self: *Self, new_len: usize) !void {
101 try self.list.resize(new_len + 1);
102 self.list.items[self.len()] = sentinel;
103 }
104
105 pub fn isNull(self: Self) bool {
106 return self.list.items.len == 0;
107 }
108
109 pub fn len(self: Self) usize {
110 return self.list.items.len - 1;
111 }
112
113 pub fn capacity(self: Self) usize {
114 return if (self.list.capacity > 0)
115 self.list.capacity - 1
116 else
117 0;
118 }
119
120 pub fn appendSlice(self: *Self, m: []const T) !void {
121 const old_len = self.len();
122 try self.resize(old_len + m.len);
123 mem.copy(T, self.list.items[old_len..], m);
124 }
125
126 pub fn append(self: *Self, byte: T) !void {
127 const old_len = self.len();
128 try self.resize(old_len + 1);
129 self.list.items[old_len] = byte;
130 }
131
132 pub fn eql(self: Self, m: []const T) bool {
133 return mem.eql(T, self.span(), m);
134 }
135
136 pub fn startsWith(self: Self, m: []const T) bool {
137 if (self.len() < m.len) return false;
138 return mem.eql(T, self.list.items[0..m.len], m);
139 }
140
141 pub fn endsWith(self: Self, m: []const T) bool {
142 const l = self.len();
143 if (l < m.len) return false;
144 const start = l - m.len;
145 return mem.eql(T, self.list.items[start..l], m);
146 }
147
148 pub fn replaceContents(self: *Self, m: []const T) !void {
149 try self.resize(m.len);
150 mem.copy(T, self.list.items, m);
151 }
152
153 /// Initializes an OutStream which will append to the list.
154 /// This function may be called only when `T` is `u8`.
155 pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) {
156 return .{ .context = self };
157 }
158
159 /// Same as `append` except it returns the number of bytes written, which is always the same
160 /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API.
161 /// This function may be called only when `T` is `u8`.
162 pub fn appendWrite(self: *Self, m: []const u8) !usize {
163 try self.appendSlice(m);
164 return m.len;
165 }
166 };
167}
168
169test "simple" {
170 var buf = try ArrayListSentineled(u8, 0).init(testing.allocator, "");
171 defer buf.deinit();
172
173 testing.expect(buf.len() == 0);
174 try buf.appendSlice("hello");
175 try buf.appendSlice(" ");
176 try buf.appendSlice("world");
177 testing.expect(buf.eql("hello world"));
178 testing.expect(mem.eql(u8, mem.spanZ(buf.span().ptr), buf.span()));
179
180 var buf2 = try ArrayListSentineled(u8, 0).initFromBuffer(buf);
181 defer buf2.deinit();
182 testing.expect(buf.eql(buf2.span()));
183
184 testing.expect(buf.startsWith("hell"));
185 testing.expect(buf.endsWith("orld"));
186
187 try buf2.resize(4);
188 testing.expect(buf.startsWith(buf2.span()));
189}
190
191test "initSize" {
192 var buf = try ArrayListSentineled(u8, 0).initSize(testing.allocator, 3);
193 defer buf.deinit();
194 testing.expect(buf.len() == 3);
195 try buf.appendSlice("hello");
196 testing.expect(mem.eql(u8, buf.span()[3..], "hello"));
197}
198
199test "initCapacity" {
200 var buf = try ArrayListSentineled(u8, 0).initCapacity(testing.allocator, 10);
201 defer buf.deinit();
202 testing.expect(buf.len() == 0);
203 testing.expect(buf.capacity() >= 10);
204 const old_cap = buf.capacity();
205 try buf.appendSlice("hello");
206 testing.expect(buf.len() == 5);
207 testing.expect(buf.capacity() == old_cap);
208 testing.expect(mem.eql(u8, buf.span(), "hello"));
209}
210
211test "print" {
212 var buf = try ArrayListSentineled(u8, 0).init(testing.allocator, "");
213 defer buf.deinit();
214
215 try buf.outStream().print("Hello {d} the {s}", .{ 2, "world" });
216 testing.expect(buf.eql("Hello 2 the world"));
217}
218
219test "outStream" {
220 var buffer = try ArrayListSentineled(u8, 0).initSize(testing.allocator, 0);
221 defer buffer.deinit();
222 const buf_stream = buffer.outStream();
223
224 const x: i32 = 42;
225 const y: i32 = 1234;
226 try buf_stream.print("x: {}\ny: {}\n", .{ x, y });
227
228 testing.expect(mem.eql(u8, buffer.span(), "x: 42\ny: 1234\n"));
229}
lib/std/build.zig+69-69
......@@ -294,7 +294,7 @@ pub const Builder = struct {
294294 /// To run an executable built with zig build, see `LibExeObjStep.run`.
295295 pub fn addSystemCommand(self: *Builder, argv: []const []const u8) *RunStep {
296296 assert(argv.len >= 1);
297 const run_step = RunStep.create(self, self.fmt("run {}", .{argv[0]}));
297 const run_step = RunStep.create(self, self.fmt("run {s}", .{argv[0]}));
298298 run_step.addArgs(argv);
299299 return run_step;
300300 }
......@@ -409,7 +409,7 @@ pub const Builder = struct {
409409 for (self.installed_files.items) |installed_file| {
410410 const full_path = self.getInstallPath(installed_file.dir, installed_file.path);
411411 if (self.verbose) {
412 warn("rm {}\n", .{full_path});
412 warn("rm {s}\n", .{full_path});
413413 }
414414 fs.cwd().deleteTree(full_path) catch {};
415415 }
......@@ -419,7 +419,7 @@ pub const Builder = struct {
419419
420420 fn makeOneStep(self: *Builder, s: *Step) anyerror!void {
421421 if (s.loop_flag) {
422 warn("Dependency loop detected:\n {}\n", .{s.name});
422 warn("Dependency loop detected:\n {s}\n", .{s.name});
423423 return error.DependencyLoopDetected;
424424 }
425425 s.loop_flag = true;
......@@ -427,7 +427,7 @@ pub const Builder = struct {
427427 for (s.dependencies.items) |dep| {
428428 self.makeOneStep(dep) catch |err| {
429429 if (err == error.DependencyLoopDetected) {
430 warn(" {}\n", .{s.name});
430 warn(" {s}\n", .{s.name});
431431 }
432432 return err;
433433 };
......@@ -444,7 +444,7 @@ pub const Builder = struct {
444444 return &top_level_step.step;
445445 }
446446 }
447 warn("Cannot run step '{}' because it does not exist\n", .{name});
447 warn("Cannot run step '{s}' because it does not exist\n", .{name});
448448 return error.InvalidStepName;
449449 }
450450
......@@ -456,7 +456,7 @@ pub const Builder = struct {
456456 .description = description,
457457 };
458458 if ((self.available_options_map.fetchPut(name, available_option) catch unreachable) != null) {
459 panic("Option '{}' declared twice", .{name});
459 panic("Option '{s}' declared twice", .{name});
460460 }
461461 self.available_options_list.append(available_option) catch unreachable;
462462
......@@ -471,32 +471,32 @@ pub const Builder = struct {
471471 } else if (mem.eql(u8, s, "false")) {
472472 return false;
473473 } else {
474 warn("Expected -D{} to be a boolean, but received '{}'\n\n", .{ name, s });
474 warn("Expected -D{s} to be a boolean, but received '{s}'\n\n", .{ name, s });
475475 self.markInvalidUserInput();
476476 return null;
477477 }
478478 },
479479 .List => {
480 warn("Expected -D{} to be a boolean, but received a list.\n\n", .{name});
480 warn("Expected -D{s} to be a boolean, but received a list.\n\n", .{name});
481481 self.markInvalidUserInput();
482482 return null;
483483 },
484484 },
485485 .Int => switch (entry.value.value) {
486486 .Flag => {
487 warn("Expected -D{} to be an integer, but received a boolean.\n\n", .{name});
487 warn("Expected -D{s} to be an integer, but received a boolean.\n\n", .{name});
488488 self.markInvalidUserInput();
489489 return null;
490490 },
491491 .Scalar => |s| {
492492 const n = std.fmt.parseInt(T, s, 10) catch |err| switch (err) {
493493 error.Overflow => {
494 warn("-D{} value {} cannot fit into type {}.\n\n", .{ name, s, @typeName(T) });
494 warn("-D{s} value {} cannot fit into type {s}.\n\n", .{ name, s, @typeName(T) });
495495 self.markInvalidUserInput();
496496 return null;
497497 },
498498 else => {
499 warn("Expected -D{} to be an integer of type {}.\n\n", .{ name, @typeName(T) });
499 warn("Expected -D{s} to be an integer of type {s}.\n\n", .{ name, @typeName(T) });
500500 self.markInvalidUserInput();
501501 return null;
502502 },
......@@ -504,34 +504,34 @@ pub const Builder = struct {
504504 return n;
505505 },
506506 .List => {
507 warn("Expected -D{} to be an integer, but received a list.\n\n", .{name});
507 warn("Expected -D{s} to be an integer, but received a list.\n\n", .{name});
508508 self.markInvalidUserInput();
509509 return null;
510510 },
511511 },
512512 .Float => switch (entry.value.value) {
513513 .Flag => {
514 warn("Expected -D{} to be a float, but received a boolean.\n\n", .{name});
514 warn("Expected -D{s} to be a float, but received a boolean.\n\n", .{name});
515515 self.markInvalidUserInput();
516516 return null;
517517 },
518518 .Scalar => |s| {
519519 const n = std.fmt.parseFloat(T, s) catch |err| {
520 warn("Expected -D{} to be a float of type {}.\n\n", .{ name, @typeName(T) });
520 warn("Expected -D{s} to be a float of type {s}.\n\n", .{ name, @typeName(T) });
521521 self.markInvalidUserInput();
522522 return null;
523523 };
524524 return n;
525525 },
526526 .List => {
527 warn("Expected -D{} to be a float, but received a list.\n\n", .{name});
527 warn("Expected -D{s} to be a float, but received a list.\n\n", .{name});
528528 self.markInvalidUserInput();
529529 return null;
530530 },
531531 },
532532 .Enum => switch (entry.value.value) {
533533 .Flag => {
534 warn("Expected -D{} to be a string, but received a boolean.\n\n", .{name});
534 warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name});
535535 self.markInvalidUserInput();
536536 return null;
537537 },
......@@ -539,25 +539,25 @@ pub const Builder = struct {
539539 if (std.meta.stringToEnum(T, s)) |enum_lit| {
540540 return enum_lit;
541541 } else {
542 warn("Expected -D{} to be of type {}.\n\n", .{ name, @typeName(T) });
542 warn("Expected -D{s} to be of type {s}.\n\n", .{ name, @typeName(T) });
543543 self.markInvalidUserInput();
544544 return null;
545545 }
546546 },
547547 .List => {
548 warn("Expected -D{} to be a string, but received a list.\n\n", .{name});
548 warn("Expected -D{s} to be a string, but received a list.\n\n", .{name});
549549 self.markInvalidUserInput();
550550 return null;
551551 },
552552 },
553553 .String => switch (entry.value.value) {
554554 .Flag => {
555 warn("Expected -D{} to be a string, but received a boolean.\n\n", .{name});
555 warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name});
556556 self.markInvalidUserInput();
557557 return null;
558558 },
559559 .List => {
560 warn("Expected -D{} to be a string, but received a list.\n\n", .{name});
560 warn("Expected -D{s} to be a string, but received a list.\n\n", .{name});
561561 self.markInvalidUserInput();
562562 return null;
563563 },
......@@ -565,7 +565,7 @@ pub const Builder = struct {
565565 },
566566 .List => switch (entry.value.value) {
567567 .Flag => {
568 warn("Expected -D{} to be a list, but received a boolean.\n\n", .{name});
568 warn("Expected -D{s} to be a list, but received a boolean.\n\n", .{name});
569569 self.markInvalidUserInput();
570570 return null;
571571 },
......@@ -592,7 +592,7 @@ pub const Builder = struct {
592592 if (self.release_mode != null) {
593593 @panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice");
594594 }
595 const description = self.fmt("Create a release build ({})", .{@tagName(mode)});
595 const description = self.fmt("Create a release build ({s})", .{@tagName(mode)});
596596 self.is_release = self.option(bool, "release", description) orelse false;
597597 self.release_mode = if (self.is_release) mode else builtin.Mode.Debug;
598598 }
......@@ -646,12 +646,12 @@ pub const Builder = struct {
646646 .diagnostics = &diags,
647647 }) catch |err| switch (err) {
648648 error.UnknownCpuModel => {
649 warn("Unknown CPU: '{}'\nAvailable CPUs for architecture '{}':\n", .{
649 warn("Unknown CPU: '{s}'\nAvailable CPUs for architecture '{s}':\n", .{
650650 diags.cpu_name.?,
651651 @tagName(diags.arch.?),
652652 });
653653 for (diags.arch.?.allCpuModels()) |cpu| {
654 warn(" {}\n", .{cpu.name});
654 warn(" {s}\n", .{cpu.name});
655655 }
656656 warn("\n", .{});
657657 self.markInvalidUserInput();
......@@ -659,15 +659,15 @@ pub const Builder = struct {
659659 },
660660 error.UnknownCpuFeature => {
661661 warn(
662 \\Unknown CPU feature: '{}'
663 \\Available CPU features for architecture '{}':
662 \\Unknown CPU feature: '{s}'
663 \\Available CPU features for architecture '{s}':
664664 \\
665665 , .{
666666 diags.unknown_feature_name,
667667 @tagName(diags.arch.?),
668668 });
669669 for (diags.arch.?.allFeaturesList()) |feature| {
670 warn(" {}: {}\n", .{ feature.name, feature.description });
670 warn(" {s}: {s}\n", .{ feature.name, feature.description });
671671 }
672672 warn("\n", .{});
673673 self.markInvalidUserInput();
......@@ -675,19 +675,19 @@ pub const Builder = struct {
675675 },
676676 error.UnknownOperatingSystem => {
677677 warn(
678 \\Unknown OS: '{}'
678 \\Unknown OS: '{s}'
679679 \\Available operating systems:
680680 \\
681681 , .{diags.os_name});
682682 inline for (std.meta.fields(std.Target.Os.Tag)) |field| {
683 warn(" {}\n", .{field.name});
683 warn(" {s}\n", .{field.name});
684684 }
685685 warn("\n", .{});
686686 self.markInvalidUserInput();
687687 return args.default_target;
688688 },
689689 else => |e| {
690 warn("Unable to parse target '{}': {}\n\n", .{ triple, @errorName(e) });
690 warn("Unable to parse target '{}': {s}\n\n", .{ triple, @errorName(e) });
691691 self.markInvalidUserInput();
692692 return args.default_target;
693693 },
......@@ -703,12 +703,12 @@ pub const Builder = struct {
703703 break :whitelist_check;
704704 }
705705 }
706 warn("Chosen target '{}' does not match one of the supported targets:\n", .{
706 warn("Chosen target '{s}' does not match one of the supported targets:\n", .{
707707 selected_canonicalized_triple,
708708 });
709709 for (list) |t| {
710710 const t_triple = t.zigTriple(self.allocator) catch unreachable;
711 warn(" {}\n", .{t_triple});
711 warn(" {s}\n", .{t_triple});
712712 }
713713 warn("\n", .{});
714714 self.markInvalidUserInput();
......@@ -752,7 +752,7 @@ pub const Builder = struct {
752752 }) catch unreachable;
753753 },
754754 UserValue.Flag => {
755 warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", .{ name, value, name });
755 warn("Option '-D{s}={s}' conflicts with flag '-D{s}'.\n", .{ name, value, name });
756756 return true;
757757 },
758758 }
......@@ -773,11 +773,11 @@ pub const Builder = struct {
773773 // option already exists
774774 switch (gop.entry.value.value) {
775775 UserValue.Scalar => |s| {
776 warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", .{ name, name, s });
776 warn("Flag '-D{s}' conflicts with option '-D{s}={s}'.\n", .{ name, name, s });
777777 return true;
778778 },
779779 UserValue.List => {
780 warn("Flag '-D{}' conflicts with multiple options of the same name.\n", .{name});
780 warn("Flag '-D{s}' conflicts with multiple options of the same name.\n", .{name});
781781 return true;
782782 },
783783 UserValue.Flag => {},
......@@ -820,7 +820,7 @@ pub const Builder = struct {
820820 while (true) {
821821 const entry = it.next() orelse break;
822822 if (!entry.value.used) {
823 warn("Invalid option: -D{}\n\n", .{entry.key});
823 warn("Invalid option: -D{s}\n\n", .{entry.key});
824824 self.markInvalidUserInput();
825825 }
826826 }
......@@ -833,9 +833,9 @@ pub const Builder = struct {
833833 }
834834
835835 fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
836 if (cwd) |yes_cwd| warn("cd {} && ", .{yes_cwd});
836 if (cwd) |yes_cwd| warn("cd {s} && ", .{yes_cwd});
837837 for (argv) |arg| {
838 warn("{} ", .{arg});
838 warn("{s} ", .{arg});
839839 }
840840 warn("\n", .{});
841841 }
......@@ -852,7 +852,7 @@ pub const Builder = struct {
852852 child.env_map = env_map;
853853
854854 const term = child.spawnAndWait() catch |err| {
855 warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) });
855 warn("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) });
856856 return err;
857857 };
858858
......@@ -875,7 +875,7 @@ pub const Builder = struct {
875875
876876 pub fn makePath(self: *Builder, path: []const u8) !void {
877877 fs.cwd().makePath(self.pathFromRoot(path)) catch |err| {
878 warn("Unable to create path {}: {}\n", .{ path, @errorName(err) });
878 warn("Unable to create path {s}: {s}\n", .{ path, @errorName(err) });
879879 return err;
880880 };
881881 }
......@@ -959,7 +959,7 @@ pub const Builder = struct {
959959
960960 pub fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void {
961961 if (self.verbose) {
962 warn("cp {} {} ", .{ source_path, dest_path });
962 warn("cp {s} {s} ", .{ source_path, dest_path });
963963 }
964964 const cwd = fs.cwd();
965965 const prev_status = try fs.Dir.updateFile(cwd, source_path, cwd, dest_path, .{});
......@@ -988,7 +988,7 @@ pub const Builder = struct {
988988 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
989989 search_prefix,
990990 "bin",
991 self.fmt("{}{}", .{ name, exe_extension }),
991 self.fmt("{s}{s}", .{ name, exe_extension }),
992992 });
993993 return fs.realpathAlloc(self.allocator, full_path) catch continue;
994994 }
......@@ -1002,7 +1002,7 @@ pub const Builder = struct {
10021002 while (it.next()) |path| {
10031003 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
10041004 path,
1005 self.fmt("{}{}", .{ name, exe_extension }),
1005 self.fmt("{s}{s}", .{ name, exe_extension }),
10061006 });
10071007 return fs.realpathAlloc(self.allocator, full_path) catch continue;
10081008 }
......@@ -1015,7 +1015,7 @@ pub const Builder = struct {
10151015 for (paths) |path| {
10161016 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
10171017 path,
1018 self.fmt("{}{}", .{ name, exe_extension }),
1018 self.fmt("{s}{s}", .{ name, exe_extension }),
10191019 });
10201020 return fs.realpathAlloc(self.allocator, full_path) catch continue;
10211021 }
......@@ -1070,19 +1070,19 @@ pub const Builder = struct {
10701070 var code: u8 = undefined;
10711071 return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) {
10721072 error.FileNotFound => {
1073 if (src_step) |s| warn("{}...", .{s.name});
1073 if (src_step) |s| warn("{s}...", .{s.name});
10741074 warn("Unable to spawn the following command: file not found\n", .{});
10751075 printCmd(null, argv);
10761076 std.os.exit(@truncate(u8, code));
10771077 },
10781078 error.ExitCodeFailure => {
1079 if (src_step) |s| warn("{}...", .{s.name});
1080 warn("The following command exited with error code {}:\n", .{code});
1079 if (src_step) |s| warn("{s}...", .{s.name});
1080 warn("The following command exited with error code {d}:\n", .{code});
10811081 printCmd(null, argv);
10821082 std.os.exit(@truncate(u8, code));
10831083 },
10841084 error.ProcessTerminated => {
1085 if (src_step) |s| warn("{}...", .{s.name});
1085 if (src_step) |s| warn("{s}...", .{s.name});
10861086 warn("The following command terminated unexpectedly:\n", .{});
10871087 printCmd(null, argv);
10881088 std.os.exit(@truncate(u8, code));
......@@ -1405,7 +1405,7 @@ pub const LibExeObjStep = struct {
14051405 ver: ?Version,
14061406 ) LibExeObjStep {
14071407 if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {
1408 panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
1408 panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
14091409 }
14101410 var self = LibExeObjStep{
14111411 .strip = false,
......@@ -1421,9 +1421,9 @@ pub const LibExeObjStep = struct {
14211421 .step = Step.init(.LibExeObj, name, builder.allocator, make),
14221422 .version = ver,
14231423 .out_filename = undefined,
1424 .out_h_filename = builder.fmt("{}.h", .{name}),
1424 .out_h_filename = builder.fmt("{s}.h", .{name}),
14251425 .out_lib_filename = undefined,
1426 .out_pdb_filename = builder.fmt("{}.pdb", .{name}),
1426 .out_pdb_filename = builder.fmt("{s}.pdb", .{name}),
14271427 .major_only_filename = undefined,
14281428 .name_only_filename = undefined,
14291429 .packages = ArrayList(Pkg).init(builder.allocator),
......@@ -1529,7 +1529,7 @@ pub const LibExeObjStep = struct {
15291529 // It doesn't have to be native. We catch that if you actually try to run it.
15301530 // Consider that this is declarative; the run step may not be run unless a user
15311531 // option is supplied.
1532 const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", .{exe.step.name}));
1532 const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {s}", .{exe.step.name}));
15331533 run_step.addArtifactArg(exe);
15341534
15351535 if (exe.vcpkg_bin_path) |path| {
......@@ -1680,7 +1680,7 @@ pub const LibExeObjStep = struct {
16801680 } else if (mem.eql(u8, tok, "-pthread")) {
16811681 self.linkLibC();
16821682 } else if (self.builder.verbose) {
1683 warn("Ignoring pkg-config flag '{}'\n", .{tok});
1683 warn("Ignoring pkg-config flag '{s}'\n", .{tok});
16841684 }
16851685 }
16861686 }
......@@ -1926,7 +1926,7 @@ pub const LibExeObjStep = struct {
19261926 },
19271927 else => {},
19281928 }
1929 out.print("pub const {z}: {} = {};\n", .{ name, @typeName(T), value }) catch unreachable;
1929 out.print("pub const {z}: {s} = {};\n", .{ name, @typeName(T), value }) catch unreachable;
19301930 }
19311931
19321932 /// The value is the path in the cache dir.
......@@ -2048,7 +2048,7 @@ pub const LibExeObjStep = struct {
20482048 const builder = self.builder;
20492049
20502050 if (self.root_src == null and self.link_objects.items.len == 0) {
2051 warn("{}: linker needs 1 or more objects to link\n", .{self.step.name});
2051 warn("{s}: linker needs 1 or more objects to link\n", .{self.step.name});
20522052 return error.NeedAnObject;
20532053 }
20542054
......@@ -2156,12 +2156,12 @@ pub const LibExeObjStep = struct {
21562156 // Render build artifact options at the last minute, now that the path is known.
21572157 for (self.build_options_artifact_args.items) |item| {
21582158 const out = self.build_options_contents.writer();
2159 out.print("pub const {}: []const u8 = \"{Z}\";\n", .{ item.name, item.artifact.getOutputPath() }) catch unreachable;
2159 out.print("pub const {s}: []const u8 = \"{Z}\";\n", .{ item.name, item.artifact.getOutputPath() }) catch unreachable;
21602160 }
21612161
21622162 const build_options_file = try fs.path.join(
21632163 builder.allocator,
2164 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) },
2164 &[_][]const u8{ builder.cache_root, builder.fmt("{s}_build_options.zig", .{self.name}) },
21652165 );
21662166 const path_from_root = builder.pathFromRoot(build_options_file);
21672167 try fs.cwd().writeFile(path_from_root, self.build_options_contents.items);
......@@ -2294,16 +2294,16 @@ pub const LibExeObjStep = struct {
22942294 } else {
22952295 var mcpu_buffer = std.ArrayList(u8).init(builder.allocator);
22962296
2297 try mcpu_buffer.outStream().print("-mcpu={}", .{cross.cpu.model.name});
2297 try mcpu_buffer.outStream().print("-mcpu={s}", .{cross.cpu.model.name});
22982298
22992299 for (all_features) |feature, i_usize| {
23002300 const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);
23012301 const in_cpu_set = populated_cpu_features.isEnabled(i);
23022302 const in_actual_set = cross.cpu.features.isEnabled(i);
23032303 if (in_cpu_set and !in_actual_set) {
2304 try mcpu_buffer.outStream().print("-{}", .{feature.name});
2304 try mcpu_buffer.outStream().print("-{s}", .{feature.name});
23052305 } else if (!in_cpu_set and in_actual_set) {
2306 try mcpu_buffer.outStream().print("+{}", .{feature.name});
2306 try mcpu_buffer.outStream().print("+{s}", .{feature.name});
23072307 }
23082308 }
23092309
......@@ -2536,7 +2536,7 @@ pub const InstallArtifactStep = struct {
25362536 const self = builder.allocator.create(Self) catch unreachable;
25372537 self.* = Self{
25382538 .builder = builder,
2539 .step = Step.init(.InstallArtifact, builder.fmt("install {}", .{artifact.step.name}), builder.allocator, make),
2539 .step = Step.init(.InstallArtifact, builder.fmt("install {s}", .{artifact.step.name}), builder.allocator, make),
25402540 .artifact = artifact,
25412541 .dest_dir = artifact.override_dest_dir orelse switch (artifact.kind) {
25422542 .Obj => unreachable,
......@@ -2612,7 +2612,7 @@ pub const InstallFileStep = struct {
26122612 builder.pushInstalledFile(dir, dest_rel_path);
26132613 return InstallFileStep{
26142614 .builder = builder,
2615 .step = Step.init(.InstallFile, builder.fmt("install {}", .{src_path}), builder.allocator, make),
2615 .step = Step.init(.InstallFile, builder.fmt("install {s}", .{src_path}), builder.allocator, make),
26162616 .src_path = src_path,
26172617 .dir = dir,
26182618 .dest_rel_path = dest_rel_path,
......@@ -2646,7 +2646,7 @@ pub const InstallDirStep = struct {
26462646 builder.pushInstalledFile(options.install_dir, options.install_subdir);
26472647 return InstallDirStep{
26482648 .builder = builder,
2649 .step = Step.init(.InstallDir, builder.fmt("install {}/", .{options.source_dir}), builder.allocator, make),
2649 .step = Step.init(.InstallDir, builder.fmt("install {s}/", .{options.source_dir}), builder.allocator, make),
26502650 .options = options,
26512651 };
26522652 }
......@@ -2682,14 +2682,14 @@ pub const LogStep = struct {
26822682 pub fn init(builder: *Builder, data: []const u8) LogStep {
26832683 return LogStep{
26842684 .builder = builder,
2685 .step = Step.init(.Log, builder.fmt("log {}", .{data}), builder.allocator, make),
2685 .step = Step.init(.Log, builder.fmt("log {s}", .{data}), builder.allocator, make),
26862686 .data = data,
26872687 };
26882688 }
26892689
26902690 fn make(step: *Step) anyerror!void {
26912691 const self = @fieldParentPtr(LogStep, "step", step);
2692 warn("{}", .{self.data});
2692 warn("{s}", .{self.data});
26932693 }
26942694};
26952695
......@@ -2701,7 +2701,7 @@ pub const RemoveDirStep = struct {
27012701 pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {
27022702 return RemoveDirStep{
27032703 .builder = builder,
2704 .step = Step.init(.RemoveDir, builder.fmt("RemoveDir {}", .{dir_path}), builder.allocator, make),
2704 .step = Step.init(.RemoveDir, builder.fmt("RemoveDir {s}", .{dir_path}), builder.allocator, make),
27052705 .dir_path = dir_path,
27062706 };
27072707 }
......@@ -2711,7 +2711,7 @@ pub const RemoveDirStep = struct {
27112711
27122712 const full_path = self.builder.pathFromRoot(self.dir_path);
27132713 fs.cwd().deleteTree(full_path) catch |err| {
2714 warn("Unable to remove {}: {}\n", .{ full_path, @errorName(err) });
2714 warn("Unable to remove {s}: {s}\n", .{ full_path, @errorName(err) });
27152715 return err;
27162716 };
27172717 }
......@@ -2799,7 +2799,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
27992799 &[_][]const u8{ out_dir, filename_major_only },
28002800 ) catch unreachable;
28012801 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
2802 warn("Unable to symlink {} -> {}\n", .{ major_only_path, out_basename });
2802 warn("Unable to symlink {s} -> {s}\n", .{ major_only_path, out_basename });
28032803 return err;
28042804 };
28052805 // sym link for libfoo.so to libfoo.so.1
......@@ -2808,7 +2808,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
28082808 &[_][]const u8{ out_dir, filename_name_only },
28092809 ) catch unreachable;
28102810 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
2811 warn("Unable to symlink {} -> {}\n", .{ name_only_path, filename_major_only });
2811 warn("Unable to symlink {s} -> {s}\n", .{ name_only_path, filename_major_only });
28122812 return err;
28132813 };
28142814}
lib/std/build/check_file.zig+2-2
......@@ -45,9 +45,9 @@ pub const CheckFileStep = struct {
4545 warn(
4646 \\
4747 \\========= Expected to find: ===================
48 \\{}
48 \\{s}
4949 \\========= But file does not contain it: =======
50 \\{}
50 \\{s}
5151 \\
5252 , .{ expected_match, contents });
5353 return error.TestFailed;
lib/std/build/emit_raw.zig+1-1
......@@ -189,7 +189,7 @@ pub const InstallRawStep = struct {
189189 pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *Self {
190190 const self = builder.allocator.create(Self) catch unreachable;
191191 self.* = Self{
192 .step = Step.init(.InstallRaw, builder.fmt("install raw binary {}", .{artifact.step.name}), builder.allocator, make),
192 .step = Step.init(.InstallRaw, builder.fmt("install raw binary {s}", .{artifact.step.name}), builder.allocator, make),
193193 .builder = builder,
194194 .artifact = artifact,
195195 .dest_dir = switch (artifact.kind) {
lib/std/build/run.zig+13-13
......@@ -116,7 +116,7 @@ pub const RunStep = struct {
116116 }
117117
118118 if (prev_path) |pp| {
119 const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", .{ pp, search_path });
119 const new_path = self.builder.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path });
120120 env_map.set(key, new_path) catch unreachable;
121121 } else {
122122 env_map.set(key, search_path) catch unreachable;
......@@ -189,7 +189,7 @@ pub const RunStep = struct {
189189 child.stderr_behavior = stdIoActionToBehavior(self.stderr_action);
190190
191191 child.spawn() catch |err| {
192 warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) });
192 warn("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) });
193193 return err;
194194 };
195195
......@@ -216,7 +216,7 @@ pub const RunStep = struct {
216216 }
217217
218218 const term = child.wait() catch |err| {
219 warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) });
219 warn("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) });
220220 return err;
221221 };
222222
......@@ -245,9 +245,9 @@ pub const RunStep = struct {
245245 warn(
246246 \\
247247 \\========= Expected this stderr: =========
248 \\{}
248 \\{s}
249249 \\========= But found: ====================
250 \\{}
250 \\{s}
251251 \\
252252 , .{ expected_bytes, stderr.? });
253253 printCmd(cwd, argv);
......@@ -259,9 +259,9 @@ pub const RunStep = struct {
259259 warn(
260260 \\
261261 \\========= Expected to find in stderr: =========
262 \\{}
262 \\{s}
263263 \\========= But stderr does not contain it: =====
264 \\{}
264 \\{s}
265265 \\
266266 , .{ match, stderr.? });
267267 printCmd(cwd, argv);
......@@ -277,9 +277,9 @@ pub const RunStep = struct {
277277 warn(
278278 \\
279279 \\========= Expected this stdout: =========
280 \\{}
280 \\{s}
281281 \\========= But found: ====================
282 \\{}
282 \\{s}
283283 \\
284284 , .{ expected_bytes, stdout.? });
285285 printCmd(cwd, argv);
......@@ -291,9 +291,9 @@ pub const RunStep = struct {
291291 warn(
292292 \\
293293 \\========= Expected to find in stdout: =========
294 \\{}
294 \\{s}
295295 \\========= But stdout does not contain it: =====
296 \\{}
296 \\{s}
297297 \\
298298 , .{ match, stdout.? });
299299 printCmd(cwd, argv);
......@@ -304,9 +304,9 @@ pub const RunStep = struct {
304304 }
305305
306306 fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
307 if (cwd) |yes_cwd| warn("cd {} && ", .{yes_cwd});
307 if (cwd) |yes_cwd| warn("cd {s} && ", .{yes_cwd});
308308 for (argv) |arg| {
309 warn("{} ", .{arg});
309 warn("{s} ", .{arg});
310310 }
311311 warn("\n", .{});
312312 }
lib/std/build/write_file.zig+2-2
......@@ -80,14 +80,14 @@ pub const WriteFileStep = struct {
8080 });
8181 // TODO replace with something like fs.makePathAndOpenDir
8282 fs.cwd().makePath(self.output_dir) catch |err| {
83 warn("unable to make path {}: {}\n", .{ self.output_dir, @errorName(err) });
83 warn("unable to make path {s}: {s}\n", .{ self.output_dir, @errorName(err) });
8484 return err;
8585 };
8686 var dir = try fs.cwd().openDir(self.output_dir, .{});
8787 defer dir.close();
8888 for (self.files.items) |file| {
8989 dir.writeFile(file.basename, file.bytes) catch |err| {
90 warn("unable to write {} into {}: {}\n", .{
90 warn("unable to write {s} into {s}: {s}\n", .{
9191 file.basename,
9292 self.output_dir,
9393 @errorName(err),
lib/std/builtin.zig+7-7
......@@ -67,12 +67,12 @@ pub const StackTrace = struct {
6767 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
6868 defer arena.deinit();
6969 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
70 return writer.print("\nUnable to print stack trace: Unable to open debug info: {}\n", .{@errorName(err)});
70 return writer.print("\nUnable to print stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
7171 };
7272 const tty_config = std.debug.detectTTYConfig();
7373 try writer.writeAll("\n");
7474 std.debug.writeStackTrace(self, writer, &arena.allocator, debug_info, tty_config) catch |err| {
75 try writer.print("Unable to print stack trace: {}\n", .{@errorName(err)});
75 try writer.print("Unable to print stack trace: {s}\n", .{@errorName(err)});
7676 };
7777 try writer.writeAll("\n");
7878 }
......@@ -529,12 +529,12 @@ pub const Version = struct {
529529 if (fmt.len == 0) {
530530 if (self.patch == 0) {
531531 if (self.minor == 0) {
532 return std.fmt.format(out_stream, "{}", .{self.major});
532 return std.fmt.format(out_stream, "{d}", .{self.major});
533533 } else {
534 return std.fmt.format(out_stream, "{}.{}", .{ self.major, self.minor });
534 return std.fmt.format(out_stream, "{d}.{d}", .{ self.major, self.minor });
535535 }
536536 } else {
537 return std.fmt.format(out_stream, "{}.{}.{}", .{ self.major, self.minor, self.patch });
537 return std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
538538 }
539539 } else {
540540 @compileError("Unknown format string: '" ++ fmt ++ "'");
......@@ -683,7 +683,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
683683 }
684684 },
685685 .wasi => {
686 std.debug.warn("{}", .{msg});
686 std.debug.warn("{s}", .{msg});
687687 std.os.abort();
688688 },
689689 .uefi => {
......@@ -692,7 +692,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
692692 },
693693 else => {
694694 const first_trace_addr = @returnAddress();
695 std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", .{msg});
695 std.debug.panicExtra(error_return_trace, first_trace_addr, "{s}", .{msg});
696696 },
697697 }
698698}
lib/std/c/tokenizer.zig+1-1
......@@ -1552,7 +1552,7 @@ fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
15521552 for (expected_tokens) |expected_token_id| {
15531553 const token = tokenizer.next();
15541554 if (!std.meta.eql(token.id, expected_token_id)) {
1555 std.debug.panic("expected {}, found {}\n", .{ @tagName(expected_token_id), @tagName(token.id) });
1555 std.debug.panic("expected {s}, found {s}\n", .{ @tagName(expected_token_id), @tagName(token.id) });
15561556 }
15571557 }
15581558 const last_token = tokenizer.next();
lib/std/crypto/bcrypt.zig+1-1
......@@ -247,7 +247,7 @@ fn strHashInternal(password: []const u8, rounds_log: u6, salt: [salt_length]u8)
247247 Codec.encode(ct_str[0..], ct[0 .. ct.len - 1]);
248248
249249 var s_buf: [hash_length]u8 = undefined;
250 const s = fmt.bufPrint(s_buf[0..], "$2b${}{}${}{}", .{ rounds_log / 10, rounds_log % 10, salt_str, ct_str }) catch unreachable;
250 const s = fmt.bufPrint(s_buf[0..], "$2b${d}{d}${s}{s}", .{ rounds_log / 10, rounds_log % 10, salt_str, ct_str }) catch unreachable;
251251 debug.assert(s.len == s_buf.len);
252252 return s_buf;
253253}
lib/std/debug.zig+7-7
......@@ -108,11 +108,11 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
108108 return;
109109 }
110110 const debug_info = getSelfDebugInfo() catch |err| {
111 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
111 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
112112 return;
113113 };
114114 writeCurrentStackTrace(stderr, debug_info, detectTTYConfig(), start_addr) catch |err| {
115 stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;
115 stderr.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch return;
116116 return;
117117 };
118118 }
......@@ -129,7 +129,7 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
129129 return;
130130 }
131131 const debug_info = getSelfDebugInfo() catch |err| {
132 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
132 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
133133 return;
134134 };
135135 const tty_config = detectTTYConfig();
......@@ -199,11 +199,11 @@ pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {
199199 return;
200200 }
201201 const debug_info = getSelfDebugInfo() catch |err| {
202 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
202 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
203203 return;
204204 };
205205 writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, detectTTYConfig()) catch |err| {
206 stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;
206 stderr.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch return;
207207 return;
208208 };
209209 }
......@@ -611,7 +611,7 @@ fn printLineInfo(
611611 tty_config.setColor(out_stream, .White);
612612
613613 if (line_info) |*li| {
614 try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column });
614 try out_stream.print("{s}:{d}:{d}", .{ li.file_name, li.line, li.column });
615615 } else {
616616 try out_stream.writeAll("???:?:?");
617617 }
......@@ -619,7 +619,7 @@ fn printLineInfo(
619619 tty_config.setColor(out_stream, .Reset);
620620 try out_stream.writeAll(": ");
621621 tty_config.setColor(out_stream, .Dim);
622 try out_stream.print("0x{x} in {} ({})", .{ address, symbol_name, compile_unit_name });
622 try out_stream.print("0x{x} in {s} ({s})", .{ address, symbol_name, compile_unit_name });
623623 tty_config.setColor(out_stream, .Reset);
624624 try out_stream.writeAll("\n");
625625
lib/std/fifo.zig+1-1
......@@ -466,7 +466,7 @@ test "LinearFifo(u8, .Dynamic)" {
466466 fifo.shrink(0);
467467
468468 {
469 try fifo.writer().print("{}, {}!", .{ "Hello", "World" });
469 try fifo.writer().print("{s}, {s}!", .{ "Hello", "World" });
470470 var result: [30]u8 = undefined;
471471 testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
472472 testing.expectEqual(@as(usize, 0), fifo.readableLength());
lib/std/fmt.zig+24-24
......@@ -506,12 +506,12 @@ pub fn formatType(
506506 if (info.child == u8) {
507507 return formatText(value, fmt, options, writer);
508508 }
509 return format(writer, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) });
509 return format(writer, "{s}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) });
510510 },
511511 .Enum, .Union, .Struct => {
512512 return formatType(value.*, fmt, options, writer, max_depth);
513513 },
514 else => return format(writer, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) }),
514 else => return format(writer, "{s}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) }),
515515 },
516516 .Many, .C => {
517517 if (ptr_info.sentinel) |sentinel| {
......@@ -522,7 +522,7 @@ pub fn formatType(
522522 return formatText(mem.span(value), fmt, options, writer);
523523 }
524524 }
525 return format(writer, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) });
525 return format(writer, "{s}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) });
526526 },
527527 .Slice => {
528528 if (max_depth == 0) {
......@@ -573,7 +573,7 @@ pub fn formatType(
573573 try writer.writeAll(" }");
574574 },
575575 .Fn => {
576 return format(writer, "{}@{x}", .{ @typeName(T), @ptrToInt(value) });
576 return format(writer, "{s}@{x}", .{ @typeName(T), @ptrToInt(value) });
577577 },
578578 .Type => return formatBuf(@typeName(value), options, writer),
579579 .EnumLiteral => {
......@@ -695,7 +695,7 @@ pub fn formatText(
695695 options: FormatOptions,
696696 writer: anytype,
697697) !void {
698 if (comptime std.mem.eql(u8, fmt, "s") or (fmt.len == 0)) {
698 if (comptime std.mem.eql(u8, fmt, "s")) {
699699 return formatBuf(bytes, options, writer);
700700 } else if (comptime (std.mem.eql(u8, fmt, "x") or std.mem.eql(u8, fmt, "X"))) {
701701 for (bytes) |c| {
......@@ -1559,8 +1559,8 @@ test "buffer" {
15591559test "array" {
15601560 {
15611561 const value: [3]u8 = "abc".*;
1562 try testFmt("array: abc\n", "array: {}\n", .{value});
1563 try testFmt("array: abc\n", "array: {}\n", .{&value});
1562 try testFmt("array: abc\n", "array: {s}\n", .{value});
1563 try testFmt("array: abc\n", "array: {s}\n", .{&value});
15641564 try testFmt("array: { 97, 98, 99 }\n", "array: {d}\n", .{value});
15651565
15661566 var buf: [100]u8 = undefined;
......@@ -1575,7 +1575,7 @@ test "array" {
15751575test "slice" {
15761576 {
15771577 const value: []const u8 = "abc";
1578 try testFmt("slice: abc\n", "slice: {}\n", .{value});
1578 try testFmt("slice: abc\n", "slice: {s}\n", .{value});
15791579 }
15801580 {
15811581 var runtime_zero: usize = 0;
......@@ -1902,9 +1902,9 @@ fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) !
19021902 if (mem.eql(u8, result, expected)) return;
19031903
19041904 std.debug.warn("\n====== expected this output: =========\n", .{});
1905 std.debug.warn("{}", .{expected});
1905 std.debug.warn("{s}", .{expected});
19061906 std.debug.warn("\n======== instead found this: =========\n", .{});
1907 std.debug.warn("{}", .{result});
1907 std.debug.warn("{s}", .{result});
19081908 std.debug.warn("\n======================================\n", .{});
19091909 return error.TestFailed;
19101910}
......@@ -2061,24 +2061,24 @@ test "vector" {
20612061}
20622062
20632063test "enum-literal" {
2064 try testFmt(".hello_world", "{}", .{.hello_world});
2064 try testFmt(".hello_world", "{s}", .{.hello_world});
20652065}
20662066
20672067test "padding" {
2068 try testFmt("Simple", "{}", .{"Simple"});
2068 try testFmt("Simple", "{s}", .{"Simple"});
20692069 try testFmt(" true", "{:10}", .{true});
20702070 try testFmt(" true", "{:>10}", .{true});
20712071 try testFmt("======true", "{:=>10}", .{true});
20722072 try testFmt("true======", "{:=<10}", .{true});
20732073 try testFmt(" true ", "{:^10}", .{true});
20742074 try testFmt("===true===", "{:=^10}", .{true});
2075 try testFmt(" Minimum width", "{:18} width", .{"Minimum"});
2076 try testFmt("==================Filled", "{:=>24}", .{"Filled"});
2077 try testFmt(" Centered ", "{:^24}", .{"Centered"});
2078 try testFmt("-", "{:-^1}", .{""});
2079 try testFmt("==crêpe===", "{:=^10}", .{"crêpe"});
2080 try testFmt("=====crêpe", "{:=>10}", .{"crêpe"});
2081 try testFmt("crêpe=====", "{:=<10}", .{"crêpe"});
2075 try testFmt(" Minimum width", "{s:18} width", .{"Minimum"});
2076 try testFmt("==================Filled", "{s:=>24}", .{"Filled"});
2077 try testFmt(" Centered ", "{s:^24}", .{"Centered"});
2078 try testFmt("-", "{s:-^1}", .{""});
2079 try testFmt("==crêpe===", "{s:=^10}", .{"crêpe"});
2080 try testFmt("=====crêpe", "{s:=>10}", .{"crêpe"});
2081 try testFmt("crêpe=====", "{s:=<10}", .{"crêpe"});
20822082}
20832083
20842084test "decimal float padding" {
......@@ -2107,15 +2107,15 @@ test "type" {
21072107}
21082108
21092109test "named arguments" {
2110 try testFmt("hello world!", "{} world{c}", .{ "hello", '!' });
2111 try testFmt("hello world!", "{[greeting]} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });
2112 try testFmt("hello world!", "{[1]} world{[0]c}", .{ '!', "hello" });
2110 try testFmt("hello world!", "{s} world{c}", .{ "hello", '!' });
2111 try testFmt("hello world!", "{[greeting]s} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });
2112 try testFmt("hello world!", "{[1]s} world{[0]c}", .{ '!', "hello" });
21132113}
21142114
21152115test "runtime width specifier" {
21162116 var width: usize = 9;
2117 try testFmt("~~hello~~", "{:~^[1]}", .{ "hello", width });
2118 try testFmt("~~hello~~", "{:~^[width]}", .{ .string = "hello", .width = width });
2117 try testFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });
2118 try testFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });
21192119}
21202120
21212121test "runtime precision specifier" {
lib/std/heap/general_purpose_allocator.zig+4-4
......@@ -314,7 +314,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
314314 if (is_used) {
315315 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);
316316 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
317 log.err("Memory leak detected: {}", .{stack_trace});
317 log.err("Memory leak detected: {s}", .{stack_trace});
318318 leaks = true;
319319 }
320320 if (bit_index == math.maxInt(u3))
......@@ -342,7 +342,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
342342 }
343343 var it = self.large_allocations.iterator();
344344 while (it.next()) |large_alloc| {
345 log.err("Memory leak detected: {}", .{large_alloc.value.getStackTrace()});
345 log.err("Memory leak detected: {s}", .{large_alloc.value.getStackTrace()});
346346 leaks = true;
347347 }
348348 return leaks;
......@@ -443,7 +443,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
443443 .index = 0,
444444 };
445445 std.debug.captureStackTrace(ret_addr, &free_stack_trace);
446 log.err("Allocation size {} bytes does not match free size {}. Allocation: {} Free: {}", .{
446 log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {s} Free: {s}", .{
447447 entry.value.bytes.len,
448448 old_mem.len,
449449 entry.value.getStackTrace(),
......@@ -526,7 +526,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
526526 .index = 0,
527527 };
528528 std.debug.captureStackTrace(ret_addr, &second_free_stack_trace);
529 log.err("Double free detected. Allocation: {} First free: {} Second free: {}", .{
529 log.err("Double free detected. Allocation: {s} First free: {s} Second free: {s}", .{
530530 alloc_stack_trace,
531531 free_stack_trace,
532532 second_free_stack_trace,
lib/std/io/fixed_buffer_stream.zig+1-1
......@@ -147,7 +147,7 @@ test "FixedBufferStream output" {
147147 var fbs = fixedBufferStream(&buf);
148148 const stream = fbs.writer();
149149
150 try stream.print("{}{}!", .{ "Hello", "World" });
150 try stream.print("{s}{s}!", .{ "Hello", "World" });
151151 testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
152152}
153153
lib/std/json.zig+4-4
......@@ -2642,9 +2642,9 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions
26422642 if (self.expected_remaining.len < bytes.len) {
26432643 std.debug.warn(
26442644 \\====== expected this output: =========
2645 \\{}
2645 \\{s}
26462646 \\======== instead found this: =========
2647 \\{}
2647 \\{s}
26482648 \\======================================
26492649 , .{
26502650 self.expected_remaining,
......@@ -2655,9 +2655,9 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions
26552655 if (!mem.eql(u8, self.expected_remaining[0..bytes.len], bytes)) {
26562656 std.debug.warn(
26572657 \\====== expected this output: =========
2658 \\{}
2658 \\{s}
26592659 \\======== instead found this: =========
2660 \\{}
2660 \\{s}
26612661 \\======================================
26622662 , .{
26632663 self.expected_remaining[0..bytes.len],
lib/std/net.zig+1-1
......@@ -154,7 +154,7 @@ pub const Address = extern union {
154154 unreachable;
155155 }
156156
157 try std.fmt.format(out_stream, "{}", .{&self.un.path});
157 try std.fmt.format(out_stream, "{s}", .{&self.un.path});
158158 },
159159 else => unreachable,
160160 }
lib/std/os/windows.zig+1-1
......@@ -1618,7 +1618,7 @@ pub fn unexpectedError(err: Win32Error) std.os.UnexpectedError {
16181618 null,
16191619 );
16201620 _ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable;
1621 std.debug.warn("error.Unexpected: GetLastError({}): {}\n", .{ @enumToInt(err), buf_u8[0..len] });
1621 std.debug.warn("error.Unexpected: GetLastError({}): {s}\n", .{ @enumToInt(err), buf_u8[0..len] });
16221622 std.debug.dumpCurrentStackTrace(null);
16231623 }
16241624 return error.Unexpected;
lib/std/process.zig+1-1
......@@ -596,7 +596,7 @@ fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []con
596596 for (expected_args) |expected_arg| {
597597 const arg = it.next(std.testing.allocator).? catch unreachable;
598598 defer std.testing.allocator.free(arg);
599 testing.expectEqualSlices(u8, expected_arg, arg);
599 testing.expectEqualStrings(expected_arg, arg);
600600 }
601601 testing.expect(it.next(std.testing.allocator) == null);
602602}
lib/std/progress.zig created+310
......@@ -0,0 +1,310 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2020 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6const std = @import("std");
7const windows = std.os.windows;
8const testing = std.testing;
9const assert = std.debug.assert;
10
11/// This API is non-allocating and non-fallible. The tradeoff is that users of
12/// this API must provide the storage for each `Progress.Node`.
13/// Initialize the struct directly, overriding these fields as desired:
14/// * `refresh_rate_ms`
15/// * `initial_delay_ms`
16pub const Progress = struct {
17 /// `null` if the current node (and its children) should
18 /// not print on update()
19 terminal: ?std.fs.File = undefined,
20
21 /// Whether the terminal supports ANSI escape codes.
22 supports_ansi_escape_codes: bool = false,
23
24 root: Node = undefined,
25
26 /// Keeps track of how much time has passed since the beginning.
27 /// Used to compare with `initial_delay_ms` and `refresh_rate_ms`.
28 timer: std.time.Timer = undefined,
29
30 /// When the previous refresh was written to the terminal.
31 /// Used to compare with `refresh_rate_ms`.
32 prev_refresh_timestamp: u64 = undefined,
33
34 /// This buffer represents the maximum number of bytes written to the terminal
35 /// with each refresh.
36 output_buffer: [100]u8 = undefined,
37
38 /// How many nanoseconds between writing updates to the terminal.
39 refresh_rate_ns: u64 = 50 * std.time.ns_per_ms,
40
41 /// How many nanoseconds to keep the output hidden
42 initial_delay_ns: u64 = 500 * std.time.ns_per_ms,
43
44 done: bool = true,
45
46 /// Keeps track of how many columns in the terminal have been output, so that
47 /// we can move the cursor back later.
48 columns_written: usize = undefined,
49
50 /// Represents one unit of progress. Each node can have children nodes, or
51 /// one can use integers with `update`.
52 pub const Node = struct {
53 context: *Progress,
54 parent: ?*Node,
55 completed_items: usize,
56 name: []const u8,
57 recently_updated_child: ?*Node = null,
58
59 /// This field may be updated freely.
60 estimated_total_items: ?usize,
61
62 /// Create a new child progress node.
63 /// Call `Node.end` when done.
64 /// TODO solve https://github.com/ziglang/zig/issues/2765 and then change this
65 /// API to set `self.parent.recently_updated_child` with the return value.
66 /// Until that is fixed you probably want to call `activate` on the return value.
67 pub fn start(self: *Node, name: []const u8, estimated_total_items: ?usize) Node {
68 return Node{
69 .context = self.context,
70 .parent = self,
71 .completed_items = 0,
72 .name = name,
73 .estimated_total_items = estimated_total_items,
74 };
75 }
76
77 /// This is the same as calling `start` and then `end` on the returned `Node`.
78 pub fn completeOne(self: *Node) void {
79 if (self.parent) |parent| parent.recently_updated_child = self;
80 self.completed_items += 1;
81 self.context.maybeRefresh();
82 }
83
84 pub fn end(self: *Node) void {
85 self.context.maybeRefresh();
86 if (self.parent) |parent| {
87 if (parent.recently_updated_child) |parent_child| {
88 if (parent_child == self) {
89 parent.recently_updated_child = null;
90 }
91 }
92 parent.completeOne();
93 } else {
94 self.context.done = true;
95 self.context.refresh();
96 }
97 }
98
99 /// Tell the parent node that this node is actively being worked on.
100 pub fn activate(self: *Node) void {
101 if (self.parent) |parent| parent.recently_updated_child = self;
102 }
103 };
104
105 /// Create a new progress node.
106 /// Call `Node.end` when done.
107 /// TODO solve https://github.com/ziglang/zig/issues/2765 and then change this
108 /// API to return Progress rather than accept it as a parameter.
109 pub fn start(self: *Progress, name: []const u8, estimated_total_items: ?usize) !*Node {
110 const stderr = std.io.getStdErr();
111 self.terminal = null;
112 if (stderr.supportsAnsiEscapeCodes()) {
113 self.terminal = stderr;
114 self.supports_ansi_escape_codes = true;
115 } else if (std.builtin.os.tag == .windows and stderr.isTty()) {
116 self.terminal = stderr;
117 }
118 self.root = Node{
119 .context = self,
120 .parent = null,
121 .completed_items = 0,
122 .name = name,
123 .estimated_total_items = estimated_total_items,
124 };
125 self.columns_written = 0;
126 self.prev_refresh_timestamp = 0;
127 self.timer = try std.time.Timer.start();
128 self.done = false;
129 return &self.root;
130 }
131
132 /// Updates the terminal if enough time has passed since last update.
133 pub fn maybeRefresh(self: *Progress) void {
134 const now = self.timer.read();
135 if (now < self.initial_delay_ns) return;
136 if (now - self.prev_refresh_timestamp < self.refresh_rate_ns) return;
137 self.refresh();
138 }
139
140 /// Updates the terminal and resets `self.next_refresh_timestamp`.
141 pub fn refresh(self: *Progress) void {
142 const file = self.terminal orelse return;
143
144 const prev_columns_written = self.columns_written;
145 var end: usize = 0;
146 if (self.columns_written > 0) {
147 // restore the cursor position by moving the cursor
148 // `columns_written` cells to the left, then clear the rest of the
149 // line
150 if (self.supports_ansi_escape_codes) {
151 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{d}D", .{self.columns_written}) catch unreachable).len;
152 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len;
153 } else if (std.builtin.os.tag == .windows) winapi: {
154 var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
155 if (windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != windows.TRUE)
156 unreachable;
157
158 var cursor_pos = windows.COORD{
159 .X = info.dwCursorPosition.X - @intCast(windows.SHORT, self.columns_written),
160 .Y = info.dwCursorPosition.Y,
161 };
162
163 if (cursor_pos.X < 0)
164 cursor_pos.X = 0;
165
166 const fill_chars = @intCast(windows.DWORD, info.dwSize.X - cursor_pos.X);
167
168 var written: windows.DWORD = undefined;
169 if (windows.kernel32.FillConsoleOutputAttribute(
170 file.handle,
171 info.wAttributes,
172 fill_chars,
173 cursor_pos,
174 &written,
175 ) != windows.TRUE) {
176 // Stop trying to write to this file.
177 self.terminal = null;
178 break :winapi;
179 }
180 if (windows.kernel32.FillConsoleOutputCharacterA(
181 file.handle,
182 ' ',
183 fill_chars,
184 cursor_pos,
185 &written,
186 ) != windows.TRUE) unreachable;
187
188 if (windows.kernel32.SetConsoleCursorPosition(file.handle, cursor_pos) != windows.TRUE)
189 unreachable;
190 } else unreachable;
191
192 self.columns_written = 0;
193 }
194
195 if (!self.done) {
196 var need_ellipse = false;
197 var maybe_node: ?*Node = &self.root;
198 while (maybe_node) |node| {
199 if (need_ellipse) {
200 self.bufWrite(&end, "... ", .{});
201 }
202 need_ellipse = false;
203 if (node.name.len != 0 or node.estimated_total_items != null) {
204 if (node.name.len != 0) {
205 self.bufWrite(&end, "{s}", .{node.name});
206 need_ellipse = true;
207 }
208 if (node.estimated_total_items) |total| {
209 if (need_ellipse) self.bufWrite(&end, " ", .{});
210 self.bufWrite(&end, "[{d}/{d}] ", .{ node.completed_items + 1, total });
211 need_ellipse = false;
212 } else if (node.completed_items != 0) {
213 if (need_ellipse) self.bufWrite(&end, " ", .{});
214 self.bufWrite(&end, "[{d}] ", .{node.completed_items + 1});
215 need_ellipse = false;
216 }
217 }
218 maybe_node = node.recently_updated_child;
219 }
220 if (need_ellipse) {
221 self.bufWrite(&end, "... ", .{});
222 }
223 }
224
225 _ = file.write(self.output_buffer[0..end]) catch |e| {
226 // Stop trying to write to this file once it errors.
227 self.terminal = null;
228 };
229 self.prev_refresh_timestamp = self.timer.read();
230 }
231
232 pub fn log(self: *Progress, comptime format: []const u8, args: anytype) void {
233 const file = self.terminal orelse return;
234 self.refresh();
235 file.outStream().print(format, args) catch {
236 self.terminal = null;
237 return;
238 };
239 self.columns_written = 0;
240 }
241
242 fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: anytype) void {
243 if (std.fmt.bufPrint(self.output_buffer[end.*..], format, args)) |written| {
244 const amt = written.len;
245 end.* += amt;
246 self.columns_written += amt;
247 } else |err| switch (err) {
248 error.NoSpaceLeft => {
249 self.columns_written += self.output_buffer.len - end.*;
250 end.* = self.output_buffer.len;
251 },
252 }
253 const bytes_needed_for_esc_codes_at_end = if (std.builtin.os.tag == .windows) 0 else 11;
254 const max_end = self.output_buffer.len - bytes_needed_for_esc_codes_at_end;
255 if (end.* > max_end) {
256 const suffix = "... ";
257 self.columns_written = self.columns_written - (end.* - max_end) + suffix.len;
258 std.mem.copy(u8, self.output_buffer[max_end..], suffix);
259 end.* = max_end + suffix.len;
260 }
261 }
262};
263
264test "basic functionality" {
265 var disable = true;
266 if (disable) {
267 // This test is disabled because it uses time.sleep() and is therefore slow. It also
268 // prints bogus progress data to stderr.
269 return error.SkipZigTest;
270 }
271 var progress = Progress{};
272 const root_node = try progress.start("", 100);
273 defer root_node.end();
274
275 const sub_task_names = [_][]const u8{
276 "reticulating splines",
277 "adjusting shoes",
278 "climbing towers",
279 "pouring juice",
280 };
281 var next_sub_task: usize = 0;
282
283 var i: usize = 0;
284 while (i < 100) : (i += 1) {
285 var node = root_node.start(sub_task_names[next_sub_task], 5);
286 node.activate();
287 next_sub_task = (next_sub_task + 1) % sub_task_names.len;
288
289 node.completeOne();
290 std.time.sleep(5 * std.time.ns_per_ms);
291 node.completeOne();
292 node.completeOne();
293 std.time.sleep(5 * std.time.ns_per_ms);
294 node.completeOne();
295 node.completeOne();
296 std.time.sleep(5 * std.time.ns_per_ms);
297
298 node.end();
299
300 std.time.sleep(5 * std.time.ns_per_ms);
301 }
302 {
303 var node = root_node.start("this is a really long name designed to activate the truncation code. let's find out if it works", null);
304 node.activate();
305 std.time.sleep(10 * std.time.ns_per_ms);
306 progress.refresh();
307 std.time.sleep(10 * std.time.ns_per_ms);
308 node.end();
309 }
310}
lib/std/special/test_runner.zig+8-8
......@@ -48,7 +48,7 @@ pub fn main() anyerror!void {
4848 test_node.activate();
4949 progress.refresh();
5050 if (progress.terminal == null) {
51 std.debug.print("{}/{} {}... ", .{ i + 1, test_fn_list.len, test_fn.name });
51 std.debug.print("{d}/{d} {s}... ", .{ i + 1, test_fn_list.len, test_fn.name });
5252 }
5353 const result = if (test_fn.async_frame_size) |size| switch (io_mode) {
5454 .evented => blk: {
......@@ -62,7 +62,7 @@ pub fn main() anyerror!void {
6262 .blocking => {
6363 skip_count += 1;
6464 test_node.end();
65 progress.log("{}...SKIP (async test)\n", .{test_fn.name});
65 progress.log("{s}...SKIP (async test)\n", .{test_fn.name});
6666 if (progress.terminal == null) std.debug.print("SKIP (async test)\n", .{});
6767 continue;
6868 },
......@@ -75,7 +75,7 @@ pub fn main() anyerror!void {
7575 error.SkipZigTest => {
7676 skip_count += 1;
7777 test_node.end();
78 progress.log("{}...SKIP\n", .{test_fn.name});
78 progress.log("{s}...SKIP\n", .{test_fn.name});
7979 if (progress.terminal == null) std.debug.print("SKIP\n", .{});
8080 },
8181 else => {
......@@ -86,15 +86,15 @@ pub fn main() anyerror!void {
8686 }
8787 root_node.end();
8888 if (ok_count == test_fn_list.len) {
89 std.debug.print("All {} tests passed.\n", .{ok_count});
89 std.debug.print("All {d} tests passed.\n", .{ok_count});
9090 } else {
91 std.debug.print("{} passed; {} skipped.\n", .{ ok_count, skip_count });
91 std.debug.print("{d} passed; {d} skipped.\n", .{ ok_count, skip_count });
9292 }
9393 if (log_err_count != 0) {
94 std.debug.print("{} errors were logged.\n", .{log_err_count});
94 std.debug.print("{d} errors were logged.\n", .{log_err_count});
9595 }
9696 if (leaks != 0) {
97 std.debug.print("{} tests leaked memory.\n", .{leaks});
97 std.debug.print("{d} tests leaked memory.\n", .{leaks});
9898 }
9999 if (leaks != 0 or log_err_count != 0) {
100100 std.process.exit(1);
......@@ -111,6 +111,6 @@ pub fn log(
111111 log_err_count += 1;
112112 }
113113 if (@enumToInt(message_level) <= @enumToInt(std.testing.log_level)) {
114 std.debug.print("[{}] ({}): " ++ format ++ "\n", .{ @tagName(scope), @tagName(message_level) } ++ args);
114 std.debug.print("[{s}] ({s}): " ++ format ++ "\n", .{ @tagName(scope), @tagName(message_level) } ++ args);
115115 }
116116}
lib/std/start.zig+3-3
......@@ -266,7 +266,7 @@ inline fn initEventLoopAndCallMain() u8 {
266266 if (std.event.Loop.instance) |loop| {
267267 if (!@hasDecl(root, "event_loop")) {
268268 loop.init() catch |err| {
269 std.log.err("{}", .{@errorName(err)});
269 std.log.err("{s}", .{@errorName(err)});
270270 if (@errorReturnTrace()) |trace| {
271271 std.debug.dumpStackTrace(trace.*);
272272 }
......@@ -295,7 +295,7 @@ inline fn initEventLoopAndCallWinMain() std.os.windows.INT {
295295 if (std.event.Loop.instance) |loop| {
296296 if (!@hasDecl(root, "event_loop")) {
297297 loop.init() catch |err| {
298 std.log.err("{}", .{@errorName(err)});
298 std.log.err("{s}", .{@errorName(err)});
299299 if (@errorReturnTrace()) |trace| {
300300 std.debug.dumpStackTrace(trace.*);
301301 }
......@@ -343,7 +343,7 @@ pub fn callMain() u8 {
343343 },
344344 .ErrorUnion => {
345345 const result = root.main() catch |err| {
346 std.log.err("{}", .{@errorName(err)});
346 std.log.err("{s}", .{@errorName(err)});
347347 if (@errorReturnTrace()) |trace| {
348348 std.debug.dumpStackTrace(trace.*);
349349 }
lib/std/target.zig+6-6
......@@ -136,14 +136,14 @@ pub const Target = struct {
136136 ) !void {
137137 if (fmt.len > 0 and fmt[0] == 's') {
138138 if (@enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.latest)) {
139 try std.fmt.format(out_stream, ".{}", .{@tagName(self)});
139 try std.fmt.format(out_stream, ".{s}", .{@tagName(self)});
140140 } else {
141141 // TODO this code path breaks zig triples, but it is used in `builtin`
142142 try std.fmt.format(out_stream, "@intToEnum(Target.Os.WindowsVersion, 0x{X:0>8})", .{@enumToInt(self)});
143143 }
144144 } else {
145145 if (@enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.latest)) {
146 try std.fmt.format(out_stream, "WindowsVersion.{}", .{@tagName(self)});
146 try std.fmt.format(out_stream, "WindowsVersion.{s}", .{@tagName(self)});
147147 } else {
148148 try std.fmt.format(out_stream, "WindowsVersion(0x{X:0>8})", .{@enumToInt(self)});
149149 }
......@@ -1177,7 +1177,7 @@ pub const Target = struct {
11771177 }
11781178
11791179 pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 {
1180 return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) });
1180 return std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) });
11811181 }
11821182
11831183 pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
......@@ -1381,7 +1381,7 @@ pub const Target = struct {
13811381
13821382 if (self.abi == .android) {
13831383 const suffix = if (self.cpu.arch.ptrBitWidth() == 64) "64" else "";
1384 return print(&result, "/system/bin/linker{}", .{suffix});
1384 return print(&result, "/system/bin/linker{s}", .{suffix});
13851385 }
13861386
13871387 if (self.abi.isMusl()) {
......@@ -1395,7 +1395,7 @@ pub const Target = struct {
13951395 else => |arch| @tagName(arch),
13961396 };
13971397 const arch_suffix = if (is_arm and self.abi.floatAbi() == .hard) "hf" else "";
1398 return print(&result, "/lib/ld-musl-{}{}.so.1", .{ arch_part, arch_suffix });
1398 return print(&result, "/lib/ld-musl-{s}{s}.so.1", .{ arch_part, arch_suffix });
13991399 }
14001400
14011401 switch (self.os.tag) {
......@@ -1434,7 +1434,7 @@ pub const Target = struct {
14341434 };
14351435 const is_nan_2008 = mips.featureSetHas(self.cpu.features, .nan2008);
14361436 const loader = if (is_nan_2008) "ld-linux-mipsn8.so.1" else "ld.so.1";
1437 return print(&result, "/lib{}/{}", .{ lib_suffix, loader });
1437 return print(&result, "/lib{s}/{s}", .{ lib_suffix, loader });
14381438 },
14391439
14401440 .powerpc => return copy(&result, "/lib/ld.so.1"),
lib/std/testing.zig+8-7
......@@ -29,10 +29,11 @@ pub var zig_exe_path: []const u8 = undefined;
2929/// and then aborts when actual_error_union is not expected_error.
3030pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void {
3131 if (actual_error_union) |actual_payload| {
32 std.debug.panic("expected error.{}, found {}", .{ @errorName(expected_error), actual_payload });
32 // std.debug.panic("expected error.{s}, found {}", .{ @errorName(expected_error), actual_payload });
33 std.debug.panic("expected error.{s}, found", .{@errorName(expected_error)});
3334 } else |actual_error| {
3435 if (expected_error != actual_error) {
35 std.debug.panic("expected error.{}, found error.{}", .{
36 std.debug.panic("expected error.{s}, found error.{s}", .{
3637 @errorName(expected_error),
3738 @errorName(actual_error),
3839 });
......@@ -60,7 +61,7 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
6061
6162 .Type => {
6263 if (actual != expected) {
63 std.debug.panic("expected type {}, found type {}", .{ @typeName(expected), @typeName(actual) });
64 std.debug.panic("expected type {s}, found type {s}", .{ @typeName(expected), @typeName(actual) });
6465 }
6566 },
6667
......@@ -360,7 +361,7 @@ pub fn expectEqualStrings(expected: []const u8, actual: []const u8) void {
360361 for (expected[0..diff_index]) |value| {
361362 if (value == '\n') diff_line_number += 1;
362363 }
363 print("First difference occurs on line {}:\n", .{diff_line_number});
364 print("First difference occurs on line {d}:\n", .{diff_line_number});
364365
365366 print("expected:\n", .{});
366367 printIndicatorLine(expected, diff_index);
......@@ -416,15 +417,15 @@ fn printWithVisibleNewlines(source: []const u8) void {
416417 while (std.mem.indexOf(u8, source[i..], "\n")) |nl| : (i += nl + 1) {
417418 printLine(source[i .. i + nl]);
418419 }
419 print("{}␃\n", .{source[i..]}); // End of Text symbol (ETX)
420 print("{s}␃\n", .{source[i..]}); // End of Text symbol (ETX)
420421}
421422
422423fn printLine(line: []const u8) void {
423424 if (line.len != 0) switch (line[line.len - 1]) {
424 ' ', '\t' => print("{}⏎\n", .{line}), // Carriage return symbol,
425 ' ', '\t' => print("{s}⏎\n", .{line}), // Carriage return symbol,
425426 else => {},
426427 };
427 print("{}\n", .{line});
428 print("{s}\n", .{line});
428429}
429430
430431test "" {
lib/std/thread.zig+3-3
......@@ -186,7 +186,7 @@ pub const Thread = struct {
186186 @compileError(bad_startfn_ret);
187187 }
188188 startFn(arg) catch |err| {
189 std.debug.warn("error: {}\n", .{@errorName(err)});
189 std.debug.warn("error: {s}\n", .{@errorName(err)});
190190 if (@errorReturnTrace()) |trace| {
191191 std.debug.dumpStackTrace(trace.*);
192192 }
......@@ -247,7 +247,7 @@ pub const Thread = struct {
247247 @compileError(bad_startfn_ret);
248248 }
249249 startFn(arg) catch |err| {
250 std.debug.warn("error: {}\n", .{@errorName(err)});
250 std.debug.warn("error: {s}\n", .{@errorName(err)});
251251 if (@errorReturnTrace()) |trace| {
252252 std.debug.dumpStackTrace(trace.*);
253253 }
......@@ -281,7 +281,7 @@ pub const Thread = struct {
281281 @compileError(bad_startfn_ret);
282282 }
283283 startFn(arg) catch |err| {
284 std.debug.warn("error: {}\n", .{@errorName(err)});
284 std.debug.warn("error: {s}\n", .{@errorName(err)});
285285 if (@errorReturnTrace()) |trace| {
286286 std.debug.dumpStackTrace(trace.*);
287287 }
lib/std/zig/ast.zig+42-42
......@@ -281,41 +281,41 @@ pub const Error = union(enum) {
281281 }
282282 }
283283
284 pub const InvalidToken = SingleTokenError("Invalid token '{}'");
285 pub const ExpectedContainerMembers = SingleTokenError("Expected test, comptime, var decl, or container field, found '{}'");
286 pub const ExpectedStringLiteral = SingleTokenError("Expected string literal, found '{}'");
287 pub const ExpectedIntegerLiteral = SingleTokenError("Expected integer literal, found '{}'");
288 pub const ExpectedIdentifier = SingleTokenError("Expected identifier, found '{}'");
289 pub const ExpectedStatement = SingleTokenError("Expected statement, found '{}'");
290 pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found '{}'");
291 pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found '{}'");
292 pub const ExpectedFn = SingleTokenError("Expected function, found '{}'");
293 pub const ExpectedReturnType = SingleTokenError("Expected 'var' or return type expression, found '{}'");
294 pub const ExpectedAggregateKw = SingleTokenError("Expected '" ++ Token.Id.Keyword_struct.symbol() ++ "', '" ++ Token.Id.Keyword_union.symbol() ++ "', '" ++ Token.Id.Keyword_enum.symbol() ++ "', or '" ++ Token.Id.Keyword_opaque.symbol() ++ "', found '{}'");
295 pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found '{}'");
296 pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found '{}'");
297 pub const ExpectedSemiOrElse = SingleTokenError("Expected ';' or 'else', found '{}'");
298 pub const ExpectedLBrace = SingleTokenError("Expected '{{', found '{}'");
299 pub const ExpectedLabelOrLBrace = SingleTokenError("Expected label or '{{', found '{}'");
300 pub const ExpectedColonOrRParen = SingleTokenError("Expected ':' or ')', found '{}'");
301 pub const ExpectedLabelable = SingleTokenError("Expected 'while', 'for', 'inline', 'suspend', or '{{', found '{}'");
302 pub const ExpectedInlinable = SingleTokenError("Expected 'while' or 'for', found '{}'");
303 pub const ExpectedAsmOutputReturnOrType = SingleTokenError("Expected '->' or '" ++ Token.Id.Identifier.symbol() ++ "', found '{}'");
304 pub const ExpectedSliceOrRBracket = SingleTokenError("Expected ']' or '..', found '{}'");
305 pub const ExpectedTypeExpr = SingleTokenError("Expected type expression, found '{}'");
306 pub const ExpectedPrimaryTypeExpr = SingleTokenError("Expected primary type expression, found '{}'");
307 pub const ExpectedExpr = SingleTokenError("Expected expression, found '{}'");
308 pub const ExpectedPrimaryExpr = SingleTokenError("Expected primary expression, found '{}'");
309 pub const ExpectedParamList = SingleTokenError("Expected parameter list, found '{}'");
310 pub const ExpectedPayload = SingleTokenError("Expected loop payload, found '{}'");
311 pub const ExpectedBlockOrAssignment = SingleTokenError("Expected block or assignment, found '{}'");
312 pub const ExpectedBlockOrExpression = SingleTokenError("Expected block or expression, found '{}'");
313 pub const ExpectedExprOrAssignment = SingleTokenError("Expected expression or assignment, found '{}'");
314 pub const ExpectedPrefixExpr = SingleTokenError("Expected prefix expression, found '{}'");
315 pub const ExpectedLoopExpr = SingleTokenError("Expected loop expression, found '{}'");
316 pub const ExpectedDerefOrUnwrap = SingleTokenError("Expected pointer dereference or optional unwrap, found '{}'");
317 pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found '{}'");
318 pub const ExpectedBlockOrField = SingleTokenError("Expected block or field, found '{}'");
284 pub const InvalidToken = SingleTokenError("Invalid token '{s}'");
285 pub const ExpectedContainerMembers = SingleTokenError("Expected test, comptime, var decl, or container field, found '{s}'");
286 pub const ExpectedStringLiteral = SingleTokenError("Expected string literal, found '{s}'");
287 pub const ExpectedIntegerLiteral = SingleTokenError("Expected integer literal, found '{s}'");
288 pub const ExpectedIdentifier = SingleTokenError("Expected identifier, found '{s}'");
289 pub const ExpectedStatement = SingleTokenError("Expected statement, found '{s}'");
290 pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found '{s}'");
291 pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found '{s}'");
292 pub const ExpectedFn = SingleTokenError("Expected function, found '{s}'");
293 pub const ExpectedReturnType = SingleTokenError("Expected 'var' or return type expression, found '{s}'");
294 pub const ExpectedAggregateKw = SingleTokenError("Expected '" ++ Token.Id.Keyword_struct.symbol() ++ "', '" ++ Token.Id.Keyword_union.symbol() ++ "', '" ++ Token.Id.Keyword_enum.symbol() ++ "', or '" ++ Token.Id.Keyword_opaque.symbol() ++ "', found '{s}'");
295 pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found '{s}'");
296 pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found '{s}'");
297 pub const ExpectedSemiOrElse = SingleTokenError("Expected ';' or 'else', found '{s}'");
298 pub const ExpectedLBrace = SingleTokenError("Expected '{{', found '{s}'");
299 pub const ExpectedLabelOrLBrace = SingleTokenError("Expected label or '{{', found '{s}'");
300 pub const ExpectedColonOrRParen = SingleTokenError("Expected ':' or ')', found '{s}'");
301 pub const ExpectedLabelable = SingleTokenError("Expected 'while', 'for', 'inline', 'suspend', or '{{', found '{s}'");
302 pub const ExpectedInlinable = SingleTokenError("Expected 'while' or 'for', found '{s}'");
303 pub const ExpectedAsmOutputReturnOrType = SingleTokenError("Expected '->' or '" ++ Token.Id.Identifier.symbol() ++ "', found '{s}'");
304 pub const ExpectedSliceOrRBracket = SingleTokenError("Expected ']' or '..', found '{s}'");
305 pub const ExpectedTypeExpr = SingleTokenError("Expected type expression, found '{s}'");
306 pub const ExpectedPrimaryTypeExpr = SingleTokenError("Expected primary type expression, found '{s}'");
307 pub const ExpectedExpr = SingleTokenError("Expected expression, found '{s}'");
308 pub const ExpectedPrimaryExpr = SingleTokenError("Expected primary expression, found '{s}'");
309 pub const ExpectedParamList = SingleTokenError("Expected parameter list, found '{s}'");
310 pub const ExpectedPayload = SingleTokenError("Expected loop payload, found '{s}'");
311 pub const ExpectedBlockOrAssignment = SingleTokenError("Expected block or assignment, found '{s}'");
312 pub const ExpectedBlockOrExpression = SingleTokenError("Expected block or expression, found '{s}'");
313 pub const ExpectedExprOrAssignment = SingleTokenError("Expected expression or assignment, found '{s}'");
314 pub const ExpectedPrefixExpr = SingleTokenError("Expected prefix expression, found '{s}'");
315 pub const ExpectedLoopExpr = SingleTokenError("Expected loop expression, found '{s}'");
316 pub const ExpectedDerefOrUnwrap = SingleTokenError("Expected pointer dereference or optional unwrap, found '{s}'");
317 pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found '{s}'");
318 pub const ExpectedBlockOrField = SingleTokenError("Expected block or field, found '{s}'");
319319
320320 pub const ExpectedParamType = SimpleError("Expected parameter type");
321321 pub const ExpectedPubItem = SimpleError("Expected function or variable declaration after pub");
......@@ -332,7 +332,7 @@ pub const Error = union(enum) {
332332 node: *Node,
333333
334334 pub fn render(self: *const ExpectedCall, tokens: []const Token.Id, stream: anytype) !void {
335 return stream.print("expected " ++ @tagName(Node.Tag.Call) ++ ", found {}", .{
335 return stream.print("expected " ++ @tagName(Node.Tag.Call) ++ ", found {s}", .{
336336 @tagName(self.node.tag),
337337 });
338338 }
......@@ -343,7 +343,7 @@ pub const Error = union(enum) {
343343
344344 pub fn render(self: *const ExpectedCallOrFnProto, tokens: []const Token.Id, stream: anytype) !void {
345345 return stream.print("expected " ++ @tagName(Node.Tag.Call) ++ " or " ++
346 @tagName(Node.Tag.FnProto) ++ ", found {}", .{@tagName(self.node.tag)});
346 @tagName(Node.Tag.FnProto) ++ ", found {s}", .{@tagName(self.node.tag)});
347347 }
348348 };
349349
......@@ -355,11 +355,11 @@ pub const Error = union(enum) {
355355 const found_token = tokens[self.token];
356356 switch (found_token) {
357357 .Invalid => {
358 return stream.print("expected '{}', found invalid bytes", .{self.expected_id.symbol()});
358 return stream.print("expected '{s}', found invalid bytes", .{self.expected_id.symbol()});
359359 },
360360 else => {
361361 const token_name = found_token.symbol();
362 return stream.print("expected '{}', found '{}'", .{ self.expected_id.symbol(), token_name });
362 return stream.print("expected '{s}', found '{s}'", .{ self.expected_id.symbol(), token_name });
363363 },
364364 }
365365 }
......@@ -371,7 +371,7 @@ pub const Error = union(enum) {
371371
372372 pub fn render(self: *const ExpectedCommaOrEnd, tokens: []const Token.Id, stream: anytype) !void {
373373 const actual_token = tokens[self.token];
374 return stream.print("expected ',' or '{}', found '{}'", .{
374 return stream.print("expected ',' or '{s}', found '{s}'", .{
375375 self.end_id.symbol(),
376376 actual_token.symbol(),
377377 });
......@@ -843,7 +843,7 @@ pub const Node = struct {
843843 std.debug.warn(" ", .{});
844844 }
845845 }
846 std.debug.warn("{}\n", .{@tagName(self.tag)});
846 std.debug.warn("{s}\n", .{@tagName(self.tag)});
847847
848848 var child_i: usize = 0;
849849 while (self.iterate(child_i)) |child| : (child_i += 1) {
......@@ -1418,7 +1418,7 @@ pub const Node = struct {
14181418 @alignOf(ParamDecl),
14191419 @ptrCast([*]const u8, self) + @sizeOf(FnProto) + @sizeOf(ParamDecl) * self.params_len,
14201420 );
1421 std.debug.print("{*} flags: {b} name_token: {} {*} params_len: {}\n", .{
1421 std.debug.print("{*} flags: {b} name_token: {s} {*} params_len: {d}\n", .{
14221422 self,
14231423 self.trailer_flags.bits,
14241424 self.getNameToken(),
lib/std/zig/cross_target.zig+5-5
......@@ -519,7 +519,7 @@ pub const CrossTarget = struct {
519519 var result = std.ArrayList(u8).init(allocator);
520520 defer result.deinit();
521521
522 try result.outStream().print("{}-{}", .{ arch_name, os_name });
522 try result.outStream().print("{s}-{s}", .{ arch_name, os_name });
523523
524524 // The zig target syntax does not allow specifying a max os version with no min, so
525525 // if either are present, we need the min.
......@@ -539,9 +539,9 @@ pub const CrossTarget = struct {
539539 }
540540
541541 if (self.glibc_version) |v| {
542 try result.outStream().print("-{}.{}", .{ @tagName(self.getAbi()), v });
542 try result.outStream().print("-{s}.{}", .{ @tagName(self.getAbi()), v });
543543 } else if (self.abi) |abi| {
544 try result.outStream().print("-{}", .{@tagName(abi)});
544 try result.outStream().print("-{s}", .{@tagName(abi)});
545545 }
546546
547547 return result.toOwnedSlice();
......@@ -595,7 +595,7 @@ pub const CrossTarget = struct {
595595 .Dynamic => "",
596596 };
597597
598 return std.fmt.allocPrint(allocator, "{}-{}{}", .{ arch, os, static_suffix });
598 return std.fmt.allocPrint(allocator, "{s}-{s}{s}", .{ arch, os, static_suffix });
599599 }
600600
601601 pub const Executor = union(enum) {
......@@ -790,7 +790,7 @@ test "CrossTarget.parse" {
790790 var buf: [256]u8 = undefined;
791791 const triple = std.fmt.bufPrint(
792792 buf[0..],
793 "native-native-{}.2.1.1",
793 "native-native-{s}.2.1.1",
794794 .{@tagName(std.Target.current.abi)},
795795 ) catch unreachable;
796796
lib/std/zig/parser_test.zig+1-1
......@@ -3744,7 +3744,7 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
37443744 const loc = tree.tokenLocation(0, parse_error.loc());
37453745 try stderr.print("(memory buffer):{}:{}: error: ", .{ loc.line + 1, loc.column + 1 });
37463746 try tree.renderError(parse_error, stderr);
3747 try stderr.print("\n{}\n", .{source[loc.line_start..loc.line_end]});
3747 try stderr.print("\n{s}\n", .{source[loc.line_start..loc.line_end]});
37483748 {
37493749 var i: usize = 0;
37503750 while (i < loc.column) : (i += 1) {
lib/std/zig/render.zig+1-1
......@@ -41,7 +41,7 @@ fn renderRoot(
4141 for (tree.token_ids) |token_id, i| {
4242 if (token_id != .LineComment) break;
4343 const token_loc = tree.token_locs[i];
44 try ais.writer().print("{}\n", .{mem.trimRight(u8, tree.tokenSliceLoc(token_loc), " ")});
44 try ais.writer().print("{s}\n", .{mem.trimRight(u8, tree.tokenSliceLoc(token_loc), " ")});
4545 const next_token = tree.token_locs[i + 1];
4646 const loc = tree.tokenLocationLoc(token_loc.end, next_token);
4747 if (loc.line >= 2) {
lib/std/zig/system.zig+8-8
......@@ -51,7 +51,7 @@ pub const NativePaths = struct {
5151 };
5252 try self.addIncludeDir(include_path);
5353 } else {
54 try self.addWarningFmt("Unrecognized C flag from NIX_CFLAGS_COMPILE: {}", .{word});
54 try self.addWarningFmt("Unrecognized C flag from NIX_CFLAGS_COMPILE: {s}", .{word});
5555 break;
5656 }
5757 }
......@@ -77,7 +77,7 @@ pub const NativePaths = struct {
7777 const lib_path = word[2..];
7878 try self.addLibDir(lib_path);
7979 } else {
80 try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {}", .{word});
80 try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word});
8181 break;
8282 }
8383 }
......@@ -113,22 +113,22 @@ pub const NativePaths = struct {
113113 // TODO: some of these are suspect and should only be added on some systems. audit needed.
114114
115115 try self.addIncludeDir("/usr/local/include");
116 try self.addLibDirFmt("/usr/local/lib{}", .{qual});
116 try self.addLibDirFmt("/usr/local/lib{d}", .{qual});
117117 try self.addLibDir("/usr/local/lib");
118118
119 try self.addIncludeDirFmt("/usr/include/{}", .{triple});
120 try self.addLibDirFmt("/usr/lib/{}", .{triple});
119 try self.addIncludeDirFmt("/usr/include/{s}", .{triple});
120 try self.addLibDirFmt("/usr/lib/{s}", .{triple});
121121
122122 try self.addIncludeDir("/usr/include");
123 try self.addLibDirFmt("/lib{}", .{qual});
123 try self.addLibDirFmt("/lib{d}", .{qual});
124124 try self.addLibDir("/lib");
125 try self.addLibDirFmt("/usr/lib{}", .{qual});
125 try self.addLibDirFmt("/usr/lib{d}", .{qual});
126126 try self.addLibDir("/usr/lib");
127127
128128 // example: on a 64-bit debian-based linux distro, with zlib installed from apt:
129129 // zlib.h is in /usr/include (added above)
130130 // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
131 try self.addLibDirFmt("/lib/{}", .{triple});
131 try self.addLibDirFmt("/lib/{s}", .{triple});
132132 }
133133
134134 return self;
lib/std/zig/tokenizer.zig+2-2
......@@ -334,7 +334,7 @@ pub const Tokenizer = struct {
334334
335335 /// For debugging purposes
336336 pub fn dump(self: *Tokenizer, token: *const Token) void {
337 std.debug.warn("{} \"{}\"\n", .{ @tagName(token.id), self.buffer[token.start..token.end] });
337 std.debug.warn("{s} \"{s}\"\n", .{ @tagName(token.id), self.buffer[token.start..token.end] });
338338 }
339339
340340 pub fn init(buffer: []const u8) Tokenizer {
......@@ -2046,7 +2046,7 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {
20462046 for (expected_tokens) |expected_token_id| {
20472047 const token = tokenizer.next();
20482048 if (token.id != expected_token_id) {
2049 std.debug.panic("expected {}, found {}\n", .{ @tagName(expected_token_id), @tagName(token.id) });
2049 std.debug.panic("expected {s}, found {s}\n", .{ @tagName(expected_token_id), @tagName(token.id) });
20502050 }
20512051 }
20522052 const last_token = tokenizer.next();
test/stage1/behavior.zig+1-1
......@@ -141,5 +141,5 @@ comptime {
141141 _ = @import("behavior/while.zig");
142142 _ = @import("behavior/widening.zig");
143143 _ = @import("behavior/src.zig");
144 _ = @import("behavior/translate_c_macros.zig");
144 // _ = @import("behavior/translate_c_macros.zig");
145145}