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 {...@@ -523,7 +523,7 @@ pub const Builder = struct {
523 const name = self.dupe(name_raw);523 const name = self.dupe(name_raw);
524 const description = self.dupe(description_raw);524 const description = self.dupe(description_raw);
525 const type_id = comptime typeToEnum(T);525 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: {
527 const fields = comptime std.meta.fields(T);527 const fields = comptime std.meta.fields(T);
528 var options = ArrayList([]const u8).initCapacity(self.allocator, fields.len) catch unreachable;528 var options = ArrayList([]const u8).initCapacity(self.allocator, fields.len) catch unreachable;
529529
...@@ -531,13 +531,13 @@ pub const Builder = struct {...@@ -531,13 +531,13 @@ pub const Builder = struct {
531 options.appendAssumeCapacity(field.name);531 options.appendAssumeCapacity(field.name);
532 }532 }
533533
534 break :blk options;534 break :blk options.toOwnedSlice() catch unreachable;
535 } else null;535 } else null;
536 const available_option = AvailableOption{536 const available_option = AvailableOption{
537 .name = name,537 .name = name,
538 .type_id = type_id,538 .type_id = type_id,
539 .description = description,539 .description = description,
540 .enum_options = if (enum_options) |options| options.items else null,540 .enum_options = enum_options,
541 };541 };
542 if ((self.available_options_map.fetchPut(name, available_option) catch unreachable) != null) {542 if ((self.available_options_map.fetchPut(name, available_option) catch unreachable) != null) {
543 panic("Option '{s}' declared twice", .{name});543 panic("Option '{s}' declared twice", .{name});