mirror of
https://github.com/ziglang/zig.git
synced 2024-12-13 14:47:09 +00:00
HashMap.put returns !void, not a !bool
This commit is contained in:
parent
490654c332
commit
d4af35b3fe
@ -32,7 +32,7 @@ pub const BufSet = struct {
|
||||
if (self.hash_map.get(key) == null) {
|
||||
const key_copy = try self.copy(key);
|
||||
errdefer self.free(key_copy);
|
||||
_ = try self.hash_map.put(key_copy, {});
|
||||
try self.hash_map.put(key_copy, {});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -790,7 +790,7 @@ pub const Builder = struct {
|
||||
var list = ArrayList([]const u8).init(self.allocator);
|
||||
list.append(s) catch unreachable;
|
||||
list.append(value) catch unreachable;
|
||||
_ = self.user_input_options.put(name, UserInputOption{
|
||||
self.user_input_options.put(name, UserInputOption{
|
||||
.name = name,
|
||||
.value = UserValue{ .List = list },
|
||||
.used = false,
|
||||
@ -799,7 +799,7 @@ pub const Builder = struct {
|
||||
UserValue.List => |*list| {
|
||||
// append to the list
|
||||
list.append(value) catch unreachable;
|
||||
_ = self.user_input_options.put(name, UserInputOption{
|
||||
self.user_input_options.put(name, UserInputOption{
|
||||
.name = name,
|
||||
.value = UserValue{ .List = list.* },
|
||||
.used = false,
|
||||
|
@ -563,7 +563,6 @@ pub fn HashMapUnmanaged(
|
||||
}
|
||||
|
||||
/// Insert an entry if the associated key is not already present, otherwise update preexisting value.
|
||||
/// Returns true if the key was already present.
|
||||
pub fn put(self: *Self, allocator: *Allocator, key: K, value: V) !void {
|
||||
const result = try self.getOrPut(allocator, key);
|
||||
result.entry.value = value;
|
||||
@ -1116,7 +1115,7 @@ test "std.hash_map put" {
|
||||
|
||||
var i: u32 = 0;
|
||||
while (i < 16) : (i += 1) {
|
||||
_ = try map.put(i, i);
|
||||
try map.put(i, i);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
@ -2077,27 +2077,27 @@ pub const Parser = struct {
|
||||
p.state = .ArrayValue;
|
||||
},
|
||||
.String => |s| {
|
||||
_ = try object.put(key, try p.parseString(allocator, s, input, i));
|
||||
try object.put(key, try p.parseString(allocator, s, input, i));
|
||||
_ = p.stack.pop();
|
||||
p.state = .ObjectKey;
|
||||
},
|
||||
.Number => |n| {
|
||||
_ = try object.put(key, try p.parseNumber(n, input, i));
|
||||
try object.put(key, try p.parseNumber(n, input, i));
|
||||
_ = p.stack.pop();
|
||||
p.state = .ObjectKey;
|
||||
},
|
||||
.True => {
|
||||
_ = try object.put(key, Value{ .Bool = true });
|
||||
try object.put(key, Value{ .Bool = true });
|
||||
_ = p.stack.pop();
|
||||
p.state = .ObjectKey;
|
||||
},
|
||||
.False => {
|
||||
_ = try object.put(key, Value{ .Bool = false });
|
||||
try object.put(key, Value{ .Bool = false });
|
||||
_ = p.stack.pop();
|
||||
p.state = .ObjectKey;
|
||||
},
|
||||
.Null => {
|
||||
_ = try object.put(key, Value.Null);
|
||||
try object.put(key, Value.Null);
|
||||
_ = p.stack.pop();
|
||||
p.state = .ObjectKey;
|
||||
},
|
||||
@ -2184,7 +2184,7 @@ pub const Parser = struct {
|
||||
_ = p.stack.pop();
|
||||
|
||||
var object = &p.stack.items[p.stack.items.len - 1].Object;
|
||||
_ = try object.put(key, value.*);
|
||||
try object.put(key, value.*);
|
||||
p.state = .ObjectKey;
|
||||
},
|
||||
// Array Parent -> [ ..., <array>, value ]
|
||||
|
@ -293,7 +293,7 @@ test "json write stream" {
|
||||
|
||||
fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value {
|
||||
var value = std.json.Value{ .Object = std.json.ObjectMap.init(allocator) };
|
||||
_ = try value.Object.put("one", std.json.Value{ .Integer = @intCast(i64, 1) });
|
||||
_ = try value.Object.put("two", std.json.Value{ .Float = 2.0 });
|
||||
try value.Object.put("one", std.json.Value{ .Integer = @intCast(i64, 1) });
|
||||
try value.Object.put("two", std.json.Value{ .Float = 2.0 });
|
||||
return value;
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ test "std.PriorityQueue: iterator" {
|
||||
const items = [_]u32{ 54, 12, 7, 23, 25, 13 };
|
||||
for (items) |e| {
|
||||
_ = try queue.add(e);
|
||||
_ = try map.put(e, {});
|
||||
try map.put(e, {});
|
||||
}
|
||||
|
||||
var it = queue.iterator();
|
||||
|
@ -2165,7 +2165,7 @@ pub fn freeDecl(self: *Elf, decl: *Module.Decl) void {
|
||||
// is desired for both.
|
||||
_ = self.dbg_line_fn_free_list.remove(&decl.fn_link.elf);
|
||||
if (decl.fn_link.elf.prev) |prev| {
|
||||
_ = self.dbg_line_fn_free_list.put(self.base.allocator, prev, {}) catch {};
|
||||
self.dbg_line_fn_free_list.put(self.base.allocator, prev, {}) catch {};
|
||||
prev.next = decl.fn_link.elf.next;
|
||||
if (decl.fn_link.elf.next) |next| {
|
||||
next.prev = prev;
|
||||
@ -2423,7 +2423,7 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void {
|
||||
if (src_fn.off + src_fn.len + min_nop_size > next.off) {
|
||||
// It grew too big, so we move it to a new location.
|
||||
if (src_fn.prev) |prev| {
|
||||
_ = self.dbg_line_fn_free_list.put(self.base.allocator, prev, {}) catch {};
|
||||
self.dbg_line_fn_free_list.put(self.base.allocator, prev, {}) catch {};
|
||||
prev.next = src_fn.next;
|
||||
}
|
||||
assert(src_fn.prev != next);
|
||||
@ -2579,7 +2579,7 @@ fn updateDeclDebugInfoAllocation(self: *Elf, text_block: *TextBlock, len: u32) !
|
||||
if (text_block.dbg_info_off + text_block.dbg_info_len + min_nop_size > next.dbg_info_off) {
|
||||
// It grew too big, so we move it to a new location.
|
||||
if (text_block.dbg_info_prev) |prev| {
|
||||
_ = self.dbg_info_decl_free_list.put(self.base.allocator, prev, {}) catch {};
|
||||
self.dbg_info_decl_free_list.put(self.base.allocator, prev, {}) catch {};
|
||||
prev.dbg_info_next = text_block.dbg_info_next;
|
||||
}
|
||||
next.dbg_info_prev = text_block.dbg_info_prev;
|
||||
|
@ -1096,7 +1096,7 @@ pub fn commitDeclDebugInfo(
|
||||
if (src_fn.off + src_fn.len + min_nop_size > next.off) {
|
||||
// It grew too big, so we move it to a new location.
|
||||
if (src_fn.prev) |prev| {
|
||||
_ = self.dbg_line_fn_free_list.put(allocator, prev, {}) catch {};
|
||||
self.dbg_line_fn_free_list.put(allocator, prev, {}) catch {};
|
||||
prev.next = src_fn.next;
|
||||
}
|
||||
next.prev = src_fn.prev;
|
||||
@ -1256,7 +1256,7 @@ fn updateDeclDebugInfoAllocation(
|
||||
if (text_block.dbg_info_off + text_block.dbg_info_len + min_nop_size > next.dbg_info_off) {
|
||||
// It grew too big, so we move it to a new location.
|
||||
if (text_block.dbg_info_prev) |prev| {
|
||||
_ = self.dbg_info_decl_free_list.put(allocator, prev, {}) catch {};
|
||||
self.dbg_info_decl_free_list.put(allocator, prev, {}) catch {};
|
||||
prev.dbg_info_next = text_block.dbg_info_next;
|
||||
}
|
||||
next.dbg_info_prev = text_block.dbg_info_prev;
|
||||
|
@ -119,7 +119,7 @@ fn analyzeInst(
|
||||
if (!else_table.contains(then_death)) {
|
||||
try else_entry_deaths.append(then_death);
|
||||
}
|
||||
_ = try table.put(then_death, {});
|
||||
try table.put(then_death, {});
|
||||
}
|
||||
}
|
||||
// Now we have to correctly populate new_set.
|
||||
@ -195,7 +195,7 @@ fn analyzeInst(
|
||||
}
|
||||
}
|
||||
// undo resetting the table
|
||||
_ = try table.put(case_death, {});
|
||||
try table.put(case_death, {});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -377,7 +377,7 @@ fn prepopulateGlobalNameTable(ast_unit: *clang.ASTUnit, c: *Context) !void {
|
||||
const macro = @ptrCast(*clang.MacroDefinitionRecord, entity);
|
||||
const raw_name = macro.getName_getNameStart();
|
||||
const name = try c.str(raw_name);
|
||||
_ = try c.global_names.put(c.gpa, name, {});
|
||||
try c.global_names.put(c.gpa, name, {});
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
@ -399,7 +399,7 @@ fn declVisitorC(context: ?*c_void, decl: *const clang.Decl) callconv(.C) bool {
|
||||
fn declVisitorNamesOnly(c: *Context, decl: *const clang.Decl) Error!void {
|
||||
if (decl.castToNamedDecl()) |named_decl| {
|
||||
const decl_name = try c.str(named_decl.getName_bytes_begin());
|
||||
_ = try c.global_names.put(c.gpa, decl_name, {});
|
||||
try c.global_names.put(c.gpa, decl_name, {});
|
||||
}
|
||||
}
|
||||
|
||||
@ -788,7 +788,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
|
||||
const is_pub = toplevel and !is_unnamed;
|
||||
const init_node = blk: {
|
||||
const record_def = record_decl.getDefinition() orelse {
|
||||
_ = try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});
|
||||
try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});
|
||||
break :blk Tag.opaque_literal.init();
|
||||
};
|
||||
|
||||
@ -805,13 +805,13 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
|
||||
const field_qt = field_decl.getType();
|
||||
|
||||
if (field_decl.isBitField()) {
|
||||
_ = try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});
|
||||
try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});
|
||||
try warn(c, scope, field_loc, "{s} demoted to opaque type - has bitfield", .{container_kind_name});
|
||||
break :blk Tag.opaque_literal.init();
|
||||
}
|
||||
|
||||
if (qualTypeCanon(field_qt).isIncompleteOrZeroLengthArrayType(c.clang_context)) {
|
||||
_ = try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});
|
||||
try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});
|
||||
try warn(c, scope, field_loc, "{s} demoted to opaque type - has variable length array", .{container_kind_name});
|
||||
break :blk Tag.opaque_literal.init();
|
||||
}
|
||||
@ -826,7 +826,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
|
||||
}
|
||||
const field_type = transQualType(c, scope, field_qt, field_loc) catch |err| switch (err) {
|
||||
error.UnsupportedType => {
|
||||
_ = try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});
|
||||
try c.opaque_demotes.put(c.gpa, @ptrToInt(record_decl.getCanonicalDecl()), {});
|
||||
try warn(c, scope, record_loc, "{s} demoted to opaque type - unable to translate type of field {s}", .{ container_kind_name, field_name });
|
||||
break :blk Tag.opaque_literal.init();
|
||||
},
|
||||
@ -972,7 +972,7 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E
|
||||
.fields = try c.arena.dupe(ast.Payload.Enum.Field, fields.items),
|
||||
});
|
||||
} else blk: {
|
||||
_ = try c.opaque_demotes.put(c.gpa, @ptrToInt(enum_decl.getCanonicalDecl()), {});
|
||||
try c.opaque_demotes.put(c.gpa, @ptrToInt(enum_decl.getCanonicalDecl()), {});
|
||||
break :blk Tag.opaque_literal.init();
|
||||
};
|
||||
|
||||
@ -3199,7 +3199,7 @@ fn maybeSuppressResult(
|
||||
}
|
||||
|
||||
fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: Node) !void {
|
||||
_ = try c.global_scope.sym_table.put(name, decl_node);
|
||||
try c.global_scope.sym_table.put(name, decl_node);
|
||||
try c.global_scope.nodes.append(decl_node);
|
||||
}
|
||||
|
||||
@ -4235,7 +4235,7 @@ fn transMacroDefine(c: *Context, m: *MacroCtx) ParseError!void {
|
||||
return m.fail(c, "unable to translate C expr: unexpected token .{s}", .{@tagName(last)});
|
||||
|
||||
const var_decl = try Tag.pub_var_simple.create(c.arena, .{ .name = m.name, .init = init_node });
|
||||
_ = try c.global_scope.macro_table.put(m.name, var_decl);
|
||||
try c.global_scope.macro_table.put(m.name, var_decl);
|
||||
}
|
||||
|
||||
fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void {
|
||||
@ -4294,7 +4294,7 @@ fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void {
|
||||
.return_type = return_type,
|
||||
.body = try block_scope.complete(c),
|
||||
});
|
||||
_ = try c.global_scope.macro_table.put(m.name, fn_decl);
|
||||
try c.global_scope.macro_table.put(m.name, fn_decl);
|
||||
}
|
||||
|
||||
const ParseError = Error || error{ParseError};
|
||||
|
@ -200,7 +200,7 @@ pub fn main() !void {
|
||||
continue;
|
||||
}
|
||||
if (std.mem.startsWith(u8, ver, "GCC_")) continue;
|
||||
_ = try global_ver_set.put(ver, undefined);
|
||||
try global_ver_set.put(ver, undefined);
|
||||
const gop = try global_fn_set.getOrPut(name);
|
||||
if (gop.found_existing) {
|
||||
if (!std.mem.eql(u8, gop.entry.value.lib, "c")) {
|
||||
@ -242,7 +242,7 @@ pub fn main() !void {
|
||||
var buffered = std.io.bufferedWriter(vers_txt_file.writer());
|
||||
const vers_txt = buffered.writer();
|
||||
for (global_ver_list) |name, i| {
|
||||
_ = global_ver_set.put(name, i) catch unreachable;
|
||||
global_ver_set.put(name, i) catch unreachable;
|
||||
try vers_txt.print("{s}\n", .{name});
|
||||
}
|
||||
try buffered.flush();
|
||||
|
Loading…
Reference in New Issue
Block a user