Commit 1cf1cb6ae0

Andrew Kelley <andrew@ziglang.org>
2024-05-24 19:34:29
std.debug.Trace: follow the struct default field guidance
1 parent a486392
Changed files (2)
lib/std/debug.zig
@@ -2759,13 +2759,19 @@ pub const Trace = ConfigurableTrace(2, 4, builtin.mode == .Debug);
 
 pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize, comptime is_enabled: bool) type {
     return struct {
-        addrs: [actual_size][stack_frame_count]usize = undefined,
-        notes: [actual_size][]const u8 = undefined,
-        index: Index = 0,
+        addrs: [actual_size][stack_frame_count]usize,
+        notes: [actual_size][]const u8,
+        index: Index,
 
         const actual_size = if (enabled) size else 0;
         const Index = if (enabled) usize else u0;
 
+        pub const init: @This() = .{
+            .addrs = undefined,
+            .notes = undefined,
+            .index = 0,
+        };
+
         pub const enabled = is_enabled;
 
         pub const add = if (enabled) addNoInline else addNoOp;
lib/std/zig.zig
@@ -718,7 +718,7 @@ pub const LazySrcLoc = union(enum) {
     /// where in semantic analysis the value got set.
     pub const TracedOffset = struct {
         x: i32,
-        trace: std.debug.Trace = .{},
+        trace: std.debug.Trace = std.debug.Trace.init,
 
         const want_tracing = false;
     };