authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-16 12:30:24-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-16 12:34:42-08:00
log790d28d6cd9029805af857d56645a6ce191bfe91
treec382578db89fed7fde266d1b7ecf43d72d1c6ace
parent081888286bcee495c4b9c3a9e45db6485c6bd367

std.testing: delete refAllDeclsRecursive

suggested alternatives: - actual tests - explicitly list the decls - compile an example application that uses the API - stop worrying about dead code - refAllDecls (non recursive) in each file Don't fight the laziness, embrace it. closes #23608 closes #30813

3 files changed, 2 insertions(+), 18 deletions(-)

lib/std/os/uefi/protocol.zig+1-2
...@@ -53,6 +53,5 @@ pub const HiiDatabase = @import("protocol/hii_database.zig").HiiDatabase;...@@ -53,6 +53,5 @@ pub const HiiDatabase = @import("protocol/hii_database.zig").HiiDatabase;
53pub const HiiPopup = @import("protocol/hii_popup.zig").HiiPopup;53pub const HiiPopup = @import("protocol/hii_popup.zig").HiiPopup;
5454
55test {55test {
56 @setEvalBranchQuota(2000);56 std.testing.refAllDecls(@This());
57 @import("std").testing.refAllDeclsRecursive(@This());
58}57}
lib/std/os/uefi/tables.zig+1-1
...@@ -305,5 +305,5 @@ pub const global_variable = Guid{...@@ -305,5 +305,5 @@ pub const global_variable = Guid{
305};305};
306306
307test {307test {
308 std.testing.refAllDeclsRecursive(@This());308 std.testing.refAllDecls(@This());
309}309}
lib/std/testing.zig-15
...@@ -1200,21 +1200,6 @@ pub fn refAllDecls(comptime T: type) void {...@@ -1200,21 +1200,6 @@ pub fn refAllDecls(comptime T: type) void {
1200 }1200 }
1201}1201}
12021202
1203/// Given a type, recursively references all the declarations inside, so that the semantic analyzer sees them.
1204/// For deep types, you may use `@setEvalBranchQuota`.
1205pub fn refAllDeclsRecursive(comptime T: type) void {
1206 if (!builtin.is_test) return;
1207 inline for (comptime std.meta.declarations(T)) |decl| {
1208 if (@TypeOf(@field(T, decl.name)) == type) {
1209 switch (@typeInfo(@field(T, decl.name))) {
1210 .@"struct", .@"enum", .@"union", .@"opaque" => refAllDeclsRecursive(@field(T, decl.name)),
1211 else => {},
1212 }
1213 }
1214 _ = &@field(T, decl.name);
1215 }
1216}
1217
1218pub const FuzzInputOptions = struct {1203pub const FuzzInputOptions = struct {
1219 corpus: []const []const u8 = &.{},1204 corpus: []const []const u8 = &.{},
1220};1205};