std: Remove a handful of things deprecated during the 0.15 release cycle

- std.Build.Step.Compile.root_module mutators -> std.Build.Module
- std.Build.Step.Compile.want_lto -> std.Build.Step.Compile.lto
- std.Build.Step.ConfigHeader.getOutput -> std.Build.Step.ConfigHeader.getOutputFile
- std.Build.Step.Run.max_stdio_size -> std.Build.Step.Run.stdio_limit
- std.enums.nameCast -> @field(E, tag_name) / @field(E, @tagName(tag))
- std.Io.tty.detectConfig -> std.Io.tty.Config.detect
- std.mem.trimLeft -> std.mem.trimStart
- std.mem.trimRight -> std.mem.trimEnd
- std.meta.intToEnum -> std.enums.fromInt
- std.meta.TagPayload -> @FieldType(U, @tagName(tag))
- std.meta.TagPayloadByName -> @FieldType(U, tag_name)
This commit is contained in:
Linus Groh 2025-10-15 17:30:06 +02:00
parent 688c151550
commit da1415efce
21 changed files with 42 additions and 280 deletions

View file

@ -58,7 +58,7 @@ fn serializeFloat(comptime T: type, value: T, w: *std.Io.Writer) !void {
}, },
else => { else => {
const size = @bitSizeOf(T); const size = @bitSizeOf(T);
const storage_unit = std.meta.intToEnum(StorageUnit, size) catch unreachable; const storage_unit = std.enums.fromInt(StorageUnit, size).?;
const IntTy = @Type(.{ .int = .{ .signedness = .unsigned, .bits = size } }); const IntTy = @Type(.{ .int = .{ .signedness = .unsigned, .bits = size } });
const int_val: IntTy = @bitCast(value); const int_val: IntTy = @bitCast(value);
return serializeInt(int_val, storage_unit, w); return serializeInt(int_val, storage_unit, w);
@ -95,7 +95,7 @@ fn emitSingleValue(c: *AsmCodeGen, qt: QualType, node: Node.Index) !void {
if (!scalar_kind.isReal()) { if (!scalar_kind.isReal()) {
return c.todo("Codegen _Complex values", node.tok(c.tree)); return c.todo("Codegen _Complex values", node.tok(c.tree));
} else if (scalar_kind.isInt()) { } else if (scalar_kind.isInt()) {
const storage_unit = std.meta.intToEnum(StorageUnit, bit_size) catch return c.todo("Codegen _BitInt values", node.tok(c.tree)); const storage_unit = std.enums.fromInt(StorageUnit, bit_size) orelse return c.todo("Codegen _BitInt values", node.tok(c.tree));
try c.data.print(" .{s} ", .{@tagName(storage_unit)}); try c.data.print(" .{s} ", .{@tagName(storage_unit)});
_ = try value.print(qt, c.comp, c.data); _ = try value.print(qt, c.comp, c.data);
try c.data.writeByte('\n'); try c.data.writeByte('\n');

View file

@ -149,7 +149,7 @@ fn mainImpl() !void {
var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer); var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer);
while (stdin_reader.takeDelimiterExclusive('\n')) |line| { while (stdin_reader.takeDelimiterExclusive('\n')) |line| {
const trimmed = std.mem.trimRight(u8, line, '\r'); const trimmed = std.mem.trimEnd(u8, line, '\r');
try parser.feedLine(trimmed); try parser.feedLine(trimmed);
} else |err| switch (err) { } else |err| switch (err) {
error.EndOfStream => {}, error.EndOfStream => {},

View file

@ -187,9 +187,6 @@ force_undefined_symbols: std.StringHashMap(void),
/// Overrides the default stack size /// Overrides the default stack size
stack_size: ?u64 = null, stack_size: ?u64 = null,
/// Deprecated; prefer using `lto`.
want_lto: ?bool = null,
use_llvm: ?bool, use_llvm: ?bool,
use_lld: ?bool, use_lld: ?bool,
use_new_linker: ?bool, use_new_linker: ?bool,
@ -539,7 +536,7 @@ pub fn installHeadersDirectory(
/// When a module links with this artifact, all headers marked for installation are added to that /// When a module links with this artifact, all headers marked for installation are added to that
/// module's include search path. /// module's include search path.
pub fn installConfigHeader(cs: *Compile, config_header: *Step.ConfigHeader) void { pub fn installConfigHeader(cs: *Compile, config_header: *Step.ConfigHeader) void {
cs.installHeader(config_header.getOutput(), config_header.include_path); cs.installHeader(config_header.getOutputFile(), config_header.include_path);
} }
/// Forwards all headers marked for installation from `lib` to this artifact. /// Forwards all headers marked for installation from `lib` to this artifact.
@ -682,18 +679,6 @@ pub fn producesImplib(compile: *Compile) bool {
return compile.isDll(); return compile.isDll();
} }
/// Deprecated; use `compile.root_module.link_libc = true` instead.
/// To be removed after 0.15.0 is tagged.
pub fn linkLibC(compile: *Compile) void {
compile.root_module.link_libc = true;
}
/// Deprecated; use `compile.root_module.link_libcpp = true` instead.
/// To be removed after 0.15.0 is tagged.
pub fn linkLibCpp(compile: *Compile) void {
compile.root_module.link_libcpp = true;
}
const PkgConfigResult = struct { const PkgConfigResult = struct {
cflags: []const []const u8, cflags: []const []const u8,
libs: []const []const u8, libs: []const []const u8,
@ -807,46 +792,6 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
}; };
} }
/// Deprecated; use `compile.root_module.linkSystemLibrary(name, .{})` instead.
/// To be removed after 0.15.0 is tagged.
pub fn linkSystemLibrary(compile: *Compile, name: []const u8) void {
return compile.root_module.linkSystemLibrary(name, .{});
}
/// Deprecated; use `compile.root_module.linkSystemLibrary(name, options)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn linkSystemLibrary2(
compile: *Compile,
name: []const u8,
options: Module.LinkSystemLibraryOptions,
) void {
return compile.root_module.linkSystemLibrary(name, options);
}
/// Deprecated; use `c.root_module.linkFramework(name, .{})` instead.
/// To be removed after 0.15.0 is tagged.
pub fn linkFramework(c: *Compile, name: []const u8) void {
c.root_module.linkFramework(name, .{});
}
/// Deprecated; use `compile.root_module.addCSourceFiles(options)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addCSourceFiles(compile: *Compile, options: Module.AddCSourceFilesOptions) void {
compile.root_module.addCSourceFiles(options);
}
/// Deprecated; use `compile.root_module.addCSourceFile(source)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addCSourceFile(compile: *Compile, source: Module.CSourceFile) void {
compile.root_module.addCSourceFile(source);
}
/// Deprecated; use `compile.root_module.addWin32ResourceFile(source)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addWin32ResourceFile(compile: *Compile, source: Module.RcSourceFile) void {
compile.root_module.addWin32ResourceFile(source);
}
pub fn setVerboseLink(compile: *Compile, value: bool) void { pub fn setVerboseLink(compile: *Compile, value: bool) void {
compile.verbose_link = value; compile.verbose_link = value;
} }
@ -928,84 +873,6 @@ pub fn getEmittedLlvmBc(compile: *Compile) LazyPath {
return compile.getEmittedFileGeneric(&compile.generated_llvm_bc); return compile.getEmittedFileGeneric(&compile.generated_llvm_bc);
} }
/// Deprecated; use `compile.root_module.addAssemblyFile(source)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addAssemblyFile(compile: *Compile, source: LazyPath) void {
compile.root_module.addAssemblyFile(source);
}
/// Deprecated; use `compile.root_module.addObjectFile(source)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addObjectFile(compile: *Compile, source: LazyPath) void {
compile.root_module.addObjectFile(source);
}
/// Deprecated; use `compile.root_module.addObject(object)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addObject(compile: *Compile, object: *Compile) void {
compile.root_module.addObject(object);
}
/// Deprecated; use `compile.root_module.linkLibrary(library)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn linkLibrary(compile: *Compile, library: *Compile) void {
compile.root_module.linkLibrary(library);
}
/// Deprecated; use `compile.root_module.addAfterIncludePath(lazy_path)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addAfterIncludePath(compile: *Compile, lazy_path: LazyPath) void {
compile.root_module.addAfterIncludePath(lazy_path);
}
/// Deprecated; use `compile.root_module.addSystemIncludePath(lazy_path)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addSystemIncludePath(compile: *Compile, lazy_path: LazyPath) void {
compile.root_module.addSystemIncludePath(lazy_path);
}
/// Deprecated; use `compile.root_module.addIncludePath(lazy_path)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addIncludePath(compile: *Compile, lazy_path: LazyPath) void {
compile.root_module.addIncludePath(lazy_path);
}
/// Deprecated; use `compile.root_module.addConfigHeader(config_header)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addConfigHeader(compile: *Compile, config_header: *Step.ConfigHeader) void {
compile.root_module.addConfigHeader(config_header);
}
/// Deprecated; use `compile.root_module.addEmbedPath(lazy_path)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addEmbedPath(compile: *Compile, lazy_path: LazyPath) void {
compile.root_module.addEmbedPath(lazy_path);
}
/// Deprecated; use `compile.root_module.addLibraryPath(directory_path)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addLibraryPath(compile: *Compile, directory_path: LazyPath) void {
compile.root_module.addLibraryPath(directory_path);
}
/// Deprecated; use `compile.root_module.addRPath(directory_path)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addRPath(compile: *Compile, directory_path: LazyPath) void {
compile.root_module.addRPath(directory_path);
}
/// Deprecated; use `compile.root_module.addSystemFrameworkPath(directory_path)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addSystemFrameworkPath(compile: *Compile, directory_path: LazyPath) void {
compile.root_module.addSystemFrameworkPath(directory_path);
}
/// Deprecated; use `compile.root_module.addFrameworkPath(directory_path)` instead.
/// To be removed after 0.15.0 is tagged.
pub fn addFrameworkPath(compile: *Compile, directory_path: LazyPath) void {
compile.root_module.addFrameworkPath(directory_path);
}
pub fn setExecCmd(compile: *Compile, args: []const ?[]const u8) void { pub fn setExecCmd(compile: *Compile, args: []const ?[]const u8) void {
const b = compile.step.owner; const b = compile.step.owner;
assert(compile.kind == .@"test"); assert(compile.kind == .@"test");
@ -1758,7 +1625,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
.thin => "-flto=thin", .thin => "-flto=thin",
.none => "-fno-lto", .none => "-fno-lto",
}); });
} else try addFlag(&zig_args, "lto", compile.want_lto); }
try addFlag(&zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard); try addFlag(&zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard);

