Merge pull request #24199 from Justus2308/24106-fmt-casts

zig fmt: canonicalize nested cast builtin order
This commit is contained in:
Matthew Lugg
2025-08-07 10:55:03 +01:00
committed by GitHub
30 changed files with 87 additions and 46 deletions

View File

@@ -1091,7 +1091,7 @@ test "initialize pointer to anyopaque with reference to empty array initializer"
const ptr: *const anyopaque = &.{};
// The above acts like an untyped initializer, since the `.{}` has no result type.
// So, `ptr` points in memory to an empty tuple (`@TypeOf(.{})`).
const casted: *const @TypeOf(.{}) = @alignCast(@ptrCast(ptr));
const casted: *const @TypeOf(.{}) = @ptrCast(@alignCast(ptr));
const loaded = casted.*;
// `val` should be a `@TypeOf(.{})`, as expected.
// We can't check the value, but it's zero-bit, so the type matching is good enough.

View File

@@ -477,7 +477,7 @@ fn GenericIntApplier(
}
fn typeErasedApplyFn(context: *const anyopaque, arg: u32) void {
const ptr: *const Context = @alignCast(@ptrCast(context));
const ptr: *const Context = @ptrCast(@alignCast(context));
applyFn(ptr.*, arg);
}
};

View File

@@ -8,7 +8,7 @@ test "anyopaque extern symbol" {
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
const a = @extern(*anyopaque, .{ .name = "a_mystery_symbol" });
const b: *i32 = @alignCast(@ptrCast(a));
const b: *i32 = @ptrCast(@alignCast(a));
try expect(b.* == 1234);
}