Skip to content

Commit 19ebd59

Browse files
committed
std.error_set: Avoid comptime dereference-related compile errors
e.g. `comptime dereference requires '[3]builtin.Type.Error' to have a well-defined layout, but it does not.`
1 parent 7f7d907 commit 19ebd59

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/std/error_set.zig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ pub fn Excluding(comptime BaseErrorSet: type, comptime ToExcludeErrorSet: type)
5656
remaining_error_count += 1;
5757
}
5858
}
59-
return @Type(.{ .ErrorSet = remaining_error_buffer[0..remaining_error_count] });
59+
var final_errors: [remaining_error_count]Type.Error = undefined;
60+
@memcpy(&final_errors, remaining_error_buffer[0..remaining_error_count]);
61+
const errors = final_errors;
62+
return @Type(.{ .ErrorSet = &errors });
6063
}
6164
test Excluding {
6265
comptime {
@@ -106,7 +109,10 @@ pub fn Intersect(comptime ErrorSetA: type, comptime ErrorSetB: type) type {
106109
remaining_error_count += 1;
107110
}
108111
}
109-
return @Type(.{ .ErrorSet = remaining_error_buffer[0..remaining_error_count] });
112+
var final_errors: [remaining_error_count]Type.Error = undefined;
113+
@memcpy(&final_errors, remaining_error_buffer[0..remaining_error_count]);
114+
const errors = final_errors;
115+
return @Type(.{ .ErrorSet = &errors });
110116
}
111117
test Intersect {
112118
comptime {

0 commit comments

Comments
 (0)