diff --git a/source/command.zig b/source/command.zig index e9a2c8c..39845a0 100644 --- a/source/command.zig +++ b/source/command.zig @@ -297,15 +297,15 @@ pub fn CommandBuilder(comptime UserContext: type) type { if (PType.is_flag) { var peek = idx + 1; var bias_seen: [ncmeta.enum_length(FlagBias)]bool = [_]bool{false} ** ncmeta.enum_length(FlagBias); - bias_seen[@enumToInt(param.flag_bias)] = true; + bias_seen[@intFromEnum(param.flag_bias)] = true; while (peek < spec.len) : (peek += 1) { const peek_param = spec[peek]; if (@TypeOf(peek_param).is_flag and std.mem.eql(u8, param.name, peek_param.name)) { - if (bias_seen[@enumToInt(peek_param.flag_bias)] == true) { + if (bias_seen[@intFromEnum(peek_param.flag_bias)] == true) { @compileError("redundant flag!!!! " ++ param.name); } else { - bias_seen[@enumToInt(peek_param.flag_bias)] = true; + bias_seen[@intFromEnum(peek_param.flag_bias)] = true; } flag_skip += 1; } else { @@ -372,15 +372,15 @@ pub fn CommandBuilder(comptime UserContext: type) type { if (PType.is_flag) { var peek = idx + 1; var bias_seen: [ncmeta.enum_length(FlagBias)]bool = [_]bool{false} ** ncmeta.enum_length(FlagBias); - bias_seen[@enumToInt(param.flag_bias)] = true; + bias_seen[@intFromEnum(param.flag_bias)] = true; while (peek < spec.len) : (peek += 1) { const peek_param = spec[peek]; if (@TypeOf(peek_param).is_flag and std.mem.eql(u8, param.name, peek_param.name)) { - if (bias_seen[@enumToInt(peek_param.flag_bias)] == true) { + if (bias_seen[@intFromEnum(peek_param.flag_bias)] == true) { @compileError("redundant flag!!!! " ++ param.name); } else { - bias_seen[@enumToInt(peek_param.flag_bias)] = true; + bias_seen[@intFromEnum(peek_param.flag_bias)] = true; } flag_skip += 1; } else { @@ -397,13 +397,10 @@ pub fn CommandBuilder(comptime UserContext: type) type { fields = &(@as([fields.len]StructField, fields[0..fields.len].*) ++ [1]StructField{.{ .name = param.name, .type = FieldType, - .default_value = @ptrCast( - ?*const anyopaque, - &@as( - FieldType, - if (PType.value_count == .count) 0 else null, - ), - ), + .default_value = @ptrCast(&@as( + FieldType, + if (PType.value_count == .count) 0 else null, + )), .is_comptime = false, .alignment = @alignOf(?[]const u8), }}); diff --git a/source/meta.zig b/source/meta.zig index 752671b..027564e 100644 --- a/source/meta.zig +++ b/source/meta.zig @@ -30,7 +30,7 @@ pub fn UpdateDefaults(comptime input: type, comptime defaults: anytype) type { // the appropriate type, which is nice for ergonomics. Not sure // if it introduces weird edge cases. Probably it's fine? .default_value = if (@hasField(@TypeOf(defaults), field.name)) - @ptrCast(?*const anyopaque, &@as(field.field_type, @field(defaults, field.name))) + @ptrCast(&@as(field.field_type, @field(defaults, field.name))) else field.default_value, .is_comptime = field.is_comptime, @@ -203,7 +203,7 @@ pub const TupleBuilder = struct { } pub fn retrieve(comptime self: @This(), comptime index: comptime_int) self.types[index] { - return @ptrCast(*const self.types[index], @alignCast(@alignOf(*const self.types[index]), self.pointers[index])).*; + return @as(*const self.types[index], @ptrCast(@alignCast(self.pointers[index]))).*; } pub fn realTuple(comptime self: @This()) self.TupleType() { diff --git a/source/parser.zig b/source/parser.zig index fb4697b..4054280 100644 --- a/source/parser.zig +++ b/source/parser.zig @@ -60,7 +60,7 @@ fn InterfaceGen(comptime ParserType: type, comptime UserContext: type) type { pub fn interface(self: *ParserType, context: UserContext) ParserInterface { return .{ .parser = self, - .context = @ptrCast(*anyopaque, @constCast(context)), + .context = @ptrCast(@constCast(context)), .methods = &.{ .execute = ParserType.wrap_execute, .parse = ParserType.wrap_parse, @@ -71,13 +71,13 @@ fn InterfaceGen(comptime ParserType: type, comptime UserContext: type) type { } fn cast_context(ctx: *anyopaque) UserContext { - return @ptrCast(UserContext, @alignCast(std.meta.alignment(UserContext), ctx)); + return @ptrCast(@alignCast(ctx)); } } else struct { pub fn interface(self: *ParserType, context: *const UserContext) ParserInterface { return .{ .parser = self, - .context = @ptrCast(*anyopaque, @constCast(context)), + .context = @ptrCast(@constCast(context)), .methods = &.{ .execute = ParserType.wrap_execute, .parse = ParserType.wrap_parse, @@ -88,7 +88,7 @@ fn InterfaceGen(comptime ParserType: type, comptime UserContext: type) type { } fn cast_context(ctx: *anyopaque) UserContext { - return @ptrCast(*const UserContext, @alignCast(@alignOf(UserContext), ctx)).*; + return @as(*const UserContext, @ptrCast(@alignCast(ctx))).*; } }; } @@ -124,7 +124,7 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type { pub usingnamespace Interface; inline fn cast_interface_parser(parser: *anyopaque) *@This() { - return @ptrCast(*@This(), @alignCast(@alignOf(@This()), parser)); + return @ptrCast(@alignCast(parser)); } fn wrap_execute(parser: *anyopaque, ctx: *anyopaque) anyerror!void {