diff options
| author | Tadeo Kondrak <me@tadeo.ca> | 2020-08-27 16:01:08 -0600 |
|---|---|---|
| committer | Tadeo Kondrak <me@tadeo.ca> | 2020-08-27 16:02:00 -0600 |
| commit | e4b61aa527f7ea06943bab720f672dd435b9dfba (patch) | |
| tree | 43e8b8e051ba5c0007d005334fb1cc408359f4aa /lib | |
| parent | 3c87872dc5d7574e0e845568dc753ec48cb0cba0 (diff) | |
| download | zig-e4b61aa527f7ea06943bab720f672dd435b9dfba.tar.gz zig-e4b61aa527f7ea06943bab720f672dd435b9dfba.zip | |
std.meta.TrailerFlags fixes
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/meta/trailer_flags.zig | 24 | ||||
| -rw-r--r-- | lib/std/zig/ast.zig | 2 |
2 files changed, 12 insertions, 14 deletions
diff --git a/lib/std/meta/trailer_flags.zig b/lib/std/meta/trailer_flags.zig index 630400dcb5..19f6ee2e80 100644 --- a/lib/std/meta/trailer_flags.zig +++ b/lib/std/meta/trailer_flags.zig @@ -22,16 +22,14 @@ pub fn TrailerFlags(comptime Fields: type) type { pub const bit_count = @typeInfo(Fields).Struct.fields.len; pub const FieldEnum = blk: { - comptime var fields: []const TypeInfo.EnumField = &[_]TypeInfo.EnumField{}; - inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| { - const field = TypeInfo.EnumField{ .name = struct_field.name, .value = i }; - fields = fields ++ [_]TypeInfo.EnumField{field}; - } + comptime var fields: [bit_count]TypeInfo.EnumField = undefined; + inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| + fields[i] = .{ .name = struct_field.name, .value = i }; break :blk @Type(.{ .Enum = .{ .layout = .Auto, .tag_type = std.math.IntFittingRange(0, bit_count - 1), - .fields = fields, + .fields = &fields, .decls = &[_]TypeInfo.Declaration{}, .is_exhaustive = true, }, @@ -39,19 +37,21 @@ pub fn TrailerFlags(comptime Fields: type) type { }; pub const InitStruct = blk: { - comptime var fields: []const TypeInfo.StructField = &[_]TypeInfo.StructField{}; + comptime var fields: [bit_count]TypeInfo.StructField = undefined; inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| { - const field = TypeInfo.StructField{ + fields[i] = TypeInfo.StructField{ .name = struct_field.name, .field_type = ?struct_field.field_type, - .default_value = @as(??struct_field.field_type, @as(?struct_field.field_type, null)), + .default_value = @as( + ??struct_field.field_type, + @as(?struct_field.field_type, null), + ), }; - fields = fields ++ [_]TypeInfo.StructField{field}; } break :blk @Type(.{ .Struct = .{ .layout = .Auto, - .fields = fields, + .fields = &fields, .decls = &[_]TypeInfo.Declaration{}, .is_tuple = false, }, @@ -77,7 +77,6 @@ pub fn TrailerFlags(comptime Fields: type) type { } /// `fields` is a struct with each field set to an optional value. - /// Missing fields are assumed to be `null`. /// Only the non-null bits are observed and are used to set the flag bits. pub fn init(fields: InitStruct) Self { var self: Self = .{ .bits = 0 }; @@ -89,7 +88,6 @@ pub fn TrailerFlags(comptime Fields: type) type { } /// `fields` is a struct with each field set to an optional value (same as `init`). - /// Missing fields are assumed to be `null`. pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: InitStruct) void { inline for (@typeInfo(Fields).Struct.fields) |field, i| { if (@field(fields, field.name)) |value| diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index 4bbf6f4381..c235c92585 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -1321,7 +1321,7 @@ pub const Node = struct { self, self.trailer_flags.bits, self.getTrailer(.name_token), - self.trailer_flags.ptrConst(trailers_start, "name_token"), + self.trailer_flags.ptrConst(trailers_start, .name_token), self.params_len, }); } |
