authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-07-23 17:02:55+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-27 18:07:53+03:00
log4ef7d8581085394d55f5effbb38c05a15546af1b
tree6491407fba9ac7738e31852387e9089623afdb1d
parent7ba1f9bfb52a1f6fa776eeafb45790331be4388f

std.fmt: lowercase compile errors

`compileError\("([A-Z])` and `compileError\("\L\1`. It's pretty convenient.

2 files changed, 25 insertions(+), 25 deletions(-)

doc/langref.html.in+1-1
...@@ -7228,7 +7228,7 @@ pub fn print(self: *Writer, arg0: []const u8, arg1: i32) !void {...@@ -7228,7 +7228,7 @@ pub fn print(self: *Writer, arg0: []const u8, arg1: i32) !void {
7228 <p>7228 <p>
7229 And now, what happens if we give too many arguments to {#syntax#}print{#endsyntax#}?7229 And now, what happens if we give too many arguments to {#syntax#}print{#endsyntax#}?
7230 </p>7230 </p>
7231 {#code_begin|test_err|Unused argument in 'here is a string: '{s}' here is a number: {}#}7231 {#code_begin|test_err|unused argument in 'here is a string: '{s}' here is a number: {}#}
7232const print = @import("std").debug.print;7232const print = @import("std").debug.print;
72337233
7234const a_number: i32 = 1234;7234const a_number: i32 = 1234;
lib/std/fmt.zig+24-24
...@@ -83,7 +83,7 @@ pub fn format(...@@ -83,7 +83,7 @@ pub fn format(
83 const ArgsType = @TypeOf(args);83 const ArgsType = @TypeOf(args);
84 const args_type_info = @typeInfo(ArgsType);84 const args_type_info = @typeInfo(ArgsType);
85 if (args_type_info != .Struct) {85 if (args_type_info != .Struct) {
86 @compileError("Expected tuple or struct argument, found " ++ @typeName(ArgsType));86 @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
87 }87 }
8888
89 const fields_info = args_type_info.Struct.fields;89 const fields_info = args_type_info.Struct.fields;
...@@ -127,7 +127,7 @@ pub fn format(...@@ -127,7 +127,7 @@ pub fn format(
127 if (i >= fmt.len) break;127 if (i >= fmt.len) break;
128128
129 if (fmt[i] == '}') {129 if (fmt[i] == '}') {
130 @compileError("Missing opening {");130 @compileError("missing opening {");
131 }131 }
132132
133 // Get past the {133 // Get past the {
...@@ -140,7 +140,7 @@ pub fn format(...@@ -140,7 +140,7 @@ pub fn format(
140 const fmt_end = i;140 const fmt_end = i;
141141
142 if (i >= fmt.len) {142 if (i >= fmt.len) {
143 @compileError("Missing closing }");143 @compileError("missing closing }");
144 }144 }
145145
146 // Get past the }146 // Get past the }
...@@ -152,7 +152,7 @@ pub fn format(...@@ -152,7 +152,7 @@ pub fn format(
152 .none => null,152 .none => null,
153 .number => |pos| pos,153 .number => |pos| pos,
154 .named => |arg_name| meta.fieldIndex(ArgsType, arg_name) orelse154 .named => |arg_name| meta.fieldIndex(ArgsType, arg_name) orelse
155 @compileError("No argument with name '" ++ arg_name ++ "'"),155 @compileError("no argument with name '" ++ arg_name ++ "'"),
156 };156 };
157157
158 const width = switch (placeholder.width) {158 const width = switch (placeholder.width) {
...@@ -160,8 +160,8 @@ pub fn format(...@@ -160,8 +160,8 @@ pub fn format(
160 .number => |v| v,160 .number => |v| v,
161 .named => |arg_name| blk: {161 .named => |arg_name| blk: {
162 const arg_i = comptime meta.fieldIndex(ArgsType, arg_name) orelse162 const arg_i = comptime meta.fieldIndex(ArgsType, arg_name) orelse
163 @compileError("No argument with name '" ++ arg_name ++ "'");163 @compileError("no argument with name '" ++ arg_name ++ "'");
164 _ = comptime arg_state.nextArg(arg_i) orelse @compileError("Too few arguments");164 _ = comptime arg_state.nextArg(arg_i) orelse @compileError("too few arguments");
165 break :blk @field(args, arg_name);165 break :blk @field(args, arg_name);
166 },166 },
167 };167 };
...@@ -171,14 +171,14 @@ pub fn format(...@@ -171,14 +171,14 @@ pub fn format(
171 .number => |v| v,171 .number => |v| v,
172 .named => |arg_name| blk: {172 .named => |arg_name| blk: {
173 const arg_i = comptime meta.fieldIndex(ArgsType, arg_name) orelse173 const arg_i = comptime meta.fieldIndex(ArgsType, arg_name) orelse
174 @compileError("No argument with name '" ++ arg_name ++ "'");174 @compileError("no argument with name '" ++ arg_name ++ "'");
175 _ = comptime arg_state.nextArg(arg_i) orelse @compileError("Too few arguments");175 _ = comptime arg_state.nextArg(arg_i) orelse @compileError("too few arguments");
176 break :blk @field(args, arg_name);176 break :blk @field(args, arg_name);
177 },177 },
178 };178 };
179179
180 const arg_to_print = comptime arg_state.nextArg(arg_pos) orelse180 const arg_to_print = comptime arg_state.nextArg(arg_pos) orelse
181 @compileError("Too few arguments");181 @compileError("too few arguments");
182182
183 try formatType(183 try formatType(
184 @field(args, fields_info[arg_to_print].name),184 @field(args, fields_info[arg_to_print].name),
...@@ -198,7 +198,7 @@ pub fn format(...@@ -198,7 +198,7 @@ pub fn format(
198 const missing_count = arg_state.args_len - @popCount(ArgSetType, arg_state.used_args);198 const missing_count = arg_state.args_len - @popCount(ArgSetType, arg_state.used_args);
199 switch (missing_count) {199 switch (missing_count) {
200 0 => unreachable,200 0 => unreachable,
201 1 => @compileError("Unused argument in '" ++ fmt ++ "'"),201 1 => @compileError("unused argument in '" ++ fmt ++ "'"),
202 else => @compileError((comptime comptimePrint("{d}", .{missing_count})) ++ " unused arguments in '" ++ fmt ++ "'"),202 else => @compileError((comptime comptimePrint("{d}", .{missing_count})) ++ " unused arguments in '" ++ fmt ++ "'"),
203 }203 }
204 }204 }
...@@ -217,7 +217,7 @@ fn parsePlaceholder(comptime str: anytype) Placeholder {...@@ -217,7 +217,7 @@ fn parsePlaceholder(comptime str: anytype) Placeholder {
217 // Skip the colon, if present217 // Skip the colon, if present
218 if (comptime parser.char()) |ch| {218 if (comptime parser.char()) |ch| {
219 if (ch != ':') {219 if (ch != ':') {
220 @compileError("Expected : or }, found '" ++ [1]u8{ch} ++ "'");220 @compileError("expected : or }, found '" ++ [1]u8{ch} ++ "'");
221 }221 }
222 }222 }
223223
...@@ -252,7 +252,7 @@ fn parsePlaceholder(comptime str: anytype) Placeholder {...@@ -252,7 +252,7 @@ fn parsePlaceholder(comptime str: anytype) Placeholder {
252 // Skip the dot, if present252 // Skip the dot, if present
253 if (comptime parser.char()) |ch| {253 if (comptime parser.char()) |ch| {
254 if (ch != '.') {254 if (ch != '.') {
255 @compileError("Expected . or }, found '" ++ [1]u8{ch} ++ "'");255 @compileError("expected . or }, found '" ++ [1]u8{ch} ++ "'");
256 }256 }
257 }257 }
258258
...@@ -261,7 +261,7 @@ fn parsePlaceholder(comptime str: anytype) Placeholder {...@@ -261,7 +261,7 @@ fn parsePlaceholder(comptime str: anytype) Placeholder {
261 @compileError(@errorName(err));261 @compileError(@errorName(err));
262262
263 if (comptime parser.char()) |ch| {263 if (comptime parser.char()) |ch| {
264 @compileError("Extraneous trailing character '" ++ [1]u8{ch} ++ "'");264 @compileError("extraneous trailing character '" ++ [1]u8{ch} ++ "'");
265 }265 }
266266
267 return Placeholder{267 return Placeholder{
...@@ -423,7 +423,7 @@ pub fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @T...@@ -423,7 +423,7 @@ pub fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @T
423 else => {},423 else => {},
424 }424 }
425425
426 @compileError("Cannot format non-pointer type " ++ @typeName(T) ++ " with * specifier");426 @compileError("cannot format non-pointer type " ++ @typeName(T) ++ " with * specifier");
427}427}
428428
429// This ANY const is a workaround for: https://github.com/ziglang/zig/issues/7948429// This ANY const is a workaround for: https://github.com/ziglang/zig/issues/7948
...@@ -608,7 +608,7 @@ pub fn formatType(...@@ -608,7 +608,7 @@ pub fn formatType(
608 }608 }
609 return;609 return;
610 }610 }
611 @compileError("Unknown format string: '" ++ actual_fmt ++ "' for type '" ++ @typeName(T) ++ "'");611 @compileError("unknown format string: '" ++ actual_fmt ++ "' for type '" ++ @typeName(T) ++ "'");
612 },612 },
613 .Enum, .Union, .Struct => {613 .Enum, .Union, .Struct => {
614 return formatType(value.*, actual_fmt, options, writer, max_depth);614 return formatType(value.*, actual_fmt, options, writer, max_depth);
...@@ -630,7 +630,7 @@ pub fn formatType(...@@ -630,7 +630,7 @@ pub fn formatType(
630 else => {},630 else => {},
631 }631 }
632 }632 }
633 @compileError("Unknown format string: '" ++ actual_fmt ++ "' for type '" ++ @typeName(T) ++ "'");633 @compileError("unknown format string: '" ++ actual_fmt ++ "' for type '" ++ @typeName(T) ++ "'");
634 },634 },
635 .Slice => {635 .Slice => {
636 if (actual_fmt.len == 0)636 if (actual_fmt.len == 0)
...@@ -701,7 +701,7 @@ pub fn formatType(...@@ -701,7 +701,7 @@ pub fn formatType(
701 return formatBuf(buffer, options, writer);701 return formatBuf(buffer, options, writer);
702 },702 },
703 .Null => return formatBuf("null", options, writer),703 .Null => return formatBuf("null", options, writer),
704 else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),704 else => @compileError("unable to format type '" ++ @typeName(T) ++ "'"),
705 }705 }
706}706}
707707
...@@ -747,13 +747,13 @@ pub fn formatIntValue(...@@ -747,13 +747,13 @@ pub fn formatIntValue(
747 if (@typeInfo(@TypeOf(int_value)).Int.bits <= 8) {747 if (@typeInfo(@TypeOf(int_value)).Int.bits <= 8) {
748 return formatAsciiChar(@as(u8, int_value), options, writer);748 return formatAsciiChar(@as(u8, int_value), options, writer);
749 } else {749 } else {
750 @compileError("Cannot print integer that is larger than 8 bits as an ASCII character");750 @compileError("cannot print integer that is larger than 8 bits as an ASCII character");
751 }751 }
752 } else if (comptime std.mem.eql(u8, fmt, "u")) {752 } else if (comptime std.mem.eql(u8, fmt, "u")) {
753 if (@typeInfo(@TypeOf(int_value)).Int.bits <= 21) {753 if (@typeInfo(@TypeOf(int_value)).Int.bits <= 21) {
754 return formatUnicodeCodepoint(@as(u21, int_value), options, writer);754 return formatUnicodeCodepoint(@as(u21, int_value), options, writer);
755 } else {755 } else {
756 @compileError("Cannot print integer that is larger than 21 bits as an UTF-8 sequence");756 @compileError("cannot print integer that is larger than 21 bits as an UTF-8 sequence");
757 }757 }
758 } else if (comptime std.mem.eql(u8, fmt, "b")) {758 } else if (comptime std.mem.eql(u8, fmt, "b")) {
759 radix = 2;759 radix = 2;
...@@ -768,7 +768,7 @@ pub fn formatIntValue(...@@ -768,7 +768,7 @@ pub fn formatIntValue(
768 radix = 8;768 radix = 8;
769 case = .lower;769 case = .lower;
770 } else {770 } else {
771 @compileError("Unsupported format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");771 @compileError("unsupported format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
772 }772 }
773773
774 return formatInt(int_value, radix, case, options, writer);774 return formatInt(int_value, radix, case, options, writer);
...@@ -797,7 +797,7 @@ fn formatFloatValue(...@@ -797,7 +797,7 @@ fn formatFloatValue(
797 error.NoSpaceLeft => unreachable,797 error.NoSpaceLeft => unreachable,
798 };798 };
799 } else {799 } else {
800 @compileError("Unsupported format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");800 @compileError("unsupported format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
801 }801 }
802802
803 return formatBuf(buf_stream.getWritten(), options, writer);803 return formatBuf(buf_stream.getWritten(), options, writer);
...@@ -959,7 +959,7 @@ pub fn fmtIntSizeBin(value: u64) std.fmt.Formatter(formatSizeBin) {...@@ -959,7 +959,7 @@ pub fn fmtIntSizeBin(value: u64) std.fmt.Formatter(formatSizeBin) {
959959
960fn checkTextFmt(comptime fmt: []const u8) void {960fn checkTextFmt(comptime fmt: []const u8) void {
961 if (fmt.len != 1)961 if (fmt.len != 1)
962 @compileError("Unsupported format string '" ++ fmt ++ "' when formatting text");962 @compileError("unsupported format string '" ++ fmt ++ "' when formatting text");
963 switch (fmt[0]) {963 switch (fmt[0]) {
964 'x' => @compileError("specifier 'x' has been deprecated, wrap your argument in std.fmt.fmtSliceHexLower instead"),964 'x' => @compileError("specifier 'x' has been deprecated, wrap your argument in std.fmt.fmtSliceHexLower instead"),
965 'X' => @compileError("specifier 'X' has been deprecated, wrap your argument in std.fmt.fmtSliceHexUpper instead"),965 'X' => @compileError("specifier 'X' has been deprecated, wrap your argument in std.fmt.fmtSliceHexUpper instead"),
...@@ -2377,7 +2377,7 @@ test "custom" {...@@ -2377,7 +2377,7 @@ test "custom" {
2377 } else if (comptime std.mem.eql(u8, fmt, "d")) {2377 } else if (comptime std.mem.eql(u8, fmt, "d")) {
2378 return std.fmt.format(writer, "{d:.3}x{d:.3}", .{ self.x, self.y });2378 return std.fmt.format(writer, "{d:.3}x{d:.3}", .{ self.x, self.y });
2379 } else {2379 } else {
2380 @compileError("Unknown format character: '" ++ fmt ++ "'");2380 @compileError("unknown format character: '" ++ fmt ++ "'");
2381 }2381 }
2382 }2382 }
2383 };2383 };
...@@ -2585,7 +2585,7 @@ test "formatType max_depth" {...@@ -2585,7 +2585,7 @@ test "formatType max_depth" {
2585 if (fmt.len == 0) {2585 if (fmt.len == 0) {
2586 return std.fmt.format(writer, "({d:.3},{d:.3})", .{ self.x, self.y });2586 return std.fmt.format(writer, "({d:.3},{d:.3})", .{ self.x, self.y });
2587 } else {2587 } else {
2588 @compileError("Unknown format string: '" ++ fmt ++ "'");2588 @compileError("unknown format string: '" ++ fmt ++ "'");
2589 }2589 }
2590 }2590 }
2591 };2591 };