From f26dda21171e26f44aeec8c59a75bbb3331eeb2e Mon Sep 17 00:00:00 2001 From: mlugg Date: Thu, 22 Jun 2023 18:46:56 +0100 Subject: 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 --- test/behavior/basic.zig | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'test/behavior/basic.zig') diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index f98cf8f237..87cbb3e242 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -20,7 +20,7 @@ test "truncate" { try comptime expect(testTruncate(0x10fd) == 0xfd); } fn testTruncate(x: u32) u8 { - return @truncate(u8, x); + return @as(u8, @truncate(x)); } test "truncate to non-power-of-two integers" { @@ -56,7 +56,7 @@ test "truncate to non-power-of-two integers from 128-bit" { } fn testTrunc(comptime Big: type, comptime Little: type, big: Big, little: Little) !void { - try expect(@truncate(Little, big) == little); + try expect(@as(Little, @truncate(big)) == little); } const g1: i32 = 1233 + 1; @@ -229,9 +229,9 @@ test "opaque types" { const global_a: i32 = 1234; const global_b: *const i32 = &global_a; -const global_c: *const f32 = @ptrCast(*const f32, global_b); +const global_c: *const f32 = @as(*const f32, @ptrCast(global_b)); test "compile time global reinterpret" { - const d = @ptrCast(*const i32, global_c); + const d = @as(*const i32, @ptrCast(global_c)); try expect(d.* == 1234); } @@ -362,7 +362,7 @@ test "variable is allowed to be a pointer to an opaque type" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: i32 = 1234; - _ = hereIsAnOpaqueType(@ptrCast(*OpaqueA, &x)); + _ = hereIsAnOpaqueType(@as(*OpaqueA, @ptrCast(&x))); } fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA { var a = ptr; @@ -442,7 +442,7 @@ test "array 3D const double ptr with offset" { } fn testArray2DConstDoublePtr(ptr: *const f32) !void { - const ptr2 = @ptrCast([*]const f32, ptr); + const ptr2 = @as([*]const f32, @ptrCast(ptr)); try expect(ptr2[0] == 1.0); try expect(ptr2[1] == 2.0); } @@ -574,9 +574,9 @@ test "constant equal function pointers" { fn emptyFn() void {} -const addr1 = @ptrCast(*const u8, &emptyFn); +const addr1 = @as(*const u8, @ptrCast(&emptyFn)); test "comptime cast fn to ptr" { - const addr2 = @ptrCast(*const u8, &emptyFn); + const addr2 = @as(*const u8, @ptrCast(&emptyFn)); try comptime expect(addr1 == addr2); } @@ -667,7 +667,7 @@ test "string escapes" { test "explicit cast optional pointers" { const a: ?*i32 = undefined; - const b: ?*f32 = @ptrCast(?*f32, a); + const b: ?*f32 = @as(?*f32, @ptrCast(a)); _ = b; } @@ -752,7 +752,7 @@ test "auto created variables have correct alignment" { const S = struct { fn foo(str: [*]const u8) u32 { - for (@ptrCast([*]align(1) const u32, str)[0..1]) |v| { + for (@as([*]align(1) const u32, @ptrCast(str))[0..1]) |v| { return v; } return 0; @@ -772,7 +772,7 @@ test "extern variable with non-pointer opaque type" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; @export(var_to_export, .{ .name = "opaque_extern_var" }); - try expect(@ptrCast(*align(1) u32, &opaque_extern_var).* == 42); + try expect(@as(*align(1) u32, @ptrCast(&opaque_extern_var)).* == 42); } extern var opaque_extern_var: opaque {}; var var_to_export: u32 = 42; -- cgit v1.2.3