all: migrate code to new cast builtin syntax

Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
This commit is contained in:
mlugg
2023-06-22 18:46:56 +01:00
committed by Andrew Kelley
parent 447ca4e3ff
commit f26dda2117
651 changed files with 8967 additions and 9039 deletions

View File

@@ -68,7 +68,7 @@ pub const EnvMap = struct {
pub const EnvNameHashContext = struct {
fn upcase(c: u21) u21 {
if (c <= std.math.maxInt(u16))
return std.os.windows.ntdll.RtlUpcaseUnicodeChar(@intCast(u16, c));
return std.os.windows.ntdll.RtlUpcaseUnicodeChar(@as(u16, @intCast(c)));
return c;
}
@@ -80,9 +80,9 @@ pub const EnvMap = struct {
while (it.nextCodepoint()) |cp| {
const cp_upper = upcase(cp);
h.update(&[_]u8{
@intCast(u8, (cp_upper >> 16) & 0xff),
@intCast(u8, (cp_upper >> 8) & 0xff),
@intCast(u8, (cp_upper >> 0) & 0xff),
@as(u8, @intCast((cp_upper >> 16) & 0xff)),
@as(u8, @intCast((cp_upper >> 8) & 0xff)),
@as(u8, @intCast((cp_upper >> 0) & 0xff)),
});
}
return h.final();
@@ -872,8 +872,8 @@ pub fn argsFree(allocator: Allocator, args_alloc: []const [:0]u8) void {
for (args_alloc) |arg| {
total_bytes += @sizeOf([]u8) + arg.len + 1;
}
const unaligned_allocated_buf = @ptrCast([*]const u8, args_alloc.ptr)[0..total_bytes];
const aligned_allocated_buf = @alignCast(@alignOf([]u8), unaligned_allocated_buf);
const unaligned_allocated_buf = @as([*]const u8, @ptrCast(args_alloc.ptr))[0..total_bytes];
const aligned_allocated_buf: []align(@alignOf([]u8)) const u8 = @alignCast(unaligned_allocated_buf);
return allocator.free(aligned_allocated_buf);
}
@@ -1143,7 +1143,7 @@ pub fn execve(
} else if (builtin.output_mode == .Exe) {
// Then we have Zig start code and this works.
// TODO type-safety for null-termination of `os.environ`.
break :m @ptrCast([*:null]const ?[*:0]const u8, os.environ.ptr);
break :m @as([*:null]const ?[*:0]const u8, @ptrCast(os.environ.ptr));
} else {
// TODO come up with a solution for this.
@compileError("missing std lib enhancement: std.process.execv implementation has no way to collect the environment variables to forward to the child process");
@@ -1175,7 +1175,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
error.NameTooLong, error.UnknownName => unreachable,
else => return error.UnknownTotalSystemMemory,
};
return @intCast(usize, physmem);
return @as(usize, @intCast(physmem));
},
.openbsd => {
const mib: [2]c_int = [_]c_int{
@@ -1192,7 +1192,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
else => return error.UnknownTotalSystemMemory,
};
assert(physmem >= 0);
return @bitCast(usize, physmem);
return @as(usize, @bitCast(physmem));
},
.windows => {
var sbi: std.os.windows.SYSTEM_BASIC_INFORMATION = undefined;