aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-08-30 14:50:33 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-08-31 12:49:18 -0700
commit150169f1e0cf08d4b76fed81fc205a63177b6e01 (patch)
treec39318b34c361a9a5a8ddaa1aae80cba1fe27f0c /lib/std
parentab99dd9c5d22a3d927453081654b1f75b2521b48 (diff)
downloadzig-150169f1e0cf08d4b76fed81fc205a63177b6e01.tar.gz
zig-150169f1e0cf08d4b76fed81fc205a63177b6e01.zip
std.fmt: delete deprecated APIs
std.fmt.Formatter -> std.fmt.Alt std.fmt.format -> std.Io.Writer.print
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/Build/Cache/Path.zig4
-rw-r--r--lib/std/Build/Step/CheckObject.zig6
-rw-r--r--lib/std/Build/Step/Run.zig2
-rw-r--r--lib/std/Uri.zig2
-rw-r--r--lib/std/ascii.zig2
-rw-r--r--lib/std/fmt.zig18
-rw-r--r--lib/std/fs/path.zig2
-rw-r--r--lib/std/unicode.zig4
-rw-r--r--lib/std/zig.zig4
-rw-r--r--lib/std/zig/llvm/Builder.zig32
-rw-r--r--lib/std/zig/string_literal.zig2
11 files changed, 32 insertions, 46 deletions
diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig
index 335c1dc23e..bf16fc6814 100644
--- a/lib/std/Build/Cache/Path.zig
+++ b/lib/std/Build/Cache/Path.zig
@@ -147,7 +147,7 @@ pub fn toStringZ(p: Path, allocator: Allocator) Allocator.Error![:0]u8 {
return std.fmt.allocPrintSentinel(allocator, "{f}", .{p}, 0);
}
-pub fn fmtEscapeString(path: Path) std.fmt.Formatter(Path, formatEscapeString) {
+pub fn fmtEscapeString(path: Path) std.fmt.Alt(Path, formatEscapeString) {
return .{ .data = path };
}
@@ -162,7 +162,7 @@ pub fn formatEscapeString(path: Path, writer: *std.Io.Writer) std.Io.Writer.Erro
}
/// Deprecated, use double quoted escape to print paths.
-pub fn fmtEscapeChar(path: Path) std.fmt.Formatter(Path, formatEscapeChar) {
+pub fn fmtEscapeChar(path: Path) std.fmt.Alt(Path, formatEscapeChar) {
return .{ .data = path };
}
diff --git a/lib/std/Build/Step/CheckObject.zig b/lib/std/Build/Step/CheckObject.zig
index 4a2efde407..9dfe65829a 100644
--- a/lib/std/Build/Step/CheckObject.zig
+++ b/lib/std/Build/Step/CheckObject.zig
@@ -595,7 +595,7 @@ fn make(step: *Step, make_options: Step.MakeOptions) !void {
// we either format message string with escaped codes, or not to aid debugging
// the failed test.
const fmtMessageString = struct {
- fn fmtMessageString(kind: Check.Kind, msg: []const u8) std.fmt.Formatter(Ctx, formatMessageString) {
+ fn fmtMessageString(kind: Check.Kind, msg: []const u8) std.fmt.Alt(Ctx, formatMessageString) {
return .{ .data = .{
.kind = kind,
.msg = msg,
@@ -2281,7 +2281,7 @@ const ElfDumper = struct {
return mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + off)), 0);
}
- fn fmtShType(sh_type: u32) std.fmt.Formatter(u32, formatShType) {
+ fn fmtShType(sh_type: u32) std.fmt.Alt(u32, formatShType) {
return .{ .data = sh_type };
}
@@ -2321,7 +2321,7 @@ const ElfDumper = struct {
try writer.writeAll(name);
}
- fn fmtPhType(ph_type: u32) std.fmt.Formatter(u32, formatPhType) {
+ fn fmtPhType(ph_type: u32) std.fmt.Alt(u32, formatPhType) {
return .{ .data = ph_type };
}
diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig
index 78cf08dd43..09e75f4c8b 100644
--- a/lib/std/Build/Step/Run.zig
+++ b/lib/std/Build/Step/Run.zig
@@ -1025,7 +1025,7 @@ fn formatTerm(term: ?std.process.Child.Term, w: *std.Io.Writer) std.Io.Writer.Er
try w.writeAll("exited with any code");
}
}
-fn fmtTerm(term: ?std.process.Child.Term) std.fmt.Formatter(?std.process.Child.Term, formatTerm) {
+fn fmtTerm(term: ?std.process.Child.Term) std.fmt.Alt(?std.process.Child.Term, formatTerm) {
return .{ .data = term };
}
diff --git a/lib/std/Uri.zig b/lib/std/Uri.zig
index 7244c9595b..54e0f6a4f2 100644
--- a/lib/std/Uri.zig
+++ b/lib/std/Uri.zig
@@ -359,7 +359,7 @@ pub const Format = struct {
}
};
-pub fn fmt(uri: *const Uri, flags: Format.Flags) std.fmt.Formatter(Format, Format.default) {
+pub fn fmt(uri: *const Uri, flags: Format.Flags) std.fmt.Alt(Format, Format.default) {
return .{ .data = .{ .uri = uri, .flags = flags } };
}
diff --git a/lib/std/ascii.zig b/lib/std/ascii.zig
index e2e6c1c6fa..48116a7230 100644
--- a/lib/std/ascii.zig
+++ b/lib/std/ascii.zig
@@ -464,7 +464,7 @@ pub const HexEscape = struct {
};
/// Replaces non-ASCII bytes with hex escapes.
-pub fn hexEscape(bytes: []const u8, case: std.fmt.Case) std.fmt.Formatter(HexEscape, HexEscape.format) {
+pub fn hexEscape(bytes: []const u8, case: std.fmt.Case) std.fmt.Alt(HexEscape, HexEscape.format) {
return .{ .data = .{ .bytes = bytes, .charset = switch (case) {
.lower => HexEscape.lower_charset,
.upper => HexEscape.upper_charset,
diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig
index bee3eb9dfc..a346d68a4f 100644
--- a/lib/std/fmt.zig
+++ b/lib/std/fmt.zig
@@ -28,9 +28,6 @@ pub const Case = enum { lower, upper };
const default_alignment = .right;
const default_fill_char = ' ';
-/// Deprecated in favor of `Options`.
-pub const FormatOptions = Options;
-
pub const Options = struct {
precision: ?usize = null,
width: ?usize = null,
@@ -77,14 +74,6 @@ pub const Number = struct {
};
};
-/// Deprecated in favor of `Writer.print`.
-pub fn format(writer: anytype, comptime fmt: []const u8, args: anytype) !void {
- var adapter = writer.adaptToNewApi(&.{});
- return adapter.new_interface.print(fmt, args) catch |err| switch (err) {
- error.WriteFailed => return adapter.err.?,
- };
-}
-
pub const Placeholder = struct {
specifier_arg: []const u8,
fill: u8,
@@ -274,9 +263,6 @@ pub fn digits2(value: u8) [2]u8 {
}
}
-/// Deprecated in favor of `Alt`.
-pub const Formatter = Alt;
-
/// Creates a type suitable for instantiating and passing to a "{f}" placeholder.
pub fn Alt(
comptime Data: type,
@@ -294,7 +280,7 @@ pub fn Alt(
pub fn alt(
context: anytype,
comptime func_name: @TypeOf(.enum_literal),
-) Formatter(@TypeOf(context), @field(@TypeOf(context), @tagName(func_name))) {
+) Alt(@TypeOf(context), @field(@TypeOf(context), @tagName(func_name))) {
return .{ .data = context };
}
@@ -607,7 +593,7 @@ pub const BufPrintError = error{
NoSpaceLeft,
};
-/// Print a Formatter string into `buf`. Returns a slice of the bytes printed.
+/// Print a format string into `buf`. Returns a slice of the bytes printed.
pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![]u8 {
var w: Writer = .fixed(buf);
w.print(fmt, args) catch |err| switch (err) {
diff --git a/lib/std/fs/path.zig b/lib/std/fs/path.zig
index b63269abf4..9f5ed323f1 100644
--- a/lib/std/fs/path.zig
+++ b/lib/std/fs/path.zig
@@ -146,7 +146,7 @@ pub fn joinZ(allocator: Allocator, paths: []const []const u8) ![:0]u8 {
return out[0 .. out.len - 1 :0];
}
-pub fn fmtJoin(paths: []const []const u8) std.fmt.Formatter([]const []const u8, formatJoin) {
+pub fn fmtJoin(paths: []const []const u8) std.fmt.Alt([]const []const u8, formatJoin) {
return .{ .data = paths };
}
diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig
index a248e983e4..7fbf1094ba 100644
--- a/lib/std/unicode.zig
+++ b/lib/std/unicode.zig
@@ -893,7 +893,7 @@ fn formatUtf8(utf8: []const u8, writer: *std.Io.Writer) std.Io.Writer.Error!void
/// Ill-formed UTF-8 byte sequences are replaced by the replacement character (U+FFFD)
/// according to "U+FFFD Substitution of Maximal Subparts" from Chapter 3 of
/// the Unicode standard, and as specified by https://encoding.spec.whatwg.org/#utf-8-decoder
-pub fn fmtUtf8(utf8: []const u8) std.fmt.Formatter([]const u8, formatUtf8) {
+pub fn fmtUtf8(utf8: []const u8) std.fmt.Alt([]const u8, formatUtf8) {
return .{ .data = utf8 };
}
@@ -1483,7 +1483,7 @@ fn formatUtf16Le(utf16le: []const u16, writer: *std.Io.Writer) std.Io.Writer.Err
/// Return a Formatter for a (potentially ill-formed) UTF-16 LE string,
/// which will be converted to UTF-8 during formatting.
/// Unpaired surrogates are replaced by the replacement character (U+FFFD).
-pub fn fmtUtf16Le(utf16le: []const u16) std.fmt.Formatter([]const u16, formatUtf16Le) {
+pub fn fmtUtf16Le(utf16le: []const u16) std.fmt.Alt([]const u16, formatUtf16Le) {
return .{ .data = utf16le };
}
diff --git a/lib/std/zig.zig b/lib/std/zig.zig
index 8dc3e6ced7..c8eea995cd 100644
--- a/lib/std/zig.zig
+++ b/lib/std/zig.zig
@@ -462,12 +462,12 @@ pub const FormatId = struct {
};
/// Return a formatter for escaping a double quoted Zig string.
-pub fn fmtString(bytes: []const u8) std.fmt.Formatter([]const u8, stringEscape) {
+pub fn fmtString(bytes: []const u8) std.fmt.Alt([]const u8, stringEscape) {
return .{ .data = bytes };
}
/// Return a formatter for escaping a single quoted Zig string.
-pub fn fmtChar(c: u21) std.fmt.Formatter(u21, charEscape) {
+pub fn fmtChar(c: u21) std.fmt.Alt(u21, charEscape) {
return .{ .data = c };
}
diff --git a/lib/std/zig/llvm/Builder.zig b/lib/std/zig/llvm/Builder.zig
index a4b9d981b2..4afb0b8734 100644
--- a/lib/std/zig/llvm/Builder.zig
+++ b/lib/std/zig/llvm/Builder.zig
@@ -111,7 +111,7 @@ pub const String = enum(u32) {
return printEscapedString(string_slice, quote_behavior, w);
}
- pub fn fmt(self: String, builder: *const Builder) std.fmt.Formatter(FormatData, format) {
+ pub fn fmt(self: String, builder: *const Builder) std.fmt.Alt(FormatData, format) {
return .{ .data = .{
.string = self,
.builder = builder,
@@ -119,7 +119,7 @@ pub const String = enum(u32) {
} };
}
- pub fn fmtQ(self: String, builder: *const Builder) std.fmt.Formatter(FormatData, format) {
+ pub fn fmtQ(self: String, builder: *const Builder) std.fmt.Alt(FormatData, format) {
return .{ .data = .{
.string = self,
.builder = builder,
@@ -127,7 +127,7 @@ pub const String = enum(u32) {
} };
}
- pub fn fmtRaw(self: String, builder: *const Builder) std.fmt.Formatter(FormatData, format) {
+ pub fn fmtRaw(self: String, builder: *const Builder) std.fmt.Alt(FormatData, format) {
return .{ .data = .{
.string = self,
.builder = builder,
@@ -846,7 +846,7 @@ pub const Type = enum(u32) {
},
}
}
- pub fn fmt(self: Type, builder: *const Builder, mode: FormatData.Mode) std.fmt.Formatter(FormatData, format) {
+ pub fn fmt(self: Type, builder: *const Builder, mode: FormatData.Mode) std.fmt.Alt(FormatData, format) {
return .{ .data = .{ .type = self, .builder = builder, .mode = mode } };
}
@@ -1325,7 +1325,7 @@ pub const Attribute = union(Kind) {
.none => unreachable,
}
}
- pub fn fmt(self: Index, builder: *const Builder, mode: FormatData.mode) std.fmt.Formatter(FormatData, format) {
+ pub fn fmt(self: Index, builder: *const Builder, mode: FormatData.mode) std.fmt.Alt(FormatData, format) {
return .{ .data = .{ .attribute_index = self, .builder = builder, .mode = mode } };
}
@@ -1609,7 +1609,7 @@ pub const Attributes = enum(u32) {
.flags = data.flags,
}, w);
}
- pub fn fmt(self: Attributes, builder: *const Builder, flags: FormatData.Flags) std.fmt.Formatter(FormatData, format) {
+ pub fn fmt(self: Attributes, builder: *const Builder, flags: FormatData.Flags) std.fmt.Alt(FormatData, format) {
return .{ .data = .{ .attributes = self, .builder = builder, .flags = flags } };
}
};
@@ -1803,7 +1803,7 @@ pub const Linkage = enum(u4) {
fn formatOptional(data: ?Linkage, w: *Writer) Writer.Error!void {
if (data) |linkage| try w.print(" {s}", .{@tagName(linkage)});
}
- pub fn fmtOptional(self: ?Linkage) std.fmt.Formatter(?Linkage, formatOptional) {
+ pub fn fmtOptional(self: ?Linkage) std.fmt.Alt(?Linkage, formatOptional) {
return .{ .data = self };
}
};
@@ -2208,7 +2208,7 @@ pub const StrtabString = enum(u32) {
self: StrtabString,
builder: *const Builder,
quote_behavior: ?QuoteBehavior,
- ) std.fmt.Formatter(FormatData, format) {
+ ) std.fmt.Alt(FormatData, format) {
return .{ .data = .{
.string = self,
.builder = builder,
@@ -2387,7 +2387,7 @@ pub const Global = struct {
data.global.unwrap(data.builder).name(data.builder).fmt(data.builder, .quote_unless_valid_identifier),
});
}
- pub fn fmt(self: Index, builder: *const Builder) std.fmt.Formatter(FormatData, format) {
+ pub fn fmt(self: Index, builder: *const Builder) std.fmt.Alt(FormatData, format) {
return .{ .data = .{ .global = self, .builder = builder } };
}
@@ -4852,7 +4852,7 @@ pub const Function = struct {
function: Function.Index,
builder: *Builder,
flags: FormatFlags,
- ) std.fmt.Formatter(FormatData, format) {
+ ) std.fmt.Alt(FormatData, format) {
return .{ .data = .{
.instruction = self,
.function = function,
@@ -7790,7 +7790,7 @@ pub const Constant = enum(u32) {
.global => |global| try w.print("{f}", .{global.fmt(data.builder)}),
}
}
- pub fn fmt(self: Constant, builder: *Builder, flags: FormatFlags) std.fmt.Formatter(FormatData, format) {
+ pub fn fmt(self: Constant, builder: *Builder, flags: FormatFlags) std.fmt.Alt(FormatData, format) {
return .{ .data = .{
.constant = self,
.builder = builder,
@@ -7868,7 +7868,7 @@ pub const Value = enum(u32) {
.metadata => unreachable,
}
}
- pub fn fmt(self: Value, function: Function.Index, builder: *Builder, flags: FormatFlags) std.fmt.Formatter(FormatData, format) {
+ pub fn fmt(self: Value, function: Function.Index, builder: *Builder, flags: FormatFlags) std.fmt.Alt(FormatData, format) {
return .{ .data = .{ .value = self, .function = function, .builder = builder, .flags = flags } };
}
};
@@ -7902,7 +7902,7 @@ pub const MetadataString = enum(u32) {
fn format(data: FormatData, w: *Writer) Writer.Error!void {
try printEscapedString(data.metadata_string.slice(data.builder), .always_quote, w);
}
- fn fmt(self: MetadataString, builder: *const Builder) std.fmt.Formatter(FormatData, format) {
+ fn fmt(self: MetadataString, builder: *const Builder) std.fmt.Alt(FormatData, format) {
return .{ .data = .{ .metadata_string = self, .builder = builder } };
}
};
@@ -8411,7 +8411,7 @@ pub const Metadata = enum(u32) {
inline fn fmt(formatter: *Formatter, prefix: []const u8, node: anytype, special: ?FormatFlags) switch (@TypeOf(node)) {
Metadata => Allocator.Error,
else => error{},
- }!std.fmt.Formatter(FormatData, format) {
+ }!std.fmt.Alt(FormatData, format) {
const Node = @TypeOf(node);
const MaybeNode = switch (@typeInfo(Node)) {
.optional => Node,
@@ -8456,7 +8456,7 @@ pub const Metadata = enum(u32) {
prefix: []const u8,
value: Value,
function: Function.Index,
- ) Allocator.Error!std.fmt.Formatter(FormatData, format) {
+ ) Allocator.Error!std.fmt.Alt(FormatData, format) {
return .{ .data = .{
.formatter = formatter,
.prefix = prefix,
@@ -8539,7 +8539,7 @@ pub const Metadata = enum(u32) {
fmt_str = fmt_str ++ "(";
inline for (fields[2..], names) |*field, name| {
fmt_str = fmt_str ++ "{[" ++ name ++ "]f}";
- const T = std.fmt.Formatter(FormatData, format);
+ const T = std.fmt.Alt(FormatData, format);
field.* = .{
.name = name,
.type = T,
diff --git a/lib/std/zig/string_literal.zig b/lib/std/zig/string_literal.zig
index 391764c925..3699636c79 100644
--- a/lib/std/zig/string_literal.zig
+++ b/lib/std/zig/string_literal.zig
@@ -87,7 +87,7 @@ pub const Error = union(enum) {
}
}
- pub fn fmt(self: @This(), raw_string: []const u8) std.fmt.Formatter(FormatMessage, formatMessage) {
+ pub fn fmt(self: @This(), raw_string: []const u8) std.fmt.Alt(FormatMessage, formatMessage) {
return .{ .data = .{
.err = self,
.raw_string = raw_string,