diff --git a/test/behavior/abs.zig b/test/behavior/abs.zig index 51ade3dbcf..fad29a1a58 100644 --- a/test/behavior/abs.zig +++ b/test/behavior/abs.zig @@ -16,26 +16,32 @@ test "@abs integers" { fn testAbsIntegers() !void { { var x: i32 = -1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: i32 = 0; + _ = &x; try expect(@abs(x) == 0); } { var x: i32 = 1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: i64 = std.math.minInt(i64); + _ = &x; try expect(@abs(x) == @as(u64, -std.math.minInt(i64))); } { var x: i5 = -1; + _ = &x; try expect(@abs(x) == 1); } { var x: i5 = -5; + _ = &x; try expect(@abs(x) == 5); } comptime { @@ -56,22 +62,27 @@ test "@abs unsigned integers" { fn testAbsUnsignedIntegers() !void { { var x: u32 = 1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: u32 = 0; + _ = &x; try expect(@abs(x) == 0); } { var x: u32 = 1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: u5 = 1; + _ = &x; try expect(@abs(x) == 1); } { var x: u5 = 5; + _ = &x; try expect(@abs(x) == 5); } comptime { @@ -102,27 +113,33 @@ test "@abs floats" { fn testAbsFloats(comptime T: type) !void { { var x: T = -2.62; + _ = &x; try expect(@abs(x) == 2.62); } { var x: T = 2.62; + _ = &x; try expect(@abs(x) == 2.62); } { var x: T = 0.0; + _ = &x; try expect(@abs(x) == 0.0); } { var x: T = -std.math.pi; + _ = &x; try expect(@abs(x) == std.math.pi); } { var x: T = -std.math.inf(T); + _ = &x; try expect(@abs(x) == std.math.inf(T)); } { var x: T = std.math.inf(T); + _ = &x; try expect(@abs(x) == std.math.inf(T)); } comptime { @@ -164,31 +181,37 @@ fn testAbsIntVectors(comptime len: comptime_int) !void { { var x: I32 = @splat(-10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: I32 = @splat(10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: I32 = @splat(0); var y: U32 = @splat(0); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: I64 = @splat(-10); var y: U64 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); } { var x: I64 = @splat(std.math.minInt(i64)); var y: U64 = @splat(-std.math.minInt(i64)); + _ = .{ &x, &y }; try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); } { var x = std.simd.repeat(len, @Vector(4, i32){ -2, 5, std.math.minInt(i32), -7 }); var y = std.simd.repeat(len, @Vector(4, u32){ 2, 5, -std.math.minInt(i32), 7 }); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } } @@ -225,26 +248,31 @@ fn testAbsUnsignedIntVectors(comptime len: comptime_int) !void { { var x: U32 = @splat(10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: U32 = @splat(10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: U32 = @splat(0); var y: U32 = @splat(0); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: U64 = @splat(10); var y: U64 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); } { var x = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); var y = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } } @@ -346,26 +374,31 @@ fn testAbsFloatVectors(comptime T: type, comptime len: comptime_int) !void { { var x: V = @splat(-7.5); var y: V = @splat(7.5); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(7.5); var y: V = @splat(7.5); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(0.0); var y: V = @splat(0.0); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(-std.math.pi); var y: V = @splat(std.math.pi); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(std.math.pi); var y: V = @splat(std.math.pi); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } } diff --git a/test/behavior/align.zig b/test/behavior/align.zig index 7b95cf8a56..4458bc49e9 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -29,6 +29,7 @@ test "slicing array of length 1 can not assume runtime index is always zero" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var runtime_index: usize = 1; + _ = &runtime_index; const slice = @as(*align(4) [1]u8, &foo)[runtime_index..]; try expect(@TypeOf(slice) == []u8); try expect(slice.len == 0); @@ -438,6 +439,7 @@ test "runtime-known array index has best alignment possible" { // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2 var smaller align(2) = [_]u32{ 1, 2, 3, 4 }; var runtime_zero: usize = 0; + _ = &runtime_zero; comptime assert(@TypeOf(smaller[runtime_zero..]) == []align(2) u32); comptime assert(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32); try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32); @@ -464,6 +466,7 @@ test "alignment of function with c calling convention" { const a = @alignOf(@TypeOf(nothing)); var runtime_nothing = ¬hing; + _ = &runtime_nothing; const casted1: *align(a) const u8 = @ptrCast(runtime_nothing); const casted2: *const fn () callconv(.C) void = @ptrCast(casted1); casted2(); @@ -486,6 +489,7 @@ test "read 128-bit field from default aligned struct in stack memory" { .nevermind = 1, .badguy = 12, }; + _ = &default_aligned; try expect(12 == default_aligned.badguy); } @@ -579,10 +583,10 @@ test "comptime alloc alignment" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; comptime var bytes1 = [_]u8{0}; - _ = bytes1; + _ = &bytes1; comptime var bytes2 align(256) = [_]u8{0}; - var bytes2_addr = @intFromPtr(&bytes2); + const bytes2_addr = @intFromPtr(&bytes2); try expect(bytes2_addr & 0xff == 0); } @@ -591,6 +595,7 @@ test "@alignCast null" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var ptr: ?*anyopaque = null; + _ = &ptr; const aligned: ?*anyopaque = @alignCast(ptr); try expect(aligned == null); } @@ -637,6 +642,7 @@ test "alignment of zero-bit types is respected" { var s32: S align(32) = .{}; var zero: usize = 0; + _ = &zero; try expect(@intFromPtr(&s) % @alignOf(usize) == 0); try expect(@intFromPtr(&s.arr) % @alignOf(usize) == 0); diff --git a/test/behavior/alignof.zig b/test/behavior/alignof.zig index 0443b2d6b3..81d1e49fdf 100644 --- a/test/behavior/alignof.zig +++ b/test/behavior/alignof.zig @@ -31,6 +31,7 @@ test "correct alignment for elements and slices of aligned array" { var buf: [1024]u8 align(64) = undefined; var start: usize = 1; var end: usize = undefined; + _ = .{ &start, &end }; try expect(@alignOf(@TypeOf(buf[start..end])) == @alignOf(*u8)); try expect(@alignOf(@TypeOf(&buf[start..end])) == @alignOf(*u8)); try expect(@alignOf(@TypeOf(&buf[start])) == @alignOf(*u8)); diff --git a/test/behavior/array.zig b/test/behavior/array.zig index 2586770c6f..e9a7f4b9c0 100644 --- a/test/behavior/array.zig +++ b/test/behavior/array.zig @@ -138,6 +138,7 @@ test "array literal with specified size" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var array = [2]u8{ 1, 2 }; + _ = &array; try expect(array[0] == 1); try expect(array[1] == 2); } @@ -146,7 +147,7 @@ test "array len field" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var arr = [4]u8{ 0, 0, 0, 0 }; - var ptr = &arr; + const ptr = &arr; try expect(arr.len == 4); try comptime expect(arr.len == 4); try expect(ptr.len == 4); @@ -163,7 +164,8 @@ test "array with sentinels" { { var zero_sized: [0:0xde]u8 = [_:0xde]u8{}; try expect(zero_sized[0] == 0xde); - var reinterpreted = @as(*[1]u8, @ptrCast(&zero_sized)); + var reinterpreted: *[1]u8 = @ptrCast(&zero_sized); + _ = &reinterpreted; try expect(reinterpreted[0] == 0xde); } var arr: [3:0x55]u8 = undefined; @@ -225,6 +227,7 @@ test "implicit comptime in array type size" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var arr: [plusOne(10)]bool = undefined; + _ = &arr; try expect(arr.len == 11); } @@ -281,6 +284,7 @@ test "anonymous list literal syntax" { const S = struct { fn doTheTest() !void { var array: [4]u8 = .{ 1, 2, 3, 4 }; + _ = &array; try expect(array[0] == 1); try expect(array[1] == 2); try expect(array[2] == 3); @@ -365,6 +369,7 @@ test "runtime initialize array elem and then implicit cast to slice" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var two: i32 = 2; + _ = &two; const x: []const i32 = &[_]i32{two}; try expect(x[0] == 2); } @@ -472,6 +477,7 @@ test "anonymous literal in array" { .{ .a = 3 }, .{ .b = 3 }, }; + _ = &array; try expect(array[0].a == 3); try expect(array[0].b == 4); try expect(array[1].a == 2); @@ -489,8 +495,10 @@ test "access the null element of a null terminated array" { const S = struct { fn doTheTest() !void { var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' }; + _ = &array; try expect(array[4] == 0); var len: usize = 4; + _ = &len; try expect(array[len] == 0); } }; @@ -510,6 +518,7 @@ test "type deduction for array subscript expression" { try expect(@as(u8, 0xAA) == array[if (v0) 1 else 0]); var v1 = false; try expect(@as(u8, 0x55) == array[if (v1) 1 else 0]); + _ = .{ &array, &v0, &v1 }; } }; try S.doTheTest(); @@ -529,7 +538,7 @@ test "sentinel element count towards the ABI size calculation" { fill_post: u8 = 0xAA, }; var x = T{}; - var as_slice = mem.asBytes(&x); + const as_slice = mem.asBytes(&x); try expect(@as(usize, 3) == as_slice.len); try expect(@as(u8, 0x55) == as_slice[0]); try expect(@as(u8, 0xAA) == as_slice[2]); @@ -559,6 +568,7 @@ test "zero-sized array with recursive type definition" { }; var t: S = .{ .list = .{ .s = undefined } }; + _ = &t; try expect(@as(usize, 0) == t.list.x); } @@ -576,15 +586,17 @@ test "type coercion of anon struct literal to array" { fn doTheTest() !void { var x1: u8 = 42; + _ = &x1; const t1 = .{ x1, 56, 54 }; - var arr1: [3]u8 = t1; + const arr1: [3]u8 = t1; try expect(arr1[0] == 42); try expect(arr1[1] == 56); try expect(arr1[2] == 54); var x2: U = .{ .a = 42 }; + _ = &x2; const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } }; - var arr2: [3]U = t2; + const arr2: [3]U = t2; try expect(arr2[0].a == 42); try expect(arr2[1].b == true); try expect(mem.eql(u8, arr2[2].c, "hello")); @@ -608,15 +620,17 @@ test "type coercion of pointer to anon struct literal to pointer to array" { fn doTheTest() !void { var x1: u8 = 42; + _ = &x1; const t1 = &.{ x1, 56, 54 }; - var arr1: *const [3]u8 = t1; + const arr1: *const [3]u8 = t1; try expect(arr1[0] == 42); try expect(arr1[1] == 56); try expect(arr1[2] == 54); var x2: U = .{ .a = 42 }; + _ = &x2; const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } }; - var arr2: *const [3]U = t2; + const arr2: *const [3]U = t2; try expect(arr2[0].a == 42); try expect(arr2[1].b == true); try expect(mem.eql(u8, arr2[2].c, "hello")); @@ -656,6 +670,7 @@ test "array init of container level array variable" { } noinline fn bar(x: usize, y: usize) void { var tmp: [2]usize = .{ x, y }; + _ = &tmp; pair = tmp; } }; @@ -668,6 +683,7 @@ test "array init of container level array variable" { test "runtime initialized sentinel-terminated array literal" { var c: u16 = 300; + _ = &c; const f = &[_:0x9999]u16{c}; const g = @as(*const [4]u8, @ptrCast(f)); try std.testing.expect(g[2] == 0x99); @@ -681,6 +697,7 @@ test "array of array agregate init" { var a = [1]u32{11} ** 10; var b = [1][10]u32{a} ** 2; + _ = .{ &a, &b }; try std.testing.expect(b[1][1] == 11); } @@ -778,6 +795,7 @@ test "runtime side-effects in comptime-known array init" { test "slice initialized through reference to anonymous array init provides result types" { var my_u32: u32 = 123; var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; const foo: []const u16 = &.{ @intCast(my_u32), @intCast(my_u64), @@ -790,6 +808,7 @@ test "slice initialized through reference to anonymous array init provides resul test "pointer to array initialized through reference to anonymous array init provides result types" { var my_u32: u32 = 123; var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; const foo: *const [4]u16 = &.{ @intCast(my_u32), @intCast(my_u64), diff --git a/test/behavior/asm.zig b/test/behavior/asm.zig index ca7497225e..acb17ea004 100644 --- a/test/behavior/asm.zig +++ b/test/behavior/asm.zig @@ -180,6 +180,7 @@ test "asm modifiers (AArch64)" { if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly var x: u32 = 15; + _ = &x; const double = asm ("add %[ret:w], %[in:w], %[in:w]" : [ret] "=r" (-> u32), : [in] "r" (x), diff --git a/test/behavior/async_fn.zig b/test/behavior/async_fn.zig index 7eaa5c78d0..a8efbcfa8c 100644 --- a/test/behavior/async_fn.zig +++ b/test/behavior/async_fn.zig @@ -137,11 +137,13 @@ test "@frameSize" { fn doTheTest() !void { { var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other)); + _ = &ptr; const size = @frameSize(ptr); try expect(size == @sizeOf(@Frame(other))); } { var ptr = @as(fn () callconv(.Async) void, @ptrCast(first)); + _ = &ptr; const size = @frameSize(ptr); try expect(size == @sizeOf(@Frame(first))); } @@ -153,7 +155,7 @@ test "@frameSize" { fn other(param: i32) void { _ = param; var local: i32 = undefined; - _ = local; + _ = &local; suspend {} } }; @@ -239,7 +241,7 @@ test "coroutine await" { await_seq('a'); var p = async await_amain(); - _ = p; + _ = &p; await_seq('f'); resume await_a_promise; await_seq('i'); @@ -279,7 +281,7 @@ test "coroutine await early return" { early_seq('a'); var p = async early_amain(); - _ = p; + _ = &p; early_seq('f'); try expect(early_final_result == 1234); try expect(std.mem.eql(u8, &early_points, "abcdef")); @@ -329,6 +331,7 @@ test "async fn pointer in a struct field" { bar: fn (*i32) callconv(.Async) void, }; var foo = Foo{ .bar = simpleAsyncFn2 }; + _ = &foo; var bytes: [64]u8 align(16) = undefined; const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); try comptime expect(@TypeOf(f) == anyframe->void); @@ -367,6 +370,7 @@ test "@asyncCall with return type" { } }; var foo = Foo{ .bar = Foo.middle }; + _ = &foo; var bytes: [150]u8 align(16) = undefined; var aresult: i32 = 0; _ = @asyncCall(&bytes, &aresult, foo.bar, .{}); @@ -385,6 +389,7 @@ test "async fn with inferred error set" { fn doTheTest() !void { var frame: [1]@Frame(middle) = undefined; var fn_ptr = middle; + _ = &fn_ptr; var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined; _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{}); resume global_frame; @@ -827,7 +832,7 @@ test "alignment of local variables in async functions" { const S = struct { fn doTheTest() !void { var y: u8 = 123; - _ = y; + _ = &y; var x: u8 align(128) = 1; try expect(@intFromPtr(&x) % 128 == 0); } @@ -843,7 +848,7 @@ test "no reason to resolve frame still works" { } fn simpleNothing() void { var x: i32 = 1234; - _ = x; + _ = &x; } test "async call a generic function" { @@ -913,13 +918,14 @@ test "struct parameter to async function is copied to the frame" { if (x == 0) return; clobberStack(x - 1); var y: i32 = x; - _ = y; + _ = &y; } fn bar(f: *@Frame(foo)) void { var pt = Point{ .x = 1, .y = 2 }; + _ = &pt; f.* = async foo(pt); - var result = await f; + const result = await f; expect(result == 1) catch @panic("test failure"); } @@ -1141,6 +1147,7 @@ test "@asyncCall using the result location inside the frame" { bar: fn (*i32) callconv(.Async) i32, }; var foo = Foo{ .bar = S.simple2 }; + _ = &foo; var bytes: [64]u8 align(16) = undefined; const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); try comptime expect(@TypeOf(f) == anyframe->i32); @@ -1465,7 +1472,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" { // the for loop spills still happen even though there is a VarDecl in scope // before the suspend. var anything = true; - _ = anything; + _ = &anything; suspend { global_frame = @frame(); } @@ -1538,6 +1545,7 @@ test "async function passed align(16) arg after align(8) arg" { fn foo() void { var a: u128 = 99; + _ = &a; bar(10, .{a}) catch unreachable; } @@ -1590,6 +1598,7 @@ test "async function call resolves target fn frame, runtime func" { const stack_size = 1000; var stack_frame: [stack_size]u8 align(std.Target.stack_align) = undefined; var func: fn () callconv(.Async) anyerror!void = bar; + _ = &func; return await @asyncCall(&stack_frame, {}, func, .{}); } @@ -1614,6 +1623,7 @@ test "properly spill optional payload capture value" { fn foo() void { var opt: ?usize = 1234; + _ = &opt; if (opt) |x| { bar(); global_int += x; @@ -1863,6 +1873,7 @@ test "@asyncCall with pass-by-value arguments" { var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; // The function pointer must not be comptime-known. var t = S.f; + _ = &t; var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, .{ .f0 = 1, .f1 = 2 }, @@ -1870,7 +1881,7 @@ test "@asyncCall with pass-by-value arguments" { [_]u8{ 1, 2, 3, 4, 5 }, F2, }); - _ = frame_ptr; + _ = &frame_ptr; } test "@asyncCall with arguments having non-standard alignment" { @@ -1893,6 +1904,7 @@ test "@asyncCall with arguments having non-standard alignment" { var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; // The function pointer must not be comptime-known. var t = S.f; + _ = &t; var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 }); - _ = frame_ptr; + _ = &frame_ptr; } diff --git a/test/behavior/await_struct.zig b/test/behavior/await_struct.zig index bc1420f96a..4175a90cd9 100644 --- a/test/behavior/await_struct.zig +++ b/test/behavior/await_struct.zig @@ -14,7 +14,7 @@ test "coroutine await struct" { await_seq('a'); var p = async await_amain(); - _ = p; + _ = &p; await_seq('f'); resume await_a_promise; await_seq('i'); diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index 30b6286658..c2ec18d0fe 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -118,6 +118,7 @@ fn thisIsAColdFn() void { test "unicode escape in character literal" { var a: u24 = '\u{01f4a9}'; + _ = &a; try expect(a == 128169); } @@ -362,6 +363,7 @@ test "variable is allowed to be a pointer to an opaque type" { } fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA { var a = ptr; + _ = &a; return a; } @@ -441,6 +443,7 @@ test "double implicit cast in same expression" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x = @as(i32, @as(u16, nine())); + _ = &x; try expect(x == 9); } fn nine() u8 { @@ -570,6 +573,7 @@ test "comptime cast fn to ptr" { test "equality compare fn ptrs" { var a = &emptyFn; + _ = &a; try expect(a == a); } @@ -611,6 +615,7 @@ test "global constant is loaded with a runtime-known index" { const S = struct { fn doTheTest() !void { var index: usize = 1; + _ = &index; const ptr = &pieces[index].field; try expect(ptr.* == 2); } @@ -785,6 +790,7 @@ test "variable name containing underscores does not shadow int primitive" { test "if expression type coercion" { var cond: bool = true; + _ = &cond; const x: u16 = if (cond) 1 else 0; try expect(@as(u16, x) == 1); } @@ -825,6 +831,7 @@ test "discarding the result of various expressions" { test "labeled block implicitly ends in a break" { var a = false; + _ = &a; blk: { if (a) break :blk; } @@ -852,6 +859,7 @@ test "catch in block has correct result location" { test "labeled block with runtime branch forwards its result location type to break statements" { const E = enum { a, b }; var a = false; + _ = &a; const e: E = blk: { if (a) { break :blk .a; @@ -872,8 +880,7 @@ test "try in labeled block doesn't cast to wrong type" { }; const s: ?*S = blk: { var a = try S.foo(); - - _ = a; + _ = &a; break :blk null; }; _ = s; @@ -894,6 +901,7 @@ test "weird array and tuple initializations" { const E = enum { a, b }; const S = struct { e: E }; var a = false; + _ = &a; const b = S{ .e = .a }; _ = &[_]S{ @@ -1009,6 +1017,7 @@ test "switch inside @as gets correct type" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: u32 = 0; + _ = &a; var b: [2]u32 = undefined; b[0] = @as(u32, switch (a) { 1 => 1, @@ -1110,7 +1119,8 @@ test "orelse coercion as function argument" { } }; var optional: ?Loc = .{}; - var foo = Container.init(optional orelse .{}); + _ = &optional; + const foo = Container.init(optional orelse .{}); try expect(foo.a.?.start == -1); } @@ -1153,6 +1163,7 @@ test "arrays and vectors with big integers" { test "pointer to struct literal with runtime field is constant" { const S = struct { data: usize }; var runtime_zero: usize = 0; + _ = &runtime_zero; const ptr = &S{ .data = runtime_zero }; try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_const); } @@ -1163,6 +1174,7 @@ test "integer compare" { var z: T = 0; var p: T = 123; var n: T = -123; + _ = .{ &z, &p, &n }; try expect(z == z and z != p and z != n); try expect(p == p and p != n and n == n); try expect(z > n and z < p and z >= n and z <= p); @@ -1180,6 +1192,7 @@ test "integer compare" { fn doTheTestUnsigned(comptime T: type) !void { var z: T = 0; var p: T = 123; + _ = .{ &z, &p }; try expect(z == z and z != p); try expect(p == p); try expect(z < p and z <= p); diff --git a/test/behavior/bit_shifting.zig b/test/behavior/bit_shifting.zig index 8b605385d2..b47dfa23c1 100644 --- a/test/behavior/bit_shifting.zig +++ b/test/behavior/bit_shifting.zig @@ -99,9 +99,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c // #2225 test "comptime shr of BigInt" { comptime { - var n0 = 0xdeadbeef0000000000000000; + const n0 = 0xdeadbeef0000000000000000; try expect(n0 >> 64 == 0xdeadbeef); - var n1 = 17908056155735594659; + const n1 = 17908056155735594659; try expect(n1 >> 64 == 0); } } diff --git a/test/behavior/bitcast.zig b/test/behavior/bitcast.zig index 846a1c33af..131a8ee0ac 100644 --- a/test/behavior/bitcast.zig +++ b/test/behavior/bitcast.zig @@ -149,8 +149,9 @@ test "bitcast literal [4]u8 param to u32" { } test "bitcast generates a temporary value" { - var y = @as(u16, 0x55AA); - const x = @as(u16, @bitCast(@as([2]u8, @bitCast(y)))); + var y: u16 = 0x55AA; + _ = &y; + const x: u16 = @bitCast(@as([2]u8, @bitCast(y))); try expect(y == x); } @@ -171,7 +172,8 @@ test "@bitCast packed structs at runtime and comptime" { const S = struct { fn doTheTest() !void { var full = Full{ .number = 0x1234 }; - var two_halves = @as(Divided, @bitCast(full)); + _ = &full; + const two_halves: Divided = @bitCast(full); try expect(two_halves.half1 == 0x34); try expect(two_halves.quarter3 == 0x2); try expect(two_halves.quarter4 == 0x1); @@ -195,7 +197,8 @@ test "@bitCast extern structs at runtime and comptime" { const S = struct { fn doTheTest() !void { var full = Full{ .number = 0x1234 }; - var two_halves = @as(TwoHalves, @bitCast(full)); + _ = &full; + const two_halves: TwoHalves = @bitCast(full); switch (native_endian) { .big => { try expect(two_halves.half1 == 0x12); @@ -225,8 +228,9 @@ test "bitcast packed struct to integer and back" { const S = struct { fn doTheTest() !void { var move = LevelUpMove{ .move_id = 1, .level = 2 }; - var v = @as(u16, @bitCast(move)); - var back_to_a_move = @as(LevelUpMove, @bitCast(v)); + _ = &move; + const v: u16 = @bitCast(move); + const back_to_a_move: LevelUpMove = @bitCast(v); try expect(back_to_a_move.move_id == 1); try expect(back_to_a_move.level == 2); } @@ -312,7 +316,8 @@ test "@bitCast packed struct of floats" { const S = struct { fn doTheTest() !void { var foo = Foo{}; - var v = @as(Foo2, @bitCast(foo)); + _ = &foo; + const v: Foo2 = @bitCast(foo); try expect(v.a == foo.a); try expect(v.b == foo.b); try expect(v.c == foo.c); @@ -354,10 +359,12 @@ test "comptime @bitCast packed struct to int and back" { // S -> Int var s: S = .{}; + _ = &s; try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{}))); // Int -> S var i: Int = 0; + _ = &i; const rt_cast = @as(S, @bitCast(i)); const ct_cast = comptime @as(S, @bitCast(@as(Int, 0))); inline for (@typeInfo(S).Struct.fields) |field| { @@ -376,6 +383,7 @@ 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 @as(u256, @bitCast(x)); + _ = &x_as_uint; try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f); try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x); @@ -428,6 +436,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u16, bitCastWrapper16(snan_f16_const)); var snan_f16_var = math.snan(f16); + _ = &snan_f16_var; try expectEqual(snan_u16, @as(u16, @bitCast(snan_f16_var))); try expectEqual(snan_u16, bitCastWrapper16(snan_f16_var)); @@ -437,6 +446,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u32, bitCastWrapper32(snan_f32_const)); var snan_f32_var = math.snan(f32); + _ = &snan_f32_var; try expectEqual(snan_u32, @as(u32, @bitCast(snan_f32_var))); try expectEqual(snan_u32, bitCastWrapper32(snan_f32_var)); @@ -446,6 +456,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u64, bitCastWrapper64(snan_f64_const)); var snan_f64_var = math.snan(f64); + _ = &snan_f64_var; try expectEqual(snan_u64, @as(u64, @bitCast(snan_f64_var))); try expectEqual(snan_u64, bitCastWrapper64(snan_f64_var)); @@ -455,6 +466,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u128, bitCastWrapper128(snan_f128_const)); var snan_f128_var = math.snan(f128); + _ = &snan_f128_var; try expectEqual(snan_u128, @as(u128, @bitCast(snan_f128_var))); try expectEqual(snan_u128, bitCastWrapper128(snan_f128_var)); } diff --git a/test/behavior/bitreverse.zig b/test/behavior/bitreverse.zig index b254910e46..a179e120e8 100644 --- a/test/behavior/bitreverse.zig +++ b/test/behavior/bitreverse.zig @@ -86,11 +86,30 @@ fn testBitReverse() !void { try expect(@bitReverse(@as(i24, -6773785)) == @bitReverse(neg24)); var neg32: i32 = -16773785; try expect(@bitReverse(@as(i32, -16773785)) == @bitReverse(neg32)); + + _ = .{ + &num0, + &num5, + &num8, + &num16, + &num24, + &num32, + &num40, + &num48, + &num56, + &num64, + &num128, + &neg8, + &neg16, + &neg24, + &neg32, + }; } fn vector8() !void { var v = @Vector(2, u8){ 0x12, 0x23 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0x48); try expect(result[1] == 0xc4); } @@ -109,7 +128,8 @@ test "bitReverse vectors u8" { fn vector16() !void { var v = @Vector(2, u16){ 0x1234, 0x2345 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0x2c48); try expect(result[1] == 0xa2c4); } @@ -128,7 +148,8 @@ test "bitReverse vectors u16" { fn vector24() !void { var v = @Vector(2, u24){ 0x123456, 0x234567 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0x6a2c48); try expect(result[1] == 0xe6a2c4); } @@ -147,7 +168,8 @@ test "bitReverse vectors u24" { fn vector0() !void { var v = @Vector(2, u0){ 0, 0 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0); try expect(result[1] == 0); } diff --git a/test/behavior/bugs/10147.zig b/test/behavior/bugs/10147.zig index a1fe9bff68..b8d6090479 100644 --- a/test/behavior/bugs/10147.zig +++ b/test/behavior/bugs/10147.zig @@ -10,9 +10,11 @@ test "test calling @clz on both vector and scalar inputs" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u32 = 0x1; + _ = &x; var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 }; - var a = @clz(x); - var b = @clz(y); + _ = &y; + const a = @clz(x); + const b = @clz(y); try std.testing.expectEqual(@as(u6, 31), a); try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b); } diff --git a/test/behavior/bugs/10970.zig b/test/behavior/bugs/10970.zig index 539dfaff71..cd1c78ad98 100644 --- a/test/behavior/bugs/10970.zig +++ b/test/behavior/bugs/10970.zig @@ -9,6 +9,7 @@ test "breaking from a loop in an if statement" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var cond = true; + _ = &cond; const opt = while (cond) { if (retOpt()) |opt| { break opt; diff --git a/test/behavior/bugs/11046.zig b/test/behavior/bugs/11046.zig index a13e02e45c..3c08dc649e 100644 --- a/test/behavior/bugs/11046.zig +++ b/test/behavior/bugs/11046.zig @@ -2,6 +2,7 @@ const builtin = @import("builtin"); fn foo() !void { var a = true; + _ = &a; if (a) return error.Foo; return error.Bar; } diff --git a/test/behavior/bugs/11139.zig b/test/behavior/bugs/11139.zig index 7af8b59101..93b25f3921 100644 --- a/test/behavior/bugs/11139.zig +++ b/test/behavior/bugs/11139.zig @@ -21,5 +21,6 @@ fn storeArrayOfArrayOfStructs() u8 { S{ .x = 15 }, }, }; + _ = &cases; return cases[0][0].x; } diff --git a/test/behavior/bugs/11159.zig b/test/behavior/bugs/11159.zig index 352491fefc..56ffb45b82 100644 --- a/test/behavior/bugs/11159.zig +++ b/test/behavior/bugs/11159.zig @@ -4,7 +4,7 @@ const builtin = @import("builtin"); test { const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); var a: T = .{ 0, 0 }; - _ = a; + _ = &a; } test { @@ -13,7 +13,7 @@ test { comptime y: u32 = 0, }; var a: S = .{}; - _ = a; + _ = &a; var b = S{}; - _ = b; + _ = &b; } diff --git a/test/behavior/bugs/11162.zig b/test/behavior/bugs/11162.zig index 6b4cef78e7..918cf1c793 100644 --- a/test/behavior/bugs/11162.zig +++ b/test/behavior/bugs/11162.zig @@ -6,8 +6,9 @@ test "aggregate initializers should allow initializing comptime fields, verifyin if (true) return error.SkipZigTest; // TODO var x: u32 = 15; + _ = &x; const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); - var a: T = .{ -1234, 5678, x + 1 }; + const a: T = .{ -1234, 5678, x + 1 }; try expect(a[0] == -1234); try expect(a[1] == 5678); diff --git a/test/behavior/bugs/11165.zig b/test/behavior/bugs/11165.zig index e23861ddc1..ff4695f647 100644 --- a/test/behavior/bugs/11165.zig +++ b/test/behavior/bugs/11165.zig @@ -18,7 +18,7 @@ test "bytes" { }; var u_2 = U{ .s = s_1 }; - _ = u_2; + _ = &u_2; } test "aggregate" { @@ -40,5 +40,5 @@ test "aggregate" { }; var u_2 = U{ .s = s_1 }; - _ = u_2; + _ = &u_2; } diff --git a/test/behavior/bugs/11181.zig b/test/behavior/bugs/11181.zig index 8abccc40c3..7819fe0ad8 100644 --- a/test/behavior/bugs/11181.zig +++ b/test/behavior/bugs/11181.zig @@ -21,5 +21,5 @@ test "var inferred array of slices" { .{ .v = false }, }, }; - _ = decls; + _ = &decls; } diff --git a/test/behavior/bugs/12000.zig b/test/behavior/bugs/12000.zig index d7b856d2f5..d13e402d87 100644 --- a/test/behavior/bugs/12000.zig +++ b/test/behavior/bugs/12000.zig @@ -11,5 +11,6 @@ test { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO var t: T = .{ .next = null }; + _ = &t; try std.testing.expect(t.next == null); } diff --git a/test/behavior/bugs/12025.zig b/test/behavior/bugs/12025.zig index 92f8aff0aa..73eca7c99b 100644 --- a/test/behavior/bugs/12025.zig +++ b/test/behavior/bugs/12025.zig @@ -5,6 +5,7 @@ test { .foo = &1, .bar = &2, }; + _ = &st; inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| { _ = field; diff --git a/test/behavior/bugs/12092.zig b/test/behavior/bugs/12092.zig index e5e89a9c58..673a0f1f47 100644 --- a/test/behavior/bugs/12092.zig +++ b/test/behavior/bugs/12092.zig @@ -19,6 +19,7 @@ test { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO var baz: u32 = 24; + _ = &baz; try takeFoo(&.{ .a = .{ .b = baz, diff --git a/test/behavior/bugs/12498.zig b/test/behavior/bugs/12498.zig index 3e4bafc2db..fd9ee98d29 100644 --- a/test/behavior/bugs/12498.zig +++ b/test/behavior/bugs/12498.zig @@ -4,5 +4,6 @@ const expect = std.testing.expect; const S = struct { a: usize }; test "lazy abi size used in comparison" { var rhs: i32 = 100; + _ = &rhs; try expect(@sizeOf(S) < rhs); } diff --git a/test/behavior/bugs/12776.zig b/test/behavior/bugs/12776.zig index 91df319dec..8195a9df6f 100644 --- a/test/behavior/bugs/12776.zig +++ b/test/behavior/bugs/12776.zig @@ -22,6 +22,7 @@ const CPU = packed struct { } fn tick(self: *CPU) !void { var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F); + _ = &queued_interrupts; if (self.interrupts and queued_interrupts != 0) { self.interrupts = false; } diff --git a/test/behavior/bugs/12891.zig b/test/behavior/bugs/12891.zig index 354d9e856e..20caab294c 100644 --- a/test/behavior/bugs/12891.zig +++ b/test/behavior/bugs/12891.zig @@ -4,26 +4,31 @@ const builtin = @import("builtin"); test "issue12891" { const f = 10.0; var i: usize = 0; + _ = &i; try std.testing.expect(i < f); } test "nan" { const f = comptime std.math.nan(f64); var i: usize = 0; + _ = &i; try std.testing.expect(!(f < i)); } test "inf" { const f = comptime std.math.inf(f64); var i: usize = 0; + _ = &i; try std.testing.expect(f > i); } test "-inf < 0" { const f = comptime -std.math.inf(f64); var i: usize = 0; + _ = &i; try std.testing.expect(f < i); } test "inf >= 1" { const f = comptime std.math.inf(f64); var i: usize = 1; + _ = &i; try std.testing.expect(f >= i); } test "isNan(nan * 1)" { diff --git a/test/behavior/bugs/12972.zig b/test/behavior/bugs/12972.zig index 3c256a19f8..f27a6bac8d 100644 --- a/test/behavior/bugs/12972.zig +++ b/test/behavior/bugs/12972.zig @@ -12,6 +12,7 @@ test { f(&.{c}); var v: u8 = 42; + _ = &v; f(&[_:null]?u8{v}); f(&.{v}); } diff --git a/test/behavior/bugs/12984.zig b/test/behavior/bugs/12984.zig index 75f2747eda..5cbb021ba9 100644 --- a/test/behavior/bugs/12984.zig +++ b/test/behavior/bugs/12984.zig @@ -16,5 +16,5 @@ test "simple test" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO var c: CustomDraw = undefined; - _ = c; + _ = &c; } diff --git a/test/behavior/bugs/13128.zig b/test/behavior/bugs/13128.zig index b87513d510..fff5be8e7e 100644 --- a/test/behavior/bugs/13128.zig +++ b/test/behavior/bugs/13128.zig @@ -18,6 +18,7 @@ test "runtime union init, most-aligned field != largest" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u8 = 1; + _ = &x; try foo(.{ .x = x }); const val: U = @unionInit(U, "x", x); diff --git a/test/behavior/bugs/13159.zig b/test/behavior/bugs/13159.zig index eec01658e6..db28f9e5be 100644 --- a/test/behavior/bugs/13159.zig +++ b/test/behavior/bugs/13159.zig @@ -13,5 +13,6 @@ test { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var foo = Bar.Baz.fizz; + _ = &foo; try expect(foo == .fizz); } diff --git a/test/behavior/bugs/13285.zig b/test/behavior/bugs/13285.zig index 15ebfa5804..a50cf71e55 100644 --- a/test/behavior/bugs/13285.zig +++ b/test/behavior/bugs/13285.zig @@ -8,7 +8,7 @@ test { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: Crasher = undefined; - var crasher_ptr = &a; + const crasher_ptr = &a; var crasher_local = crasher_ptr.*; const crasher_local_ptr = &crasher_local; crasher_local_ptr.lets_crash = 1; diff --git a/test/behavior/bugs/13366.zig b/test/behavior/bugs/13366.zig index 9b08bcd3fc..c87f122929 100644 --- a/test/behavior/bugs/13366.zig +++ b/test/behavior/bugs/13366.zig @@ -18,9 +18,11 @@ test { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO var a: u32 = 16; + _ = &a; var reason = .{ .c_import = .{ .a = a } }; var block = Block{ .reason = &reason, }; + _ = █ try expect(block.reason.?.c_import.a == 16); } diff --git a/test/behavior/bugs/13714.zig b/test/behavior/bugs/13714.zig index f11dac3676..b1902720c5 100644 --- a/test/behavior/bugs/13714.zig +++ b/test/behavior/bugs/13714.zig @@ -1,4 +1,5 @@ comptime { var image: [1]u8 = undefined; + _ = ℑ _ = @shlExact(@as(u16, image[0]), 8); } diff --git a/test/behavior/bugs/13785.zig b/test/behavior/bugs/13785.zig index 53d03f5413..e3c71d954c 100644 --- a/test/behavior/bugs/13785.zig +++ b/test/behavior/bugs/13785.zig @@ -9,5 +9,6 @@ test { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var a: u8 = 0; + _ = &a; try std.io.null_writer.print("\n{} {}\n", .{ a, S{} }); } diff --git a/test/behavior/bugs/1381.zig b/test/behavior/bugs/1381.zig index c9ea2102f5..090883e875 100644 --- a/test/behavior/bugs/1381.zig +++ b/test/behavior/bugs/1381.zig @@ -20,6 +20,7 @@ test "union that needs padding bytes inside an array" { A{ .B = B{ .D = 1 } }, A{ .B = B{ .D = 1 } }, }; + _ = &as; const a = as[0].B; try std.testing.expect(a.D == 1); diff --git a/test/behavior/bugs/1442.zig b/test/behavior/bugs/1442.zig index 02170ccabe..3d02686c48 100644 --- a/test/behavior/bugs/1442.zig +++ b/test/behavior/bugs/1442.zig @@ -12,5 +12,6 @@ test "const error union field alignment" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var union_or_err: anyerror!Union = Union{ .Color = 1234 }; + _ = &union_or_err; try std.testing.expect((union_or_err catch unreachable).Color == 1234); } diff --git a/test/behavior/bugs/1500.zig b/test/behavior/bugs/1500.zig index cc12c5d0be..ac0d76f879 100644 --- a/test/behavior/bugs/1500.zig +++ b/test/behavior/bugs/1500.zig @@ -8,6 +8,7 @@ const B = *const fn (A) void; test "allow these dependencies" { var a: A = undefined; var b: B = undefined; + _ = .{ &a, &b }; if (false) { a; b; diff --git a/test/behavior/bugs/1735.zig b/test/behavior/bugs/1735.zig index 68f851e578..0115143b94 100644 --- a/test/behavior/bugs/1735.zig +++ b/test/behavior/bugs/1735.zig @@ -45,6 +45,6 @@ test "initialization" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - var t = a.init(); + const t = a.init(); try std.testing.expect(t.foo.len == 0); } diff --git a/test/behavior/bugs/2557.zig b/test/behavior/bugs/2557.zig index 05cf8156c0..3f05b628ab 100644 --- a/test/behavior/bugs/2557.zig +++ b/test/behavior/bugs/2557.zig @@ -2,5 +2,5 @@ test { var a = if (true) { return; } else true; - _ = a; + _ = &a; } diff --git a/test/behavior/bugs/3468.zig b/test/behavior/bugs/3468.zig index adf3db3306..293e608aec 100644 --- a/test/behavior/bugs/3468.zig +++ b/test/behavior/bugs/3468.zig @@ -3,4 +3,5 @@ test "pointer deref next to assignment" { var a:i32=2; var b=&a; b.*=3; + _=&b; } diff --git a/test/behavior/bugs/3586.zig b/test/behavior/bugs/3586.zig index 1952714728..5bc682b149 100644 --- a/test/behavior/bugs/3586.zig +++ b/test/behavior/bugs/3586.zig @@ -12,5 +12,5 @@ test "fixed" { var ctr = Container{ .params = NoteParams{}, }; - _ = ctr; + _ = &ctr; } diff --git a/test/behavior/bugs/4560.zig b/test/behavior/bugs/4560.zig index ca9a34ea89..4f6e456755 100644 --- a/test/behavior/bugs/4560.zig +++ b/test/behavior/bugs/4560.zig @@ -11,6 +11,7 @@ test "fixed" { .max_distance_from_start_index = 456, }, }; + _ = &s; try std.testing.expect(s.a == 1); try std.testing.expect(s.b.size == 123); try std.testing.expect(s.b.max_distance_from_start_index == 456); diff --git a/test/behavior/bugs/6047.zig b/test/behavior/bugs/6047.zig index 9e6547a116..0288a52627 100644 --- a/test/behavior/bugs/6047.zig +++ b/test/behavior/bugs/6047.zig @@ -6,6 +6,7 @@ fn getError() !void { fn getError2() !void { var a: u8 = 'c'; + _ = &a; try if (a == 'a') getError() else if (a == 'b') getError() else getError(); } diff --git a/test/behavior/bugs/624.zig b/test/behavior/bugs/624.zig index a0a93c0104..14d6bbdfb1 100644 --- a/test/behavior/bugs/624.zig +++ b/test/behavior/bugs/624.zig @@ -25,5 +25,6 @@ test "foo" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var allocator = ContextAllocator{ .n = 10 }; + _ = &allocator; try expect(allocator.n == 10); } diff --git a/test/behavior/bugs/656.zig b/test/behavior/bugs/656.zig index 004f442165..a44ccb3647 100644 --- a/test/behavior/bugs/656.zig +++ b/test/behavior/bugs/656.zig @@ -22,6 +22,7 @@ fn foo(a: bool, b: bool) !void { var prefix_op = PrefixOp{ .AddrOf = Value{ .align_expr = 1234 }, }; + _ = &prefix_op; if (a) {} else { switch (prefix_op) { PrefixOp.AddrOf => |addr_of_info| { diff --git a/test/behavior/bugs/6781.zig b/test/behavior/bugs/6781.zig index eb1f9766d1..fdbb1dd917 100644 --- a/test/behavior/bugs/6781.zig +++ b/test/behavior/bugs/6781.zig @@ -51,7 +51,8 @@ pub const JournalHeader = packed struct { return @as(u128, @bitCast(target[0..hash_chain_root_size].*)); } else { var array = target[0..hash_chain_root_size].*; - return @as(u128, @bitCast(array)); + _ = &array; + return @bitCast(array); } } diff --git a/test/behavior/bugs/679.zig b/test/behavior/bugs/679.zig index 6420e7f99f..81de1bb038 100644 --- a/test/behavior/bugs/679.zig +++ b/test/behavior/bugs/679.zig @@ -14,5 +14,6 @@ const Element = struct { test "false dependency loop in struct definition" { const listType = ElementList; var x: listType = 42; + _ = &x; try expect(x == 42); } diff --git a/test/behavior/bugs/6905.zig b/test/behavior/bugs/6905.zig index be96efaace..2d473e108c 100644 --- a/test/behavior/bugs/6905.zig +++ b/test/behavior/bugs/6905.zig @@ -6,13 +6,15 @@ test "sentinel-terminated 0-length slices" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO - var u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; + const u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; var index: u8 = 2; - var slice = u32s[index..index :2]; - var array_ptr = u32s[2..2 :2]; + _ = &index; + const slice = u32s[index..index :2]; + const array_ptr = u32s[2..2 :2]; const comptime_known_array_value = u32s[2..2 :2].*; var runtime_array_value = u32s[2..2 :2].*; + _ = &runtime_array_value; try expect(slice[0] == 2); try expect(array_ptr[0] == 2); diff --git a/test/behavior/bugs/7187.zig b/test/behavior/bugs/7187.zig index bb2e82af89..0af9512963 100644 --- a/test/behavior/bugs/7187.zig +++ b/test/behavior/bugs/7187.zig @@ -5,7 +5,7 @@ const expect = std.testing.expect; test "miscompilation with bool return type" { var x: usize = 1; var y: bool = getFalse(); - _ = y; + _ = .{ &x, &y }; try expect(x == 1); } diff --git a/test/behavior/bugs/726.zig b/test/behavior/bugs/726.zig index c544e422a4..e6fd6a92b3 100644 --- a/test/behavior/bugs/726.zig +++ b/test/behavior/bugs/726.zig @@ -7,7 +7,8 @@ test "@ptrCast from const to nullable" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO const c: u8 = 4; - var x: ?*const u8 = @as(?*const u8, @ptrCast(&c)); + var x: ?*const u8 = @ptrCast(&c); + _ = &x; try expect(x.?.* == 4); } @@ -19,6 +20,7 @@ test "@ptrCast from var in empty struct to nullable" { const container = struct { var c: u8 = 4; }; - var x: ?*const u8 = @as(?*const u8, @ptrCast(&container.c)); + var x: ?*const u8 = @ptrCast(&container.c); + _ = &x; try expect(x.?.* == 4); } diff --git a/test/behavior/bugs/7325.zig b/test/behavior/bugs/7325.zig index 3652553b51..85c3b385f0 100644 --- a/test/behavior/bugs/7325.zig +++ b/test/behavior/bugs/7325.zig @@ -85,6 +85,7 @@ test { var param: ParamType = .{ .one_of = .{ .name = "name" }, }; + _ = ¶m; var arg: CallArg = .{ .value = .{ .literal_enum_value = .{ @@ -92,6 +93,7 @@ test { }, }, }; + _ = &arg; const result = try genExpression(arg.value); switch (result) { diff --git a/test/behavior/bugs/9584.zig b/test/behavior/bugs/9584.zig index 6f3223c362..0e41307bf4 100644 --- a/test/behavior/bugs/9584.zig +++ b/test/behavior/bugs/9584.zig @@ -60,6 +60,7 @@ test { .g = false, .h = false, }; + _ = &flags; var x = X{ .x = flags, }; diff --git a/test/behavior/byteswap.zig b/test/behavior/byteswap.zig index 88c5372364..3cbf35a40c 100644 --- a/test/behavior/byteswap.zig +++ b/test/behavior/byteswap.zig @@ -56,7 +56,8 @@ test "@byteSwap integers" { fn vector8() !void { var v = @Vector(2, u8){ 0x12, 0x13 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0x12); try expect(result[1] == 0x13); } @@ -75,7 +76,8 @@ test "@byteSwap vectors u8" { fn vector16() !void { var v = @Vector(2, u16){ 0x1234, 0x2345 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0x3412); try expect(result[1] == 0x4523); } @@ -94,7 +96,8 @@ test "@byteSwap vectors u16" { fn vector24() !void { var v = @Vector(2, u24){ 0x123456, 0x234567 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0x563412); try expect(result[1] == 0x674523); } @@ -113,7 +116,8 @@ test "@byteSwap vectors u24" { fn vector0() !void { var v = @Vector(2, u0){ 0, 0 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0); try expect(result[1] == 0); } diff --git a/test/behavior/call.zig b/test/behavior/call.zig index 61aa48803b..a476ba1788 100644 --- a/test/behavior/call.zig +++ b/test/behavior/call.zig @@ -47,6 +47,7 @@ test "basic invocations" { { // call of non comptime-known function var alias_foo = &foo; + _ = &alias_foo; try expect(@call(.no_async, alias_foo, .{}) == 1234); try expect(@call(.never_tail, alias_foo, .{}) == 1234); try expect(@call(.never_inline, alias_foo, .{}) == 1234); @@ -66,6 +67,7 @@ test "tuple parameters" { }.add; var a: i32 = 12; var b: i32 = 34; + _ = .{ &a, &b }; try expect(@call(.auto, add, .{ a, 34 }) == 46); try expect(@call(.auto, add, .{ 12, b }) == 46); try expect(@call(.auto, add, .{ a, b }) == 46); @@ -101,6 +103,7 @@ test "result location of function call argument through runtime condition and st } }; var runtime = true; + _ = &runtime; try namespace.foo(.{ .e = if (!runtime) .a else .b, }); @@ -445,6 +448,7 @@ test "non-anytype generic parameters provide result type" { var rt_u16: u16 = 123; var rt_u32: u32 = 0x10000222; + _ = .{ &rt_u16, &rt_u32 }; try S.f(u8, @intCast(rt_u16)); try S.f(u8, @intCast(123)); @@ -470,6 +474,7 @@ test "argument to generic function has correct result type" { fn doTheTest() !void { var t = true; + _ = &t; // Since the enum literal passes through a runtime conditional here, these can only // compile if RLS provides the correct result type to the argument diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index aeb7a8f1fa..486014074d 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -58,6 +58,7 @@ test "@intCast to comptime_int" { test "implicit cast comptime numbers to any type when the value fits" { const a: u64 = 255; var b: u8 = a; + _ = &b; try expect(b == 255); } @@ -273,7 +274,7 @@ test "implicit cast from *[N]T to [*c]T" { test "*usize to *void" { var i = @as(usize, 0); - var v = @as(*void, @ptrCast(&i)); + const v: *void = @ptrCast(&i); v.* = {}; } @@ -391,7 +392,8 @@ test "peer type unsigned int to signed" { var w: u31 = 5; var x: u8 = 7; var y: i32 = -5; - var a = w + y + x; + _ = .{ &w, &x, &y }; + const a = w + y + x; try comptime expect(@TypeOf(a) == i32); try expect(a == 7); } @@ -401,8 +403,9 @@ test "expected [*c]const u8, found [*:0]const u8" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: [*:0]const u8 = "hello"; - var b: [*c]const u8 = a; - var c: [*:0]const u8 = b; + _ = &a; + const b: [*c]const u8 = a; + const c: [*:0]const u8 = b; try expect(std.mem.eql(u8, c[0..5], "hello")); } @@ -609,14 +612,16 @@ test "@intCast on vector" { fn doTheTest() !void { // Upcast (implicit, equivalent to @intCast) var up0: @Vector(2, u8) = [_]u8{ 0x55, 0xaa }; - var up1 = @as(@Vector(2, u16), up0); - var up2 = @as(@Vector(2, u32), up0); - var up3 = @as(@Vector(2, u64), up0); + _ = &up0; + const up1 = @as(@Vector(2, u16), up0); + const up2 = @as(@Vector(2, u32), up0); + const up3 = @as(@Vector(2, u64), up0); // Downcast (safety-checked) var down0 = up3; - var down1 = @as(@Vector(2, u32), @intCast(down0)); - var down2 = @as(@Vector(2, u16), @intCast(down0)); - var down3 = @as(@Vector(2, u8), @intCast(down0)); + _ = &down0; + const down1 = @as(@Vector(2, u32), @intCast(down0)); + const down2 = @as(@Vector(2, u16), @intCast(down0)); + const 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 })); @@ -629,7 +634,8 @@ test "@intCast on vector" { fn doTheTestFloat() !void { var vec: @Vector(2, f32) = @splat(1234.0); - var wider: @Vector(2, f64) = vec; + _ = &vec; + const wider: @Vector(2, f64) = vec; try expect(wider[0] == 1234.0); try expect(wider[1] == 1234.0); } @@ -648,7 +654,8 @@ test "@floatCast cast down" { { var double: f64 = 0.001534; - var single = @as(f32, @floatCast(double)); + _ = &double; + const single = @as(f32, @floatCast(double)); try expect(single == 0.001534); } { @@ -672,6 +679,7 @@ test "peer type resolution: unreachable, error set, unreachable" { Unexpected, }; var err = Error.SystemResources; + _ = &err; const transformed_err = switch (err) { error.FileDescriptorAlreadyPresentInSet => unreachable, error.OperationCausesCircularLoop => unreachable, @@ -821,10 +829,11 @@ test "peer cast *[0]T to E![]const T" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var buffer: [5]u8 = "abcde".*; - var buf: anyerror![]const u8 = buffer[0..]; + const buf: anyerror![]const u8 = buffer[0..]; var b = false; - var y = if (b) &[0]u8{} else buf; - var z = if (!b) buf else &[0]u8{}; + _ = &b; + const y = if (b) &[0]u8{} else buf; + const z = if (!b) buf else &[0]u8{}; try expect(mem.eql(u8, "abcde", y catch unreachable)); try expect(mem.eql(u8, "abcde", z catch unreachable)); } @@ -835,9 +844,10 @@ test "peer cast *[0]T to []const T" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var buffer: [5]u8 = "abcde".*; - var buf: []const u8 = buffer[0..]; + const buf: []const u8 = buffer[0..]; var b = false; - var y = if (b) &[0]u8{} else buf; + _ = &b; + const y = if (b) &[0]u8{} else buf; try expect(mem.eql(u8, "abcde", y)); } @@ -846,6 +856,7 @@ test "peer cast *[N]T to [*]T" { var array = [4:99]i32{ 1, 2, 3, 4 }; var dest: [*]i32 = undefined; + _ = &dest; try expect(@TypeOf(&array, dest) == [*]i32); try expect(@TypeOf(dest, &array) == [*]i32); } @@ -879,8 +890,8 @@ test "peer cast [:x]T to []T" { const S = struct { fn doTheTest() !void { var array = [4:0]i32{ 1, 2, 3, 4 }; - var slice: [:0]i32 = &array; - var dest: []i32 = slice; + const slice: [:0]i32 = &array; + const dest: []i32 = slice; try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); } }; @@ -895,7 +906,8 @@ test "peer cast [N:x]T to [N]T" { const S = struct { fn doTheTest() !void { var array = [4:0]i32{ 1, 2, 3, 4 }; - var dest: [4]i32 = array; + _ = &array; + const dest: [4]i32 = array; try expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 })); } }; @@ -910,7 +922,7 @@ test "peer cast *[N:x]T to *[N]T" { const S = struct { fn doTheTest() !void { var array = [4:0]i32{ 1, 2, 3, 4 }; - var dest: *[4]i32 = &array; + const dest: *[4]i32 = &array; try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); } }; @@ -925,7 +937,7 @@ test "peer cast [*:x]T to [*]T" { const S = struct { fn doTheTest() !void { var array = [4:99]i32{ 1, 2, 3, 4 }; - var dest: [*]i32 = &array; + const dest: [*]i32 = &array; try expect(dest[0] == 1); try expect(dest[1] == 2); try expect(dest[2] == 3); @@ -945,8 +957,8 @@ test "peer cast [:x]T to [*:x]T" { const S = struct { fn doTheTest() !void { var array = [4:0]i32{ 1, 2, 3, 4 }; - var slice: [:0]i32 = &array; - var dest: [*:0]i32 = slice; + const slice: [:0]i32 = &array; + const dest: [*:0]i32 = slice; try expect(dest[0] == 1); try expect(dest[1] == 2); try expect(dest[2] == 3); @@ -998,6 +1010,7 @@ test "peer type resolution implicit cast to variable type" { test "variable initialization uses result locations properly with regards to the type" { var b = true; + _ = &b; const x: i32 = if (b) 1 else 2; try expect(x == 1); } @@ -1025,7 +1038,7 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" { var array: [4:0]u8 = undefined; array[4] = 0; // TODO remove this when #4372 is solved - var slice: [:0]u8 = array[0..4 :0]; + const slice: [:0]u8 = array[0..4 :0]; try comptime expect(@TypeOf(slice, "hi") == [:0]const u8); try comptime expect(@TypeOf("hi", slice) == [:0]const u8); } @@ -1042,6 +1055,7 @@ test "peer type resolve array pointer and unknown pointer" { var array: [4]u8 = undefined; var const_ptr: [*]const u8 = undefined; var ptr: [*]u8 = undefined; + _ = .{ &const_ptr, &ptr }; try comptime expect(@TypeOf(&array, ptr) == [*]u8); try comptime expect(@TypeOf(ptr, &array) == [*]u8); @@ -1090,6 +1104,7 @@ test "implicit cast from [*]T to ?*anyopaque" { var a = [_]u8{ 3, 2, 1 }; var runtime_zero: usize = 0; + _ = &runtime_zero; incrementVoidPtrArray(a[runtime_zero..].ptr, 3); try expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 })); } @@ -1151,11 +1166,11 @@ test "implicit ptr to *anyopaque" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: u32 = 1; - var ptr: *align(@alignOf(u32)) anyopaque = &a; - var b: *u32 = @as(*u32, @ptrCast(ptr)); + const ptr: *align(@alignOf(u32)) anyopaque = &a; + const b: *u32 = @as(*u32, @ptrCast(ptr)); try expect(b.* == 1); - var ptr2: ?*align(@alignOf(u32)) anyopaque = &a; - var c: *u32 = @as(*u32, @ptrCast(ptr2.?)); + const ptr2: ?*align(@alignOf(u32)) anyopaque = &a; + const c: *u32 = @as(*u32, @ptrCast(ptr2.?)); try expect(c.* == 1); } @@ -1264,6 +1279,7 @@ test "implicit cast *[0]T to E![]const u8" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x = @as(anyerror![]const u8, &[0]u8{}); + _ = &x; try expect((x catch unreachable).len == 0); } @@ -1274,6 +1290,7 @@ test "cast from array reference to fn: comptime fn ptr" { } test "cast from array reference to fn: runtime fn ptr" { var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array)); + _ = &f; try expect(@intFromPtr(f) == @intFromPtr(&global_array)); } @@ -1285,7 +1302,8 @@ test "*const [N]null u8 to ?[]const u8" { const S = struct { fn doTheTest() !void { var a = "Hello"; - var b: ?[]const u8 = a; + _ = &a; + const b: ?[]const u8 = a; try expect(mem.eql(u8, b.?, "Hello")); } }; @@ -1318,12 +1336,13 @@ test "assignment to optional pointer result loc" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var foo: struct { ptr: ?*anyopaque } = .{ .ptr = &global_struct }; + _ = &foo; try expect(foo.ptr.? == @as(*anyopaque, @ptrCast(&global_struct))); } test "cast between *[N]void and []void" { var a: [4]void = undefined; - var b: []void = &a; + const b: []void = &a; try expect(b.len == 4); } @@ -1351,6 +1370,7 @@ test "cast f16 to wider types" { const S = struct { fn doTheTest() !void { var x: f16 = 1234.0; + _ = &x; try expect(@as(f32, 1234.0) == x); try expect(@as(f64, 1234.0) == x); try expect(@as(f128, 1234.0) == x); @@ -1370,6 +1390,7 @@ test "cast f128 to narrower types" { const S = struct { fn doTheTest() !void { var x: f128 = 1234.0; + _ = &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))); @@ -1404,6 +1425,7 @@ test "cast i8 fn call peers to i32 result" { const S = struct { fn doTheTest() !void { var cond = true; + _ = &cond; const value: i32 = if (cond) smallBoi() else bigBoi(); try expect(value == 123); } @@ -1424,7 +1446,8 @@ test "cast compatible optional types" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: ?[:0]const u8 = null; - var b: ?[]const u8 = a; + _ = &a; + const b: ?[]const u8 = a; try expect(b == null); } @@ -1434,6 +1457,7 @@ test "coerce undefined single-item pointer of array to error union of slice" { const a = @as([*]u8, undefined)[0..0]; var b: error{a}![]const u8 = a; + _ = &b; const s = try b; try expect(s.len == 0); } @@ -1442,6 +1466,7 @@ test "pointer to empty struct literal to mutable slice" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: []i32 = &.{}; + _ = &x; try expect(x.len == 0); } @@ -1466,7 +1491,7 @@ test "coerce between pointers of compatible differently-named floats" { else => @compileError("unreachable"), }; var f1: F = 12.34; - var f2: *c_longdouble = &f1; + const f2: *c_longdouble = &f1; f2.* += 1; try expect(f1 == @as(F, 12.34) + 1); } @@ -1507,8 +1532,9 @@ test "implicit cast from [:0]T to [*c]T" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO var a: [:0]const u8 = "foo"; - var b: [*c]const u8 = a; - var c = std.mem.span(b); + _ = &a; + const b: [*c]const u8 = a; + const c = std.mem.span(b); try expect(c.len == a.len); try expect(c.ptr == a.ptr); } @@ -1544,6 +1570,7 @@ test "single item pointer to pointer to array to slice" { test "peer type resolution forms error union" { var foo: i32 = 123; + _ = &foo; const result = if (foo < 0) switch (-foo) { 0 => unreachable, 42 => error.AccessDenied, @@ -1561,7 +1588,7 @@ test "@constCast without a result location" { test "@volatileCast without a result location" { var x: i32 = 1234; - var y: *volatile i32 = &x; + const y: *volatile i32 = &x; const z = @volatileCast(y); try expect(@TypeOf(z) == *i32); try expect(z.* == 1234); @@ -1585,10 +1612,12 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice" fn doTheTest(comptime T: type, comptime s: T) !void { var a: [:s]const T = @as(*const [2:s]T, @ptrFromInt(0x1000)); var b: []T = @as(*[3]T, @ptrFromInt(0x2000)); + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == []const T); comptime assert(@TypeOf(b, a) == []const T); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1611,10 +1640,12 @@ test "peer type resolution: float and comptime-known fixed-width integer" { const i: u8 = 100; var f: f32 = 1.234; + _ = &f; comptime assert(@TypeOf(i, f) == f32); comptime assert(@TypeOf(f, i) == f32); var t = true; + _ = &t; const r1 = if (t) i else f; const r2 = if (t) f else i; @@ -1631,10 +1662,12 @@ test "peer type resolution: same array type with sentinel" { var a: [2:0]u32 = .{ 0, 1 }; var b: [2:0]u32 = .{ 2, 3 }; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == [2:0]u32); comptime assert(@TypeOf(b, a) == [2:0]u32); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1651,10 +1684,12 @@ test "peer type resolution: array with sentinel and array without sentinel" { var a: [2:0]u32 = .{ 0, 1 }; var b: [2]u32 = .{ 2, 3 }; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == [2]u32); comptime assert(@TypeOf(b, a) == [2]u32); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1671,10 +1706,12 @@ test "peer type resolution: array and vector with same child type" { var arr: [2]u32 = .{ 0, 1 }; var vec: @Vector(2, u32) = .{ 2, 3 }; + _ = .{ &arr, &vec }; comptime assert(@TypeOf(arr, vec) == @Vector(2, u32)); comptime assert(@TypeOf(vec, arr) == @Vector(2, u32)); var t = true; + _ = &t; const r1 = if (t) arr else vec; const r2 = if (t) vec else arr; @@ -1694,10 +1731,12 @@ test "peer type resolution: array with smaller child type and vector with larger var arr: [2]u8 = .{ 0, 1 }; var vec: @Vector(2, u64) = .{ 2, 3 }; + _ = .{ &arr, &vec }; comptime assert(@TypeOf(arr, vec) == @Vector(2, u64)); comptime assert(@TypeOf(vec, arr) == @Vector(2, u64)); var t = true; + _ = &t; const r1 = if (t) arr else vec; const r2 = if (t) vec else arr; @@ -1715,10 +1754,12 @@ test "peer type resolution: error union and optional of same type" { const E = error{Foo}; var a: E!*u8 = error.Foo; var b: ?*u8 = null; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == E!?*u8); comptime assert(@TypeOf(b, a) == E!?*u8); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1734,11 +1775,13 @@ test "peer type resolution: C pointer and @TypeOf(null)" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: [*c]c_int = 0x1000; + _ = &a; const b = null; comptime assert(@TypeOf(a, b) == [*c]c_int); comptime assert(@TypeOf(b, a) == [*c]c_int); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1755,8 +1798,9 @@ 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 = @as(*const [5:0]u8, @ptrFromInt(0x1000)); + var b: *const [5:0]u8 = @ptrFromInt(0x1000); var c: ?[*:0]u8 = null; + _ = .{ &a, &b, &c }; comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8); comptime assert(@TypeOf(a, c, b) == E!?[*:0]const u8); comptime assert(@TypeOf(b, a, c) == E!?[*:0]const u8); @@ -1765,6 +1809,7 @@ test "peer type resolution: three-way resolution combines error set and optional comptime assert(@TypeOf(c, b, a) == E!?[*:0]const u8); var x: u8 = 0; + _ = &x; const r1 = switch (x) { 0 => a, 1 => b, @@ -1797,10 +1842,12 @@ test "peer type resolution: vector and optional vector" { var a: ?@Vector(3, u32) = .{ 0, 1, 2 }; var b: @Vector(3, u32) = .{ 3, 4, 5 }; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == ?@Vector(3, u32)); comptime assert(@TypeOf(b, a) == ?@Vector(3, u32)); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1816,11 +1863,13 @@ test "peer type resolution: optional fixed-width int and comptime_int" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: ?i32 = 42; + _ = &a; const b: comptime_int = 50; comptime assert(@TypeOf(a, b) == ?i32); comptime assert(@TypeOf(b, a) == ?i32); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1836,12 +1885,14 @@ test "peer type resolution: array and tuple" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var arr: [3]i32 = .{ 1, 2, 3 }; + _ = &arr; const tup = .{ 4, 5, 6 }; comptime assert(@TypeOf(arr, tup) == [3]i32); comptime assert(@TypeOf(tup, arr) == [3]i32); var t = true; + _ = &t; const r1 = if (t) arr else tup; const r2 = if (t) tup else arr; @@ -1858,12 +1909,14 @@ test "peer type resolution: vector and tuple" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var vec: @Vector(3, i32) = .{ 1, 2, 3 }; + _ = &vec; const tup = .{ 4, 5, 6 }; comptime assert(@TypeOf(vec, tup) == @Vector(3, i32)); comptime assert(@TypeOf(tup, vec) == @Vector(3, i32)); var t = true; + _ = &t; const r1 = if (t) vec else tup; const r2 = if (t) tup else vec; @@ -1881,6 +1934,7 @@ test "peer type resolution: vector and array and tuple" { var vec: @Vector(2, i8) = .{ 10, 20 }; var arr: [2]i8 = .{ 30, 40 }; + _ = .{ &vec, &arr }; const tup = .{ 50, 60 }; comptime assert(@TypeOf(vec, arr, tup) == @Vector(2, i8)); @@ -1891,6 +1945,7 @@ test "peer type resolution: vector and array and tuple" { comptime assert(@TypeOf(tup, arr, vec) == @Vector(2, i8)); var x: u8 = 0; + _ = &x; const r1 = switch (x) { 0 => vec, 1 => arr, @@ -1921,11 +1976,13 @@ test "peer type resolution: empty tuple pointer and slice" { var a: [:0]const u8 = "Hello"; var b = &.{}; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == []const u8); comptime assert(@TypeOf(b, a) == []const u8); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1940,11 +1997,13 @@ test "peer type resolution: tuple pointer and slice" { var a: [:0]const u8 = "Hello"; var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') }; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == []const u8); comptime assert(@TypeOf(b, a) == []const u8); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1959,11 +2018,13 @@ test "peer type resolution: tuple pointer and optional slice" { var a: ?[:0]const u8 = null; var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') }; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == ?[]const u8); comptime assert(@TypeOf(b, a) == ?[]const u8); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1986,6 +2047,7 @@ test "peer type resolution: many compatible pointers" { @as([*]u8, &buf), @as(*const [5]u8, "foo-4"), }; + _ = &vals; // Check every possible permutation of types in @TypeOf @setEvalBranchQuota(5000); @@ -2015,6 +2077,7 @@ test "peer type resolution: many compatible pointers" { comptime assert(perms == 5 * 4 * 3 * 2 * 1); var x: u8 = 0; + _ = &x; inline for (0..5) |i| { const r = switch (x) { 0 => vals[i], @@ -2057,6 +2120,7 @@ test "peer type resolution: tuples with comptime fields" { } var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -2074,13 +2138,15 @@ test "peer type resolution: C pointer and many pointer" { var buf = "hello".*; - var a: [*c]u8 = &buf; + const a: [*c]u8 = &buf; var b: [*:0]const u8 = "world"; + _ = &b; comptime assert(@TypeOf(a, b) == [*c]const u8); comptime assert(@TypeOf(b, a) == [*c]const u8); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -2097,9 +2163,9 @@ test "peer type resolution: pointer attributes are combined correctly" { var buf_b align(4) = "bar".*; var buf_c align(4) = "baz".*; - var a: [*:0]align(4) const u8 = &buf_a; - var b: *align(2) volatile [3:0]u8 = &buf_b; - var c: [*:0]align(4) u8 = &buf_c; + const a: [*:0]align(4) const u8 = &buf_a; + const b: *align(2) volatile [3:0]u8 = &buf_b; + const c: [*:0]align(4) u8 = &buf_c; comptime assert(@TypeOf(a, b, c) == [*:0]align(2) const volatile u8); comptime assert(@TypeOf(a, c, b) == [*:0]align(2) const volatile u8); @@ -2109,6 +2175,7 @@ test "peer type resolution: pointer attributes are combined correctly" { comptime assert(@TypeOf(c, b, a) == [*:0]align(2) const volatile u8); var x: u8 = 0; + _ = &x; const r1 = switch (x) { 0 => a, 1 => b, @@ -2254,6 +2321,7 @@ test "@floatCast on vector" { const S = struct { fn doTheTest() !void { var a: @Vector(3, f64) = .{ 1.5, 2.5, 3.5 }; + _ = &a; const b: @Vector(3, f32) = @floatCast(a); try expectEqual(@Vector(3, f32){ 1.5, 2.5, 3.5 }, b); } @@ -2274,6 +2342,7 @@ test "@ptrFromInt on vector" { const S = struct { fn doTheTest() !void { var a: @Vector(3, usize) = .{ 0x1000, 0x2000, 0x3000 }; + _ = &a; const b: @Vector(3, *anyopaque) = @ptrFromInt(a); try expectEqual(@Vector(3, *anyopaque){ @ptrFromInt(0x1000), @@ -2302,6 +2371,7 @@ test "@intFromPtr on vector" { @ptrFromInt(0x2000), @ptrFromInt(0x3000), }; + _ = &a; const b: @Vector(3, usize) = @intFromPtr(a); try expectEqual(@Vector(3, usize){ 0x1000, 0x2000, 0x3000 }, b); } @@ -2322,6 +2392,7 @@ test "@floatFromInt on vector" { const S = struct { fn doTheTest() !void { var a: @Vector(3, u32) = .{ 10, 20, 30 }; + _ = &a; const b: @Vector(3, f32) = @floatFromInt(a); try expectEqual(@Vector(3, f32){ 10.0, 20.0, 30.0 }, b); } @@ -2342,6 +2413,7 @@ test "@intFromFloat on vector" { const S = struct { fn doTheTest() !void { var a: @Vector(3, f32) = .{ 10.3, 20.5, 30.7 }; + _ = &a; const b: @Vector(3, u32) = @intFromFloat(a); try expectEqual(@Vector(3, u32){ 10, 20, 30 }, b); } @@ -2362,6 +2434,7 @@ test "@intFromBool on vector" { const S = struct { fn doTheTest() !void { var a: @Vector(3, bool) = .{ false, true, false }; + _ = &a; const b: @Vector(3, u1) = @intFromBool(a); try expectEqual(@Vector(3, u1){ 0, 1, 0 }, b); } @@ -2385,7 +2458,8 @@ test "15-bit int to float" { if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; var a: u15 = 42; - var b: f32 = @floatFromInt(a); + _ = &a; + const b: f32 = @floatFromInt(a); try expect(b == 42.0); } @@ -2417,6 +2491,7 @@ test "result information is preserved through many nested structures" { const T = *const ?E!struct { x: ?*const E!?u8 }; var val: T = &.{ .x = &@truncate(0x1234) }; + _ = &val; const struct_val = val.*.? catch unreachable; const int_val = (struct_val.x.?.* catch unreachable).?; @@ -2439,6 +2514,7 @@ test "@intCast vector of signed integer" { if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO var x: @Vector(4, i32) = .{ 1, 2, 3, 4 }; + _ = &x; const y: @Vector(4, i8) = @intCast(x); try expect(y[0] == 1); diff --git a/test/behavior/cast_int.zig b/test/behavior/cast_int.zig index 23e5a614f8..8a832f7820 100644 --- a/test/behavior/cast_int.zig +++ b/test/behavior/cast_int.zig @@ -12,7 +12,8 @@ test "@intCast i32 to u7" { var x: u128 = maxInt(u128); var y: i32 = 120; - var z = x >> @as(u7, @intCast(y)); + _ = .{ &x, &y }; + const z = x >> @as(u7, @intCast(y)); try expect(z == 0xff); } @@ -23,20 +24,24 @@ test "coerce i8 to i32 and @intCast back" { var x: i8 = -5; var y: i32 = -5; + _ = .{ &x, &y }; try expect(y == x); var x2: i32 = -5; var y2: i8 = -5; + _ = .{ &x2, &y2 }; try expect(y2 == @as(i8, @intCast(x2))); } test "coerce non byte-sized integers accross 32bits boundary" { { var v: u21 = 6417; + _ = &v; const a: u32 = v; const b: u64 = v; const c: u64 = a; var w: u64 = 0x1234567812345678; + _ = &w; const d: u21 = @truncate(w); const e: u60 = d; try expectEqual(@as(u32, 6417), a); @@ -48,10 +53,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { { var v: u10 = 234; + _ = &v; const a: u32 = v; const b: u64 = v; const c: u64 = a; var w: u64 = 0x1234567812345678; + _ = &w; const d: u10 = @truncate(w); const e: u60 = d; try expectEqual(@as(u32, 234), a); @@ -62,10 +69,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { } { var v: u7 = 11; + _ = &v; const a: u32 = v; const b: u64 = v; const c: u64 = a; var w: u64 = 0x1234567812345678; + _ = &w; const d: u7 = @truncate(w); const e: u60 = d; try expectEqual(@as(u32, 11), a); @@ -77,10 +86,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { { var v: i21 = -6417; + _ = &v; const a: i32 = v; const b: i64 = v; const c: i64 = a; var w: i64 = -12345; + _ = &w; const d: i21 = @intCast(w); const e: i60 = d; try expectEqual(@as(i32, -6417), a); @@ -92,10 +103,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { { var v: i10 = -234; + _ = &v; const a: i32 = v; const b: i64 = v; const c: i64 = a; var w: i64 = -456; + _ = &w; const d: i10 = @intCast(w); const e: i60 = d; try expectEqual(@as(i32, -234), a); @@ -106,10 +119,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { } { var v: i7 = -11; + _ = &v; const a: i32 = v; const b: i64 = v; const c: i64 = a; var w: i64 = -42; + _ = &w; const d: i7 = @intCast(w); const e: i60 = d; try expectEqual(@as(i32, -11), a); @@ -152,7 +167,7 @@ test "load non byte-sized optional value" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // note: this bug is triggered by the == operator, expectEqual will hide it - var opt: ?Piece = try Piece.charToPiece('p'); + const opt: ?Piece = try Piece.charToPiece('p'); try expect(opt.?.type == .PAWN); try expect(opt.?.color == .BLACK); diff --git a/test/behavior/comptime_memory.zig b/test/behavior/comptime_memory.zig index 4245f332d6..bfeaa339b2 100644 --- a/test/behavior/comptime_memory.zig +++ b/test/behavior/comptime_memory.zig @@ -280,7 +280,7 @@ test "dance on linker values" { if (ptr_size > @sizeOf(Bits)) try doTypePunBitsTest(&weird_ptr[1]); - var arr_bytes = @as(*[2][ptr_size]u8, @ptrCast(&arr)); + const arr_bytes: *[2][ptr_size]u8 = @ptrCast(&arr); var rebuilt_bytes: [ptr_size]u8 = undefined; var i: usize = 0; diff --git a/test/behavior/destructure.zig b/test/behavior/destructure.zig index 4d7c336daa..c2a5ca329a 100644 --- a/test/behavior/destructure.zig +++ b/test/behavior/destructure.zig @@ -7,6 +7,7 @@ test "simple destructure" { fn doTheTest() !void { var x: u32 = undefined; x, const y, var z: u64 = .{ 1, @as(u16, 2), 3 }; + _ = &z; comptime assert(@TypeOf(y) == u16); @@ -25,6 +26,7 @@ test "destructure with comptime syntax" { fn doTheTest() void { comptime var x: f32 = undefined; comptime x, const y, var z = .{ 0.5, 123, 456 }; // z is a comptime var + _ = &z; comptime assert(@TypeOf(y) == comptime_int); comptime assert(@TypeOf(z) == comptime_int); @@ -112,6 +114,7 @@ test "destructure of comptime-known tuple is comptime-known" { test "destructure of comptime-known tuple where some destinations are runtime-known is comptime-known" { var z: u32 = undefined; var x: u8, const y, z = .{ 1, 2, 3 }; + _ = &x; comptime assert(@TypeOf(y) == comptime_int); comptime assert(y == 2); @@ -122,6 +125,7 @@ test "destructure of comptime-known tuple where some destinations are runtime-kn test "destructure of tuple with comptime fields results in some comptime-known values" { var runtime: u32 = 42; + _ = &runtime; const a, const b, const c, const d = .{ 123, runtime, 456, runtime }; // a, c are comptime-known diff --git a/test/behavior/empty_union.zig b/test/behavior/empty_union.zig index 40bdd627f3..f05feacfaf 100644 --- a/test/behavior/empty_union.zig +++ b/test/behavior/empty_union.zig @@ -5,12 +5,14 @@ const expect = std.testing.expect; test "switch on empty enum" { const E = enum {}; var e: E = undefined; + _ = &e; switch (e) {} } test "switch on empty enum with a specified tag type" { const E = enum(u8) {}; var e: E = undefined; + _ = &e; switch (e) {} } @@ -19,6 +21,7 @@ test "switch on empty auto numbered tagged union" { const U = union(enum(u8)) {}; var u: U = undefined; + _ = &u; switch (u) {} } @@ -28,6 +31,7 @@ test "switch on empty tagged union" { const E = enum {}; const U = union(E) {}; var u: U = undefined; + _ = &u; switch (u) {} } diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig index efd0295a97..d203476afc 100644 --- a/test/behavior/enum.zig +++ b/test/behavior/enum.zig @@ -579,6 +579,7 @@ test "enum literal cast to enum" { var color1: Color = .Auto; var color2 = Color.Auto; + _ = .{ &color1, &color2 }; try expect(color1 == color2); } @@ -663,7 +664,8 @@ test "empty non-exhaustive enum" { const E = enum(u8) { _ }; fn doTheTest(y: u8) !void { - var e = @as(E, @enumFromInt(y)); + var e: E = @enumFromInt(y); + _ = &e; try expect(switch (e) { _ => true, }); @@ -858,6 +860,7 @@ test "comparison operator on enum with one member is comptime-known" { const State = enum { Start }; test "switch on enum with one member is comptime-known" { var state = State.Start; + _ = &state; switch (state) { State.Start => return, } @@ -917,7 +920,8 @@ test "enum literal casting to tagged union" { var t = true; var x: Arch = .x86_64; - var y = if (t) x else .x86_64; + _ = .{ &t, &x }; + const y = if (t) x else .x86_64; switch (y) { .x86_64 => {}, else => @panic("fail"), @@ -1031,6 +1035,7 @@ test "tag name with assigned enum values" { B = 0, }; var b = LocalFoo.B; + _ = &b; try expect(mem.eql(u8, @tagName(b), "B")); } @@ -1055,6 +1060,7 @@ test "tag name with signed enum values" { delta = 65, }; var b = LocalFoo.bravo; + _ = &b; try expect(mem.eql(u8, @tagName(b), "bravo")); } @@ -1135,13 +1141,13 @@ test "tag name functions are unique" { const E = enum { a, b }; var b = E.a; var a = @tagName(b); - _ = a; + _ = .{ &a, &b }; } { const E = enum { a, b, c, d, e, f }; var b = E.a; var a = @tagName(b); - _ = a; + _ = .{ &a, &b }; } } @@ -1189,6 +1195,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; + _ = &runtime; if (@as(E, @enumFromInt(runtime)) != .one) { @compileError("test failed"); } diff --git a/test/behavior/error.zig b/test/behavior/error.zig index dfd511af2e..715cd6e445 100644 --- a/test/behavior/error.zig +++ b/test/behavior/error.zig @@ -102,8 +102,7 @@ test "widen cast integer payload of error union function call" { const S = struct { fn errorable() !u64 { - var x = @as(u64, try number()); - return x; + return @as(u64, try number()); } fn number() anyerror!u32 { @@ -119,7 +118,7 @@ test "debug info for optional error set" { const SomeError = error{ Hello, Hello2 }; var a_local_variable: ?SomeError = null; - _ = a_local_variable; + _ = &a_local_variable; } test "implicit cast to optional to error union to return result loc" { @@ -160,6 +159,7 @@ fn entry() void { fn entryPtr() void { var ptr = &bar2; + _ = &ptr; fooPtr(ptr); } @@ -226,9 +226,9 @@ const Set1 = error{ A, B }; const Set2 = error{ A, C }; fn testExplicitErrorSetCast(set1: Set1) !void { - var x = @as(Set2, @errorCast(set1)); + const x: Set2 = @errorCast(set1); try expect(@TypeOf(x) == Set2); - var y = @as(Set1, @errorCast(x)); + const y: Set1 = @errorCast(x); try expect(@TypeOf(y) == Set1); try expect(y == error.A); } @@ -408,17 +408,17 @@ test "nested error union function call in optional unwrap" { }; fn errorable() !i32 { - var x: Foo = (try getFoo()) orelse return error.Other; + const x: Foo = (try getFoo()) orelse return error.Other; return x.a; } fn errorable2() !i32 { - var x: Foo = (try getFoo2()) orelse return error.Other; + const x: Foo = (try getFoo2()) orelse return error.Other; return x.a; } fn errorable3() !i32 { - var x: Foo = (try getFoo3()) orelse return error.Other; + const x: Foo = (try getFoo3()) orelse return error.Other; return x.a; } @@ -673,6 +673,7 @@ test "peer type resolution of two different error unions" { const a: error{B}!void = {}; const b: error{A}!void = {}; var cond = true; + _ = &cond; const err = if (cond) a else b; try err; } @@ -681,6 +682,7 @@ test "coerce error set to the current inferred error set" { const S = struct { fn foo() !void { var a = false; + _ = &a; if (a) { const b: error{A}!void = error.A; return b; @@ -831,6 +833,7 @@ test "alignment of wrapping an error union payload" { fn foo() anyerror!I { var i: I = .{ .x = 1234 }; + _ = &i; return i; } }; @@ -842,6 +845,7 @@ test "compare error union and error set" { var a: anyerror = error.Foo; var b: anyerror!u32 = error.Bar; + _ = &a; try expect(a != b); try expect(b != a); @@ -863,6 +867,7 @@ fn non_errorable() void { // This test is needed because stage 2's fix for #1923 means that catch blocks interact // with the error return trace index. var x: error{Foo}!void = {}; + _ = &x; return x catch {}; } @@ -902,6 +907,7 @@ test "optional error union return type" { const S = struct { fn foo() ?anyerror!u32 { var x: u32 = 1234; + _ = &x; return @as(anyerror!u32, x); } }; diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig index 39e9e32484..ac09066552 100644 --- a/test/behavior/eval.zig +++ b/test/behavior/eval.zig @@ -37,6 +37,7 @@ fn gimme1or2(comptime a: bool) i32 { const x: i32 = 1; const y: i32 = 2; comptime var z: i32 = if (a) x else y; + _ = &z; return z; } test "inline variable gets result of const if" { @@ -74,6 +75,7 @@ test "constant expressions" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var array: [array_size]u8 = undefined; + _ = &array; try expect(@sizeOf(@TypeOf(array)) == 20); } const array_size: u8 = 20; @@ -129,7 +131,7 @@ test "pointer to type" { comptime { var T: type = i32; try expect(T == i32); - var ptr = &T; + const ptr = &T; try expect(@TypeOf(ptr) == *type); ptr.* = f32; try expect(T == f32); @@ -372,6 +374,7 @@ fn doNothingWithType(comptime T: type) void { test "zero extend from u0 to u1" { var zero_u0: u0 = 0; var zero_u1: u1 = zero_u0; + _ = .{ &zero_u0, &zero_u1 }; try expect(zero_u1 == 0); } @@ -408,6 +411,7 @@ test "inline for with same type but different values" { var res: usize = 0; inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| { var a: T = undefined; + _ = &a; res += a.len; } try expect(res == 5); @@ -460,9 +464,9 @@ test "comptime shl" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - var a: u128 = 3; - var b: u7 = 63; - var c: u128 = 3 << 63; + const a: u128 = 3; + const b: u7 = 63; + const c: u128 = 3 << 63; try expect((a << b) == c); } @@ -489,6 +493,7 @@ test "comptime shlWithOverflow" { const ct_shifted = @shlWithOverflow(~@as(u64, 0), 16)[0]; var a = ~@as(u64, 0); + _ = &a; const rt_shifted = @shlWithOverflow(a, 16)[0]; try expect(ct_shifted == rt_shifted); @@ -521,7 +526,8 @@ test "runtime 128 bit integer division" { var a: u128 = 152313999999999991610955792383; var b: u128 = 10000000000000000000; - var c = a / b; + _ = .{ &a, &b }; + const c = a / b; try expect(c == 15231399999); } @@ -555,6 +561,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var runtime = [1]i32{3}; + _ = &runtime; comptime var i: usize = 0; inline while (i < 2) : (i += 1) { const result = if (i == 0) [1]i32{2} else runtime; @@ -692,7 +699,7 @@ test "call method with comptime pass-by-non-copying-value self parameter" { }; const s = S{ .a = 2 }; - var b = s.b(); + const b = s.b(); try expect(b == 2); } @@ -759,7 +766,8 @@ test "array concatenation peer resolves element types - value" { var a = [2]u3{ 1, 7 }; var b = [3]u8{ 200, 225, 255 }; - var c = a ++ b; + _ = .{ &a, &b }; + const c = a ++ b; comptime assert(@TypeOf(c) == [5]u8); try expect(c[0] == 1); try expect(c[1] == 7); @@ -775,7 +783,7 @@ test "array concatenation peer resolves element types - pointer" { var a = [2]u3{ 1, 7 }; var b = [3]u8{ 200, 225, 255 }; - var c = &a ++ &b; + const c = &a ++ &b; comptime assert(@TypeOf(c) == *[5]u8); try expect(c[0] == 1); try expect(c[1] == 7); @@ -791,14 +799,15 @@ test "array concatenation sets the sentinel - value" { var a = [2]u3{ 1, 7 }; var b = [3:69]u8{ 200, 225, 255 }; - var c = a ++ b; + _ = .{ &a, &b }; + const c = a ++ b; comptime assert(@TypeOf(c) == [5:69]u8); try expect(c[0] == 1); try expect(c[1] == 7); try expect(c[2] == 200); try expect(c[3] == 225); try expect(c[4] == 255); - var ptr: [*]const u8 = &c; + const ptr: [*]const u8 = &c; try expect(ptr[5] == 69); } @@ -808,14 +817,14 @@ test "array concatenation sets the sentinel - pointer" { var a = [2]u3{ 1, 7 }; var b = [3:69]u8{ 200, 225, 255 }; - var c = &a ++ &b; + const c = &a ++ &b; comptime assert(@TypeOf(c) == *[5:69]u8); try expect(c[0] == 1); try expect(c[1] == 7); try expect(c[2] == 200); try expect(c[3] == 225); try expect(c[4] == 255); - var ptr: [*]const u8 = c; + const ptr: [*]const u8 = c; try expect(ptr[5] == 69); } @@ -825,13 +834,14 @@ test "array multiplication sets the sentinel - value" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a = [2:7]u3{ 1, 6 }; - var b = a ** 2; + _ = &a; + const b = a ** 2; comptime assert(@TypeOf(b) == [4:7]u3); try expect(b[0] == 1); try expect(b[1] == 6); try expect(b[2] == 1); try expect(b[3] == 6); - var ptr: [*]const u3 = &b; + const ptr: [*]const u3 = &b; try expect(ptr[4] == 7); } @@ -841,13 +851,13 @@ test "array multiplication sets the sentinel - pointer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a = [2:7]u3{ 1, 6 }; - var b = &a ** 2; + const b = &a ** 2; comptime assert(@TypeOf(b) == *[4:7]u3); try expect(b[0] == 1); try expect(b[1] == 6); try expect(b[2] == 1); try expect(b[3] == 6); - var ptr: [*]const u3 = b; + const ptr: [*]const u3 = b; try expect(ptr[4] == 7); } @@ -913,8 +923,8 @@ test "comptime pointer load through elem_ptr" { .x = i, }; } - var ptr = @as([*]S, @ptrCast(&array)); - var x = ptr[0].x; + var ptr: [*]S = @ptrCast(&array); + const x = ptr[0].x; assert(x == 0); ptr += 1; assert(ptr[1].x == 2); @@ -953,11 +963,12 @@ test "closure capture type of runtime-known parameter" { const S = struct { fn b(c: anytype) !void { const D = struct { c: @TypeOf(c) }; - var d = D{ .c = c }; + const d: D = .{ .c = c }; try expect(d.c == 1234); } }; var c: i32 = 1234; + _ = &c; try S.b(c); } @@ -966,6 +977,7 @@ test "closure capture type of runtime-known var" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 1234; + _ = &x; const S = struct { val: @TypeOf(x + 100) }; const s: S = .{ .val = x }; try expect(s.val == 1234); @@ -977,6 +989,7 @@ test "comptime break passing through runtime condition converted to runtime brea const S = struct { fn doTheTest() !void { var runtime: u8 = 'b'; + _ = &runtime; inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { bar(); if (byte == runtime) { @@ -1010,6 +1023,7 @@ test "comptime break to outer loop passing through runtime condition converted t const S = struct { fn doTheTest() !void { var runtime: u8 = 'b'; + _ = &runtime; outer: inline for ([3]u8{ 'A', 'B', 'C' }) |outer_byte| { inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { bar(outer_byte); @@ -1387,6 +1401,7 @@ test "break from inline loop depends on runtime condition" { test "inline for inside a runtime condition" { var a = false; + _ = &a; if (a) { const arr = .{ 1, 2, 3 }; inline for (arr) |val| { @@ -1522,6 +1537,7 @@ test "non-optional and optional array elements concatenated" { const array = [1]u8{'A'} ++ [1]?u8{null}; var index: usize = 0; + _ = &index; try expect(array[index].? == 'A'); } @@ -1556,6 +1572,7 @@ test "container level const and var have unique addresses" { var v: @This() = c; }; var p = &S.c; + _ = &p; try std.testing.expect(p.x == S.c.x); S.v.x = 2; try std.testing.expect(p.x == S.c.x); @@ -1625,7 +1642,8 @@ test "inline for loop of functions returning error unions" { test "if inside a switch" { var condition = true; var wave_type: u32 = 0; - var sample: i32 = switch (wave_type) { + _ = .{ &condition, &wave_type }; + const sample: i32 = switch (wave_type) { 0 => if (condition) 2 else 3, 1 => 100, 2 => 200, @@ -1673,6 +1691,7 @@ test "@inComptime" { comptime { var foo = [3]u8{ 0x55, 0x55, 0x55 }; var bar = [2]u8{ 1, 2 }; + _ = .{ &foo, &bar }; foo[0..2].* = bar; assert(foo[0] == 1); assert(foo[1] == 2); diff --git a/test/behavior/extern_struct_zero_size_fields.zig b/test/behavior/extern_struct_zero_size_fields.zig index 1b13532f11..592ec85f50 100644 --- a/test/behavior/extern_struct_zero_size_fields.zig +++ b/test/behavior/extern_struct_zero_size_fields.zig @@ -17,5 +17,5 @@ const T = extern struct { test { var t: T = .{}; - _ = t; + _ = &t; } diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig index f114f30fa9..e1c870bce6 100644 --- a/test/behavior/floatop.zig +++ b/test/behavior/floatop.zig @@ -42,6 +42,8 @@ test "add f80/f128/c_longdouble" { fn testAdd(comptime T: type) !void { var one_point_two_five: T = 1.25; var two_point_seven_five: T = 2.75; + _ = &one_point_two_five; + _ = &two_point_seven_five; try expect(one_point_two_five + two_point_seven_five == 4); } @@ -74,6 +76,8 @@ test "sub f80/f128/c_longdouble" { fn testSub(comptime T: type) !void { var one_point_two_five: T = 1.25; var two_point_seven_five: T = 2.75; + _ = &one_point_two_five; + _ = &two_point_seven_five; try expect(one_point_two_five - two_point_seven_five == -1.5); } @@ -106,6 +110,8 @@ test "mul f80/f128/c_longdouble" { fn testMul(comptime T: type) !void { var one_point_two_five: T = 1.25; var two_point_seven_five: T = 2.75; + _ = &one_point_two_five; + _ = &two_point_seven_five; try expect(one_point_two_five * two_point_seven_five == 3.4375); } @@ -152,6 +158,7 @@ fn testCmp(comptime T: type) !void { { // No decimal part var x: T = 1.0; + _ = &x; try expect(x == 1.0); try expect(x != 0.0); try expect(x > 0.0); @@ -162,6 +169,7 @@ fn testCmp(comptime T: type) !void { { // Non-zero decimal part var x: T = 1.5; + _ = &x; try expect(x != 1.0); try expect(x != 2.0); try expect(x > 1.0); @@ -184,6 +192,7 @@ fn testCmp(comptime T: type) !void { math.floatMax(T), math.inf(T), }; + _ = &edges; for (edges, 0..) |rhs, rhs_i| { for (edges, 0..) |lhs, lhs_i| { const no_nan = lhs_i != 5 and rhs_i != 5; @@ -212,6 +221,7 @@ test "different sized float comparisons" { fn testDifferentSizedFloatComparisons() !void { var a: f16 = 1; var b: f64 = 2; + _ = .{ &a, &b }; try expect(a < b); } @@ -240,7 +250,8 @@ test "negative f128 intFromFloat at compile-time" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; const a: f128 = -2; - var b = @as(i64, @intFromFloat(a)); + var b: i64 = @intFromFloat(a); + _ = &b; try expect(@as(i64, -2) == b); } @@ -331,6 +342,28 @@ fn testSqrt(comptime T: type) !void { try expect(math.isNan(@sqrt(neg_one))); var nan: T = math.nan(T); try expect(math.isNan(@sqrt(nan))); + + _ = .{ + &four, + &nine, + &twenty_five, + &sixty_four, + &one_point_one, + &two, + &three_point_six, + &sixty_four_point_one, + &twelve, + &thirteen, + &fourteen, + &a, + &b, + &c, + &inf, + &zero, + &neg_zero, + &neg_one, + &nan, + }; } test "@sqrt with vectors" { @@ -345,7 +378,8 @@ test "@sqrt with vectors" { fn testSqrtWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @sqrt(v); + _ = &v; + const result = @sqrt(v); try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon)); @@ -394,8 +428,10 @@ test "@sin f80/f128/c_longdouble" { fn testSin(comptime T: type) !void { const eps = epsForType(T); var zero: T = 0; + _ = &zero; try expect(@sin(zero) == 0); var pi: T = math.pi; + _ = π try expect(math.approxEqAbs(T, @sin(pi), 0, eps)); try expect(math.approxEqAbs(T, @sin(pi / 2.0), 1, eps)); try expect(math.approxEqAbs(T, @sin(pi / 4.0), 0.7071067811865475, eps)); @@ -414,7 +450,8 @@ test "@sin with vectors" { fn testSinWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @sin(v); + _ = &v; + const result = @sin(v); try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon)); @@ -463,8 +500,10 @@ test "@cos f80/f128/c_longdouble" { fn testCos(comptime T: type) !void { const eps = epsForType(T); var zero: T = 0; + _ = &zero; try expect(@cos(zero) == 1); var pi: T = math.pi; + _ = π try expect(math.approxEqAbs(T, @cos(pi), -1, eps)); try expect(math.approxEqAbs(T, @cos(pi / 2.0), 0, eps)); try expect(math.approxEqAbs(T, @cos(pi / 4.0), 0.7071067811865475, eps)); @@ -483,7 +522,8 @@ test "@cos with vectors" { fn testCosWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @cos(v); + _ = &v; + const result = @cos(v); try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon)); @@ -532,8 +572,10 @@ test "@tan f80/f128/c_longdouble" { fn testTan(comptime T: type) !void { const eps = epsForType(T); var zero: T = 0; + _ = &zero; try expect(@tan(zero) == 0); var pi: T = math.pi; + _ = π try expect(math.approxEqAbs(T, @tan(pi), 0, eps)); try expect(math.approxEqAbs(T, @tan(pi / 3.0), 1.732050807568878, eps)); try expect(math.approxEqAbs(T, @tan(pi / 4.0), 1, eps)); @@ -552,7 +594,8 @@ test "@tan with vectors" { fn testTanWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @tan(v); + _ = &v; + const result = @tan(v); try expect(math.approxEqAbs(f32, @tan(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @tan(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @tan(@as(f32, 3.3)), result[2], epsilon)); @@ -600,11 +643,17 @@ test "@exp f80/f128/c_longdouble" { fn testExp(comptime T: type) !void { const eps = epsForType(T); + var zero: T = 0; + _ = &zero; try expect(@exp(zero) == 1); + var two: T = 2; + _ = &two; try expect(math.approxEqAbs(T, @exp(two), 7.389056098930650, eps)); + var five: T = 5; + _ = &five; try expect(math.approxEqAbs(T, @exp(five), 148.4131591025766, eps)); } @@ -621,7 +670,8 @@ test "@exp with vectors" { fn testExpWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @exp(v); + _ = &v; + const result = @exp(v); try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon)); @@ -675,6 +725,7 @@ fn testExp2(comptime T: type) !void { try expect(math.approxEqAbs(T, @exp2(one_point_five), 2.8284271247462, eps)); var four_point_five: T = 4.5; try expect(math.approxEqAbs(T, @exp2(four_point_five), 22.627416997969, eps)); + _ = .{ &two, &one_point_five, &four_point_five }; } test "@exp2 with @vectors" { @@ -690,7 +741,8 @@ test "@exp2 with @vectors" { fn testExp2WithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @exp2(v); + _ = &v; + const result = @exp2(v); try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon)); @@ -744,6 +796,7 @@ fn testLog(comptime T: type) !void { try expect(math.approxEqAbs(T, @log(two), 0.6931471805599, eps)); var five: T = 5; try expect(math.approxEqAbs(T, @log(five), 1.6094379124341, eps)); + _ = .{ &e, &two, &five }; } test "@log with @vectors" { @@ -756,7 +809,8 @@ test "@log with @vectors" { { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @log(v); + _ = &v; + const result = @log(v); try expect(@log(@as(f32, 1.1)) == result[0]); try expect(@log(@as(f32, 2.2)) == result[1]); try expect(@log(@as(f32, 0.3)) == result[2]); @@ -811,6 +865,7 @@ fn testLog2(comptime T: type) !void { try expect(math.approxEqAbs(T, @log2(six), 2.5849625007212, eps)); var ten: T = 10; try expect(math.approxEqAbs(T, @log2(ten), 3.3219280948874, eps)); + _ = .{ &four, &six, &ten }; } test "@log2 with vectors" { @@ -830,7 +885,8 @@ test "@log2 with vectors" { fn testLog2WithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @log2(v); + _ = &v; + const result = @log2(v); try expect(@log2(@as(f32, 1.1)) == result[0]); try expect(@log2(@as(f32, 2.2)) == result[1]); try expect(@log2(@as(f32, 0.3)) == result[2]); @@ -884,6 +940,7 @@ fn testLog10(comptime T: type) !void { try expect(math.approxEqAbs(T, @log10(fifteen), 1.176091259056, eps)); var fifty: T = 50; try expect(math.approxEqAbs(T, @log10(fifty), 1.698970004336, eps)); + _ = .{ &hundred, &fifteen, &fifty }; } test "@log10 with vectors" { @@ -899,7 +956,8 @@ test "@log10 with vectors" { fn testLog10WithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @log10(v); + _ = &v; + const result = @log10(v); try expect(@log10(@as(f32, 1.1)) == result[0]); try expect(@log10(@as(f32, 2.2)) == result[1]); try expect(@log10(@as(f32, 0.3)) == result[2]); @@ -987,6 +1045,26 @@ fn testFabs(comptime T: type) !void { try expect(math.isPositiveInf(@abs(neg_inf))); var nan: T = math.nan(T); try expect(math.isNan(@abs(nan))); + + _ = .{ + &two_point_five, + &neg_two_point_five, + &twelve, + &neg_fourteen, + &one, + &neg_one, + &min, + &neg_min, + &max, + &neg_max, + &zero, + &neg_zero, + &true_min, + &neg_true_min, + &inf, + &neg_inf, + &nan, + }; } test "@abs with vectors" { @@ -1001,7 +1079,8 @@ test "@abs with vectors" { fn testFabsWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @abs(v); + _ = &v; + const result = @abs(v); try expect(math.approxEqAbs(f32, @abs(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @abs(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @abs(@as(f32, 0.3)), result[2], epsilon)); @@ -1070,6 +1149,17 @@ fn testFloor(comptime T: type) !void { try expect(@floor(fourteen_point_seven) == 14.0); var neg_fourteen_point_seven: T = -14.7; try expect(@floor(neg_fourteen_point_seven) == -15.0); + + _ = .{ + &two_point_one, + &neg_two_point_one, + &three_point_five, + &neg_three_point_five, + &twelve, + &neg_twelve, + &fourteen_point_seven, + &neg_fourteen_point_seven, + }; } test "@floor with vectors" { @@ -1086,7 +1176,8 @@ test "@floor with vectors" { fn testFloorWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @floor(v); + _ = &v; + const result = @floor(v); try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon)); @@ -1155,6 +1246,17 @@ fn testCeil(comptime T: type) !void { try expect(@ceil(fourteen_point_seven) == 15.0); var neg_fourteen_point_seven: T = -14.7; try expect(@ceil(neg_fourteen_point_seven) == -14.0); + + _ = .{ + &two_point_one, + &neg_two_point_one, + &three_point_five, + &neg_three_point_five, + &twelve, + &neg_twelve, + &fourteen_point_seven, + &neg_fourteen_point_seven, + }; } test "@ceil with vectors" { @@ -1171,7 +1273,8 @@ test "@ceil with vectors" { fn testCeilWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @ceil(v); + _ = &v; + const result = @ceil(v); try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon)); @@ -1250,6 +1353,17 @@ fn testTrunc(comptime T: type) !void { try expect(@trunc(fourteen_point_seven) == 14.0); var neg_fourteen_point_seven: T = -14.7; try expect(@trunc(neg_fourteen_point_seven) == -14.0); + + _ = .{ + &two_point_one, + &neg_two_point_one, + &three_point_five, + &neg_three_point_five, + &twelve, + &neg_twelve, + &fourteen_point_seven, + &neg_fourteen_point_seven, + }; } test "@trunc with vectors" { @@ -1266,7 +1380,8 @@ test "@trunc with vectors" { fn testTruncWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @trunc(v); + _ = &v; + const result = @trunc(v); try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon)); @@ -1365,6 +1480,27 @@ fn testNeg(comptime T: type) !void { var neg_nan: T = -math.nan(T); try expect(math.isNan(-neg_nan)); try expect(!math.signbit(-neg_nan)); + + _ = .{ + &two_point_five, + &neg_two_point_five, + &twelve, + &neg_fourteen, + &one, + &neg_one, + &min, + &neg_min, + &max, + &neg_max, + &zero, + &neg_zero, + &true_min, + &neg_true_min, + &inf, + &neg_inf, + &nan, + &neg_nan, + }; } test "eval @setFloatMode at compile-time" { diff --git a/test/behavior/fn.zig b/test/behavior/fn.zig index ddfc9648c2..4f8dd35490 100644 --- a/test/behavior/fn.zig +++ b/test/behavior/fn.zig @@ -21,6 +21,7 @@ fn testLocVars(b: i32) void { test "mutable local variables" { var zero: i32 = 0; + _ = &zero; try expect(zero == 0); var i = @as(i32, 0); @@ -70,7 +71,7 @@ fn outer(y: u32) *const fn (u32) u32 { test "return inner function which references comptime variable of outer function" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - var func = outer(10); + const func = outer(10); try expect(func(3) == 7); } @@ -259,7 +260,7 @@ test "implicit cast fn call result to optional in field result" { const S = struct { fn entry() !void { - var x = Foo{ + const x = Foo{ .field = optionalPtr(), }; try expect(x.field.?.* == 999); @@ -386,6 +387,7 @@ test "ability to give comptime types and non comptime types to same parameter" { const S = struct { fn doTheTest() !void { var x: i32 = 1; + _ = &x; try expect(foo(x) == 10); try expect(foo(i32) == 20); } @@ -413,11 +415,11 @@ test "import passed byref to function in return type" { const S = struct { fn get() @import("std").ArrayListUnmanaged(i32) { - var x: @import("std").ArrayListUnmanaged(i32) = .{}; + const x: @import("std").ArrayListUnmanaged(i32) = .{}; return x; } }; - var list = S.get(); + const list = S.get(); try expect(list.items.len == 0); } @@ -434,11 +436,13 @@ test "implicit cast function to function ptr" { } }; var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue; + _ = &fnPtr1; try expect(fnPtr1() == 123); const S2 = struct { extern fn someFunctionThatReturnsAValue() c_int; }; var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue; + _ = &fnPtr2; try expect(fnPtr2() == 123); } @@ -588,5 +592,6 @@ test "pointer to alias behaves same as pointer to function" { const bar = foo; }; var a = &S.bar; + _ = &a; try std.testing.expect(S.foo() == a()); } diff --git a/test/behavior/fn_in_struct_in_comptime.zig b/test/behavior/fn_in_struct_in_comptime.zig index 0acadbc5ea..40410d4aea 100644 --- a/test/behavior/fn_in_struct_in_comptime.zig +++ b/test/behavior/fn_in_struct_in_comptime.zig @@ -5,8 +5,7 @@ fn get_foo() fn (*u8) usize { comptime { return struct { fn func(ptr: *u8) usize { - var u = @intFromPtr(ptr); - return u; + return @intFromPtr(ptr); } }.func; } diff --git a/test/behavior/for.zig b/test/behavior/for.zig index 5a41f75077..a43fc2305b 100644 --- a/test/behavior/for.zig +++ b/test/behavior/for.zig @@ -26,7 +26,7 @@ test "break from outer for loop" { } fn testBreakOuter() !void { - var array = "aoeu"; + const array = "aoeu"; var count: usize = 0; outer: for (array) |_| { for (array) |_| { @@ -43,7 +43,7 @@ test "continue outer for loop" { } fn testContinueOuter() !void { - var array = "aoeu"; + const array = "aoeu"; var counter: usize = 0; outer: for (array) |_| { for (array) |_| { @@ -137,7 +137,7 @@ test "2 break statements and an else" { fn entry(t: bool, f: bool) !void { var buf: [10]u8 = undefined; var ok = false; - ok = for (buf) |item| { + ok = for (&buf) |*item| { _ = item; if (f) break false; if (t) break true; @@ -201,7 +201,7 @@ test "for on slice with allowzero ptr" { const S = struct { fn doTheTest(slice: []const u8) !void { - var ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len]; + const 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); } @@ -230,6 +230,7 @@ test "for loop with else branch" { { var x = [_]u32{ 1, 2 }; + _ = &x; const q = for (x) |y| { if ((y & 1) != 0) continue; break y * 2; @@ -238,6 +239,7 @@ test "for loop with else branch" { } { var x = [_]u32{ 1, 2 }; + _ = &x; const q = for (x) |y| { if ((y & 1) != 0) continue; break y * 2; @@ -310,6 +312,7 @@ test "slice and two counters, one is offset and one is runtime" { const slice: []const u8 = "blah"; var start: usize = 0; + _ = &start; for (slice, start..4, 1..5) |a, b, c| { if (a == 'b') { @@ -394,6 +397,7 @@ test "inline for with slice as the comptime-known" { const comptime_slice = "hello"; var runtime_i: usize = 3; + _ = &runtime_i; const S = struct { var ok: usize = 0; @@ -424,6 +428,7 @@ test "inline for with counter as the comptime-known" { var runtime_slice = "hello"; var runtime_i: usize = 3; + _ = &runtime_i; const S = struct { var ok: usize = 0; @@ -484,14 +489,16 @@ test "inferred alloc ptr of for loop" { { var cond = false; - var opt = for (0..1) |_| { + _ = &cond; + const opt = for (0..1) |_| { if (cond) break cond; } else null; try expectEqual(@as(?bool, null), opt); } { var cond = true; - var opt = for (0..1) |_| { + _ = &cond; + const opt = for (0..1) |_| { if (cond) break cond; } else null; try expectEqual(@as(?bool, true), opt); diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index d52ad20677..d0c97bdbf3 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -102,6 +102,7 @@ test "type constructed by comptime function call" { fn SimpleList(comptime L: usize) type { var mutable_T = u8; + _ = &mutable_T; const T = mutable_T; return struct { array: [L]T, @@ -238,6 +239,7 @@ test "function parameter is generic" { } }; var rng: u32 = 2; + _ = &rng; S.init(rng, S.fill); } diff --git a/test/behavior/if.zig b/test/behavior/if.zig index 68ea986c05..c4dfd04f71 100644 --- a/test/behavior/if.zig +++ b/test/behavior/if.zig @@ -61,6 +61,7 @@ test "unwrap mutable global var" { test "labeled break inside comptime if inside runtime if" { var answer: i32 = 0; var c = true; + _ = &c; if (c) { answer = if (true) blk: { break :blk @as(i32, 42); @@ -73,6 +74,7 @@ test "const result loc, runtime if cond, else unreachable" { const Num = enum { One, Two }; var t = true; + _ = &t; const x = if (t) Num.Two else unreachable; try expect(x == .Two); } @@ -103,6 +105,7 @@ test "if prongs cast to expected type instead of peer type resolution" { try expect(x == 2); var b = true; + _ = &b; const y: i32 = if (b) 1 else 2; try expect(y == 1); } @@ -118,10 +121,11 @@ test "if peer expressions inferred optional type" { var self: []const u8 = "abcdef"; var index: usize = 0; - var left_index = (index << 1) + 1; - var right_index = left_index + 1; - var left = if (left_index < self.len) self[left_index] else null; - var right = if (right_index < self.len) self[right_index] else null; + _ = .{ &self, &index }; + const left_index = (index << 1) + 1; + const right_index = left_index + 1; + const left = if (left_index < self.len) self[left_index] else null; + const right = if (right_index < self.len) self[right_index] else null; try expect(left_index < self.len); try expect(right_index < self.len); try expect(left.? == 98); @@ -135,6 +139,7 @@ test "if-else expression with runtime condition result location is inferred opti const A = struct { b: u64, c: u64 }; var d: bool = true; + _ = &d; const e = if (d) A{ .b = 15, .c = 30 } else null; try expect(e != null); } @@ -142,7 +147,8 @@ test "if-else expression with runtime condition result location is inferred opti test "result location with inferred type ends up being pointer to comptime_int" { var a: ?u32 = 1234; var b: u32 = 2000; - var c = if (a) |d| blk: { + _ = .{ &a, &b }; + const c = if (a) |d| blk: { if (d < b) break :blk @as(u32, 1); break :blk 0; } else @as(u32, 0); @@ -152,6 +158,7 @@ test "result location with inferred type ends up being pointer to comptime_int" test "if-@as-if chain" { var fast = true; var very_fast = false; + _ = .{ &fast, &very_fast }; const num_frames = if (fast) @as(u32, if (very_fast) 16 else 4) diff --git a/test/behavior/inline_switch.zig b/test/behavior/inline_switch.zig index deb4518820..59dc7096b9 100644 --- a/test/behavior/inline_switch.zig +++ b/test/behavior/inline_switch.zig @@ -22,6 +22,7 @@ test "inline prong ranges" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: usize = 0; + _ = &x; switch (x) { inline 0...20, 24 => |item| { if (item > 25) @compileError("bad"); @@ -36,6 +37,7 @@ test "inline switch enums" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: E = .a; + _ = &x; switch (x) { inline .a, .b => |aorb| if (aorb != .a and aorb != .b) @compileError("bad"), inline .c, .d => |cord| if (cord != .c and cord != .d) @compileError("bad"), @@ -49,6 +51,7 @@ test "inline switch unions" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: U = .a; + _ = &x; switch (x) { inline .a, .b => |aorb, tag| { if (tag == .a) { @@ -74,6 +77,7 @@ test "inline else bool" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a = true; + _ = &a; switch (a) { true => {}, inline else => |val| if (val != false) @compileError("bad"), @@ -86,6 +90,7 @@ test "inline else error" { const Err = error{ a, b, c }; var a = Err.a; + _ = &a; switch (a) { error.a => {}, inline else => |val| comptime if (val == error.a) @compileError("bad"), @@ -98,6 +103,7 @@ test "inline else enum" { const E2 = enum(u8) { a = 2, b = 3, c = 4, d = 5 }; var a: E2 = .a; + _ = &a; switch (a) { .a, .b => {}, inline else => |val| comptime if (@intFromEnum(val) < 4) @compileError("bad"), @@ -109,6 +115,7 @@ test "inline else int with gaps" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: u8 = 0; + _ = &a; switch (a) { 1...125, 128...254 => {}, inline else => |val| { @@ -126,6 +133,7 @@ test "inline else int all values" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: u2 = 0; + _ = &a; switch (a) { inline else => |val| { if (val != 0 and diff --git a/test/behavior/int128.zig b/test/behavior/int128.zig index 01e6bc42ac..7287cd1ab2 100644 --- a/test/behavior/int128.zig +++ b/test/behavior/int128.zig @@ -39,6 +39,7 @@ test "undefined 128 bit int" { var undef: u128 = undefined; var undef_signed: i128 = undefined; + _ = .{ &undef, &undef_signed }; try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @as(u128, @bitCast(undef_signed)) == undef); } @@ -73,6 +74,7 @@ test "truncate int128" { { var buff: u128 = maxInt(u128); + _ = &buff; try expect(@as(u64, @truncate(buff)) == maxInt(u64)); try expect(@as(u90, @truncate(buff)) == maxInt(u90)); try expect(@as(u128, @truncate(buff)) == maxInt(u128)); @@ -80,6 +82,7 @@ test "truncate int128" { { var buff: i128 = maxInt(i128); + _ = &buff; 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/int_comparison_elision.zig b/test/behavior/int_comparison_elision.zig index c384f62086..9ac9e1fca1 100644 --- a/test/behavior/int_comparison_elision.zig +++ b/test/behavior/int_comparison_elision.zig @@ -30,6 +30,7 @@ fn testIntEdges(comptime T: type) void { const max = maxInt(T); var runtime_val: T = undefined; + _ = &runtime_val; if (min > runtime_val) @compileError("analyzed impossible branch"); if (min <= runtime_val) {} else @compileError("analyzed impossible branch"); diff --git a/test/behavior/int_div.zig b/test/behavior/int_div.zig index 12368f0fba..bc570434ce 100644 --- a/test/behavior/int_div.zig +++ b/test/behavior/int_div.zig @@ -100,11 +100,13 @@ test "large integer division" { { var numerator: u256 = 99999999999999999997315645440; var divisor: u256 = 10000000000000000000000000000; + _ = .{ &numerator, &divisor }; try expect(numerator / divisor == 9); } { var numerator: u256 = 99999999999999999999000000000000000000000; var divisor: u256 = 10000000000000000000000000000000000000000; + _ = .{ &numerator, &divisor }; try expect(numerator / divisor == 9); } } diff --git a/test/behavior/math.zig b/test/behavior/math.zig index 3a5f753dd8..ab54c9e4a9 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -624,7 +624,8 @@ const DivResult = struct { test "bit shift a u1" { var x: u1 = 1; - var y = x << 0; + _ = &x; + const y = x << 0; try expect(y == 1); } @@ -692,7 +693,8 @@ test "128-bit multiplication" { { var a: u128 = 0xffffffffffffffff; var b: u128 = 100; - var c = a * b; + _ = .{ &a, &b }; + const c = a * b; try expect(c == 0x63ffffffffffffff9c); } } @@ -704,18 +706,21 @@ test "@addWithOverflow" { { var a: u8 = 250; + _ = &a; const ov = @addWithOverflow(a, 100); try expect(ov[0] == 94); try expect(ov[1] == 1); } { var a: u8 = 100; + _ = &a; const ov = @addWithOverflow(a, 150); try expect(ov[0] == 250); try expect(ov[1] == 0); } { var a: u8 = 200; + _ = &a; var b: u8 = 99; var ov = @addWithOverflow(a, b); try expect(ov[0] == 43); @@ -729,6 +734,7 @@ test "@addWithOverflow" { { var a: usize = 6; var b: usize = 6; + _ = .{ &a, &b }; const ov = @addWithOverflow(a, b); try expect(ov[0] == 12); try expect(ov[1] == 0); @@ -737,6 +743,7 @@ test "@addWithOverflow" { { var a: isize = -6; var b: isize = -6; + _ = .{ &a, &b }; const ov = @addWithOverflow(a, b); try expect(ov[0] == -12); try expect(ov[1] == 0); @@ -772,18 +779,21 @@ test "basic @mulWithOverflow" { { var a: u8 = 86; + _ = &a; const ov = @mulWithOverflow(a, 3); try expect(ov[0] == 2); try expect(ov[1] == 1); } { var a: u8 = 85; + _ = &a; const ov = @mulWithOverflow(a, 3); try expect(ov[0] == 255); try expect(ov[1] == 0); } var a: u8 = 123; + _ = &a; var b: u8 = 2; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 246); @@ -802,6 +812,7 @@ test "extensive @mulWithOverflow" { { var a: u5 = 3; + _ = &a; var b: u5 = 10; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 30); @@ -815,6 +826,7 @@ test "extensive @mulWithOverflow" { { var a: i5 = 3; + _ = &a; var b: i5 = -5; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -15); @@ -828,6 +840,7 @@ test "extensive @mulWithOverflow" { { var a: u8 = 3; + _ = &a; var b: u8 = 85; var ov = @mulWithOverflow(a, b); @@ -842,6 +855,7 @@ test "extensive @mulWithOverflow" { { var a: i8 = 3; + _ = &a; var b: i8 = -42; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -126); @@ -855,6 +869,7 @@ test "extensive @mulWithOverflow" { { var a: u14 = 3; + _ = &a; var b: u14 = 0x1555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0x3fff); @@ -868,6 +883,7 @@ test "extensive @mulWithOverflow" { { var a: i14 = 3; + _ = &a; var b: i14 = -0xaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x1ffe); @@ -880,6 +896,7 @@ test "extensive @mulWithOverflow" { { var a: u16 = 3; + _ = &a; var b: u16 = 0x5555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0xffff); @@ -893,6 +910,7 @@ test "extensive @mulWithOverflow" { { var a: i16 = 3; + _ = &a; var b: i16 = -0x2aaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x7ffe); @@ -906,6 +924,7 @@ test "extensive @mulWithOverflow" { { var a: u30 = 3; + _ = &a; var b: u30 = 0x15555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0x3fffffff); @@ -919,6 +938,7 @@ test "extensive @mulWithOverflow" { { var a: i30 = 3; + _ = &a; var b: i30 = -0xaaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x1ffffffe); @@ -932,6 +952,7 @@ test "extensive @mulWithOverflow" { { var a: u32 = 3; + _ = &a; var b: u32 = 0x55555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0xffffffff); @@ -945,6 +966,7 @@ test "extensive @mulWithOverflow" { { var a: i32 = 3; + _ = &a; var b: i32 = -0x2aaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x7ffffffe); @@ -967,6 +989,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: u62 = 3; + _ = &a; var b: u62 = 0x1555555555555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0x3fffffffffffffff); @@ -980,6 +1003,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: i62 = 3; + _ = &a; var b: i62 = -0xaaaaaaaaaaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x1ffffffffffffffe); @@ -993,6 +1017,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: u64 = 3; + _ = &a; var b: u64 = 0x5555555555555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0xffffffffffffffff); @@ -1006,6 +1031,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: i64 = 3; + _ = &a; var b: i64 = -0x2aaaaaaaaaaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x7ffffffffffffffe); @@ -1025,12 +1051,14 @@ test "@subWithOverflow" { { var a: u8 = 1; + _ = &a; const ov = @subWithOverflow(a, 2); try expect(ov[0] == 255); try expect(ov[1] == 1); } { var a: u8 = 1; + _ = &a; const ov = @subWithOverflow(a, 1); try expect(ov[0] == 0); try expect(ov[1] == 0); @@ -1038,6 +1066,7 @@ test "@subWithOverflow" { { var a: u8 = 1; + _ = &a; var b: u8 = 2; var ov = @subWithOverflow(a, b); try expect(ov[0] == 255); @@ -1051,6 +1080,7 @@ test "@subWithOverflow" { { var a: usize = 6; var b: usize = 6; + _ = .{ &a, &b }; const ov = @subWithOverflow(a, b); try expect(ov[0] == 0); try expect(ov[1] == 0); @@ -1059,6 +1089,7 @@ test "@subWithOverflow" { { var a: isize = -6; var b: isize = -6; + _ = .{ &a, &b }; const ov = @subWithOverflow(a, b); try expect(ov[0] == 0); try expect(ov[1] == 0); @@ -1072,6 +1103,7 @@ test "@shlWithOverflow" { { var a: u4 = 2; + _ = &a; var b: u2 = 1; var ov = @shlWithOverflow(a, b); try expect(ov[0] == 4); @@ -1085,6 +1117,7 @@ test "@shlWithOverflow" { { var a: i9 = 127; + _ = &a; var b: u4 = 1; var ov = @shlWithOverflow(a, b); try expect(ov[0] == 254); @@ -1108,6 +1141,7 @@ test "@shlWithOverflow" { } { var a: u16 = 0b0000_0000_0000_0011; + _ = &a; var b: u4 = 15; var ov = @shlWithOverflow(a, b); try expect(ov[0] == 0b1000_0000_0000_0000); @@ -1124,24 +1158,28 @@ test "overflow arithmetic with u0 values" { { var a: u0 = 0; + _ = &a; const ov = @addWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); } { var a: u0 = 0; + _ = &a; const ov = @subWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); } { var a: u0 = 0; + _ = &a; const ov = @mulWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); } { var a: u0 = 0; + _ = &a; const ov = @shlWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); @@ -1157,6 +1195,7 @@ test "allow signed integer division/remainder when values are comptime-known and try expect(-6 % 3 == 0); var undef: i32 = undefined; + _ = &undef; if (0 % undef != 0) { @compileError("0 as numerator should return comptime zero independent of denominator"); } @@ -1183,18 +1222,22 @@ test "quad hex float literal parsing accurate" { fn doTheTest() !void { { var f: f128 = 0x1.2eab345678439abcdefea56782346p+5; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234); } { var f: f128 = 0x1.edcb34a235253948765432134674fp-1; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even } { var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50); } { var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568); } const exp2ft = [_]f64{ @@ -1294,6 +1337,7 @@ test "shift left/right on u0 operand" { fn doTheTest() !void { var x: u0 = 0; var y: u0 = 0; + _ = .{ &x, &y }; try expectEqual(@as(u0, 0), x << 0); try expectEqual(@as(u0, 0), x >> 0); try expectEqual(@as(u0, 0), x << y); @@ -1310,7 +1354,7 @@ test "shift left/right on u0 operand" { test "comptime float rem int" { comptime { - var x = @as(f32, 1) % 2; + const x = @as(f32, 1) % 2; try expect(x == 1.0); } } @@ -1511,7 +1555,8 @@ test "vector integer addition" { fn doTheTest() !void { var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; - var result = a + b; + _ = .{ &a, &b }; + const result = a + b; var result_array: [4]i32 = result; const expected = [_]i32{ 6, 8, 10, 12 }; try expectEqualSlices(i32, &expected, &result_array); @@ -1552,6 +1597,7 @@ test "NaN comparison f80" { fn testNanEqNan(comptime F: type) !void { var nan1 = math.nan(F); var nan2 = math.nan(F); + _ = .{ &nan1, &nan2 }; try expect(nan1 != nan2); try expect(!(nan1 == nan2)); try expect(!(nan1 > nan2)); @@ -1571,6 +1617,7 @@ test "vector comparison" { fn doTheTest() !void { var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 }; var b: @Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 }; + _ = .{ &a, &b }; try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false })); try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false })); try expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false })); @@ -1609,7 +1656,8 @@ 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 = @as(ST, @bitCast(as_fp_val)); + _ = &as_fp_val; + const as_uint_val: 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/maximum_minimum.zig b/test/behavior/maximum_minimum.zig index 7d19f1dcdc..f7cb1ee513 100644 --- a/test/behavior/maximum_minimum.zig +++ b/test/behavior/maximum_minimum.zig @@ -15,6 +15,7 @@ test "@max" { var x: i32 = 10; var y: f32 = 0.68; var nan: f32 = std.math.nan(f32); + _ = .{ &x, &y, &nan }; try expect(@as(i32, 10) == @max(@as(i32, -3), x)); try expect(@as(f32, 3.2) == @max(@as(f32, 3.2), y)); try expect(y == @max(nan, y)); @@ -38,17 +39,20 @@ test "@max on vectors" { fn doTheTest() !void { var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; - var x = @max(a, b); + const x = @max(a, b); + _ = .{ &a, &b }; try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 2147483647, 2147483647, 30, 40 })); var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 }; - var y = @max(c, d); + const y = @max(c, d); + _ = .{ &c, &d }; try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ 0, 0.42, -0.64, 7.8 })); var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 }; - var z = @max(e, f); + const z = @max(e, f); + _ = .{ &e, &f }; try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 })); } }; @@ -66,6 +70,7 @@ test "@min" { var x: i32 = 10; var y: f32 = 0.68; var nan: f32 = std.math.nan(f32); + _ = .{ &x, &y, &nan }; try expect(@as(i32, -3) == @min(@as(i32, -3), x)); try expect(@as(f32, 0.68) == @min(@as(f32, 3.2), y)); try expect(y == @min(nan, y)); @@ -89,17 +94,20 @@ test "@min for vectors" { fn doTheTest() !void { var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; - var x = @min(a, b); + _ = .{ &a, &b }; + const x = @min(a, b); try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 1, -2, 3, 4 })); var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 }; - var y = @min(c, d); + _ = .{ &c, &d }; + const y = @min(c, d); try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ -0.23, 0.4, -2.4, 0.9 })); var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 }; - var z = @max(e, f); + _ = .{ &e, &f }; + const z = @max(e, f); try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 })); } }; @@ -119,6 +127,7 @@ test "@min/max for floats" { fn doTheTest(comptime T: type) !void { var x: T = -3.14; var y: T = 5.27; + _ = .{ &x, &y }; try expectEqual(x, @min(x, y)); try expectEqual(x, @min(y, x)); try expectEqual(y, @max(x, y)); @@ -126,6 +135,7 @@ test "@min/max for floats" { if (T != comptime_float) { var nan: T = std.math.nan(T); + _ = &nan; try expectEqual(y, @max(nan, y)); try expectEqual(y, @max(y, nan)); } @@ -175,6 +185,7 @@ test "@min/@max notices bounds" { var x: u16 = 20; const y = 30; var z: u32 = 100; + _ = .{ &x, &z }; const min = @min(x, y, z); const max = @max(x, y, z); try expectEqual(x, min); @@ -194,6 +205,7 @@ test "@min/@max notices vector bounds" { var x: @Vector(2, u16) = .{ 140, 40 }; const y: @Vector(2, u64) = .{ 5, 100 }; var z: @Vector(2, u32) = .{ 10, 300 }; + _ = .{ &x, &z }; const min = @min(x, y, z); const max = @max(x, y, z); try expectEqual(@Vector(2, u32){ 5, 40 }, min); @@ -224,6 +236,7 @@ test "@min/@max notices bounds from types" { var x: u16 = 123; var y: u32 = 456; var z: u8 = 10; + _ = .{ &x, &y, &z }; const min = @min(x, y, z); const max = @max(x, y, z); @@ -246,6 +259,7 @@ test "@min/@max notices bounds from vector types" { var x: @Vector(2, u16) = .{ 30, 67 }; var y: @Vector(2, u32) = .{ 20, 500 }; var z: @Vector(2, u8) = .{ 60, 15 }; + _ = .{ &x, &y, &z }; const min = @min(x, y, z); const max = @max(x, y, z); @@ -263,6 +277,7 @@ test "@min/@max notices bounds from types when comptime-known value is undef" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 1_000_000; + _ = &x; const y: u16 = undefined; // y is comptime-known, but is undef, so bounds cannot be refined using its value @@ -285,6 +300,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx)) return error.SkipZigTest; var x: @Vector(2, u32) = .{ 1_000_000, 12345 }; + _ = &x; const y: @Vector(2, u16) = .{ 10, undefined }; // y is comptime-known, but an element is undef, so bounds cannot be refined using its value @@ -302,6 +318,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known test "@min/@max of signed and unsigned runtime integers" { var x: i32 = -1; var y: u31 = 1; + _ = .{ &x, &y }; const min = @min(x, y); const max = @max(x, y); diff --git a/test/behavior/memcpy.zig b/test/behavior/memcpy.zig index 8d9880ccb0..33f6c0f34c 100644 --- a/test/behavior/memcpy.zig +++ b/test/behavior/memcpy.zig @@ -57,6 +57,7 @@ fn testMemcpyDestManyPtr() !void { var str = "hello".*; var buf: [5]u8 = undefined; var len: usize = 5; + _ = &len; @memcpy(@as([*]u8, @ptrCast(&buf)), @as([*]const u8, @ptrCast(&str))[0..len]); try expect(buf[0] == 'h'); try expect(buf[1] == 'e'); diff --git a/test/behavior/memset.zig b/test/behavior/memset.zig index e3cf646f87..966443f9cc 100644 --- a/test/behavior/memset.zig +++ b/test/behavior/memset.zig @@ -46,7 +46,8 @@ fn testMemsetSlice() !void { // memset slice to non-undefined, ABI size == 1 var array: [20]u8 = undefined; var len = array.len; - var slice = array[0..len]; + _ = &len; + const slice = array[0..len]; @memset(slice, 'A'); try expect(slice[0] == 'A'); try expect(slice[11] == 'A'); @@ -56,7 +57,8 @@ fn testMemsetSlice() !void { // memset slice to non-undefined, ABI size > 1 var array: [20]u32 = undefined; var len = array.len; - var slice = array[0..len]; + _ = &len; + const slice = array[0..len]; @memset(slice, 1234); try expect(slice[0] == 1234); try expect(slice[11] == 1234); @@ -111,6 +113,7 @@ test "memset with large array element, runtime known" { const A = [128]u64; var buf: [5]A = undefined; var runtime_known_element = [_]u64{0} ** 128; + _ = &runtime_known_element; @memset(&buf, runtime_known_element); for (buf[0]) |elem| try expect(elem == 0); for (buf[1]) |elem| try expect(elem == 0); diff --git a/test/behavior/muladd.zig b/test/behavior/muladd.zig index b17c95a24e..3bdba835f9 100644 --- a/test/behavior/muladd.zig +++ b/test/behavior/muladd.zig @@ -21,12 +21,14 @@ fn testMulAdd() !void { var a: f32 = 5.5; var b: f32 = 2.5; var c: f32 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f32, a, b, c) == 20); } { var a: f64 = 5.5; var b: f64 = 2.5; var c: f64 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f64, a, b, c) == 20); } } @@ -46,6 +48,7 @@ fn testMulAdd16() !void { var a: f16 = 5.5; var b: f16 = 2.5; var c: f16 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f16, a, b, c) == 20); } @@ -65,6 +68,7 @@ fn testMulAdd80() !void { var a: f16 = 5.5; var b: f80 = 2.5; var c: f80 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f80, a, b, c) == 20); } @@ -84,6 +88,7 @@ fn testMulAdd128() !void { var a: f16 = 5.5; var b: f128 = 2.5; var c: f128 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f128, a, b, c) == 20); } @@ -91,7 +96,8 @@ fn vector16() !void { var a = @Vector(4, f16){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f16){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f16){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f16), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f16), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); @@ -115,7 +121,8 @@ fn vector32() !void { var a = @Vector(4, f32){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f32){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f32){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f32), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f32), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); @@ -139,7 +146,8 @@ fn vector64() !void { var a = @Vector(4, f64){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f64){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f64){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f64), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f64), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); @@ -163,7 +171,8 @@ fn vector80() !void { var a = @Vector(4, f80){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f80){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f80){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f80), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f80), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); try expect(x[2] == 20); @@ -187,7 +196,8 @@ fn vector128() !void { var a = @Vector(4, f128){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f128){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f128){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f128), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f128), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); diff --git a/test/behavior/null.zig b/test/behavior/null.zig index 3fe6e663e1..20afa21cb8 100644 --- a/test/behavior/null.zig +++ b/test/behavior/null.zig @@ -134,6 +134,7 @@ test "optional pointer to 0 bit type null value at runtime" { const EmptyStruct = struct {}; var x: ?*EmptyStruct = null; + _ = &x; try expect(x == null); } diff --git a/test/behavior/optional.zig b/test/behavior/optional.zig index 648b698842..d6dd27db3b 100644 --- a/test/behavior/optional.zig +++ b/test/behavior/optional.zig @@ -11,7 +11,7 @@ test "passing an optional integer as a parameter" { const S = struct { fn entry() bool { - var x: i32 = 1234; + const x: i32 = 1234; return foo(x); } @@ -29,7 +29,7 @@ test "optional pointer to size zero struct" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var e = EmptyStruct{}; - var o: ?*EmptyStruct = &e; + const o: ?*EmptyStruct = &e; try expect(o != null); } @@ -63,6 +63,7 @@ test "optional with void type" { x: ?void, }; var x = Foo{ .x = null }; + _ = &x; try expect(x.x == null); } @@ -102,6 +103,7 @@ test "nested optional field in struct" { var s = S1{ .x = S2{ .y = 127 }, }; + _ = &s; try expect(s.x.?.y == 127); } @@ -120,6 +122,8 @@ fn test_cmp_optional_non_optional() !void { var five: i32 = 5; var int_n: ?i32 = null; + _ = .{ &ten, &opt_ten, &five, &int_n }; + try expect(int_n != ten); try expect(opt_ten == ten); try expect(opt_ten != five); @@ -208,7 +212,7 @@ test "self-referential struct through a slice of optional" { }; }; - var n = S.Node.new(); + const n = S.Node.new(); try expect(n.data == null); } @@ -252,7 +256,7 @@ test "0-bit child type coerced to optional return ptr result location" { const S = struct { fn doTheTest() !void { var y = Foo{}; - var z = y.thing(); + const z = y.thing(); try expect(z != null); } @@ -425,6 +429,7 @@ test "alignment of wrapping an optional payload" { fn foo() ?I { var i: I = .{ .x = 1234 }; + _ = &i; return i; } }; @@ -450,15 +455,16 @@ test "peer type resolution in nested if expressions" { const Thing = struct { n: i32 }; var a = false; var b = false; + _ = .{ &a, &b }; - var result1 = if (a) + const result1 = if (a) Thing{ .n = 1 } else null; try expect(result1 == null); try expect(@TypeOf(result1) == ?Thing); - var result2 = if (a) + const result2 = if (a) Thing{ .n = 0 } else if (b) Thing{ .n = 1 } @@ -486,5 +492,6 @@ test "cast slice to const slice nested in error union and optional" { test "variable of optional of noreturn" { var null_opv: ?noreturn = null; + _ = &null_opv; try std.testing.expectEqual(@as(?noreturn, null), null_opv); } diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig index a8665a02ea..60e8d6d93a 100644 --- a/test/behavior/packed-struct.zig +++ b/test/behavior/packed-struct.zig @@ -479,10 +479,9 @@ test "load pointer from packed struct" { y: u32, }; var a: A = .{ .index = 123 }; - var b_list: []const B = &.{.{ .x = &a, .y = 99 }}; + const b_list: []const B = &.{.{ .x = &a, .y = 99 }}; for (b_list) |b| { - var i = b.x.index; - try expect(i == 123); + try expect(b.x.index == 123); } } @@ -770,6 +769,7 @@ test "nested packed struct field access test" { }; var arg = a{ .b = hld{ .c = 1, .d = 2 }, .g = mld{ .h = 6, .i = 8 } }; + _ = &arg; try std.testing.expect(arg.b.c == 1); try std.testing.expect(arg.b.d == 2); try std.testing.expect(arg.g.h == 6); @@ -790,6 +790,7 @@ test "nested packed struct at non-zero offset" { }; var k: u8 = 123; + _ = &k; var v: A = .{ .p1 = .{ .a = k + 1, .b = k }, .p2 = .{ .a = k + 1, .b = k }, @@ -833,6 +834,7 @@ test "nested packed struct at non-zero offset 2" { fn doTheTest() !void { var k: u8 = 123; + _ = &k; var v: A = .{ .p1 = .{ .a = k + 1, .b = k }, .p2 = .{ .a = k + 1, .b = k }, @@ -877,6 +879,7 @@ test "runtime init of unnamed packed struct type" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var z: u8 = 123; + _ = &z; try (packed struct { x: u8, pub fn m(s: @This()) !void { @@ -941,6 +944,7 @@ test "packed struct initialized in bitcast" { const T = packed struct { val: u8 }; var val: u8 = 123; + _ = &val; const t = @as(u8, @bitCast(T{ .val = val })); try expect(t == val); } @@ -976,7 +980,8 @@ test "store undefined to packed result location" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u4 = 0; - var s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined }; + _ = &x; + const s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined }; try expectEqual(x, s.x); } @@ -1004,7 +1009,7 @@ test "field access of packed struct smaller than its abi size inside struct init } }; - var s = S.init(true); + const s = S.init(true); // note: this bug is triggered by the == operator, expectEqual will hide it try expect(@as(i2, 0) == s.ps.x); try expect(@as(i2, 1) == s.ps.y); diff --git a/test/behavior/pointers.zig b/test/behavior/pointers.zig index 52e3e68c3f..3e3e67cc4e 100644 --- a/test/behavior/pointers.zig +++ b/test/behavior/pointers.zig @@ -11,7 +11,7 @@ test "dereference pointer" { fn testDerefPtr() !void { var x: i32 = 1234; - var y = &x; + const y = &x; y.* += 1; try expect(x == 1235); } @@ -53,8 +53,8 @@ test "implicit cast single item pointer to C pointer and back" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var y: u8 = 11; - var x: [*c]u8 = &y; - var z: *u8 = x; + const x: [*c]u8 = &y; + const z: *u8 = x; z.* += 1; try expect(y == 12); } @@ -74,6 +74,7 @@ test "assigning integer to C pointer" { var ptr2: [*c]u8 = x; var ptr3: [*c]u8 = 1; var ptr4: [*c]u8 = y; + _ = .{ &x, &y, &ptr, &ptr2, &ptr3, &ptr4 }; try expect(ptr == ptr2); try expect(ptr3 == ptr4); @@ -88,6 +89,7 @@ test "C pointer comparison and arithmetic" { fn doTheTest() !void { var ptr1: [*c]u32 = 0; var ptr2 = ptr1 + 10; + _ = &ptr1; try expect(ptr1 == 0); try expect(ptr1 >= 0); try expect(ptr1 <= 0); @@ -125,14 +127,15 @@ fn testDerefPtrOneVal() !void { } test "peer type resolution with C pointers" { - var ptr_one: *u8 = undefined; - var ptr_many: [*]u8 = undefined; - var ptr_c: [*c]u8 = undefined; + const ptr_one: *u8 = undefined; + const ptr_many: [*]u8 = undefined; + const ptr_c: [*c]u8 = undefined; var t = true; - var x1 = if (t) ptr_one else ptr_c; - var x2 = if (t) ptr_many else ptr_c; - var x3 = if (t) ptr_c else ptr_one; - var x4 = if (t) ptr_c else ptr_many; + _ = &t; + const x1 = if (t) ptr_one else ptr_c; + const x2 = if (t) ptr_many else ptr_c; + const x3 = if (t) ptr_c else ptr_one; + const x4 = if (t) ptr_c else ptr_many; try expect(@TypeOf(x1) == [*c]u8); try expect(@TypeOf(x2) == [*c]u8); try expect(@TypeOf(x3) == [*c]u8); @@ -141,8 +144,9 @@ test "peer type resolution with C pointers" { test "peer type resolution with C pointer and const pointer" { var ptr_c: [*c]u8 = undefined; - const ptr_const: u8 = undefined; - try expect(@TypeOf(ptr_c, &ptr_const) == [*c]const u8); + var ptr_const: *const u8 = &undefined; + _ = .{ &ptr_c, &ptr_const }; + try expect(@TypeOf(ptr_c, ptr_const) == [*c]const u8); } test "implicit casting between C pointer and optional non-C pointer" { @@ -151,9 +155,10 @@ test "implicit casting between C pointer and optional non-C pointer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var slice: []const u8 = "aoeu"; + _ = &slice; const opt_many_ptr: ?[*]const u8 = slice.ptr; var ptr_opt_many_ptr = &opt_many_ptr; - var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; + const c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; try expect(c_ptr.*.* == 'a'); ptr_opt_many_ptr = c_ptr; try expect(ptr_opt_many_ptr.*.?[1] == 'o'); @@ -192,11 +197,12 @@ test "allowzero pointer and slice" { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - var ptr = @as([*]allowzero i32, @ptrFromInt(0)); - var opt_ptr: ?[*]allowzero i32 = ptr; + var ptr: [*]allowzero i32 = @ptrFromInt(0); + const opt_ptr: ?[*]allowzero i32 = ptr; try expect(opt_ptr != null); try expect(@intFromPtr(ptr) == 0); var runtime_zero: usize = 0; + _ = &runtime_zero; var slice = ptr[runtime_zero..10]; try comptime expect(@TypeOf(slice) == []allowzero i32); try expect(@intFromPtr(&slice[5]) == 20); @@ -211,6 +217,7 @@ test "assign null directly to C pointer and test null equality" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: [*c]i32 = null; + _ = &x; try expect(x == null); try expect(null == x); try expect(!(x != null)); @@ -236,7 +243,7 @@ test "assign null directly to C pointer and test null equality" { try comptime expect((y orelse ptr_othery) == ptr_othery); var n: i32 = 1234; - var x1: [*c]i32 = &n; + const x1: [*c]i32 = &n; try expect(!(x1 == null)); try expect(!(null == x1)); try expect(x1 != null); @@ -279,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 = @as([*:0]const u8, @ptrCast(&array_with_zero)); - var no_zero_ptr: [*]const u8 = zero_ptr; - var zero_ptr_again = @as([*:0]const u8, @ptrCast(no_zero_ptr)); + const zero_ptr: [*:0]const u8 = @ptrCast(&array_with_zero); + const no_zero_ptr: [*]const u8 = zero_ptr; + const zero_ptr_again: [*:0]const u8 = @ptrCast(no_zero_ptr); try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello")); } }; @@ -296,7 +303,7 @@ test "allow any sentinel" { const S = struct { fn doTheTest() !void { var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 }; - var ptr: [*:std.math.minInt(i32)]i32 = &array; + const ptr: [*:std.math.minInt(i32)]i32 = &array; try expect(ptr[4] == std.math.minInt(i32)); } }; @@ -317,6 +324,7 @@ test "pointer sentinel with enums" { fn doTheTest() !void { var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; + _ = &ptr; try expect(ptr[4] == .sentinel); // TODO this should be try comptime expect, see #3731 } }; @@ -332,6 +340,7 @@ test "pointer sentinel with optional element" { const S = struct { fn doTheTest() !void { var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; + _ = &ptr; try expect(ptr[4] == null); // TODO this should be try comptime expect, see #3731 } }; @@ -348,6 +357,7 @@ test "pointer sentinel with +inf" { fn doTheTest() !void { const inf_f32 = comptime std.math.inf(f32); var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 }; + _ = &ptr; try expect(ptr[4] == inf_f32); // TODO this should be try comptime expect, see #3731 } }; @@ -366,6 +376,7 @@ test "pointer arithmetic affects the alignment" { { var ptr: [*]align(8) u32 = undefined; var x: usize = 1; + _ = .{ &ptr, &x }; try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8); const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4 @@ -380,6 +391,7 @@ test "pointer arithmetic affects the alignment" { { var ptr: [*]align(8) [3]u8 = undefined; var x: usize = 1; + _ = .{ &ptr, &x }; const ptr1 = ptr + 17; // 3 * 17 = 51 try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1); @@ -467,8 +479,8 @@ test "array slicing to slice" { const S = struct { fn doTheTest() !void { var str: [5]i32 = [_]i32{ 1, 2, 3, 4, 5 }; - var sub: *[2]i32 = str[1..3]; - var slice: []i32 = sub; // used to cause failures + const sub: *[2]i32 = str[1..3]; + const slice: []i32 = sub; // used to cause failures try testing.expect(slice.len == 2); try testing.expect(slice[0] == 2); } @@ -495,7 +507,8 @@ test "ptrCast comptime known slice to C pointer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO const s: [:0]const u8 = "foo"; - var p = @as([*c]const u8, @ptrCast(s)); + var p: [*c]const u8 = @ptrCast(s); + _ = &p; try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0)); } @@ -527,6 +540,7 @@ test "pointer to array has explicit alignment" { test "result type preserved through multiple references" { const S = struct { x: u32 }; var my_u64: u64 = 12345; + _ = &my_u64; const foo: *const *const *const S = &&&.{ .x = @intCast(my_u64), }; diff --git a/test/behavior/popcount.zig b/test/behavior/popcount.zig index eda7346a2d..261019c65f 100644 --- a/test/behavior/popcount.zig +++ b/test/behavior/popcount.zig @@ -26,6 +26,7 @@ test "@popCount 128bit integer" { { var x: u128 = 0b11111111000110001100010000100001000011000011100101010001; + _ = &x; try expect(@popCount(x) == 24); } @@ -35,30 +36,37 @@ test "@popCount 128bit integer" { fn testPopCountIntegers() !void { { var x: u32 = 0xffffffff; + _ = &x; try expect(@popCount(x) == 32); } { var x: u5 = 0x1f; + _ = &x; try expect(@popCount(x) == 5); } { var x: u32 = 0xaa; + _ = &x; try expect(@popCount(x) == 4); } { var x: u32 = 0xaaaaaaaa; + _ = &x; try expect(@popCount(x) == 16); } { var x: u32 = 0xaaaaaaaa; + _ = &x; try expect(@popCount(x) == 16); } { var x: i16 = -1; + _ = &x; try expect(@popCount(x) == 16); } { var x: i8 = -120; + _ = &x; try expect(@popCount(x) == 2); } comptime { @@ -81,12 +89,14 @@ test "@popCount vectors" { fn testPopCountVectors() !void { { var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8; + _ = &x; const expected = [1]u6{32} ** 8; const result: [8]u6 = @popCount(x); try expect(std.mem.eql(u6, &expected, &result)); } { var x: @Vector(8, i16) = [1]i16{-1} ** 8; + _ = &x; const expected = [1]u5{16} ** 8; const result: [8]u5 = @popCount(x); try expect(std.mem.eql(u5, &expected, &result)); diff --git a/test/behavior/prefetch.zig b/test/behavior/prefetch.zig index d4baa649d0..e98e848393 100644 --- a/test/behavior/prefetch.zig +++ b/test/behavior/prefetch.zig @@ -6,6 +6,7 @@ test "@prefetch()" { var a: [2]u32 = .{ 42, 42 }; var a_len = a.len; + _ = &a_len; @prefetch(&a, .{}); diff --git a/test/behavior/ptrcast.zig b/test/behavior/ptrcast.zig index 635a4df843..4e9283b3a4 100644 --- a/test/behavior/ptrcast.zig +++ b/test/behavior/ptrcast.zig @@ -71,8 +71,8 @@ fn testReinterpretBytesAsExternStruct() !void { c: u8, }; - var ptr = @as(*const S, @ptrCast(&bytes)); - var val = ptr.c; + const ptr: *const S = @ptrCast(&bytes); + const val = ptr.c; try expect(val == 5); } @@ -95,8 +95,8 @@ fn testReinterpretExternStructAsExternStruct() !void { a: u32 align(2), c: u8, }; - var ptr = @as(*const S2, @ptrCast(&bytes)); - var val = ptr.c; + const ptr: *const S2 = @ptrCast(&bytes); + const val = ptr.c; try expect(val == 5); } @@ -121,8 +121,8 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void { a2: u16, c: u8, }; - var ptr = @as(*const S2, @ptrCast(&bytes)); - var val = ptr.c; + const ptr: *const S2 = @ptrCast(&bytes); + const val = ptr.c; try expect(val == 5); } @@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" { c: u8, }; comptime var ptr = @as(*const S, @ptrCast(&bytes)); - var val = &ptr.c; + const val = &ptr.c; try expect(val.* == 5); // Test lowering an elem ptr comptime var src_value = S{ .a = 15, .c = 5 }; comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); - var val2 = &ptr2[4]; + const val2 = &ptr2[4]; try expect(val2.* == 5); } @@ -160,13 +160,13 @@ test "lower reinterpreted comptime field ptr" { c: u8, }; comptime var ptr = @as(*const S, @ptrCast(&bytes)); - var val = &ptr.c; + const val = &ptr.c; try expect(val.* == 5); // Test lowering an elem ptr comptime var src_value = S{ .a = 15, .c = 5 }; comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); - var val2 = &ptr2[4]; + const val2 = &ptr2[4]; try expect(val2.* == 5); } @@ -233,9 +233,9 @@ test "implicit optional pointer to optional anyopaque pointer" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO var buf: [4]u8 = "aoeu".*; - var x: ?[*]u8 = &buf; - var y: ?*anyopaque = x; - var z = @as(*[4]u8, @ptrCast(y)); + const x: ?[*]u8 = &buf; + const y: ?*anyopaque = x; + const z: *[4]u8 = @ptrCast(y); try expect(std.mem.eql(u8, z, "aoeu")); } @@ -276,7 +276,7 @@ test "@ptrCast undefined value at comptime" { } }; comptime { - var x = S.transmute([]u8, i32, undefined); + const x = S.transmute([]u8, i32, undefined); _ = x; } } diff --git a/test/behavior/ptrfromint.zig b/test/behavior/ptrfromint.zig index 72244aa7d1..89706be891 100644 --- a/test/behavior/ptrfromint.zig +++ b/test/behavior/ptrfromint.zig @@ -9,6 +9,7 @@ test "casting integer address to function pointer" { fn addressToFunction() void { var addr: usize = 0xdeadbee0; + _ = &addr; _ = @as(*const fn () void, @ptrFromInt(addr)); } diff --git a/test/behavior/saturating_arithmetic.zig b/test/behavior/saturating_arithmetic.zig index 30d1aa712e..82d10d9540 100644 --- a/test/behavior/saturating_arithmetic.zig +++ b/test/behavior/saturating_arithmetic.zig @@ -246,9 +246,11 @@ test "saturating shl uses the LHS type" { const lhs_const: u8 = 1; var lhs_var: u8 = 1; + _ = &lhs_var; const rhs_const: usize = 8; var rhs_var: usize = 8; + _ = &rhs_var; try expect((lhs_const <<| 8) == 255); try expect((lhs_const <<| rhs_const) == 255); diff --git a/test/behavior/select.zig b/test/behavior/select.zig index 66cc0a49b0..de717e5e5b 100644 --- a/test/behavior/select.zig +++ b/test/behavior/select.zig @@ -19,7 +19,8 @@ fn selectVectors() !void { var a = @Vector(4, bool){ true, false, true, false }; var b = @Vector(4, i32){ -1, 4, 999, -31 }; var c = @Vector(4, i32){ -5, 1, 0, 1234 }; - var abc = @select(i32, a, b, c); + _ = .{ &a, &b, &c }; + const abc = @select(i32, a, b, c); try expect(abc[0] == -1); try expect(abc[1] == 1); try expect(abc[2] == 999); @@ -28,7 +29,8 @@ fn selectVectors() !void { var x = @Vector(4, bool){ false, false, false, true }; var y = @Vector(4, f32){ 0.001, 33.4, 836, -3381.233 }; var z = @Vector(4, f32){ 0.0, 312.1, -145.9, 9993.55 }; - var xyz = @select(f32, x, y, z); + _ = .{ &x, &y, &z }; + const xyz = @select(f32, x, y, z); try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); } @@ -48,7 +50,8 @@ fn selectArrays() !void { var a = [4]bool{ false, true, false, true }; var b = [4]usize{ 0, 1, 2, 3 }; var c = [4]usize{ 4, 5, 6, 7 }; - var abc = @select(usize, a, b, c); + _ = .{ &a, &b, &c }; + const abc = @select(usize, a, b, c); try expect(abc[0] == 4); try expect(abc[1] == 1); try expect(abc[2] == 6); @@ -57,6 +60,7 @@ fn selectArrays() !void { var x = [4]bool{ false, false, false, true }; var y = [4]f32{ 0.001, 33.4, 836, -3381.233 }; var z = [4]f32{ 0.0, 312.1, -145.9, 9993.55 }; - var xyz = @select(f32, x, y, z); + _ = .{ &x, &y, &z }; + const xyz = @select(f32, x, y, z); try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); } diff --git a/test/behavior/shuffle.zig b/test/behavior/shuffle.zig index 6137c66f1f..e9d7706ff4 100644 --- a/test/behavior/shuffle.zig +++ b/test/behavior/shuffle.zig @@ -13,7 +13,9 @@ test "@shuffle int" { const S = struct { fn doTheTest() !void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; + _ = &v; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; + _ = &x; const mask = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; var res = @shuffle(i32, v, x, mask); try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 })); @@ -29,12 +31,14 @@ test "@shuffle int" { // Upcasting of b var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; + _ = &v2; const mask3 = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; res = @shuffle(i32, x, v2, mask3); try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 })); // Upcasting of a var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; + _ = &v3; const mask4 = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; res = @shuffle(i32, v3, x, mask4); try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 })); @@ -55,9 +59,11 @@ test "@shuffle bool 1" { const S = struct { fn doTheTest() !void { var x: @Vector(4, bool) = [4]bool{ false, true, false, true }; + _ = &x; var v: @Vector(2, bool) = [2]bool{ true, false }; + _ = &v; const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; - var res = @shuffle(bool, x, v, mask); + const res = @shuffle(bool, x, v, mask); try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false })); } }; @@ -81,9 +87,11 @@ test "@shuffle bool 2" { const S = struct { fn doTheTest() !void { var x: @Vector(3, bool) = [3]bool{ false, true, false }; + _ = &x; var v: @Vector(2, bool) = [2]bool{ true, false }; + _ = &v; const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; - var res = @shuffle(bool, x, v, mask); + const res = @shuffle(bool, x, v, mask); try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false })); } }; diff --git a/test/behavior/sizeof_and_typeof.zig b/test/behavior/sizeof_and_typeof.zig index 74b02d7fdb..00f891a70f 100644 --- a/test/behavior/sizeof_and_typeof.zig +++ b/test/behavior/sizeof_and_typeof.zig @@ -22,20 +22,24 @@ test "@TypeOf() with multiple arguments" { var var_1: u32 = undefined; var var_2: u8 = undefined; var var_3: u64 = undefined; + _ = .{ &var_1, &var_2, &var_3 }; try comptime expect(@TypeOf(var_1, var_2, var_3) == u64); } { var var_1: f16 = undefined; var var_2: f32 = undefined; var var_3: f64 = undefined; + _ = .{ &var_1, &var_2, &var_3 }; try comptime expect(@TypeOf(var_1, var_2, var_3) == f64); } { var var_1: u16 = undefined; + _ = &var_1; try comptime expect(@TypeOf(var_1, 0xffff) == u16); } { var var_1: f32 = undefined; + _ = &var_1; try comptime expect(@TypeOf(var_1, 3.1415) == f32); } } @@ -269,6 +273,7 @@ test "runtime instructions inside typeof in comptime only scope" { { var y: i8 = 2; + _ = &y; const i: [2]i8 = [_]i8{ 1, y }; const T = struct { a: @TypeOf(i) = undefined, // causes crash @@ -279,6 +284,7 @@ test "runtime instructions inside typeof in comptime only scope" { } { var y: i8 = 2; + _ = &y; const i = .{ 1, y }; const T = struct { b: @TypeOf(i[1]) = undefined, diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig index c95bc293ef..7ceabf05cf 100644 --- a/test/behavior/slice.zig +++ b/test/behavior/slice.zig @@ -23,7 +23,7 @@ comptime { }; const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong }; const list: []const type = &unsigned; - var pos = S.indexOfScalar(type, list, c_ulong).?; + const pos = S.indexOfScalar(type, list, c_ulong).?; if (pos != 1) @compileError("bad pos"); } @@ -36,13 +36,14 @@ test "slicing" { var slice = array[5..10]; - if (slice.len != 5) unreachable; + try expect(slice.len == 5); const ptr = &slice[0]; - if (ptr.* != 1234) unreachable; + try expect(ptr.* == 1234); var slice_rest = array[10..]; - if (slice_rest.len != 10) unreachable; + _ = &slice_rest; + try expect(slice_rest.len == 10); } test "const slice" { @@ -79,7 +80,7 @@ test "access len index of sentinel-terminated slice" { const S = struct { fn doTheTest() !void { var slice: [:0]const u8 = "hello"; - + _ = &slice; try expect(slice.len == 5); try expect(slice[5] == 0); } @@ -208,6 +209,7 @@ test "slice string literal has correct type" { try expect(@TypeOf(array[0..]) == *const [4]i32); } var runtime_zero: usize = 0; + _ = &runtime_zero; try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8); const array = [_]i32{ 1, 2, 3, 4 }; try comptime expect(@TypeOf(array[runtime_zero..]) == []const i32); @@ -219,7 +221,8 @@ test "result location zero sized array inside struct field implicit cast to slic const E = struct { entries: []u32, }; - var foo = E{ .entries = &[_]u32{} }; + var foo: E = .{ .entries = &[_]u32{} }; + _ = &foo; try expect(foo.entries.len == 0); } @@ -242,7 +245,8 @@ test "C pointer" { var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf"; var len: u32 = 10; - var slice = buf[0..len]; + _ = &len; + const slice = buf[0..len]; try expect(mem.eql(u8, "kjdhfkjdhf", slice)); } @@ -255,6 +259,7 @@ test "C pointer slice access" { const c_ptr = @as([*c]const u32, @ptrCast(&buf)); var runtime_zero: usize = 0; + _ = &runtime_zero; try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1])); try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1])); @@ -306,11 +311,13 @@ test "obtaining a null terminated slice" { _ = ptr; var runtime_len: usize = 3; + _ = &runtime_len; const ptr2 = buf[0..runtime_len :0]; // ptr2 is a null-terminated slice try comptime expect(@TypeOf(ptr2) == [:0]u8); try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8); var runtime_zero: usize = 0; + _ = &runtime_zero; try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8); } @@ -338,8 +345,8 @@ test "@ptrCast slice to pointer" { const S = struct { fn doTheTest() !void { var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff }; - var slice: []align(@alignOf(u16)) u8 = &array; - var ptr = @as(*u16, @ptrCast(slice)); + const slice: []align(@alignOf(u16)) u8 = &array; + const ptr: *u16 = @ptrCast(slice); try expect(ptr.* == 65535); } }; @@ -357,8 +364,8 @@ test "slice multi-pointer without end" { fn testPointer() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; - var pointer: [*]u8 = &array; - var slice = pointer[1..]; + const pointer: [*]u8 = &array; + const slice = pointer[1..]; try comptime expect(@TypeOf(slice) == [*]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -366,13 +373,13 @@ test "slice multi-pointer without end" { fn testPointerZ() !void { var array = [5:0]u8{ 1, 2, 3, 4, 5 }; - var pointer: [*:0]u8 = &array; + const pointer: [*:0]u8 = &array; try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8); try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8); - var slice = pointer[1..]; + const slice = pointer[1..]; try comptime expect(@TypeOf(slice) == [*:0]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -413,7 +420,7 @@ test "slice syntax resulting in pointer-to-array" { fn testArray() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; - var slice = array[1..3]; + const slice = array[1..3]; try comptime expect(@TypeOf(slice) == *[2]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -430,12 +437,12 @@ test "slice syntax resulting in pointer-to-array" { fn testArray0() !void { { var array = [0]u8{}; - var slice = array[0..0]; + const slice = array[0..0]; try comptime expect(@TypeOf(slice) == *[0]u8); } { var array = [0:0]u8{}; - var slice = array[0..0]; + const slice = array[0..0]; try comptime expect(@TypeOf(slice) == *[0:0]u8); try expect(slice[0] == 0); } @@ -443,7 +450,7 @@ test "slice syntax resulting in pointer-to-array" { fn testArrayAlign() !void { var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; - var slice = array[4..5]; + const slice = array[4..5]; try comptime expect(@TypeOf(slice) == *align(4) [1]u8); try expect(slice[0] == 5); try comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8); @@ -452,7 +459,7 @@ test "slice syntax resulting in pointer-to-array" { fn testPointer() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; var pointer: [*]u8 = &array; - var slice = pointer[1..3]; + const slice = pointer[1..3]; try comptime expect(@TypeOf(slice) == *[2]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -467,7 +474,7 @@ test "slice syntax resulting in pointer-to-array" { fn testPointer0() !void { var pointer: [*]const u0 = &[1]u0{0}; - var slice = pointer[0..1]; + const slice = pointer[0..1]; try comptime expect(@TypeOf(slice) == *const [1]u0); try expect(slice[0] == 0); } @@ -475,7 +482,7 @@ test "slice syntax resulting in pointer-to-array" { fn testPointerAlign() !void { var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; var pointer: [*]align(4) u8 = &array; - var slice = pointer[4..5]; + const slice = pointer[4..5]; try comptime expect(@TypeOf(slice) == *align(4) [1]u8); try expect(slice[0] == 5); try comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8); @@ -484,7 +491,7 @@ test "slice syntax resulting in pointer-to-array" { fn testSlice() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; var src_slice: []u8 = &array; - var slice = src_slice[1..3]; + const slice = src_slice[1..3]; try comptime expect(@TypeOf(slice) == *[2]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -513,7 +520,7 @@ test "slice syntax resulting in pointer-to-array" { fn testSliceAlign() !void { var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; var src_slice: []align(4) u8 = &array; - var slice = src_slice[4..5]; + const slice = src_slice[4..5]; try comptime expect(@TypeOf(slice) == *align(4) [1]u8); try expect(slice[0] == 5); try comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8); @@ -616,13 +623,13 @@ test "slice pointer-to-array zero length" { { var array = [0]u8{}; var src_slice: []u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try expect(@TypeOf(slice) == *[0]u8); } { var array = [0:0]u8{}; var src_slice: [:0]u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try expect(@TypeOf(slice) == *[0:0]u8); } } @@ -630,13 +637,13 @@ test "slice pointer-to-array zero length" { { var array = [0]u8{}; var src_slice: []u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try comptime expect(@TypeOf(slice) == *[0]u8); } { var array = [0:0]u8{}; var src_slice: [:0]u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try comptime expect(@TypeOf(slice) == *[0]u8); } } @@ -655,17 +662,19 @@ test "type coercion of pointer to anon struct literal to pointer to slice" { fn doTheTest() !void { var x1: u8 = 42; + _ = &x1; const t1 = &.{ x1, 56, 54 }; - var slice1: []const u8 = t1; + const slice1: []const u8 = t1; try expect(slice1.len == 3); try expect(slice1[0] == 42); try expect(slice1[1] == 56); try expect(slice1[2] == 54); var x2: []const u8 = "hello"; + _ = &x2; const t2 = &.{ x2, ", ", "world!" }; // @compileLog(@TypeOf(t2)); - var slice2: []const []const u8 = t2; + const slice2: []const []const u8 = t2; try expect(slice2.len == 3); try expect(mem.eql(u8, slice2[0], "hello")); try expect(mem.eql(u8, slice2[1], ", ")); @@ -680,6 +689,7 @@ test "array concat of slices gives ptr to array" { comptime { var a: []const u8 = "aoeu"; var b: []const u8 = "asdf"; + _ = .{ &a, &b }; const c = a ++ b; try expect(std.mem.eql(u8, c, "aoeuasdf")); try expect(@TypeOf(c) == *const [8]u8); @@ -689,6 +699,7 @@ test "array concat of slices gives ptr to array" { test "array mult of slice gives ptr to array" { comptime { var a: []const u8 = "aoeu"; + _ = &a; const c = a ** 2; try expect(std.mem.eql(u8, c, "aoeuaoeu")); try expect(@TypeOf(c) == *const [8]u8); @@ -736,7 +747,7 @@ test "slicing array with sentinel as end index" { const S = struct { fn do() !void { var array = [_:0]u8{ 1, 2, 3, 4 }; - var slice = array[4..5]; + const slice = array[4..5]; try expect(slice.len == 1); try expect(slice[0] == 0); try expect(@TypeOf(slice) == *[1]u8); @@ -754,8 +765,8 @@ test "slicing slice with sentinel as end index" { const S = struct { fn do() !void { var array = [_:0]u8{ 1, 2, 3, 4 }; - var src_slice: [:0]u8 = &array; - var slice = src_slice[4..5]; + const src_slice: [:0]u8 = &array; + const slice = src_slice[4..5]; try expect(slice.len == 1); try expect(slice[0] == 0); try expect(@TypeOf(slice) == *[1]u8); @@ -820,6 +831,7 @@ test "global slice field access" { test "slice of void" { var n: usize = 10; + _ = &n; var arr: [12]void = undefined; const slice = @as([]void, &arr)[0..n]; try expect(slice.len == n); @@ -827,7 +839,7 @@ test "slice of void" { test "slice with dereferenced value" { var a: usize = 0; - var idx: *usize = &a; + const idx: *usize = &a; _ = blk: { var array = [_]u8{}; break :blk array[idx.*..]; diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 08954dfd68..97ccb3212f 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -254,7 +254,8 @@ test "struct field init with catch" { const S = struct { fn doTheTest() !void { var x: anyerror!isize = 1; - var req = Foo{ + _ = &x; + const req = Foo{ .field = x catch undefined, }; try expect(req.field == 1); @@ -505,7 +506,7 @@ 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], @as([*]u8, @ptrCast(&all))); - var bitfields = @as(*Bitfields, @ptrCast(&bytes)).*; + const bitfields = @as(*Bitfields, @ptrCast(&bytes)).*; try expect(bitfields.f1 == 0x1111); try expect(bitfields.f2 == 0x2222); @@ -545,7 +546,7 @@ test "zero-bit field in packed struct" { y: void, }; var x: S = undefined; - _ = x; + _ = &x; } test "packed struct with non-ABI-aligned field" { @@ -624,6 +625,7 @@ test "default struct initialization fields" { .b = 5, }; var five: i32 = 5; + _ = &five; const y = S{ .b = five, }; @@ -714,7 +716,7 @@ test "pointer to packed struct member in a stack variable" { }; var s = S{ .a = 2, .b = 0 }; - var b_ptr = &s.b; + const b_ptr = &s.b; try expect(s.b == 0); b_ptr.* = 2; try expect(s.b == 2); @@ -727,6 +729,7 @@ test "packed struct with u0 field access" { f0: u0, }; var s = S{ .f0 = 0 }; + _ = &s; try comptime expect(s.f0 == 0); } @@ -788,7 +791,7 @@ test "fn with C calling convention returns struct by value" { const S = struct { fn entry() !void { - var x = makeBar(10); + const x = makeBar(10); try expect(@as(i32, 10) == x.handle); } @@ -827,6 +830,7 @@ test "non-packed struct with u128 entry in union" { var s = &sx; try expect(@intFromPtr(&s.f2) - @intFromPtr(&s.f1) == @offsetOf(S, "f2")); var v2 = U{ .Num = 123 }; + _ = &v2; s.f2 = v2; try expect(s.f2.Num == 123); } @@ -852,7 +856,7 @@ test "packed struct field passed to generic function" { var p: S.P = undefined; p.b = 29; - var loaded = S.genericReadPackedField(&p.b); + const loaded = S.genericReadPackedField(&p.b); try expect(loaded == 29); } @@ -871,6 +875,7 @@ test "anonymous struct literal syntax" { .x = 1, .y = 2, }; + _ = &p; try expect(p.x == 1); try expect(p.y == 2); } @@ -920,6 +925,7 @@ test "fully anonymous list literal" { test "tuple assigned to variable" { var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) }; + _ = &vec; try expect(vec.@"0" == 22); try expect(vec.@"1" == 55); try expect(vec.@"2" == 99); @@ -940,6 +946,7 @@ test "comptime struct field" { comptime std.debug.assert(@sizeOf(T) == 4); var foo: T = undefined; + _ = &foo; try comptime expect(foo.b == 1234); } @@ -950,7 +957,7 @@ test "tuple element initialized with fn call" { const S = struct { fn doTheTest() !void { - var x = .{foo()}; + const x = .{foo()}; try expectEqualSlices(u8, x[0], "hi"); } fn foo() []const u8 { @@ -977,6 +984,7 @@ test "struct with union field" { var True = Value{ .kind = .{ .Bool = true }, }; + _ = &True; try expect(@as(u32, 2) == True.ref); try expect(True.kind.Bool); } @@ -996,6 +1004,7 @@ test "struct with 0-length union array field" { }; var s: S = undefined; + _ = &s; try expectEqual(@as(usize, 0), s.zero_length.len); } @@ -1019,10 +1028,11 @@ test "type coercion of anon struct literal to struct" { fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = .{ .A = 123, .B = "foo", .C = {} }; const t1 = .{ .A = y, .B = "foo", .C = {} }; const y0: S2 = t0; - var y1: S2 = t1; + const y1: S2 = t1; try expect(y0.A == 123); try expect(std.mem.eql(u8, y0.B, "foo")); try expect(y0.C == {}); @@ -1057,10 +1067,11 @@ test "type coercion of pointer to anon struct literal to pointer to struct" { fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = &.{ .A = 123, .B = "foo", .C = {} }; const t1 = &.{ .A = y, .B = "foo", .C = {} }; const y0: *const S2 = t0; - var y1: *const S2 = t1; + const y1: *const S2 = t1; try expect(y0.A == 123); try expect(std.mem.eql(u8, y0.B, "foo")); try expect(y0.C == {}); @@ -1161,8 +1172,8 @@ test "anon init through error unions and optionals" { } fn doTheTest() !void { - var a = try (try foo()).?; - var b = try bar().?; + const a = try (try foo()).?; + const b = try bar().?; try expect(a.a + b[1] == 3); } }; @@ -1227,8 +1238,8 @@ test "typed init through error unions and optionals" { } fn doTheTest() !void { - var a = try (try foo()).?; - var b = try bar().?; + const a = try (try foo()).?; + const b = try bar().?; try expect(a.a + b[1] == 3); } }; @@ -1243,6 +1254,7 @@ test "initialize struct with empty literal" { const S = struct { x: i32 = 1234 }; var s: S = .{}; + _ = &s; try expect(s.x == 1234); } @@ -1301,10 +1313,10 @@ test "packed struct field access via pointer" { fn doTheTest() !void { const S = packed struct { a: u30 }; var s1: S = .{ .a = 1 }; - var s2 = &s1; + const s2 = &s1; try expect(s2.a == 1); var s3: S = undefined; - var s4 = &s3; + const s4 = &s3; _ = s4; } }; @@ -1343,6 +1355,7 @@ test "struct field init value is size of the struct" { }; }; var s: namespace.S = .{ .blah = 1234 }; + _ = &s; try expect(s.size == 4); } @@ -1362,6 +1375,7 @@ test "under-aligned struct field" { data: U align(4), }; var runtime: usize = 1234; + _ = &runtime; const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } }; const array = @as(*const [12]u8, @ptrCast(ptr)); const result = std.mem.readInt(u64, array[4..12], native_endian); @@ -1509,6 +1523,7 @@ test "function pointer in struct returns the struct" { } }; var a = A.f(); + _ = &a; try expect(a.f == A.f); } @@ -1538,7 +1553,8 @@ test "optional field init with tuple" { a: ?struct { b: u32 }, }; var a: u32 = 0; - var b = S{ + _ = &a; + const b = S{ .a = .{ .b = a }, }; try expect(b.a.?.b == a); @@ -1550,7 +1566,8 @@ test "if inside struct init inside if" { const MyStruct = struct { x: u32 }; const b: u32 = 5; var i: u32 = 1; - var my_var = if (i < 5) + _ = &i; + const my_var = if (i < 5) MyStruct{ .x = 1 + if (i > 0) b else 0, } @@ -1599,7 +1616,7 @@ test "instantiate struct with comptime field" { var things = struct { comptime foo: i8 = 1, }{}; - + _ = &things; comptime std.debug.assert(things.foo == 1); } @@ -1608,7 +1625,7 @@ test "instantiate struct with comptime field" { comptime foo: i8 = 1, }; var things = T{}; - + _ = &things; comptime std.debug.assert(things.foo == 1); } @@ -1616,7 +1633,7 @@ test "instantiate struct with comptime field" { var things: struct { comptime foo: i8 = 1, } = .{}; - + _ = &things; comptime std.debug.assert(things.foo == 1); } @@ -1624,7 +1641,7 @@ test "instantiate struct with comptime field" { var things: struct { comptime foo: i8 = 1, } = undefined; // Segmentation fault at address 0x0 - + _ = &things; comptime std.debug.assert(things.foo == 1); } } @@ -1755,6 +1772,7 @@ test "runtime side-effects in comptime-known struct init" { test "pointer to struct initialized through reference to anonymous initializer provides result types" { const S = struct { a: u8, b: u16, c: *const anyopaque }; var my_u16: u16 = 0xABCD; + _ = &my_u16; const s: *const S = &.{ // intentionally out of order .c = @ptrCast("hello"), @@ -1792,6 +1810,7 @@ test "initializer uses own alignment" { }; var s: S = .{}; + _ = &s; try expectEqual(4, @alignOf(S)); try expectEqual(@as(usize, 5), s.x); } @@ -1802,6 +1821,7 @@ test "initializer uses own size" { }; var s: S = .{}; + _ = &s; try expectEqual(4, @sizeOf(S)); try expectEqual(@as(usize, 5), s.x); } @@ -1815,6 +1835,7 @@ test "initializer takes a pointer to a variable inside its struct" { fn doTheTest() !void { var foo: S = .{}; + _ = &foo; try expectEqual(&S.instance, foo.s); } }; @@ -1839,6 +1860,7 @@ test "circular dependency through pointer field of a struct" { }; }; var outer: S.StructOuter = .{}; + _ = &outer; try expect(outer.middle.outer == null); try expect(outer.middle.inner == null); } @@ -1855,5 +1877,6 @@ test "field calls do not force struct field init resolution" { } }; var s: S = .{}; + _ = &s; try expect(s.x == 123); } diff --git a/test/behavior/struct_contains_null_ptr_itself.zig b/test/behavior/struct_contains_null_ptr_itself.zig index 7f0182af22..d0cb3ef443 100644 --- a/test/behavior/struct_contains_null_ptr_itself.zig +++ b/test/behavior/struct_contains_null_ptr_itself.zig @@ -7,6 +7,7 @@ test "struct contains null pointer which contains original struct" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: ?*NodeLineComment = null; + _ = &x; try expect(x == null); } diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig index 37cf8b7c6f..ae4923609f 100644 --- a/test/behavior/switch.zig +++ b/test/behavior/switch.zig @@ -157,6 +157,7 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool { test "u0" { var val: u0 = 0; + _ = &val; switch (val) { 0 => try expect(val == 0), } @@ -164,6 +165,7 @@ test "u0" { test "undefined.u0" { var val: u0 = undefined; + _ = &val; switch (val) { 0 => try expect(val == 0), } @@ -173,6 +175,7 @@ test "switch with disjoint range" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var q: u8 = 0; + _ = &q; switch (q) { 0...125 => {}, 127...255 => {}, @@ -183,12 +186,8 @@ test "switch with disjoint range" { test "switch variable for range and multiple prongs" { const S = struct { fn doTheTest() !void { - var u: u8 = 16; - try doTheSwitch(u); - try comptime doTheSwitch(u); - var v: u8 = 42; - try doTheSwitch(v); - try comptime doTheSwitch(v); + try doTheSwitch(16); + try doTheSwitch(42); } fn doTheSwitch(q: u8) !void { switch (q) { @@ -198,7 +197,8 @@ test "switch variable for range and multiple prongs" { } } }; - _ = S; + try S.doTheTest(); + try comptime S.doTheTest(); } var state: u32 = 0; @@ -322,7 +322,8 @@ test "switch on union with some prongs capturing" { }; var x: X = X{ .b = 10 }; - var y: i32 = switch (x) { + _ = &x; + const y: i32 = switch (x) { .a => unreachable, .b => |b| b + 1, }; @@ -357,6 +358,7 @@ test "anon enum literal used in switch on union enum" { }; var foo = Foo{ .a = 1234 }; + _ = &foo; switch (foo) { .a => |x| { try expect(x == 1234); @@ -406,6 +408,7 @@ test "switch on integer with else capturing expr" { const S = struct { fn doTheTest() !void { var x: i32 = 5; + _ = &x; switch (x + 10) { 14 => @panic("fail"), 16 => @panic("fail"), @@ -606,6 +609,7 @@ test "switch on error set with single else" { const S = struct { fn doTheTest() !void { var some: error{Foo} = error.Foo; + _ = &some; try expect(switch (some) { else => blk: { break :blk true; @@ -672,7 +676,8 @@ test "enum value without tag name used as switch item" { b = 2, _, }; - var e: E = @as(E, @enumFromInt(0)); + var e: E = @enumFromInt(0); + _ = &e; switch (e) { @as(E, @enumFromInt(0)) => {}, .a => return error.TestFailed, @@ -685,6 +690,7 @@ test "switch item sizeof" { const S = struct { fn doTheTest() !void { var a: usize = 0; + _ = &a; switch (a) { @sizeOf(struct {}) => {}, else => return error.TestFailed, @@ -699,6 +705,7 @@ test "comptime inline switch" { const U = union(enum) { a: type, b: type }; const value = comptime blk: { var u: U = .{ .a = u32 }; + _ = &u; break :blk switch (u) { inline .a, .b => |v| v, }; @@ -814,6 +821,7 @@ test "peer type resolution on switch captures ignores unused payload bits" { // This is runtime-known so the following store isn't comptime-known. var rt: u32 = 123; + _ = &rt; val = .{ .a = rt }; // will not necessarily zero remaning payload memory // Fields intentionally backwards here diff --git a/test/behavior/truncate.zig b/test/behavior/truncate.zig index 4fc095b66c..3d128b7656 100644 --- a/test/behavior/truncate.zig +++ b/test/behavior/truncate.zig @@ -4,58 +4,62 @@ const expect = std.testing.expect; test "truncate u0 to larger integer allowed and has comptime-known result" { var x: u0 = 0; + _ = &x; const y = @as(u8, @truncate(x)); try comptime expect(y == 0); } test "truncate.u0.literal" { - var z = @as(u0, @truncate(0)); + const z: u0 = @truncate(0); try expect(z == 0); } test "truncate.u0.const" { const c0: usize = 0; - var z = @as(u0, @truncate(c0)); + const z: u0 = @truncate(c0); try expect(z == 0); } test "truncate.u0.var" { var d: u8 = 2; - var z = @as(u0, @truncate(d)); + _ = &d; + const z: 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 = @as(i8, @truncate(x)); + _ = &x; + const y: i8 = @truncate(x); try comptime expect(y == 0); } test "truncate.i0.literal" { - var z = @as(i0, @truncate(0)); + const z: i0 = @truncate(0); try expect(z == 0); } test "truncate.i0.const" { const c0: isize = 0; - var z = @as(i0, @truncate(c0)); + const z: i0 = @truncate(c0); try expect(z == 0); } test "truncate.i0.var" { var d: i8 = 2; - var z = @as(i0, @truncate(d)); + _ = &d; + const z: i0 = @truncate(d); try expect(z == 0); } test "truncate on comptime integer" { - var x = @as(u16, @truncate(9999)); + const x: u16 = @truncate(9999); try expect(x == 9999); - var y = @as(u16, @truncate(-21555)); + const y: u16 = @truncate(-21555); try expect(y == 0xabcd); - var z = @as(i16, @truncate(-65537)); + const z: i16 = @truncate(-65537); try expect(z == -1); - var w = @as(u1, @truncate(1 << 100)); + const w: u1 = @truncate(1 << 100); try expect(w == 0); } @@ -69,7 +73,8 @@ test "truncate on vectors" { const S = struct { fn doTheTest() !void { var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 }; - var v2: @Vector(4, u8) = @truncate(v1); + _ = &v1; + const 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 63e2cde46e..039a96d29f 100644 --- a/test/behavior/tuple.zig +++ b/test/behavior/tuple.zig @@ -15,9 +15,10 @@ test "tuple concatenation" { fn doTheTest() !void { var a: i32 = 1; var b: i32 = 2; - var x = .{a}; - var y = .{b}; - var c = x ++ y; + _ = .{ &a, &b }; + const x = .{a}; + const y = .{b}; + const c = x ++ y; try expect(@as(i32, 1) == c[0]); try expect(@as(i32, 2) == c[1]); } @@ -119,7 +120,7 @@ test "tuple initializer for var" { .id = @as(usize, 2), .name = Bytes{ .id = 20 }, }; - _ = tmp; + _ = &tmp; } }; @@ -157,6 +158,7 @@ test "array-like initializer for tuple types" { const S = struct { fn doTheTest() !void { var obj: T = .{ -1234, 128 }; + _ = &obj; try expect(@as(i32, -1234) == obj[0]); try expect(@as(u8, 128) == obj[1]); } @@ -171,6 +173,7 @@ test "anon struct as the result from a labeled block" { fn doTheTest() !void { const precomputed = comptime blk: { var x: i32 = 1234; + _ = &x; break :blk .{ .x = x, }; @@ -188,6 +191,7 @@ test "tuple as the result from a labeled block" { fn doTheTest() !void { const precomputed = comptime blk: { var x: i32 = 1234; + _ = &x; break :blk .{x}; }; try expect(precomputed[0] == 1234); @@ -201,13 +205,13 @@ test "tuple as the result from a labeled block" { test "initializing tuple with explicit type" { const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); var a = T{ 0, 0 }; - _ = a; + _ = &a; } test "initializing anon struct with explicit type" { const T = @TypeOf(.{ .foo = @as(i32, 1), .bar = @as(i32, 2) }); var a = T{ .foo = 1, .bar = 2 }; - _ = a; + _ = &a; } test "fieldParentPtr of tuple" { @@ -216,6 +220,7 @@ test "fieldParentPtr of tuple" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 0; + _ = &x; const tuple = .{ x, x }; try testing.expect(&tuple == @fieldParentPtr(@TypeOf(tuple), "1", &tuple[1])); } @@ -226,18 +231,21 @@ test "fieldParentPtr of anon struct" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 0; + _ = &x; const anon_st = .{ .foo = x, .bar = x }; try testing.expect(&anon_st == @fieldParentPtr(@TypeOf(anon_st), "bar", &anon_st.bar)); } test "offsetOf tuple" { var x: u32 = 0; + _ = &x; const T = @TypeOf(.{ x, x }); try expect(@offsetOf(T, "1") == @sizeOf(u32)); } test "offsetOf anon struct" { var x: u32 = 0; + _ = &x; const T = @TypeOf(.{ .foo = x, .bar = x }); try expect(@offsetOf(T, "bar") == @sizeOf(u32)); } @@ -247,8 +255,10 @@ test "initializing tuple with mixed comptime-runtime fields" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u32 = 15; + _ = &x; const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); var a: T = .{ -1234, 5678, x + 1 }; + _ = &a; try expect(a[2] == 16); } @@ -257,8 +267,10 @@ test "initializing anon struct with mixed comptime-runtime fields" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u32 = 15; + _ = &x; const T = @TypeOf(.{ .foo = @as(i32, -1234), .bar = x }); var a: T = .{ .foo = -1234, .bar = x + 1 }; + _ = &a; try expect(a.bar == 16); } @@ -338,6 +350,7 @@ test "tuple type with void field and a runtime field" { const T = std.meta.Tuple(&[_]type{ usize, void }); var t: T = .{ 5, {} }; + _ = &t; try expect(t[0] == 5); } @@ -352,6 +365,7 @@ test "branching inside tuple literal" { } }; var a = false; + _ = &a; try S.foo(.{if (a) @as(u32, 5678) else @as(u32, 1234)}); } @@ -363,6 +377,7 @@ test "tuple initialized with a runtime known value" { const E = union(enum) { e: []const u8 }; const W = union(enum) { w: E }; var e = E{ .e = "test" }; + _ = &e; const w = .{W{ .w = e }}; try expectEqualStrings(w[0].w.e, "test"); } @@ -388,6 +403,7 @@ test "nested runtime conditionals in tuple initializer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var data: u8 = 0; + _ = &data; const x = .{ if (data != 0) "" else switch (@as(u1, @truncate(data))) { 0 => "up", @@ -446,8 +462,9 @@ test "coerce anon tuple to tuple" { var x: u8 = 1; var y: u16 = 2; - var t = .{ x, y }; - var s: struct { u8, u16 } = t; + _ = .{ &x, &y }; + const t = .{ x, y }; + const s: struct { u8, u16 } = t; try expectEqual(x, s[0]); try expectEqual(y, s[1]); } diff --git a/test/behavior/tuple_declarations.zig b/test/behavior/tuple_declarations.zig index 8ffc25613d..e3730b3995 100644 --- a/test/behavior/tuple_declarations.zig +++ b/test/behavior/tuple_declarations.zig @@ -38,17 +38,19 @@ test "Tuple declaration usage" { const T = struct { u32, []const u8 }; var t: T = .{ 1, "foo" }; + _ = &t; try expect(t[0] == 1); try expectEqualStrings(t[1], "foo"); - var mul = t ** 3; + const mul = t ** 3; try expect(@TypeOf(mul) != T); try expect(mul.len == 6); try expect(mul[2] == 1); try expectEqualStrings(mul[3], "foo"); var t2: T = .{ 2, "bar" }; - var cat = t ++ t2; + _ = &t2; + const cat = t ++ t2; try expect(@TypeOf(cat) != T); try expect(cat.len == 4); try expect(cat[2] == 2); diff --git a/test/behavior/type.zig b/test/behavior/type.zig index 7d0147c508..64c4c85669 100644 --- a/test/behavior/type.zig +++ b/test/behavior/type.zig @@ -410,7 +410,8 @@ test "Type.Union" { .decls = &.{}, }, }); - var packed_untagged = PackedUntagged{ .signed = -1 }; + var packed_untagged: PackedUntagged = .{ .signed = -1 }; + _ = &packed_untagged; try testing.expectEqual(@as(i32, -1), packed_untagged.signed); try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned); @@ -529,7 +530,7 @@ test "reified struct field name from optional payload" { .decls = &.{}, .is_tuple = false, } }); - var t: T = .{ .a = 123 }; + const t: T = .{ .a = 123 }; try std.testing.expect(t.a == 123); } } diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig index bc4737a552..63f2ecb30f 100644 --- a/test/behavior/type_info.zig +++ b/test/behavior/type_info.zig @@ -417,7 +417,7 @@ test "typeInfo with comptime parameter in struct fn def" { } }; comptime var info = @typeInfo(S); - _ = info; + _ = &info; } test "type info: vectors" { diff --git a/test/behavior/union.zig b/test/behavior/union.zig index 338db47036..804cea47f8 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -171,6 +171,7 @@ test "constant tagged union with payload" { var empty = TaggedUnionWithPayload{ .Empty = {} }; var full = TaggedUnionWithPayload{ .Full = 13 }; + _ = .{ &empty, &full }; shouldBeEmpty(empty); shouldBeNotEmpty(full); } @@ -254,6 +255,7 @@ fn bar(value: Payload) error{TestUnexpectedResult}!i32 { fn testComparison() !void { var x = Payload{ .A = 42 }; + _ = &x; try expect(x == .A); try expect(x != .B); try expect(x != .C); @@ -288,6 +290,7 @@ test "cast union to tag type of union" { fn testCastUnionToTag() !void { var u = TheUnion{ .B = 1234 }; + _ = &u; try expect(@as(TheTag, u) == TheTag.B); } @@ -303,6 +306,7 @@ test "cast tag type of union to union" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: Value2 = Letter2.B; + _ = &x; try expect(@as(Letter2, x) == Letter2.B); } const Letter2 = enum { A, B, C }; @@ -318,6 +322,7 @@ test "implicit cast union to its tag type" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: Value2 = Letter2.B; + _ = &x; try expect(x == Letter2.B); try giveMeLetterB(x); } @@ -356,6 +361,7 @@ test "simple union(enum(u32))" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x = MultipleChoice.C; + _ = &x; try expect(x == MultipleChoice.C); try expect(@intFromEnum(@as(Tag(MultipleChoice), x)) == 60); } @@ -420,9 +426,11 @@ test "union with only 1 field casted to its enum type" { }; var e = Expr{ .Literal = Literal{ .Bool = true } }; + _ = &e; const ExprTag = Tag(Expr); try comptime expect(Tag(ExprTag) == u0); var t = @as(ExprTag, e); + _ = &t; try expect(t == Expr.Literal); } @@ -494,6 +502,7 @@ test "union initializer generates padding only if needed" { }; var v = U{ .A = 532 }; + _ = &v; try expect(v.A == 532); } @@ -506,6 +515,7 @@ test "runtime tag name with single field" { }; var v = U{ .A = 42 }; + _ = &v; try expect(std.mem.eql(u8, @tagName(v), "A")); } @@ -698,8 +708,9 @@ test "union with only 1 field casted to its enum type which has enum value speci }; var e = Expr{ .Literal = Literal{ .Bool = true } }; + _ = &e; try comptime expect(Tag(ExprTag) == comptime_int); - comptime var t = @as(ExprTag, e); + const t = comptime @as(ExprTag, e); try expect(t == Expr.Literal); try expect(@intFromEnum(t) == 33); try comptime expect(@intFromEnum(t) == 33); @@ -719,6 +730,7 @@ test "@intFromEnum works on unions" { const a = Bar{ .A = true }; var b = Bar{ .B = undefined }; var c = Bar.C; + _ = .{ &b, &c }; try expect(@intFromEnum(a) == 0); try expect(@intFromEnum(b) == 1); try expect(@intFromEnum(c) == 2); @@ -800,11 +812,13 @@ test "@unionInit stored to a const" { fn doTheTest() !void { { var t = true; + _ = &t; const u = @unionInit(U, "boolean", t); try expect(u.boolean); } { var byte: u8 = 69; + _ = &byte; const u = @unionInit(U, "byte", byte); try expect(u.byte == 69); } @@ -849,7 +863,7 @@ test "@unionInit can modify a pointer value" { }; var value: UnionInitEnum = undefined; - var value_ptr = &value; + const value_ptr = &value; value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true); try expect(value.Boolean == true); @@ -906,7 +920,8 @@ test "anonymous union literal syntax" { fn doTheTest() !void { var i: Number = .{ .int = 42 }; - var f = makeNumber(); + _ = &i; + const f = makeNumber(); try expect(i.int == 42); try expect(f.float == 12.34); } @@ -934,9 +949,11 @@ test "function call result coerces from tagged union to the tag" { fn doTheTest() !void { var x: ArchTag = getArch1(); + _ = &x; try expect(x == .One); var y: ArchTag = getArch2(); + _ = &y; try expect(y == .Two); } @@ -965,14 +982,17 @@ test "cast from anonymous struct to union" { }; fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = .{ .A = 123 }; const t1 = .{ .B = "foo" }; const t2 = .{ .C = {} }; const t3 = .{ .A = y }; const x0: U = t0; var x1: U = t1; + _ = &x1; const x2: U = t2; var x3: U = t3; + _ = &x3; try expect(x0.A == 123); try expect(std.mem.eql(u8, x1.B, "foo")); try expect(x2 == .C); @@ -996,14 +1016,17 @@ test "cast from pointer to anonymous struct to pointer to union" { }; fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = &.{ .A = 123 }; const t1 = &.{ .B = "foo" }; const t2 = &.{ .C = {} }; const t3 = &.{ .A = y }; const x0: *const U = t0; var x1: *const U = t1; + _ = &x1; const x2: *const U = t2; var x3: *const U = t3; + _ = &x3; try expect(x0.A == 123); try expect(std.mem.eql(u8, x1.B, "foo")); try expect(x2.* == .C); @@ -1031,6 +1054,7 @@ test "switching on non exhaustive union" { }; fn doTheTest() !void { var a = U{ .a = 2 }; + _ = &a; switch (a) { .a => |val| try expect(val == 2), .b => return error.Fail, @@ -1055,11 +1079,13 @@ test "containers with single-field enums" { fn doTheTest() !void { var array1 = [1]A{A{ .f1 = {} }}; var array2 = [1]B{B{ .f1 = {} }}; + _ = .{ &array1, &array2 }; try expect(array1[0] == .f1); try expect(array2[0] == .f1); var struct1 = C{ .a = A{ .f1 = {} } }; var struct2 = D{ .a = B{ .f1 = {} } }; + _ = .{ &struct1, &struct2 }; try expect(struct1.a == .f1); try expect(struct2.a == .f1); } @@ -1092,8 +1118,9 @@ test "@unionInit on union with tag but no fields" { fn doTheTest() !void { var data: Data = .{ .no_op = {} }; - _ = data; + _ = &data; var o = Data.decode(&[_]u8{}); + _ = &o; try expectEqual(Type.no_op, o); } }; @@ -1156,6 +1183,7 @@ test "union with no result loc initiated with a runtime value" { } }; var a: u32 = 1; + _ = &a; U.foo(U{ .a = a }); } @@ -1174,6 +1202,7 @@ test "union with a large struct field" { fn foo(_: @This()) void {} }; var s: S = undefined; + _ = &s; U.foo(U{ .s = s }); } @@ -1207,6 +1236,7 @@ test "union tag is set when initiated as a temporary value at runtime" { } }; var b: u32 = 1; + _ = &b; try (U{ .b = b }).doTheTest(); } @@ -1226,6 +1256,7 @@ test "extern union most-aligned field is smaller" { un: [110]u8, }; var a: ?U = .{ .un = [_]u8{0} ** 110 }; + _ = &a; try expect(a != null); } @@ -1246,6 +1277,7 @@ test "return an extern union from C calling convention" { fn bar(arg_u: U) callconv(.C) U { var u = arg_u; + _ = &u; return u; } }; @@ -1324,13 +1356,16 @@ test "@unionInit uses tag value instead of field index" { a: usize, }; var i: isize = -1; + _ = &i; var u = @unionInit(U, "b", i); { var a = u.b; + _ = &a; try expect(a == i); } { var a = &u.b; + _ = &a; try expect(a.* == i); } try expect(@intFromEnum(u) == 255); @@ -1508,7 +1543,7 @@ test "coerce enum literal to union in result loc" { b: u8, fn doTest(c: bool) !void { - var u = if (c) .a else @This(){ .b = 0 }; + const u = if (c) .a else @This(){ .b = 0 }; try expect(u == .a); } }; @@ -1947,6 +1982,7 @@ test "packed union initialized via reintepreted struct field initializer" { }; var s: S = .{}; + _ = &s; try expect(s.u.a == littleToNativeEndian(u32, 0xddccbbaa)); try expect(s.u.b == if (endian == .little) 0xaa else 0xdd); } @@ -1966,6 +2002,7 @@ test "store of comptime reinterpreted memory to extern union" { }; var u: U = reinterpreted; + _ = &u; try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); try expect(u.b == 0xaa); } @@ -1985,6 +2022,7 @@ test "store of comptime reinterpreted memory to packed union" { }; var u: U = reinterpreted; + _ = &u; try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); try expect(u.b == if (endian == .little) 0xaa else 0xdd); } @@ -2018,6 +2056,7 @@ test "pass register-sized field as non-register-sized union" { }; var x: usize = 42; + _ = &x; try S.taggedUnion(.{ .x = x }); try S.untaggedUnion(.{ .x = x }); try S.externUnion(.{ .x = x }); @@ -2039,6 +2078,7 @@ test "circular dependency through pointer field of a union" { }; }; var outer: S.UnionOuter = .{}; + _ = &outer; try expect(outer.u.outer == null); try expect(outer.u.inner == null); } @@ -2057,5 +2097,6 @@ test "pass nested union with rls" { }; var c: u7 = 32; + _ = &c; try expectEqual(@as(u7, 32), Union.getC(.{ .b = .{ .c = c } })); } diff --git a/test/behavior/var_args.zig b/test/behavior/var_args.zig index 7fda8b208a..b0dccc1383 100644 --- a/test/behavior/var_args.zig +++ b/test/behavior/var_args.zig @@ -147,6 +147,7 @@ test "simple variadic function" { var runtime: bool = true; var a: i32 = 1; var b: i32 = 2; + _ = .{ &runtime, &a, &b }; try expect(1 == S.add(1, if (runtime) a else b)); } } diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig index a1b9a4f66e..a9569d1b1b 100644 --- a/test/behavior/vector.zig +++ b/test/behavior/vector.zig @@ -40,6 +40,7 @@ test "vector wrap operators" { try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 })); var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; try expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 })); + _ = .{ &v, &x, &z }; } }; try S.doTheTest(); @@ -57,6 +58,7 @@ test "vector bin compares with mem.eql" { fn doTheTest() !void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; + _ = .{ &v, &x }; try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false })); try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true })); try expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false })); @@ -81,6 +83,7 @@ test "vector int operators" { fn doTheTest() !void { var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; + _ = .{ &v, &x }; try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 })); try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 })); try expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 })); @@ -105,6 +108,7 @@ test "vector float operators" { fn doTheTest() !void { var v: @Vector(4, T) = [4]T{ 10, 20, 30, 40 }; var x: @Vector(4, T) = [4]T{ 1, 2, 3, 4 }; + _ = .{ &v, &x }; try expect(mem.eql(T, &@as([4]T, v + x), &[4]T{ 11, 22, 33, 44 })); try expect(mem.eql(T, &@as([4]T, v - x), &[4]T{ 9, 18, 27, 36 })); try expect(mem.eql(T, &@as([4]T, v * x), &[4]T{ 10, 40, 90, 160 })); @@ -126,6 +130,7 @@ test "vector bit operators" { fn doTheTest() !void { var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; + _ = .{ &v, &x }; try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); try expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); @@ -143,6 +148,7 @@ test "implicit cast vector to array" { const S = struct { fn doTheTest() !void { var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; + _ = &a; var result_array: [4]i32 = a; result_array = a; try expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 })); @@ -160,8 +166,9 @@ test "array to vector" { const S = struct { fn doTheTest() !void { var foo: f32 = 3.14; - var arr = [4]f32{ foo, 1.5, 0.0, 0.0 }; - var vec: @Vector(4, f32) = arr; + _ = &foo; + const arr = [4]f32{ foo, 1.5, 0.0, 0.0 }; + const vec: @Vector(4, f32) = arr; try expect(mem.eql(f32, &@as([4]f32, vec), &arr)); } }; @@ -180,25 +187,28 @@ test "array vector coercion - odd sizes" { const S = struct { fn doTheTest() !void { var foo1: i48 = 124578; - var vec1: @Vector(2, i48) = [2]i48{ foo1, 1 }; - var arr1: [2]i48 = vec1; + _ = &foo1; + const vec1: @Vector(2, i48) = [2]i48{ foo1, 1 }; + const arr1: [2]i48 = vec1; try expect(vec1[0] == foo1 and vec1[1] == 1); try expect(arr1[0] == foo1 and arr1[1] == 1); var foo2: u4 = 5; - var vec2: @Vector(2, u4) = [2]u4{ foo2, 1 }; - var arr2: [2]u4 = vec2; + _ = &foo2; + const vec2: @Vector(2, u4) = [2]u4{ foo2, 1 }; + const arr2: [2]u4 = vec2; try expect(vec2[0] == foo2 and vec2[1] == 1); try expect(arr2[0] == foo2 and arr2[1] == 1); var foo3: u13 = 13; - var vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 }; - var arr3: [3]u13 = vec3; + _ = &foo3; + const vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 }; + const arr3: [3]u13 = vec3; try expect(vec3[0] == foo3 and vec3[1] == 0 and vec3[2] == 1); try expect(arr3[0] == foo3 and arr3[1] == 0 and arr3[2] == 1); - var arr4 = [4:0]u24{ foo3, foo2, 0, 1 }; - var vec4: @Vector(4, u24) = arr4; + const arr4 = [4:0]u24{ foo3, foo2, 0, 1 }; + const vec4: @Vector(4, u24) = arr4; try expect(vec4[0] == foo3 and vec4[1] == foo2 and vec4[2] == 0 and vec4[3] == 1); } }; @@ -217,8 +227,9 @@ test "array to vector with element type coercion" { const S = struct { fn doTheTest() !void { var foo: f16 = 3.14; - var arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 }; - var vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 }; + _ = &foo; + const arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 }; + const vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 }; try std.testing.expect(std.mem.eql(f32, &@as([4]f32, vec), &arr32)); } }; @@ -237,7 +248,8 @@ test "peer type resolution with coercible element types" { var b: @Vector(2, u8) = .{ 1, 2 }; var a: @Vector(2, u16) = .{ 2, 1 }; var t: bool = true; - var c = if (t) a else b; + _ = .{ &a, &b, &t }; + const c = if (t) a else b; try std.testing.expect(@TypeOf(c) == @Vector(2, u16)); } }; @@ -285,22 +297,26 @@ test "vector casts of sizes not divisible by 8" { fn doTheTest() !void { { var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; - var x: [4]u3 = v; + _ = &v; + const x: [4]u3 = v; try expect(mem.eql(u3, &x, &@as([4]u3, v))); } { var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; - var x: [4]u2 = v; + _ = &v; + const x: [4]u2 = v; try expect(mem.eql(u2, &x, &@as([4]u2, v))); } { var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; - var x: [4]u1 = v; + _ = &v; + const x: [4]u1 = v; try expect(mem.eql(u1, &x, &@as([4]u1, v))); } { var v: @Vector(4, bool) = [4]bool{ false, false, true, false }; - var x: [4]bool = v; + _ = &v; + const x: [4]bool = v; try expect(mem.eql(bool, &x, &@as([4]bool, v))); } } @@ -327,7 +343,8 @@ test "vector @splat" { fn testForT(comptime N: comptime_int, v: anytype) !void { const T = @TypeOf(v); var vec: @Vector(N, T) = @splat(v); - var as_array = @as([N]T, vec); + _ = &vec; + const as_array = @as([N]T, vec); for (as_array) |elem| try expect(v == elem); } fn doTheTest() !void { @@ -412,6 +429,7 @@ test "load vector elements via runtime index" { const S = struct { fn doTheTest() !void { var v: @Vector(4, i32) = [_]i32{ 1, 2, 3, undefined }; + _ = &v; var i: u32 = 0; try expect(v[i] == 1); i += 1; @@ -461,7 +479,7 @@ test "initialize vector which is a struct field" { var foo = Vec4Obj{ .data = [_]f32{ 1, 2, 3, 4 }, }; - _ = foo; + _ = &foo; } }; try S.doTheTest(); @@ -481,6 +499,7 @@ test "vector comparison operators" { const V = @Vector(4, bool); var v1: V = [_]bool{ true, false, true, false }; var v2: V = [_]bool{ false, true, false, true }; + _ = .{ &v1, &v2 }; try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v1))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v2))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v2))); @@ -491,6 +510,7 @@ test "vector comparison operators" { var v1: @Vector(4, u32) = @splat(0xc0ffeeee); var v2: @Vector(4, c_uint) = v1; var v3: @Vector(4, u32) = @splat(0xdeadbeef); + _ = .{ &v1, &v2, &v3 }; try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v2))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v3))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v3))); @@ -499,6 +519,7 @@ test "vector comparison operators" { { // Comptime-known LHS/RHS var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 }; + _ = &v1; const v2: @Vector(4, u32) = @splat(2); const v3: @Vector(4, bool) = [_]bool{ true, false, true, false }; try expect(mem.eql(bool, &@as([4]bool, v3), &@as([4]bool, v1 == v2))); @@ -604,7 +625,7 @@ test "vector bitwise not operator" { const S = struct { fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void { - var y = ~x; + const y = ~x; for (@as([4]T, y), 0..) |v, i| { try expect(~x[i] == v); } @@ -640,14 +661,14 @@ test "vector shift operators" { const TX = @typeInfo(@TypeOf(x)).Array.child; const TY = @typeInfo(@TypeOf(y)).Array.child; - var xv = @as(@Vector(N, TX), x); - var yv = @as(@Vector(N, TY), y); + const xv = @as(@Vector(N, TX), x); + const yv = @as(@Vector(N, TY), y); - var z0 = xv >> yv; + const z0 = xv >> yv; for (@as([N]TX, z0), 0..) |v, i| { try expect(x[i] >> y[i] == v); } - var z1 = xv << yv; + const z1 = xv << yv; for (@as([N]TX, z1), 0..) |v, i| { try expect(x[i] << y[i] == v); } @@ -657,10 +678,10 @@ test "vector shift operators" { const TX = @typeInfo(@TypeOf(x)).Array.child; const TY = @typeInfo(@TypeOf(y)).Array.child; - var xv = @as(@Vector(N, TX), x); - var yv = @as(@Vector(N, TY), y); + const xv = @as(@Vector(N, TX), x); + const yv = @as(@Vector(N, TY), y); - var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv); + const z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv); for (@as([N]TX, z), 0..) |v, i| { const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i]; try expect(check == v); @@ -734,7 +755,7 @@ test "vector reduce operation" { const N = @typeInfo(@TypeOf(x)).Array.len; const TX = @typeInfo(@TypeOf(x)).Array.child; - var r = @reduce(op, @as(@Vector(N, TX), x)); + const r = @reduce(op, @as(@Vector(N, TX), x)); switch (@typeInfo(TX)) { .Int, .Bool => try expect(expected == r), .Float => { @@ -892,7 +913,8 @@ test "mask parameter of @shuffle is comptime scope" { const __v4hi = @Vector(4, i16); var v4_a = __v4hi{ 0, 0, 0, 0 }; var v4_b = __v4hi{ 0, 0, 0, 0 }; - var shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){ + _ = .{ &v4_a, &v4_b }; + const shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){ std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), @@ -915,7 +937,8 @@ test "saturating add" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 255, 254, 1 }; var rhs = u8x3{ 1, 2, 255 }; - var result = lhs +| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs +| rhs; const expected = u8x3{ 255, 255, 255 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -923,7 +946,8 @@ test "saturating add" { const i8x3 = @Vector(3, i8); var lhs = i8x3{ 127, 126, 1 }; var rhs = i8x3{ 1, 2, 127 }; - var result = lhs +| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs +| rhs; const expected = i8x3{ 127, 127, 127 }; try expect(mem.eql(i8, &@as([3]i8, expected), &@as([3]i8, result))); } @@ -947,7 +971,8 @@ test "saturating subtraction" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 0, 0, 0 }; var rhs = u8x3{ 255, 255, 255 }; - var result = lhs -| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs -| rhs; const expected = u8x3{ 0, 0, 0 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -973,7 +998,8 @@ test "saturating multiplication" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 2, 2, 2 }; var rhs = u8x3{ 255, 255, 255 }; - var result = lhs *| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs *| rhs; const expected = u8x3{ 255, 255, 255 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -997,7 +1023,8 @@ test "saturating shift-left" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 1, 1, 1 }; var rhs = u8x3{ 255, 255, 255 }; - var result = lhs <<| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs <<| rhs; const expected = u8x3{ 255, 255, 255 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -1040,29 +1067,33 @@ test "@addWithOverflow" { { var lhs = @Vector(4, u8){ 250, 250, 250, 250 }; var rhs = @Vector(4, u8){ 0, 5, 6, 10 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, i8){ -125, -125, 125, 125 }; var rhs = @Vector(4, i8){ -3, -4, 2, 3 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, u1){ 0, 0, 1, 1 }; var rhs = @Vector(4, u1){ 0, 1, 0, 1 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 0, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, u0){ 0, 0, 0, 0 }; var rhs = @Vector(4, u0){ 0, 0, 0, 0 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 0, 0 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 0, 0 }; try expectEqual(expected, overflow); } } @@ -1084,15 +1115,17 @@ test "@subWithOverflow" { { var lhs = @Vector(2, u8){ 5, 5 }; var rhs = @Vector(2, u8){ 5, 6 }; - var overflow = @subWithOverflow(lhs, rhs)[1]; - var expected: @Vector(2, u1) = .{ 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @subWithOverflow(lhs, rhs)[1]; + const expected: @Vector(2, u1) = .{ 0, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, i8){ -120, -120, 120, 120 }; var rhs = @Vector(4, i8){ 8, 9, -7, -8 }; - var overflow = @subWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @subWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; try expectEqual(expected, overflow); } } @@ -1113,8 +1146,9 @@ test "@mulWithOverflow" { fn doTheTest() !void { var lhs = @Vector(4, u8){ 10, 10, 10, 10 }; var rhs = @Vector(4, u8){ 25, 26, 0, 30 }; - var overflow = @mulWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @mulWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; try expectEqual(expected, overflow); } }; @@ -1134,8 +1168,9 @@ test "@shlWithOverflow" { fn doTheTest() !void { var lhs = @Vector(4, u8){ 0, 1, 8, 255 }; var rhs = @Vector(4, u3){ 7, 7, 7, 7 }; - var overflow = @shlWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @shlWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; try expectEqual(expected, overflow); } }; @@ -1161,8 +1196,8 @@ test "loading the second vector from a slice of vectors" { @Vector(2, u8){ 0, 1 }, @Vector(2, u8){ 2, 3 }, }; - var a: []const @Vector(2, u8) = &small_bases; - var a4 = a[1][1]; + const a: []const @Vector(2, u8) = &small_bases; + const a4 = a[1][1]; try expect(a4 == 3); } @@ -1183,6 +1218,7 @@ test "array of vectors is copied" { Vec3{ -345, -311, 381 }, Vec3{ -661, -816, -575 }, }; + _ = &points; var points2: [20]Vec3 = undefined; points2[0..points.len].* = points; try std.testing.expectEqual(points2[6], Vec3{ -345, -311, 381 }); @@ -1244,6 +1280,7 @@ test "zero multiplicand" { const zeros = @Vector(2, u32){ 0.0, 0.0 }; var ones = @Vector(2, u32){ 1.0, 1.0 }; + _ = &ones; _ = (ones * zeros)[0]; _ = (zeros * zeros)[0]; @@ -1266,6 +1303,7 @@ test "@intCast to u0" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var zeros = @Vector(2, u32){ 0, 0 }; + _ = &zeros; const casted = @as(@Vector(2, u0), @intCast(zeros)); _ = casted[0]; @@ -1292,7 +1330,8 @@ test "array operands to shuffle are coerced to vectors" { const mask = [5]i32{ -1, 0, 1, 2, 3 }; var a = [5]u32{ 3, 5, 7, 9, 0 }; - var b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask); + _ = &a; + const b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask); try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b); } @@ -1320,6 +1359,7 @@ test "store packed vector element" { var v = @Vector(4, u1){ 1, 1, 1, 1 }; try expectEqual(@Vector(4, u1){ 1, 1, 1, 1 }, v); var index: usize = 0; + _ = &index; v[index] = 0; try expectEqual(@Vector(4, u1){ 0, 1, 1, 1 }, v); } @@ -1337,6 +1377,7 @@ test "store to vector in slice" { }; var s: []@Vector(3, f32) = &v; var i: usize = 1; + _ = &i; s[i] = s[0]; try expectEqual(v[1], v[0]); } @@ -1378,6 +1419,7 @@ test "store vector with memset" { var kc = @Vector(2, i4){ 2, 3 }; var kd = @Vector(2, u8){ 4, 5 }; var ke = @Vector(2, i9){ 6, 7 }; + _ = .{ &ka, &kb, &kc, &kd, &ke }; @memset(&a, ka); @memset(&b, kb); @memset(&c, kc); @@ -1410,6 +1452,7 @@ test "compare vectors with different element types" { var a: @Vector(2, u8) = .{ 1, 2 }; var b: @Vector(2, u9) = .{ 3, 0 }; + _ = .{ &a, &b }; try expectEqual(@Vector(2, bool){ true, false }, a < b); } @@ -1465,8 +1508,9 @@ test "bitcast to vector with different child type" { const VecB = @Vector(4, u32); var vec_a = VecA{ 1, 1, 1, 1, 1, 1, 1, 1 }; - var vec_b: VecB = @bitCast(vec_a); - var vec_c: VecA = @bitCast(vec_b); + _ = &vec_a; + const vec_b: VecB = @bitCast(vec_a); + const vec_c: VecA = @bitCast(vec_b); try expectEqual(vec_a, vec_c); } }; diff --git a/test/behavior/void.zig b/test/behavior/void.zig index 8c6269123d..42c57ca3a6 100644 --- a/test/behavior/void.zig +++ b/test/behavior/void.zig @@ -38,16 +38,18 @@ test "void optional" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: ?void = {}; + _ = &x; try expect(x != null); } test "void array as a local variable initializer" { var x = [_]void{{}} ** 1004; + _ = &x[0]; _ = x[0]; } const void_constant = {}; test "reference to void constants" { var a = void_constant; - _ = a; + _ = &a; } diff --git a/test/behavior/wasm.zig b/test/behavior/wasm.zig index 11bf6cff05..c7d12be29d 100644 --- a/test/behavior/wasm.zig +++ b/test/behavior/wasm.zig @@ -4,6 +4,7 @@ const builtin = @import("builtin"); test "memory size and grow" { var prev = @wasmMemorySize(0); + _ = &prev; try expect(prev == @wasmMemoryGrow(0, 1)); try expect(prev + 1 == @wasmMemorySize(0)); } diff --git a/test/behavior/widening.zig b/test/behavior/widening.zig index f44f577dcb..3badb40169 100644 --- a/test/behavior/widening.zig +++ b/test/behavior/widening.zig @@ -15,6 +15,7 @@ test "integer widening" { var d: u64 = c; var e: u64 = d; var f: u128 = e; + _ = .{ &a, &b, &c, &d, &e, &f }; try expect(f == a); } @@ -33,6 +34,7 @@ test "implicit unsigned integer to signed integer" { var a: u8 = 250; var b: i16 = a; + _ = .{ &a, &b }; try expect(b == 250); } @@ -47,10 +49,12 @@ test "float widening" { var b: f32 = a; var c: f64 = b; var d: f128 = c; + _ = .{ &a, &b, &c, &d }; try expect(a == b); try expect(b == c); try expect(c == d); var e: f80 = c; + _ = &e; try expect(c == e); } @@ -63,6 +67,7 @@ test "float widening f16 to f128" { var x: f16 = 12.34; var y: f128 = x; + _ = .{ &x, &y }; try expect(x == y); }