diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-06-24 16:58:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-24 16:58:19 -0700 |
| commit | 146b79af153bbd5dafda0ba12a040385c7fc58f8 (patch) | |
| tree | 67e3db8b444d65c667e314770fc983a7fc8ba293 /lib/std/event | |
| parent | 13853bef0df3c90633021850cc6d6abaeea03282 (diff) | |
| parent | 21ac0beb436f49fe49c6982a872f2dc48e4bea5e (diff) | |
| download | zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.tar.gz zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.zip | |
Merge pull request #16163 from mlugg/feat/builtins-infer-dest-ty
Infer destination type of cast builtins using result type
Diffstat (limited to 'lib/std/event')
| -rw-r--r-- | lib/std/event/lock.zig | 6 | ||||
| -rw-r--r-- | lib/std/event/loop.zig | 12 | ||||
| -rw-r--r-- | lib/std/event/rwlock.zig | 8 |
3 files changed, 13 insertions, 13 deletions
diff --git a/lib/std/event/lock.zig b/lib/std/event/lock.zig index 9da3943d5d..8608298c29 100644 --- a/lib/std/event/lock.zig +++ b/lib/std/event/lock.zig @@ -55,7 +55,7 @@ pub const Lock = struct { const head = switch (self.head) { UNLOCKED => unreachable, LOCKED => null, - else => @ptrFromInt(*Waiter, self.head), + else => @as(*Waiter, @ptrFromInt(self.head)), }; if (head) |h| { @@ -102,7 +102,7 @@ pub const Lock = struct { break :blk null; }, else => { - const waiter = @ptrFromInt(*Waiter, self.lock.head); + const waiter = @as(*Waiter, @ptrFromInt(self.lock.head)); self.lock.head = if (waiter.next == null) LOCKED else @intFromPtr(waiter.next); if (waiter.next) |next| next.tail = waiter.tail; @@ -130,7 +130,7 @@ test "std.event.Lock" { var lock = Lock{}; testLock(&lock); - const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len; + const expected_result = [1]i32{3 * @as(i32, @intCast(shared_test_data.len))} ** shared_test_data.len; try testing.expectEqualSlices(i32, &expected_result, &shared_test_data); } fn testLock(lock: *Lock) void { diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index 7eec26a2b1..b5021a5378 100644 --- a/lib/std/event/loop.zig +++ b/lib/std/event/loop.zig @@ -556,7 +556,7 @@ pub const Loop = struct { self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.IN); }, .macos, .ios, .tvos, .watchos, .freebsd, .netbsd, .dragonfly, .openbsd => { - self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_READ, os.system.EV_ONESHOT); + self.bsdWaitKev(@as(usize, @intCast(fd)), os.system.EVFILT_READ, os.system.EV_ONESHOT); }, else => @compileError("Unsupported OS"), } @@ -568,7 +568,7 @@ pub const Loop = struct { self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.OUT); }, .macos, .ios, .tvos, .watchos, .freebsd, .netbsd, .dragonfly, .openbsd => { - self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_WRITE, os.system.EV_ONESHOT); + self.bsdWaitKev(@as(usize, @intCast(fd)), os.system.EVFILT_WRITE, os.system.EV_ONESHOT); }, else => @compileError("Unsupported OS"), } @@ -580,8 +580,8 @@ pub const Loop = struct { self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.OUT | os.linux.EPOLL.IN); }, .macos, .ios, .tvos, .watchos, .freebsd, .netbsd, .dragonfly, .openbsd => { - self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_READ, os.system.EV_ONESHOT); - self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_WRITE, os.system.EV_ONESHOT); + self.bsdWaitKev(@as(usize, @intCast(fd)), os.system.EVFILT_READ, os.system.EV_ONESHOT); + self.bsdWaitKev(@as(usize, @intCast(fd)), os.system.EVFILT_WRITE, os.system.EV_ONESHOT); }, else => @compileError("Unsupported OS"), } @@ -1415,7 +1415,7 @@ pub const Loop = struct { var events: [1]os.linux.epoll_event = undefined; const count = os.epoll_wait(self.os_data.epollfd, events[0..], -1); for (events[0..count]) |ev| { - const resume_node = @ptrFromInt(*ResumeNode, ev.data.ptr); + const resume_node = @as(*ResumeNode, @ptrFromInt(ev.data.ptr)); const handle = resume_node.handle; const resume_node_id = resume_node.id; switch (resume_node_id) { @@ -1439,7 +1439,7 @@ pub const Loop = struct { const empty_kevs = &[0]os.Kevent{}; const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable; for (eventlist[0..count]) |ev| { - const resume_node = @ptrFromInt(*ResumeNode, ev.udata); + const resume_node = @as(*ResumeNode, @ptrFromInt(ev.udata)); const handle = resume_node.handle; const resume_node_id = resume_node.id; switch (resume_node_id) { diff --git a/lib/std/event/rwlock.zig b/lib/std/event/rwlock.zig index c19330d5a9..47ddf74fd5 100644 --- a/lib/std/event/rwlock.zig +++ b/lib/std/event/rwlock.zig @@ -223,7 +223,7 @@ test "std.event.RwLock" { _ = testLock(std.heap.page_allocator, &lock); - const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len; + const expected_result = [1]i32{shared_it_count * @as(i32, @intCast(shared_test_data.len))} ** shared_test_data.len; try testing.expectEqualSlices(i32, expected_result, shared_test_data); } fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void { @@ -244,12 +244,12 @@ fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void { } for (write_nodes) |*write_node| { - const casted = @ptrCast(*const @Frame(writeRunner), write_node.data); + const casted = @as(*const @Frame(writeRunner), @ptrCast(write_node.data)); await casted; allocator.destroy(casted); } for (read_nodes) |*read_node| { - const casted = @ptrCast(*const @Frame(readRunner), read_node.data); + const casted = @as(*const @Frame(readRunner), @ptrCast(read_node.data)); await casted; allocator.destroy(casted); } @@ -287,6 +287,6 @@ fn readRunner(lock: *RwLock) callconv(.Async) void { defer handle.release(); try testing.expect(shared_test_index == 0); - try testing.expect(shared_test_data[i] == @intCast(i32, shared_count)); + try testing.expect(shared_test_data[i] == @as(i32, @intCast(shared_count))); } } |
