| ... | @@ -1181,13 +1181,16 @@ fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, opti | ... | @@ -1181,13 +1181,16 @@ fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, opti |
| 1181 | return buf[0..formatIntBuf(buf, value, base, uppercase, options)]; | 1181 | return buf[0..formatIntBuf(buf, value, base, uppercase, options)]; |
| 1182 | } | 1182 | } |
| 1183 | | 1183 | |
| 1184 | pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args)]u8 { | 1184 | pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args):0]u8 { |
| 1185 | comptime var buf: [count(fmt, args)]u8 = undefined; | 1185 | comptime var buf: [count(fmt, args):0]u8 = undefined; |
| 1186 | _ = bufPrint(&buf, fmt, args) catch unreachable; | 1186 | _ = bufPrint(&buf, fmt, args) catch unreachable; |
| | 1187 | buf[buf.len] = 0; |
| 1187 | return &buf; | 1188 | return &buf; |
| 1188 | } | 1189 | } |
| 1189 | | 1190 | |
| 1190 | test "comptimePrint" { | 1191 | test "comptimePrint" { |
| | 1192 | @setEvalBranchQuota(2000); |
| | 1193 | std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100}))); |
| 1191 | std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100})); | 1194 | std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100})); |
| 1192 | } | 1195 | } |
| 1193 | | 1196 | |