diff options
| author | Jarred Sumner <jarred@jarredsumner.com> | 2021-06-08 20:42:29 -0700 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2021-06-13 10:33:49 +0300 |
| commit | 540b52931aeeee7c72c73361118d07ab986cf048 (patch) | |
| tree | 6530a554de35d5b84fce69ddec0009d2de0301e2 /lib/std | |
| parent | b2879825d7e59fc40f3defe272039d723b692f43 (diff) | |
| download | zig-540b52931aeeee7c72c73361118d07ab986cf048.tar.gz zig-540b52931aeeee7c72c73361118d07ab986cf048.zip | |
Improve error message when std.fmt.format is missing arguments
Use fmt in fmt so the number in the error message is fmt'd
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/fmt.zig | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 07c076a248..81b505c952 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -359,7 +359,12 @@ pub fn format( } if (comptime arg_state.hasUnusedArgs()) { - @compileError("Unused arguments"); + const missing_count = arg_state.args_len - @popCount(ArgSetType, arg_state.used_args); + switch (missing_count) { + 0 => unreachable, + 1 => @compileError("Unused argument in \"" ++ fmt ++ "\""), + else => @compileError((comptime comptimePrint("{d}", .{missing_count})) ++ " unused arguments in \"" ++ fmt ++ "\""), + } } } |