View file

@ -124,9 +124,6 @@ pub fn getOutputFile(ch: *ConfigHeader) std.Build.LazyPath {
return ch.getOutputDir().path(ch.step.owner, ch.include_path); return ch.getOutputDir().path(ch.step.owner, ch.include_path);
} }
/// Deprecated; use `getOutputFile`.
pub const getOutput = getOutputFile;
fn addValueInner(config_header: *ConfigHeader, name: []const u8, comptime T: type, value: T) !void { fn addValueInner(config_header: *ConfigHeader, name: []const u8, comptime T: type, value: T) !void {
switch (@typeInfo(T)) { switch (@typeInfo(T)) {
.null => { .null => {

View file

@ -73,9 +73,6 @@ skip_foreign_checks: bool,
/// external executor (such as qemu) but not fail if the executor is unavailable. /// external executor (such as qemu) but not fail if the executor is unavailable.
failing_to_execute_foreign_is_an_error: bool, failing_to_execute_foreign_is_an_error: bool,
/// Deprecated in favor of `stdio_limit`.
max_stdio_size: usize,
/// If stderr or stdout exceeds this amount, the child process is killed and /// If stderr or stdout exceeds this amount, the child process is killed and
/// the step fails. /// the step fails.
stdio_limit: std.Io.Limit, stdio_limit: std.Io.Limit,
@ -208,7 +205,6 @@ pub fn create(owner: *std.Build, name: []const u8) *Run {
.rename_step_with_output_arg = true, .rename_step_with_output_arg = true,
.skip_foreign_checks = false, .skip_foreign_checks = false,
.failing_to_execute_foreign_is_an_error = true, .failing_to_execute_foreign_is_an_error = true,
.max_stdio_size = 10 * 1024 * 1024,
.stdio_limit = .unlimited, .stdio_limit = .unlimited,
.captured_stdout = null, .captured_stdout = null,
.captured_stderr = null, .captured_stderr = null,
@ -2145,7 +2141,6 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult {
var stdout_bytes: ?[]const u8 = null; var stdout_bytes: ?[]const u8 = null;
var stderr_bytes: ?[]const u8 = null; var stderr_bytes: ?[]const u8 = null;
run.stdio_limit = run.stdio_limit.min(.limited(run.max_stdio_size));
if (child.stdout) |stdout| { if (child.stdout) |stdout| {
if (child.stderr) |stderr| { if (child.stderr) |stderr| {
var poller = std.Io.poll(arena, enum { stdout, stderr }, .{ var poller = std.Io.poll(arena, enum { stdout, stderr }, .{

View file

@ -1246,7 +1246,7 @@ pub const TakeEnumError = Error || error{InvalidEnumTag};
pub fn takeEnum(r: *Reader, comptime Enum: type, endian: std.builtin.Endian) TakeEnumError!Enum { pub fn takeEnum(r: *Reader, comptime Enum: type, endian: std.builtin.Endian) TakeEnumError!Enum {
const Tag = @typeInfo(Enum).@"enum".tag_type; const Tag = @typeInfo(Enum).@"enum".tag_type;
const int = try r.takeInt(Tag, endian); const int = try r.takeInt(Tag, endian);
return std.meta.intToEnum(Enum, int); return std.enums.fromInt(Enum, int) orelse return error.InvalidEnumTag;
} }
/// Reads an integer with the same size as the given nonexhaustive enum's tag type. /// Reads an integer with the same size as the given nonexhaustive enum's tag type.

View file

@ -1201,10 +1201,6 @@ pub fn printValue(
} }
const is_any = comptime std.mem.eql(u8, fmt, ANY); const is_any = comptime std.mem.eql(u8, fmt, ANY);
if (!is_any and std.meta.hasMethod(T, "format") and fmt.len == 0) {
// after 0.15.0 is tagged, delete this compile error and its condition
@compileError("ambiguous format string; specify {f} to call format method, or {any} to skip it");
}
switch (@typeInfo(T)) { switch (@typeInfo(T)) {
.float, .comptime_float => { .float, .comptime_float => {
@ -1692,7 +1688,7 @@ pub fn printFloatHex(w: *Writer, value: anytype, case: std.fmt.Case, opt_precisi
try w.writeAll("0x"); try w.writeAll("0x");
try w.writeByte(buf[0]); try w.writeByte(buf[0]);
const trimmed = std.mem.trimRight(u8, buf[1..], "0"); const trimmed = std.mem.trimEnd(u8, buf[1..], "0");
if (opt_precision) |precision| { if (opt_precision) |precision| {
if (precision > 0) try w.writeAll("."); if (precision > 0) try w.writeAll(".");
} else if (trimmed.len > 0) { } else if (trimmed.len > 0) {

View file

@ -5,11 +5,6 @@ const process = std.process;
const windows = std.os.windows; const windows = std.os.windows;
const native_os = builtin.os.tag; const native_os = builtin.os.tag;
/// Deprecated in favor of `Config.detect`.
pub fn detectConfig(file: File) Config {
return .detect(file);
}
pub const Color = enum { pub const Color = enum {
black, black,
red, red,

View file

@ -1158,7 +1158,7 @@ fn readIndirect(c: *Client) Reader.Error!usize {
P.AEAD.decrypt(cleartext, ciphertext, auth_tag, ad, nonce, pv.server_key) catch P.AEAD.decrypt(cleartext, ciphertext, auth_tag, ad, nonce, pv.server_key) catch
return failRead(c, error.TlsBadRecordMac); return failRead(c, error.TlsBadRecordMac);
// TODO use scalar, non-slice version // TODO use scalar, non-slice version
const msg = mem.trimRight(u8, cleartext, "\x00"); const msg = mem.trimEnd(u8, cleartext, "\x00");
break :cleartext .{ msg.len - 1, @enumFromInt(msg[msg.len - 1]) }; break :cleartext .{ msg.len - 1, @enumFromInt(msg[msg.len - 1]) };
}, },
.tls_1_2 => { .tls_1_2 => {

View file

@ -328,16 +328,16 @@ pub fn dumpHex(bytes: []const u8) void {
} }
/// Prints a hexadecimal view of the bytes, returning any error that occurs. /// Prints a hexadecimal view of the bytes, returning any error that occurs.
pub fn dumpHexFallible(bw: *Writer, ttyconf: tty.Config, bytes: []const u8) !void { pub fn dumpHexFallible(bw: *Writer, tty_config: tty.Config, bytes: []const u8) !void {
var chunks = mem.window(u8, bytes, 16, 16); var chunks = mem.window(u8, bytes, 16, 16);
while (chunks.next()) |window| { while (chunks.next()) |window| {
// 1. Print the address. // 1. Print the address.
const address = (@intFromPtr(bytes.ptr) + 0x10 * (std.math.divCeil(usize, chunks.index orelse bytes.len, 16) catch unreachable)) - 0x10; const address = (@intFromPtr(bytes.ptr) + 0x10 * (std.math.divCeil(usize, chunks.index orelse bytes.len, 16) catch unreachable)) - 0x10;
try ttyconf.setColor(bw, .dim); try tty_config.setColor(bw, .dim);
// We print the address in lowercase and the bytes in uppercase hexadecimal to distinguish them more. // We print the address in lowercase and the bytes in uppercase hexadecimal to distinguish them more.
// Also, make sure all lines are aligned by padding the address. // Also, make sure all lines are aligned by padding the address.
try bw.print("{x:0>[1]} ", .{ address, @sizeOf(usize) * 2 }); try bw.print("{x:0>[1]} ", .{ address, @sizeOf(usize) * 2 });
try ttyconf.setColor(bw, .reset); try tty_config.setColor(bw, .reset);
// 2. Print the bytes. // 2. Print the bytes.
for (window, 0..) |byte, index| { for (window, 0..) |byte, index| {
@ -357,7 +357,7 @@ pub fn dumpHexFallible(bw: *Writer, ttyconf: tty.Config, bytes: []const u8) !voi
try bw.writeByte(byte); try bw.writeByte(byte);
} else { } else {
// Related: https://github.com/ziglang/zig/issues/7600 // Related: https://github.com/ziglang/zig/issues/7600
if (ttyconf == .windows_api) { if (tty_config == .windows_api) {
try bw.writeByte('.'); try bw.writeByte('.');
continue; continue;
} }

View file

@ -216,48 +216,6 @@ test "directEnumArrayDefault slice" {
try testing.expectEqualSlices(u8, "default", array[2]); try testing.expectEqualSlices(u8, "default", array[2]);
} }
/// Deprecated: Use @field(E, @tagName(tag)) or @field(E, string)
pub fn nameCast(comptime E: type, comptime value: anytype) E {
return comptime blk: {
const V = @TypeOf(value);
if (V == E) break :blk value;
const name: ?[]const u8 = switch (@typeInfo(V)) {
.enum_literal, .@"enum" => @tagName(value),
.pointer => value,
else => null,
};
if (name) |n| {
if (@hasField(E, n)) {
break :blk @field(E, n);
}
@compileError("Enum " ++ @typeName(E) ++ " has no field named " ++ n);
}
@compileError("Cannot cast from " ++ @typeName(@TypeOf(value)) ++ " to " ++ @typeName(E));
};
}
test nameCast {
const A = enum(u1) { a = 0, b = 1 };
const B = enum(u1) { a = 1, b = 0 };
try testing.expectEqual(A.a, nameCast(A, .a));
try testing.expectEqual(A.a, nameCast(A, A.a));
try testing.expectEqual(A.a, nameCast(A, B.a));
try testing.expectEqual(A.a, nameCast(A, "a"));
try testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
try testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
try testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
try testing.expectEqual(B.a, nameCast(B, .a));
try testing.expectEqual(B.a, nameCast(B, A.a));
try testing.expectEqual(B.a, nameCast(B, B.a));
try testing.expectEqual(B.a, nameCast(B, "a"));
try testing.expectEqual(B.b, nameCast(B, .b));
try testing.expectEqual(B.b, nameCast(B, A.b));
try testing.expectEqual(B.b, nameCast(B, B.b));
try testing.expectEqual(B.b, nameCast(B, "b"));
}
test fromInt { test fromInt {
const E1 = enum { const E1 = enum {
A, A,

View file

@ -460,7 +460,7 @@ pub fn DebugAllocator(comptime config: Config) type {
pub fn detectLeaks(self: *Self) usize { pub fn detectLeaks(self: *Self) usize {
var leaks: usize = 0; var leaks: usize = 0;
const tty_config = std.Io.tty.detectConfig(.stderr()); const tty_config: std.Io.tty.Config = .detect(.stderr());
for (self.buckets, 0..) |init_optional_bucket, size_class_index| { for (self.buckets, 0..) |init_optional_bucket, size_class_index| {
var optional_bucket = init_optional_bucket; var optional_bucket = init_optional_bucket;
@ -536,7 +536,7 @@ pub fn DebugAllocator(comptime config: Config) type {
fn reportDoubleFree(ret_addr: usize, alloc_stack_trace: StackTrace, free_stack_trace: StackTrace) void { fn reportDoubleFree(ret_addr: usize, alloc_stack_trace: StackTrace, free_stack_trace: StackTrace) void {
var addr_buf: [stack_n]usize = undefined; var addr_buf: [stack_n]usize = undefined;
const second_free_stack_trace = std.debug.captureCurrentStackTrace(.{ .first_address = ret_addr }, &addr_buf); const second_free_stack_trace = std.debug.captureCurrentStackTrace(.{ .first_address = ret_addr }, &addr_buf);
const tty_config = std.Io.tty.detectConfig(.stderr()); const tty_config: std.Io.tty.Config = .detect(.stderr());
log.err("Double free detected. Allocation: {f} First free: {f} Second free: {f}", .{ log.err("Double free detected. Allocation: {f} First free: {f} Second free: {f}", .{
std.debug.FormatStackTrace{ std.debug.FormatStackTrace{
.stack_trace = alloc_stack_trace, .stack_trace = alloc_stack_trace,
@ -590,7 +590,7 @@ pub fn DebugAllocator(comptime config: Config) type {
if (config.safety and old_mem.len != entry.value_ptr.bytes.len) { if (config.safety and old_mem.len != entry.value_ptr.bytes.len) {
var addr_buf: [stack_n]usize = undefined; var addr_buf: [stack_n]usize = undefined;
const free_stack_trace = std.debug.captureCurrentStackTrace(.{ .first_address = ret_addr }, &addr_buf); const free_stack_trace = std.debug.captureCurrentStackTrace(.{ .first_address = ret_addr }, &addr_buf);
const tty_config = std.Io.tty.detectConfig(.stderr()); const tty_config: std.Io.tty.Config = .detect(.stderr());
log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {f} Free: {f}", .{ log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {f} Free: {f}", .{
entry.value_ptr.bytes.len, entry.value_ptr.bytes.len,
old_mem.len, old_mem.len,
@ -703,7 +703,7 @@ pub fn DebugAllocator(comptime config: Config) type {
if (config.safety and old_mem.len != entry.value_ptr.bytes.len) { if (config.safety and old_mem.len != entry.value_ptr.bytes.len) {
var addr_buf: [stack_n]usize = undefined; var addr_buf: [stack_n]usize = undefined;
const free_stack_trace = std.debug.captureCurrentStackTrace(.{ .first_address = ret_addr }, &addr_buf); const free_stack_trace = std.debug.captureCurrentStackTrace(.{ .first_address = ret_addr }, &addr_buf);
const tty_config = std.Io.tty.detectConfig(.stderr()); const tty_config: std.Io.tty.Config = .detect(.stderr());
log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {f} Free: {f}", .{ log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {f} Free: {f}", .{
entry.value_ptr.bytes.len, entry.value_ptr.bytes.len,
old_mem.len, old_mem.len,
@ -935,7 +935,7 @@ pub fn DebugAllocator(comptime config: Config) type {
var addr_buf: [stack_n]usize = undefined; var addr_buf: [stack_n]usize = undefined;
const free_stack_trace = std.debug.captureCurrentStackTrace(.{ .first_address = return_address }, &addr_buf); const free_stack_trace = std.debug.captureCurrentStackTrace(.{ .first_address = return_address }, &addr_buf);
if (old_memory.len != requested_size) { if (old_memory.len != requested_size) {
const tty_config = std.Io.tty.detectConfig(.stderr()); const tty_config: std.Io.tty.Config = .detect(.stderr());
log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {f} Free: {f}", .{ log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {f} Free: {f}", .{
requested_size, requested_size,
old_memory.len, old_memory.len,
@ -950,7 +950,7 @@ pub fn DebugAllocator(comptime config: Config) type {
}); });
} }
if (alignment != slot_alignment) { if (alignment != slot_alignment) {
const tty_config = std.Io.tty.detectConfig(.stderr()); const tty_config: std.Io.tty.Config = .detect(.stderr());
log.err("Allocation alignment {d} does not match free alignment {d}. Allocation: {f} Free: {f}", .{ log.err("Allocation alignment {d} does not match free alignment {d}. Allocation: {f} Free: {f}", .{
slot_alignment.toByteUnits(), slot_alignment.toByteUnits(),
alignment.toByteUnits(), alignment.toByteUnits(),
@ -1044,7 +1044,7 @@ pub fn DebugAllocator(comptime config: Config) type {
var addr_buf: [stack_n]usize = undefined; var addr_buf: [stack_n]usize = undefined;
const free_stack_trace = std.debug.captureCurrentStackTrace(.{ .first_address = return_address }, &addr_buf); const free_stack_trace = std.debug.captureCurrentStackTrace(.{ .first_address = return_address }, &addr_buf);
if (memory.len != requested_size) { if (memory.len != requested_size) {
const tty_config = std.Io.tty.detectConfig(.stderr()); const tty_config: std.Io.tty.Config = .detect(.stderr());
log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {f} Free: {f}", .{ log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {f} Free: {f}", .{
requested_size, requested_size,
memory.len, memory.len,
@ -1059,7 +1059,7 @@ pub fn DebugAllocator(comptime config: Config) type {
}); });
} }
if (alignment != slot_alignment) { if (alignment != slot_alignment) {
const tty_config = std.Io.tty.detectConfig(.stderr()); const tty_config: std.Io.tty.Config = .detect(.stderr());
log.err("Allocation alignment {d} does not match free alignment {d}. Allocation: {f} Free: {f}", .{ log.err("Allocation alignment {d} does not match free alignment {d}. Allocation: {f} Free: {f}", .{
slot_alignment.toByteUnits(), slot_alignment.toByteUnits(),
alignment.toByteUnits(), alignment.toByteUnits(),

View file

@ -529,7 +529,7 @@ pub const Response = struct {
}; };
if (first_line[8] != ' ') return error.HttpHeadersInvalid; if (first_line[8] != ' ') return error.HttpHeadersInvalid;
const status: http.Status = @enumFromInt(parseInt3(first_line[9..12])); const status: http.Status = @enumFromInt(parseInt3(first_line[9..12]));
const reason = mem.trimLeft(u8, first_line[12..], " "); const reason = mem.trimStart(u8, first_line[12..], " ");
res.version = version; res.version = version;
res.status = status; res.status = status;

View file

@ -1247,9 +1247,6 @@ test trimStart {
try testing.expectEqualSlices(u8, "foo\n ", trimStart(u8, " foo\n ", " \n")); try testing.expectEqualSlices(u8, "foo\n ", trimStart(u8, " foo\n ", " \n"));
} }
/// Deprecated: use `trimStart` instead.
pub const trimLeft = trimStart;
/// Remove a set of values from the end of a slice. /// Remove a set of values from the end of a slice.
pub fn trimEnd(comptime T: type, slice: []const T, values_to_strip: []const T) []const T { pub fn trimEnd(comptime T: type, slice: []const T, values_to_strip: []const T) []const T {
var end: usize = slice.len; var end: usize = slice.len;
@ -1261,9 +1258,6 @@ test trimEnd {
try testing.expectEqualSlices(u8, " foo", trimEnd(u8, " foo\n ", " \n")); try testing.expectEqualSlices(u8, " foo", trimEnd(u8, " foo\n ", " \n"));
} }
/// Deprecated: use `trimEnd` instead.
pub const trimRight = trimEnd;
/// Remove a set of values from the beginning and end of a slice. /// Remove a set of values from the beginning and end of a slice.
pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []const T { pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []const T {
var begin: usize = 0; var begin: usize = 0;

View file

@ -671,38 +671,6 @@ test activeTag {
try testing.expect(activeTag(u) == UE.Float); try testing.expect(activeTag(u) == UE.Float);
} }
/// Deprecated: Use @FieldType(U, tag_name)
const TagPayloadType = TagPayload;
/// Deprecated: Use @FieldType(U, tag_name)
pub fn TagPayloadByName(comptime U: type, comptime tag_name: []const u8) type {
const info = @typeInfo(U).@"union";
inline for (info.fields) |field_info| {
if (comptime mem.eql(u8, field_info.name, tag_name))
return field_info.type;
}
@compileError("no field '" ++ tag_name ++ "' in union '" ++ @typeName(U) ++ "'");
}
/// Deprecated: Use @FieldType(U, @tagName(tag))
pub fn TagPayload(comptime U: type, comptime tag: Tag(U)) type {
return TagPayloadByName(U, @tagName(tag));
}
test TagPayload {
const Event = union(enum) {
Moved: struct {
from: i32,
to: i32,
},
};
const MovedEvent = TagPayload(Event, Event.Moved);
const e: Event = .{ .Moved = undefined };
try testing.expect(MovedEvent == @TypeOf(e.Moved));
}
/// Compares two of any type for equality. Containers that do not support comparison /// Compares two of any type for equality. Containers that do not support comparison
/// on their own are compared on a field-by-field basis. Pointers are not followed. /// on their own are compared on a field-by-field basis. Pointers are not followed.
pub fn eql(a: anytype, b: @TypeOf(a)) bool { pub fn eql(a: anytype, b: @TypeOf(a)) bool {
@ -831,14 +799,6 @@ test eql {
try testing.expect(!eql(v1, v3)); try testing.expect(!eql(v1, v3));
} }
/// Deprecated: use `std.enums.fromInt` instead and handle null.
pub const IntToEnumError = error{InvalidEnumTag};
/// Deprecated: use `std.enums.fromInt` instead and handle null instead of an error.
pub fn intToEnum(comptime EnumTag: type, tag_int: anytype) IntToEnumError!EnumTag {
return std.enums.fromInt(EnumTag, tag_int) orelse return error.InvalidEnumTag;
}
/// Given a type and a name, return the field index according to source order. /// Given a type and a name, return the field index according to source order.
/// Returns `null` if the field is not found. /// Returns `null` if the field is not found.
pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int { pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int {

View file

@ -138,23 +138,23 @@ test "sigset_t" {
// See that none are set, then set each one, see that they're all set, then // See that none are set, then set each one, see that they're all set, then
// remove them all, and then see that none are set. // remove them all, and then see that none are set.
for (1..linux.NSIG) |i| { for (1..linux.NSIG) |i| {
const sig = std.meta.intToEnum(SIG, i) catch continue; const sig = std.enums.fromInt(SIG, i) orelse continue;
try expectEqual(false, linux.sigismember(&sigset, sig)); try expectEqual(false, linux.sigismember(&sigset, sig));
} }
for (1..linux.NSIG) |i| { for (1..linux.NSIG) |i| {
const sig = std.meta.intToEnum(SIG, i) catch continue; const sig = std.enums.fromInt(SIG, i) orelse continue;
linux.sigaddset(&sigset, sig); linux.sigaddset(&sigset, sig);
} }
for (1..linux.NSIG) |i| { for (1..linux.NSIG) |i| {
const sig = std.meta.intToEnum(SIG, i) catch continue; const sig = std.enums.fromInt(SIG, i) orelse continue;
try expectEqual(true, linux.sigismember(&sigset, sig)); try expectEqual(true, linux.sigismember(&sigset, sig));
} }
for (1..linux.NSIG) |i| { for (1..linux.NSIG) |i| {
const sig = std.meta.intToEnum(SIG, i) catch continue; const sig = std.enums.fromInt(SIG, i) orelse continue;
linux.sigdelset(&sigset, sig); linux.sigdelset(&sigset, sig);
} }
for (1..linux.NSIG) |i| { for (1..linux.NSIG) |i| {
const sig = std.meta.intToEnum(SIG, i) catch continue; const sig = std.enums.fromInt(SIG, i) orelse continue;
try expectEqual(false, linux.sigismember(&sigset, sig)); try expectEqual(false, linux.sigismember(&sigset, sig));
} }
} }
@ -163,7 +163,7 @@ test "sigfillset" {
// unlike the C library, all the signals are set in the kernel-level fillset // unlike the C library, all the signals are set in the kernel-level fillset
const sigset = linux.sigfillset(); const sigset = linux.sigfillset();
for (1..linux.NSIG) |i| { for (1..linux.NSIG) |i| {
const sig = std.meta.intToEnum(linux.SIG, i) catch continue; const sig = std.enums.fromInt(linux.SIG, i) orelse continue;
try expectEqual(true, linux.sigismember(&sigset, sig)); try expectEqual(true, linux.sigismember(&sigset, sig));
} }
} }
@ -171,7 +171,7 @@ test "sigfillset" {
test "sigemptyset" { test "sigemptyset" {
const sigset = linux.sigemptyset(); const sigset = linux.sigemptyset();
for (1..linux.NSIG) |i| { for (1..linux.NSIG) |i| {
const sig = std.meta.intToEnum(linux.SIG, i) catch continue; const sig = std.enums.fromInt(linux.SIG, i) orelse continue;
try expectEqual(false, linux.sigismember(&sigset, sig)); try expectEqual(false, linux.sigismember(&sigset, sig));
} }
} }

View file

@ -44,7 +44,7 @@ pub const Ip6Config = extern struct {
pub fn setData( pub fn setData(
self: *const Ip6Config, self: *const Ip6Config,
comptime data_type: std.meta.Tag(DataType), comptime data_type: std.meta.Tag(DataType),
payload: *const std.meta.TagPayload(DataType, data_type), payload: *const @FieldType(DataType, @tagName(data_type)),
) SetDataError!void { ) SetDataError!void {
const data_size = @sizeOf(@TypeOf(payload)); const data_size = @sizeOf(@TypeOf(payload));
switch (self._set_data(self, data_type, data_size, @ptrCast(payload))) { switch (self._set_data(self, data_type, data_size, @ptrCast(payload))) {
@ -64,8 +64,8 @@ pub const Ip6Config = extern struct {
pub fn getData( pub fn getData(
self: *const Ip6Config, self: *const Ip6Config,
comptime data_type: std.meta.Tag(DataType), comptime data_type: std.meta.Tag(DataType),
) GetDataError!std.meta.TagPayload(DataType, data_type) { ) GetDataError!@FieldType(DataType, @tagName(data_type)) {
const DataPayload = std.meta.TagPayload(DataType, data_type); const DataPayload = @FieldType(DataType, @tagName(data_type));
var payload: DataPayload = undefined; var payload: DataPayload = undefined;
var payload_size: usize = @sizeOf(DataPayload); var payload_size: usize = @sizeOf(DataPayload);

View file

@ -536,7 +536,7 @@ test "sigset empty/full" {
var set: posix.sigset_t = posix.sigemptyset(); var set: posix.sigset_t = posix.sigemptyset();
for (1..posix.NSIG) |i| { for (1..posix.NSIG) |i| {
const sig = std.meta.intToEnum(posix.SIG, i) catch continue; const sig = std.enums.fromInt(posix.SIG, i) orelse continue;
try expectEqual(false, posix.sigismember(&set, sig)); try expectEqual(false, posix.sigismember(&set, sig));
} }
@ -565,29 +565,29 @@ test "sigset add/del" {
// See that none are set, then set each one, see that they're all set, then // See that none are set, then set each one, see that they're all set, then
// remove them all, and then see that none are set. // remove them all, and then see that none are set.
for (1..posix.NSIG) |i| { for (1..posix.NSIG) |i| {
const sig = std.meta.intToEnum(posix.SIG, i) catch continue; const sig = std.enums.fromInt(posix.SIG, i) orelse continue;
try expectEqual(false, posix.sigismember(&sigset, sig)); try expectEqual(false, posix.sigismember(&sigset, sig));
} }
for (1..posix.NSIG) |i| { for (1..posix.NSIG) |i| {
if (!reserved_signo(i)) { if (!reserved_signo(i)) {
const sig = std.meta.intToEnum(posix.SIG, i) catch continue; const sig = std.enums.fromInt(posix.SIG, i) orelse continue;
posix.sigaddset(&sigset, sig); posix.sigaddset(&sigset, sig);
} }
} }
for (1..posix.NSIG) |i| { for (1..posix.NSIG) |i| {
if (!reserved_signo(i)) { if (!reserved_signo(i)) {
const sig = std.meta.intToEnum(posix.SIG, i) catch continue; const sig = std.enums.fromInt(posix.SIG, i) orelse continue;
try expectEqual(true, posix.sigismember(&sigset, sig)); try expectEqual(true, posix.sigismember(&sigset, sig));
} }
} }
for (1..posix.NSIG) |i| { for (1..posix.NSIG) |i| {
if (!reserved_signo(i)) { if (!reserved_signo(i)) {
const sig = std.meta.intToEnum(posix.SIG, i) catch continue; const sig = std.enums.fromInt(posix.SIG, i) orelse continue;
posix.sigdelset(&sigset, sig); posix.sigdelset(&sigset, sig);
} }
} }
for (1..posix.NSIG) |i| { for (1..posix.NSIG) |i| {
const sig = std.meta.intToEnum(posix.SIG, i) catch continue; const sig = std.enums.fromInt(posix.SIG, i) orelse continue;
try expectEqual(false, posix.sigismember(&sigset, sig)); try expectEqual(false, posix.sigismember(&sigset, sig));
} }
} }

View file

@ -1148,7 +1148,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime
} else |err| switch (err) { } else |err| switch (err) {
error.OutOfMemory => { error.OutOfMemory => {
if (failing_allocator_inst.allocated_bytes != failing_allocator_inst.freed_bytes) { if (failing_allocator_inst.allocated_bytes != failing_allocator_inst.freed_bytes) {
const tty_config = std.Io.tty.detectConfig(.stderr()); const tty_config: std.Io.tty.Config = .detect(.stderr());
print( print(
"\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\nallocation that was made to fail: {f}", "\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\nallocation that was made to fail: {f}",
.{ .{

View file

@ -21,7 +21,7 @@ pub fn build(b: *std.Build) void {
}, },
); );
const check_config_header = b.addCheckFile(config_header.getOutput(), .{ .expected_exact = @embedFile("config.h") }); const check_config_header = b.addCheckFile(config_header.getOutputFile(), .{ .expected_exact = @embedFile("config.h") });
const test_step = b.step("test", "Test it"); const test_step = b.step("test", "Test it");
test_step.dependOn(&check_config_header.step); test_step.dependOn(&check_config_header.step);

View file

@ -9,9 +9,9 @@ pub fn build(b: *std.Build) void {
}), }),
}); });
if (is_windows) { if (is_windows) {
test_obj.linkSystemLibrary("ntdll"); test_obj.root_module.linkSystemLibrary("ntdll", .{});
test_obj.linkSystemLibrary("kernel32"); test_obj.root_module.linkSystemLibrary("kernel32", .{});
test_obj.linkSystemLibrary("ws2_32"); test_obj.root_module.linkSystemLibrary("ws2_32", .{});
} }
const test_exe_mod = b.createModule(.{ const test_exe_mod = b.createModule(.{