authorgravatar for mrjbq7@gmail.comJohn Benediktsson <mrjbq7@gmail.com> 2025-07-17 09:42:53-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-07-17 16:42:53+00:00
loge62e42f0d901fd1b053b22ecd14a42bdac7dbac4
tree5ae070e8f06ad0edd812f1630f50801a5946147a
parenta8dc32e4ec5a1370b0b8d1d0ae3bdc5ad3add49f
signaturebadge-check Signed by PGP key B5690EEEBB952194

std.io.Writer: remove requirement of a 2-byte buffer for extern unions (#24489)

closes #24486

1 files changed, 2 insertions(+), 7 deletions(-)

lib/std/Io/Writer.zig+2-7
......@@ -618,10 +618,6 @@ pub fn writeAllPreserve(w: *Writer, preserve_length: usize, bytes: []const u8) E
618618/// A user type may be a `struct`, `vector`, `union` or `enum` type.
619619///
620620/// To print literal curly braces, escape them by writing them twice, e.g. `{{` or `}}`.
621///
622/// Asserts `buffer` capacity of at least 2 if a union is printed. This
623/// requirement could be lifted by adjusting the code, but if you trigger that
624/// assertion it is a clue that you should probably be using a buffer.
625621pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void {
626622 const ArgsType = @TypeOf(args);
627623 const args_type_info = @typeInfo(ArgsType);
......@@ -1257,14 +1253,13 @@ pub fn printValue(
12571253 .@"extern", .@"packed" => {
12581254 if (info.fields.len == 0) return w.writeAll(".{}");
12591255 try w.writeAll(".{ ");
1260 inline for (info.fields) |field| {
1256 inline for (info.fields, 1..) |field, i| {
12611257 try w.writeByte('.');
12621258 try w.writeAll(field.name);
12631259 try w.writeAll(" = ");
12641260 try w.printValue(ANY, options, @field(value, field.name), max_depth - 1);
1265 (try w.writableArray(2)).* = ", ".*;
1261 try w.writeAll(if (i < info.fields.len) ", " else " }");
12661262 }
1267 w.buffer[w.end - 2 ..][0..2].* = " }".*;
12681263 },
12691264 }
12701265 },