Skip to content

Commit fd9cfc3

Browse files
authored
Merge pull request #24199 from Justus2308/24106-fmt-casts
zig fmt: canonicalize nested cast builtin order
2 parents 04fe1bf + 7c35070 commit fd9cfc3

30 files changed

+87
-46
lines changed

lib/build-web/fuzz.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fn updateStats() error{OutOfMemory}!void {
256256

257257
if (recent_coverage_update.items.len == 0) return;
258258

259-
const hdr: *abi.fuzz.CoverageUpdateHeader = @alignCast(@ptrCast(
259+
const hdr: *abi.fuzz.CoverageUpdateHeader = @ptrCast(@alignCast(
260260
recent_coverage_update.items[0..@sizeOf(abi.fuzz.CoverageUpdateHeader)],
261261
));
262262

lib/compiler_rt/memcpy.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ inline fn copyForwards(
110110
const d = dest + alignment_offset;
111111
const s = src + alignment_offset;
112112

113-
copyBlocksAlignedSource(@ptrCast(d), @alignCast(@ptrCast(s)), n);
113+
copyBlocksAlignedSource(@ptrCast(d), @ptrCast(@alignCast(s)), n);
114114

115115
// copy last `@sizeOf(Element)` bytes unconditionally, since block copy
116116
// methods only copy a multiple of `@sizeOf(Element)` bytes.

lib/compiler_rt/memmove.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ inline fn copyForwards(
157157
const d = dest + alignment_offset;
158158
const s = src + alignment_offset;
159159

160-
copyBlocksAlignedSource(@ptrCast(d), @alignCast(@ptrCast(s)), n);
160+
copyBlocksAlignedSource(@ptrCast(d), @ptrCast(@alignCast(s)), n);
161161

162162
// copy last `copy_size` bytes unconditionally, since block copy
163163
// methods only copy a multiple of `copy_size` bytes.

lib/std/Io.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub fn GenericReader(
289289
const Self = @This();
290290

291291
fn typeErasedReadFn(context: *const anyopaque, buffer: []u8) anyerror!usize {
292-
const ptr: *const Context = @alignCast(@ptrCast(context));
292+
const ptr: *const Context = @ptrCast(@alignCast(context));
293293
return readFn(ptr.*, buffer);
294294
}
295295

@@ -382,7 +382,7 @@ pub fn GenericWriter(
382382
}
383383

384384
fn typeErasedWriteFn(context: *const anyopaque, bytes: []const u8) anyerror!usize {
385-
const ptr: *const Context = @alignCast(@ptrCast(context));
385+
const ptr: *const Context = @ptrCast(@alignCast(context));
386386
return writeFn(ptr.*, bytes);
387387
}
388388

lib/std/Io/Reader.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ pub fn adaptToOldInterface(r: *Reader) std.Io.AnyReader {
16891689
}
16901690

16911691
fn derpRead(context: *const anyopaque, buffer: []u8) anyerror!usize {
1692-
const r: *Reader = @constCast(@alignCast(@ptrCast(context)));
1692+
const r: *Reader = @ptrCast(@alignCast(@constCast(context)));
16931693
return r.readSliceShort(buffer);
16941694
}
16951695

lib/std/array_hash_map.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ const IndexHeader = struct {
20862086
/// Returns the attached array of indexes. I must match the type
20872087
/// returned by capacityIndexType.
20882088
fn indexes(header: *IndexHeader, comptime I: type) []Index(I) {
2089-
const start_ptr: [*]Index(I) = @alignCast(@ptrCast(@as([*]u8, @ptrCast(header)) + @sizeOf(IndexHeader)));
2089+
const start_ptr: [*]Index(I) = @ptrCast(@alignCast(@as([*]u8, @ptrCast(header)) + @sizeOf(IndexHeader)));
20902090
return start_ptr[0..header.length()];
20912091
}
20922092

@@ -2122,7 +2122,7 @@ const IndexHeader = struct {
21222122
const nbytes = @sizeOf(IndexHeader) + index_size * len;
21232123
const bytes = try gpa.alignedAlloc(u8, .of(IndexHeader), nbytes);
21242124
@memset(bytes[@sizeOf(IndexHeader)..], 0xff);
2125-
const result: *IndexHeader = @alignCast(@ptrCast(bytes.ptr));
2125+
const result: *IndexHeader = @ptrCast(@alignCast(bytes.ptr));
21262126
result.* = .{
21272127
.bit_index = new_bit_index,
21282128
};

lib/std/crypto/codecs/asn1/der/Encoder.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void {
3737
// > The encoding of a set value or sequence value shall not include an encoding for any
3838
// > component value which is equal to its default value.
3939
const is_default = if (f.is_comptime) false else if (f.default_value_ptr) |v| brk: {
40-
const default_val: *const f.type = @alignCast(@ptrCast(v));
40+
const default_val: *const f.type = @ptrCast(@alignCast(v));
4141
break :brk std.mem.eql(u8, std.mem.asBytes(default_val), std.mem.asBytes(&field_val));
4242
} else false;
4343

lib/std/crypto/timing_safe.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn markSecret(ptr: anytype, comptime action: enum { classify, declassify }) void
147147
@compileError("A pointer value is always assumed leak information via side channels");
148148
},
149149
else => {
150-
const mem8: *const [@sizeOf(@TypeOf(ptr.*))]u8 = @constCast(@ptrCast(ptr));
150+
const mem8: *const [@sizeOf(@TypeOf(ptr.*))]u8 = @ptrCast(@constCast(ptr));
151151
if (action == .classify) {
152152
std.valgrind.memcheck.makeMemUndefined(mem8);
153153
} else {

lib/std/debug.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ pub fn assertReadable(slice: []const volatile u8) void {
569569
/// Invokes detectable illegal behavior when the provided array is not aligned
570570
/// to the provided amount.
571571
pub fn assertAligned(ptr: anytype, comptime alignment: std.mem.Alignment) void {
572-
const aligned_ptr: *align(alignment.toByteUnits()) anyopaque = @alignCast(@ptrCast(ptr));
572+
const aligned_ptr: *align(alignment.toByteUnits()) anyopaque = @ptrCast(@alignCast(ptr));
573573
_ = aligned_ptr;
574574
}
575575

lib/std/debug/SelfInfo.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ pub const WindowsModule = struct {
836836

837837
pub fn deinit(self: @This()) void {
838838
const process_handle = windows.GetCurrentProcess();
839-
assert(windows.ntdll.NtUnmapViewOfSection(process_handle, @constCast(@ptrCast(self.section_view.ptr))) == .SUCCESS);
839+
assert(windows.ntdll.NtUnmapViewOfSection(process_handle, @ptrCast(@constCast(self.section_view.ptr))) == .SUCCESS);
840840
windows.CloseHandle(self.section_handle);
841841
self.file.close();
842842
}

0 commit comments

Comments
 (0)