summaryrefslogtreecommitdiff
path: root/src/cli/diagnostics.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/diagnostics.zig')
-rw-r--r--src/cli/diagnostics.zig13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/cli/diagnostics.zig b/src/cli/diagnostics.zig
index 2c6cb3b30..2af8bb4f8 100644
--- a/src/cli/diagnostics.zig
+++ b/src/cli/diagnostics.zig
@@ -16,7 +16,7 @@ pub const Diagnostic = struct {
message: [:0]const u8,
/// Write the full user-friendly diagnostic message to the writer.
- pub fn write(self: *const Diagnostic, writer: anytype) !void {
+ pub fn format(self: *const Diagnostic, writer: *std.Io.Writer) !void {
switch (self.location) {
.none => {},
.cli => |index| try writer.print("cli:{}:", .{index}),
@@ -157,11 +157,14 @@ pub const DiagnosticList = struct {
errdefer _ = self.list.pop();
if (comptime precompute_enabled) {
- var buf = std.ArrayList(u8).init(alloc);
- defer buf.deinit();
- try diag.write(buf.writer());
+ var stream: std.Io.Writer.Allocating = .init(alloc);
+ defer stream.deinit();
+ diag.format(&stream.writer) catch |err| switch (err) {
+ // WriteFailed in this instance can only mean an OOM
+ error.WriteFailed => return error.OutOfMemory,
+ };
- const owned: [:0]const u8 = try buf.toOwnedSliceSentinel(0);
+ const owned: [:0]const u8 = try stream.toOwnedSliceSentinel(0);
errdefer alloc.free(owned);
try self.precompute.messages.append(alloc, owned);