aboutsummaryrefslogtreecommitdiff
path: root/src/Type.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-07-01 19:48:34 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-07-07 22:43:52 -0700
commit941bc3719382a4f6245ad42175d911964f1bc9a4 (patch)
treef17c7a8b9afb241b7de4f43973bea882cb06bf2d /src/Type.zig
parent49be02e6d75acd996d9b2a573714552ba081ea13 (diff)
downloadzig-941bc3719382a4f6245ad42175d911964f1bc9a4.tar.gz
zig-941bc3719382a4f6245ad42175d911964f1bc9a4.zip
compiler: update all instances of std.fmt.Formatter
Diffstat (limited to 'src/Type.zig')
-rw-r--r--src/Type.zig35
1 files changed, 10 insertions, 25 deletions
diff --git a/src/Type.zig b/src/Type.zig
index 1a1f1d2b06..fc6e8c7250 100644
--- a/src/Type.zig
+++ b/src/Type.zig
@@ -121,15 +121,14 @@ pub fn eql(a: Type, b: Type, zcu: *const Zcu) bool {
return a.toIntern() == b.toIntern();
}
-pub fn format(ty: Type, comptime unused_fmt_string: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
+pub fn format(ty: Type, writer: *std.io.Writer, comptime unused_fmt_string: []const u8) !void {
_ = ty;
_ = unused_fmt_string;
- _ = options;
_ = writer;
@compileError("do not format types directly; use either ty.fmtDebug() or ty.fmt()");
}
-pub const Formatter = std.fmt.Formatter(format2);
+pub const Formatter = std.fmt.Formatter(Format, Format.default);
pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {
return .{ .data = .{
@@ -138,42 +137,28 @@ pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {
} };
}
-const FormatContext = struct {
+const Format = struct {
ty: Type,
pt: Zcu.PerThread,
-};
-fn format2(
- ctx: FormatContext,
- comptime unused_format_string: []const u8,
- options: std.fmt.FormatOptions,
- writer: anytype,
-) !void {
- comptime assert(unused_format_string.len == 0);
- _ = options;
- return print(ctx.ty, writer, ctx.pt);
-}
+ fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
+ return print(f.ty, writer, f.pt);
+ }
+};
-pub fn fmtDebug(ty: Type) std.fmt.Formatter(dump) {
+pub fn fmtDebug(ty: Type) std.fmt.Formatter(Type, dump) {
return .{ .data = ty };
}
/// This is a debug function. In order to print types in a meaningful way
/// we also need access to the module.
-pub fn dump(
- start_type: Type,
- comptime unused_format_string: []const u8,
- options: std.fmt.FormatOptions,
- writer: anytype,
-) @TypeOf(writer).Error!void {
- _ = options;
- comptime assert(unused_format_string.len == 0);
+pub fn dump(start_type: Type, writer: *std.io.Writer) std.io.Writer.Error!void {
return writer.print("{any}", .{start_type.ip_index});
}
/// Prints a name suitable for `@typeName`.
/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.
-pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error!void {
+pub fn print(ty: Type, writer: *std.io.Writer, pt: Zcu.PerThread) std.io.Writer.Error!void {
const zcu = pt.zcu;
const ip = &zcu.intern_pool;
switch (ip.indexToKey(ty.toIntern())) {