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 /test | |
| 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 'test')
149 files changed, 652 insertions, 660 deletions
diff --git a/test/behavior/align.zig b/test/behavior/align.zig index d3e4d81250..c8eb71a433 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -24,7 +24,7 @@ test "slicing array of length 1 can not assume runtime index is always zero" { const slice = @as(*align(4) [1]u8, &foo)[runtime_index..]; try expect(@TypeOf(slice) == []u8); try expect(slice.len == 0); - try expect(@truncate(u2, @intFromPtr(slice.ptr) - 1) == 0); + try expect(@as(u2, @truncate(@intFromPtr(slice.ptr) - 1)) == 0); } test "default alignment allows unspecified in type syntax" { @@ -47,7 +47,7 @@ test "@alignCast pointers" { try expect(x == 2); } fn expectsOnly1(x: *align(1) u32) void { - expects4(@alignCast(4, x)); + expects4(@alignCast(x)); } fn expects4(x: *align(4) u32) void { x.* += 1; @@ -213,12 +213,6 @@ test "alignment and size of structs with 128-bit fields" { } } -test "@ptrCast preserves alignment of bigger source" { - var x: u32 align(16) = 1234; - const ptr = @ptrCast(*u8, &x); - try expect(@TypeOf(ptr) == *align(16) u8); -} - test "alignstack" { try expect(fnWithAlignedStack() == 1234); } @@ -249,7 +243,7 @@ test "specifying alignment allows pointer cast" { } fn testBytesAlign(b: u8) !void { var bytes align(4) = [_]u8{ b, b, b, b }; - const ptr = @ptrCast(*u32, &bytes[0]); + const ptr = @as(*u32, @ptrCast(&bytes[0])); try expect(ptr.* == 0x33333333); } @@ -265,7 +259,7 @@ test "@alignCast slices" { try expect(slice[0] == 2); } fn sliceExpectsOnly1(slice: []align(1) u32) void { - sliceExpects4(@alignCast(4, slice)); + sliceExpects4(@alignCast(slice)); } fn sliceExpects4(slice: []align(4) u32) void { slice[0] += 1; @@ -302,8 +296,8 @@ test "page aligned array on stack" { try expect(@intFromPtr(&array[0]) & 0xFFF == 0); try expect(array[3] == 4); - try expect(@truncate(u4, @intFromPtr(&number1)) == 0); - try expect(@truncate(u4, @intFromPtr(&number2)) == 0); + try expect(@as(u4, @truncate(@intFromPtr(&number1))) == 0); + try expect(@as(u4, @truncate(@intFromPtr(&number2))) == 0); try expect(number1 == 42); try expect(number2 == 43); } @@ -366,7 +360,7 @@ test "@alignCast functions" { try expect(fnExpectsOnly1(simple4) == 0x19); } fn fnExpectsOnly1(ptr: *const fn () align(1) i32) i32 { - return fnExpects4(@alignCast(4, ptr)); + return fnExpects4(@alignCast(ptr)); } fn fnExpects4(ptr: *const fn () align(4) i32) i32 { return ptr(); @@ -461,9 +455,11 @@ fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void { test "alignment of function with c calling convention" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + const a = @alignOf(@TypeOf(nothing)); + var runtime_nothing = ¬hing; - const casted1 = @ptrCast(*const u8, runtime_nothing); - const casted2 = @ptrCast(*const fn () callconv(.C) void, casted1); + const casted1: *align(a) const u8 = @ptrCast(runtime_nothing); + const casted2: *const fn () callconv(.C) void = @ptrCast(casted1); casted2(); } @@ -588,7 +584,7 @@ test "@alignCast null" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var ptr: ?*anyopaque = null; - const aligned: ?*anyopaque = @alignCast(@alignOf(?*anyopaque), ptr); + const aligned: ?*anyopaque = @alignCast(ptr); try expect(aligned == null); } diff --git a/test/behavior/array.zig b/test/behavior/array.zig index 9ef4a55b39..bc8176aa9c 100644 --- a/test/behavior/array.zig +++ b/test/behavior/array.zig @@ -170,7 +170,7 @@ test "array with sentinels" { { var zero_sized: [0:0xde]u8 = [_:0xde]u8{}; try expect(zero_sized[0] == 0xde); - var reinterpreted = @ptrCast(*[1]u8, &zero_sized); + var reinterpreted = @as(*[1]u8, @ptrCast(&zero_sized)); try expect(reinterpreted[0] == 0xde); } var arr: [3:0x55]u8 = undefined; @@ -694,7 +694,7 @@ test "array init of container level array variable" { test "runtime initialized sentinel-terminated array literal" { var c: u16 = 300; const f = &[_:0x9999]u16{c}; - const g = @ptrCast(*const [4]u8, f); + const g = @as(*const [4]u8, @ptrCast(f)); try std.testing.expect(g[2] == 0x99); try std.testing.expect(g[3] == 0x99); } diff --git a/test/behavior/async_fn.zig b/test/behavior/async_fn.zig index dcbe78b091..7eaa5c78d0 100644 --- a/test/behavior/async_fn.zig +++ b/test/behavior/async_fn.zig @@ -136,12 +136,12 @@ test "@frameSize" { const S = struct { fn doTheTest() !void { { - var ptr = @ptrCast(fn (i32) callconv(.Async) void, other); + var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other)); const size = @frameSize(ptr); try expect(size == @sizeOf(@Frame(other))); } { - var ptr = @ptrCast(fn () callconv(.Async) void, first); + var ptr = @as(fn () callconv(.Async) void, @ptrCast(first)); const size = @frameSize(ptr); try expect(size == @sizeOf(@Frame(first))); } @@ -1184,7 +1184,7 @@ test "using @TypeOf on a generic function call" { global_frame = @frame(); } const F = @TypeOf(async amain(x - 1)); - const frame = @ptrFromInt(*F, @intFromPtr(&buf)); + const frame = @as(*F, @ptrFromInt(@intFromPtr(&buf))); return await @asyncCall(frame, {}, amain, .{x - 1}); } }; @@ -1212,7 +1212,7 @@ test "recursive call of await @asyncCall with struct return type" { global_frame = @frame(); } const F = @TypeOf(async amain(x - 1)); - const frame = @ptrFromInt(*F, @intFromPtr(&buf)); + const frame = @as(*F, @ptrFromInt(@intFromPtr(&buf))); return await @asyncCall(frame, {}, amain, .{x - 1}); } @@ -1833,7 +1833,7 @@ test "avoid forcing frame alignment resolution implicit cast to *anyopaque" { } }; var frame = async S.foo(); - resume @ptrCast(anyframe->bool, @alignCast(@alignOf(@Frame(S.foo)), S.x)); + resume @as(anyframe->bool, @ptrCast(@alignCast(S.x))); try expect(nosuspend await frame); } diff --git a/test/behavior/atomics.zig b/test/behavior/atomics.zig index 4394e62f6f..5264ef75cf 100644 --- a/test/behavior/atomics.zig +++ b/test/behavior/atomics.zig @@ -326,7 +326,7 @@ fn testAtomicRmwInt128(comptime signedness: std.builtin.Signedness) !void { const uint = std.meta.Int(.unsigned, 128); const int = std.meta.Int(signedness, 128); - const initial: int = @bitCast(int, @as(uint, 0xaaaaaaaa_bbbbbbbb_cccccccc_dddddddd)); + const initial: int = @as(int, @bitCast(@as(uint, 0xaaaaaaaa_bbbbbbbb_cccccccc_dddddddd))); const replacement: int = 0x00000000_00000005_00000000_00000003; var x: int align(16) = initial; 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; diff --git a/test/behavior/bit_shifting.zig b/test/behavior/bit_shifting.zig index 03eb4433e1..8b605385d2 100644 --- a/test/behavior/bit_shifting.zig +++ b/test/behavior/bit_shifting.zig @@ -28,7 +28,7 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt // TODO: https://github.com/ziglang/zig/issues/1544 // This cast could be implicit if we teach the compiler that // u32 >> 30 -> u2 - return @intCast(ShardKey, shard_key); + return @as(ShardKey, @intCast(shard_key)); } pub fn put(self: *Self, node: *Node) void { @@ -85,14 +85,14 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c var table = Table.create(); var node_buffer: [node_count]Table.Node = undefined; for (&node_buffer, 0..) |*node, i| { - const key = @intCast(Key, i); + const key = @as(Key, @intCast(i)); try expect(table.get(key) == null); node.init(key, {}); table.put(node); } for (&node_buffer, 0..) |*node, i| { - try expect(table.get(@intCast(Key, i)) == node); + try expect(table.get(@as(Key, @intCast(i))) == node); } } diff --git a/test/behavior/bitcast.zig b/test/behavior/bitcast.zig index f71a05cada..0c137a2baa 100644 --- a/test/behavior/bitcast.zig +++ b/test/behavior/bitcast.zig @@ -71,11 +71,11 @@ fn testBitCast(comptime N: usize) !void { } fn conv_iN(comptime N: usize, x: std.meta.Int(.signed, N)) std.meta.Int(.unsigned, N) { - return @bitCast(std.meta.Int(.unsigned, N), x); + return @as(std.meta.Int(.unsigned, N), @bitCast(x)); } fn conv_uN(comptime N: usize, x: std.meta.Int(.unsigned, N)) std.meta.Int(.signed, N) { - return @bitCast(std.meta.Int(.signed, N), x); + return @as(std.meta.Int(.signed, N), @bitCast(x)); } test "bitcast uX to bytes" { @@ -114,14 +114,14 @@ fn testBitCastuXToBytes(comptime N: usize) !void { while (byte_i < (byte_count - 1)) : (byte_i += 1) { try expect(bytes[byte_i] == 0xff); } - try expect(((bytes[byte_i] ^ 0xff) << -%@truncate(u3, N)) == 0); + try expect(((bytes[byte_i] ^ 0xff) << -%@as(u3, @truncate(N))) == 0); }, .Big => { var byte_i = byte_count - 1; while (byte_i > 0) : (byte_i -= 1) { try expect(bytes[byte_i] == 0xff); } - try expect(((bytes[byte_i] ^ 0xff) << -%@truncate(u3, N)) == 0); + try expect(((bytes[byte_i] ^ 0xff) << -%@as(u3, @truncate(N))) == 0); }, } } @@ -130,12 +130,12 @@ fn testBitCastuXToBytes(comptime N: usize) !void { test "nested bitcast" { const S = struct { fn moo(x: isize) !void { - try expect(@intCast(isize, 42) == x); + try expect(@as(isize, @intCast(42)) == x); } fn foo(x: isize) !void { try @This().moo( - @bitCast(isize, if (x != 0) @bitCast(usize, x) else @bitCast(usize, x)), + @as(isize, @bitCast(if (x != 0) @as(usize, @bitCast(x)) else @as(usize, @bitCast(x)))), ); } }; @@ -146,7 +146,7 @@ test "nested bitcast" { // issue #3010: compiler segfault test "bitcast literal [4]u8 param to u32" { - const ip = @bitCast(u32, [_]u8{ 255, 255, 255, 255 }); + const ip = @as(u32, @bitCast([_]u8{ 255, 255, 255, 255 })); try expect(ip == maxInt(u32)); } @@ -154,7 +154,7 @@ test "bitcast generates a temporary value" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var y = @as(u16, 0x55AA); - const x = @bitCast(u16, @bitCast([2]u8, y)); + const x = @as(u16, @bitCast(@as([2]u8, @bitCast(y)))); try expect(y == x); } @@ -175,7 +175,7 @@ test "@bitCast packed structs at runtime and comptime" { const S = struct { fn doTheTest() !void { var full = Full{ .number = 0x1234 }; - var two_halves = @bitCast(Divided, full); + var two_halves = @as(Divided, @bitCast(full)); try expect(two_halves.half1 == 0x34); try expect(two_halves.quarter3 == 0x2); try expect(two_halves.quarter4 == 0x1); @@ -200,7 +200,7 @@ test "@bitCast extern structs at runtime and comptime" { const S = struct { fn doTheTest() !void { var full = Full{ .number = 0x1234 }; - var two_halves = @bitCast(TwoHalves, full); + var two_halves = @as(TwoHalves, @bitCast(full)); switch (native_endian) { .Big => { try expect(two_halves.half1 == 0x12); @@ -230,8 +230,8 @@ test "bitcast packed struct to integer and back" { const S = struct { fn doTheTest() !void { var move = LevelUpMove{ .move_id = 1, .level = 2 }; - var v = @bitCast(u16, move); - var back_to_a_move = @bitCast(LevelUpMove, v); + var v = @as(u16, @bitCast(move)); + var back_to_a_move = @as(LevelUpMove, @bitCast(v)); try expect(back_to_a_move.move_id == 1); try expect(back_to_a_move.level == 2); } @@ -250,7 +250,7 @@ test "implicit cast to error union by returning" { try expect((func(-1) catch unreachable) == maxInt(u64)); } pub fn func(sz: i64) anyerror!u64 { - return @bitCast(u64, sz); + return @as(u64, @bitCast(sz)); } }; try S.entry(); @@ -261,7 +261,7 @@ test "bitcast packed struct literal to byte" { const Foo = packed struct { value: u8, }; - const casted = @bitCast(u8, Foo{ .value = 0xF }); + const casted = @as(u8, @bitCast(Foo{ .value = 0xF })); try expect(casted == 0xf); } @@ -269,7 +269,7 @@ test "comptime bitcast used in expression has the correct type" { const Foo = packed struct { value: u8, }; - try expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf); + try expect(@as(u8, @bitCast(Foo{ .value = 0xF })) == 0xf); } test "bitcast passed as tuple element" { @@ -279,7 +279,7 @@ test "bitcast passed as tuple element" { try expect(args[0] == 12.34); } }; - try S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))}); + try S.foo(.{@as(f32, @bitCast(@as(u32, 0x414570A4)))}); } test "triple level result location with bitcast sandwich passed as tuple element" { @@ -289,7 +289,7 @@ test "triple level result location with bitcast sandwich passed as tuple element try expect(args[0] > 12.33 and args[0] < 12.35); } }; - try S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))}); + try S.foo(.{@as(f64, @as(f32, @bitCast(@as(u32, 0x414570A4))))}); } test "@bitCast packed struct of floats" { @@ -318,7 +318,7 @@ test "@bitCast packed struct of floats" { const S = struct { fn doTheTest() !void { var foo = Foo{}; - var v = @bitCast(Foo2, foo); + var v = @as(Foo2, @bitCast(foo)); try expect(v.a == foo.a); try expect(v.b == foo.b); try expect(v.c == foo.c); @@ -360,12 +360,12 @@ test "comptime @bitCast packed struct to int and back" { // S -> Int var s: S = .{}; - try expectEqual(@bitCast(Int, s), comptime @bitCast(Int, S{})); + try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{}))); // Int -> S var i: Int = 0; - const rt_cast = @bitCast(S, i); - const ct_cast = comptime @bitCast(S, @as(Int, 0)); + const rt_cast = @as(S, @bitCast(i)); + const ct_cast = comptime @as(S, @bitCast(@as(Int, 0))); inline for (@typeInfo(S).Struct.fields) |field| { try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name)); } @@ -381,10 +381,10 @@ test "comptime bitcast with fields following f80" { const FloatT = extern struct { f: f80, x: u128 align(16) }; const x: FloatT = .{ .f = 0.5, .x = 123 }; - var x_as_uint: u256 = comptime @bitCast(u256, x); + var x_as_uint: u256 = comptime @as(u256, @bitCast(x)); - try expect(x.f == @bitCast(FloatT, x_as_uint).f); - try expect(x.x == @bitCast(FloatT, x_as_uint).x); + try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f); + try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x); } test "bitcast vector to integer and back" { @@ -398,20 +398,20 @@ test "bitcast vector to integer and back" { const arr: [16]bool = [_]bool{ true, false } ++ [_]bool{true} ** 14; var x = @splat(16, true); x[1] = false; - try expect(@bitCast(u16, x) == comptime @bitCast(u16, @as(@Vector(16, bool), arr))); + try expect(@as(u16, @bitCast(x)) == comptime @as(u16, @bitCast(@as(@Vector(16, bool), arr)))); } fn bitCastWrapper16(x: f16) u16 { - return @bitCast(u16, x); + return @as(u16, @bitCast(x)); } fn bitCastWrapper32(x: f32) u32 { - return @bitCast(u32, x); + return @as(u32, @bitCast(x)); } fn bitCastWrapper64(x: f64) u64 { - return @bitCast(u64, x); + return @as(u64, @bitCast(x)); } fn bitCastWrapper128(x: f128) u128 { - return @bitCast(u128, x); + return @as(u128, @bitCast(x)); } test "bitcast nan float does modify signaling bit" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO @@ -425,37 +425,37 @@ test "bitcast nan float does modify signaling bit" { // 16 bit const snan_f16_const = math.nan_f16; - try expectEqual(math.nan_u16, @bitCast(u16, snan_f16_const)); + try expectEqual(math.nan_u16, @as(u16, @bitCast(snan_f16_const))); try expectEqual(math.nan_u16, bitCastWrapper16(snan_f16_const)); var snan_f16_var = math.nan_f16; - try expectEqual(math.nan_u16, @bitCast(u16, snan_f16_var)); + try expectEqual(math.nan_u16, @as(u16, @bitCast(snan_f16_var))); try expectEqual(math.nan_u16, bitCastWrapper16(snan_f16_var)); // 32 bit const snan_f32_const = math.nan_f32; - try expectEqual(math.nan_u32, @bitCast(u32, snan_f32_const)); + try expectEqual(math.nan_u32, @as(u32, @bitCast(snan_f32_const))); try expectEqual(math.nan_u32, bitCastWrapper32(snan_f32_const)); var snan_f32_var = math.nan_f32; - try expectEqual(math.nan_u32, @bitCast(u32, snan_f32_var)); + try expectEqual(math.nan_u32, @as(u32, @bitCast(snan_f32_var))); try expectEqual(math.nan_u32, bitCastWrapper32(snan_f32_var)); // 64 bit const snan_f64_const = math.nan_f64; - try expectEqual(math.nan_u64, @bitCast(u64, snan_f64_const)); + try expectEqual(math.nan_u64, @as(u64, @bitCast(snan_f64_const))); try expectEqual(math.nan_u64, bitCastWrapper64(snan_f64_const)); var snan_f64_var = math.nan_f64; - try expectEqual(math.nan_u64, @bitCast(u64, snan_f64_var)); + try expectEqual(math.nan_u64, @as(u64, @bitCast(snan_f64_var))); try expectEqual(math.nan_u64, bitCastWrapper64(snan_f64_var)); // 128 bit const snan_f128_const = math.nan_f128; - try expectEqual(math.nan_u128, @bitCast(u128, snan_f128_const)); + try expectEqual(math.nan_u128, @as(u128, @bitCast(snan_f128_const))); try expectEqual(math.nan_u128, bitCastWrapper128(snan_f128_const)); var snan_f128_var = math.nan_f128; - try expectEqual(math.nan_u128, @bitCast(u128, snan_f128_var)); + try expectEqual(math.nan_u128, @as(u128, @bitCast(snan_f128_var))); try expectEqual(math.nan_u128, bitCastWrapper128(snan_f128_var)); } diff --git a/test/behavior/bitreverse.zig b/test/behavior/bitreverse.zig index e19a560a9d..722edef25e 100644 --- a/test/behavior/bitreverse.zig +++ b/test/behavior/bitreverse.zig @@ -62,20 +62,20 @@ fn testBitReverse() !void { // using comptime_ints, signed, positive try expect(@bitReverse(@as(u8, 0)) == 0); - try expect(@bitReverse(@bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49))); - try expect(@bitReverse(@bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48))); - try expect(@bitReverse(@bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48))); - try expect(@bitReverse(@bitCast(i24, @as(u24, 0x12345f))) == @bitCast(i24, @as(u24, 0xfa2c48))); - try expect(@bitReverse(@bitCast(i24, @as(u24, 0xf23456))) == @bitCast(i24, @as(u24, 0x6a2c4f))); - try expect(@bitReverse(@bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48))); - try expect(@bitReverse(@bitCast(i32, @as(u32, 0xf2345678))) == @bitCast(i32, @as(u32, 0x1e6a2c4f))); - try expect(@bitReverse(@bitCast(i32, @as(u32, 0x1234567f))) == @bitCast(i32, @as(u32, 0xfe6a2c48))); - try expect(@bitReverse(@bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48))); - try expect(@bitReverse(@bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48))); - try expect(@bitReverse(@bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48))); - try expect(@bitReverse(@bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48))); - try expect(@bitReverse(@bitCast(i96, @as(u96, 0x123456789abcdef111213141))) == @bitCast(i96, @as(u96, 0x828c84888f7b3d591e6a2c48))); - try expect(@bitReverse(@bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48))); + try expect(@bitReverse(@as(i8, @bitCast(@as(u8, 0x92)))) == @as(i8, @bitCast(@as(u8, 0x49)))); + try expect(@bitReverse(@as(i16, @bitCast(@as(u16, 0x1234)))) == @as(i16, @bitCast(@as(u16, 0x2c48)))); + try expect(@bitReverse(@as(i24, @bitCast(@as(u24, 0x123456)))) == @as(i24, @bitCast(@as(u24, 0x6a2c48)))); + try expect(@bitReverse(@as(i24, @bitCast(@as(u24, 0x12345f)))) == @as(i24, @bitCast(@as(u24, 0xfa2c48)))); + try expect(@bitReverse(@as(i24, @bitCast(@as(u24, 0xf23456)))) == @as(i24, @bitCast(@as(u24, 0x6a2c4f)))); + try expect(@bitReverse(@as(i32, @bitCast(@as(u32, 0x12345678)))) == @as(i32, @bitCast(@as(u32, 0x1e6a2c48)))); + try expect(@bitReverse(@as(i32, @bitCast(@as(u32, 0xf2345678)))) == @as(i32, @bitCast(@as(u32, 0x1e6a2c4f)))); + try expect(@bitReverse(@as(i32, @bitCast(@as(u32, 0x1234567f)))) == @as(i32, @bitCast(@as(u32, 0xfe6a2c48)))); + try expect(@bitReverse(@as(i40, @bitCast(@as(u40, 0x123456789a)))) == @as(i40, @bitCast(@as(u40, 0x591e6a2c48)))); + try expect(@bitReverse(@as(i48, @bitCast(@as(u48, 0x123456789abc)))) == @as(i48, @bitCast(@as(u48, 0x3d591e6a2c48)))); + try expect(@bitReverse(@as(i56, @bitCast(@as(u56, 0x123456789abcde)))) == @as(i56, @bitCast(@as(u56, 0x7b3d591e6a2c48)))); + try expect(@bitReverse(@as(i64, @bitCast(@as(u64, 0x123456789abcdef1)))) == @as(i64, @bitCast(@as(u64, 0x8f7b3d591e6a2c48)))); + try expect(@bitReverse(@as(i96, @bitCast(@as(u96, 0x123456789abcdef111213141)))) == @as(i96, @bitCast(@as(u96, 0x828c84888f7b3d591e6a2c48)))); + try expect(@bitReverse(@as(i128, @bitCast(@as(u128, 0x123456789abcdef11121314151617181)))) == @as(i128, @bitCast(@as(u128, 0x818e868a828c84888f7b3d591e6a2c48)))); // using signed, negative. Compare to runtime ints returned from llvm. var neg8: i8 = -18; diff --git a/test/behavior/bool.zig b/test/behavior/bool.zig index 50a098c111..5d09e5f8a0 100644 --- a/test/behavior/bool.zig +++ b/test/behavior/bool.zig @@ -15,8 +15,8 @@ test "cast bool to int" { const f = false; try expectEqual(@as(u32, 1), @intFromBool(t)); try expectEqual(@as(u32, 0), @intFromBool(f)); - try expectEqual(-1, @bitCast(i1, @intFromBool(t))); - try expectEqual(0, @bitCast(i1, @intFromBool(f))); + try expectEqual(-1, @as(i1, @bitCast(@intFromBool(t)))); + try expectEqual(0, @as(i1, @bitCast(@intFromBool(f)))); try expectEqual(u1, @TypeOf(@intFromBool(t))); try expectEqual(u1, @TypeOf(@intFromBool(f))); try nonConstCastIntFromBool(t, f); @@ -25,8 +25,8 @@ test "cast bool to int" { fn nonConstCastIntFromBool(t: bool, f: bool) !void { try expectEqual(@as(u32, 1), @intFromBool(t)); try expectEqual(@as(u32, 0), @intFromBool(f)); - try expectEqual(@as(i1, -1), @bitCast(i1, @intFromBool(t))); - try expectEqual(@as(i1, 0), @bitCast(i1, @intFromBool(f))); + try expectEqual(@as(i1, -1), @as(i1, @bitCast(@intFromBool(t)))); + try expectEqual(@as(i1, 0), @as(i1, @bitCast(@intFromBool(f)))); try expectEqual(u1, @TypeOf(@intFromBool(t))); try expectEqual(u1, @TypeOf(@intFromBool(f))); } diff --git a/test/behavior/bugs/11995.zig b/test/behavior/bugs/11995.zig index 0ee8e56214..fe554bc4bf 100644 --- a/test/behavior/bugs/11995.zig +++ b/test/behavior/bugs/11995.zig @@ -25,7 +25,7 @@ test { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var string: [5]u8 = "hello".*; - const arg_data = wuffs_base__slice_u8{ .ptr = @ptrCast([*c]u8, &string), .len = string.len }; + const arg_data = wuffs_base__slice_u8{ .ptr = @as([*c]u8, @ptrCast(&string)), .len = string.len }; var arg_meta = wuffs_base__io_buffer_meta{ .wi = 1, .ri = 2, .pos = 3, .closed = true }; wuffs_base__make_io_buffer(arg_data, &arg_meta); try std.testing.expectEqualStrings("wello", arg_data.ptr[0..arg_data.len]); diff --git a/test/behavior/bugs/12051.zig b/test/behavior/bugs/12051.zig index 5509ab97cd..342e851b77 100644 --- a/test/behavior/bugs/12051.zig +++ b/test/behavior/bugs/12051.zig @@ -30,8 +30,8 @@ const Y = struct { return .{ .a = 0, .b = false, - .c = @bitCast(Z, @as(u32, 0)), - .d = @bitCast(Z, @as(u32, 0)), + .c = @as(Z, @bitCast(@as(u32, 0))), + .d = @as(Z, @bitCast(@as(u32, 0))), }; } }; diff --git a/test/behavior/bugs/12119.zig b/test/behavior/bugs/12119.zig index bb5167a3da..6cfb015eb0 100644 --- a/test/behavior/bugs/12119.zig +++ b/test/behavior/bugs/12119.zig @@ -12,6 +12,6 @@ test { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; const zerox32: u8x32 = [_]u8{0} ** 32; - const bigsum: u32x8 = @bitCast(u32x8, zerox32); + const bigsum: u32x8 = @as(u32x8, @bitCast(zerox32)); try std.testing.expectEqual(0, @reduce(.Add, bigsum)); } diff --git a/test/behavior/bugs/12450.zig b/test/behavior/bugs/12450.zig index db91529051..5ab6565f3c 100644 --- a/test/behavior/bugs/12450.zig +++ b/test/behavior/bugs/12450.zig @@ -16,7 +16,7 @@ test { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - var f1: *align(16) Foo = @alignCast(16, @ptrCast(*align(1) Foo, &buffer[0])); + var f1: *align(16) Foo = @alignCast(@as(*align(1) Foo, @ptrCast(&buffer[0]))); try expect(@typeInfo(@TypeOf(f1)).Pointer.alignment == 16); try expect(@intFromPtr(f1) == @intFromPtr(&f1.a)); try expect(@typeInfo(@TypeOf(&f1.a)).Pointer.alignment == 16); diff --git a/test/behavior/bugs/12723.zig b/test/behavior/bugs/12723.zig index abecf89025..955cc11c11 100644 --- a/test/behavior/bugs/12723.zig +++ b/test/behavior/bugs/12723.zig @@ -3,6 +3,6 @@ const expect = @import("std").testing.expect; test "Non-exhaustive enum backed by comptime_int" { const E = enum(comptime_int) { a, b, c, _ }; comptime var e: E = .a; - e = @enumFromInt(E, 378089457309184723749); + e = @as(E, @enumFromInt(378089457309184723749)); try expect(@intFromEnum(e) == 378089457309184723749); } diff --git a/test/behavior/bugs/13664.zig b/test/behavior/bugs/13664.zig index 34f6e9110b..b0ea3f70af 100644 --- a/test/behavior/bugs/13664.zig +++ b/test/behavior/bugs/13664.zig @@ -21,7 +21,7 @@ test { const timestamp: i64 = value(); const id = ID{ .fields = Fields{ - .timestamp = @intCast(u50, timestamp), + .timestamp = @as(u50, @intCast(timestamp)), .random_bits = 420, } }; try std.testing.expect((ID{ .value = id.value }).fields.timestamp == timestamp); diff --git a/test/behavior/bugs/421.zig b/test/behavior/bugs/421.zig index 1ed4a66738..f92bfb9899 100644 --- a/test/behavior/bugs/421.zig +++ b/test/behavior/bugs/421.zig @@ -16,6 +16,6 @@ fn testBitCastArray() !void { } fn extractOne64(a: u128) u64 { - const x = @bitCast([2]u64, a); + const x = @as([2]u64, @bitCast(a)); return x[1]; } diff --git a/test/behavior/bugs/6781.zig b/test/behavior/bugs/6781.zig index 2f5d7a3807..aac0c31a11 100644 --- a/test/behavior/bugs/6781.zig +++ b/test/behavior/bugs/6781.zig @@ -23,7 +23,7 @@ pub const JournalHeader = packed struct { var target: [32]u8 = undefined; std.crypto.hash.Blake3.hash(entry[checksum_offset + checksum_size ..], target[0..], .{}); - return @bitCast(u128, target[0..checksum_size].*); + return @as(u128, @bitCast(target[0..checksum_size].*)); } pub fn calculate_hash_chain_root(self: *const JournalHeader) u128 { @@ -42,16 +42,16 @@ pub const JournalHeader = packed struct { assert(prev_hash_chain_root_offset + prev_hash_chain_root_size == checksum_offset); - const header = @bitCast([@sizeOf(JournalHeader)]u8, self.*); + const header = @as([@sizeOf(JournalHeader)]u8, @bitCast(self.*)); const source = header[prev_hash_chain_root_offset .. checksum_offset + checksum_size]; assert(source.len == prev_hash_chain_root_size + checksum_size); var target: [32]u8 = undefined; std.crypto.hash.Blake3.hash(source, target[0..], .{}); if (segfault) { - return @bitCast(u128, target[0..hash_chain_root_size].*); + return @as(u128, @bitCast(target[0..hash_chain_root_size].*)); } else { var array = target[0..hash_chain_root_size].*; - return @bitCast(u128, array); + return @as(u128, @bitCast(array)); } } diff --git a/test/behavior/bugs/718.zig b/test/behavior/bugs/718.zig index b0f0d1ec52..0dad101e4b 100644 --- a/test/behavior/bugs/718.zig +++ b/test/behavior/bugs/718.zig @@ -15,7 +15,7 @@ test "zero keys with @memset" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - @memset(@ptrCast([*]u8, &keys)[0..@sizeOf(@TypeOf(keys))], 0); + @memset(@as([*]u8, @ptrCast(&keys))[0..@sizeOf(@TypeOf(keys))], 0); try expect(!keys.up); try expect(!keys.down); try expect(!keys.left); diff --git a/test/behavior/bugs/726.zig b/test/behavior/bugs/726.zig index 0cd8abc1cf..37e8d31cc9 100644 --- a/test/behavior/bugs/726.zig +++ b/test/behavior/bugs/726.zig @@ -8,7 +8,7 @@ test "@ptrCast from const to nullable" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; const c: u8 = 4; - var x: ?*const u8 = @ptrCast(?*const u8, &c); + var x: ?*const u8 = @as(?*const u8, @ptrCast(&c)); try expect(x.?.* == 4); } @@ -21,6 +21,6 @@ test "@ptrCast from var in empty struct to nullable" { const container = struct { var c: u8 = 4; }; - var x: ?*const u8 = @ptrCast(?*const u8, &container.c); + var x: ?*const u8 = @as(?*const u8, @ptrCast(&container.c)); try expect(x.?.* == 4); } diff --git a/test/behavior/builtin_functions_returning_void_or_noreturn.zig b/test/behavior/builtin_functions_returning_void_or_noreturn.zig index ae369c4e9d..1eb2ef3049 100644 --- a/test/behavior/builtin_functions_returning_void_or_noreturn.zig +++ b/test/behavior/builtin_functions_returning_void_or_noreturn.zig @@ -17,8 +17,8 @@ test { try testing.expectEqual(void, @TypeOf(@breakpoint())); try testing.expectEqual({}, @export(x, .{ .name = "x" })); try testing.expectEqual({}, @fence(.Acquire)); - try testing.expectEqual({}, @memcpy(@ptrFromInt([*]u8, 1)[0..0], @ptrFromInt([*]u8, 1)[0..0])); - try testing.expectEqual({}, @memset(@ptrFromInt([*]u8, 1)[0..0], undefined)); + try testing.expectEqual({}, @memcpy(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0])); + try testing.expectEqual({}, @memset(@as([*]u8, @ptrFromInt(1))[0..0], undefined)); try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {})); try testing.expectEqual({}, @prefetch(&val, .{})); try testing.expectEqual({}, @setAlignStack(16)); diff --git a/test/behavior/byteswap.zig b/test/behavior/byteswap.zig index 8d28285d27..ce33834ffa 100644 --- a/test/behavior/byteswap.zig +++ b/test/behavior/byteswap.zig @@ -16,13 +16,13 @@ test "@byteSwap integers" { try t(u8, 0x12, 0x12); try t(u16, 0x1234, 0x3412); try t(u24, 0x123456, 0x563412); - try t(i24, @bitCast(i24, @as(u24, 0xf23456)), 0x5634f2); - try t(i24, 0x1234f6, @bitCast(i24, @as(u24, 0xf63412))); + try t(i24, @as(i24, @bitCast(@as(u24, 0xf23456))), 0x5634f2); + try t(i24, 0x1234f6, @as(i24, @bitCast(@as(u24, 0xf63412)))); try t(u32, 0x12345678, 0x78563412); - try t(i32, @bitCast(i32, @as(u32, 0xf2345678)), 0x785634f2); - try t(i32, 0x123456f8, @bitCast(i32, @as(u32, 0xf8563412))); + try t(i32, @as(i32, @bitCast(@as(u32, 0xf2345678))), 0x785634f2); + try t(i32, 0x123456f8, @as(i32, @bitCast(@as(u32, 0xf8563412)))); try t(u40, 0x123456789a, 0x9a78563412); - try t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412))); + try t(i48, 0x123456789abc, @as(i48, @bitCast(@as(u48, 0xbc9a78563412)))); try t(u56, 0x123456789abcde, 0xdebc9a78563412); try t(u64, 0x123456789abcdef1, 0xf1debc9a78563412); try t(u88, 0x123456789abcdef1112131, 0x312111f1debc9a78563412); @@ -31,19 +31,19 @@ test "@byteSwap integers" { try t(u0, @as(u0, 0), 0); try t(i8, @as(i8, -50), -50); - try t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412))); - try t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412))); - try t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412))); - try t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412)); - try t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412))); - try t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412))); - try t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412))); - try t(i88, @bitCast(i88, @as(u88, 0x123456789abcdef1112131)), @bitCast(i88, @as(u88, 0x312111f1debc9a78563412))); - try t(i96, @bitCast(i96, @as(u96, 0x123456789abcdef111213141)), @bitCast(i96, @as(u96, 0x41312111f1debc9a78563412))); + try t(i16, @as(i16, @bitCast(@as(u16, 0x1234))), @as(i16, @bitCast(@as(u16, 0x3412)))); + try t(i24, @as(i24, @bitCast(@as(u24, 0x123456))), @as(i24, @bitCast(@as(u24, 0x563412)))); + try t(i32, @as(i32, @bitCast(@as(u32, 0x12345678))), @as(i32, @bitCast(@as(u32, 0x78563412)))); + try t(u40, @as(i40, @bitCast(@as(u40, 0x123456789a))), @as(u40, 0x9a78563412)); + try t(i48, @as(i48, @bitCast(@as(u48, 0x123456789abc))), @as(i48, @bitCast(@as(u48, 0xbc9a78563412)))); + try t(i56, @as(i56, @bitCast(@as(u56, 0x123456789abcde))), @as(i56, @bitCast(@as(u56, 0xdebc9a78563412)))); + try t(i64, @as(i64, @bitCast(@as(u64, 0x123456789abcdef1))), @as(i64, @bitCast(@as(u64, 0xf1debc9a78563412)))); + try t(i88, @as(i88, @bitCast(@as(u88, 0x123456789abcdef1112131))), @as(i88, @bitCast(@as(u88, 0x312111f1debc9a78563412)))); + try t(i96, @as(i96, @bitCast(@as(u96, 0x123456789abcdef111213141))), @as(i96, @bitCast(@as(u96, 0x41312111f1debc9a78563412)))); try t( i128, - @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)), - @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)), + @as(i128, @bitCast(@as(u128, 0x123456789abcdef11121314151617181))), + @as(i128, @bitCast(@as(u128, 0x8171615141312111f1debc9a78563412))), ); } fn t(comptime I: type, input: I, expected_output: I) !void { diff --git a/test/behavior/call.zig b/test/behavior/call.zig index 627df37e9b..633f5e9c3f 100644 --- a/test/behavior/call.zig +++ b/test/behavior/call.zig @@ -368,7 +368,7 @@ test "Enum constructed by @Type passed as generic argument" { } }; inline for (@typeInfo(S.E).Enum.fields, 0..) |_, i| { - try S.foo(@enumFromInt(S.E, i), i); + try S.foo(@as(S.E, @enumFromInt(i)), i); } } diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index d51d864ea1..e6aa53bd41 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -10,13 +10,13 @@ const native_endian = builtin.target.cpu.arch.endian(); test "int to ptr cast" { const x = @as(usize, 13); - const y = @ptrFromInt(*u8, x); + const y = @as(*u8, @ptrFromInt(x)); const z = @intFromPtr(y); try expect(z == 13); } test "integer literal to pointer cast" { - const vga_mem = @ptrFromInt(*u16, 0xB8000); + const vga_mem = @as(*u16, @ptrFromInt(0xB8000)); try expect(@intFromPtr(vga_mem) == 0xB8000); } @@ -52,7 +52,7 @@ fn testResolveUndefWithInt(b: bool, x: i32) !void { } test "@intCast to comptime_int" { - try expect(@intCast(comptime_int, 0) == 0); + try expect(@as(comptime_int, @intCast(0)) == 0); } test "implicit cast comptime numbers to any type when the value fits" { @@ -68,29 +68,29 @@ test "implicit cast comptime_int to comptime_float" { test "comptime_int @floatFromInt" { { - const result = @floatFromInt(f16, 1234); + const result = @as(f16, @floatFromInt(1234)); try expect(@TypeOf(result) == f16); try expect(result == 1234.0); } { - const result = @floatFromInt(f32, 1234); + const result = @as(f32, @floatFromInt(1234)); try expect(@TypeOf(result) == f32); try expect(result == 1234.0); } { - const result = @floatFromInt(f64, 1234); + const result = @as(f64, @floatFromInt(1234)); try expect(@TypeOf(result) == f64); try expect(result == 1234.0); } { - const result = @floatFromInt(f128, 1234); + const result = @as(f128, @floatFromInt(1234)); try expect(@TypeOf(result) == f128); try expect(result == 1234.0); } // big comptime_int (> 64 bits) to f128 conversion { - const result = @floatFromInt(f128, 0x1_0000_0000_0000_0000); + const result = @as(f128, @floatFromInt(0x1_0000_0000_0000_0000)); try expect(@TypeOf(result) == f128); try expect(result == 0x1_0000_0000_0000_0000.0); } @@ -107,8 +107,8 @@ test "@floatFromInt" { } fn testIntToFloat(k: i32) !void { - const f = @floatFromInt(f32, k); - const i = @intFromFloat(i32, f); + const f = @as(f32, @floatFromInt(k)); + const i = @as(i32, @intFromFloat(f)); try expect(i == k); } }; @@ -131,8 +131,8 @@ test "@floatFromInt(f80)" { fn testIntToFloat(comptime Int: type, k: Int) !void { @setRuntimeSafety(false); // TODO - const f = @floatFromInt(f80, k); - const i = @intFromFloat(Int, f); + const f = @as(f80, @floatFromInt(k)); + const i = @as(Int, @intFromFloat(f)); try expect(i == k); } }; @@ -165,7 +165,7 @@ test "@intFromFloat" { fn testIntFromFloats() !void { const x = @as(i32, 1e4); try expect(x == 10000); - const y = @intFromFloat(i32, @as(f32, 1e4)); + const y = @as(i32, @intFromFloat(@as(f32, 1e4))); try expect(y == 10000); try expectIntFromFloat(f32, 255.1, u8, 255); try expectIntFromFloat(f32, 127.2, i8, 127); @@ -173,7 +173,7 @@ fn testIntFromFloats() !void { } fn expectIntFromFloat(comptime F: type, f: F, comptime I: type, i: I) !void { - try expect(@intFromFloat(I, f) == i); + try expect(@as(I, @intFromFloat(f)) == i); } test "implicitly cast indirect pointer to maybe-indirect pointer" { @@ -208,29 +208,29 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" { } test "@intCast comptime_int" { - const result = @intCast(i32, 1234); + const result = @as(i32, @intCast(1234)); try expect(@TypeOf(result) == i32); try expect(result == 1234); } test "@floatCast comptime_int and comptime_float" { { - const result = @floatCast(f16, 1234); + const result = @as(f16, @floatCast(1234)); try expect(@TypeOf(result) == f16); try expect(result == 1234.0); } { - const result = @floatCast(f16, 1234.0); + const result = @as(f16, @floatCast(1234.0)); try expect(@TypeOf(result) == f16); try expect(result == 1234.0); } { - const result = @floatCast(f32, 1234); + const result = @as(f32, @floatCast(1234)); try expect(@TypeOf(result) == f32); try expect(result == 1234.0); } { - const result = @floatCast(f32, 1234.0); + const result = @as(f32, @floatCast(1234.0)); try expect(@TypeOf(result) == f32); try expect(result == 1234.0); } @@ -276,21 +276,21 @@ test "*usize to *void" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var i = @as(usize, 0); - var v = @ptrCast(*void, &i); + var v = @as(*void, @ptrCast(&i)); v.* = {}; } test "@enumFromInt passed a comptime_int to an enum with one item" { const E = enum { A }; - const x = @enumFromInt(E, 0); + const x = @as(E, @enumFromInt(0)); try expect(x == E.A); } test "@intCast to u0 and use the result" { const S = struct { fn doTheTest(zero: u1, one: u1, bigzero: i32) !void { - try expect((one << @intCast(u0, bigzero)) == 1); - try expect((zero << @intCast(u0, bigzero)) == 0); + try expect((one << @as(u0, @intCast(bigzero))) == 1); + try expect((zero << @as(u0, @intCast(bigzero))) == 0); } }; try S.doTheTest(0, 1, 0); @@ -605,7 +605,7 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" { const window_name = [1][*]const u8{"window name"}; const x: [*]const ?[*]const u8 = &window_name; - try expect(mem.eql(u8, std.mem.sliceTo(@ptrCast([*:0]const u8, x[0].?), 0), "window name")); + try expect(mem.eql(u8, std.mem.sliceTo(@as([*:0]const u8, @ptrCast(x[0].?)), 0), "window name")); } test "vector casts" { @@ -625,9 +625,9 @@ test "vector casts" { var up3 = @as(@Vector(2, u64), up0); // Downcast (safety-checked) var down0 = up3; - var down1 = @intCast(@Vector(2, u32), down0); - var down2 = @intCast(@Vector(2, u16), down0); - var down3 = @intCast(@Vector(2, u8), down0); + var down1 = @as(@Vector(2, u32), @intCast(down0)); + var down2 = @as(@Vector(2, u16), @intCast(down0)); + var down3 = @as(@Vector(2, u8), @intCast(down0)); try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa })); try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa })); @@ -660,12 +660,12 @@ test "@floatCast cast down" { { var double: f64 = 0.001534; - var single = @floatCast(f32, double); + var single = @as(f32, @floatCast(double)); try expect(single == 0.001534); } { const double: f64 = 0.001534; - const single = @floatCast(f32, double); + const single = @as(f32, @floatCast(double)); try expect(single == 0.001534); } } @@ -1041,7 +1041,7 @@ test "cast between C pointer with different but compatible types" { } fn doTheTest() !void { var x = [_]u16{ 4, 2, 1, 3 }; - try expect(foo(@ptrCast([*]u16, &x)) == 4); + try expect(foo(@as([*]u16, @ptrCast(&x))) == 4); } }; try S.doTheTest(); @@ -1093,10 +1093,10 @@ test "peer type resolve array pointer and unknown pointer" { test "comptime float casts" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - const a = @floatFromInt(comptime_float, 1); + const a = @as(comptime_float, @floatFromInt(1)); try expect(a == 1); try expect(@TypeOf(a) == comptime_float); - const b = @intFromFloat(comptime_int, 2); + const b = @as(comptime_int, @intFromFloat(2)); try expect(b == 2); try expect(@TypeOf(b) == comptime_int); @@ -1111,7 +1111,7 @@ test "pointer reinterpret const float to int" { // The hex representation is 0x3fe3333333333303. const float: f64 = 5.99999999999994648725e-01; const float_ptr = &float; - const int_ptr = @ptrCast(*const i32, float_ptr); + const int_ptr = @as(*const i32, @ptrCast(float_ptr)); const int_val = int_ptr.*; if (native_endian == .Little) try expect(int_val == 0x33333303) @@ -1134,7 +1134,7 @@ test "implicit cast from [*]T to ?*anyopaque" { fn incrementVoidPtrArray(array: ?*anyopaque, len: usize) void { var n: usize = 0; while (n < len) : (n += 1) { - @ptrCast([*]u8, array.?)[n] += 1; + @as([*]u8, @ptrCast(array.?))[n] += 1; } } @@ -1146,7 +1146,7 @@ test "compile time int to ptr of function" { // On some architectures function pointers must be aligned. const hardcoded_fn_addr = maxInt(usize) & ~@as(usize, 0xf); -pub const FUNCTION_CONSTANT = @ptrFromInt(PFN_void, hardcoded_fn_addr); +pub const FUNCTION_CONSTANT = @as(PFN_void, @ptrFromInt(hardcoded_fn_addr)); pub const PFN_void = *const fn (*anyopaque) callconv(.C) void; fn foobar(func: PFN_void) !void { @@ -1161,10 +1161,10 @@ test "implicit ptr to *anyopaque" { var a: u32 = 1; var ptr: *align(@alignOf(u32)) anyopaque = &a; - var b: *u32 = @ptrCast(*u32, ptr); + var b: *u32 = @as(*u32, @ptrCast(ptr)); try expect(b.* == 1); var ptr2: ?*align(@alignOf(u32)) anyopaque = &a; - var c: *u32 = @ptrCast(*u32, ptr2.?); + var c: *u32 = @as(*u32, @ptrCast(ptr2.?)); try expect(c.* == 1); } @@ -1235,11 +1235,11 @@ fn testCast128() !void { } fn cast128Int(x: f128) u128 { - return @bitCast(u128, x); + return @as(u128, @bitCast(x)); } fn cast128Float(x: u128) f128 { - return @bitCast(f128, x); + return @as(f128, @bitCast(x)); } test "implicit cast from *[N]T to ?[*]T" { @@ -1270,7 +1270,7 @@ test "implicit cast from *T to ?*anyopaque" { } fn incrementVoidPtrValue(value: ?*anyopaque) void { - @ptrCast(*u8, value.?).* += 1; + @as(*u8, @ptrCast(value.?)).* += 1; } test "implicit cast *[0]T to E![]const u8" { @@ -1284,11 +1284,11 @@ test "implicit cast *[0]T to E![]const u8" { var global_array: [4]u8 = undefined; test "cast from array reference to fn: comptime fn ptr" { - const f = @ptrCast(*align(1) const fn () callconv(.C) void, &global_array); + const f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array)); try expect(@intFromPtr(f) == @intFromPtr(&global_array)); } test "cast from array reference to fn: runtime fn ptr" { - var f = @ptrCast(*align(1) const fn () callconv(.C) void, &global_array); + var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array)); try expect(@intFromPtr(f) == @intFromPtr(&global_array)); } @@ -1337,7 +1337,7 @@ test "assignment to optional pointer result loc" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var foo: struct { ptr: ?*anyopaque } = .{ .ptr = &global_struct }; - try expect(foo.ptr.? == @ptrCast(*anyopaque, &global_struct)); + try expect(foo.ptr.? == @as(*anyopaque, @ptrCast(&global_struct))); } test "cast between *[N]void and []void" { @@ -1393,9 +1393,9 @@ test "cast f128 to narrower types" { const S = struct { fn doTheTest() !void { var x: f128 = 1234.0; - try expect(@as(f16, 1234.0) == @floatCast(f16, x)); - try expect(@as(f32, 1234.0) == @floatCast(f32, x)); - try expect(@as(f64, 1234.0) == @floatCast(f64, x)); + try expect(@as(f16, 1234.0) == @as(f16, @floatCast(x))); + try expect(@as(f32, 1234.0) == @as(f32, @floatCast(x))); + try expect(@as(f64, 1234.0) == @as(f64, @floatCast(x))); } }; try S.doTheTest(); @@ -1500,8 +1500,8 @@ test "coerce between pointers of compatible differently-named floats" { } test "peer type resolution of const and non-const pointer to array" { - const a = @ptrFromInt(*[1024]u8, 42); - const b = @ptrFromInt(*const [1024]u8, 42); + const a = @as(*[1024]u8, @ptrFromInt(42)); + const b = @as(*const [1024]u8, @ptrFromInt(42)); try std.testing.expect(@TypeOf(a, b) == *const [1024]u8); try std.testing.expect(a == b); } @@ -1512,7 +1512,7 @@ test "intFromFloat to zero-bit int" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO const a: f32 = 0.0; - try comptime std.testing.expect(@intFromFloat(u0, a) == 0); + try comptime std.testing.expect(@as(u0, @intFromFloat(a)) == 0); } test "peer type resolution of function pointer and function body" { @@ -1547,10 +1547,10 @@ test "bitcast packed struct with u0" { if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO const S = packed struct(u2) { a: u0, b: u2 }; - const s = @bitCast(S, @as(u2, 2)); + const s = @as(S, @bitCast(@as(u2, 2))); try expect(s.a == 0); try expect(s.b == 2); - const i = @bitCast(u2, s); + const i = @as(u2, @bitCast(s)); try expect(i == 2); } @@ -1560,7 +1560,7 @@ test "optional pointer coerced to optional allowzero pointer" { var p: ?*u32 = undefined; var q: ?*allowzero u32 = undefined; - p = @ptrFromInt(*u32, 4); + p = @as(*u32, @ptrFromInt(4)); q = p; try expect(@intFromPtr(q.?) == 4); } @@ -1583,7 +1583,7 @@ test "peer type resolution forms error union" { 0 => unreachable, 42 => error.AccessDenied, else => unreachable, - } else @intCast(u32, foo); + } else @as(u32, @intCast(foo)); try expect(try result == 123); } @@ -1623,8 +1623,8 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice" const S = struct { fn doTheTest(comptime T: type, comptime s: T) !void { - var a: [:s]const T = @ptrFromInt(*const [2:s]T, 0x1000); - var b: []T = @ptrFromInt(*[3]T, 0x2000); + var a: [:s]const T = @as(*const [2:s]T, @ptrFromInt(0x1000)); + var b: []T = @as(*[3]T, @ptrFromInt(0x2000)); comptime assert(@TypeOf(a, b) == []const T); comptime assert(@TypeOf(b, a) == []const T); @@ -1634,8 +1634,8 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice" const R = @TypeOf(r1); - try expectEqual(@as(R, @ptrFromInt(*const [2:s]T, 0x1000)), r1); - try expectEqual(@as(R, @ptrFromInt(*const [3]T, 0x2000)), r2); + try expectEqual(@as(R, @as(*const [2:s]T, @ptrFromInt(0x1000))), r1); + try expectEqual(@as(R, @as(*const [3]T, @ptrFromInt(0x2000))), r2); } }; @@ -1815,7 +1815,7 @@ test "peer type resolution: three-way resolution combines error set and optional const E = error{Foo}; var a: E = error.Foo; - var b: *const [5:0]u8 = @ptrFromInt(*const [5:0]u8, 0x1000); + var b: *const [5:0]u8 = @as(*const [5:0]u8, @ptrFromInt(0x1000)); var c: ?[*:0]u8 = null; comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8); comptime assert(@TypeOf(a, c, b) == E!?[*:0]const u8); @@ -1844,7 +1844,7 @@ test "peer type resolution: three-way resolution combines error set and optional const T = @TypeOf(r1); try expectEqual(@as(T, error.Foo), r1); - try expectEqual(@as(T, @ptrFromInt([*:0]u8, 0x1000)), r2); + try expectEqual(@as(T, @as([*:0]u8, @ptrFromInt(0x1000))), r2); try expectEqual(@as(T, null), r3); } @@ -2114,7 +2114,7 @@ test "peer type resolution: many compatible pointers" { 4 => "foo-4", else => unreachable, }; - try expectEqualSlices(u8, expected, std.mem.span(@ptrCast([*:0]const u8, r))); + try expectEqualSlices(u8, expected, std.mem.span(@as([*:0]const u8, @ptrCast(r)))); } } diff --git a/test/behavior/cast_int.zig b/test/behavior/cast_int.zig index 041ee193e8..6d4f530409 100644 --- a/test/behavior/cast_int.zig +++ b/test/behavior/cast_int.zig @@ -11,6 +11,6 @@ test "@intCast i32 to u7" { var x: u128 = maxInt(u128); var y: i32 = 120; - var z = x >> @intCast(u7, y); + var z = x >> @as(u7, @intCast(y)); try expect(z == 0xff); } diff --git a/test/behavior/comptime_memory.zig b/test/behavior/comptime_memory.zig index d327afb783..b0c5e9c91e 100644 --- a/test/behavior/comptime_memory.zig +++ b/test/behavior/comptime_memory.zig @@ -6,7 +6,7 @@ const ptr_size = @sizeOf(usize); test "type pun signed and unsigned as single pointer" { comptime { var x: u32 = 0; - const y = @ptrCast(*i32, &x); + const y = @as(*i32, @ptrCast(&x)); y.* = -1; try testing.expectEqual(@as(u32, 0xFFFFFFFF), x); } @@ -15,7 +15,7 @@ test "type pun signed and unsigned as single pointer" { test "type pun signed and unsigned as many pointer" { comptime { var x: u32 = 0; - const y = @ptrCast([*]i32, &x); + const y = @as([*]i32, @ptrCast(&x)); y[0] = -1; try testing.expectEqual(@as(u32, 0xFFFFFFFF), x); } @@ -24,7 +24,7 @@ test "type pun signed and unsigned as many pointer" { test "type pun signed and unsigned as array pointer" { comptime { var x: u32 = 0; - const y = @ptrCast(*[1]i32, &x); + const y = @as(*[1]i32, @ptrCast(&x)); y[0] = -1; try testing.expectEqual(@as(u32, 0xFFFFFFFF), x); } @@ -38,7 +38,7 @@ test "type pun signed and unsigned as offset many pointer" { comptime { var x: u32 = 0; - var y = @ptrCast([*]i32, &x); + var y = @as([*]i32, @ptrCast(&x)); y -= 10; y[10] = -1; try testing.expectEqual(@as(u32, 0xFFFFFFFF), x); @@ -53,7 +53,7 @@ test "type pun signed and unsigned as array pointer with pointer arithemtic" { comptime { var x: u32 = 0; - const y = @ptrCast([*]i32, &x) - 10; + const y = @as([*]i32, @ptrCast(&x)) - 10; const z: *[15]i32 = y[0..15]; z[10] = -1; try testing.expectEqual(@as(u32, 0xFFFFFFFF), x); @@ -64,9 +64,9 @@ test "type pun value and struct" { comptime { const StructOfU32 = extern struct { x: u32 }; var inst: StructOfU32 = .{ .x = 0 }; - @ptrCast(*i32, &inst.x).* = -1; + @as(*i32, @ptrCast(&inst.x)).* = -1; try testing.expectEqual(@as(u32, 0xFFFFFFFF), inst.x); - @ptrCast(*i32, &inst).* = -2; + @as(*i32, @ptrCast(&inst)).* = -2; try testing.expectEqual(@as(u32, 0xFFFFFFFE), inst.x); } } @@ -81,8 +81,8 @@ test "type pun endianness" { comptime { const StructOfBytes = extern struct { x: [4]u8 }; var inst: StructOfBytes = .{ .x = [4]u8{ 0, 0, 0, 0 } }; - const structPtr = @ptrCast(*align(1) u32, &inst); - const arrayPtr = @ptrCast(*align(1) u32, &inst.x); + const structPtr = @as(*align(1) u32, @ptrCast(&inst)); + const arrayPtr = @as(*align(1) u32, @ptrCast(&inst.x)); inst.x[0] = 0xFE; inst.x[2] = 0xBE; try testing.expectEqual(bigToNativeEndian(u32, 0xFE00BE00), structPtr.*); @@ -124,8 +124,8 @@ fn shuffle(ptr: usize, comptime From: type, comptime To: type) usize { @compileError("Mismatched sizes! " ++ @typeName(From) ++ " and " ++ @typeName(To) ++ " must have the same size!"); const array_len = @divExact(ptr_size, @sizeOf(From)); var result: usize = 0; - const pSource = @ptrCast(*align(1) const [array_len]From, &ptr); - const pResult = @ptrCast(*align(1) [array_len]To, &result); + const pSource = @as(*align(1) const [array_len]From, @ptrCast(&ptr)); + const pResult = @as(*align(1) [array_len]To, @ptrCast(&result)); var i: usize = 0; while (i < array_len) : (i += 1) { inline for (@typeInfo(To).Struct.fields) |f| { @@ -136,8 +136,8 @@ fn shuffle(ptr: usize, comptime From: type, comptime To: type) usize { } fn doTypePunBitsTest(as_bits: *Bits) !void { - const as_u32 = @ptrCast(*align(1) u32, as_bits); - const as_bytes = @ptrCast(*[4]u8, as_bits); + const as_u32 = @as(*align(1) u32, @ptrCast(as_bits)); + const as_bytes = @as(*[4]u8, @ptrCast(as_bits)); as_u32.* = bigToNativeEndian(u32, 0xB0A7DEED); try testing.expectEqual(@as(u1, 0x00), as_bits.p0); try testing.expectEqual(@as(u4, 0x08), as_bits.p1); @@ -176,7 +176,7 @@ test "type pun bits" { comptime { var v: u32 = undefined; - try doTypePunBitsTest(@ptrCast(*Bits, &v)); + try doTypePunBitsTest(@as(*Bits, @ptrCast(&v))); } } @@ -194,7 +194,7 @@ test "basic pointer preservation" { comptime { const lazy_address = @intFromPtr(&imports.global_u32); try testing.expectEqual(@intFromPtr(&imports.global_u32), lazy_address); - try testing.expectEqual(&imports.global_u32, @ptrFromInt(*u32, lazy_address)); + try testing.expectEqual(&imports.global_u32, @as(*u32, @ptrFromInt(lazy_address))); } } @@ -207,8 +207,8 @@ test "byte copy preserves linker value" { const ct_value = comptime blk: { const lazy = &imports.global_u32; var result: *u32 = undefined; - const pSource = @ptrCast(*const [ptr_size]u8, &lazy); - const pResult = @ptrCast(*[ptr_size]u8, &result); + const pSource = @as(*const [ptr_size]u8, @ptrCast(&lazy)); + const pResult = @as(*[ptr_size]u8, @ptrCast(&result)); var i: usize = 0; while (i < ptr_size) : (i += 1) { pResult[i] = pSource[i]; @@ -230,8 +230,8 @@ test "unordered byte copy preserves linker value" { const ct_value = comptime blk: { const lazy = &imports.global_u32; var result: *u32 = undefined; - const pSource = @ptrCast(*const [ptr_size]u8, &lazy); - const pResult = @ptrCast(*[ptr_size]u8, &result); + const pSource = @as(*const [ptr_size]u8, @ptrCast(&lazy)); + const pResult = @as(*[ptr_size]u8, @ptrCast(&result)); if (ptr_size > 8) @compileError("This array needs to be expanded for platform with very big pointers"); const shuffled_indices = [_]usize{ 4, 5, 2, 6, 1, 3, 0, 7 }; for (shuffled_indices) |i| { @@ -274,12 +274,12 @@ test "dance on linker values" { arr[0] = @intFromPtr(&imports.global_u32); arr[1] = @intFromPtr(&imports.global_u32); - const weird_ptr = @ptrCast([*]Bits, @ptrCast([*]u8, &arr) + @sizeOf(usize) - 3); + const weird_ptr = @as([*]Bits, @ptrCast(@as([*]u8, @ptrCast(&arr)) + @sizeOf(usize) - 3)); try doTypePunBitsTest(&weird_ptr[0]); if (ptr_size > @sizeOf(Bits)) try doTypePunBitsTest(&weird_ptr[1]); - var arr_bytes = @ptrCast(*[2][ptr_size]u8, &arr); + var arr_bytes = @as(*[2][ptr_size]u8, @ptrCast(&arr)); var rebuilt_bytes: [ptr_size]u8 = undefined; var i: usize = 0; @@ -290,7 +290,7 @@ test "dance on linker values" { rebuilt_bytes[i] = arr_bytes[1][i]; } - try testing.expectEqual(&imports.global_u32, @ptrFromInt(*u32, @bitCast(usize, rebuilt_bytes))); + try testing.expectEqual(&imports.global_u32, @as(*u32, @ptrFromInt(@as(usize, @bitCast(rebuilt_bytes))))); } } @@ -316,7 +316,7 @@ test "offset array ptr by element size" { try testing.expectEqual(@intFromPtr(&arr[2]), address + 2 * @sizeOf(VirtualStruct)); try testing.expectEqual(@intFromPtr(&arr[3]), address + @sizeOf(VirtualStruct) * 3); - const secondElement = @ptrFromInt(*VirtualStruct, @intFromPtr(&arr[0]) + 2 * @sizeOf(VirtualStruct)); + const secondElement = @as(*VirtualStruct, @ptrFromInt(@intFromPtr(&arr[0]) + 2 * @sizeOf(VirtualStruct))); try testing.expectEqual(bigToNativeEndian(u32, 0x02060a0e), secondElement.x); } } @@ -334,15 +334,15 @@ test "offset instance by field size" { var ptr = @intFromPtr(&inst); ptr -= 4; ptr += @offsetOf(VirtualStruct, "x"); - try testing.expectEqual(@as(u32, 0), @ptrFromInt([*]u32, ptr)[1]); + try testing.expectEqual(@as(u32, 0), @as([*]u32, @ptrFromInt(ptr))[1]); ptr -= @offsetOf(VirtualStruct, "x"); ptr += @offsetOf(VirtualStruct, "y"); - try testing.expectEqual(@as(u32, 1), @ptrFromInt([*]u32, ptr)[1]); + try testing.expectEqual(@as(u32, 1), @as([*]u32, @ptrFromInt(ptr))[1]); ptr = ptr - @offsetOf(VirtualStruct, "y") + @offsetOf(VirtualStruct, "z"); - try testing.expectEqual(@as(u32, 2), @ptrFromInt([*]u32, ptr)[1]); + try testing.expectEqual(@as(u32, 2), @as([*]u32, @ptrFromInt(ptr))[1]); ptr = @intFromPtr(&inst.z) - 4 - @offsetOf(VirtualStruct, "z"); ptr += @offsetOf(VirtualStruct, "w"); - try testing.expectEqual(@as(u32, 3), @ptrFromInt(*u32, ptr + 4).*); + try testing.expectEqual(@as(u32, 3), @as(*u32, @ptrFromInt(ptr + 4)).*); } } @@ -363,13 +363,13 @@ test "offset field ptr by enclosing array element size" { var i: usize = 0; while (i < 4) : (i += 1) { - var ptr: [*]u8 = @ptrCast([*]u8, &arr[0]); + var ptr: [*]u8 = @as([*]u8, @ptrCast(&arr[0])); ptr += i; ptr += @offsetOf(VirtualStruct, "x"); var j: usize = 0; while (j < 4) : (j += 1) { const base = ptr + j * @sizeOf(VirtualStruct); - try testing.expectEqual(@intCast(u8, i * 4 + j), base[0]); + try testing.expectEqual(@as(u8, @intCast(i * 4 + j)), base[0]); } } } @@ -393,7 +393,7 @@ test "accessing reinterpreted memory of parent object" { .c = 2.6, }; const ptr = &x.b[0]; - const b = @ptrCast([*c]const u8, ptr)[5]; + const b = @as([*c]const u8, @ptrCast(ptr))[5]; try testing.expect(b == expected); } } @@ -407,11 +407,11 @@ test "bitcast packed union to integer" { comptime { const a = U{ .x = 1 }; const b = U{ .y = 2 }; - const cast_a = @bitCast(u2, a); - const cast_b = @bitCast(u2, b); + const cast_a = @as(u2, @bitCast(a)); + const cast_b = @as(u2, @bitCast(b)); // truncated because the upper bit is garbage memory that we don't care about - try testing.expectEqual(@as(u1, 1), @truncate(u1, cast_a)); + try testing.expectEqual(@as(u1, 1), @as(u1, @truncate(cast_a))); try testing.expectEqual(@as(u2, 2), cast_b); } } @@ -435,6 +435,6 @@ test "dereference undefined pointer to zero-bit type" { test "type pun extern struct" { const S = extern struct { f: u8 }; comptime var s = S{ .f = 123 }; - @ptrCast(*u8, &s).* = 72; + @as(*u8, @ptrCast(&s)).* = 72; try testing.expectEqual(@as(u8, 72), s.f); } diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig index 1076f5e3ea..ffb254f765 100644 --- a/test/behavior/enum.zig +++ b/test/behavior/enum.zig @@ -20,7 +20,7 @@ test "enum to int" { } fn testIntToEnumEval(x: i32) !void { - try expect(@enumFromInt(IntToEnumNumber, x) == IntToEnumNumber.Three); + try expect(@as(IntToEnumNumber, @enumFromInt(x)) == IntToEnumNumber.Three); } const IntToEnumNumber = enum { Zero, One, Two, Three, Four }; @@ -629,7 +629,7 @@ test "non-exhaustive enum" { .b => true, _ => false, }); - e = @enumFromInt(E, 12); + e = @as(E, @enumFromInt(12)); try expect(switch (e) { .a => false, .b => false, @@ -648,9 +648,9 @@ test "non-exhaustive enum" { }); try expect(@typeInfo(E).Enum.fields.len == 2); - e = @enumFromInt(E, 12); + e = @as(E, @enumFromInt(12)); try expect(@intFromEnum(e) == 12); - e = @enumFromInt(E, y); + e = @as(E, @enumFromInt(y)); try expect(@intFromEnum(e) == 52); try expect(@typeInfo(E).Enum.is_exhaustive == false); } @@ -666,7 +666,7 @@ test "empty non-exhaustive enum" { const E = enum(u8) { _ }; fn doTheTest(y: u8) !void { - var e = @enumFromInt(E, y); + var e = @as(E, @enumFromInt(y)); try expect(switch (e) { _ => true, }); @@ -693,7 +693,7 @@ test "single field non-exhaustive enum" { .a => true, _ => false, }); - e = @enumFromInt(E, 12); + e = @as(E, @enumFromInt(12)); try expect(switch (e) { .a => false, _ => true, @@ -709,7 +709,7 @@ test "single field non-exhaustive enum" { else => false, }); - try expect(@intFromEnum(@enumFromInt(E, y)) == y); + try expect(@intFromEnum(@as(E, @enumFromInt(y))) == y); try expect(@typeInfo(E).Enum.fields.len == 1); try expect(@typeInfo(E).Enum.is_exhaustive == false); } @@ -741,8 +741,8 @@ const MultipleChoice2 = enum(u32) { }; test "cast integer literal to enum" { - try expect(@enumFromInt(MultipleChoice2, 0) == MultipleChoice2.Unspecified1); - try expect(@enumFromInt(MultipleChoice2, 40) == MultipleChoice2.B); + try expect(@as(MultipleChoice2, @enumFromInt(0)) == MultipleChoice2.Unspecified1); + try expect(@as(MultipleChoice2, @enumFromInt(40)) == MultipleChoice2.B); } test "enum with specified and unspecified tag values" { @@ -1155,7 +1155,7 @@ test "size of enum with only one tag which has explicit integer tag type" { var s1: S1 = undefined; s1.e = .nope; try expect(s1.e == .nope); - const ptr = @ptrCast(*u8, &s1); + const ptr = @as(*u8, @ptrCast(&s1)); try expect(ptr.* == 10); var s0: S0 = undefined; @@ -1183,7 +1183,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" { test "runtime int to enum with one possible value" { const E = enum { one }; var runtime: usize = 0; - if (@enumFromInt(E, runtime) != .one) { + if (@as(E, @enumFromInt(runtime)) != .one) { @compileError("test failed"); } } @@ -1194,7 +1194,7 @@ test "enum tag from a local variable" { return enum(Inner) { _ }; } }; - const i = @enumFromInt(S.Int(u32), 0); + const i = @as(S.Int(u32), @enumFromInt(0)); try std.testing.expect(@intFromEnum(i) == 0); } @@ -1203,12 +1203,12 @@ test "auto-numbered enum with signed tag type" { try std.testing.expectEqual(@as(i32, 0), @intFromEnum(E.a)); try std.testing.expectEqual(@as(i32, 1), @intFromEnum(E.b)); - try std.testing.expectEqual(E.a, @enumFromInt(E, 0)); - try std.testing.expectEqual(E.b, @enumFromInt(E, 1)); - try std.testing.expectEqual(E.a, @enumFromInt(E, @as(i32, 0))); - try std.testing.expectEqual(E.b, @enumFromInt(E, @as(i32, 1))); - try std.testing.expectEqual(E.a, @enumFromInt(E, @as(u32, 0))); - try std.testing.expectEqual(E.b, @enumFromInt(E, @as(u32, 1))); + try std.testing.expectEqual(E.a, @as(E, @enumFromInt(0))); + try std.testing.expectEqual(E.b, @as(E, @enumFromInt(1))); + try std.testing.expectEqual(E.a, @as(E, @enumFromInt(@as(i32, 0)))); + try std.testing.expectEqual(E.b, @as(E, @enumFromInt(@as(i32, 1)))); + try std.testing.expectEqual(E.a, @as(E, @enumFromInt(@as(u32, 0)))); + try std.testing.expectEqual(E.b, @as(E, @enumFromInt(@as(u32, 1)))); try std.testing.expectEqualStrings("a", @tagName(E.a)); try std.testing.expectEqualStrings("b", @tagName(E.b)); } diff --git a/test/behavior/error.zig b/test/behavior/error.zig index 14b0eca030..06062ac66c 100644 --- a/test/behavior/error.zig +++ b/test/behavior/error.zig @@ -234,9 +234,9 @@ const Set1 = error{ A, B }; const Set2 = error{ A, C }; fn testExplicitErrorSetCast(set1: Set1) !void { - var x = @errSetCast(Set2, set1); + var x = @as(Set2, @errSetCast(set1)); try expect(@TypeOf(x) == Set2); - var y = @errSetCast(Set1, x); + var y = @as(Set1, @errSetCast(x)); try expect(@TypeOf(y) == Set1); try expect(y == error.A); } diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig index 85dc5e29b5..f2b91e66ac 100644 --- a/test/behavior/eval.zig +++ b/test/behavior/eval.zig @@ -9,7 +9,7 @@ test "compile time recursion" { try expect(some_data.len == 21); } -var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined; +var some_data: [@as(usize, @intCast(fibonacci(7)))]u8 = undefined; fn fibonacci(x: i32) i32 { if (x <= 1) return 1; return fibonacci(x - 1) + fibonacci(x - 2); @@ -123,7 +123,7 @@ fn fnWithSetRuntimeSafety() i32 { test "compile-time downcast when the bits fit" { comptime { const spartan_count: u16 = 255; - const byte = @intCast(u8, spartan_count); + const byte = @as(u8, @intCast(spartan_count)); try expect(byte == 255); } } @@ -149,7 +149,7 @@ test "a type constructed in a global expression" { l.array[0] = 10; l.array[1] = 11; l.array[2] = 12; - const ptr = @ptrCast([*]u8, &l.array); + const ptr = @as([*]u8, @ptrCast(&l.array)); try expect(ptr[0] == 10); try expect(ptr[1] == 11); try expect(ptr[2] == 12); @@ -332,7 +332,7 @@ fn generateTable(comptime T: type) [1010]T { var res: [1010]T = undefined; var i: usize = 0; while (i < 1010) : (i += 1) { - res[i] = @intCast(T, i); + res[i] = @as(T, @intCast(i)); } return res; } @@ -460,7 +460,7 @@ test "binary math operator in partially inlined function" { var b: [16]u8 = undefined; for (&b, 0..) |*r, i| - r.* = @intCast(u8, i + 1); + r.* = @as(u8, @intCast(i + 1)); copyWithPartialInline(s[0..], b[0..]); try expect(s[0] == 0x1020304); @@ -942,7 +942,7 @@ test "comptime pointer load through elem_ptr" { .x = i, }; } - var ptr = @ptrCast([*]S, &array); + var ptr = @as([*]S, @ptrCast(&array)); var x = ptr[0].x; assert(x == 0); ptr += 1; @@ -1281,9 +1281,9 @@ test "comptime write through extern struct reinterpreted as array" { c: u8, }; var s: S = undefined; - @ptrCast(*[3]u8, &s)[0] = 1; - @ptrCast(*[3]u8, &s)[1] = 2; - @ptrCast(*[3]u8, &s)[2] = 3; + @as(*[3]u8, @ptrCast(&s))[0] = 1; + @as(*[3]u8, @ptrCast(&s))[1] = 2; + @as(*[3]u8, @ptrCast(&s))[2] = 3; assert(s.a == 1); assert(s.b == 2); assert(s.c == 3); @@ -1371,7 +1371,7 @@ test "lazy value is resolved as slice operand" { var a: [512]u64 = undefined; const ptr1 = a[0..@sizeOf(A)]; - const ptr2 = @ptrCast([*]u8, &a)[0..@sizeOf(A)]; + const ptr2 = @as([*]u8, @ptrCast(&a))[0..@sizeOf(A)]; try expect(@intFromPtr(ptr1) == @intFromPtr(ptr2)); try expect(ptr1.len == ptr2.len); } diff --git a/test/behavior/export.zig b/test/behavior/export.zig index 4928e86725..4751ccafe5 100644 --- a/test/behavior/export.zig +++ b/test/behavior/export.zig @@ -7,7 +7,7 @@ const builtin = @import("builtin"); // can't really run this test but we can make sure it has no compile error // and generates code -const vram = @ptrFromInt([*]volatile u8, 0x20000000)[0..0x8000]; +const vram = @as([*]volatile u8, @ptrFromInt(0x20000000))[0..0x8000]; export fn writeToVRam() void { vram[0] = 'X'; } diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig index 56f3885a4a..e21645ae8f 100644 --- a/test/behavior/floatop.zig +++ b/test/behavior/floatop.zig @@ -94,7 +94,7 @@ test "negative f128 intFromFloat at compile-time" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO const a: f128 = -2; - var b = @intFromFloat(i64, a); + var b = @as(i64, @intFromFloat(a)); try expect(@as(i64, -2) == b); } @@ -387,11 +387,11 @@ fn testLog() !void { } { var a: f32 = e; - try expect(@log(a) == 1 or @log(a) == @bitCast(f32, @as(u32, 0x3f7fffff))); + try expect(@log(a) == 1 or @log(a) == @as(f32, @bitCast(@as(u32, 0x3f7fffff)))); } { var a: f64 = e; - try expect(@log(a) == 1 or @log(a) == @bitCast(f64, @as(u64, 0x3ff0000000000000))); + try expect(@log(a) == 1 or @log(a) == @as(f64, @bitCast(@as(u64, 0x3ff0000000000000)))); } inline for ([_]type{ f16, f32, f64 }) |ty| { const eps = epsForType(ty); diff --git a/test/behavior/fn.zig b/test/behavior/fn.zig index 6c7e127964..e7b7e63e33 100644 --- a/test/behavior/fn.zig +++ b/test/behavior/fn.zig @@ -326,7 +326,7 @@ test "function pointers" { &fn4, }; for (fns, 0..) |f, i| { - try expect(f() == @intCast(u32, i) + 5); + try expect(f() == @as(u32, @intCast(i)) + 5); } } fn fn1() u32 { @@ -512,8 +512,8 @@ test "using @ptrCast on function pointers" { fn run() !void { const a = A{ .data = "abcd".* }; - const casted_fn = @ptrCast(*const fn (*const anyopaque, usize) *const u8, &at); - const casted_impl = @ptrCast(*const anyopaque, &a); + const casted_fn = @as(*const fn (*const anyopaque, usize) *const u8, @ptrCast(&at)); + const casted_impl = @as(*const anyopaque, @ptrCast(&a)); const ptr = casted_fn(casted_impl, 2); try expect(ptr.* == 'c'); } @@ -575,7 +575,7 @@ test "lazy values passed to anytype parameter" { try B.foo(.{ .x = @sizeOf(B) }); const C = struct {}; - try expect(@truncate(u32, @sizeOf(C)) == 0); + try expect(@as(u32, @truncate(@sizeOf(C))) == 0); const D = struct {}; try expect(@sizeOf(D) << 1 == 0); diff --git a/test/behavior/fn_in_struct_in_comptime.zig b/test/behavior/fn_in_struct_in_comptime.zig index b31b377c04..0acadbc5ea 100644 --- a/test/behavior/fn_in_struct_in_comptime.zig +++ b/test/behavior/fn_in_struct_in_comptime.zig @@ -14,5 +14,5 @@ fn get_foo() fn (*u8) usize { test "define a function in an anonymous struct in comptime" { const foo = get_foo(); - try expect(foo(@ptrFromInt(*u8, 12345)) == 12345); + try expect(foo(@as(*u8, @ptrFromInt(12345))) == 12345); } diff --git a/test/behavior/for.zig b/test/behavior/for.zig index 12b82c44a4..f751d35d96 100644 --- a/test/behavior/for.zig +++ b/test/behavior/for.zig @@ -84,7 +84,7 @@ test "basic for loop" { } for (array, 0..) |item, index| { _ = item; - buffer[buf_index] = @intCast(u8, index); + buffer[buf_index] = @as(u8, @intCast(index)); buf_index += 1; } const array_ptr = &array; @@ -94,7 +94,7 @@ test "basic for loop" { } for (array_ptr, 0..) |item, index| { _ = item; - buffer[buf_index] = @intCast(u8, index); + buffer[buf_index] = @as(u8, @intCast(index)); buf_index += 1; } const unknown_size: []const u8 = &array; @@ -103,7 +103,7 @@ test "basic for loop" { buf_index += 1; } for (unknown_size, 0..) |_, index| { - buffer[buf_index] = @intCast(u8, index); + buffer[buf_index] = @as(u8, @intCast(index)); buf_index += 1; } @@ -208,7 +208,7 @@ test "for on slice with allowzero ptr" { const S = struct { fn doTheTest(slice: []const u8) !void { - var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len]; + var ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len]; for (ptr, 0..) |x, i| try expect(x == i + 1); for (ptr, 0..) |*x, i| try expect(x.* == i + 1); } @@ -393,7 +393,7 @@ test "raw pointer and counter" { const ptr: [*]u8 = &buf; for (ptr, 0..4) |*a, b| { - a.* = @intCast(u8, 'A' + b); + a.* = @as(u8, @intCast('A' + b)); } try expect(buf[0] == 'A'); diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index f0c8516f67..7d4a841a62 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -97,7 +97,7 @@ test "type constructed by comptime function call" { l.array[0] = 10; l.array[1] = 11; l.array[2] = 12; - const ptr = @ptrCast([*]u8, &l.array); + const ptr = @as([*]u8, @ptrCast(&l.array)); try expect(ptr[0] == 10); try expect(ptr[1] == 11); try expect(ptr[2] == 12); @@ -171,7 +171,7 @@ fn getByte(ptr: ?*const u8) u8 { return ptr.?.*; } fn getFirstByte(comptime T: type, mem: []const T) u8 { - return getByte(@ptrCast(*const u8, &mem[0])); + return getByte(@as(*const u8, @ptrCast(&mem[0]))); } test "generic fn keeps non-generic parameter types" { @@ -428,7 +428,7 @@ test "null sentinel pointer passed as generic argument" { try std.testing.expect(@intFromPtr(a) == 8); } }; - try S.doTheTest((@ptrFromInt([*:null]const [*c]const u8, 8))); + try S.doTheTest((@as([*:null]const [*c]const u8, @ptrFromInt(8)))); } test "generic function passed as comptime argument" { diff --git a/test/behavior/int128.zig b/test/behavior/int128.zig index 6fd2c192a2..42f0b00922 100644 --- a/test/behavior/int128.zig +++ b/test/behavior/int128.zig @@ -38,7 +38,7 @@ test "undefined 128 bit int" { var undef: u128 = undefined; var undef_signed: i128 = undefined; - try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @bitCast(u128, undef_signed) == undef); + try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @as(u128, @bitCast(undef_signed)) == undef); } test "int128" { @@ -49,7 +49,7 @@ test "int128" { var buff: i128 = -1; try expect(buff < 0 and (buff + 1) == 0); - try expect(@intCast(i8, buff) == @as(i8, -1)); + try expect(@as(i8, @intCast(buff)) == @as(i8, -1)); buff = minInt(i128); try expect(buff < 0); @@ -73,16 +73,16 @@ test "truncate int128" { { var buff: u128 = maxInt(u128); - try expect(@truncate(u64, buff) == maxInt(u64)); - try expect(@truncate(u90, buff) == maxInt(u90)); - try expect(@truncate(u128, buff) == maxInt(u128)); + try expect(@as(u64, @truncate(buff)) == maxInt(u64)); + try expect(@as(u90, @truncate(buff)) == maxInt(u90)); + try expect(@as(u128, @truncate(buff)) == maxInt(u128)); } { var buff: i128 = maxInt(i128); - try expect(@truncate(i64, buff) == -1); - try expect(@truncate(i90, buff) == -1); - try expect(@truncate(i128, buff) == maxInt(i128)); + try expect(@as(i64, @truncate(buff)) == -1); + try expect(@as(i90, @truncate(buff)) == -1); + try expect(@as(i128, @truncate(buff)) == maxInt(i128)); } } diff --git a/test/behavior/math.zig b/test/behavior/math.zig index 42c328c7d4..3b5d4876fd 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -391,11 +391,11 @@ test "binary not 128-bit" { break :x ~@as(u128, 0x55555555_55555555_55555555_55555555) == 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa; }); try expect(comptime x: { - break :x ~@as(i128, 0x55555555_55555555_55555555_55555555) == @bitCast(i128, @as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa)); + break :x ~@as(i128, 0x55555555_55555555_55555555_55555555) == @as(i128, @bitCast(@as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa))); }); try testBinaryNot128(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa); - try testBinaryNot128(i128, @bitCast(i128, @as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa))); + try testBinaryNot128(i128, @as(i128, @bitCast(@as(u128, 0xaaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa)))); } fn testBinaryNot128(comptime Type: type, x: Type) !void { @@ -1156,29 +1156,29 @@ test "quad hex float literal parsing accurate" { // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing. const expected: u128 = 0x3fff1111222233334444555566667777; - try expect(@bitCast(u128, a) == expected); + try expect(@as(u128, @bitCast(a)) == expected); // non-normalized const b: f128 = 0x11.111222233334444555566667777p-4; - try expect(@bitCast(u128, b) == expected); + try expect(@as(u128, @bitCast(b)) == expected); const S = struct { fn doTheTest() !void { { var f: f128 = 0x1.2eab345678439abcdefea56782346p+5; - try expect(@bitCast(u128, f) == 0x40042eab345678439abcdefea5678234); + try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234); } { var f: f128 = 0x1.edcb34a235253948765432134674fp-1; - try expect(@bitCast(u128, f) == 0x3ffeedcb34a235253948765432134675); // round-to-even + try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even } { var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50; - try expect(@bitCast(u128, f) == 0x3fcd353e45674d89abacc3a2ebf3ff50); + try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50); } { var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9; - try expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568); + try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568); } const exp2ft = [_]f64{ 0x1.6a09e667f3bcdp-1, @@ -1233,7 +1233,7 @@ test "quad hex float literal parsing accurate" { }; for (exp2ft, 0..) |x, i| { - try expect(@bitCast(u64, x) == answers[i]); + try expect(@as(u64, @bitCast(x)) == answers[i]); } } }; @@ -1586,7 +1586,7 @@ test "signed zeros are represented properly" { fn testOne(comptime T: type) !void { const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); var as_fp_val = -@as(T, 0.0); - var as_uint_val = @bitCast(ST, as_fp_val); + var as_uint_val = @as(ST, @bitCast(as_fp_val)); // Ensure the sign bit is set. try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1); } diff --git a/test/behavior/memcpy.zig b/test/behavior/memcpy.zig index 3a87b66fb1..f1776dfe57 100644 --- a/test/behavior/memcpy.zig +++ b/test/behavior/memcpy.zig @@ -59,7 +59,7 @@ fn testMemcpyDestManyPtr() !void { var str = "hello".*; var buf: [5]u8 = undefined; var len: usize = 5; - @memcpy(@ptrCast([*]u8, &buf), @ptrCast([*]const u8, &str)[0..len]); + @memcpy(@as([*]u8, @ptrCast(&buf)), @as([*]const u8, @ptrCast(&str))[0..len]); try expect(buf[0] == 'h'); try expect(buf[1] == 'e'); try expect(buf[2] == 'l'); diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig index 037fee74ee..12cc027ef4 100644 --- a/test/behavior/packed-struct.zig +++ b/test/behavior/packed-struct.zig @@ -166,7 +166,7 @@ test "correct sizeOf and offsets in packed structs" { try expectEqual(4, @sizeOf(PStruct)); if (native_endian == .Little) { - const s1 = @bitCast(PStruct, @as(u32, 0x12345678)); + const s1 = @as(PStruct, @bitCast(@as(u32, 0x12345678))); try expectEqual(false, s1.bool_a); try expectEqual(false, s1.bool_b); try expectEqual(false, s1.bool_c); @@ -180,7 +180,7 @@ test "correct sizeOf and offsets in packed structs" { try expectEqual(@as(u10, 0b1101000101), s1.u10_a); try expectEqual(@as(u10, 0b0001001000), s1.u10_b); - const s2 = @bitCast(packed struct { x: u1, y: u7, z: u24 }, @as(u32, 0xd5c71ff4)); + const s2 = @as(packed struct { x: u1, y: u7, z: u24 }, @bitCast(@as(u32, 0xd5c71ff4))); try expectEqual(@as(u1, 0), s2.x); try expectEqual(@as(u7, 0b1111010), s2.y); try expectEqual(@as(u24, 0xd5c71f), s2.z); @@ -207,7 +207,7 @@ test "nested packed structs" { try expectEqual(24, @bitOffsetOf(S3, "y")); if (native_endian == .Little) { - const s3 = @bitCast(S3Padded, @as(u64, 0xe952d5c71ff4)).s3; + const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3; try expectEqual(@as(u8, 0xf4), s3.x.a); try expectEqual(@as(u8, 0x1f), s3.x.b); try expectEqual(@as(u8, 0xc7), s3.x.c); @@ -600,7 +600,7 @@ test "packed struct initialized in bitcast" { const T = packed struct { val: u8 }; var val: u8 = 123; - const t = @bitCast(u8, T{ .val = val }); + const t = @as(u8, @bitCast(T{ .val = val })); try expect(t == val); } @@ -627,7 +627,7 @@ test "pointer to container level packed struct field" { }, var arr = [_]u32{0} ** 2; }; - @ptrCast(*S, &S.arr[0]).other_bits.enable_3 = true; + @as(*S, @ptrCast(&S.arr[0])).other_bits.enable_3 = true; try expect(S.arr[0] == 0x10000000); } diff --git a/test/behavior/packed_struct_explicit_backing_int.zig b/test/behavior/packed_struct_explicit_backing_int.zig index 62dd178fd5..9e476572ab 100644 --- a/test/behavior/packed_struct_explicit_backing_int.zig +++ b/test/behavior/packed_struct_explicit_backing_int.zig @@ -25,7 +25,7 @@ test "packed struct explicit backing integer" { try expectEqual(24, @bitOffsetOf(S3, "y")); if (native_endian == .Little) { - const s3 = @bitCast(S3Padded, @as(u64, 0xe952d5c71ff4)).s3; + const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3; try expectEqual(@as(u8, 0xf4), s3.x.a); try expectEqual(@as(u8, 0x1f), s3.x.b); try expectEqual(@as(u8, 0xc7), s3.x.c); diff --git a/test/behavior/pointers.zig b/test/behavior/pointers.zig index 4e04fe580c..d007e7b480 100644 --- a/test/behavior/pointers.zig +++ b/test/behavior/pointers.zig @@ -184,8 +184,8 @@ test "implicit cast error unions with non-optional to optional pointer" { } test "compare equality of optional and non-optional pointer" { - const a = @ptrFromInt(*const usize, 0x12345678); - const b = @ptrFromInt(?*usize, 0x12345678); + const a = @as(*const usize, @ptrFromInt(0x12345678)); + const b = @as(?*usize, @ptrFromInt(0x12345678)); try expect(a == b); try expect(b == a); } @@ -197,7 +197,7 @@ test "allowzero pointer and slice" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - var ptr = @ptrFromInt([*]allowzero i32, 0); + var ptr = @as([*]allowzero i32, @ptrFromInt(0)); var opt_ptr: ?[*]allowzero i32 = ptr; try expect(opt_ptr != null); try expect(@intFromPtr(ptr) == 0); @@ -286,9 +286,9 @@ test "null terminated pointer" { const S = struct { fn doTheTest() !void { var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' }; - var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero); + var zero_ptr: [*:0]const u8 = @as([*:0]const u8, @ptrCast(&array_with_zero)); var no_zero_ptr: [*]const u8 = zero_ptr; - var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr); + var zero_ptr_again = @as([*:0]const u8, @ptrCast(no_zero_ptr)); try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello")); } }; @@ -367,7 +367,7 @@ test "pointer sentinel with +inf" { } test "pointer to array at fixed address" { - const array = @ptrFromInt(*volatile [2]u32, 0x10); + const array = @as(*volatile [2]u32, @ptrFromInt(0x10)); // Silly check just to reference `array` try expect(@intFromPtr(&array[0]) == 0x10); try expect(@intFromPtr(&array[1]) == 0x14); @@ -406,13 +406,13 @@ test "pointer arithmetic affects the alignment" { test "@intFromPtr on null optional at comptime" { { - const pointer = @ptrFromInt(?*u8, 0x000); + const pointer = @as(?*u8, @ptrFromInt(0x000)); const x = @intFromPtr(pointer); _ = x; try comptime expect(0 == @intFromPtr(pointer)); } { - const pointer = @ptrFromInt(?*u8, 0xf00); + const pointer = @as(?*u8, @ptrFromInt(0xf00)); try comptime expect(0xf00 == @intFromPtr(pointer)); } } @@ -463,8 +463,8 @@ test "element pointer arithmetic to slice" { }; const elem_ptr = &cases[0]; // *[2]i32 - const many = @ptrCast([*][2]i32, elem_ptr); - const many_elem = @ptrCast(*[2]i32, &many[1]); + const many = @as([*][2]i32, @ptrCast(elem_ptr)); + const many_elem = @as(*[2]i32, @ptrCast(&many[1])); const items: []i32 = many_elem; try testing.expect(items.len == 2); try testing.expect(items[1] == 3); @@ -512,7 +512,7 @@ test "ptrCast comptime known slice to C pointer" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; const s: [:0]const u8 = "foo"; - var p = @ptrCast([*c]const u8, s); + var p = @as([*c]const u8, @ptrCast(s)); try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0)); } @@ -550,7 +550,7 @@ test "pointer to array has explicit alignment" { const Base = extern struct { a: u8 }; const Base2 = extern struct { a: u8 }; fn func(ptr: *[4]Base) *align(1) [4]Base2 { - return @alignCast(1, @ptrCast(*[4]Base2, ptr)); + return @alignCast(@as(*[4]Base2, @ptrCast(ptr))); } }; var bases = [_]S.Base{.{ .a = 2 }} ** 4; diff --git a/test/behavior/popcount.zig b/test/behavior/popcount.zig index 51146b14c8..da152d4dc5 100644 --- a/test/behavior/popcount.zig +++ b/test/behavior/popcount.zig @@ -63,7 +63,7 @@ fn testPopCountIntegers() !void { try expect(@popCount(x) == 2); } comptime { - try expect(@popCount(@bitCast(u8, @as(i8, -120))) == 2); + try expect(@popCount(@as(u8, @bitCast(@as(i8, -120)))) == 2); } } diff --git a/test/behavior/ptrcast.zig b/test/behavior/ptrcast.zig index aadae132d9..3a2ec9db19 100644 --- a/test/behavior/ptrcast.zig +++ b/test/behavior/ptrcast.zig @@ -16,7 +16,7 @@ fn testReinterpretBytesAsInteger() !void { .Little => 0xab785634, .Big => 0x345678ab, }; - try expect(@ptrCast(*align(1) const u32, bytes[1..5]).* == expected); + try expect(@as(*align(1) const u32, @ptrCast(bytes[1..5])).* == expected); } test "reinterpret an array over multiple elements, with no well-defined layout" { @@ -32,7 +32,7 @@ test "reinterpret an array over multiple elements, with no well-defined layout" fn testReinterpretWithOffsetAndNoWellDefinedLayout() !void { const bytes: ?[5]?u8 = [5]?u8{ 0x12, 0x34, 0x56, 0x78, 0x9a }; const ptr = &bytes.?[1]; - const copy: [4]?u8 = @ptrCast(*const [4]?u8, ptr).*; + const copy: [4]?u8 = @as(*const [4]?u8, @ptrCast(ptr)).*; _ = copy; //try expect(@ptrCast(*align(1)?u8, bytes[1..5]).* == ); } @@ -51,7 +51,7 @@ fn testReinterpretStructWrappedBytesAsInteger() !void { .Little => 0xab785634, .Big => 0x345678ab, }; - try expect(@ptrCast(*align(1) const u32, obj.bytes[1..5]).* == expected); + try expect(@as(*align(1) const u32, @ptrCast(obj.bytes[1..5])).* == expected); } test "reinterpret bytes of an array into an extern struct" { @@ -71,7 +71,7 @@ fn testReinterpretBytesAsExternStruct() !void { c: u8, }; - var ptr = @ptrCast(*const S, &bytes); + var ptr = @as(*const S, @ptrCast(&bytes)); var val = ptr.c; try expect(val == 5); } @@ -95,7 +95,7 @@ fn testReinterpretExternStructAsExternStruct() !void { a: u32 align(2), c: u8, }; - var ptr = @ptrCast(*const S2, &bytes); + var ptr = @as(*const S2, @ptrCast(&bytes)); var val = ptr.c; try expect(val == 5); } @@ -121,7 +121,7 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void { a2: u16, c: u8, }; - var ptr = @ptrCast(*const S2, &bytes); + var ptr = @as(*const S2, @ptrCast(&bytes)); var val = ptr.c; try expect(val == 5); } @@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" { a: u32 align(2), c: u8, }; - comptime var ptr = @ptrCast(*const S, &bytes); + comptime var ptr = @as(*const S, @ptrCast(&bytes)); var val = &ptr.c; try expect(val.* == 5); // Test lowering an elem ptr comptime var src_value = S{ .a = 15, .c = 5 }; - comptime var ptr2 = @ptrCast(*[@sizeOf(S)]u8, &src_value); + comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); var val2 = &ptr2[4]; try expect(val2.* == 5); } @@ -161,13 +161,13 @@ test "lower reinterpreted comptime field ptr" { a: u32, c: u8, }; - comptime var ptr = @ptrCast(*const S, &bytes); + comptime var ptr = @as(*const S, @ptrCast(&bytes)); var val = &ptr.c; try expect(val.* == 5); // Test lowering an elem ptr comptime var src_value = S{ .a = 15, .c = 5 }; - comptime var ptr2 = @ptrCast(*[@sizeOf(S)]u8, &src_value); + comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); var val2 = &ptr2[4]; try expect(val2.* == 5); } @@ -190,27 +190,17 @@ const Bytes = struct { pub fn init(v: u32) Bytes { var res: Bytes = undefined; - @ptrCast(*align(1) u32, &res.bytes).* = v; + @as(*align(1) u32, @ptrCast(&res.bytes)).* = v; return res; } }; -test "comptime ptrcast keeps larger alignment" { - if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - - comptime { - const a: u32 = 1234; - const p = @ptrCast([*]const u8, &a); - try expect(@TypeOf(p) == [*]align(@alignOf(u32)) const u8); - } -} - test "ptrcast of const integer has the correct object size" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - const is_value = ~@intCast(isize, std.math.minInt(isize)); - const is_bytes = @ptrCast([*]const u8, &is_value)[0..@sizeOf(isize)]; + const is_value = ~@as(isize, @intCast(std.math.minInt(isize))); + const is_bytes = @as([*]const u8, @ptrCast(&is_value))[0..@sizeOf(isize)]; if (@sizeOf(isize) == 8) { switch (native_endian) { .Little => { @@ -248,7 +238,7 @@ test "implicit optional pointer to optional anyopaque pointer" { var buf: [4]u8 = "aoeu".*; var x: ?[*]u8 = &buf; var y: ?*anyopaque = x; - var z = @ptrCast(*[4]u8, y); + var z = @as(*[4]u8, @ptrCast(y)); try expect(std.mem.eql(u8, z, "aoeu")); } @@ -260,7 +250,7 @@ test "@ptrCast slice to slice" { const S = struct { fn foo(slice: []u32) []i32 { - return @ptrCast([]i32, slice); + return @as([]i32, @ptrCast(slice)); } }; var buf: [4]u32 = .{ 0, 0, 0, 0 }; @@ -277,7 +267,7 @@ test "comptime @ptrCast a subset of an array, then write through it" { comptime { var buff: [16]u8 align(4) = undefined; - const len_bytes = @ptrCast(*u32, &buff); + const len_bytes = @as(*u32, @ptrCast(&buff)); len_bytes.* = 16; std.mem.copy(u8, buff[4..], "abcdef"); } @@ -286,7 +276,7 @@ test "comptime @ptrCast a subset of an array, then write through it" { test "@ptrCast undefined value at comptime" { const S = struct { fn transmute(comptime T: type, comptime U: type, value: T) U { - return @ptrCast(*const U, &value).*; + return @as(*const U, @ptrCast(&value)).*; } }; comptime { diff --git a/test/behavior/ptrfromint.zig b/test/behavior/ptrfromint.zig index c07a6df834..72244aa7d1 100644 --- a/test/behavior/ptrfromint.zig +++ b/test/behavior/ptrfromint.zig @@ -9,7 +9,7 @@ test "casting integer address to function pointer" { fn addressToFunction() void { var addr: usize = 0xdeadbee0; - _ = @ptrFromInt(*const fn () void, addr); + _ = @as(*const fn () void, @ptrFromInt(addr)); } test "mutate through ptr initialized with constant ptrFromInt value" { @@ -21,7 +21,7 @@ test "mutate through ptr initialized with constant ptrFromInt value" { } fn forceCompilerAnalyzeBranchHardCodedPtrDereference(x: bool) void { - const hardCodedP = @ptrFromInt(*volatile u8, 0xdeadbeef); + const hardCodedP = @as(*volatile u8, @ptrFromInt(0xdeadbeef)); if (x) { hardCodedP.* = hardCodedP.* | 10; } else { @@ -34,7 +34,7 @@ test "@ptrFromInt creates null pointer" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - const ptr = @ptrFromInt(?*u32, 0); + const ptr = @as(?*u32, @ptrFromInt(0)); try expectEqual(@as(?*u32, null), ptr); } @@ -43,6 +43,6 @@ test "@ptrFromInt creates allowzero zero pointer" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - const ptr = @ptrFromInt(*allowzero u32, 0); + const ptr = @as(*allowzero u32, @ptrFromInt(0)); try expectEqual(@as(usize, 0), @intFromPtr(ptr)); } diff --git a/test/behavior/sizeof_and_typeof.zig b/test/behavior/sizeof_and_typeof.zig index 3657e77e50..a161be66eb 100644 --- a/test/behavior/sizeof_and_typeof.zig +++ b/test/behavior/sizeof_and_typeof.zig @@ -231,7 +231,7 @@ test "@sizeOf comparison against zero" { test "hardcoded address in typeof expression" { const S = struct { - fn func() @TypeOf(@ptrFromInt(*[]u8, 0x10).*[0]) { + fn func() @TypeOf(@as(*[]u8, @ptrFromInt(0x10)).*[0]) { return 0; } }; @@ -252,7 +252,7 @@ test "array access of generic param in typeof expression" { test "lazy size cast to float" { { const S = struct { a: u8 }; - try expect(@floatFromInt(f32, @sizeOf(S)) == 1.0); + try expect(@as(f32, @floatFromInt(@sizeOf(S))) == 1.0); } { const S = struct { a: u8 }; diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig index fcbae214ac..4316aca34f 100644 --- a/test/behavior/slice.zig +++ b/test/behavior/slice.zig @@ -129,7 +129,7 @@ test "generic malloc free" { } var some_mem: [100]u8 = undefined; fn memAlloc(comptime T: type, n: usize) anyerror![]T { - return @ptrCast([*]T, &some_mem[0])[0..n]; + return @as([*]T, @ptrCast(&some_mem[0]))[0..n]; } fn memFree(comptime T: type, memory: []T) void { _ = memory; @@ -138,7 +138,7 @@ fn memFree(comptime T: type, memory: []T) void { test "slice of hardcoded address to pointer" { const S = struct { fn doTheTest() !void { - const pointer = @ptrFromInt([*]u8, 0x04)[0..2]; + const pointer = @as([*]u8, @ptrFromInt(0x04))[0..2]; try comptime expect(@TypeOf(pointer) == *[2]u8); const slice: []const u8 = pointer; try expect(@intFromPtr(slice.ptr) == 4); @@ -152,7 +152,7 @@ test "slice of hardcoded address to pointer" { test "comptime slice of pointer preserves comptime var" { comptime { var buff: [10]u8 = undefined; - var a = @ptrCast([*]u8, &buff); + var a = @as([*]u8, @ptrCast(&buff)); a[0..1][0] = 1; try expect(buff[0..][0..][0] == 1); } @@ -161,7 +161,7 @@ test "comptime slice of pointer preserves comptime var" { test "comptime pointer cast array and then slice" { const array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 }; - const ptrA: [*]const u8 = @ptrCast([*]const u8, &array); + const ptrA: [*]const u8 = @as([*]const u8, @ptrCast(&array)); const sliceA: []const u8 = ptrA[0..2]; const ptrB: [*]const u8 = &array; @@ -188,7 +188,7 @@ test "slicing pointer by length" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; const array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 }; - const ptr: [*]const u8 = @ptrCast([*]const u8, &array); + const ptr: [*]const u8 = @as([*]const u8, @ptrCast(&array)); const slice = ptr[1..][0..5]; try expect(slice.len == 5); var i: usize = 0; @@ -197,7 +197,7 @@ test "slicing pointer by length" { } } -const x = @ptrFromInt([*]i32, 0x1000)[0..0x500]; +const x = @as([*]i32, @ptrFromInt(0x1000))[0..0x500]; const y = x[0x100..]; test "compile time slice of pointer to hard coded address" { try expect(@intFromPtr(x) == 0x1000); @@ -262,7 +262,7 @@ test "C pointer slice access" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var buf: [10]u32 = [1]u32{42} ** 10; - const c_ptr = @ptrCast([*c]const u32, &buf); + const c_ptr = @as([*c]const u32, @ptrCast(&buf)); var runtime_zero: usize = 0; try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1])); @@ -352,7 +352,7 @@ test "@ptrCast slice to pointer" { fn doTheTest() !void { var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff }; var slice: []align(@alignOf(u16)) u8 = &array; - var ptr = @ptrCast(*u16, slice); + var ptr = @as(*u16, @ptrCast(slice)); try expect(ptr.* == 65535); } }; @@ -837,13 +837,13 @@ test "empty slice ptr is non null" { { const empty_slice: []u8 = &[_]u8{}; const p: [*]u8 = empty_slice.ptr + 0; - const t = @ptrCast([*]i8, p); + const t = @as([*]i8, @ptrCast(p)); try expect(@intFromPtr(t) == @intFromPtr(empty_slice.ptr)); } { const empty_slice: []u8 = &.{}; const p: [*]u8 = empty_slice.ptr + 0; - const t = @ptrCast([*]i8, p); + const t = @as([*]i8, @ptrCast(p)); try expect(@intFromPtr(t) == @intFromPtr(empty_slice.ptr)); } } diff --git a/test/behavior/slice_sentinel_comptime.zig b/test/behavior/slice_sentinel_comptime.zig index 368860547e..31b7e2349e 100644 --- a/test/behavior/slice_sentinel_comptime.zig +++ b/test/behavior/slice_sentinel_comptime.zig @@ -25,7 +25,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { // vector_ConstPtrSpecialRef comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); const slice = target[0..3 :'d']; _ = slice; } @@ -41,7 +41,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { // cvector_ConstPtrSpecialRef comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); const slice = target[0..3 :'d']; _ = slice; } @@ -82,7 +82,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { // vector_ConstPtrSpecialRef comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); const slice = target[0..13 :0xff]; _ = slice; } @@ -98,7 +98,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { // cvector_ConstPtrSpecialRef comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); const slice = target[0..13 :0xff]; _ = slice; } @@ -139,7 +139,7 @@ test "comptime slice-sentinel in bounds (terminated)" { // vector_ConstPtrSpecialRef comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); const slice = target[0..3 :'d']; _ = slice; } @@ -155,7 +155,7 @@ test "comptime slice-sentinel in bounds (terminated)" { // cvector_ConstPtrSpecialRef comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); const slice = target[0..3 :'d']; _ = slice; } @@ -196,7 +196,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { // vector_ConstPtrSpecialRef comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); const slice = target[0..14 :0]; _ = slice; } @@ -212,7 +212,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { // cvector_ConstPtrSpecialRef comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); const slice = target[0..14 :0]; _ = slice; } diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 6ced42998e..95b2718efd 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -92,7 +92,7 @@ test "structs" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var foo: StructFoo = undefined; - @memset(@ptrCast([*]u8, &foo)[0..@sizeOf(StructFoo)], 0); + @memset(@as([*]u8, @ptrCast(&foo))[0..@sizeOf(StructFoo)], 0); foo.a += 1; foo.b = foo.a == 1; try testFoo(foo); @@ -479,14 +479,14 @@ test "runtime struct initialization of bitfield" { .y = x1, }; const s2 = Nibbles{ - .x = @intCast(u4, x2), - .y = @intCast(u4, x2), + .x = @as(u4, @intCast(x2)), + .y = @as(u4, @intCast(x2)), }; try expect(s1.x == x1); try expect(s1.y == x1); - try expect(s2.x == @intCast(u4, x2)); - try expect(s2.y == @intCast(u4, x2)); + try expect(s2.x == @as(u4, @intCast(x2))); + try expect(s2.y == @as(u4, @intCast(x2))); } var x1 = @as(u4, 1); @@ -515,8 +515,8 @@ test "packed struct fields are ordered from LSB to MSB" { var all: u64 = 0x7765443322221111; var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined; - @memcpy(bytes[0..8], @ptrCast([*]u8, &all)); - var bitfields = @ptrCast(*Bitfields, &bytes).*; + @memcpy(bytes[0..8], @as([*]u8, @ptrCast(&all))); + var bitfields = @as(*Bitfields, @ptrCast(&bytes)).*; try expect(bitfields.f1 == 0x1111); try expect(bitfields.f2 == 0x2222); @@ -1281,7 +1281,7 @@ test "packed struct aggregate init" { const S = struct { fn foo(a: i2, b: i6) u8 { - return @bitCast(u8, P{ .a = a, .b = b }); + return @as(u8, @bitCast(P{ .a = a, .b = b })); } const P = packed struct { @@ -1289,7 +1289,7 @@ test "packed struct aggregate init" { b: i6, }; }; - const result = @bitCast(u8, S.foo(1, 2)); + const result = @as(u8, @bitCast(S.foo(1, 2))); try expect(result == 9); } @@ -1365,7 +1365,7 @@ test "under-aligned struct field" { }; var runtime: usize = 1234; const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } }; - const array = @ptrCast(*const [12]u8, ptr); + const array = @as(*const [12]u8, @ptrCast(ptr)); const result = std.mem.readIntNative(u64, array[4..12]); try expect(result == 1234); } diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig index bcbfc81ed4..0ae7c510ef 100644 --- a/test/behavior/switch.zig +++ b/test/behavior/switch.zig @@ -590,9 +590,9 @@ test "switch on pointer type" { field: u32, }; - const P1 = @ptrFromInt(*X, 0x400); - const P2 = @ptrFromInt(*X, 0x800); - const P3 = @ptrFromInt(*X, 0xC00); + const P1 = @as(*X, @ptrFromInt(0x400)); + const P2 = @as(*X, @ptrFromInt(0x800)); + const P3 = @as(*X, @ptrFromInt(0xC00)); fn doTheTest(arg: *X) i32 { switch (arg) { @@ -682,9 +682,9 @@ test "enum value without tag name used as switch item" { b = 2, _, }; - var e: E = @enumFromInt(E, 0); + var e: E = @as(E, @enumFromInt(0)); switch (e) { - @enumFromInt(E, 0) => {}, + @as(E, @enumFromInt(0)) => {}, .a => return error.TestFailed, .b => return error.TestFailed, _ => return error.TestFailed, diff --git a/test/behavior/translate_c_macros.zig b/test/behavior/translate_c_macros.zig index a69396c203..68e91bfa58 100644 --- a/test/behavior/translate_c_macros.zig +++ b/test/behavior/translate_c_macros.zig @@ -60,7 +60,7 @@ test "cast negative integer to pointer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - try expectEqual(@ptrFromInt(?*anyopaque, @bitCast(usize, @as(isize, -1))), h.MAP_FAILED); + try expectEqual(@as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))), h.MAP_FAILED); } test "casting to union with a macro" { @@ -89,7 +89,7 @@ test "casting or calling a value with a paren-surrounded macro" { const l: c_long = 42; const casted = h.CAST_OR_CALL_WITH_PARENS(c_int, l); - try expect(casted == @intCast(c_int, l)); + try expect(casted == @as(c_int, @intCast(l))); const Helper = struct { fn foo(n: c_int) !void { diff --git a/test/behavior/truncate.zig b/test/behavior/truncate.zig index 3ea979009e..4fc095b66c 100644 --- a/test/behavior/truncate.zig +++ b/test/behavior/truncate.zig @@ -4,58 +4,58 @@ const expect = std.testing.expect; test "truncate u0 to larger integer allowed and has comptime-known result" { var x: u0 = 0; - const y = @truncate(u8, x); + const y = @as(u8, @truncate(x)); try comptime expect(y == 0); } test "truncate.u0.literal" { - var z = @truncate(u0, 0); + var z = @as(u0, @truncate(0)); try expect(z == 0); } test "truncate.u0.const" { const c0: usize = 0; - var z = @truncate(u0, c0); + var z = @as(u0, @truncate(c0)); try expect(z == 0); } test "truncate.u0.var" { var d: u8 = 2; - var z = @truncate(u0, d); + var z = @as(u0, @truncate(d)); try expect(z == 0); } test "truncate i0 to larger integer allowed and has comptime-known result" { var x: i0 = 0; - const y = @truncate(i8, x); + const y = @as(i8, @truncate(x)); try comptime expect(y == 0); } test "truncate.i0.literal" { - var z = @truncate(i0, 0); + var z = @as(i0, @truncate(0)); try expect(z == 0); } test "truncate.i0.const" { const c0: isize = 0; - var z = @truncate(i0, c0); + var z = @as(i0, @truncate(c0)); try expect(z == 0); } test "truncate.i0.var" { var d: i8 = 2; - var z = @truncate(i0, d); + var z = @as(i0, @truncate(d)); try expect(z == 0); } test "truncate on comptime integer" { - var x = @truncate(u16, 9999); + var x = @as(u16, @truncate(9999)); try expect(x == 9999); - var y = @truncate(u16, -21555); + var y = @as(u16, @truncate(-21555)); try expect(y == 0xabcd); - var z = @truncate(i16, -65537); + var z = @as(i16, @truncate(-65537)); try expect(z == -1); - var w = @truncate(u1, 1 << 100); + var w = @as(u1, @truncate(1 << 100)); try expect(w == 0); } @@ -69,7 +69,7 @@ test "truncate on vectors" { const S = struct { fn doTheTest() !void { var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 }; - var v2 = @truncate(u8, v1); + var v2: @Vector(4, u8) = @truncate(v1); try expect(std.mem.eql(u8, &@as([4]u8, v2), &[4]u8{ 0xbb, 0xdd, 0xff, 0x22 })); } }; diff --git a/test/behavior/tuple.zig b/test/behavior/tuple.zig index ee414365c3..e9d3fcd0aa 100644 --- a/test/behavior/tuple.zig +++ b/test/behavior/tuple.zig @@ -403,7 +403,7 @@ test "nested runtime conditionals in tuple initializer" { var data: u8 = 0; const x = .{ - if (data != 0) "" else switch (@truncate(u1, data)) { + if (data != 0) "" else switch (@as(u1, @truncate(data))) { 0 => "up", 1 => "down", }, diff --git a/test/behavior/tuple_declarations.zig b/test/behavior/tuple_declarations.zig index c053447ccc..84b04d3e53 100644 --- a/test/behavior/tuple_declarations.zig +++ b/test/behavior/tuple_declarations.zig @@ -21,7 +21,7 @@ test "tuple declaration type info" { try expectEqualStrings(info.fields[0].name, "0"); try expect(info.fields[0].type == u32); - try expect(@ptrCast(*const u32, @alignCast(@alignOf(u32), info.fields[0].default_value)).* == 1); + try expect(@as(*const u32, @ptrCast(@alignCast(info.fields[0].default_value))).* == 1); try expect(info.fields[0].is_comptime); try expect(info.fields[0].alignment == 2); diff --git a/test/behavior/type.zig b/test/behavior/type.zig index 9420b5d2fd..a2ede838b2 100644 --- a/test/behavior/type.zig +++ b/test/behavior/type.zig @@ -289,7 +289,7 @@ test "Type.Struct" { try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value); try testing.expectEqualSlices(u8, "y", infoB.fields[1].name); try testing.expectEqual(u32, infoB.fields[1].type); - try testing.expectEqual(@as(u32, 5), @ptrCast(*align(1) const u32, infoB.fields[1].default_value.?).*); + try testing.expectEqual(@as(u32, 5), @as(*align(1) const u32, @ptrCast(infoB.fields[1].default_value.?)).*); try testing.expectEqual(@as(usize, 0), infoB.decls.len); try testing.expectEqual(@as(bool, false), infoB.is_tuple); @@ -298,10 +298,10 @@ test "Type.Struct" { try testing.expectEqual(Type.ContainerLayout.Packed, infoC.layout); try testing.expectEqualSlices(u8, "x", infoC.fields[0].name); try testing.expectEqual(u8, infoC.fields[0].type); - try testing.expectEqual(@as(u8, 3), @ptrCast(*const u8, infoC.fields[0].default_value.?).*); + try testing.expectEqual(@as(u8, 3), @as(*const u8, @ptrCast(infoC.fields[0].default_value.?)).*); try testing.expectEqualSlices(u8, "y", infoC.fields[1].name); try testing.expectEqual(u32, infoC.fields[1].type); - try testing.expectEqual(@as(u32, 5), @ptrCast(*align(1) const u32, infoC.fields[1].default_value.?).*); + try testing.expectEqual(@as(u32, 5), @as(*align(1) const u32, @ptrCast(infoC.fields[1].default_value.?)).*); try testing.expectEqual(@as(usize, 0), infoC.decls.len); try testing.expectEqual(@as(bool, false), infoC.is_tuple); @@ -311,10 +311,10 @@ test "Type.Struct" { try testing.expectEqual(Type.ContainerLayout.Auto, infoD.layout); try testing.expectEqualSlices(u8, "x", infoD.fields[0].name); try testing.expectEqual(comptime_int, infoD.fields[0].type); - try testing.expectEqual(@as(comptime_int, 3), @ptrCast(*const comptime_int, infoD.fields[0].default_value.?).*); + try testing.expectEqual(@as(comptime_int, 3), @as(*const comptime_int, @ptrCast(infoD.fields[0].default_value.?)).*); try testing.expectEqualSlices(u8, "y", infoD.fields[1].name); try testing.expectEqual(comptime_int, infoD.fields[1].type); - try testing.expectEqual(@as(comptime_int, 5), @ptrCast(*const comptime_int, infoD.fields[1].default_value.?).*); + try testing.expectEqual(@as(comptime_int, 5), @as(*const comptime_int, @ptrCast(infoD.fields[1].default_value.?)).*); try testing.expectEqual(@as(usize, 0), infoD.decls.len); try testing.expectEqual(@as(bool, false), infoD.is_tuple); @@ -324,10 +324,10 @@ test "Type.Struct" { try testing.expectEqual(Type.ContainerLayout.Auto, infoE.layout); try testing.expectEqualSlices(u8, "0", infoE.fields[0].name); try testing.expectEqual(comptime_int, infoE.fields[0].type); - try testing.expectEqual(@as(comptime_int, 1), @ptrCast(*const comptime_int, infoE.fields[0].default_value.?).*); + try testing.expectEqual(@as(comptime_int, 1), @as(*const comptime_int, @ptrCast(infoE.fields[0].default_value.?)).*); try testing.expectEqualSlices(u8, "1", infoE.fields[1].name); try testing.expectEqual(comptime_int, infoE.fields[1].type); - try testing.expectEqual(@as(comptime_int, 2), @ptrCast(*const comptime_int, infoE.fields[1].default_value.?).*); + try testing.expectEqual(@as(comptime_int, 2), @as(*const comptime_int, @ptrCast(infoE.fields[1].default_value.?)).*); try testing.expectEqual(@as(usize, 0), infoE.decls.len); try testing.expectEqual(@as(bool, true), infoE.is_tuple); @@ -379,7 +379,7 @@ test "Type.Enum" { try testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive); try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a)); try testing.expectEqual(@as(u32, 5), @intFromEnum(Bar.b)); - try testing.expectEqual(@as(u32, 6), @intFromEnum(@enumFromInt(Bar, 6))); + try testing.expectEqual(@as(u32, 6), @intFromEnum(@as(Bar, @enumFromInt(6)))); } test "Type.Union" { diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig index 87ae96768a..0d026c0078 100644 --- a/test/behavior/type_info.zig +++ b/test/behavior/type_info.zig @@ -113,7 +113,7 @@ fn testNullTerminatedPtr() !void { try expect(ptr_info.Pointer.size == .Many); try expect(ptr_info.Pointer.is_const == false); try expect(ptr_info.Pointer.is_volatile == false); - try expect(@ptrCast(*const u8, ptr_info.Pointer.sentinel.?).* == 0); + try expect(@as(*const u8, @ptrCast(ptr_info.Pointer.sentinel.?)).* == 0); try expect(@typeInfo([:0]u8).Pointer.sentinel != null); } @@ -151,7 +151,7 @@ fn testArray() !void { const info = @typeInfo([10:0]u8); try expect(info.Array.len == 10); try expect(info.Array.child == u8); - try expect(@ptrCast(*const u8, info.Array.sentinel.?).* == @as(u8, 0)); + try expect(@as(*const u8, @ptrCast(info.Array.sentinel.?)).* == @as(u8, 0)); try expect(@sizeOf([10:0]u8) == info.Array.len + 1); } } @@ -295,8 +295,8 @@ fn testStruct() !void { try expect(unpacked_struct_info.Struct.is_tuple == false); try expect(unpacked_struct_info.Struct.backing_integer == null); try expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32)); - try expect(@ptrCast(*align(1) const u32, unpacked_struct_info.Struct.fields[0].default_value.?).* == 4); - try expect(mem.eql(u8, "foobar", @ptrCast(*align(1) const *const [6:0]u8, unpacked_struct_info.Struct.fields[1].default_value.?).*)); + try expect(@as(*align(1) const u32, @ptrCast(unpacked_struct_info.Struct.fields[0].default_value.?)).* == 4); + try expect(mem.eql(u8, "foobar", @as(*align(1) const *const [6:0]u8, @ptrCast(unpacked_struct_info.Struct.fields[1].default_value.?)).*)); } const TestStruct = struct { @@ -319,7 +319,7 @@ fn testPackedStruct() !void { try expect(struct_info.Struct.fields[0].alignment == 0); try expect(struct_info.Struct.fields[2].type == f32); try expect(struct_info.Struct.fields[2].default_value == null); - try expect(@ptrCast(*align(1) const u32, struct_info.Struct.fields[3].default_value.?).* == 4); + try expect(@as(*align(1) const u32, @ptrCast(struct_info.Struct.fields[3].default_value.?)).* == 4); try expect(struct_info.Struct.fields[3].alignment == 0); try expect(struct_info.Struct.decls.len == 2); try expect(struct_info.Struct.decls[0].is_pub); @@ -504,7 +504,7 @@ test "type info for async frames" { switch (@typeInfo(@Frame(add))) { .Frame => |frame| { - try expect(@ptrCast(@TypeOf(add), frame.function) == add); + try expect(@as(@TypeOf(add), @ptrCast(frame.function)) == add); }, else => unreachable, } @@ -564,7 +564,7 @@ test "typeInfo resolves usingnamespace declarations" { test "value from struct @typeInfo default_value can be loaded at comptime" { comptime { const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).Struct.fields[0].default_value; - try expect(@ptrCast(*const u8, a).* == 1); + try expect(@as(*const u8, @ptrCast(a)).* == 1); } } @@ -607,6 +607,6 @@ test "@typeInfo decls ignore dependency loops" { test "type info of tuple of string literal default value" { const struct_field = @typeInfo(@TypeOf(.{"hi"})).Struct.fields[0]; - const value = @ptrCast(*align(1) const *const [2:0]u8, struct_field.default_value.?).*; + const value = @as(*align(1) const *const [2:0]u8, @ptrCast(struct_field.default_value.?)).*; comptime std.debug.assert(value[0] == 'h'); } diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig index 47864a83c9..2aab98ea72 100644 --- a/test/behavior/vector.zig +++ b/test/behavior/vector.zig @@ -1244,7 +1244,7 @@ test "@intCast to u0" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var zeros = @Vector(2, u32){ 0, 0 }; - const casted = @intCast(@Vector(2, u0), zeros); + const casted = @as(@Vector(2, u0), @intCast(zeros)); _ = casted[0]; } diff --git a/test/c_abi/main.zig b/test/c_abi/main.zig index f06d455060..d421f0aace 100644 --- a/test/c_abi/main.zig +++ b/test/c_abi/main.zig @@ -143,7 +143,7 @@ export fn zig_longdouble(x: c_longdouble) void { extern fn c_ptr(*anyopaque) void; test "C ABI pointer" { - c_ptr(@ptrFromInt(*anyopaque, 0xdeadbeef)); + c_ptr(@as(*anyopaque, @ptrFromInt(0xdeadbeef))); } export fn zig_ptr(x: *anyopaque) void { @@ -1058,14 +1058,14 @@ test "C function that takes byval struct called via function pointer" { var fn_ptr = &c_func_ptr_byval; fn_ptr( - @ptrFromInt(*anyopaque, 1), - @ptrFromInt(*anyopaque, 2), + @as(*anyopaque, @ptrFromInt(1)), + @as(*anyopaque, @ptrFromInt(2)), ByVal{ .origin = .{ .x = 9, .y = 10, .z = 11 }, .size = .{ .width = 12, .height = 13, .depth = 14 }, }, @as(c_ulong, 3), - @ptrFromInt(*anyopaque, 4), + @as(*anyopaque, @ptrFromInt(4)), @as(c_ulong, 5), ); } @@ -1098,7 +1098,7 @@ test "f80 bare" { if (!has_f80) return error.SkipZigTest; const a = c_f80(12.34); - try expect(@floatCast(f64, a) == 56.78); + try expect(@as(f64, @floatCast(a)) == 56.78); } const f80_struct = extern struct { @@ -1111,7 +1111,7 @@ test "f80 struct" { if (builtin.mode != .Debug) return error.SkipZigTest; const a = c_f80_struct(.{ .a = 12.34 }); - try expect(@floatCast(f64, a.a) == 56.78); + try expect(@as(f64, @floatCast(a.a)) == 56.78); } const f80_extra_struct = extern struct { @@ -1124,7 +1124,7 @@ test "f80 extra struct" { if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; const a = c_f80_extra_struct(.{ .a = 12.34, .b = 42 }); - try expect(@floatCast(f64, a.a) == 56.78); + try expect(@as(f64, @floatCast(a.a)) == 56.78); try expect(a.b == 24); } @@ -1133,7 +1133,7 @@ test "f128 bare" { if (!has_f128) return error.SkipZigTest; const a = c_f128(12.34); - try expect(@floatCast(f64, a) == 56.78); + try expect(@as(f64, @floatCast(a)) == 56.78); } const f128_struct = extern struct { @@ -1144,7 +1144,7 @@ test "f128 struct" { if (!has_f128) return error.SkipZigTest; const a = c_f128_struct(.{ .a = 12.34 }); - try expect(@floatCast(f64, a.a) == 56.78); + try expect(@as(f64, @floatCast(a.a)) == 56.78); } // The stdcall attribute on C functions is ignored when compiled on non-x86 diff --git a/test/cases/compile_errors/alignCast_expects_pointer_or_slice.zig b/test/cases/compile_errors/alignCast_expects_pointer_or_slice.zig index 1b8e3767b2..25345aced0 100644 --- a/test/cases/compile_errors/alignCast_expects_pointer_or_slice.zig +++ b/test/cases/compile_errors/alignCast_expects_pointer_or_slice.zig @@ -1,9 +1,10 @@ export fn entry() void { - @alignCast(4, @as(u32, 3)); + const x: *align(8) u32 = @alignCast(@as(u32, 3)); + _ = x; } // error // backend=stage2 // target=native // -// :2:19: error: expected pointer type, found 'u32' +// :2:41: error: expected pointer type, found 'u32' diff --git a/test/cases/compile_errors/bad_alignCast_at_comptime.zig b/test/cases/compile_errors/bad_alignCast_at_comptime.zig index 885700ecac..c870521822 100644 --- a/test/cases/compile_errors/bad_alignCast_at_comptime.zig +++ b/test/cases/compile_errors/bad_alignCast_at_comptime.zig @@ -1,6 +1,6 @@ comptime { - const ptr = @ptrFromInt(*align(1) i32, 0x1); - const aligned = @alignCast(4, ptr); + const ptr: *align(1) i32 = @ptrFromInt(0x1); + const aligned: *align(4) i32 = @alignCast(ptr); _ = aligned; } @@ -8,4 +8,4 @@ comptime { // backend=stage2 // target=native // -// :3:35: error: pointer address 0x1 is not aligned to 4 bytes +// :3:47: error: pointer address 0x1 is not aligned to 4 bytes diff --git a/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig b/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig index 2f7bd9c9bc..e366e0cb03 100644 --- a/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig +++ b/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig @@ -1,5 +1,5 @@ export fn entry(byte: u8) void { - var oops = @bitCast(u7, byte); + var oops: u7 = @bitCast(byte); _ = oops; } @@ -7,4 +7,4 @@ export fn entry(byte: u8) void { // backend=stage2 // target=native // -// :2:16: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits +// :2:20: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits diff --git a/test/cases/compile_errors/bitCast_to_enum_type.zig b/test/cases/compile_errors/bitCast_to_enum_type.zig index b3bc72c21b..7f3711b7f1 100644 --- a/test/cases/compile_errors/bitCast_to_enum_type.zig +++ b/test/cases/compile_errors/bitCast_to_enum_type.zig @@ -1,6 +1,6 @@ export fn entry() void { const E = enum(u32) { a, b }; - const y = @bitCast(E, @as(u32, 3)); + const y: E = @bitCast(@as(u32, 3)); _ = y; } @@ -8,5 +8,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :3:24: error: cannot @bitCast to 'tmp.entry.E' -// :3:24: note: use @enumFromInt to cast from 'u32' +// :3:18: error: cannot @bitCast to 'tmp.entry.E' +// :3:18: note: use @enumFromInt to cast from 'u32' diff --git a/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig b/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig index bf87ba8bc5..f73dfeb38a 100644 --- a/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig +++ b/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig @@ -1,5 +1,5 @@ export fn entry() void { - var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); + var foo = (@as(u8, @bitCast(@as(f32, 1.0))) == 0xf); _ = foo; } @@ -7,4 +7,4 @@ export fn entry() void { // backend=stage2 // target=native // -// :2:16: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits +// :2:24: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits diff --git a/test/cases/compile_errors/cast_negative_value_to_unsigned_integer.zig b/test/cases/compile_errors/cast_negative_value_to_unsigned_integer.zig index ebd9012015..57206b267f 100644 --- a/test/cases/compile_errors/cast_negative_value_to_unsigned_integer.zig +++ b/test/cases/compile_errors/cast_negative_value_to_unsigned_integer.zig @@ -1,6 +1,6 @@ comptime { const value: i32 = -1; - const unsigned = @intCast(u32, value); + const unsigned: u32 = @intCast(value); _ = unsigned; } export fn entry1() void { diff --git a/test/cases/compile_errors/compile_log_a_pointer_to_an_opaque_value.zig b/test/cases/compile_errors/compile_log_a_pointer_to_an_opaque_value.zig index 73de52fc97..4f79da9fb1 100644 --- a/test/cases/compile_errors/compile_log_a_pointer_to_an_opaque_value.zig +++ b/test/cases/compile_errors/compile_log_a_pointer_to_an_opaque_value.zig @@ -1,5 +1,5 @@ export fn entry() void { - @compileLog(@as(*align(1) const anyopaque, @ptrCast(*const anyopaque, &entry))); + @compileLog(@as(*const anyopaque, @ptrCast(&entry))); } // error diff --git a/test/cases/compile_errors/compile_time_null_ptr_cast.zig b/test/cases/compile_errors/compile_time_null_ptr_cast.zig index 25805e9f35..7d25931aaa 100644 --- a/test/cases/compile_errors/compile_time_null_ptr_cast.zig +++ b/test/cases/compile_errors/compile_time_null_ptr_cast.zig @@ -1,6 +1,6 @@ comptime { var opt_ptr: ?*i32 = null; - const ptr = @ptrCast(*i32, opt_ptr); + const ptr: *i32 = @ptrCast(opt_ptr); _ = ptr; } diff --git a/test/cases/compile_errors/compile_time_undef_ptr_cast.zig b/test/cases/compile_errors/compile_time_undef_ptr_cast.zig index 14edd293de..d93e8bc73d 100644 --- a/test/cases/compile_errors/compile_time_undef_ptr_cast.zig +++ b/test/cases/compile_errors/compile_time_undef_ptr_cast.zig @@ -1,6 +1,6 @@ comptime { var undef_ptr: *i32 = undefined; - const ptr = @ptrCast(*i32, undef_ptr); + const ptr: *i32 = @ptrCast(undef_ptr); _ = ptr; } diff --git a/test/cases/compile_errors/comptime_call_of_function_pointer.zig b/test/cases/compile_errors/comptime_call_of_function_pointer.zig index d6598aab39..574f55e9f3 100644 --- a/test/cases/compile_errors/comptime_call_of_function_pointer.zig +++ b/test/cases/compile_errors/comptime_call_of_function_pointer.zig @@ -1,5 +1,5 @@ export fn entry() void { - const fn_ptr = @ptrFromInt(*align(1) fn () void, 0xffd2); + const fn_ptr: *align(1) fn () void = @ptrFromInt(0xffd2); comptime fn_ptr(); } diff --git a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig index ffa21af10a..83c48e8acd 100644 --- a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig +++ b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig @@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { export fn foo_vector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @ptrCast(&buf); const slice = target[0..3 :0]; _ = slice; } @@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { export fn foo_cvector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @ptrCast(&buf); const slice = target[0..3 :0]; _ = slice; } diff --git a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig index c5bb2d9643..c111b026a5 100644 --- a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig +++ b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig @@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { export fn foo_vector_ConstPtrSpecialRef() void { comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @ptrCast(&buf); const slice = target[0..3 :0]; _ = slice; } @@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { export fn foo_cvector_ConstPtrSpecialRef() void { comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @ptrCast(&buf); const slice = target[0..3 :0]; _ = slice; } diff --git a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig index aa52fb9756..24aa36949b 100644 --- a/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig +++ b/test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig @@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { export fn foo_vector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @ptrCast(&buf); const slice = target[0..14 :255]; _ = slice; } @@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { export fn foo_cvector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @ptrCast(&buf); const slice = target[0..14 :255]; _ = slice; } diff --git a/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_terminated.zig b/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_terminated.zig index 86bd4ce8bb..249d59414a 100644 --- a/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_terminated.zig +++ b/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_terminated.zig @@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { export fn foo_vector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @ptrCast(&buf); const slice = target[0..15 :0]; _ = slice; } @@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { export fn foo_cvector_ConstPtrSpecialRef() void { comptime { var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @ptrCast(&buf); const slice = target[0..15 :0]; _ = slice; } diff --git a/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig b/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig index e1b8a5bc2d..a6e599ca38 100644 --- a/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig +++ b/test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig @@ -24,7 +24,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { export fn foo_vector_ConstPtrSpecialRef() void { comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*]u8 = @ptrCast([*]u8, &buf); + var target: [*]u8 = @ptrCast(&buf); const slice = target[0..14 :0]; _ = slice; } @@ -40,7 +40,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { export fn foo_cvector_ConstPtrSpecialRef() void { comptime { var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - var target: [*c]u8 = @ptrCast([*c]u8, &buf); + var target: [*c]u8 = @ptrCast(&buf); const slice = target[0..14 :0]; _ = slice; } diff --git a/test/cases/compile_errors/enumFromInt_on_non-exhaustive_enums_checks_int_in_range.zig b/test/cases/compile_errors/enumFromInt_on_non-exhaustive_enums_checks_int_in_range.zig index dfef66b628..112017d29d 100644 --- a/test/cases/compile_errors/enumFromInt_on_non-exhaustive_enums_checks_int_in_range.zig +++ b/test/cases/compile_errors/enumFromInt_on_non-exhaustive_enums_checks_int_in_range.zig @@ -1,11 +1,11 @@ pub export fn entry() void { const E = enum(u3) { a, b, c, _ }; - @compileLog(@enumFromInt(E, 100)); + @compileLog(@as(E, @enumFromInt(100))); } // error // target=native // backend=stage2 // -// :3:17: error: int value '100' out of range of non-exhaustive enum 'tmp.entry.E' +// :3:24: error: int value '100' out of range of non-exhaustive enum 'tmp.entry.E' // :2:15: note: enum declared here diff --git a/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig b/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig index 0cf9fcce01..3e1190cc32 100644 --- a/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig +++ b/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig @@ -3,7 +3,7 @@ const Foo = enum(u32) { B = 11, }; export fn entry() void { - var x = @enumFromInt(Foo, 0); + var x: Foo = @enumFromInt(0); _ = x; } @@ -11,5 +11,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :6:13: error: enum 'tmp.Foo' has no tag with value '0' +// :6:18: error: enum 'tmp.Foo' has no tag with value '0' // :1:13: note: enum declared here diff --git a/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig b/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig index a3af883198..cfb01c3ddc 100644 --- a/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig +++ b/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig @@ -2,7 +2,7 @@ const Set1 = error{ A, B }; const Set2 = error{ A, C }; comptime { var x = Set1.B; - var y = @errSetCast(Set2, x); + var y: Set2 = @errSetCast(x); _ = y; } @@ -10,4 +10,4 @@ comptime { // backend=stage2 // target=native // -// :5:13: error: 'error.B' not a member of error set 'error{C,A}' +// :5:19: error: 'error.B' not a member of error set 'error{C,A}' diff --git a/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig b/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig index 6ae39489a0..bb920138e1 100644 --- a/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig +++ b/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig @@ -7,7 +7,7 @@ const Small = enum(u2) { export fn entry() void { var y = @as(f32, 3); - var x = @enumFromInt(Small, y); + var x: Small = @enumFromInt(y); _ = x; } diff --git a/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig b/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig index 9fc8038d7a..2147fb8aed 100644 --- a/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig +++ b/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig @@ -8,7 +8,7 @@ const foo = Foo{ }; comptime { - const field_ptr = @ptrFromInt(*i32, 0x1234); + const field_ptr: *i32 = @ptrFromInt(0x1234); const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); _ = another_foo_ptr; } diff --git a/test/cases/compile_errors/field_access_of_opaque_type.zig b/test/cases/compile_errors/field_access_of_opaque_type.zig index f9ec483305..7f975c4b0a 100644 --- a/test/cases/compile_errors/field_access_of_opaque_type.zig +++ b/test/cases/compile_errors/field_access_of_opaque_type.zig @@ -2,7 +2,7 @@ const MyType = opaque {}; export fn entry() bool { var x: i32 = 1; - return bar(@ptrCast(*MyType, &x)); + return bar(@ptrCast(&x)); } fn bar(x: *MyType) bool { diff --git a/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig b/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig index 44405b3c20..55af9c1185 100644 --- a/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig +++ b/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig @@ -2,7 +2,7 @@ pub export fn entry() void { var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; var slice: []u8 = &buf; const a: u32 = 1234; - @memcpy(slice.ptr, @ptrCast([*]const u8, &a)); + @memcpy(slice.ptr, @as([*]const u8, @ptrCast(&a))); } pub export fn entry1() void { var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; @@ -39,7 +39,7 @@ pub export fn memset_array() void { // // :5:5: error: unknown @memcpy length // :5:18: note: destination type '[*]u8' provides no length -// :5:24: note: source type '[*]align(4) const u8' provides no length +// :5:24: note: source type '[*]const u8' provides no length // :10:13: error: type '*u8' is not an indexable pointer // :10:13: note: operand must be a slice, a many pointer or a pointer to an array // :15:13: error: type '*u8' is not an indexable pointer diff --git a/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig b/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig index 8d7e14acae..22bd90b068 100644 --- a/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig +++ b/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig @@ -1,6 +1,6 @@ export fn entry() u32 { var bytes: [4]u8 = [_]u8{ 0x01, 0x02, 0x03, 0x04 }; - const ptr = @ptrCast(*u32, &bytes[0]); + const ptr: *u32 = @ptrCast(&bytes[0]); return ptr.*; } @@ -8,7 +8,7 @@ export fn entry() u32 { // backend=stage2 // target=native // -// :3:17: error: cast increases pointer alignment +// :3:23: error: cast increases pointer alignment // :3:32: note: '*u8' has alignment '1' -// :3:26: note: '*u32' has alignment '4' -// :3:17: note: consider using '@alignCast' +// :3:23: note: '*u32' has alignment '4' +// :3:23: note: use @alignCast to assert pointer alignment diff --git a/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig b/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig index ecf8f61fc5..7724632069 100644 --- a/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig +++ b/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig @@ -1,17 +1,17 @@ export fn foo() void { var a: f32 = 2; - _ = @intFromFloat(comptime_int, a); + _ = @as(comptime_int, @intFromFloat(a)); } export fn bar() void { var a: u32 = 2; - _ = @floatFromInt(comptime_float, a); + _ = @as(comptime_float, @floatFromInt(a)); } // error // backend=stage2 // target=native // -// :3:37: error: unable to resolve comptime value -// :3:37: note: value being casted to 'comptime_int' must be comptime-known -// :7:39: error: unable to resolve comptime value -// :7:39: note: value being casted to 'comptime_float' must be comptime-known +// :3:41: error: unable to resolve comptime value +// :3:41: note: value being casted to 'comptime_int' must be comptime-known +// :7:43: error: unable to resolve comptime value +// :7:43: note: value being casted to 'comptime_float' must be comptime-known diff --git a/test/cases/compile_errors/intFromFloat_comptime_safety.zig b/test/cases/compile_errors/intFromFloat_comptime_safety.zig index 275f67006f..e3bfc3eb96 100644 --- a/test/cases/compile_errors/intFromFloat_comptime_safety.zig +++ b/test/cases/compile_errors/intFromFloat_comptime_safety.zig @@ -1,17 +1,17 @@ comptime { - _ = @intFromFloat(i8, @as(f32, -129.1)); + _ = @as(i8, @intFromFloat(@as(f32, -129.1))); } comptime { - _ = @intFromFloat(u8, @as(f32, -1.1)); + _ = @as(u8, @intFromFloat(@as(f32, -1.1))); } comptime { - _ = @intFromFloat(u8, @as(f32, 256.1)); + _ = @as(u8, @intFromFloat(@as(f32, 256.1))); } // error // backend=stage2 // target=native // -// :2:27: error: float value '-129.10000610351562' cannot be stored in integer type 'i8' -// :5:27: error: float value '-1.100000023841858' cannot be stored in integer type 'u8' -// :8:27: error: float value '256.1000061035156' cannot be stored in integer type 'u8' +// :2:31: error: float value '-129.10000610351562' cannot be stored in integer type 'i8' +// :5:31: error: float value '-1.100000023841858' cannot be stored in integer type 'u8' +// :8:31: error: float value '256.1000061035156' cannot be stored in integer type 'u8' diff --git a/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig b/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig index 4a2ea05eaa..e443b3daa9 100644 --- a/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig +++ b/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig @@ -1,5 +1,5 @@ export fn entry() void { - var b = @ptrFromInt(*i32, 0); + var b: *i32 = @ptrFromInt(0); _ = b; } diff --git a/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig b/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig index 6a1f2db531..32f4657ed5 100644 --- a/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig +++ b/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig @@ -8,7 +8,7 @@ const Set2 = error{ }; comptime { var x = @intFromError(Set1.B); - var y = @errSetCast(Set2, @errorFromInt(x)); + var y: Set2 = @errSetCast(@errorFromInt(x)); _ = y; } @@ -16,4 +16,4 @@ comptime { // backend=llvm // target=native // -// :11:13: error: 'error.B' not a member of error set 'error{C,A}' +// :11:19: error: 'error.B' not a member of error set 'error{C,A}' diff --git a/test/cases/compile_errors/integer_cast_truncates_bits.zig b/test/cases/compile_errors/integer_cast_truncates_bits.zig index 82eb6b61cf..a230dd3e5b 100644 --- a/test/cases/compile_errors/integer_cast_truncates_bits.zig +++ b/test/cases/compile_errors/integer_cast_truncates_bits.zig @@ -1,6 +1,6 @@ export fn entry1() void { const spartan_count: u16 = 300; - const byte = @intCast(u8, spartan_count); + const byte: u8 = @intCast(spartan_count); _ = byte; } export fn entry2() void { diff --git a/test/cases/compile_errors/integer_underflow_error.zig b/test/cases/compile_errors/integer_underflow_error.zig index 275b593ecc..49f46ee558 100644 --- a/test/cases/compile_errors/integer_underflow_error.zig +++ b/test/cases/compile_errors/integer_underflow_error.zig @@ -1,9 +1,9 @@ export fn entry() void { - _ = @ptrFromInt(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1); + _ = @as(*anyopaque, @ptrFromInt(~@as(usize, @import("std").math.maxInt(usize)) - 1)); } // error // backend=stage2 // target=native // -// :2:80: error: overflow of integer type 'usize' with value '-1' +// :2:84: error: overflow of integer type 'usize' with value '-1' diff --git a/test/cases/compile_errors/invalid_float_casts.zig b/test/cases/compile_errors/invalid_float_casts.zig index 507ced1e57..789eb10976 100644 --- a/test/cases/compile_errors/invalid_float_casts.zig +++ b/test/cases/compile_errors/invalid_float_casts.zig @@ -1,25 +1,25 @@ export fn foo() void { var a: f32 = 2; - _ = @floatCast(comptime_float, a); + _ = @as(comptime_float, @floatCast(a)); } export fn bar() void { var a: f32 = 2; - _ = @intFromFloat(f32, a); + _ = @as(f32, @intFromFloat(a)); } export fn baz() void { var a: f32 = 2; - _ = @floatFromInt(f32, a); + _ = @as(f32, @floatFromInt(a)); } export fn qux() void { var a: u32 = 2; - _ = @floatCast(f32, a); + _ = @as(f32, @floatCast(a)); } // error // backend=stage2 // target=native // -// :3:36: error: unable to cast runtime value to 'comptime_float' -// :7:23: error: expected integer type, found 'f32' -// :11:28: error: expected integer type, found 'f32' -// :15:25: error: expected float type, found 'u32' +// :3:40: error: unable to cast runtime value to 'comptime_float' +// :7:18: error: expected integer type, found 'f32' +// :11:32: error: expected integer type, found 'f32' +// :15:29: error: expected float type, found 'u32' diff --git a/test/cases/compile_errors/invalid_int_casts.zig b/test/cases/compile_errors/invalid_int_casts.zig index 262a096bd9..1e52c52609 100644 --- a/test/cases/compile_errors/invalid_int_casts.zig +++ b/test/cases/compile_errors/invalid_int_casts.zig @@ -1,25 +1,25 @@ export fn foo() void { var a: u32 = 2; - _ = @intCast(comptime_int, a); + _ = @as(comptime_int, @intCast(a)); } export fn bar() void { var a: u32 = 2; - _ = @floatFromInt(u32, a); + _ = @as(u32, @floatFromInt(a)); } export fn baz() void { var a: u32 = 2; - _ = @intFromFloat(u32, a); + _ = @as(u32, @intFromFloat(a)); } export fn qux() void { var a: f32 = 2; - _ = @intCast(u32, a); + _ = @as(u32, @intCast(a)); } // error // backend=stage2 // target=native // -// :3:32: error: unable to cast runtime value to 'comptime_int' -// :7:23: error: expected float type, found 'u32' -// :11:28: error: expected float type, found 'u32' -// :15:23: error: expected integer or vector, found 'f32' +// :3:36: error: unable to cast runtime value to 'comptime_int' +// :7:18: error: expected float type, found 'u32' +// :11:32: error: expected float type, found 'u32' +// :15:27: error: expected integer or vector, found 'f32' diff --git a/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig b/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig index 5457a61d3f..d7a93edfcd 100644 --- a/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig +++ b/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig @@ -8,12 +8,12 @@ const U = union(E) { b, }; export fn foo() void { - var e = @enumFromInt(E, 15); + var e: E = @enumFromInt(15); var u: U = e; _ = u; } export fn bar() void { - const e = @enumFromInt(E, 15); + const e: E = @enumFromInt(15); var u: U = e; _ = u; } @@ -24,5 +24,5 @@ export fn bar() void { // // :12:16: error: runtime coercion to union 'tmp.U' from non-exhaustive enum // :1:11: note: enum declared here -// :17:16: error: union 'tmp.U' has no tag with value '@enumFromInt(tmp.E, 15)' +// :17:16: error: union 'tmp.U' has no tag with value '@enumFromInt(15)' // :6:11: note: union declared here diff --git a/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig b/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig index 7a4c0eb7e8..c6566bb46a 100644 --- a/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig +++ b/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig @@ -1,11 +1,11 @@ export fn foo1() void { var bytes = [_]u8{ 1, 2 }; - const word: u16 = @bitCast(u16, bytes[0..]); + const word: u16 = @bitCast(bytes[0..]); _ = word; } export fn foo2() void { var bytes: []const u8 = &[_]u8{ 1, 2 }; - const word: u16 = @bitCast(u16, bytes); + const word: u16 = @bitCast(bytes); _ = word; } @@ -13,7 +13,7 @@ export fn foo2() void { // backend=stage2 // target=native // -// :3:42: error: cannot @bitCast from '*[2]u8' -// :3:42: note: use @intFromPtr to cast to 'u16' -// :8:37: error: cannot @bitCast from '[]const u8' -// :8:37: note: use @intFromPtr to cast to 'u16' +// :3:37: error: cannot @bitCast from '*[2]u8' +// :3:37: note: use @intFromPtr to cast to 'u16' +// :8:32: error: cannot @bitCast from '[]const u8' +// :8:32: note: use @intFromPtr to cast to 'u16' diff --git a/test/cases/compile_errors/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig b/test/cases/compile_errors/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig index baeb3e8c82..e4952e6951 100644 --- a/test/cases/compile_errors/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig +++ b/test/cases/compile_errors/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig @@ -1,7 +1,7 @@ export fn entry() void { const float: f32 align(@alignOf(i64)) = 5.99999999999994648725e-01; const float_ptr = &float; - const int_ptr = @ptrCast(*const i64, float_ptr); + const int_ptr: *const i64 = @ptrCast(float_ptr); const int_val = int_ptr.*; _ = int_val; } diff --git a/test/cases/compile_errors/missing_builtin_arg_in_initializer.zig b/test/cases/compile_errors/missing_builtin_arg_in_initializer.zig index 0bada117b2..cdbebf5457 100644 --- a/test/cases/compile_errors/missing_builtin_arg_in_initializer.zig +++ b/test/cases/compile_errors/missing_builtin_arg_in_initializer.zig @@ -1,8 +1,11 @@ comptime { - const v = @as(); + const a = @as(); } comptime { - const u = @bitCast(u32); + const b = @bitCast(); +} +comptime { + const c = @as(u32); } // error @@ -10,4 +13,5 @@ comptime { // target=native // // :2:15: error: expected 2 arguments, found 0 -// :5:15: error: expected 2 arguments, found 1 +// :5:15: error: expected 1 argument, found 0 +// :8:15: error: expected 2 arguments, found 1 diff --git a/test/cases/compile_errors/non_float_passed_to_intFromFloat.zig b/test/cases/compile_errors/non_float_passed_to_intFromFloat.zig index fac51c59c8..ee0b5e733e 100644 --- a/test/cases/compile_errors/non_float_passed_to_intFromFloat.zig +++ b/test/cases/compile_errors/non_float_passed_to_intFromFloat.zig @@ -1,5 +1,5 @@ export fn entry() void { - const x = @intFromFloat(i32, @as(i32, 54)); + const x: i32 = @intFromFloat(@as(i32, 54)); _ = x; } diff --git a/test/cases/compile_errors/non_int_passed_to_floatFromInt.zig b/test/cases/compile_errors/non_int_passed_to_floatFromInt.zig index 63e6753a53..c60842e980 100644 --- a/test/cases/compile_errors/non_int_passed_to_floatFromInt.zig +++ b/test/cases/compile_errors/non_int_passed_to_floatFromInt.zig @@ -1,5 +1,5 @@ export fn entry() void { - const x = @floatFromInt(f32, 1.1); + const x: f32 = @floatFromInt(1.1); _ = x; } diff --git a/test/cases/compile_errors/out_of_int_range_comptime_float_passed_to_intFromFloat.zig b/test/cases/compile_errors/out_of_int_range_comptime_float_passed_to_intFromFloat.zig index 574ffc5a20..d9cfd4b2de 100644 --- a/test/cases/compile_errors/out_of_int_range_comptime_float_passed_to_intFromFloat.zig +++ b/test/cases/compile_errors/out_of_int_range_comptime_float_passed_to_intFromFloat.zig @@ -1,5 +1,5 @@ export fn entry() void { - const x = @intFromFloat(i8, 200); + const x: i8 = @intFromFloat(200); _ = x; } diff --git a/test/cases/compile_errors/ptrCast_discards_const_qualifier.zig b/test/cases/compile_errors/ptrCast_discards_const_qualifier.zig index f27f5f4f93..a704ea456b 100644 --- a/test/cases/compile_errors/ptrCast_discards_const_qualifier.zig +++ b/test/cases/compile_errors/ptrCast_discards_const_qualifier.zig @@ -1,6 +1,6 @@ export fn entry() void { const x: i32 = 1234; - const y = @ptrCast(*i32, &x); + const y: *i32 = @ptrCast(&x); _ = y; } @@ -8,5 +8,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :3:15: error: cast discards const qualifier -// :3:15: note: consider using '@constCast' +// :3:21: error: cast discards const qualifier +// :3:21: note: use @constCast to discard const qualifier diff --git a/test/cases/compile_errors/ptrFromInt_non_ptr_type.zig b/test/cases/compile_errors/ptrFromInt_non_ptr_type.zig index f472789aff..c75ceb444b 100644 --- a/test/cases/compile_errors/ptrFromInt_non_ptr_type.zig +++ b/test/cases/compile_errors/ptrFromInt_non_ptr_type.zig @@ -1,15 +1,15 @@ pub export fn entry() void { - _ = @ptrFromInt(i32, 10); + _ = @as(i32, @ptrFromInt(10)); } pub export fn entry2() void { - _ = @ptrFromInt([]u8, 20); + _ = @as([]u8, @ptrFromInt(20)); } // error // backend=stage2 // target=native // -// :2:21: error: expected pointer type, found 'i32' -// :6:21: error: integer cannot be converted to slice type '[]u8' -// :6:21: note: slice length cannot be inferred from address +// :2:18: error: expected pointer type, found 'i32' +// :6:19: error: integer cannot be converted to slice type '[]u8' +// :6:19: note: slice length cannot be inferred from address diff --git a/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig b/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig index c45e998d82..dfcbf6849c 100644 --- a/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig +++ b/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig @@ -1,5 +1,5 @@ pub export fn entry() void { - var y = @ptrFromInt([*]align(4) u8, 5); + var y: [*]align(4) u8 = @ptrFromInt(5); _ = y; } diff --git a/test/cases/compile_errors/ptrcast_to_non-pointer.zig b/test/cases/compile_errors/ptrcast_to_non-pointer.zig index 66a11a602b..ec93dc12c2 100644 --- a/test/cases/compile_errors/ptrcast_to_non-pointer.zig +++ b/test/cases/compile_errors/ptrcast_to_non-pointer.zig @@ -1,9 +1,9 @@ export fn entry(a: *i32) usize { - return @ptrCast(usize, a); + return @ptrCast(a); } // error // backend=llvm // target=native // -// :2:21: error: expected pointer type, found 'usize' +// :2:12: error: expected pointer type, found 'usize' diff --git a/test/cases/compile_errors/reading_past_end_of_pointer_casted_array.zig b/test/cases/compile_errors/reading_past_end_of_pointer_casted_array.zig index d3d9b03ff5..b06b541984 100644 --- a/test/cases/compile_errors/reading_past_end_of_pointer_casted_array.zig +++ b/test/cases/compile_errors/reading_past_end_of_pointer_casted_array.zig @@ -1,7 +1,7 @@ comptime { const array: [4]u8 = "aoeu".*; const sub_array = array[1..]; - const int_ptr = @ptrCast(*const u24, @alignCast(@alignOf(u24), sub_array)); + const int_ptr: *const u24 = @ptrCast(@alignCast(sub_array)); const deref = int_ptr.*; _ = deref; } diff --git a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig index 9b140a0923..b26ec70296 100644 --- a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig +++ b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig @@ -7,7 +7,7 @@ const Tag = @Type(.{ }, }); export fn entry() void { - _ = @enumFromInt(Tag, 0); + _ = @as(Tag, @enumFromInt(0)); } // error diff --git a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig index b2cd8e1214..5d5294ba30 100644 --- a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig +++ b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig @@ -7,7 +7,7 @@ const Tag = @Type(.{ }, }); export fn entry() void { - _ = @enumFromInt(Tag, 0); + _ = @as(Tag, @enumFromInt(0)); } // error diff --git a/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig b/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig index 5fab9c90a9..85fb0065d1 100644 --- a/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig +++ b/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig @@ -1,6 +1,6 @@ export fn foo() void { const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16; - var value = @ptrCast(*const []const u8, &bytes).*; + var value = @as(*const []const u8, @ptrCast(&bytes)).*; _ = value; } @@ -8,4 +8,4 @@ export fn foo() void { // backend=stage2 // target=native // -// :3:52: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not. +// :3:57: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not. diff --git a/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig b/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig index df454a38d0..2b45fb6076 100644 --- a/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig +++ b/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig @@ -1,6 +1,6 @@ test "enum" { const E = enum(u8) { A, B, _ }; - _ = @tagName(@enumFromInt(E, 5)); + _ = @tagName(@as(E, @enumFromInt(5))); } // error @@ -8,5 +8,5 @@ test "enum" { // target=native // is_test=1 // -// :3:9: error: no field with value '@enumFromInt(tmp.test.enum.E, 5)' in enum 'test.enum.E' +// :3:9: error: no field with value '@enumFromInt(5)' in enum 'test.enum.E' // :2:15: note: declared here diff --git a/test/cases/compile_errors/truncate_sign_mismatch.zig b/test/cases/compile_errors/truncate_sign_mismatch.zig index a05660e28c..b34dfa8e07 100644 --- a/test/cases/compile_errors/truncate_sign_mismatch.zig +++ b/test/cases/compile_errors/truncate_sign_mismatch.zig @@ -1,25 +1,25 @@ export fn entry1() i8 { var x: u32 = 10; - return @truncate(i8, x); + return @truncate(x); } export fn entry2() u8 { var x: i32 = -10; - return @truncate(u8, x); + return @truncate(x); } export fn entry3() i8 { comptime var x: u32 = 10; - return @truncate(i8, x); + return @truncate(x); } export fn entry4() u8 { comptime var x: i32 = -10; - return @truncate(u8, x); + return @truncate(x); } // error // backend=stage2 // target=native // -// :3:26: error: expected signed integer type, found 'u32' -// :7:26: error: expected unsigned integer type, found 'i32' -// :11:26: error: expected signed integer type, found 'u32' -// :15:26: error: expected unsigned integer type, found 'i32' +// :3:22: error: expected signed integer type, found 'u32' +// :7:22: error: expected unsigned integer type, found 'i32' +// :11:22: error: expected signed integer type, found 'u32' +// :15:22: error: expected unsigned integer type, found 'i32' diff --git a/test/cases/compile_errors/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig b/test/cases/compile_errors/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig index a050eb6a4c..a7c8f0eb72 100644 --- a/test/cases/compile_errors/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig +++ b/test/cases/compile_errors/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig @@ -2,7 +2,7 @@ const Derp = opaque {}; extern fn bar(d: *Derp) void; export fn foo() void { var x = @as(u8, 1); - bar(@ptrCast(*anyopaque, &x)); + bar(@as(*anyopaque, @ptrCast(&x))); } // error diff --git a/test/cases/enum_values.0.zig b/test/cases/enum_values.0.zig index 2c44a095dd..71c3e3521a 100644 --- a/test/cases/enum_values.0.zig +++ b/test/cases/enum_values.0.zig @@ -7,7 +7,7 @@ pub fn main() void { number1; number2; } - const number3 = @enumFromInt(Number, 2); + const number3: Number = @enumFromInt(2); if (@intFromEnum(number3) != 2) { unreachable; } diff --git a/test/cases/enum_values.1.zig b/test/cases/enum_values.1.zig index 1b5a9836db..934106dd79 100644 --- a/test/cases/enum_values.1.zig +++ b/test/cases/enum_values.1.zig @@ -3,7 +3,7 @@ const Number = enum { One, Two, Three }; pub fn main() void { var number1 = Number.One; var number2: Number = .Two; - const number3 = @enumFromInt(Number, 2); + const number3: Number = @enumFromInt(2); assert(number1 != number2); assert(number2 != number3); assert(@intFromEnum(number1) == 0); diff --git a/test/cases/error_in_nested_declaration.zig b/test/cases/error_in_nested_declaration.zig index 710b821e65..20afacfb68 100644 --- a/test/cases/error_in_nested_declaration.zig +++ b/test/cases/error_in_nested_declaration.zig @@ -3,7 +3,7 @@ const S = struct { c: i32, a: struct { pub fn str(_: @This(), extra: []u32) []i32 { - return @bitCast([]i32, extra); + return @bitCast(extra); } }, }; @@ -27,5 +27,5 @@ pub export fn entry2() void { // target=native // // :17:12: error: C pointers cannot point to opaque types -// :6:29: error: cannot @bitCast to '[]i32' -// :6:29: note: use @ptrCast to cast from '[]u32' +// :6:20: error: cannot @bitCast to '[]i32' +// :6:20: note: use @ptrCast to cast from '[]u32' diff --git a/test/cases/int_to_ptr.0.zig b/test/cases/int_to_ptr.0.zig index ba14c03804..09efb8b1a5 100644 --- a/test/cases/int_to_ptr.0.zig +++ b/test/cases/int_to_ptr.0.zig @@ -1,8 +1,8 @@ pub fn main() void { - _ = @ptrFromInt(*u8, 0); + _ = @as(*u8, @ptrFromInt(0)); } // error // output_mode=Exe // -// :2:24: error: pointer type '*u8' does not allow address zero +// :2:18: error: pointer type '*u8' does not allow address zero diff --git a/test/cases/int_to_ptr.1.zig b/test/cases/int_to_ptr.1.zig index e75ae81f6f..d5aed471e1 100644 --- a/test/cases/int_to_ptr.1.zig +++ b/test/cases/int_to_ptr.1.zig @@ -1,7 +1,7 @@ pub fn main() void { - _ = @ptrFromInt(*u32, 2); + _ = @as(*u32, @ptrFromInt(2)); } // error // -// :2:25: error: pointer type '*u32' requires aligned address +// :2:19: error: pointer type '*u32' requires aligned address diff --git a/test/cases/llvm/f_segment_address_space_reading_and_writing.zig b/test/cases/llvm/f_segment_address_space_reading_and_writing.zig index 507362a937..ddcd41bf16 100644 --- a/test/cases/llvm/f_segment_address_space_reading_and_writing.zig +++ b/test/cases/llvm/f_segment_address_space_reading_and_writing.zig @@ -34,7 +34,7 @@ pub fn main() void { setFs(@intFromPtr(&test_value)); assert(getFs() == @intFromPtr(&test_value)); - var test_ptr = @ptrFromInt(*allowzero addrspace(.fs) u64, 0); + var test_ptr: *allowzero addrspace(.fs) u64 = @ptrFromInt(0); assert(test_ptr.* == 12345); test_ptr.* = 98765; assert(test_value == 98765); diff --git a/test/cases/llvm/large_slices.zig b/test/cases/llvm/large_slices.zig index f90e588ab0..8e9431df8c 100644 --- a/test/cases/llvm/large_slices.zig +++ b/test/cases/llvm/large_slices.zig @@ -1,5 +1,5 @@ pub fn main() void { - const large_slice = @ptrFromInt([*]const u8, 1)[0..(0xffffffffffffffff >> 3)]; + const large_slice = @as([*]const u8, @ptrFromInt(1))[0..(0xffffffffffffffff >> 3)]; _ = large_slice; } diff --git a/test/cases/safety/@alignCast misaligned.zig b/test/cases/safety/@alignCast misaligned.zig index 538e0ecdf6..ade27c2747 100644 --- a/test/cases/safety/@alignCast misaligned.zig +++ b/test/cases/safety/@alignCast misaligned.zig @@ -16,7 +16,8 @@ pub fn main() !void { } fn foo(bytes: []u8) u32 { const slice4 = bytes[1..5]; - const int_slice = std.mem.bytesAsSlice(u32, @alignCast(4, slice4)); + const aligned: *align(4) [4]u8 = @alignCast(slice4); + const int_slice = std.mem.bytesAsSlice(u32, aligned); return int_slice[0]; } // run diff --git a/test/cases/safety/@enumFromInt - no matching tag value.zig b/test/cases/safety/@enumFromInt - no matching tag value.zig index 57f8954f93..5051869cc0 100644 --- a/test/cases/safety/@enumFromInt - no matching tag value.zig +++ b/test/cases/safety/@enumFromInt - no matching tag value.zig @@ -17,7 +17,7 @@ pub fn main() !void { return error.TestFailed; } fn bar(a: u2) Foo { - return @enumFromInt(Foo, a); + return @enumFromInt(a); } fn baz(_: Foo) void {} diff --git a/test/cases/safety/@errSetCast error not present in destination.zig b/test/cases/safety/@errSetCast error not present in destination.zig index 372bd80aa5..84aeb7610e 100644 --- a/test/cases/safety/@errSetCast error not present in destination.zig +++ b/test/cases/safety/@errSetCast error not present in destination.zig @@ -14,7 +14,7 @@ pub fn main() !void { return error.TestFailed; } fn foo(set1: Set1) Set2 { - return @errSetCast(Set2, set1); + return @errSetCast(set1); } // run // backend=llvm diff --git a/test/cases/safety/@intCast to u0.zig b/test/cases/safety/@intCast to u0.zig index f3f969548b..8c9f76e2aa 100644 --- a/test/cases/safety/@intCast to u0.zig +++ b/test/cases/safety/@intCast to u0.zig @@ -14,7 +14,7 @@ pub fn main() !void { } fn bar(one: u1, not_zero: i32) void { - var x = one << @intCast(u0, not_zero); + var x = one << @as(u0, @intCast(not_zero)); _ = x; } // run diff --git a/test/cases/safety/@intFromFloat cannot fit - negative out of range.zig b/test/cases/safety/@intFromFloat cannot fit - negative out of range.zig index 9a8853c0e9..a5a8d831b3 100644 --- a/test/cases/safety/@intFromFloat cannot fit - negative out of range.zig +++ b/test/cases/safety/@intFromFloat cannot fit - negative out of range.zig @@ -12,7 +12,7 @@ pub fn main() !void { return error.TestFailed; } fn bar(a: f32) i8 { - return @intFromFloat(i8, a); + return @intFromFloat(a); } fn baz(_: i8) void {} // run diff --git a/test/cases/safety/@intFromFloat cannot fit - negative to unsigned.zig b/test/cases/safety/@intFromFloat cannot fit - negative to unsigned.zig index caf7bbf0d6..1bf1a66765 100644 --- a/test/cases/safety/@intFromFloat cannot fit - negative to unsigned.zig +++ b/test/cases/safety/@intFromFloat cannot fit - negative to unsigned.zig @@ -12,7 +12,7 @@ pub fn main() !void { return error.TestFailed; } fn bar(a: f32) u8 { - return @intFromFloat(u8, a); + return @intFromFloat(a); } fn baz(_: u8) void {} // run diff --git a/test/cases/safety/@intFromFloat cannot fit - positive out of range.zig b/test/cases/safety/@intFromFloat cannot fit - positive out of range.zig index d335238b65..15a9fa7ad1 100644 --- a/test/cases/safety/@intFromFloat cannot fit - positive out of range.zig +++ b/test/cases/safety/@intFromFloat cannot fit - positive out of range.zig @@ -12,7 +12,7 @@ pub fn main() !void { return error.TestFailed; } fn bar(a: f32) u8 { - return @intFromFloat(u8, a); + return @intFromFloat(a); } fn baz(_: u8) void {} // run diff --git a/test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig b/test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig index 345d5cfc74..41cff07e32 100644 --- a/test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig +++ b/test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig @@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var zero: usize = 0; - var b = @ptrFromInt(*u8, zero); + var b: *u8 = @ptrFromInt(zero); _ = b; return error.TestFailed; } diff --git a/test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig b/test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig index e7d3b66d6c..92e98d4777 100644 --- a/test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig +++ b/test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig @@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var zero: usize = 0; - var b = @ptrFromInt(*i32, zero); + var b: *i32 = @ptrFromInt(zero); _ = b; return error.TestFailed; } diff --git a/test/cases/safety/@ptrFromInt with misaligned address.zig b/test/cases/safety/@ptrFromInt with misaligned address.zig index c2e1d351eb..afb8aa7eb8 100644 --- a/test/cases/safety/@ptrFromInt with misaligned address.zig +++ b/test/cases/safety/@ptrFromInt with misaligned address.zig @@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var x: usize = 5; - var y = @ptrFromInt([*]align(4) u8, x); + var y: [*]align(4) u8 = @ptrFromInt(x); _ = y; return error.TestFailed; } diff --git a/test/cases/safety/@tagName on corrupted enum value.zig b/test/cases/safety/@tagName on corrupted enum value.zig index 43af9fbda6..a541771df1 100644 --- a/test/cases/safety/@tagName on corrupted enum value.zig +++ b/test/cases/safety/@tagName on corrupted enum value.zig @@ -15,7 +15,7 @@ const E = enum(u32) { pub fn main() !void { var e: E = undefined; - @memset(@ptrCast([*]u8, &e)[0..@sizeOf(E)], 0x55); + @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55); var n = @tagName(e); _ = n; return error.TestFailed; diff --git a/test/cases/safety/@tagName on corrupted union value.zig b/test/cases/safety/@tagName on corrupted union value.zig index a72755abdc..dd3d9bd3bf 100644 --- a/test/cases/safety/@tagName on corrupted union value.zig +++ b/test/cases/safety/@tagName on corrupted union value.zig @@ -15,7 +15,7 @@ const U = union(enum(u32)) { pub fn main() !void { var u: U = undefined; - @memset(@ptrCast([*]u8, &u)[0..@sizeOf(U)], 0x55); + @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55); var t: @typeInfo(U).Union.tag_type.? = u; var n = @tagName(t); _ = n; diff --git a/test/cases/safety/pointer casting to null function pointer.zig b/test/cases/safety/pointer casting to null function pointer.zig index 7736cb5034..8f399b66dc 100644 --- a/test/cases/safety/pointer casting to null function pointer.zig +++ b/test/cases/safety/pointer casting to null function pointer.zig @@ -13,7 +13,7 @@ fn getNullPtr() ?*const anyopaque { } pub fn main() !void { const null_ptr: ?*const anyopaque = getNullPtr(); - const required_ptr: *align(1) const fn () void = @ptrCast(*align(1) const fn () void, null_ptr); + const required_ptr: *align(1) const fn () void = @ptrCast(null_ptr); _ = required_ptr; return error.TestFailed; } diff --git a/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig b/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig index a79298b7da..9052913691 100644 --- a/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig +++ b/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig @@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var value: c_short = -1; - var casted = @intCast(u32, value); + var casted: u32 = @intCast(value); _ = casted; return error.TestFailed; } diff --git a/test/cases/safety/signed integer not fitting in cast to unsigned integer.zig b/test/cases/safety/signed integer not fitting in cast to unsigned integer.zig index 6c4e9e256d..5d8c3f88c8 100644 --- a/test/cases/safety/signed integer not fitting in cast to unsigned integer.zig +++ b/test/cases/safety/signed integer not fitting in cast to unsigned integer.zig @@ -13,7 +13,7 @@ pub fn main() !void { return error.TestFailed; } fn unsigned_cast(x: i32) u32 { - return @intCast(u32, x); + return @intCast(x); } // run // backend=llvm diff --git a/test/cases/safety/signed-unsigned vector cast.zig b/test/cases/safety/signed-unsigned vector cast.zig index d287c0a1ae..60406aa8a3 100644 --- a/test/cases/safety/signed-unsigned vector cast.zig +++ b/test/cases/safety/signed-unsigned vector cast.zig @@ -10,7 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var x = @splat(4, @as(i32, -2147483647)); - var y = @intCast(@Vector(4, u32), x); + var y: @Vector(4, u32) = @intCast(x); _ = y; return error.TestFailed; } diff --git a/test/cases/safety/slice sentinel mismatch - optional pointers.zig b/test/cases/safety/slice sentinel mismatch - optional pointers.zig index 33f4a1099b..a3b4a98575 100644 --- a/test/cases/safety/slice sentinel mismatch - optional pointers.zig +++ b/test/cases/safety/slice sentinel mismatch - optional pointers.zig @@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { - var buf: [4]?*i32 = .{ @ptrFromInt(*i32, 4), @ptrFromInt(*i32, 8), @ptrFromInt(*i32, 12), @ptrFromInt(*i32, 16) }; + var buf: [4]?*i32 = .{ @ptrFromInt(4), @ptrFromInt(8), @ptrFromInt(12), @ptrFromInt(16) }; const slice = buf[0..3 :null]; _ = slice; return error.TestFailed; diff --git a/test/cases/safety/switch else on corrupt enum value - one prong.zig b/test/cases/safety/switch else on corrupt enum value - one prong.zig index 2c0b58fcd4..c11227c3be 100644 --- a/test/cases/safety/switch else on corrupt enum value - one prong.zig +++ b/test/cases/safety/switch else on corrupt enum value - one prong.zig @@ -13,7 +13,7 @@ const E = enum(u32) { }; pub fn main() !void { var a: E = undefined; - @ptrCast(*u32, &a).* = 255; + @as(*u32, @ptrCast(&a)).* = 255; switch (a) { .one => @panic("one"), else => @panic("else"), diff --git a/test/cases/safety/switch else on corrupt enum value - union.zig b/test/cases/safety/switch else on corrupt enum value - union.zig index 358ecc89ac..a63c78597e 100644 --- a/test/cases/safety/switch else on corrupt enum value - union.zig +++ b/test/cases/safety/switch else on corrupt enum value - union.zig @@ -18,7 +18,7 @@ const U = union(E) { }; pub fn main() !void { var a: U = undefined; - @ptrCast(*align(@alignOf(U)) u32, &a).* = 0xFFFF_FFFF; + @as(*align(@alignOf(U)) u32, @ptrCast(&a)).* = 0xFFFF_FFFF; switch (a) { .one => @panic("one"), else => @panic("else"), diff --git a/test/cases/safety/switch else on corrupt enum value.zig b/test/cases/safety/switch else on corrupt enum value.zig index af04b7f4c3..7e050838c0 100644 --- a/test/cases/safety/switch else on corrupt enum value.zig +++ b/test/cases/safety/switch else on corrupt enum value.zig @@ -13,7 +13,7 @@ const E = enum(u32) { }; pub fn main() !void { var a: E = undefined; - @ptrCast(*u32, &a).* = 255; + @as(*u32, @ptrCast(&a)).* = 255; switch (a) { else => @panic("else"), } diff --git a/test/cases/safety/switch on corrupted enum value.zig b/test/cases/safety/switch on corrupted enum value.zig index 687be0b598..f890761911 100644 --- a/test/cases/safety/switch on corrupted enum value.zig +++ b/test/cases/safety/switch on corrupted enum value.zig @@ -15,7 +15,7 @@ const E = enum(u32) { pub fn main() !void { var e: E = undefined; - @memset(@ptrCast([*]u8, &e)[0..@sizeOf(E)], 0x55); + @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55); switch (e) { .X, .Y => @breakpoint(), } diff --git a/test/cases/safety/switch on corrupted union value.zig b/test/cases/safety/switch on corrupted union value.zig index 745a3fd037..fc93c9d6e7 100644 --- a/test/cases/safety/switch on corrupted union value.zig +++ b/test/cases/safety/switch on corrupted union value.zig @@ -15,7 +15,7 @@ const U = union(enum(u32)) { pub fn main() !void { var u: U = undefined; - @memset(@ptrCast([*]u8, &u)[0..@sizeOf(U)], 0x55); + @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55); switch (u) { .X, .Y => @breakpoint(), } diff --git a/test/cases/safety/truncating vector cast.zig b/test/cases/safety/truncating vector cast.zig index e81a6e64ef..501bf694ac 100644 --- a/test/cases/safety/truncating vector cast.zig +++ b/test/cases/safety/truncating vector cast.zig @@ -10,7 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var x = @splat(4, @as(u32, 0xdeadbeef)); - var y = @intCast(@Vector(4, u16), x); + var y: @Vector(4, u16) = @intCast(x); _ = y; return error.TestFailed; } diff --git a/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig b/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig index f370f76557..bd35f35422 100644 --- a/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig +++ b/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig @@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var value: u8 = 245; - var casted = @intCast(i8, value); + var casted: i8 = @intCast(value); _ = casted; return error.TestFailed; } diff --git a/test/cases/safety/unsigned-signed vector cast.zig b/test/cases/safety/unsigned-signed vector cast.zig index d4b80fb05c..cf827878b6 100644 --- a/test/cases/safety/unsigned-signed vector cast.zig +++ b/test/cases/safety/unsigned-signed vector cast.zig @@ -10,7 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var x = @splat(4, @as(u32, 0x80000000)); - var y = @intCast(@Vector(4, i32), x); + var y: @Vector(4, i32) = @intCast(x); _ = y; return error.TestFailed; } diff --git a/test/cases/safety/value does not fit in shortening cast - u0.zig b/test/cases/safety/value does not fit in shortening cast - u0.zig index 9b303e5cf5..ec111a2cae 100644 --- a/test/cases/safety/value does not fit in shortening cast - u0.zig +++ b/test/cases/safety/value does not fit in shortening cast - u0.zig @@ -14,7 +14,7 @@ pub fn main() !void { return error.TestFailed; } fn shorten_cast(x: u8) u0 { - return @intCast(u0, x); + return @intCast(x); } // run // backend=llvm diff --git a/test/cases/safety/value does not fit in shortening cast.zig b/test/cases/safety/value does not fit in shortening cast.zig index 0e98a09787..a5ea41659e 100644 --- a/test/cases/safety/value does not fit in shortening cast.zig +++ b/test/cases/safety/value does not fit in shortening cast.zig @@ -14,7 +14,7 @@ pub fn main() !void { return error.TestFailed; } fn shorten_cast(x: i32) i8 { - return @intCast(i8, x); + return @intCast(x); } // run // backend=llvm diff --git a/test/cbe.zig b/test/cbe.zig index f0cf720fd3..b56202c7e5 100644 --- a/test/cbe.zig +++ b/test/cbe.zig @@ -642,7 +642,7 @@ pub fn addCases(ctx: *Cases) !void { \\pub export fn main() c_int { \\ var number1 = Number.One; \\ var number2: Number = .Two; - \\ const number3 = @enumFromInt(Number, 2); + \\ const number3: Number = @enumFromInt(2); \\ if (number1 == number2) return 1; \\ if (number2 == number3) return 1; \\ if (@intFromEnum(number1) != 0) return 1; @@ -737,19 +737,19 @@ pub fn addCases(ctx: *Cases) !void { case.addError( \\pub export fn main() c_int { \\ const a = 1; - \\ _ = @enumFromInt(bool, a); + \\ _ = @as(bool, @enumFromInt(a)); \\} , &.{ - ":3:20: error: expected enum, found 'bool'", + ":3:19: error: expected enum, found 'bool'", }); case.addError( \\const E = enum { a, b, c }; \\pub export fn main() c_int { - \\ _ = @enumFromInt(E, 3); + \\ _ = @as(E, @enumFromInt(3)); \\} , &.{ - ":3:9: error: enum 'tmp.E' has no tag with value '3'", + ":3:16: error: enum 'tmp.E' has no tag with value '3'", ":1:11: note: enum declared here", }); diff --git a/test/compare_output.zig b/test/compare_output.zig index 66b5624443..92dfd76b58 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -180,8 +180,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\const c = @cImport(@cInclude("stdlib.h")); \\ \\export fn compare_fn(a: ?*const anyopaque, b: ?*const anyopaque) c_int { - \\ const a_int = @ptrCast(*const i32, @alignCast(@alignOf(i32), a)); - \\ const b_int = @ptrCast(*const i32, @alignCast(@alignOf(i32), b)); + \\ const a_int: *const i32 = @ptrCast(@alignCast(a)); + \\ const b_int: *const i32 = @ptrCast(@alignCast(b)); \\ if (a_int.* < b_int.*) { \\ return -1; \\ } else if (a_int.* > b_int.*) { @@ -194,7 +194,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\pub export fn main() c_int { \\ var array = [_]u32{ 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 }; \\ - \\ c.qsort(@ptrCast(?*anyopaque, &array), @intCast(c_ulong, array.len), @sizeOf(i32), compare_fn); + \\ c.qsort(@ptrCast(&array), @intCast(array.len), @sizeOf(i32), compare_fn); \\ \\ for (array, 0..) |item, i| { \\ if (item != i) { @@ -229,8 +229,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ } \\ const small: f32 = 3.25; \\ const x: f64 = small; - \\ const y = @intFromFloat(i32, x); - \\ const z = @floatFromInt(f64, y); + \\ const y: i32 = @intFromFloat(x); + \\ const z: f64 = @floatFromInt(y); \\ _ = c.printf("%.2f\n%d\n%.2f\n%.2f\n", x, y, z, @as(f64, -0.4)); \\ return 0; \\} diff --git a/test/link/macho/dead_strip_dylibs/build.zig b/test/link/macho/dead_strip_dylibs/build.zig index ec073e183a..c226e03196 100644 --- a/test/link/macho/dead_strip_dylibs/build.zig +++ b/test/link/macho/dead_strip_dylibs/build.zig @@ -37,7 +37,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize exe.dead_strip_dylibs = true; const run_cmd = b.addRunArtifact(exe); - run_cmd.expectExitCode(@bitCast(u8, @as(i8, -2))); // should fail + run_cmd.expectExitCode(@as(u8, @bitCast(@as(i8, -2)))); // should fail test_step.dependOn(&run_cmd.step); } } diff --git a/test/nvptx.zig b/test/nvptx.zig index 0bdc9455f7..c3748570e8 100644 --- a/test/nvptx.zig +++ b/test/nvptx.zig @@ -60,7 +60,7 @@ pub fn addCases(ctx: *Cases) !void { \\ \\ var _sdata: [1024]f32 addrspace(.shared) = undefined; \\ pub export fn reduceSum(d_x: []const f32, out: *f32) callconv(.Kernel) void { - \\ var sdata = @addrSpaceCast(.generic, &_sdata); + \\ var sdata: *addrspace(.generic) [1024]f32 = @addrSpaceCast(&_sdata); \\ const tid: u32 = threadIdX(); \\ var sum = d_x[tid]; \\ sdata[tid] = sum; diff --git a/test/standalone/hello_world/hello_libc.zig b/test/standalone/hello_world/hello_libc.zig index 42ba4db4b1..992afd736e 100644 --- a/test/standalone/hello_world/hello_libc.zig +++ b/test/standalone/hello_world/hello_libc.zig @@ -10,6 +10,6 @@ const msg = "Hello, world!\n"; pub export fn main(argc: c_int, argv: **u8) c_int { _ = argv; _ = argc; - if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1; + if (c.printf(msg) != @as(c_int, @intCast(c.strlen(msg)))) return -1; return 0; } diff --git a/test/standalone/issue_11595/main.zig b/test/standalone/issue_11595/main.zig index b91f54cb9c..12aa6ac3cd 100644 --- a/test/standalone/issue_11595/main.zig +++ b/test/standalone/issue_11595/main.zig @@ -1,5 +1,5 @@ extern fn check() c_int; pub fn main() u8 { - return @intCast(u8, check()); + return @as(u8, @intCast(check())); } diff --git a/test/standalone/main_return_error/error_u8_non_zero.zig b/test/standalone/main_return_error/error_u8_non_zero.zig index 9f7de780ac..c45458fb21 100644 --- a/test/standalone/main_return_error/error_u8_non_zero.zig +++ b/test/standalone/main_return_error/error_u8_non_zero.zig @@ -1,7 +1,7 @@ const Err = error{Foo}; fn foo() u8 { - var x = @intCast(u8, 9); + var x = @as(u8, @intCast(9)); return x; } diff --git a/test/standalone/mix_c_files/main.zig b/test/standalone/mix_c_files/main.zig index 913d284fe9..d755ada04c 100644 --- a/test/standalone/mix_c_files/main.zig +++ b/test/standalone/mix_c_files/main.zig @@ -25,6 +25,6 @@ pub fn main() anyerror!void { x = add_C(x); x = add_C_zig(x); - const u = @intCast(u32, x); + const u = @as(u32, @intCast(x)); try std.testing.expect(u / 100 == u % 100); } diff --git a/test/standalone/pie/main.zig b/test/standalone/pie/main.zig index 89d204aa1c..edf6a3fcaa 100644 --- a/test/standalone/pie/main.zig +++ b/test/standalone/pie/main.zig @@ -5,7 +5,7 @@ threadlocal var foo: u8 = 42; test "Check ELF header" { // PIE executables are marked as ET_DYN, regular exes as ET_EXEC. - const header = @ptrFromInt(*elf.Ehdr, std.process.getBaseAddress()); + const header = @as(*elf.Ehdr, @ptrFromInt(std.process.getBaseAddress())); try std.testing.expectEqual(elf.ET.DYN, header.e_type); } diff --git a/test/translate_c.zig b/test/translate_c.zig index 966f3e2785..40edec57f7 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -351,7 +351,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} , &[_][]const u8{ \\pub export fn main() void { - \\ var a: c_int = @bitCast(c_int, @truncate(c_uint, @alignOf(c_int))); + \\ var a: c_int = @as(c_int, @bitCast(@as(c_uint, @truncate(@alignOf(c_int))))); \\ _ = @TypeOf(a); \\} }); @@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) { \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8); \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int); - \\ return @ptrCast(ReturnType, @alignCast(@alignOf(c_int), @ptrCast(Intermediate, self) + 4)); + \\ return @as(ReturnType, @ptrCast(@alignCast(@as(Intermediate, @ptrCast(self)) + 4))); \\ } \\}; \\pub const struct_bar = extern struct { @@ -473,7 +473,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) { \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8); \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int); - \\ return @ptrCast(ReturnType, @alignCast(@alignOf(c_int), @ptrCast(Intermediate, self) + 4)); + \\ return @as(ReturnType, @ptrCast(@alignCast(@as(Intermediate, @ptrCast(self)) + 4))); \\ } \\}; }); @@ -635,7 +635,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\}; \\pub export fn foo(arg_x: [*c]outer) void { \\ var x = arg_x; - \\ x.*.unnamed_0.unnamed_0.y = @bitCast(c_int, @as(c_uint, x.*.unnamed_0.x)); + \\ x.*.unnamed_0.unnamed_0.y = @as(c_int, @bitCast(@as(c_uint, x.*.unnamed_0.x))); \\} }); @@ -721,7 +721,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const struct_opaque_2 = opaque {}; \\pub export fn function(arg_opaque_1: ?*struct_opaque) void { \\ var opaque_1 = arg_opaque_1; - \\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1); + \\ var cast: ?*struct_opaque_2 = @as(?*struct_opaque_2, @ptrCast(opaque_1)); \\ _ = @TypeOf(cast); \\} }); @@ -799,7 +799,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ _ = @TypeOf(b); \\ const c: c_int = undefined; \\ _ = @TypeOf(c); - \\ const d: c_uint = @bitCast(c_uint, @as(c_int, 440)); + \\ const d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440))); \\ _ = @TypeOf(d); \\ var e: c_int = 10; \\ _ = @TypeOf(e); @@ -904,8 +904,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub extern fn foo() void; \\pub export fn bar() void { - \\ var func_ptr: ?*anyopaque = @ptrCast(?*anyopaque, &foo); - \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @ptrFromInt(?*const fn () callconv(.C) void, @intCast(c_ulong, @intFromPtr(func_ptr))); + \\ var func_ptr: ?*anyopaque = @as(?*anyopaque, @ptrCast(&foo)); + \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @as(?*const fn () callconv(.C) void, @ptrFromInt(@as(c_ulong, @intCast(@intFromPtr(func_ptr))))); \\ _ = @TypeOf(typed_func_ptr); \\} }); @@ -1353,7 +1353,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() ?*anyopaque { \\ var x: [*c]c_ushort = undefined; - \\ return @ptrCast(?*anyopaque, x); + \\ return @as(?*anyopaque, @ptrCast(x)); \\} }); @@ -1543,7 +1543,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn ptrcast() [*c]f32 { \\ var a: [*c]c_int = undefined; - \\ return @ptrCast([*c]f32, @alignCast(@import("std").meta.alignment([*c]f32), a)); + \\ return @as([*c]f32, @ptrCast(@alignCast(a))); \\} }); @@ -1555,7 +1555,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn ptrptrcast() [*c][*c]f32 { \\ var a: [*c][*c]c_int = undefined; - \\ return @ptrCast([*c][*c]f32, @alignCast(@import("std").meta.alignment([*c][*c]f32), a)); + \\ return @as([*c][*c]f32, @ptrCast(@alignCast(a))); \\} }); @@ -1579,23 +1579,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn test_ptr_cast() void { \\ var p: ?*anyopaque = undefined; \\ { - \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment([*c]u8), p)); + \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p))); \\ _ = @TypeOf(to_char); - \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment([*c]c_short), p)); + \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p))); \\ _ = @TypeOf(to_short); - \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment([*c]c_int), p)); + \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p))); \\ _ = @TypeOf(to_int); - \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment([*c]c_longlong), p)); + \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p))); \\ _ = @TypeOf(to_longlong); \\ } \\ { - \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment([*c]u8), p)); + \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p))); \\ _ = @TypeOf(to_char); - \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment([*c]c_short), p)); + \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p))); \\ _ = @TypeOf(to_short); - \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment([*c]c_int), p)); + \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p))); \\ _ = @TypeOf(to_int); - \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment([*c]c_longlong), p)); + \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p))); \\ _ = @TypeOf(to_longlong); \\ } \\} @@ -1651,7 +1651,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} , &[_][]const u8{ \\pub export fn foo() c_int { - \\ return (@as(c_int, 1) << @intCast(@import("std").math.Log2Int(c_int), 2)) >> @intCast(@import("std").math.Log2Int(c_int), 1); + \\ return (@as(c_int, 1) << @intCast(2)) >> @intCast(1); \\} }); @@ -1885,7 +1885,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\const enum_unnamed_1 = ++ " " ++ default_enum_type ++ \\; - \\pub export var h: enum_unnamed_1 = @bitCast(c_uint, e); + \\pub export var h: enum_unnamed_1 = @as(c_uint, @bitCast(e)); \\pub const i: c_int = 0; \\pub const j: c_int = 1; \\pub const k: c_int = 2; @@ -2091,12 +2091,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ _ = @TypeOf(c_1); \\ var a_2: c_int = undefined; \\ var b_3: u8 = 123; - \\ b_3 = @bitCast(u8, @truncate(i8, a_2)); + \\ b_3 = @as(u8, @bitCast(@as(i8, @truncate(a_2)))); \\ { \\ var d: c_int = 5; \\ _ = @TypeOf(d); \\ } - \\ var d: c_uint = @bitCast(c_uint, @as(c_int, 440)); + \\ var d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440))); \\ _ = @TypeOf(d); \\} }); @@ -2236,9 +2236,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\int c = 3.1415; \\double d = 3; , &[_][]const u8{ - \\pub export var a: f32 = @floatCast(f32, 3.1415); + \\pub export var a: f32 = @as(f32, @floatCast(3.1415)); \\pub export var b: f64 = 3.1415; - \\pub export var c: c_int = @intFromFloat(c_int, 3.1415); + \\pub export var c: c_int = @as(c_int, @intFromFloat(3.1415)); \\pub export var d: f64 = 3; }); @@ -2423,7 +2423,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn int_from_float(arg_a: f32) c_int { \\ var a = arg_a; - \\ return @intFromFloat(c_int, a); + \\ return @as(c_int, @intFromFloat(a)); \\} }); @@ -2533,15 +2533,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ var a = arg_a; \\ var b = arg_b; \\ var c = arg_c; - \\ var d: enum_Foo = @bitCast(c_uint, FooA); + \\ var d: enum_Foo = @as(c_uint, @bitCast(FooA)); \\ var e: c_int = @intFromBool((a != 0) and (b != 0)); \\ var f: c_int = @intFromBool((b != 0) and (c != null)); \\ var g: c_int = @intFromBool((a != 0) and (c != null)); \\ var h: c_int = @intFromBool((a != 0) or (b != 0)); \\ var i: c_int = @intFromBool((b != 0) or (c != null)); \\ var j: c_int = @intFromBool((a != 0) or (c != null)); - \\ var k: c_int = @intFromBool((a != 0) or (@bitCast(c_int, d) != 0)); - \\ var l: c_int = @intFromBool((@bitCast(c_int, d) != 0) and (b != 0)); + \\ var k: c_int = @intFromBool((a != 0) or (@as(c_int, @bitCast(d)) != 0)); + \\ var l: c_int = @intFromBool((@as(c_int, @bitCast(d)) != 0) and (b != 0)); \\ var m: c_int = @intFromBool((c != null) or (d != 0)); \\ var td: SomeTypedef = 44; \\ var o: c_int = @intFromBool((td != 0) or (b != 0)); @@ -2707,10 +2707,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export var array: [100]c_int = [1]c_int{0} ** 100; \\pub export fn foo(arg_index: c_int) c_int { \\ var index = arg_index; - \\ return array[@intCast(c_uint, index)]; + \\ return array[@as(c_uint, @intCast(index))]; \\} , - \\pub const ACCESS = array[@intCast(usize, @as(c_int, 2))]; + \\pub const ACCESS = array[@as(usize, @intCast(@as(c_int, 2)))]; }); cases.add("cast signed array index to unsigned", @@ -2722,7 +2722,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() void { \\ var a: [10]c_int = undefined; \\ var i: c_int = 0; - \\ a[@intCast(c_uint, i)] = 0; + \\ a[@as(c_uint, @intCast(i))] = 0; \\} }); @@ -2735,7 +2735,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() void { \\ var a: [10]c_longlong = undefined; \\ var i: c_longlong = 0; - \\ a[@intCast(usize, i)] = 0; + \\ a[@as(usize, @intCast(i))] = 0; \\} }); @@ -3006,8 +3006,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn log2(arg_a: c_uint) c_int { \\ var a = arg_a; \\ var i: c_int = 0; - \\ while (a > @bitCast(c_uint, @as(c_int, 0))) { - \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); + \\ while (a > @as(c_uint, @bitCast(@as(c_int, 0)))) { + \\ a >>= @intCast(@as(c_int, 1)); \\ } \\ return i; \\} @@ -3026,8 +3026,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn log2(arg_a: u32) c_int { \\ var a = arg_a; \\ var i: c_int = 0; - \\ while (a > @bitCast(u32, @as(c_int, 0))) { - \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); + \\ while (a > @as(u32, @bitCast(@as(c_int, 0)))) { + \\ a >>= @intCast(@as(c_int, 1)); \\ } \\ return i; \\} @@ -3084,14 +3084,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ ref.* ^= @as(c_int, 1); \\ break :blk ref.*; \\ }; - \\ a >>= @intCast(@import("std").math.Log2Int(c_int), blk: { + \\ a >>= @intCast(blk: { \\ const ref = &a; - \\ ref.* >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); + \\ ref.* >>= @intCast(@as(c_int, 1)); \\ break :blk ref.*; \\ }); - \\ a <<= @intCast(@import("std").math.Log2Int(c_int), blk: { + \\ a <<= @intCast(blk: { \\ const ref = &a; - \\ ref.* <<= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); + \\ ref.* <<= @intCast(@as(c_int, 1)); \\ break :blk ref.*; \\ }); \\ a = @divTrunc(a, blk: { @@ -3106,12 +3106,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ }); \\ b /= blk: { \\ const ref = &b; - \\ ref.* /= @bitCast(c_uint, @as(c_int, 1)); + \\ ref.* /= @as(c_uint, @bitCast(@as(c_int, 1))); \\ break :blk ref.*; \\ }; \\ b %= blk: { \\ const ref = &b; - \\ ref.* %= @bitCast(c_uint, @as(c_int, 1)); + \\ ref.* %= @as(c_uint, @bitCast(@as(c_int, 1))); \\ break :blk ref.*; \\ }; \\} @@ -3134,42 +3134,42 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ var a: c_uint = 0; \\ a +%= blk: { \\ const ref = &a; - \\ ref.* +%= @bitCast(c_uint, @as(c_int, 1)); + \\ ref.* +%= @as(c_uint, @bitCast(@as(c_int, 1))); \\ break :blk ref.*; \\ }; \\ a -%= blk: { \\ const ref = &a; - \\ ref.* -%= @bitCast(c_uint, @as(c_int, 1)); + \\ ref.* -%= @as(c_uint, @bitCast(@as(c_int, 1))); \\ break :blk ref.*; \\ }; \\ a *%= blk: { \\ const ref = &a; - \\ ref.* *%= @bitCast(c_uint, @as(c_int, 1)); + \\ ref.* *%= @as(c_uint, @bitCast(@as(c_int, 1))); \\ break :blk ref.*; \\ }; \\ a &= blk: { \\ const ref = &a; - \\ ref.* &= @bitCast(c_uint, @as(c_int, 1)); + \\ ref.* &= @as(c_uint, @bitCast(@as(c_int, 1))); \\ break :blk ref.*; \\ }; \\ a |= blk: { \\ const ref = &a; - \\ ref.* |= @bitCast(c_uint, @as(c_int, 1)); + \\ ref.* |= @as(c_uint, @bitCast(@as(c_int, 1))); \\ break :blk ref.*; \\ }; \\ a ^= blk: { \\ const ref = &a; - \\ ref.* ^= @bitCast(c_uint, @as(c_int, 1)); + \\ ref.* ^= @as(c_uint, @bitCast(@as(c_int, 1))); \\ break :blk ref.*; \\ }; - \\ a >>= @intCast(@import("std").math.Log2Int(c_uint), blk: { + \\ a >>= @intCast(blk: { \\ const ref = &a; - \\ ref.* >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); + \\ ref.* >>= @intCast(@as(c_int, 1)); \\ break :blk ref.*; \\ }); - \\ a <<= @intCast(@import("std").math.Log2Int(c_uint), blk: { + \\ a <<= @intCast(blk: { \\ const ref = &a; - \\ ref.* <<= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1)); + \\ ref.* <<= @intCast(@as(c_int, 1)); \\ break :blk ref.*; \\ }); \\} @@ -3258,21 +3258,21 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub extern fn fn_bool(x: bool) void; \\pub extern fn fn_ptr(x: ?*anyopaque) void; \\pub export fn call() void { - \\ fn_int(@intFromFloat(c_int, 3.0)); - \\ fn_int(@intFromFloat(c_int, 3.0)); + \\ fn_int(@as(c_int, @intFromFloat(3.0))); + \\ fn_int(@as(c_int, @intFromFloat(3.0))); \\ fn_int(@as(c_int, 1094861636)); - \\ fn_f32(@floatFromInt(f32, @as(c_int, 3))); - \\ fn_f64(@floatFromInt(f64, @as(c_int, 3))); - \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '3')))); - \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '\x01')))); - \\ fn_char(@bitCast(u8, @truncate(i8, @as(c_int, 0)))); + \\ fn_f32(@as(f32, @floatFromInt(@as(c_int, 3)))); + \\ fn_f64(@as(f64, @floatFromInt(@as(c_int, 3)))); + \\ fn_char(@as(u8, @bitCast(@as(i8, @truncate(@as(c_int, '3')))))); + \\ fn_char(@as(u8, @bitCast(@as(i8, @truncate(@as(c_int, '\x01')))))); + \\ fn_char(@as(u8, @bitCast(@as(i8, @truncate(@as(c_int, 0)))))); \\ fn_f32(3.0); \\ fn_f64(3.0); \\ fn_bool(@as(c_int, 123) != 0); \\ fn_bool(@as(c_int, 0) != 0); \\ fn_bool(@intFromPtr(&fn_int) != 0); - \\ fn_int(@intCast(c_int, @intFromPtr(&fn_int))); - \\ fn_ptr(@ptrFromInt(?*anyopaque, @as(c_int, 42))); + \\ fn_int(@as(c_int, @intCast(@intFromPtr(&fn_int)))); + \\ fn_ptr(@as(?*anyopaque, @ptrFromInt(@as(c_int, 42)))); \\} }); @@ -3411,11 +3411,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} , &[_][]const u8{ \\pub export fn foo() c_ulong { - \\ return @bitCast(c_ulong, @as(c_long, -@as(c_int, 1))); + \\ return @as(c_ulong, @bitCast(@as(c_long, -@as(c_int, 1)))); \\} \\pub export fn bar(arg_x: c_long) c_ushort { \\ var x = arg_x; - \\ return @bitCast(c_ushort, @truncate(c_short, x)); + \\ return @as(c_ushort, @bitCast(@as(c_short, @truncate(x)))); \\} }); @@ -3473,11 +3473,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} \\pub export fn bar(arg_a: [*c]const c_int) void { \\ var a = arg_a; - \\ foo(@ptrFromInt([*c]c_int, @intFromPtr(a))); + \\ foo(@as([*c]c_int, @ptrFromInt(@intFromPtr(a)))); \\} \\pub export fn baz(arg_a: [*c]volatile c_int) void { \\ var a = arg_a; - \\ foo(@ptrFromInt([*c]c_int, @intFromPtr(a))); + \\ foo(@as([*c]c_int, @ptrFromInt(@intFromPtr(a)))); \\} }); @@ -3860,9 +3860,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ p[1]; \\} , &[_][]const u8{ - \\_ = p[@intCast(c_uint, @as(c_int, 0))]; + \\_ = p[@as(c_uint, @intCast(@as(c_int, 0)))]; , - \\_ = p[@intCast(c_uint, @as(c_int, 1))]; + \\_ = p[@as(c_uint, @intCast(@as(c_int, 1)))]; }); cases.add("Undefined macro identifier", @@ -3928,7 +3928,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() void { \\ var a: S = undefined; \\ var b: S = undefined; - \\ var c: c_longlong = @divExact(@bitCast(c_longlong, @intFromPtr(a) -% @intFromPtr(b)), @sizeOf(u8)); + \\ var c: c_longlong = @divExact(@as(c_longlong, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8)); \\ _ = @TypeOf(c); \\} }); @@ -3943,7 +3943,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() void { \\ var a: S = undefined; \\ var b: S = undefined; - \\ var c: c_long = @divExact(@bitCast(c_long, @intFromPtr(a) -% @intFromPtr(b)), @sizeOf(u8)); + \\ var c: c_long = @divExact(@as(c_long, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8)); \\ _ = @TypeOf(c); \\} }); |
