authorgravatar for nick@cern.isNick Cernis <nick@cern.is> 2022-11-12 20:03:24+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-11-12 21:03:24+02:00
log8a5818535b83ba87849cb09de9f1ccd32e8bb480
tree8b63ffe15c08edbe921d17594c5d333219937670
parent32b97df50ea18a194ce9e14b267c99f146a3e2fd
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Make invalidFmtError public and use in place of compileErrors for bad format strings (#13526)

* Export invalidFmtErr To allow consistent use of "invalid format string" compile error response for badly formatted format strings. See https://github.com/ziglang/zig/pull/13489#issuecomment-1311759340. * Replace format compile errors with invalidFmtErr - Provides more consistent compile errors. - Gives user info about the type of the badly formated value. * Rename invalidFmtErr as invalidFmtError For consistency. Zig seems to use “Error” more often than “Err”. * std: add invalid format string checks to remaining custom formatters * pass reference-trace to comp when building build file; fix checkobjectstep

18 files changed, 52 insertions(+), 43 deletions(-)

lib/std/SemanticVersion.zig+1-1
...@@ -157,7 +157,7 @@ pub fn format(...@@ -157,7 +157,7 @@ pub fn format(
157 out_stream: anytype,157 out_stream: anytype,
158) !void {158) !void {
159 _ = options;159 _ = options;
160 if (fmt.len != 0) @compileError("Unknown format string: '" ++ fmt ++ "'");160 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
161 try std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });161 try std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
162 if (self.pre) |pre| try std.fmt.format(out_stream, "-{s}", .{pre});162 if (self.pre) |pre| try std.fmt.format(out_stream, "-{s}", .{pre});
163 if (self.build) |build| try std.fmt.format(out_stream, "+{s}", .{build});163 if (self.build) |build| try std.fmt.format(out_stream, "+{s}", .{build});
lib/std/build/CheckObjectStep.zig+2-2
...@@ -187,7 +187,7 @@ const ComputeCompareExpected = struct {...@@ -187,7 +187,7 @@ const ComputeCompareExpected = struct {
187 options: std.fmt.FormatOptions,187 options: std.fmt.FormatOptions,
188 writer: anytype,188 writer: anytype,
189 ) !void {189 ) !void {
190 _ = fmt;190 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, value);
191 _ = options;191 _ = options;
192 try writer.print("{s} ", .{@tagName(value.op)});192 try writer.print("{s} ", .{@tagName(value.op)});
193 switch (value.value) {193 switch (value.value) {
...@@ -360,7 +360,7 @@ fn make(step: *Step) !void {...@@ -360,7 +360,7 @@ fn make(step: *Step) !void {
360 std.debug.print(360 std.debug.print(
361 \\361 \\
362 \\========= Comparison failed for action: ===========362 \\========= Comparison failed for action: ===========
363 \\{s} {s}363 \\{s} {}
364 \\========= From parsed file: =======================364 \\========= From parsed file: =======================
365 \\{s}365 \\{s}
366 \\366 \\
lib/std/builtin.zig+3-2
...@@ -38,12 +38,13 @@ pub const StackTrace = struct {...@@ -38,12 +38,13 @@ pub const StackTrace = struct {
38 options: std.fmt.FormatOptions,38 options: std.fmt.FormatOptions,
39 writer: anytype,39 writer: anytype,
40 ) !void {40 ) !void {
41 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
42
41 // TODO: re-evaluate whether to use format() methods at all.43 // TODO: re-evaluate whether to use format() methods at all.
42 // Until then, avoid an error when using GeneralPurposeAllocator with WebAssembly44 // Until then, avoid an error when using GeneralPurposeAllocator with WebAssembly
43 // where it tries to call detectTTYConfig here.45 // where it tries to call detectTTYConfig here.
44 if (builtin.os.tag == .freestanding) return;46 if (builtin.os.tag == .freestanding) return;
4547
46 _ = fmt;
47 _ = options;48 _ = options;
48 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);49 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
49 defer arena.deinit();50 defer arena.deinit();
...@@ -534,7 +535,7 @@ pub const Version = struct {...@@ -534,7 +535,7 @@ pub const Version = struct {
534 return std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });535 return std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
535 }536 }
536 } else {537 } else {
537 @compileError("Unknown format string: '" ++ fmt ++ "'");538 std.fmt.invalidFmtError(fmt, self);
538 }539 }
539 }540 }
540};541};
lib/std/debug.zig+1-1
...@@ -2123,7 +2123,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize...@@ -2123,7 +2123,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize
2123 options: std.fmt.FormatOptions,2123 options: std.fmt.FormatOptions,
2124 writer: anytype,2124 writer: anytype,
2125 ) !void {2125 ) !void {
2126 _ = fmt;2126 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, t);
2127 _ = options;2127 _ = options;
2128 if (enabled) {2128 if (enabled) {
2129 try writer.writeAll("\n");2129 try writer.writeAll("\n");
lib/std/fmt.zig+15-15
...@@ -454,7 +454,7 @@ fn stripOptionalOrErrorUnionSpec(comptime fmt: []const u8) []const u8 {...@@ -454,7 +454,7 @@ fn stripOptionalOrErrorUnionSpec(comptime fmt: []const u8) []const u8 {
454 fmt[1..];454 fmt[1..];
455}455}
456456
457fn invalidFmtErr(comptime fmt: []const u8, value: anytype) void {457pub fn invalidFmtError(comptime fmt: []const u8, value: anytype) void {
458 @compileError("invalid format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");458 @compileError("invalid format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
459}459}
460460
...@@ -486,11 +486,11 @@ pub fn formatType(...@@ -486,11 +486,11 @@ pub fn formatType(
486 return formatValue(value, actual_fmt, options, writer);486 return formatValue(value, actual_fmt, options, writer);
487 },487 },
488 .Void => {488 .Void => {
489 if (actual_fmt.len != 0) invalidFmtErr(fmt, value);489 if (actual_fmt.len != 0) invalidFmtError(fmt, value);
490 return formatBuf("void", options, writer);490 return formatBuf("void", options, writer);
491 },491 },
492 .Bool => {492 .Bool => {
493 if (actual_fmt.len != 0) invalidFmtErr(fmt, value);493 if (actual_fmt.len != 0) invalidFmtError(fmt, value);
494 return formatBuf(if (value) "true" else "false", options, writer);494 return formatBuf(if (value) "true" else "false", options, writer);
495 },495 },
496 .Optional => {496 .Optional => {
...@@ -514,14 +514,14 @@ pub fn formatType(...@@ -514,14 +514,14 @@ pub fn formatType(
514 }514 }
515 },515 },
516 .ErrorSet => {516 .ErrorSet => {
517 if (actual_fmt.len != 0) invalidFmtErr(fmt, value);517 if (actual_fmt.len != 0) invalidFmtError(fmt, value);
518 try writer.writeAll("error.");518 try writer.writeAll("error.");
519 return writer.writeAll(@errorName(value));519 return writer.writeAll(@errorName(value));
520 },520 },
521 .Enum => |enumInfo| {521 .Enum => |enumInfo| {
522 try writer.writeAll(@typeName(T));522 try writer.writeAll(@typeName(T));
523 if (enumInfo.is_exhaustive) {523 if (enumInfo.is_exhaustive) {
524 if (actual_fmt.len != 0) invalidFmtErr(fmt, value);524 if (actual_fmt.len != 0) invalidFmtError(fmt, value);
525 try writer.writeAll(".");525 try writer.writeAll(".");
526 try writer.writeAll(@tagName(value));526 try writer.writeAll(@tagName(value));
527 return;527 return;
...@@ -542,7 +542,7 @@ pub fn formatType(...@@ -542,7 +542,7 @@ pub fn formatType(
542 try writer.writeAll(")");542 try writer.writeAll(")");
543 },543 },
544 .Union => |info| {544 .Union => |info| {
545 if (actual_fmt.len != 0) invalidFmtErr(fmt, value);545 if (actual_fmt.len != 0) invalidFmtError(fmt, value);
546 try writer.writeAll(@typeName(T));546 try writer.writeAll(@typeName(T));
547 if (max_depth == 0) {547 if (max_depth == 0) {
548 return writer.writeAll("{ ... }");548 return writer.writeAll("{ ... }");
...@@ -562,7 +562,7 @@ pub fn formatType(...@@ -562,7 +562,7 @@ pub fn formatType(
562 }562 }
563 },563 },
564 .Struct => |info| {564 .Struct => |info| {
565 if (actual_fmt.len != 0) invalidFmtErr(fmt, value);565 if (actual_fmt.len != 0) invalidFmtError(fmt, value);
566 if (info.is_tuple) {566 if (info.is_tuple) {
567 // Skip the type and field names when formatting tuples.567 // Skip the type and field names when formatting tuples.
568 if (max_depth == 0) {568 if (max_depth == 0) {
...@@ -618,7 +618,7 @@ pub fn formatType(...@@ -618,7 +618,7 @@ pub fn formatType(
618 }618 }
619 return;619 return;
620 }620 }
621 invalidFmtErr(fmt, value);621 invalidFmtError(fmt, value);
622 },622 },
623 .Enum, .Union, .Struct => {623 .Enum, .Union, .Struct => {
624 return formatType(value.*, actual_fmt, options, writer, max_depth);624 return formatType(value.*, actual_fmt, options, writer, max_depth);
...@@ -640,7 +640,7 @@ pub fn formatType(...@@ -640,7 +640,7 @@ pub fn formatType(
640 else => {},640 else => {},
641 }641 }
642 }642 }
643 invalidFmtErr(fmt, value);643 invalidFmtError(fmt, value);
644 },644 },
645 .Slice => {645 .Slice => {
646 if (actual_fmt.len == 0)646 if (actual_fmt.len == 0)
...@@ -703,20 +703,20 @@ pub fn formatType(...@@ -703,20 +703,20 @@ pub fn formatType(
703 try writer.writeAll(" }");703 try writer.writeAll(" }");
704 },704 },
705 .Fn => {705 .Fn => {
706 if (actual_fmt.len != 0) invalidFmtErr(fmt, value);706 if (actual_fmt.len != 0) invalidFmtError(fmt, value);
707 return format(writer, "{s}@{x}", .{ @typeName(T), @ptrToInt(value) });707 return format(writer, "{s}@{x}", .{ @typeName(T), @ptrToInt(value) });
708 },708 },
709 .Type => {709 .Type => {
710 if (actual_fmt.len != 0) invalidFmtErr(fmt, value);710 if (actual_fmt.len != 0) invalidFmtError(fmt, value);
711 return formatBuf(@typeName(value), options, writer);711 return formatBuf(@typeName(value), options, writer);
712 },712 },
713 .EnumLiteral => {713 .EnumLiteral => {
714 if (actual_fmt.len != 0) invalidFmtErr(fmt, value);714 if (actual_fmt.len != 0) invalidFmtError(fmt, value);
715 const buffer = [_]u8{'.'} ++ @tagName(value);715 const buffer = [_]u8{'.'} ++ @tagName(value);
716 return formatBuf(buffer, options, writer);716 return formatBuf(buffer, options, writer);
717 },717 },
718 .Null => {718 .Null => {
719 if (actual_fmt.len != 0) invalidFmtErr(fmt, value);719 if (actual_fmt.len != 0) invalidFmtError(fmt, value);
720 return formatBuf("null", options, writer);720 return formatBuf("null", options, writer);
721 },721 },
722 else => @compileError("unable to format type '" ++ @typeName(T) ++ "'"),722 else => @compileError("unable to format type '" ++ @typeName(T) ++ "'"),
...@@ -786,7 +786,7 @@ pub fn formatIntValue(...@@ -786,7 +786,7 @@ pub fn formatIntValue(
786 radix = 8;786 radix = 8;
787 case = .lower;787 case = .lower;
788 } else {788 } else {
789 invalidFmtErr(fmt, value);789 invalidFmtError(fmt, value);
790 }790 }
791791
792 return formatInt(int_value, radix, case, options, writer);792 return formatInt(int_value, radix, case, options, writer);
...@@ -815,7 +815,7 @@ fn formatFloatValue(...@@ -815,7 +815,7 @@ fn formatFloatValue(
815 error.NoSpaceLeft => unreachable,815 error.NoSpaceLeft => unreachable,
816 };816 };
817 } else {817 } else {
818 invalidFmtErr(fmt, value);818 invalidFmtError(fmt, value);
819 }819 }
820820
821 return formatBuf(buf_stream.getWritten(), options, writer);821 return formatBuf(buf_stream.getWritten(), options, writer);
lib/std/fs/wasi.zig+1-1
...@@ -62,7 +62,7 @@ pub const PreopenType = union(PreopenTypeTag) {...@@ -62,7 +62,7 @@ pub const PreopenType = union(PreopenTypeTag) {
62 }62 }
6363
64 pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype) !void {64 pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype) !void {
65 _ = fmt;65 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
66 _ = options;66 _ = options;
67 try out_stream.print("PreopenType{{ ", .{});67 try out_stream.print("PreopenType{{ ", .{});
68 switch (self) {68 switch (self) {
lib/std/heap/general_purpose_allocator.zig+5-5
...@@ -326,7 +326,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -326,7 +326,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
326 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);326 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);
327 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);327 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
328 const addr = bucket.page + slot_index * size_class;328 const addr = bucket.page + slot_index * size_class;
329 log.err("memory address 0x{x} leaked: {s}", .{329 log.err("memory address 0x{x} leaked: {}", .{
330 @ptrToInt(addr), stack_trace,330 @ptrToInt(addr), stack_trace,
331 });331 });
332 leaks = true;332 leaks = true;
...@@ -358,7 +358,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -358,7 +358,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
358 while (it.next()) |large_alloc| {358 while (it.next()) |large_alloc| {
359 if (config.retain_metadata and large_alloc.freed) continue;359 if (config.retain_metadata and large_alloc.freed) continue;
360 const stack_trace = large_alloc.getStackTrace(.alloc);360 const stack_trace = large_alloc.getStackTrace(.alloc);
361 log.err("memory address 0x{x} leaked: {s}", .{361 log.err("memory address 0x{x} leaked: {}", .{
362 @ptrToInt(large_alloc.bytes.ptr), stack_trace,362 @ptrToInt(large_alloc.bytes.ptr), stack_trace,
363 });363 });
364 leaks = true;364 leaks = true;
...@@ -443,7 +443,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -443,7 +443,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
443 .index = 0,443 .index = 0,
444 };444 };
445 std.debug.captureStackTrace(ret_addr, &second_free_stack_trace);445 std.debug.captureStackTrace(ret_addr, &second_free_stack_trace);
446 log.err("Double free detected. Allocation: {s} First free: {s} Second free: {s}", .{446 log.err("Double free detected. Allocation: {} First free: {} Second free: {}", .{
447 alloc_stack_trace, free_stack_trace, second_free_stack_trace,447 alloc_stack_trace, free_stack_trace, second_free_stack_trace,
448 });448 });
449 }449 }
...@@ -533,7 +533,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -533,7 +533,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
533 .index = 0,533 .index = 0,
534 };534 };
535 std.debug.captureStackTrace(ret_addr, &free_stack_trace);535 std.debug.captureStackTrace(ret_addr, &free_stack_trace);
536 log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {s} Free: {s}", .{536 log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {} Free: {}", .{
537 entry.value_ptr.bytes.len,537 entry.value_ptr.bytes.len,
538 old_mem.len,538 old_mem.len,
539 entry.value_ptr.getStackTrace(.alloc),539 entry.value_ptr.getStackTrace(.alloc),
...@@ -606,7 +606,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -606,7 +606,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
606 .index = 0,606 .index = 0,
607 };607 };
608 std.debug.captureStackTrace(ret_addr, &free_stack_trace);608 std.debug.captureStackTrace(ret_addr, &free_stack_trace);
609 log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {s} Free: {s}", .{609 log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {} Free: {}", .{
610 entry.value_ptr.bytes.len,610 entry.value_ptr.bytes.len,
611 old_mem.len,611 old_mem.len,
612 entry.value_ptr.getStackTrace(.alloc),612 entry.value_ptr.getStackTrace(.alloc),
lib/std/math/big/int.zig+1-1
...@@ -2061,7 +2061,7 @@ pub const Const = struct {...@@ -2061,7 +2061,7 @@ pub const Const = struct {
2061 radix = 16;2061 radix = 16;
2062 case = .upper;2062 case = .upper;
2063 } else {2063 } else {
2064 @compileError("Unknown format string: '" ++ fmt ++ "'");2064 std.fmt.invalidFmtError(fmt, self);
2065 }2065 }
20662066
2067 var limbs: [128]Limb = undefined;2067 var limbs: [128]Limb = undefined;
lib/std/net.zig+3-2
...@@ -149,6 +149,7 @@ pub const Address = extern union {...@@ -149,6 +149,7 @@ pub const Address = extern union {
149 options: std.fmt.FormatOptions,149 options: std.fmt.FormatOptions,
150 out_stream: anytype,150 out_stream: anytype,
151 ) !void {151 ) !void {
152 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
152 switch (self.any.family) {153 switch (self.any.family) {
153 os.AF.INET => try self.in.format(fmt, options, out_stream),154 os.AF.INET => try self.in.format(fmt, options, out_stream),
154 os.AF.INET6 => try self.in6.format(fmt, options, out_stream),155 os.AF.INET6 => try self.in6.format(fmt, options, out_stream),
...@@ -274,7 +275,7 @@ pub const Ip4Address = extern struct {...@@ -274,7 +275,7 @@ pub const Ip4Address = extern struct {
274 options: std.fmt.FormatOptions,275 options: std.fmt.FormatOptions,
275 out_stream: anytype,276 out_stream: anytype,
276 ) !void {277 ) !void {
277 _ = fmt;278 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
278 _ = options;279 _ = options;
279 const bytes = @ptrCast(*const [4]u8, &self.sa.addr);280 const bytes = @ptrCast(*const [4]u8, &self.sa.addr);
280 try std.fmt.format(out_stream, "{}.{}.{}.{}:{}", .{281 try std.fmt.format(out_stream, "{}.{}.{}.{}:{}", .{
...@@ -563,7 +564,7 @@ pub const Ip6Address = extern struct {...@@ -563,7 +564,7 @@ pub const Ip6Address = extern struct {
563 options: std.fmt.FormatOptions,564 options: std.fmt.FormatOptions,
564 out_stream: anytype,565 out_stream: anytype,
565 ) !void {566 ) !void {
566 _ = fmt;567 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
567 _ = options;568 _ = options;
568 const port = mem.bigToNative(u16, self.sa.port);569 const port = mem.bigToNative(u16, self.sa.port);
569 if (mem.eql(u8, self.sa.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {570 if (mem.eql(u8, self.sa.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
lib/std/os/uefi.zig+1-1
...@@ -68,7 +68,7 @@ pub const Guid = extern struct {...@@ -68,7 +68,7 @@ pub const Guid = extern struct {
68 fmt(std.mem.asBytes(&self.node)),68 fmt(std.mem.asBytes(&self.node)),
69 });69 });
70 } else {70 } else {
71 @compileError("Unknown format character: '" ++ f ++ "'");71 std.fmt.invalidFmtError(f, self);
72 }72 }
73 }73 }
7474
lib/std/target.zig+4-2
...@@ -167,19 +167,21 @@ pub const Target = struct {...@@ -167,19 +167,21 @@ pub const Target = struct {
167 _: std.fmt.FormatOptions,167 _: std.fmt.FormatOptions,
168 out_stream: anytype,168 out_stream: anytype,
169 ) !void {169 ) !void {
170 if (fmt.len > 0 and fmt[0] == 's') {170 if (comptime std.mem.eql(u8, fmt, "s")) {
171 if (@enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.latest)) {171 if (@enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.latest)) {
172 try std.fmt.format(out_stream, ".{s}", .{@tagName(self)});172 try std.fmt.format(out_stream, ".{s}", .{@tagName(self)});
173 } else {173 } else {
174 // TODO this code path breaks zig triples, but it is used in `builtin`174 // TODO this code path breaks zig triples, but it is used in `builtin`
175 try std.fmt.format(out_stream, "@intToEnum(Target.Os.WindowsVersion, 0x{X:0>8})", .{@enumToInt(self)});175 try std.fmt.format(out_stream, "@intToEnum(Target.Os.WindowsVersion, 0x{X:0>8})", .{@enumToInt(self)});
176 }176 }
177 } else {177 } else if (fmt.len == 0) {
178 if (@enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.latest)) {178 if (@enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.latest)) {
179 try std.fmt.format(out_stream, "WindowsVersion.{s}", .{@tagName(self)});179 try std.fmt.format(out_stream, "WindowsVersion.{s}", .{@tagName(self)});
180 } else {180 } else {
181 try std.fmt.format(out_stream, "WindowsVersion(0x{X:0>8})", .{@enumToInt(self)});181 try std.fmt.format(out_stream, "WindowsVersion(0x{X:0>8})", .{@enumToInt(self)});
182 }182 }
183 } else {
184 std.fmt.invalidFmtError(fmt, self);
183 }185 }
184 }186 }
185 };187 };
lib/std/testing.zig+1-1
...@@ -700,7 +700,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime...@@ -700,7 +700,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime
700 error.OutOfMemory => {700 error.OutOfMemory => {
701 if (failing_allocator_inst.allocated_bytes != failing_allocator_inst.freed_bytes) {701 if (failing_allocator_inst.allocated_bytes != failing_allocator_inst.freed_bytes) {
702 print(702 print(
703 "\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\nallocation that was made to fail: {s}",703 "\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\nallocation that was made to fail: {}",
704 .{704 .{
705 fail_index,705 fail_index,
706 needed_alloc_count,706 needed_alloc_count,
lib/std/wasm.zig+1-1
...@@ -356,7 +356,7 @@ pub const Type = struct {...@@ -356,7 +356,7 @@ pub const Type = struct {
356 returns: []const Valtype,356 returns: []const Valtype,
357357
358 pub fn format(self: Type, comptime fmt: []const u8, opt: std.fmt.FormatOptions, writer: anytype) !void {358 pub fn format(self: Type, comptime fmt: []const u8, opt: std.fmt.FormatOptions, writer: anytype) !void {
359 _ = fmt;359 if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
360 _ = opt;360 _ = opt;
361 try writer.writeByte('(');361 try writer.writeByte('(');
362 for (self.params) |param, i| {362 for (self.params) |param, i| {
lib/std/x/net/bpf.zig+1-2
...@@ -282,8 +282,7 @@ pub const Insn = extern struct {...@@ -282,8 +282,7 @@ pub const Insn = extern struct {
282 writer: anytype,282 writer: anytype,
283 ) !void {283 ) !void {
284 _ = opts;284 _ = opts;
285 if (comptime layout.len != 0 and layout[0] != 's')285 if (layout.len != 0) std.fmt.invalidFmtError(layout, self);
286 @compileError("Unsupported format specifier for BPF Insn type '" ++ layout ++ "'.");
287286
288 try std.fmt.format(287 try std.fmt.format(
289 writer,288 writer,
lib/std/x/net/ip.zig+1-1
...@@ -47,8 +47,8 @@ pub const Address = union(enum) {...@@ -47,8 +47,8 @@ pub const Address = union(enum) {
47 opts: fmt.FormatOptions,47 opts: fmt.FormatOptions,
48 writer: anytype,48 writer: anytype,
49 ) !void {49 ) !void {
50 if (layout.len != 0) std.fmt.invalidFmtError(layout, self);
50 _ = opts;51 _ = opts;
51 _ = layout;
52 switch (self) {52 switch (self) {
53 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),53 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
54 .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),54 .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
lib/std/x/os/net.zig+2-4
...@@ -168,9 +168,7 @@ pub const IPv4 = extern struct {...@@ -168,9 +168,7 @@ pub const IPv4 = extern struct {
168 writer: anytype,168 writer: anytype,
169 ) !void {169 ) !void {
170 _ = opts;170 _ = opts;
171 if (comptime layout.len != 0 and layout[0] != 's') {171 if (layout.len != 0) std.fmt.invalidFmtError(layout, self);
172 @compileError("Unsupported format specifier for IPv4 type '" ++ layout ++ "'.");
173 }
174172
175 try fmt.format(writer, "{}.{}.{}.{}", .{173 try fmt.format(writer, "{}.{}.{}.{}", .{
176 self.octets[0],174 self.octets[0],
...@@ -382,7 +380,7 @@ pub const IPv6 = extern struct {...@@ -382,7 +380,7 @@ pub const IPv6 = extern struct {
382 'x', 'X' => |specifier| specifier,380 'x', 'X' => |specifier| specifier,
383 's' => 'x',381 's' => 'x',
384 'S' => 'X',382 'S' => 'X',
385 else => @compileError("Unsupported format specifier for IPv6 type '" ++ layout ++ "'."),383 else => std.fmt.invalidFmtError(layout, self),
386 }};384 }};
387385
388 if (mem.startsWith(u8, &self.octets, &v4_mapped_prefix)) {386 if (mem.startsWith(u8, &self.octets, &v4_mapped_prefix)) {
lib/std/x/os/socket.zig+1-1
...@@ -127,8 +127,8 @@ pub const Socket = struct {...@@ -127,8 +127,8 @@ pub const Socket = struct {
127 opts: fmt.FormatOptions,127 opts: fmt.FormatOptions,
128 writer: anytype,128 writer: anytype,
129 ) !void {129 ) !void {
130 if (layout.len != 0) std.fmt.invalidFmtError(layout, self);
130 _ = opts;131 _ = opts;
131 _ = layout;
132 switch (self) {132 switch (self) {
133 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),133 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
134 .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),134 .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
src/main.zig+8
...@@ -3744,6 +3744,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -3744,6 +3744,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
3744 var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR");3744 var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR");
3745 var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR");3745 var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR");
3746 var child_argv = std.ArrayList([]const u8).init(arena);3746 var child_argv = std.ArrayList([]const u8).init(arena);
3747 var reference_trace: ?u32 = null;
37473748
3748 const argv_index_exe = child_argv.items.len;3749 const argv_index_exe = child_argv.items.len;
3749 _ = try child_argv.addOne();3750 _ = try child_argv.addOne();
...@@ -3795,10 +3796,16 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -3795,10 +3796,16 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
3795 try child_argv.append(arg);3796 try child_argv.append(arg);
3796 } else if (mem.eql(u8, arg, "-freference-trace")) {3797 } else if (mem.eql(u8, arg, "-freference-trace")) {
3797 try child_argv.append(arg);3798 try child_argv.append(arg);
3799 reference_trace = 256;
3798 } else if (mem.startsWith(u8, arg, "-freference-trace=")) {3800 } else if (mem.startsWith(u8, arg, "-freference-trace=")) {
3799 try child_argv.append(arg);3801 try child_argv.append(arg);
3802 const num = arg["-freference-trace=".len..];
3803 reference_trace = std.fmt.parseUnsigned(u32, num, 10) catch |err| {
3804 fatal("unable to parse reference_trace count '{s}': {s}", .{ num, @errorName(err) });
3805 };
3800 } else if (mem.eql(u8, arg, "-fno-reference-trace")) {3806 } else if (mem.eql(u8, arg, "-fno-reference-trace")) {
3801 try child_argv.append(arg);3807 try child_argv.append(arg);
3808 reference_trace = null;
3802 }3809 }
3803 }3810 }
3804 try child_argv.append(arg);3811 try child_argv.append(arg);
...@@ -3932,6 +3939,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -3932,6 +3939,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
3932 .thread_pool = &thread_pool,3939 .thread_pool = &thread_pool,
3933 .use_stage1 = use_stage1,3940 .use_stage1 = use_stage1,
3934 .cache_mode = .whole,3941 .cache_mode = .whole,
3942 .reference_trace = reference_trace,
3935 }) catch |err| {3943 }) catch |err| {
3936 fatal("unable to create compilation: {s}", .{@errorName(err)});3944 fatal("unable to create compilation: {s}", .{@errorName(err)});
3937 };3945 };