authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-09 15:31:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-09 15:31:02-07:00
log93ac76594a6ee88e0851bca904a2bbfb0c6509d7
tree0e1080a70520af989777c50f02fca9fac087ca10
parent4d93545ded98b1e4da01e736ede6be726dc88c70

std: fmt.format to io.Writer.print

allows reverting format -> deprecatedFormat, plus I think this is a nicer place for the function.

9 files changed, 215 insertions(+), 219 deletions(-)

lib/std/crypto/ml_kem.zig+7-7
...@@ -1737,11 +1737,11 @@ test "NIST KAT test" {...@@ -1737,11 +1737,11 @@ test "NIST KAT test" {
1737 var f = sha2.Sha256.init(.{});1737 var f = sha2.Sha256.init(.{});
1738 const fw = f.writer();1738 const fw = f.writer();
1739 var g = NistDRBG.init(seed);1739 var g = NistDRBG.init(seed);
1740 try std.fmt.deprecatedFormat(fw, "# {s}\n\n", .{mode.name});1740 try std.fmt.format(fw, "# {s}\n\n", .{mode.name});
1741 for (0..100) |i| {1741 for (0..100) |i| {
1742 g.fill(&seed);1742 g.fill(&seed);
1743 try std.fmt.deprecatedFormat(fw, "count = {}\n", .{i});1743 try std.fmt.format(fw, "count = {}\n", .{i});
1744 try std.fmt.deprecatedFormat(fw, "seed = {X}\n", .{&seed});1744 try std.fmt.format(fw, "seed = {X}\n", .{&seed});
1745 var g2 = NistDRBG.init(seed);1745 var g2 = NistDRBG.init(seed);
17461746
1747 // This is not equivalent to g2.fill(kseed[:]). As the reference1747 // This is not equivalent to g2.fill(kseed[:]). As the reference
...@@ -1756,10 +1756,10 @@ test "NIST KAT test" {...@@ -1756,10 +1756,10 @@ test "NIST KAT test" {
1756 const e = kp.public_key.encaps(eseed);1756 const e = kp.public_key.encaps(eseed);
1757 const ss2 = try kp.secret_key.decaps(&e.ciphertext);1757 const ss2 = try kp.secret_key.decaps(&e.ciphertext);
1758 try testing.expectEqual(ss2, e.shared_secret);1758 try testing.expectEqual(ss2, e.shared_secret);
1759 try std.fmt.deprecatedFormat(fw, "pk = {X}\n", .{&kp.public_key.toBytes()});1759 try std.fmt.format(fw, "pk = {X}\n", .{&kp.public_key.toBytes()});
1760 try std.fmt.deprecatedFormat(fw, "sk = {X}\n", .{&kp.secret_key.toBytes()});1760 try std.fmt.format(fw, "sk = {X}\n", .{&kp.secret_key.toBytes()});
1761 try std.fmt.deprecatedFormat(fw, "ct = {X}\n", .{&e.ciphertext});1761 try std.fmt.format(fw, "ct = {X}\n", .{&e.ciphertext});
1762 try std.fmt.deprecatedFormat(fw, "ss = {X}\n\n", .{&e.shared_secret});1762 try std.fmt.format(fw, "ss = {X}\n\n", .{&e.shared_secret});
1763 }1763 }
17641764
1765 var out: [32]u8 = undefined;1765 var out: [32]u8 = undefined;
lib/std/fmt.zig+5-193
...@@ -78,197 +78,10 @@ pub const Number = struct {...@@ -78,197 +78,10 @@ pub const Number = struct {
78 };78 };
79};79};
8080
81/// Renders fmt string with args, calling `writer` with slices of bytes.81/// Deprecated in favor of `Writer.print`.
82/// If `writer` returns an error, the error is returned from `format` and82pub fn format(writer: anytype, comptime fmt: []const u8, args: anytype) !void {
83/// `writer` is not called again.
84///
85/// The format string must be comptime-known and may contain placeholders following
86/// this format:
87/// `{[argument][specifier]:[fill][alignment][width].[precision]}`
88///
89/// Above, each word including its surrounding [ and ] is a parameter which you have to replace with something:
90///
91/// - *argument* is either the numeric index or the field name of the argument that should be inserted
92/// - when using a field name, you are required to enclose the field name (an identifier) in square
93/// brackets, e.g. {[score]...} as opposed to the numeric index form which can be written e.g. {2...}
94/// - *specifier* is a type-dependent formatting option that determines how a type should formatted (see below)
95/// - *fill* is a single byte which is used to pad formatted numbers.
96/// - *alignment* is one of the three bytes '<', '^', or '>' to make numbers
97/// left, center, or right-aligned, respectively.
98/// - Not all specifiers support alignment.
99/// - Alignment is not Unicode-aware; appropriate only when used with raw bytes or ASCII.
100/// - *width* is the total width of the field in bytes. This only applies to number formatting.
101/// - *precision* specifies how many decimals a formatted number should have.
102///
103/// Note that most of the parameters are optional and may be omitted. Also you
104/// can leave out separators like `:` and `.` when all parameters after the
105/// separator are omitted.
106///
107/// Only exception is the *fill* parameter. If a non-zero *fill* character is
108/// required at the same time as *width* is specified, one has to specify
109/// *alignment* as well, as otherwise the digit following `:` is interpreted as
110/// *width*, not *fill*.
111///
112/// The *specifier* has several options for types:
113/// - `x` and `X`: output numeric value in hexadecimal notation, or string in hexadecimal bytes
114/// - `s`:
115/// - for pointer-to-many and C pointers of u8, print as a C-string using zero-termination
116/// - for slices of u8, print the entire slice as a string without zero-termination
117/// - `t`:
118/// - for enums and tagged unions: prints the tag name
119/// - for error sets: prints the error name
120/// - `b64`: output string as standard base64
121/// - `e`: output floating point value in scientific notation
122/// - `d`: output numeric value in decimal notation
123/// - `b`: output integer value in binary notation
124/// - `o`: output integer value in octal notation
125/// - `c`: output integer as an ASCII character. Integer type must have 8 bits at max.
126/// - `u`: output integer as an UTF-8 sequence. Integer type must have 21 bits at max.
127/// - `D`: output nanoseconds as duration
128/// - `B`: output bytes in SI units (decimal)
129/// - `Bi`: output bytes in IEC units (binary)
130/// - `?`: output optional value as either the unwrapped value, or `null`; may be followed by a format specifier for the underlying value.
131/// - `!`: output error union value as either the unwrapped value, or the formatted error value; may be followed by a format specifier for the underlying value.
132/// - `*`: output the address of the value instead of the value itself.
133/// - `any`: output a value of any type using its default format.
134/// - `f`: delegates to a method on the type named "format" with the signature `fn (*Writer, args: anytype) Writer.Error!void`.
135///
136/// A user type may be a `struct`, `vector`, `union` or `enum` type.
137///
138/// To print literal curly braces, escape them by writing them twice, e.g. `{{` or `}}`.
139pub fn format(w: *Writer, comptime fmt: []const u8, args: anytype) Writer.Error!void {
140 const ArgsType = @TypeOf(args);
141 const args_type_info = @typeInfo(ArgsType);
142 if (args_type_info != .@"struct") {
143 @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
144 }
145
146 const fields_info = args_type_info.@"struct".fields;
147 if (fields_info.len > max_format_args) {
148 @compileError("32 arguments max are supported per format call");
149 }
150
151 @setEvalBranchQuota(fmt.len * 1000);
152 comptime var arg_state: ArgState = .{ .args_len = fields_info.len };
153 comptime var i = 0;
154 comptime var literal: []const u8 = "";
155 inline while (true) {
156 const start_index = i;
157
158 inline while (i < fmt.len) : (i += 1) {
159 switch (fmt[i]) {
160 '{', '}' => break,
161 else => {},
162 }
163 }
164
165 comptime var end_index = i;
166 comptime var unescape_brace = false;
167
168 // Handle {{ and }}, those are un-escaped as single braces
169 if (i + 1 < fmt.len and fmt[i + 1] == fmt[i]) {
170 unescape_brace = true;
171 // Make the first brace part of the literal...
172 end_index += 1;
173 // ...and skip both
174 i += 2;
175 }
176
177 literal = literal ++ fmt[start_index..end_index];
178
179 // We've already skipped the other brace, restart the loop
180 if (unescape_brace) continue;
181
182 // Write out the literal
183 if (literal.len != 0) {
184 try w.writeAll(literal);
185 literal = "";
186 }
187
188 if (i >= fmt.len) break;
189
190 if (fmt[i] == '}') {
191 @compileError("missing opening {");
192 }
193
194 // Get past the {
195 comptime assert(fmt[i] == '{');
196 i += 1;
197
198 const fmt_begin = i;
199 // Find the closing brace
200 inline while (i < fmt.len and fmt[i] != '}') : (i += 1) {}
201 const fmt_end = i;
202
203 if (i >= fmt.len) {
204 @compileError("missing closing }");
205 }
206
207 // Get past the }
208 comptime assert(fmt[i] == '}');
209 i += 1;
210
211 const placeholder_array = fmt[fmt_begin..fmt_end].*;
212 const placeholder = comptime Placeholder.parse(&placeholder_array);
213 const arg_pos = comptime switch (placeholder.arg) {
214 .none => null,
215 .number => |pos| pos,
216 .named => |arg_name| meta.fieldIndex(ArgsType, arg_name) orelse
217 @compileError("no argument with name '" ++ arg_name ++ "'"),
218 };
219
220 const width = switch (placeholder.width) {
221 .none => null,
222 .number => |v| v,
223 .named => |arg_name| blk: {
224 const arg_i = comptime meta.fieldIndex(ArgsType, arg_name) orelse
225 @compileError("no argument with name '" ++ arg_name ++ "'");
226 _ = comptime arg_state.nextArg(arg_i) orelse @compileError("too few arguments");
227 break :blk @field(args, arg_name);
228 },
229 };
230
231 const precision = switch (placeholder.precision) {
232 .none => null,
233 .number => |v| v,
234 .named => |arg_name| blk: {
235 const arg_i = comptime meta.fieldIndex(ArgsType, arg_name) orelse
236 @compileError("no argument with name '" ++ arg_name ++ "'");
237 _ = comptime arg_state.nextArg(arg_i) orelse @compileError("too few arguments");
238 break :blk @field(args, arg_name);
239 },
240 };
241
242 const arg_to_print = comptime arg_state.nextArg(arg_pos) orelse
243 @compileError("too few arguments");
244
245 try w.printValue(
246 placeholder.specifier_arg,
247 .{
248 .fill = placeholder.fill,
249 .alignment = placeholder.alignment,
250 .width = width,
251 .precision = precision,
252 },
253 @field(args, fields_info[arg_to_print].name),
254 std.options.fmt_max_depth,
255 );
256 }
257
258 if (comptime arg_state.hasUnusedArgs()) {
259 const missing_count = arg_state.args_len - @popCount(arg_state.used_args);
260 switch (missing_count) {
261 0 => unreachable,
262 1 => @compileError("unused argument in '" ++ fmt ++ "'"),
263 else => @compileError(comptimePrint("{d}", .{missing_count}) ++ " unused arguments in '" ++ fmt ++ "'"),
264 }
265 }
266}
267
268/// Deprecated in favor of `format`.
269pub fn deprecatedFormat(writer: anytype, comptime fmt: []const u8, args: anytype) !void {
270 var adapter = writer.adaptToNewApi();83 var adapter = writer.adaptToNewApi();
271 return format(&adapter.new_interface, fmt, args) catch |err| switch (err) {84 return adapter.new_interface.print(fmt, args) catch |err| switch (err) {
272 error.WriteFailed => return adapter.err.?,85 error.WriteFailed => return adapter.err.?,
273 };86 };
274}87}
...@@ -418,7 +231,6 @@ pub const Parser = struct {...@@ -418,7 +231,6 @@ pub const Parser = struct {
418};231};
419232
420pub const ArgSetType = u32;233pub const ArgSetType = u32;
421const max_format_args = @typeInfo(ArgSetType).int.bits;
422234
423pub const ArgState = struct {235pub const ArgState = struct {
424 next_arg: usize = 0,236 next_arg: usize = 0,
...@@ -1524,8 +1336,8 @@ test "recursive format function" {...@@ -1524,8 +1336,8 @@ test "recursive format function" {
15241336
1525 pub fn format(self: R, writer: *Writer) Writer.Error!void {1337 pub fn format(self: R, writer: *Writer) Writer.Error!void {
1526 return switch (self) {1338 return switch (self) {
1527 .Leaf => |n| std.fmt.format(writer, "Leaf({})", .{n}),1339 .Leaf => |n| writer.print("Leaf({})", .{n}),
1528 .Branch => |b| std.fmt.format(writer, "Branch({f}, {f})", .{ b.left, b.right }),1340 .Branch => |b| writer.print("Branch({f}, {f})", .{ b.left, b.right }),
1529 };1341 };
1530 }1342 }
1531 };1343 };
lib/std/io/DeprecatedWriter.zig+1-1
...@@ -21,7 +21,7 @@ pub fn writeAll(self: Self, bytes: []const u8) anyerror!void {...@@ -21,7 +21,7 @@ pub fn writeAll(self: Self, bytes: []const u8) anyerror!void {
21}21}
2222
23pub fn print(self: Self, comptime format: []const u8, args: anytype) anyerror!void {23pub fn print(self: Self, comptime format: []const u8, args: anytype) anyerror!void {
24 return std.fmt.deprecatedFormat(self, format, args);24 return std.fmt.format(self, format, args);
25}25}
2626
27pub fn writeByte(self: Self, byte: u8) anyerror!void {27pub fn writeByte(self: Self, byte: u8) anyerror!void {
lib/std/io/Writer.zig+186-2
...@@ -519,8 +519,192 @@ pub fn writeAllPreserve(w: *Writer, preserve_length: usize, bytes: []const u8) E...@@ -519,8 +519,192 @@ pub fn writeAllPreserve(w: *Writer, preserve_length: usize, bytes: []const u8) E
519 while (index < bytes.len) index += try w.writePreserve(preserve_length, bytes[index..]);519 while (index < bytes.len) index += try w.writePreserve(preserve_length, bytes[index..]);
520}520}
521521
522pub fn print(w: *Writer, comptime format: []const u8, args: anytype) Error!void {522/// Renders fmt string with args, calling `writer` with slices of bytes.
523 try std.fmt.format(w, format, args);523/// If `writer` returns an error, the error is returned from `format` and
524/// `writer` is not called again.
525///
526/// The format string must be comptime-known and may contain placeholders following
527/// this format:
528/// `{[argument][specifier]:[fill][alignment][width].[precision]}`
529///
530/// Above, each word including its surrounding [ and ] is a parameter which you have to replace with something:
531///
532/// - *argument* is either the numeric index or the field name of the argument that should be inserted
533/// - when using a field name, you are required to enclose the field name (an identifier) in square
534/// brackets, e.g. {[score]...} as opposed to the numeric index form which can be written e.g. {2...}
535/// - *specifier* is a type-dependent formatting option that determines how a type should formatted (see below)
536/// - *fill* is a single byte which is used to pad formatted numbers.
537/// - *alignment* is one of the three bytes '<', '^', or '>' to make numbers
538/// left, center, or right-aligned, respectively.
539/// - Not all specifiers support alignment.
540/// - Alignment is not Unicode-aware; appropriate only when used with raw bytes or ASCII.
541/// - *width* is the total width of the field in bytes. This only applies to number formatting.
542/// - *precision* specifies how many decimals a formatted number should have.
543///
544/// Note that most of the parameters are optional and may be omitted. Also you
545/// can leave out separators like `:` and `.` when all parameters after the
546/// separator are omitted.
547///
548/// Only exception is the *fill* parameter. If a non-zero *fill* character is
549/// required at the same time as *width* is specified, one has to specify
550/// *alignment* as well, as otherwise the digit following `:` is interpreted as
551/// *width*, not *fill*.
552///
553/// The *specifier* has several options for types:
554/// - `x` and `X`: output numeric value in hexadecimal notation, or string in hexadecimal bytes
555/// - `s`:
556/// - for pointer-to-many and C pointers of u8, print as a C-string using zero-termination
557/// - for slices of u8, print the entire slice as a string without zero-termination
558/// - `t`:
559/// - for enums and tagged unions: prints the tag name
560/// - for error sets: prints the error name
561/// - `b64`: output string as standard base64
562/// - `e`: output floating point value in scientific notation
563/// - `d`: output numeric value in decimal notation
564/// - `b`: output integer value in binary notation
565/// - `o`: output integer value in octal notation
566/// - `c`: output integer as an ASCII character. Integer type must have 8 bits at max.
567/// - `u`: output integer as an UTF-8 sequence. Integer type must have 21 bits at max.
568/// - `D`: output nanoseconds as duration
569/// - `B`: output bytes in SI units (decimal)
570/// - `Bi`: output bytes in IEC units (binary)
571/// - `?`: output optional value as either the unwrapped value, or `null`; may be followed by a format specifier for the underlying value.
572/// - `!`: output error union value as either the unwrapped value, or the formatted error value; may be followed by a format specifier for the underlying value.
573/// - `*`: output the address of the value instead of the value itself.
574/// - `any`: output a value of any type using its default format.
575/// - `f`: delegates to a method on the type named "format" with the signature `fn (*Writer, args: anytype) Writer.Error!void`.
576///
577/// A user type may be a `struct`, `vector`, `union` or `enum` type.
578///
579/// To print literal curly braces, escape them by writing them twice, e.g. `{{` or `}}`.
580pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void {
581 const ArgsType = @TypeOf(args);
582 const args_type_info = @typeInfo(ArgsType);
583 if (args_type_info != .@"struct") {
584 @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
585 }
586
587 const fields_info = args_type_info.@"struct".fields;
588 const max_format_args = @typeInfo(std.fmt.ArgSetType).int.bits;
589 if (fields_info.len > max_format_args) {
590 @compileError("32 arguments max are supported per format call");
591 }
592
593 @setEvalBranchQuota(fmt.len * 1000);
594 comptime var arg_state: std.fmt.ArgState = .{ .args_len = fields_info.len };
595 comptime var i = 0;
596 comptime var literal: []const u8 = "";
597 inline while (true) {
598 const start_index = i;
599
600 inline while (i < fmt.len) : (i += 1) {
601 switch (fmt[i]) {
602 '{', '}' => break,
603 else => {},
604 }
605 }
606
607 comptime var end_index = i;
608 comptime var unescape_brace = false;
609
610 // Handle {{ and }}, those are un-escaped as single braces
611 if (i + 1 < fmt.len and fmt[i + 1] == fmt[i]) {
612 unescape_brace = true;
613 // Make the first brace part of the literal...
614 end_index += 1;
615 // ...and skip both
616 i += 2;
617 }
618
619 literal = literal ++ fmt[start_index..end_index];
620
621 // We've already skipped the other brace, restart the loop
622 if (unescape_brace) continue;
623
624 // Write out the literal
625 if (literal.len != 0) {
626 try w.writeAll(literal);
627 literal = "";
628 }
629
630 if (i >= fmt.len) break;
631
632 if (fmt[i] == '}') {
633 @compileError("missing opening {");
634 }
635
636 // Get past the {
637 comptime assert(fmt[i] == '{');
638 i += 1;
639
640 const fmt_begin = i;
641 // Find the closing brace
642 inline while (i < fmt.len and fmt[i] != '}') : (i += 1) {}
643 const fmt_end = i;
644
645 if (i >= fmt.len) {
646 @compileError("missing closing }");
647 }
648
649 // Get past the }
650 comptime assert(fmt[i] == '}');
651 i += 1;
652
653 const placeholder_array = fmt[fmt_begin..fmt_end].*;
654 const placeholder = comptime std.fmt.Placeholder.parse(&placeholder_array);
655 const arg_pos = comptime switch (placeholder.arg) {
656 .none => null,
657 .number => |pos| pos,
658 .named => |arg_name| std.meta.fieldIndex(ArgsType, arg_name) orelse
659 @compileError("no argument with name '" ++ arg_name ++ "'"),
660 };
661
662 const width = switch (placeholder.width) {
663 .none => null,
664 .number => |v| v,
665 .named => |arg_name| blk: {
666 const arg_i = comptime std.meta.fieldIndex(ArgsType, arg_name) orelse
667 @compileError("no argument with name '" ++ arg_name ++ "'");
668 _ = comptime arg_state.nextArg(arg_i) orelse @compileError("too few arguments");
669 break :blk @field(args, arg_name);
670 },
671 };
672
673 const precision = switch (placeholder.precision) {
674 .none => null,
675 .number => |v| v,
676 .named => |arg_name| blk: {
677 const arg_i = comptime std.meta.fieldIndex(ArgsType, arg_name) orelse
678 @compileError("no argument with name '" ++ arg_name ++ "'");
679 _ = comptime arg_state.nextArg(arg_i) orelse @compileError("too few arguments");
680 break :blk @field(args, arg_name);
681 },
682 };
683
684 const arg_to_print = comptime arg_state.nextArg(arg_pos) orelse
685 @compileError("too few arguments");
686
687 try w.printValue(
688 placeholder.specifier_arg,
689 .{
690 .fill = placeholder.fill,
691 .alignment = placeholder.alignment,
692 .width = width,
693 .precision = precision,
694 },
695 @field(args, fields_info[arg_to_print].name),
696 std.options.fmt_max_depth,
697 );
698 }
699
700 if (comptime arg_state.hasUnusedArgs()) {
701 const missing_count = arg_state.args_len - @popCount(arg_state.used_args);
702 switch (missing_count) {
703 0 => unreachable,
704 1 => @compileError("unused argument in '" ++ fmt ++ "'"),
705 else => @compileError(std.fmt.comptimePrint("{d}", .{missing_count}) ++ " unused arguments in '" ++ fmt ++ "'"),
706 }
707 }
524}708}
525709
526/// Calls `drain` as many times as necessary such that `byte` is transferred.710/// Calls `drain` as many times as necessary such that `byte` is transferred.
lib/std/json/stringify.zig+3-3
...@@ -689,7 +689,7 @@ fn outputUnicodeEscape(codepoint: u21, out_stream: anytype) !void {...@@ -689,7 +689,7 @@ fn outputUnicodeEscape(codepoint: u21, out_stream: anytype) !void {
689 // by the lowercase letter u, followed by four hexadecimal digits that encode the character's code point.689 // by the lowercase letter u, followed by four hexadecimal digits that encode the character's code point.
690 try out_stream.writeAll("\\u");690 try out_stream.writeAll("\\u");
691 //try w.printInt("x", .{ .width = 4, .fill = '0' }, codepoint);691 //try w.printInt("x", .{ .width = 4, .fill = '0' }, codepoint);
692 try std.fmt.deprecatedFormat(out_stream, "{x:0>4}", .{codepoint});692 try std.fmt.format(out_stream, "{x:0>4}", .{codepoint});
693 } else {693 } else {
694 assert(codepoint <= 0x10FFFF);694 assert(codepoint <= 0x10FFFF);
695 // To escape an extended character that is not in the Basic Multilingual Plane,695 // To escape an extended character that is not in the Basic Multilingual Plane,
...@@ -698,10 +698,10 @@ fn outputUnicodeEscape(codepoint: u21, out_stream: anytype) !void {...@@ -698,10 +698,10 @@ fn outputUnicodeEscape(codepoint: u21, out_stream: anytype) !void {
698 const low = @as(u16, @intCast(codepoint & 0x3FF)) + 0xDC00;698 const low = @as(u16, @intCast(codepoint & 0x3FF)) + 0xDC00;
699 try out_stream.writeAll("\\u");699 try out_stream.writeAll("\\u");
700 //try w.printInt("x", .{ .width = 4, .fill = '0' }, high);700 //try w.printInt("x", .{ .width = 4, .fill = '0' }, high);
701 try std.fmt.deprecatedFormat(out_stream, "{x:0>4}", .{high});701 try std.fmt.format(out_stream, "{x:0>4}", .{high});
702 try out_stream.writeAll("\\u");702 try out_stream.writeAll("\\u");
703 //try w.printInt("x", .{ .width = 4, .fill = '0' }, low);703 //try w.printInt("x", .{ .width = 4, .fill = '0' }, low);
704 try std.fmt.deprecatedFormat(out_stream, "{x:0>4}", .{low});704 try std.fmt.format(out_stream, "{x:0>4}", .{low});
705 }705 }
706}706}
707707
lib/std/os/uefi.zig+1-1
...@@ -65,7 +65,7 @@ pub const Guid = extern struct {...@@ -65,7 +65,7 @@ pub const Guid = extern struct {
65 const time_mid = @byteSwap(self.time_mid);65 const time_mid = @byteSwap(self.time_mid);
66 const time_high_and_version = @byteSwap(self.time_high_and_version);66 const time_high_and_version = @byteSwap(self.time_high_and_version);
6767
68 return std.fmt.format(writer, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{68 return writer.print("{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{
69 std.mem.asBytes(&time_low),69 std.mem.asBytes(&time_low),
70 std.mem.asBytes(&time_mid),70 std.mem.asBytes(&time_mid),
71 std.mem.asBytes(&time_high_and_version),71 std.mem.asBytes(&time_high_and_version),
lib/std/zig/render.zig+2-2
...@@ -2872,7 +2872,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void {...@@ -2872,7 +2872,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void {
2872 .success => |codepoint| {2872 .success => |codepoint| {
2873 if (codepoint <= 0x7f) {2873 if (codepoint <= 0x7f) {
2874 const buf = [1]u8{@as(u8, @intCast(codepoint))};2874 const buf = [1]u8{@as(u8, @intCast(codepoint))};
2875 try std.fmt.deprecatedFormat(writer, "{f}", .{std.zig.fmtString(&buf)});2875 try std.fmt.format(writer, "{f}", .{std.zig.fmtString(&buf)});
2876 } else {2876 } else {
2877 try writer.writeAll(escape_sequence);2877 try writer.writeAll(escape_sequence);
2878 }2878 }
...@@ -2884,7 +2884,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void {...@@ -2884,7 +2884,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void {
2884 },2884 },
2885 0x00...('\\' - 1), ('\\' + 1)...0x7f => {2885 0x00...('\\' - 1), ('\\' + 1)...0x7f => {
2886 const buf = [1]u8{byte};2886 const buf = [1]u8{byte};
2887 try std.fmt.deprecatedFormat(writer, "{f}", .{std.zig.fmtString(&buf)});2887 try std.fmt.format(writer, "{f}", .{std.zig.fmtString(&buf)});
2888 pos += 1;2888 pos += 1;
2889 },2889 },
2890 0x80...0xff => {2890 0x80...0xff => {
lib/std/zon/stringify.zig+6-6
...@@ -501,7 +501,7 @@ pub fn Serializer(Writer: type) type {...@@ -501,7 +501,7 @@ pub fn Serializer(Writer: type) type {
501 try self.int(val);501 try self.int(val);
502 },502 },
503 .float, .comptime_float => try self.float(val),503 .float, .comptime_float => try self.float(val),
504 .bool, .null => try std.fmt.deprecatedFormat(self.writer, "{}", .{val}),504 .bool, .null => try std.fmt.format(self.writer, "{}", .{val}),
505 .enum_literal => try self.ident(@tagName(val)),505 .enum_literal => try self.ident(@tagName(val)),
506 .@"enum" => try self.ident(@tagName(val)),506 .@"enum" => try self.ident(@tagName(val)),
507 .pointer => |pointer| {507 .pointer => |pointer| {
...@@ -616,7 +616,7 @@ pub fn Serializer(Writer: type) type {...@@ -616,7 +616,7 @@ pub fn Serializer(Writer: type) type {
616 /// Serialize an integer.616 /// Serialize an integer.
617 pub fn int(self: *Self, val: anytype) Writer.Error!void {617 pub fn int(self: *Self, val: anytype) Writer.Error!void {
618 //try self.writer.printInt(val, 10, .lower, .{});618 //try self.writer.printInt(val, 10, .lower, .{});
619 try std.fmt.deprecatedFormat(self.writer, "{d}", .{val});619 try std.fmt.format(self.writer, "{d}", .{val});
620 }620 }
621621
622 /// Serialize a float.622 /// Serialize a float.
...@@ -631,12 +631,12 @@ pub fn Serializer(Writer: type) type {...@@ -631,12 +631,12 @@ pub fn Serializer(Writer: type) type {
631 } else if (std.math.isNegativeZero(val)) {631 } else if (std.math.isNegativeZero(val)) {
632 return self.writer.writeAll("-0.0");632 return self.writer.writeAll("-0.0");
633 } else {633 } else {
634 try std.fmt.deprecatedFormat(self.writer, "{d}", .{val});634 try std.fmt.format(self.writer, "{d}", .{val});
635 },635 },
636 .comptime_float => if (val == 0) {636 .comptime_float => if (val == 0) {
637 return self.writer.writeAll("0");637 return self.writer.writeAll("0");
638 } else {638 } else {
639 try std.fmt.deprecatedFormat(self.writer, "{d}", .{val});639 try std.fmt.format(self.writer, "{d}", .{val});
640 },640 },
641 else => comptime unreachable,641 else => comptime unreachable,
642 }642 }
...@@ -659,7 +659,7 @@ pub fn Serializer(Writer: type) type {...@@ -659,7 +659,7 @@ pub fn Serializer(Writer: type) type {
659 var buf: [8]u8 = undefined;659 var buf: [8]u8 = undefined;
660 const len = std.unicode.utf8Encode(val, &buf) catch return error.InvalidCodepoint;660 const len = std.unicode.utf8Encode(val, &buf) catch return error.InvalidCodepoint;
661 const str = buf[0..len];661 const str = buf[0..len];
662 try std.fmt.deprecatedFormat(self.writer, "'{f}'", .{std.zig.fmtChar(str)});662 try std.fmt.format(self.writer, "'{f}'", .{std.zig.fmtChar(str)});
663 }663 }
664664
665 /// Like `value`, but always serializes `val` as a tuple.665 /// Like `value`, but always serializes `val` as a tuple.
...@@ -717,7 +717,7 @@ pub fn Serializer(Writer: type) type {...@@ -717,7 +717,7 @@ pub fn Serializer(Writer: type) type {
717717
718 /// Like `value`, but always serializes `val` as a string.718 /// Like `value`, but always serializes `val` as a string.
719 pub fn string(self: *Self, val: []const u8) Writer.Error!void {719 pub fn string(self: *Self, val: []const u8) Writer.Error!void {
720 try std.fmt.deprecatedFormat(self.writer, "\"{f}\"", .{std.zig.fmtString(val)});720 try std.fmt.format(self.writer, "\"{f}\"", .{std.zig.fmtString(val)});
721 }721 }
722722
723 /// Options for formatting multiline strings.723 /// Options for formatting multiline strings.
src/link/tapi/parse.zig+4-4
...@@ -83,15 +83,15 @@ pub const Node = struct {...@@ -83,15 +83,15 @@ pub const Node = struct {
8383
84 pub fn format(self: *const Doc, writer: *std.io.Writer) std.io.Writer.Error!void {84 pub fn format(self: *const Doc, writer: *std.io.Writer) std.io.Writer.Error!void {
85 if (self.directive) |id| {85 if (self.directive) |id| {
86 try std.fmt.format(writer, "{{ ", .{});86 try writer.print("{{ ", .{});
87 const directive = self.base.tree.getRaw(id, id);87 const directive = self.base.tree.getRaw(id, id);
88 try std.fmt.format(writer, ".directive = {s}, ", .{directive});88 try writer.print(".directive = {s}, ", .{directive});
89 }89 }
90 if (self.value) |node| {90 if (self.value) |node| {
91 try std.fmt.format(writer, "{}", .{node});91 try writer.print("{}", .{node});
92 }92 }
93 if (self.directive != null) {93 if (self.directive != null) {
94 try std.fmt.format(writer, " }}", .{});94 try writer.print(" }}", .{});
95 }95 }
96 }96 }
97 };97 };