Skip to content

Commit e62e42f

Browse files
authored
std.io.Writer: remove requirement of a 2-byte buffer for extern unions (#24489)
closes #24486
1 parent a8dc32e commit e62e42f

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lib/std/Io/Writer.zig

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
625621
pub 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
},

0 commit comments

Comments
 (0)