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/Build | |
| 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/Build')
| -rw-r--r-- | lib/std/Build/Cache.zig | 4 | ||||
| -rw-r--r-- | lib/std/Build/Step.zig | 4 | ||||
| -rw-r--r-- | lib/std/Build/Step/CheckObject.zig | 14 | ||||
| -rw-r--r-- | lib/std/Build/Step/Compile.zig | 6 | ||||
| -rw-r--r-- | lib/std/Build/Step/Run.zig | 4 |
5 files changed, 16 insertions, 16 deletions
diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig index 3b7f180ae8..b0db88692c 100644 --- a/lib/std/Build/Cache.zig +++ b/lib/std/Build/Cache.zig @@ -128,7 +128,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath { const sub_path = try gpa.dupe(u8, resolved_path[p.len + 1 ..]); gpa.free(resolved_path); return PrefixedPath{ - .prefix = @intCast(u8, i), + .prefix = @as(u8, @intCast(i)), .sub_path = sub_path, }; } @@ -653,7 +653,7 @@ pub const Manifest = struct { return error.FileTooBig; } - const contents = try self.cache.gpa.alloc(u8, @intCast(usize, ch_file.stat.size)); + const contents = try self.cache.gpa.alloc(u8, @as(usize, @intCast(ch_file.stat.size))); errdefer self.cache.gpa.free(contents); // Hash while reading from disk, to keep the contents in the cpu cache while diff --git a/lib/std/Build/Step.zig b/lib/std/Build/Step.zig index a0d7a6a296..f21ef8bc8f 100644 --- a/lib/std/Build/Step.zig +++ b/lib/std/Build/Step.zig @@ -355,7 +355,7 @@ pub fn evalZigProcess( }, .error_bundle => { const EbHdr = std.zig.Server.Message.ErrorBundle; - const eb_hdr = @ptrCast(*align(1) const EbHdr, body); + const eb_hdr = @as(*align(1) const EbHdr, @ptrCast(body)); const extra_bytes = body[@sizeOf(EbHdr)..][0 .. @sizeOf(u32) * eb_hdr.extra_len]; const string_bytes = @@ -377,7 +377,7 @@ pub fn evalZigProcess( }, .emit_bin_path => { const EbpHdr = std.zig.Server.Message.EmitBinPath; - const ebp_hdr = @ptrCast(*align(1) const EbpHdr, body); + const ebp_hdr = @as(*align(1) const EbpHdr, @ptrCast(body)); s.result_cached = ebp_hdr.flags.cache_hit; result = try arena.dupe(u8, body[@sizeOf(EbpHdr)..]); }, diff --git a/lib/std/Build/Step/CheckObject.zig b/lib/std/Build/Step/CheckObject.zig index 1c2d86e4e3..171734c450 100644 --- a/lib/std/Build/Step/CheckObject.zig +++ b/lib/std/Build/Step/CheckObject.zig @@ -449,9 +449,9 @@ const MachODumper = struct { }, .SYMTAB => if (opts.dump_symtab) { const lc = cmd.cast(macho.symtab_command).?; - symtab = @ptrCast( + symtab = @as( [*]const macho.nlist_64, - @alignCast(@alignOf(macho.nlist_64), &bytes[lc.symoff]), + @ptrCast(@alignCast(&bytes[lc.symoff])), )[0..lc.nsyms]; strtab = bytes[lc.stroff..][0..lc.strsize]; }, @@ -474,7 +474,7 @@ const MachODumper = struct { try writer.print("{s}\n", .{symtab_label}); for (symtab) |sym| { if (sym.stab()) continue; - const sym_name = mem.sliceTo(@ptrCast([*:0]const u8, strtab.ptr + sym.n_strx), 0); + const sym_name = mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + sym.n_strx)), 0); if (sym.sect()) { const sect = sections.items[sym.n_sect - 1]; try writer.print("{x} ({s},{s})", .{ @@ -487,7 +487,7 @@ const MachODumper = struct { } try writer.print(" {s}\n", .{sym_name}); } else if (sym.undf()) { - const ordinal = @divTrunc(@bitCast(i16, sym.n_desc), macho.N_SYMBOL_RESOLVER); + const ordinal = @divTrunc(@as(i16, @bitCast(sym.n_desc)), macho.N_SYMBOL_RESOLVER); const import_name = blk: { if (ordinal <= 0) { if (ordinal == macho.BIND_SPECIAL_DYLIB_SELF) @@ -498,7 +498,7 @@ const MachODumper = struct { break :blk "flat lookup"; unreachable; } - const full_path = imports.items[@bitCast(u16, ordinal) - 1]; + const full_path = imports.items[@as(u16, @bitCast(ordinal)) - 1]; const basename = fs.path.basename(full_path); assert(basename.len > 0); const ext = mem.lastIndexOfScalar(u8, basename, '.') orelse basename.len; @@ -950,8 +950,8 @@ const WasmDumper = struct { switch (opcode) { .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readILEB128(i32, reader)}), .i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readILEB128(i64, reader)}), - .f32_const => try writer.print("f32.const {x}\n", .{@bitCast(f32, try reader.readIntLittle(u32))}), - .f64_const => try writer.print("f64.const {x}\n", .{@bitCast(f64, try reader.readIntLittle(u64))}), + .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.readIntLittle(u32)))}), + .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.readIntLittle(u64)))}), .global_get => try writer.print("global.get {x}\n", .{try std.leb.readULEB128(u32, reader)}), else => unreachable, } diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 89576c15fa..58973d08d0 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -321,7 +321,7 @@ pub const BuildId = union(enum) { pub fn initHexString(bytes: []const u8) BuildId { var result: BuildId = .{ .hexstring = .{ .bytes = undefined, - .len = @intCast(u8, bytes.len), + .len = @as(u8, @intCast(bytes.len)), } }; @memcpy(result.hexstring.bytes[0..bytes.len], bytes); return result; @@ -342,7 +342,7 @@ pub const BuildId = union(enum) { } else if (mem.startsWith(u8, text, "0x")) { var result: BuildId = .{ .hexstring = undefined }; const slice = try std.fmt.hexToBytes(&result.hexstring.bytes, text[2..]); - result.hexstring.len = @intCast(u8, slice.len); + result.hexstring.len = @as(u8, @intCast(slice.len)); return result; } return error.InvalidBuildIdStyle; @@ -2059,7 +2059,7 @@ fn findVcpkgRoot(allocator: Allocator) !?[]const u8 { const file = fs.cwd().openFile(path_file, .{}) catch return null; defer file.close(); - const size = @intCast(usize, try file.getEndPos()); + const size = @as(usize, @intCast(try file.getEndPos())); const vcpkg_path = try allocator.alloc(u8, size); const size_read = try file.read(vcpkg_path); std.debug.assert(size == size_read); diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index c574dbb5af..3d81873308 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -998,7 +998,7 @@ fn evalZigTest( }, .test_metadata => { const TmHdr = std.zig.Server.Message.TestMetadata; - const tm_hdr = @ptrCast(*align(1) const TmHdr, body); + const tm_hdr = @as(*align(1) const TmHdr, @ptrCast(body)); test_count = tm_hdr.tests_len; const names_bytes = body[@sizeOf(TmHdr)..][0 .. test_count * @sizeOf(u32)]; @@ -1034,7 +1034,7 @@ fn evalZigTest( const md = metadata.?; const TrHdr = std.zig.Server.Message.TestResults; - const tr_hdr = @ptrCast(*align(1) const TrHdr, body); + const tr_hdr = @as(*align(1) const TrHdr, @ptrCast(body)); fail_count += @intFromBool(tr_hdr.flags.fail); skip_count += @intFromBool(tr_hdr.flags.skip); leak_count += @intFromBool(tr_hdr.flags.leak); |
