diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-11-30 13:22:04 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-11-30 13:22:04 -0700 |
| commit | abd9089aa6f1003a0bb474ac9e8969015e8808bd (patch) | |
| tree | ae4a6e178b7218adff0c1a82506f23e489b68db1 /lib/std | |
| parent | 747f64b3fbfdbfda9aea184bbc1b534bacc78eac (diff) | |
| download | zig-abd9089aa6f1003a0bb474ac9e8969015e8808bd.tar.gz zig-abd9089aa6f1003a0bb474ac9e8969015e8808bd.zip | |
std.build: simpler fix to options implementation
Instead of messing with ArrayList and more logic, just unwrap the error
of toOwnedSlice().
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/build.zig | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig index 792a14d471..f53dcc3632 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -523,7 +523,7 @@ pub const Builder = struct { const name = self.dupe(name_raw); const description = self.dupe(description_raw); const type_id = comptime typeToEnum(T); - const enum_options: ?ArrayList([]const u8) = if (type_id == .@"enum") blk: { + const enum_options = if (type_id == .@"enum") blk: { const fields = comptime std.meta.fields(T); var options = ArrayList([]const u8).initCapacity(self.allocator, fields.len) catch unreachable; @@ -531,13 +531,13 @@ pub const Builder = struct { options.appendAssumeCapacity(field.name); } - break :blk options; + break :blk options.toOwnedSlice() catch unreachable; } else null; const available_option = AvailableOption{ .name = name, .type_id = type_id, .description = description, - .enum_options = if (enum_options) |options| options.items else null, + .enum_options = enum_options, }; if ((self.available_options_map.fetchPut(name, available_option) catch unreachable) != null) { panic("Option '{s}' declared twice", .{name}); |
