aboutsummaryrefslogtreecommitdiff
path: root/lib/std/meta.zig
diff options
context:
space:
mode:
authorTadeo Kondrak <me@tadeo.ca>2021-01-11 11:19:24 -0700
committerVeikka Tuominen <git@vexu.eu>2021-01-30 22:26:44 +0200
commit0b5f3c2ef96df02341cdf54f6eefb3cdb88781d8 (patch)
tree1a9a37f1a5fc96b56044f74c186101d5ac862654 /lib/std/meta.zig
parent1637d8ac80b46599e276eb767208f54f0a30ccf0 (diff)
downloadzig-0b5f3c2ef96df02341cdf54f6eefb3cdb88781d8.tar.gz
zig-0b5f3c2ef96df02341cdf54f6eefb3cdb88781d8.zip
Replace @TagType uses, mostly with std.meta.Tag
Diffstat (limited to 'lib/std/meta.zig')
-rw-r--r--lib/std/meta.zig10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/std/meta.zig b/lib/std/meta.zig
index 9a1215e79b..30f69ae9a5 100644
--- a/lib/std/meta.zig
+++ b/lib/std/meta.zig
@@ -606,7 +606,7 @@ pub const TagType = Tag;
pub fn Tag(comptime T: type) type {
return switch (@typeInfo(T)) {
.Enum => |info| info.tag_type,
- .Union => |info| if (info.tag_type) |TheTag| TheTag else null,
+ .Union => |info| info.tag_type orelse @compileError(@typeName(T) ++ " has no tag type"),
else => @compileError("expected enum or union type, found '" ++ @typeName(T) ++ "'"),
};
}
@@ -626,9 +626,9 @@ test "std.meta.Tag" {
}
///Returns the active tag of a tagged union
-pub fn activeTag(u: anytype) @TagType(@TypeOf(u)) {
+pub fn activeTag(u: anytype) Tag(@TypeOf(u)) {
const T = @TypeOf(u);
- return @as(@TagType(T), u);
+ return @as(Tag(T), u);
}
test "std.meta.activeTag" {
@@ -653,11 +653,11 @@ const TagPayloadType = TagPayload;
///Given a tagged union type, and an enum, return the type of the union
/// field corresponding to the enum tag.
-pub fn TagPayload(comptime U: type, tag: @TagType(U)) type {
+pub fn TagPayload(comptime U: type, tag: Tag(U)) type {
testing.expect(trait.is(.Union)(U));
const info = @typeInfo(U).Union;
- const tag_info = @typeInfo(@TagType(U)).Enum;
+ const tag_info = @typeInfo(Tag(U)).Enum;
inline for (info.fields) |field_info| {
if (comptime mem.eql(u8, field_info.name, @tagName(tag)))