aboutsummaryrefslogtreecommitdiff
path: root/lib/std/meta.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-02-02 13:39:27 -0500
committerGitHub <noreply@github.com>2022-02-02 13:39:27 -0500
commit3eb8d01f522cf23d484411794ac10777b3de1cfa (patch)
treeadcd72ca78f4b72e5bc2e20a2af68c3ce011ee14 /lib/std/meta.zig
parentf95fcb2b1fadb34588f727f22b4d5ed07cd73d5e (diff)
parent449554a7307731047fcd9c132386fdf405c3b237 (diff)
downloadzig-3eb8d01f522cf23d484411794ac10777b3de1cfa.tar.gz
zig-3eb8d01f522cf23d484411794ac10777b3de1cfa.zip
Merge pull request #10766 from ziglang/yeet-anytype-fields
remove anytype fields from the language
Diffstat (limited to 'lib/std/meta.zig')
-rw-r--r--lib/std/meta.zig21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/std/meta.zig b/lib/std/meta.zig
index 72a073fbfb..03825e2140 100644
--- a/lib/std/meta.zig
+++ b/lib/std/meta.zig
@@ -190,12 +190,21 @@ test "std.meta.Elem" {
/// Types which cannot possibly have a sentinel will be a compile error.
pub fn sentinel(comptime T: type) ?Elem(T) {
switch (@typeInfo(T)) {
- .Array => |info| return info.sentinel,
+ .Array => |info| {
+ const sentinel_ptr = info.sentinel orelse return null;
+ return @ptrCast(*const info.child, sentinel_ptr).*;
+ },
.Pointer => |info| {
switch (info.size) {
- .Many, .Slice => return info.sentinel,
+ .Many, .Slice => {
+ const sentinel_ptr = info.sentinel orelse return null;
+ return @ptrCast(*const info.child, sentinel_ptr).*;
+ },
.One => switch (@typeInfo(info.child)) {
- .Array => |array_info| return array_info.sentinel,
+ .Array => |array_info| {
+ const sentinel_ptr = array_info.sentinel orelse return null;
+ return @ptrCast(*const array_info.child, sentinel_ptr).*;
+ },
else => {},
},
else => {},
@@ -239,7 +248,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
.Array = .{
.len = array_info.len,
.child = array_info.child,
- .sentinel = sentinel_val,
+ .sentinel = &sentinel_val,
},
}),
.is_allowzero = info.is_allowzero,
@@ -257,7 +266,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
.address_space = info.address_space,
.child = info.child,
.is_allowzero = info.is_allowzero,
- .sentinel = sentinel_val,
+ .sentinel = &sentinel_val,
},
}),
else => {},
@@ -275,7 +284,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
.address_space = ptr_info.address_space,
.child = ptr_info.child,
.is_allowzero = ptr_info.is_allowzero,
- .sentinel = sentinel_val,
+ .sentinel = &sentinel_val,
},
}),
},