authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-11-30 13:22:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-11-30 13:22:04-07:00
logabd9089aa6f1003a0bb474ac9e8969015e8808bd
treeae4a6e178b7218adff0c1a82506f23e489b68db1
parent747f64b3fbfdbfda9aea184bbc1b534bacc78eac

std.build: simpler fix to options implementation

Instead of messing with ArrayList and more logic, just unwrap the error of toOwnedSlice().

1 files changed, 3 insertions(+), 3 deletions(-)

lib/std/build.zig+3-3
......@@ -523,7 +523,7 @@ pub const Builder = struct {
523523 const name = self.dupe(name_raw);
524524 const description = self.dupe(description_raw);
525525 const type_id = comptime typeToEnum(T);
526 const enum_options: ?ArrayList([]const u8) = if (type_id == .@"enum") blk: {
526 const enum_options = if (type_id == .@"enum") blk: {
527527 const fields = comptime std.meta.fields(T);
528528 var options = ArrayList([]const u8).initCapacity(self.allocator, fields.len) catch unreachable;
529529
......@@ -531,13 +531,13 @@ pub const Builder = struct {
531531 options.appendAssumeCapacity(field.name);
532532 }
533533
534 break :blk options;
534 break :blk options.toOwnedSlice() catch unreachable;
535535 } else null;
536536 const available_option = AvailableOption{
537537 .name = name,
538538 .type_id = type_id,
539539 .description = description,
540 .enum_options = if (enum_options) |options| options.items else null,
540 .enum_options = enum_options,
541541 };
542542 if ((self.available_options_map.fetchPut(name, available_option) catch unreachable) != null) {
543543 panic("Option '{s}' declared twice", .{name});