authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-16 13:21:18+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-19 09:57:03+00:00
log9c16b2370d30e74a63a84a835d840266021424fd
tree9447b9b05beb2e181d8fba96fd28b333d41792c4
parent21fa187abc2a06c9bd5cfe4355c5edbfb3177f6b
signaturelock-open Commit is signed but in an unrecognized format.

test: update behavior to silence 'var is never mutated' errors


104 files changed, 1160 insertions(+), 390 deletions(-)

test/behavior/abs.zig+33
......@@ -16,26 +16,32 @@ test "@abs integers" {
1616fn testAbsIntegers() !void {
1717 {
1818 var x: i32 = -1000;
19 _ = &x;
1920 try expect(@abs(x) == 1000);
2021 }
2122 {
2223 var x: i32 = 0;
24 _ = &x;
2325 try expect(@abs(x) == 0);
2426 }
2527 {
2628 var x: i32 = 1000;
29 _ = &x;
2730 try expect(@abs(x) == 1000);
2831 }
2932 {
3033 var x: i64 = std.math.minInt(i64);
34 _ = &x;
3135 try expect(@abs(x) == @as(u64, -std.math.minInt(i64)));
3236 }
3337 {
3438 var x: i5 = -1;
39 _ = &x;
3540 try expect(@abs(x) == 1);
3641 }
3742 {
3843 var x: i5 = -5;
44 _ = &x;
3945 try expect(@abs(x) == 5);
4046 }
4147 comptime {
......@@ -56,22 +62,27 @@ test "@abs unsigned integers" {
5662fn testAbsUnsignedIntegers() !void {
5763 {
5864 var x: u32 = 1000;
65 _ = &x;
5966 try expect(@abs(x) == 1000);
6067 }
6168 {
6269 var x: u32 = 0;
70 _ = &x;
6371 try expect(@abs(x) == 0);
6472 }
6573 {
6674 var x: u32 = 1000;
75 _ = &x;
6776 try expect(@abs(x) == 1000);
6877 }
6978 {
7079 var x: u5 = 1;
80 _ = &x;
7181 try expect(@abs(x) == 1);
7282 }
7383 {
7484 var x: u5 = 5;
85 _ = &x;
7586 try expect(@abs(x) == 5);
7687 }
7788 comptime {
......@@ -102,27 +113,33 @@ test "@abs floats" {
102113fn testAbsFloats(comptime T: type) !void {
103114 {
104115 var x: T = -2.62;
116 _ = &x;
105117 try expect(@abs(x) == 2.62);
106118 }
107119 {
108120 var x: T = 2.62;
121 _ = &x;
109122 try expect(@abs(x) == 2.62);
110123 }
111124 {
112125 var x: T = 0.0;
126 _ = &x;
113127 try expect(@abs(x) == 0.0);
114128 }
115129 {
116130 var x: T = -std.math.pi;
131 _ = &x;
117132 try expect(@abs(x) == std.math.pi);
118133 }
119134
120135 {
121136 var x: T = -std.math.inf(T);
137 _ = &x;
122138 try expect(@abs(x) == std.math.inf(T));
123139 }
124140 {
125141 var x: T = std.math.inf(T);
142 _ = &x;
126143 try expect(@abs(x) == std.math.inf(T));
127144 }
128145 comptime {
......@@ -164,31 +181,37 @@ fn testAbsIntVectors(comptime len: comptime_int) !void {
164181 {
165182 var x: I32 = @splat(-10);
166183 var y: U32 = @splat(10);
184 _ = .{ &x, &y };
167185 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
168186 }
169187 {
170188 var x: I32 = @splat(10);
171189 var y: U32 = @splat(10);
190 _ = .{ &x, &y };
172191 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
173192 }
174193 {
175194 var x: I32 = @splat(0);
176195 var y: U32 = @splat(0);
196 _ = .{ &x, &y };
177197 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
178198 }
179199 {
180200 var x: I64 = @splat(-10);
181201 var y: U64 = @splat(10);
202 _ = .{ &x, &y };
182203 try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x))));
183204 }
184205 {
185206 var x: I64 = @splat(std.math.minInt(i64));
186207 var y: U64 = @splat(-std.math.minInt(i64));
208 _ = .{ &x, &y };
187209 try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x))));
188210 }
189211 {
190212 var x = std.simd.repeat(len, @Vector(4, i32){ -2, 5, std.math.minInt(i32), -7 });
191213 var y = std.simd.repeat(len, @Vector(4, u32){ 2, 5, -std.math.minInt(i32), 7 });
214 _ = .{ &x, &y };
192215 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
193216 }
194217}
......@@ -225,26 +248,31 @@ fn testAbsUnsignedIntVectors(comptime len: comptime_int) !void {
225248 {
226249 var x: U32 = @splat(10);
227250 var y: U32 = @splat(10);
251 _ = .{ &x, &y };
228252 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
229253 }
230254 {
231255 var x: U32 = @splat(10);
232256 var y: U32 = @splat(10);
257 _ = .{ &x, &y };
233258 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
234259 }
235260 {
236261 var x: U32 = @splat(0);
237262 var y: U32 = @splat(0);
263 _ = .{ &x, &y };
238264 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
239265 }
240266 {
241267 var x: U64 = @splat(10);
242268 var y: U64 = @splat(10);
269 _ = .{ &x, &y };
243270 try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x))));
244271 }
245272 {
246273 var x = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 });
247274 var y = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 });
275 _ = .{ &x, &y };
248276 try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x))));
249277 }
250278}
......@@ -346,26 +374,31 @@ fn testAbsFloatVectors(comptime T: type, comptime len: comptime_int) !void {
346374 {
347375 var x: V = @splat(-7.5);
348376 var y: V = @splat(7.5);
377 _ = .{ &x, &y };
349378 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));
350379 }
351380 {
352381 var x: V = @splat(7.5);
353382 var y: V = @splat(7.5);
383 _ = .{ &x, &y };
354384 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));
355385 }
356386 {
357387 var x: V = @splat(0.0);
358388 var y: V = @splat(0.0);
389 _ = .{ &x, &y };
359390 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));
360391 }
361392 {
362393 var x: V = @splat(-std.math.pi);
363394 var y: V = @splat(std.math.pi);
395 _ = .{ &x, &y };
364396 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));
365397 }
366398 {
367399 var x: V = @splat(std.math.pi);
368400 var y: V = @splat(std.math.pi);
401 _ = .{ &x, &y };
369402 try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x))));
370403 }
371404}
test/behavior/align.zig+8-2
......@@ -29,6 +29,7 @@ test "slicing array of length 1 can not assume runtime index is always zero" {
2929 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3030
3131 var runtime_index: usize = 1;
32 _ = &runtime_index;
3233 const slice = @as(*align(4) [1]u8, &foo)[runtime_index..];
3334 try expect(@TypeOf(slice) == []u8);
3435 try expect(slice.len == 0);
......@@ -438,6 +439,7 @@ test "runtime-known array index has best alignment possible" {
438439 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
439440 var smaller align(2) = [_]u32{ 1, 2, 3, 4 };
440441 var runtime_zero: usize = 0;
442 _ = &runtime_zero;
441443 comptime assert(@TypeOf(smaller[runtime_zero..]) == []align(2) u32);
442444 comptime assert(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32);
443445 try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32);
......@@ -464,6 +466,7 @@ test "alignment of function with c calling convention" {
464466 const a = @alignOf(@TypeOf(nothing));
465467
466468 var runtime_nothing = &nothing;
469 _ = &runtime_nothing;
467470 const casted1: *align(a) const u8 = @ptrCast(runtime_nothing);
468471 const casted2: *const fn () callconv(.C) void = @ptrCast(casted1);
469472 casted2();
......@@ -486,6 +489,7 @@ test "read 128-bit field from default aligned struct in stack memory" {
486489 .nevermind = 1,
487490 .badguy = 12,
488491 };
492 _ = &default_aligned;
489493 try expect(12 == default_aligned.badguy);
490494}
491495
......@@ -579,10 +583,10 @@ test "comptime alloc alignment" {
579583 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
580584
581585 comptime var bytes1 = [_]u8{0};
582 _ = bytes1;
586 _ = &bytes1;
583587
584588 comptime var bytes2 align(256) = [_]u8{0};
585 var bytes2_addr = @intFromPtr(&bytes2);
589 const bytes2_addr = @intFromPtr(&bytes2);
586590 try expect(bytes2_addr & 0xff == 0);
587591}
588592
......@@ -591,6 +595,7 @@ test "@alignCast null" {
591595 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
592596
593597 var ptr: ?*anyopaque = null;
598 _ = &ptr;
594599 const aligned: ?*anyopaque = @alignCast(ptr);
595600 try expect(aligned == null);
596601}
......@@ -637,6 +642,7 @@ test "alignment of zero-bit types is respected" {
637642 var s32: S align(32) = .{};
638643
639644 var zero: usize = 0;
645 _ = &zero;
640646
641647 try expect(@intFromPtr(&s) % @alignOf(usize) == 0);
642648 try expect(@intFromPtr(&s.arr) % @alignOf(usize) == 0);
test/behavior/alignof.zig+1
......@@ -31,6 +31,7 @@ test "correct alignment for elements and slices of aligned array" {
3131 var buf: [1024]u8 align(64) = undefined;
3232 var start: usize = 1;
3333 var end: usize = undefined;
34 _ = .{ &start, &end };
3435 try expect(@alignOf(@TypeOf(buf[start..end])) == @alignOf(*u8));
3536 try expect(@alignOf(@TypeOf(&buf[start..end])) == @alignOf(*u8));
3637 try expect(@alignOf(@TypeOf(&buf[start])) == @alignOf(*u8));
test/behavior/array.zig+26-7
......@@ -138,6 +138,7 @@ test "array literal with specified size" {
138138 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
139139
140140 var array = [2]u8{ 1, 2 };
141 _ = &array;
141142 try expect(array[0] == 1);
142143 try expect(array[1] == 2);
143144}
......@@ -146,7 +147,7 @@ test "array len field" {
146147 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
147148
148149 var arr = [4]u8{ 0, 0, 0, 0 };
149 var ptr = &arr;
150 const ptr = &arr;
150151 try expect(arr.len == 4);
151152 try comptime expect(arr.len == 4);
152153 try expect(ptr.len == 4);
......@@ -163,7 +164,8 @@ test "array with sentinels" {
163164 {
164165 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
165166 try expect(zero_sized[0] == 0xde);
166 var reinterpreted = @as(*[1]u8, @ptrCast(&zero_sized));
167 var reinterpreted: *[1]u8 = @ptrCast(&zero_sized);
168 _ = &reinterpreted;
167169 try expect(reinterpreted[0] == 0xde);
168170 }
169171 var arr: [3:0x55]u8 = undefined;
......@@ -225,6 +227,7 @@ test "implicit comptime in array type size" {
225227 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
226228
227229 var arr: [plusOne(10)]bool = undefined;
230 _ = &arr;
228231 try expect(arr.len == 11);
229232}
230233
......@@ -281,6 +284,7 @@ test "anonymous list literal syntax" {
281284 const S = struct {
282285 fn doTheTest() !void {
283286 var array: [4]u8 = .{ 1, 2, 3, 4 };
287 _ = &array;
284288 try expect(array[0] == 1);
285289 try expect(array[1] == 2);
286290 try expect(array[2] == 3);
......@@ -365,6 +369,7 @@ test "runtime initialize array elem and then implicit cast to slice" {
365369 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
366370
367371 var two: i32 = 2;
372 _ = &two;
368373 const x: []const i32 = &[_]i32{two};
369374 try expect(x[0] == 2);
370375}
......@@ -472,6 +477,7 @@ test "anonymous literal in array" {
472477 .{ .a = 3 },
473478 .{ .b = 3 },
474479 };
480 _ = &array;
475481 try expect(array[0].a == 3);
476482 try expect(array[0].b == 4);
477483 try expect(array[1].a == 2);
......@@ -489,8 +495,10 @@ test "access the null element of a null terminated array" {
489495 const S = struct {
490496 fn doTheTest() !void {
491497 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
498 _ = &array;
492499 try expect(array[4] == 0);
493500 var len: usize = 4;
501 _ = &len;
494502 try expect(array[len] == 0);
495503 }
496504 };
......@@ -510,6 +518,7 @@ test "type deduction for array subscript expression" {
510518 try expect(@as(u8, 0xAA) == array[if (v0) 1 else 0]);
511519 var v1 = false;
512520 try expect(@as(u8, 0x55) == array[if (v1) 1 else 0]);
521 _ = .{ &array, &v0, &v1 };
513522 }
514523 };
515524 try S.doTheTest();
......@@ -529,7 +538,7 @@ test "sentinel element count towards the ABI size calculation" {
529538 fill_post: u8 = 0xAA,
530539 };
531540 var x = T{};
532 var as_slice = mem.asBytes(&x);
541 const as_slice = mem.asBytes(&x);
533542 try expect(@as(usize, 3) == as_slice.len);
534543 try expect(@as(u8, 0x55) == as_slice[0]);
535544 try expect(@as(u8, 0xAA) == as_slice[2]);
......@@ -559,6 +568,7 @@ test "zero-sized array with recursive type definition" {
559568 };
560569
561570 var t: S = .{ .list = .{ .s = undefined } };
571 _ = &t;
562572 try expect(@as(usize, 0) == t.list.x);
563573}
564574
......@@ -576,15 +586,17 @@ test "type coercion of anon struct literal to array" {
576586
577587 fn doTheTest() !void {
578588 var x1: u8 = 42;
589 _ = &x1;
579590 const t1 = .{ x1, 56, 54 };
580 var arr1: [3]u8 = t1;
591 const arr1: [3]u8 = t1;
581592 try expect(arr1[0] == 42);
582593 try expect(arr1[1] == 56);
583594 try expect(arr1[2] == 54);
584595
585596 var x2: U = .{ .a = 42 };
597 _ = &x2;
586598 const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };
587 var arr2: [3]U = t2;
599 const arr2: [3]U = t2;
588600 try expect(arr2[0].a == 42);
589601 try expect(arr2[1].b == true);
590602 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" {
608620
609621 fn doTheTest() !void {
610622 var x1: u8 = 42;
623 _ = &x1;
611624 const t1 = &.{ x1, 56, 54 };
612 var arr1: *const [3]u8 = t1;
625 const arr1: *const [3]u8 = t1;
613626 try expect(arr1[0] == 42);
614627 try expect(arr1[1] == 56);
615628 try expect(arr1[2] == 54);
616629
617630 var x2: U = .{ .a = 42 };
631 _ = &x2;
618632 const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } };
619 var arr2: *const [3]U = t2;
633 const arr2: *const [3]U = t2;
620634 try expect(arr2[0].a == 42);
621635 try expect(arr2[1].b == true);
622636 try expect(mem.eql(u8, arr2[2].c, "hello"));
......@@ -656,6 +670,7 @@ test "array init of container level array variable" {
656670 }
657671 noinline fn bar(x: usize, y: usize) void {
658672 var tmp: [2]usize = .{ x, y };
673 _ = &tmp;
659674 pair = tmp;
660675 }
661676 };
......@@ -668,6 +683,7 @@ test "array init of container level array variable" {
668683
669684test "runtime initialized sentinel-terminated array literal" {
670685 var c: u16 = 300;
686 _ = &c;
671687 const f = &[_:0x9999]u16{c};
672688 const g = @as(*const [4]u8, @ptrCast(f));
673689 try std.testing.expect(g[2] == 0x99);
......@@ -681,6 +697,7 @@ test "array of array agregate init" {
681697
682698 var a = [1]u32{11} ** 10;
683699 var b = [1][10]u32{a} ** 2;
700 _ = .{ &a, &b };
684701 try std.testing.expect(b[1][1] == 11);
685702}
686703
......@@ -778,6 +795,7 @@ test "runtime side-effects in comptime-known array init" {
778795test "slice initialized through reference to anonymous array init provides result types" {
779796 var my_u32: u32 = 123;
780797 var my_u64: u64 = 456;
798 _ = .{ &my_u32, &my_u64 };
781799 const foo: []const u16 = &.{
782800 @intCast(my_u32),
783801 @intCast(my_u64),
......@@ -790,6 +808,7 @@ test "slice initialized through reference to anonymous array init provides resul
790808test "pointer to array initialized through reference to anonymous array init provides result types" {
791809 var my_u32: u32 = 123;
792810 var my_u64: u64 = 456;
811 _ = .{ &my_u32, &my_u64 };
793812 const foo: *const [4]u16 = &.{
794813 @intCast(my_u32),
795814 @intCast(my_u64),
test/behavior/asm.zig+1
......@@ -180,6 +180,7 @@ test "asm modifiers (AArch64)" {
180180 if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly
181181
182182 var x: u32 = 15;
183 _ = &x;
183184 const double = asm ("add %[ret:w], %[in:w], %[in:w]"
184185 : [ret] "=r" (-> u32),
185186 : [in] "r" (x),
test/behavior/async_fn.zig+22-10
......@@ -137,11 +137,13 @@ test "@frameSize" {
137137 fn doTheTest() !void {
138138 {
139139 var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other));
140 _ = &ptr;
140141 const size = @frameSize(ptr);
141142 try expect(size == @sizeOf(@Frame(other)));
142143 }
143144 {
144145 var ptr = @as(fn () callconv(.Async) void, @ptrCast(first));
146 _ = &ptr;
145147 const size = @frameSize(ptr);
146148 try expect(size == @sizeOf(@Frame(first)));
147149 }
......@@ -153,7 +155,7 @@ test "@frameSize" {
153155 fn other(param: i32) void {
154156 _ = param;
155157 var local: i32 = undefined;
156 _ = local;
158 _ = &local;
157159 suspend {}
158160 }
159161 };
......@@ -239,7 +241,7 @@ test "coroutine await" {
239241
240242 await_seq('a');
241243 var p = async await_amain();
242 _ = p;
244 _ = &p;
243245 await_seq('f');
244246 resume await_a_promise;
245247 await_seq('i');
......@@ -279,7 +281,7 @@ test "coroutine await early return" {
279281
280282 early_seq('a');
281283 var p = async early_amain();
282 _ = p;
284 _ = &p;
283285 early_seq('f');
284286 try expect(early_final_result == 1234);
285287 try expect(std.mem.eql(u8, &early_points, "abcdef"));
......@@ -329,6 +331,7 @@ test "async fn pointer in a struct field" {
329331 bar: fn (*i32) callconv(.Async) void,
330332 };
331333 var foo = Foo{ .bar = simpleAsyncFn2 };
334 _ = &foo;
332335 var bytes: [64]u8 align(16) = undefined;
333336 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
334337 try comptime expect(@TypeOf(f) == anyframe->void);
......@@ -367,6 +370,7 @@ test "@asyncCall with return type" {
367370 }
368371 };
369372 var foo = Foo{ .bar = Foo.middle };
373 _ = &foo;
370374 var bytes: [150]u8 align(16) = undefined;
371375 var aresult: i32 = 0;
372376 _ = @asyncCall(&bytes, &aresult, foo.bar, .{});
......@@ -385,6 +389,7 @@ test "async fn with inferred error set" {
385389 fn doTheTest() !void {
386390 var frame: [1]@Frame(middle) = undefined;
387391 var fn_ptr = middle;
392 _ = &fn_ptr;
388393 var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;
389394 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{});
390395 resume global_frame;
......@@ -827,7 +832,7 @@ test "alignment of local variables in async functions" {
827832 const S = struct {
828833 fn doTheTest() !void {
829834 var y: u8 = 123;
830 _ = y;
835 _ = &y;
831836 var x: u8 align(128) = 1;
832837 try expect(@intFromPtr(&x) % 128 == 0);
833838 }
......@@ -843,7 +848,7 @@ test "no reason to resolve frame still works" {
843848}
844849fn simpleNothing() void {
845850 var x: i32 = 1234;
846 _ = x;
851 _ = &x;
847852}
848853
849854test "async call a generic function" {
......@@ -913,13 +918,14 @@ test "struct parameter to async function is copied to the frame" {
913918 if (x == 0) return;
914919 clobberStack(x - 1);
915920 var y: i32 = x;
916 _ = y;
921 _ = &y;
917922 }
918923
919924 fn bar(f: *@Frame(foo)) void {
920925 var pt = Point{ .x = 1, .y = 2 };
926 _ = &pt;
921927 f.* = async foo(pt);
922 var result = await f;
928 const result = await f;
923929 expect(result == 1) catch @panic("test failure");
924930 }
925931
......@@ -1141,6 +1147,7 @@ test "@asyncCall using the result location inside the frame" {
11411147 bar: fn (*i32) callconv(.Async) i32,
11421148 };
11431149 var foo = Foo{ .bar = S.simple2 };
1150 _ = &foo;
11441151 var bytes: [64]u8 align(16) = undefined;
11451152 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
11461153 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" {
14651472 // the for loop spills still happen even though there is a VarDecl in scope
14661473 // before the suspend.
14671474 var anything = true;
1468 _ = anything;
1475 _ = &anything;
14691476 suspend {
14701477 global_frame = @frame();
14711478 }
......@@ -1538,6 +1545,7 @@ test "async function passed align(16) arg after align(8) arg" {
15381545
15391546 fn foo() void {
15401547 var a: u128 = 99;
1548 _ = &a;
15411549 bar(10, .{a}) catch unreachable;
15421550 }
15431551
......@@ -1590,6 +1598,7 @@ test "async function call resolves target fn frame, runtime func" {
15901598 const stack_size = 1000;
15911599 var stack_frame: [stack_size]u8 align(std.Target.stack_align) = undefined;
15921600 var func: fn () callconv(.Async) anyerror!void = bar;
1601 _ = &func;
15931602 return await @asyncCall(&stack_frame, {}, func, .{});
15941603 }
15951604
......@@ -1614,6 +1623,7 @@ test "properly spill optional payload capture value" {
16141623
16151624 fn foo() void {
16161625 var opt: ?usize = 1234;
1626 _ = &opt;
16171627 if (opt) |x| {
16181628 bar();
16191629 global_int += x;
......@@ -1863,6 +1873,7 @@ test "@asyncCall with pass-by-value arguments" {
18631873 var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined;
18641874 // The function pointer must not be comptime-known.
18651875 var t = S.f;
1876 _ = &t;
18661877 var frame_ptr = @asyncCall(&buffer, {}, t, .{
18671878 F0,
18681879 .{ .f0 = 1, .f1 = 2 },
......@@ -1870,7 +1881,7 @@ test "@asyncCall with pass-by-value arguments" {
18701881 [_]u8{ 1, 2, 3, 4, 5 },
18711882 F2,
18721883 });
1873 _ = frame_ptr;
1884 _ = &frame_ptr;
18741885}
18751886
18761887test "@asyncCall with arguments having non-standard alignment" {
......@@ -1893,6 +1904,7 @@ test "@asyncCall with arguments having non-standard alignment" {
18931904 var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined;
18941905 // The function pointer must not be comptime-known.
18951906 var t = S.f;
1907 _ = &t;
18961908 var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 });
1897 _ = frame_ptr;
1909 _ = &frame_ptr;
18981910}
test/behavior/await_struct.zig+1-1
......@@ -14,7 +14,7 @@ test "coroutine await struct" {
1414
1515 await_seq('a');
1616 var p = async await_amain();
17 _ = p;
17 _ = &p;
1818 await_seq('f');
1919 resume await_a_promise;
2020 await_seq('i');
test/behavior/basic.zig+16-3
......@@ -118,6 +118,7 @@ fn thisIsAColdFn() void {
118118
119119test "unicode escape in character literal" {
120120 var a: u24 = '\u{01f4a9}';
121 _ = &a;
121122 try expect(a == 128169);
122123}
123124
......@@ -362,6 +363,7 @@ test "variable is allowed to be a pointer to an opaque type" {
362363}
363364fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA {
364365 var a = ptr;
366 _ = &a;
365367 return a;
366368}
367369
......@@ -441,6 +443,7 @@ test "double implicit cast in same expression" {
441443 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
442444
443445 var x = @as(i32, @as(u16, nine()));
446 _ = &x;
444447 try expect(x == 9);
445448}
446449fn nine() u8 {
......@@ -570,6 +573,7 @@ test "comptime cast fn to ptr" {
570573
571574test "equality compare fn ptrs" {
572575 var a = &emptyFn;
576 _ = &a;
573577 try expect(a == a);
574578}
575579
......@@ -611,6 +615,7 @@ test "global constant is loaded with a runtime-known index" {
611615 const S = struct {
612616 fn doTheTest() !void {
613617 var index: usize = 1;
618 _ = &index;
614619 const ptr = &pieces[index].field;
615620 try expect(ptr.* == 2);
616621 }
......@@ -785,6 +790,7 @@ test "variable name containing underscores does not shadow int primitive" {
785790
786791test "if expression type coercion" {
787792 var cond: bool = true;
793 _ = &cond;
788794 const x: u16 = if (cond) 1 else 0;
789795 try expect(@as(u16, x) == 1);
790796}
......@@ -825,6 +831,7 @@ test "discarding the result of various expressions" {
825831
826832test "labeled block implicitly ends in a break" {
827833 var a = false;
834 _ = &a;
828835 blk: {
829836 if (a) break :blk;
830837 }
......@@ -852,6 +859,7 @@ test "catch in block has correct result location" {
852859test "labeled block with runtime branch forwards its result location type to break statements" {
853860 const E = enum { a, b };
854861 var a = false;
862 _ = &a;
855863 const e: E = blk: {
856864 if (a) {
857865 break :blk .a;
......@@ -872,8 +880,7 @@ test "try in labeled block doesn't cast to wrong type" {
872880 };
873881 const s: ?*S = blk: {
874882 var a = try S.foo();
875
876 _ = a;
883 _ = &a;
877884 break :blk null;
878885 };
879886 _ = s;
......@@ -894,6 +901,7 @@ test "weird array and tuple initializations" {
894901 const E = enum { a, b };
895902 const S = struct { e: E };
896903 var a = false;
904 _ = &a;
897905 const b = S{ .e = .a };
898906
899907 _ = &[_]S{
......@@ -1009,6 +1017,7 @@ test "switch inside @as gets correct type" {
10091017 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
10101018
10111019 var a: u32 = 0;
1020 _ = &a;
10121021 var b: [2]u32 = undefined;
10131022 b[0] = @as(u32, switch (a) {
10141023 1 => 1,
......@@ -1110,7 +1119,8 @@ test "orelse coercion as function argument" {
11101119 }
11111120 };
11121121 var optional: ?Loc = .{};
1113 var foo = Container.init(optional orelse .{});
1122 _ = &optional;
1123 const foo = Container.init(optional orelse .{});
11141124 try expect(foo.a.?.start == -1);
11151125}
11161126
......@@ -1153,6 +1163,7 @@ test "arrays and vectors with big integers" {
11531163test "pointer to struct literal with runtime field is constant" {
11541164 const S = struct { data: usize };
11551165 var runtime_zero: usize = 0;
1166 _ = &runtime_zero;
11561167 const ptr = &S{ .data = runtime_zero };
11571168 try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_const);
11581169}
......@@ -1163,6 +1174,7 @@ test "integer compare" {
11631174 var z: T = 0;
11641175 var p: T = 123;
11651176 var n: T = -123;
1177 _ = .{ &z, &p, &n };
11661178 try expect(z == z and z != p and z != n);
11671179 try expect(p == p and p != n and n == n);
11681180 try expect(z > n and z < p and z >= n and z <= p);
......@@ -1180,6 +1192,7 @@ test "integer compare" {
11801192 fn doTheTestUnsigned(comptime T: type) !void {
11811193 var z: T = 0;
11821194 var p: T = 123;
1195 _ = .{ &z, &p };
11831196 try expect(z == z and z != p);
11841197 try expect(p == p);
11851198 try expect(z < p and z <= p);
test/behavior/bit_shifting.zig+2-2
......@@ -99,9 +99,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c
9999// #2225
100100test "comptime shr of BigInt" {
101101 comptime {
102 var n0 = 0xdeadbeef0000000000000000;
102 const n0 = 0xdeadbeef0000000000000000;
103103 try expect(n0 >> 64 == 0xdeadbeef);
104 var n1 = 17908056155735594659;
104 const n1 = 17908056155735594659;
105105 try expect(n1 >> 64 == 0);
106106 }
107107}
test/behavior/bitcast.zig+19-7
......@@ -149,8 +149,9 @@ test "bitcast literal [4]u8 param to u32" {
149149}
150150
151151test "bitcast generates a temporary value" {
152 var y = @as(u16, 0x55AA);
153 const x = @as(u16, @bitCast(@as([2]u8, @bitCast(y))));
152 var y: u16 = 0x55AA;
153 _ = &y;
154 const x: u16 = @bitCast(@as([2]u8, @bitCast(y)));
154155 try expect(y == x);
155156}
156157
......@@ -171,7 +172,8 @@ test "@bitCast packed structs at runtime and comptime" {
171172 const S = struct {
172173 fn doTheTest() !void {
173174 var full = Full{ .number = 0x1234 };
174 var two_halves = @as(Divided, @bitCast(full));
175 _ = &full;
176 const two_halves: Divided = @bitCast(full);
175177 try expect(two_halves.half1 == 0x34);
176178 try expect(two_halves.quarter3 == 0x2);
177179 try expect(two_halves.quarter4 == 0x1);
......@@ -195,7 +197,8 @@ test "@bitCast extern structs at runtime and comptime" {
195197 const S = struct {
196198 fn doTheTest() !void {
197199 var full = Full{ .number = 0x1234 };
198 var two_halves = @as(TwoHalves, @bitCast(full));
200 _ = &full;
201 const two_halves: TwoHalves = @bitCast(full);
199202 switch (native_endian) {
200203 .big => {
201204 try expect(two_halves.half1 == 0x12);
......@@ -225,8 +228,9 @@ test "bitcast packed struct to integer and back" {
225228 const S = struct {
226229 fn doTheTest() !void {
227230 var move = LevelUpMove{ .move_id = 1, .level = 2 };
228 var v = @as(u16, @bitCast(move));
229 var back_to_a_move = @as(LevelUpMove, @bitCast(v));
231 _ = &move;
232 const v: u16 = @bitCast(move);
233 const back_to_a_move: LevelUpMove = @bitCast(v);
230234 try expect(back_to_a_move.move_id == 1);
231235 try expect(back_to_a_move.level == 2);
232236 }
......@@ -312,7 +316,8 @@ test "@bitCast packed struct of floats" {
312316 const S = struct {
313317 fn doTheTest() !void {
314318 var foo = Foo{};
315 var v = @as(Foo2, @bitCast(foo));
319 _ = &foo;
320 const v: Foo2 = @bitCast(foo);
316321 try expect(v.a == foo.a);
317322 try expect(v.b == foo.b);
318323 try expect(v.c == foo.c);
......@@ -354,10 +359,12 @@ test "comptime @bitCast packed struct to int and back" {
354359
355360 // S -> Int
356361 var s: S = .{};
362 _ = &s;
357363 try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{})));
358364
359365 // Int -> S
360366 var i: Int = 0;
367 _ = &i;
361368 const rt_cast = @as(S, @bitCast(i));
362369 const ct_cast = comptime @as(S, @bitCast(@as(Int, 0)));
363370 inline for (@typeInfo(S).Struct.fields) |field| {
......@@ -376,6 +383,7 @@ test "comptime bitcast with fields following f80" {
376383 const FloatT = extern struct { f: f80, x: u128 align(16) };
377384 const x: FloatT = .{ .f = 0.5, .x = 123 };
378385 var x_as_uint: u256 = comptime @as(u256, @bitCast(x));
386 _ = &x_as_uint;
379387
380388 try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f);
381389 try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x);
......@@ -428,6 +436,7 @@ test "bitcast nan float does not modify signaling bit" {
428436 try expectEqual(snan_u16, bitCastWrapper16(snan_f16_const));
429437
430438 var snan_f16_var = math.snan(f16);
439 _ = &snan_f16_var;
431440 try expectEqual(snan_u16, @as(u16, @bitCast(snan_f16_var)));
432441 try expectEqual(snan_u16, bitCastWrapper16(snan_f16_var));
433442
......@@ -437,6 +446,7 @@ test "bitcast nan float does not modify signaling bit" {
437446 try expectEqual(snan_u32, bitCastWrapper32(snan_f32_const));
438447
439448 var snan_f32_var = math.snan(f32);
449 _ = &snan_f32_var;
440450 try expectEqual(snan_u32, @as(u32, @bitCast(snan_f32_var)));
441451 try expectEqual(snan_u32, bitCastWrapper32(snan_f32_var));
442452
......@@ -446,6 +456,7 @@ test "bitcast nan float does not modify signaling bit" {
446456 try expectEqual(snan_u64, bitCastWrapper64(snan_f64_const));
447457
448458 var snan_f64_var = math.snan(f64);
459 _ = &snan_f64_var;
449460 try expectEqual(snan_u64, @as(u64, @bitCast(snan_f64_var)));
450461 try expectEqual(snan_u64, bitCastWrapper64(snan_f64_var));
451462
......@@ -455,6 +466,7 @@ test "bitcast nan float does not modify signaling bit" {
455466 try expectEqual(snan_u128, bitCastWrapper128(snan_f128_const));
456467
457468 var snan_f128_var = math.snan(f128);
469 _ = &snan_f128_var;
458470 try expectEqual(snan_u128, @as(u128, @bitCast(snan_f128_var)));
459471 try expectEqual(snan_u128, bitCastWrapper128(snan_f128_var));
460472}
test/behavior/bitreverse.zig+26-4
......@@ -86,11 +86,30 @@ fn testBitReverse() !void {
8686 try expect(@bitReverse(@as(i24, -6773785)) == @bitReverse(neg24));
8787 var neg32: i32 = -16773785;
8888 try expect(@bitReverse(@as(i32, -16773785)) == @bitReverse(neg32));
89
90 _ = .{
91 &num0,
92 &num5,
93 &num8,
94 &num16,
95 &num24,
96 &num32,
97 &num40,
98 &num48,
99 &num56,
100 &num64,
101 &num128,
102 &neg8,
103 &neg16,
104 &neg24,
105 &neg32,
106 };
89107}
90108
91109fn vector8() !void {
92110 var v = @Vector(2, u8){ 0x12, 0x23 };
93 var result = @bitReverse(v);
111 _ = &v;
112 const result = @bitReverse(v);
94113 try expect(result[0] == 0x48);
95114 try expect(result[1] == 0xc4);
96115}
......@@ -109,7 +128,8 @@ test "bitReverse vectors u8" {
109128
110129fn vector16() !void {
111130 var v = @Vector(2, u16){ 0x1234, 0x2345 };
112 var result = @bitReverse(v);
131 _ = &v;
132 const result = @bitReverse(v);
113133 try expect(result[0] == 0x2c48);
114134 try expect(result[1] == 0xa2c4);
115135}
......@@ -128,7 +148,8 @@ test "bitReverse vectors u16" {
128148
129149fn vector24() !void {
130150 var v = @Vector(2, u24){ 0x123456, 0x234567 };
131 var result = @bitReverse(v);
151 _ = &v;
152 const result = @bitReverse(v);
132153 try expect(result[0] == 0x6a2c48);
133154 try expect(result[1] == 0xe6a2c4);
134155}
......@@ -147,7 +168,8 @@ test "bitReverse vectors u24" {
147168
148169fn vector0() !void {
149170 var v = @Vector(2, u0){ 0, 0 };
150 var result = @bitReverse(v);
171 _ = &v;
172 const result = @bitReverse(v);
151173 try expect(result[0] == 0);
152174 try expect(result[1] == 0);
153175}
test/behavior/bugs/10147.zig+4-2
......@@ -10,9 +10,11 @@ test "test calling @clz on both vector and scalar inputs" {
1010 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1111
1212 var x: u32 = 0x1;
13 _ = &x;
1314 var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 };
14 var a = @clz(x);
15 var b = @clz(y);
15 _ = &y;
16 const a = @clz(x);
17 const b = @clz(y);
1618 try std.testing.expectEqual(@as(u6, 31), a);
1719 try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b);
1820}
test/behavior/bugs/10970.zig+1
......@@ -9,6 +9,7 @@ test "breaking from a loop in an if statement" {
99 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1010
1111 var cond = true;
12 _ = &cond;
1213 const opt = while (cond) {
1314 if (retOpt()) |opt| {
1415 break opt;
test/behavior/bugs/11046.zig+1
......@@ -2,6 +2,7 @@ const builtin = @import("builtin");
22
33fn foo() !void {
44 var a = true;
5 _ = &a;
56 if (a) return error.Foo;
67 return error.Bar;
78}
test/behavior/bugs/11139.zig+1
......@@ -21,5 +21,6 @@ fn storeArrayOfArrayOfStructs() u8 {
2121 S{ .x = 15 },
2222 },
2323 };
24 _ = &cases;
2425 return cases[0][0].x;
2526}
test/behavior/bugs/11159.zig+3-3
......@@ -4,7 +4,7 @@ const builtin = @import("builtin");
44test {
55 const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });
66 var a: T = .{ 0, 0 };
7 _ = a;
7 _ = &a;
88}
99
1010test {
......@@ -13,7 +13,7 @@ test {
1313 comptime y: u32 = 0,
1414 };
1515 var a: S = .{};
16 _ = a;
16 _ = &a;
1717 var b = S{};
18 _ = b;
18 _ = &b;
1919}
test/behavior/bugs/11162.zig+2-1
......@@ -6,8 +6,9 @@ test "aggregate initializers should allow initializing comptime fields, verifyin
66 if (true) return error.SkipZigTest; // TODO
77
88 var x: u32 = 15;
9 _ = &x;
910 const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
10 var a: T = .{ -1234, 5678, x + 1 };
11 const a: T = .{ -1234, 5678, x + 1 };
1112
1213 try expect(a[0] == -1234);
1314 try expect(a[1] == 5678);
test/behavior/bugs/11165.zig+2-2
......@@ -18,7 +18,7 @@ test "bytes" {
1818 };
1919
2020 var u_2 = U{ .s = s_1 };
21 _ = u_2;
21 _ = &u_2;
2222}
2323
2424test "aggregate" {
......@@ -40,5 +40,5 @@ test "aggregate" {
4040 };
4141
4242 var u_2 = U{ .s = s_1 };
43 _ = u_2;
43 _ = &u_2;
4444}
test/behavior/bugs/11181.zig+1-1
......@@ -21,5 +21,5 @@ test "var inferred array of slices" {
2121 .{ .v = false },
2222 },
2323 };
24 _ = decls;
24 _ = &decls;
2525}
test/behavior/bugs/12000.zig+1
......@@ -11,5 +11,6 @@ test {
1111 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1212
1313 var t: T = .{ .next = null };
14 _ = &t;
1415 try std.testing.expect(t.next == null);
1516}
test/behavior/bugs/12025.zig+1
......@@ -5,6 +5,7 @@ test {
55 .foo = &1,
66 .bar = &2,
77 };
8 _ = &st;
89
910 inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| {
1011 _ = field;
test/behavior/bugs/12092.zig+1
......@@ -19,6 +19,7 @@ test {
1919 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
2020
2121 var baz: u32 = 24;
22 _ = &baz;
2223 try takeFoo(&.{
2324 .a = .{
2425 .b = baz,
test/behavior/bugs/12498.zig+1
......@@ -4,5 +4,6 @@ const expect = std.testing.expect;
44const S = struct { a: usize };
55test "lazy abi size used in comparison" {
66 var rhs: i32 = 100;
7 _ = &rhs;
78 try expect(@sizeOf(S) < rhs);
89}
test/behavior/bugs/12776.zig+1
......@@ -22,6 +22,7 @@ const CPU = packed struct {
2222 }
2323 fn tick(self: *CPU) !void {
2424 var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F);
25 _ = &queued_interrupts;
2526 if (self.interrupts and queued_interrupts != 0) {
2627 self.interrupts = false;
2728 }
test/behavior/bugs/12891.zig+5
......@@ -4,26 +4,31 @@ const builtin = @import("builtin");
44test "issue12891" {
55 const f = 10.0;
66 var i: usize = 0;
7 _ = &i;
78 try std.testing.expect(i < f);
89}
910test "nan" {
1011 const f = comptime std.math.nan(f64);
1112 var i: usize = 0;
13 _ = &i;
1214 try std.testing.expect(!(f < i));
1315}
1416test "inf" {
1517 const f = comptime std.math.inf(f64);
1618 var i: usize = 0;
19 _ = &i;
1720 try std.testing.expect(f > i);
1821}
1922test "-inf < 0" {
2023 const f = comptime -std.math.inf(f64);
2124 var i: usize = 0;
25 _ = &i;
2226 try std.testing.expect(f < i);
2327}
2428test "inf >= 1" {
2529 const f = comptime std.math.inf(f64);
2630 var i: usize = 1;
31 _ = &i;
2732 try std.testing.expect(f >= i);
2833}
2934test "isNan(nan * 1)" {
test/behavior/bugs/12972.zig+1
......@@ -12,6 +12,7 @@ test {
1212 f(&.{c});
1313
1414 var v: u8 = 42;
15 _ = &v;
1516 f(&[_:null]?u8{v});
1617 f(&.{v});
1718}
test/behavior/bugs/12984.zig+1-1
......@@ -16,5 +16,5 @@ test "simple test" {
1616 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1717
1818 var c: CustomDraw = undefined;
19 _ = c;
19 _ = &c;
2020}
test/behavior/bugs/13128.zig+1
......@@ -18,6 +18,7 @@ test "runtime union init, most-aligned field != largest" {
1818 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1919
2020 var x: u8 = 1;
21 _ = &x;
2122 try foo(.{ .x = x });
2223
2324 const val: U = @unionInit(U, "x", x);
test/behavior/bugs/13159.zig+1
......@@ -13,5 +13,6 @@ test {
1313 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1414
1515 var foo = Bar.Baz.fizz;
16 _ = &foo;
1617 try expect(foo == .fizz);
1718}
test/behavior/bugs/13285.zig+1-1
......@@ -8,7 +8,7 @@ test {
88 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
99
1010 var a: Crasher = undefined;
11 var crasher_ptr = &a;
11 const crasher_ptr = &a;
1212 var crasher_local = crasher_ptr.*;
1313 const crasher_local_ptr = &crasher_local;
1414 crasher_local_ptr.lets_crash = 1;
test/behavior/bugs/13366.zig+2
......@@ -18,9 +18,11 @@ test {
1818 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1919
2020 var a: u32 = 16;
21 _ = &a;
2122 var reason = .{ .c_import = .{ .a = a } };
2223 var block = Block{
2324 .reason = &reason,
2425 };
26 _ = &block;
2527 try expect(block.reason.?.c_import.a == 16);
2628}
test/behavior/bugs/13714.zig+1
......@@ -1,4 +1,5 @@
11comptime {
22 var image: [1]u8 = undefined;
3 _ = &image;
34 _ = @shlExact(@as(u16, image[0]), 8);
45}
test/behavior/bugs/13785.zig+1
......@@ -9,5 +9,6 @@ test {
99 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1010
1111 var a: u8 = 0;
12 _ = &a;
1213 try std.io.null_writer.print("\n{} {}\n", .{ a, S{} });
1314}
test/behavior/bugs/1381.zig+1
......@@ -20,6 +20,7 @@ test "union that needs padding bytes inside an array" {
2020 A{ .B = B{ .D = 1 } },
2121 A{ .B = B{ .D = 1 } },
2222 };
23 _ = &as;
2324
2425 const a = as[0].B;
2526 try std.testing.expect(a.D == 1);
test/behavior/bugs/1442.zig+1
......@@ -12,5 +12,6 @@ test "const error union field alignment" {
1212 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1313
1414 var union_or_err: anyerror!Union = Union{ .Color = 1234 };
15 _ = &union_or_err;
1516 try std.testing.expect((union_or_err catch unreachable).Color == 1234);
1617}
test/behavior/bugs/1500.zig+1
......@@ -8,6 +8,7 @@ const B = *const fn (A) void;
88test "allow these dependencies" {
99 var a: A = undefined;
1010 var b: B = undefined;
11 _ = .{ &a, &b };
1112 if (false) {
1213 a;
1314 b;
test/behavior/bugs/1735.zig+1-1
......@@ -45,6 +45,6 @@ test "initialization" {
4545 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
4646 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
4747
48 var t = a.init();
48 const t = a.init();
4949 try std.testing.expect(t.foo.len == 0);
5050}
test/behavior/bugs/2557.zig+1-1
......@@ -2,5 +2,5 @@ test {
22 var a = if (true) {
33 return;
44 } else true;
5 _ = a;
5 _ = &a;
66}
test/behavior/bugs/3468.zig+1
......@@ -3,4 +3,5 @@ test "pointer deref next to assignment" {
33 var a:i32=2;
44 var b=&a;
55 b.*=3;
6 _=&b;
67}
test/behavior/bugs/3586.zig+1-1
......@@ -12,5 +12,5 @@ test "fixed" {
1212 var ctr = Container{
1313 .params = NoteParams{},
1414 };
15 _ = ctr;
15 _ = &ctr;
1616}
test/behavior/bugs/4560.zig+1
......@@ -11,6 +11,7 @@ test "fixed" {
1111 .max_distance_from_start_index = 456,
1212 },
1313 };
14 _ = &s;
1415 try std.testing.expect(s.a == 1);
1516 try std.testing.expect(s.b.size == 123);
1617 try std.testing.expect(s.b.max_distance_from_start_index == 456);
test/behavior/bugs/6047.zig+1
......@@ -6,6 +6,7 @@ fn getError() !void {
66
77fn getError2() !void {
88 var a: u8 = 'c';
9 _ = &a;
910 try if (a == 'a') getError() else if (a == 'b') getError() else getError();
1011}
1112
test/behavior/bugs/624.zig+1
......@@ -25,5 +25,6 @@ test "foo" {
2525 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
2626
2727 var allocator = ContextAllocator{ .n = 10 };
28 _ = &allocator;
2829 try expect(allocator.n == 10);
2930}
test/behavior/bugs/656.zig+1
......@@ -22,6 +22,7 @@ fn foo(a: bool, b: bool) !void {
2222 var prefix_op = PrefixOp{
2323 .AddrOf = Value{ .align_expr = 1234 },
2424 };
25 _ = &prefix_op;
2526 if (a) {} else {
2627 switch (prefix_op) {
2728 PrefixOp.AddrOf => |addr_of_info| {
test/behavior/bugs/6781.zig+2-1
......@@ -51,7 +51,8 @@ pub const JournalHeader = packed struct {
5151 return @as(u128, @bitCast(target[0..hash_chain_root_size].*));
5252 } else {
5353 var array = target[0..hash_chain_root_size].*;
54 return @as(u128, @bitCast(array));
54 _ = &array;
55 return @bitCast(array);
5556 }
5657 }
5758
test/behavior/bugs/679.zig+1
......@@ -14,5 +14,6 @@ const Element = struct {
1414test "false dependency loop in struct definition" {
1515 const listType = ElementList;
1616 var x: listType = 42;
17 _ = &x;
1718 try expect(x == 42);
1819}
test/behavior/bugs/6905.zig+5-3
......@@ -6,13 +6,15 @@ test "sentinel-terminated 0-length slices" {
66 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
77 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
88
9 var u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 };
9 const u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 };
1010
1111 var index: u8 = 2;
12 var slice = u32s[index..index :2];
13 var array_ptr = u32s[2..2 :2];
12 _ = &index;
13 const slice = u32s[index..index :2];
14 const array_ptr = u32s[2..2 :2];
1415 const comptime_known_array_value = u32s[2..2 :2].*;
1516 var runtime_array_value = u32s[2..2 :2].*;
17 _ = &runtime_array_value;
1618
1719 try expect(slice[0] == 2);
1820 try expect(array_ptr[0] == 2);
test/behavior/bugs/7187.zig+1-1
......@@ -5,7 +5,7 @@ const expect = std.testing.expect;
55test "miscompilation with bool return type" {
66 var x: usize = 1;
77 var y: bool = getFalse();
8 _ = y;
8 _ = .{ &x, &y };
99
1010 try expect(x == 1);
1111}
test/behavior/bugs/726.zig+4-2
......@@ -7,7 +7,8 @@ test "@ptrCast from const to nullable" {
77 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
88
99 const c: u8 = 4;
10 var x: ?*const u8 = @as(?*const u8, @ptrCast(&c));
10 var x: ?*const u8 = @ptrCast(&c);
11 _ = &x;
1112 try expect(x.?.* == 4);
1213}
1314
......@@ -19,6 +20,7 @@ test "@ptrCast from var in empty struct to nullable" {
1920 const container = struct {
2021 var c: u8 = 4;
2122 };
22 var x: ?*const u8 = @as(?*const u8, @ptrCast(&container.c));
23 var x: ?*const u8 = @ptrCast(&container.c);
24 _ = &x;
2325 try expect(x.?.* == 4);
2426}
test/behavior/bugs/7325.zig+2
......@@ -85,6 +85,7 @@ test {
8585 var param: ParamType = .{
8686 .one_of = .{ .name = "name" },
8787 };
88 _ = &param;
8889 var arg: CallArg = .{
8990 .value = .{
9091 .literal_enum_value = .{
......@@ -92,6 +93,7 @@ test {
9293 },
9394 },
9495 };
96 _ = &arg;
9597
9698 const result = try genExpression(arg.value);
9799 switch (result) {
test/behavior/bugs/9584.zig+1
......@@ -60,6 +60,7 @@ test {
6060 .g = false,
6161 .h = false,
6262 };
63 _ = &flags;
6364 var x = X{
6465 .x = flags,
6566 };
test/behavior/byteswap.zig+8-4
......@@ -56,7 +56,8 @@ test "@byteSwap integers" {
5656
5757fn vector8() !void {
5858 var v = @Vector(2, u8){ 0x12, 0x13 };
59 var result = @byteSwap(v);
59 _ = &v;
60 const result = @byteSwap(v);
6061 try expect(result[0] == 0x12);
6162 try expect(result[1] == 0x13);
6263}
......@@ -75,7 +76,8 @@ test "@byteSwap vectors u8" {
7576
7677fn vector16() !void {
7778 var v = @Vector(2, u16){ 0x1234, 0x2345 };
78 var result = @byteSwap(v);
79 _ = &v;
80 const result = @byteSwap(v);
7981 try expect(result[0] == 0x3412);
8082 try expect(result[1] == 0x4523);
8183}
......@@ -94,7 +96,8 @@ test "@byteSwap vectors u16" {
9496
9597fn vector24() !void {
9698 var v = @Vector(2, u24){ 0x123456, 0x234567 };
97 var result = @byteSwap(v);
99 _ = &v;
100 const result = @byteSwap(v);
98101 try expect(result[0] == 0x563412);
99102 try expect(result[1] == 0x674523);
100103}
......@@ -113,7 +116,8 @@ test "@byteSwap vectors u24" {
113116
114117fn vector0() !void {
115118 var v = @Vector(2, u0){ 0, 0 };
116 var result = @byteSwap(v);
119 _ = &v;
120 const result = @byteSwap(v);
117121 try expect(result[0] == 0);
118122 try expect(result[1] == 0);
119123}
test/behavior/call.zig+5
......@@ -47,6 +47,7 @@ test "basic invocations" {
4747 {
4848 // call of non comptime-known function
4949 var alias_foo = &foo;
50 _ = &alias_foo;
5051 try expect(@call(.no_async, alias_foo, .{}) == 1234);
5152 try expect(@call(.never_tail, alias_foo, .{}) == 1234);
5253 try expect(@call(.never_inline, alias_foo, .{}) == 1234);
......@@ -66,6 +67,7 @@ test "tuple parameters" {
6667 }.add;
6768 var a: i32 = 12;
6869 var b: i32 = 34;
70 _ = .{ &a, &b };
6971 try expect(@call(.auto, add, .{ a, 34 }) == 46);
7072 try expect(@call(.auto, add, .{ 12, b }) == 46);
7173 try expect(@call(.auto, add, .{ a, b }) == 46);
......@@ -101,6 +103,7 @@ test "result location of function call argument through runtime condition and st
101103 }
102104 };
103105 var runtime = true;
106 _ = &runtime;
104107 try namespace.foo(.{
105108 .e = if (!runtime) .a else .b,
106109 });
......@@ -445,6 +448,7 @@ test "non-anytype generic parameters provide result type" {
445448
446449 var rt_u16: u16 = 123;
447450 var rt_u32: u32 = 0x10000222;
451 _ = .{ &rt_u16, &rt_u32 };
448452
449453 try S.f(u8, @intCast(rt_u16));
450454 try S.f(u8, @intCast(123));
......@@ -470,6 +474,7 @@ test "argument to generic function has correct result type" {
470474
471475 fn doTheTest() !void {
472476 var t = true;
477 _ = &t;
473478
474479 // Since the enum literal passes through a runtime conditional here, these can only
475480 // compile if RLS provides the correct result type to the argument
test/behavior/cast.zig+118-42
......@@ -58,6 +58,7 @@ test "@intCast to comptime_int" {
5858test "implicit cast comptime numbers to any type when the value fits" {
5959 const a: u64 = 255;
6060 var b: u8 = a;
61 _ = &b;
6162 try expect(b == 255);
6263}
6364
......@@ -273,7 +274,7 @@ test "implicit cast from *[N]T to [*c]T" {
273274
274275test "*usize to *void" {
275276 var i = @as(usize, 0);
276 var v = @as(*void, @ptrCast(&i));
277 const v: *void = @ptrCast(&i);
277278 v.* = {};
278279}
279280
......@@ -391,7 +392,8 @@ test "peer type unsigned int to signed" {
391392 var w: u31 = 5;
392393 var x: u8 = 7;
393394 var y: i32 = -5;
394 var a = w + y + x;
395 _ = .{ &w, &x, &y };
396 const a = w + y + x;
395397 try comptime expect(@TypeOf(a) == i32);
396398 try expect(a == 7);
397399}
......@@ -401,8 +403,9 @@ test "expected [*c]const u8, found [*:0]const u8" {
401403 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
402404
403405 var a: [*:0]const u8 = "hello";
404 var b: [*c]const u8 = a;
405 var c: [*:0]const u8 = b;
406 _ = &a;
407 const b: [*c]const u8 = a;
408 const c: [*:0]const u8 = b;
406409 try expect(std.mem.eql(u8, c[0..5], "hello"));
407410}
408411
......@@ -609,14 +612,16 @@ test "@intCast on vector" {
609612 fn doTheTest() !void {
610613 // Upcast (implicit, equivalent to @intCast)
611614 var up0: @Vector(2, u8) = [_]u8{ 0x55, 0xaa };
612 var up1 = @as(@Vector(2, u16), up0);
613 var up2 = @as(@Vector(2, u32), up0);
614 var up3 = @as(@Vector(2, u64), up0);
615 _ = &up0;
616 const up1 = @as(@Vector(2, u16), up0);
617 const up2 = @as(@Vector(2, u32), up0);
618 const up3 = @as(@Vector(2, u64), up0);
615619 // Downcast (safety-checked)
616620 var down0 = up3;
617 var down1 = @as(@Vector(2, u32), @intCast(down0));
618 var down2 = @as(@Vector(2, u16), @intCast(down0));
619 var down3 = @as(@Vector(2, u8), @intCast(down0));
621 _ = &down0;
622 const down1 = @as(@Vector(2, u32), @intCast(down0));
623 const down2 = @as(@Vector(2, u16), @intCast(down0));
624 const down3 = @as(@Vector(2, u8), @intCast(down0));
620625
621626 try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));
622627 try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa }));
......@@ -629,7 +634,8 @@ test "@intCast on vector" {
629634
630635 fn doTheTestFloat() !void {
631636 var vec: @Vector(2, f32) = @splat(1234.0);
632 var wider: @Vector(2, f64) = vec;
637 _ = &vec;
638 const wider: @Vector(2, f64) = vec;
633639 try expect(wider[0] == 1234.0);
634640 try expect(wider[1] == 1234.0);
635641 }
......@@ -648,7 +654,8 @@ test "@floatCast cast down" {
648654
649655 {
650656 var double: f64 = 0.001534;
651 var single = @as(f32, @floatCast(double));
657 _ = &double;
658 const single = @as(f32, @floatCast(double));
652659 try expect(single == 0.001534);
653660 }
654661 {
......@@ -672,6 +679,7 @@ test "peer type resolution: unreachable, error set, unreachable" {
672679 Unexpected,
673680 };
674681 var err = Error.SystemResources;
682 _ = &err;
675683 const transformed_err = switch (err) {
676684 error.FileDescriptorAlreadyPresentInSet => unreachable,
677685 error.OperationCausesCircularLoop => unreachable,
......@@ -821,10 +829,11 @@ test "peer cast *[0]T to E![]const T" {
821829 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
822830
823831 var buffer: [5]u8 = "abcde".*;
824 var buf: anyerror![]const u8 = buffer[0..];
832 const buf: anyerror![]const u8 = buffer[0..];
825833 var b = false;
826 var y = if (b) &[0]u8{} else buf;
827 var z = if (!b) buf else &[0]u8{};
834 _ = &b;
835 const y = if (b) &[0]u8{} else buf;
836 const z = if (!b) buf else &[0]u8{};
828837 try expect(mem.eql(u8, "abcde", y catch unreachable));
829838 try expect(mem.eql(u8, "abcde", z catch unreachable));
830839}
......@@ -835,9 +844,10 @@ test "peer cast *[0]T to []const T" {
835844 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
836845
837846 var buffer: [5]u8 = "abcde".*;
838 var buf: []const u8 = buffer[0..];
847 const buf: []const u8 = buffer[0..];
839848 var b = false;
840 var y = if (b) &[0]u8{} else buf;
849 _ = &b;
850 const y = if (b) &[0]u8{} else buf;
841851 try expect(mem.eql(u8, "abcde", y));
842852}
843853
......@@ -846,6 +856,7 @@ test "peer cast *[N]T to [*]T" {
846856
847857 var array = [4:99]i32{ 1, 2, 3, 4 };
848858 var dest: [*]i32 = undefined;
859 _ = &dest;
849860 try expect(@TypeOf(&array, dest) == [*]i32);
850861 try expect(@TypeOf(dest, &array) == [*]i32);
851862}
......@@ -879,8 +890,8 @@ test "peer cast [:x]T to []T" {
879890 const S = struct {
880891 fn doTheTest() !void {
881892 var array = [4:0]i32{ 1, 2, 3, 4 };
882 var slice: [:0]i32 = &array;
883 var dest: []i32 = slice;
893 const slice: [:0]i32 = &array;
894 const dest: []i32 = slice;
884895 try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
885896 }
886897 };
......@@ -895,7 +906,8 @@ test "peer cast [N:x]T to [N]T" {
895906 const S = struct {
896907 fn doTheTest() !void {
897908 var array = [4:0]i32{ 1, 2, 3, 4 };
898 var dest: [4]i32 = array;
909 _ = &array;
910 const dest: [4]i32 = array;
899911 try expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 }));
900912 }
901913 };
......@@ -910,7 +922,7 @@ test "peer cast *[N:x]T to *[N]T" {
910922 const S = struct {
911923 fn doTheTest() !void {
912924 var array = [4:0]i32{ 1, 2, 3, 4 };
913 var dest: *[4]i32 = &array;
925 const dest: *[4]i32 = &array;
914926 try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
915927 }
916928 };
......@@ -925,7 +937,7 @@ test "peer cast [*:x]T to [*]T" {
925937 const S = struct {
926938 fn doTheTest() !void {
927939 var array = [4:99]i32{ 1, 2, 3, 4 };
928 var dest: [*]i32 = &array;
940 const dest: [*]i32 = &array;
929941 try expect(dest[0] == 1);
930942 try expect(dest[1] == 2);
931943 try expect(dest[2] == 3);
......@@ -945,8 +957,8 @@ test "peer cast [:x]T to [*:x]T" {
945957 const S = struct {
946958 fn doTheTest() !void {
947959 var array = [4:0]i32{ 1, 2, 3, 4 };
948 var slice: [:0]i32 = &array;
949 var dest: [*:0]i32 = slice;
960 const slice: [:0]i32 = &array;
961 const dest: [*:0]i32 = slice;
950962 try expect(dest[0] == 1);
951963 try expect(dest[1] == 2);
952964 try expect(dest[2] == 3);
......@@ -998,6 +1010,7 @@ test "peer type resolution implicit cast to variable type" {
9981010
9991011test "variable initialization uses result locations properly with regards to the type" {
10001012 var b = true;
1013 _ = &b;
10011014 const x: i32 = if (b) 1 else 2;
10021015 try expect(x == 1);
10031016}
......@@ -1025,7 +1038,7 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" {
10251038
10261039 var array: [4:0]u8 = undefined;
10271040 array[4] = 0; // TODO remove this when #4372 is solved
1028 var slice: [:0]u8 = array[0..4 :0];
1041 const slice: [:0]u8 = array[0..4 :0];
10291042 try comptime expect(@TypeOf(slice, "hi") == [:0]const u8);
10301043 try comptime expect(@TypeOf("hi", slice) == [:0]const u8);
10311044}
......@@ -1042,6 +1055,7 @@ test "peer type resolve array pointer and unknown pointer" {
10421055 var array: [4]u8 = undefined;
10431056 var const_ptr: [*]const u8 = undefined;
10441057 var ptr: [*]u8 = undefined;
1058 _ = .{ &const_ptr, &ptr };
10451059
10461060 try comptime expect(@TypeOf(&array, ptr) == [*]u8);
10471061 try comptime expect(@TypeOf(ptr, &array) == [*]u8);
......@@ -1090,6 +1104,7 @@ test "implicit cast from [*]T to ?*anyopaque" {
10901104
10911105 var a = [_]u8{ 3, 2, 1 };
10921106 var runtime_zero: usize = 0;
1107 _ = &runtime_zero;
10931108 incrementVoidPtrArray(a[runtime_zero..].ptr, 3);
10941109 try expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 }));
10951110}
......@@ -1151,11 +1166,11 @@ test "implicit ptr to *anyopaque" {
11511166 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
11521167
11531168 var a: u32 = 1;
1154 var ptr: *align(@alignOf(u32)) anyopaque = &a;
1155 var b: *u32 = @as(*u32, @ptrCast(ptr));
1169 const ptr: *align(@alignOf(u32)) anyopaque = &a;
1170 const b: *u32 = @as(*u32, @ptrCast(ptr));
11561171 try expect(b.* == 1);
1157 var ptr2: ?*align(@alignOf(u32)) anyopaque = &a;
1158 var c: *u32 = @as(*u32, @ptrCast(ptr2.?));
1172 const ptr2: ?*align(@alignOf(u32)) anyopaque = &a;
1173 const c: *u32 = @as(*u32, @ptrCast(ptr2.?));
11591174 try expect(c.* == 1);
11601175}
11611176
......@@ -1264,6 +1279,7 @@ test "implicit cast *[0]T to E![]const u8" {
12641279 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
12651280
12661281 var x = @as(anyerror![]const u8, &[0]u8{});
1282 _ = &x;
12671283 try expect((x catch unreachable).len == 0);
12681284}
12691285
......@@ -1274,6 +1290,7 @@ test "cast from array reference to fn: comptime fn ptr" {
12741290}
12751291test "cast from array reference to fn: runtime fn ptr" {
12761292 var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array));
1293 _ = &f;
12771294 try expect(@intFromPtr(f) == @intFromPtr(&global_array));
12781295}
12791296
......@@ -1285,7 +1302,8 @@ test "*const [N]null u8 to ?[]const u8" {
12851302 const S = struct {
12861303 fn doTheTest() !void {
12871304 var a = "Hello";
1288 var b: ?[]const u8 = a;
1305 _ = &a;
1306 const b: ?[]const u8 = a;
12891307 try expect(mem.eql(u8, b.?, "Hello"));
12901308 }
12911309 };
......@@ -1318,12 +1336,13 @@ test "assignment to optional pointer result loc" {
13181336 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
13191337
13201338 var foo: struct { ptr: ?*anyopaque } = .{ .ptr = &global_struct };
1339 _ = &foo;
13211340 try expect(foo.ptr.? == @as(*anyopaque, @ptrCast(&global_struct)));
13221341}
13231342
13241343test "cast between *[N]void and []void" {
13251344 var a: [4]void = undefined;
1326 var b: []void = &a;
1345 const b: []void = &a;
13271346 try expect(b.len == 4);
13281347}
13291348
......@@ -1351,6 +1370,7 @@ test "cast f16 to wider types" {
13511370 const S = struct {
13521371 fn doTheTest() !void {
13531372 var x: f16 = 1234.0;
1373 _ = &x;
13541374 try expect(@as(f32, 1234.0) == x);
13551375 try expect(@as(f64, 1234.0) == x);
13561376 try expect(@as(f128, 1234.0) == x);
......@@ -1370,6 +1390,7 @@ test "cast f128 to narrower types" {
13701390 const S = struct {
13711391 fn doTheTest() !void {
13721392 var x: f128 = 1234.0;
1393 _ = &x;
13731394 try expect(@as(f16, 1234.0) == @as(f16, @floatCast(x)));
13741395 try expect(@as(f32, 1234.0) == @as(f32, @floatCast(x)));
13751396 try expect(@as(f64, 1234.0) == @as(f64, @floatCast(x)));
......@@ -1404,6 +1425,7 @@ test "cast i8 fn call peers to i32 result" {
14041425 const S = struct {
14051426 fn doTheTest() !void {
14061427 var cond = true;
1428 _ = &cond;
14071429 const value: i32 = if (cond) smallBoi() else bigBoi();
14081430 try expect(value == 123);
14091431 }
......@@ -1424,7 +1446,8 @@ test "cast compatible optional types" {
14241446 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
14251447
14261448 var a: ?[:0]const u8 = null;
1427 var b: ?[]const u8 = a;
1449 _ = &a;
1450 const b: ?[]const u8 = a;
14281451 try expect(b == null);
14291452}
14301453
......@@ -1434,6 +1457,7 @@ test "coerce undefined single-item pointer of array to error union of slice" {
14341457
14351458 const a = @as([*]u8, undefined)[0..0];
14361459 var b: error{a}![]const u8 = a;
1460 _ = &b;
14371461 const s = try b;
14381462 try expect(s.len == 0);
14391463}
......@@ -1442,6 +1466,7 @@ test "pointer to empty struct literal to mutable slice" {
14421466 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
14431467
14441468 var x: []i32 = &.{};
1469 _ = &x;
14451470 try expect(x.len == 0);
14461471}
14471472
......@@ -1466,7 +1491,7 @@ test "coerce between pointers of compatible differently-named floats" {
14661491 else => @compileError("unreachable"),
14671492 };
14681493 var f1: F = 12.34;
1469 var f2: *c_longdouble = &f1;
1494 const f2: *c_longdouble = &f1;
14701495 f2.* += 1;
14711496 try expect(f1 == @as(F, 12.34) + 1);
14721497}
......@@ -1507,8 +1532,9 @@ test "implicit cast from [:0]T to [*c]T" {
15071532 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
15081533
15091534 var a: [:0]const u8 = "foo";
1510 var b: [*c]const u8 = a;
1511 var c = std.mem.span(b);
1535 _ = &a;
1536 const b: [*c]const u8 = a;
1537 const c = std.mem.span(b);
15121538 try expect(c.len == a.len);
15131539 try expect(c.ptr == a.ptr);
15141540}
......@@ -1544,6 +1570,7 @@ test "single item pointer to pointer to array to slice" {
15441570
15451571test "peer type resolution forms error union" {
15461572 var foo: i32 = 123;
1573 _ = &foo;
15471574 const result = if (foo < 0) switch (-foo) {
15481575 0 => unreachable,
15491576 42 => error.AccessDenied,
......@@ -1561,7 +1588,7 @@ test "@constCast without a result location" {
15611588
15621589test "@volatileCast without a result location" {
15631590 var x: i32 = 1234;
1564 var y: *volatile i32 = &x;
1591 const y: *volatile i32 = &x;
15651592 const z = @volatileCast(y);
15661593 try expect(@TypeOf(z) == *i32);
15671594 try expect(z.* == 1234);
......@@ -1585,10 +1612,12 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice"
15851612 fn doTheTest(comptime T: type, comptime s: T) !void {
15861613 var a: [:s]const T = @as(*const [2:s]T, @ptrFromInt(0x1000));
15871614 var b: []T = @as(*[3]T, @ptrFromInt(0x2000));
1615 _ = .{ &a, &b };
15881616 comptime assert(@TypeOf(a, b) == []const T);
15891617 comptime assert(@TypeOf(b, a) == []const T);
15901618
15911619 var t = true;
1620 _ = &t;
15921621 const r1 = if (t) a else b;
15931622 const r2 = if (t) b else a;
15941623
......@@ -1611,10 +1640,12 @@ test "peer type resolution: float and comptime-known fixed-width integer" {
16111640
16121641 const i: u8 = 100;
16131642 var f: f32 = 1.234;
1643 _ = &f;
16141644 comptime assert(@TypeOf(i, f) == f32);
16151645 comptime assert(@TypeOf(f, i) == f32);
16161646
16171647 var t = true;
1648 _ = &t;
16181649 const r1 = if (t) i else f;
16191650 const r2 = if (t) f else i;
16201651
......@@ -1631,10 +1662,12 @@ test "peer type resolution: same array type with sentinel" {
16311662
16321663 var a: [2:0]u32 = .{ 0, 1 };
16331664 var b: [2:0]u32 = .{ 2, 3 };
1665 _ = .{ &a, &b };
16341666 comptime assert(@TypeOf(a, b) == [2:0]u32);
16351667 comptime assert(@TypeOf(b, a) == [2:0]u32);
16361668
16371669 var t = true;
1670 _ = &t;
16381671 const r1 = if (t) a else b;
16391672 const r2 = if (t) b else a;
16401673
......@@ -1651,10 +1684,12 @@ test "peer type resolution: array with sentinel and array without sentinel" {
16511684
16521685 var a: [2:0]u32 = .{ 0, 1 };
16531686 var b: [2]u32 = .{ 2, 3 };
1687 _ = .{ &a, &b };
16541688 comptime assert(@TypeOf(a, b) == [2]u32);
16551689 comptime assert(@TypeOf(b, a) == [2]u32);
16561690
16571691 var t = true;
1692 _ = &t;
16581693 const r1 = if (t) a else b;
16591694 const r2 = if (t) b else a;
16601695
......@@ -1671,10 +1706,12 @@ test "peer type resolution: array and vector with same child type" {
16711706
16721707 var arr: [2]u32 = .{ 0, 1 };
16731708 var vec: @Vector(2, u32) = .{ 2, 3 };
1709 _ = .{ &arr, &vec };
16741710 comptime assert(@TypeOf(arr, vec) == @Vector(2, u32));
16751711 comptime assert(@TypeOf(vec, arr) == @Vector(2, u32));
16761712
16771713 var t = true;
1714 _ = &t;
16781715 const r1 = if (t) arr else vec;
16791716 const r2 = if (t) vec else arr;
16801717
......@@ -1694,10 +1731,12 @@ test "peer type resolution: array with smaller child type and vector with larger
16941731
16951732 var arr: [2]u8 = .{ 0, 1 };
16961733 var vec: @Vector(2, u64) = .{ 2, 3 };
1734 _ = .{ &arr, &vec };
16971735 comptime assert(@TypeOf(arr, vec) == @Vector(2, u64));
16981736 comptime assert(@TypeOf(vec, arr) == @Vector(2, u64));
16991737
17001738 var t = true;
1739 _ = &t;
17011740 const r1 = if (t) arr else vec;
17021741 const r2 = if (t) vec else arr;
17031742
......@@ -1715,10 +1754,12 @@ test "peer type resolution: error union and optional of same type" {
17151754 const E = error{Foo};
17161755 var a: E!*u8 = error.Foo;
17171756 var b: ?*u8 = null;
1757 _ = .{ &a, &b };
17181758 comptime assert(@TypeOf(a, b) == E!?*u8);
17191759 comptime assert(@TypeOf(b, a) == E!?*u8);
17201760
17211761 var t = true;
1762 _ = &t;
17221763 const r1 = if (t) a else b;
17231764 const r2 = if (t) b else a;
17241765
......@@ -1734,11 +1775,13 @@ test "peer type resolution: C pointer and @TypeOf(null)" {
17341775 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
17351776
17361777 var a: [*c]c_int = 0x1000;
1778 _ = &a;
17371779 const b = null;
17381780 comptime assert(@TypeOf(a, b) == [*c]c_int);
17391781 comptime assert(@TypeOf(b, a) == [*c]c_int);
17401782
17411783 var t = true;
1784 _ = &t;
17421785 const r1 = if (t) a else b;
17431786 const r2 = if (t) b else a;
17441787
......@@ -1755,8 +1798,9 @@ test "peer type resolution: three-way resolution combines error set and optional
17551798
17561799 const E = error{Foo};
17571800 var a: E = error.Foo;
1758 var b: *const [5:0]u8 = @as(*const [5:0]u8, @ptrFromInt(0x1000));
1801 var b: *const [5:0]u8 = @ptrFromInt(0x1000);
17591802 var c: ?[*:0]u8 = null;
1803 _ = .{ &a, &b, &c };
17601804 comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8);
17611805 comptime assert(@TypeOf(a, c, b) == E!?[*:0]const u8);
17621806 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
17651809 comptime assert(@TypeOf(c, b, a) == E!?[*:0]const u8);
17661810
17671811 var x: u8 = 0;
1812 _ = &x;
17681813 const r1 = switch (x) {
17691814 0 => a,
17701815 1 => b,
......@@ -1797,10 +1842,12 @@ test "peer type resolution: vector and optional vector" {
17971842
17981843 var a: ?@Vector(3, u32) = .{ 0, 1, 2 };
17991844 var b: @Vector(3, u32) = .{ 3, 4, 5 };
1845 _ = .{ &a, &b };
18001846 comptime assert(@TypeOf(a, b) == ?@Vector(3, u32));
18011847 comptime assert(@TypeOf(b, a) == ?@Vector(3, u32));
18021848
18031849 var t = true;
1850 _ = &t;
18041851 const r1 = if (t) a else b;
18051852 const r2 = if (t) b else a;
18061853
......@@ -1816,11 +1863,13 @@ test "peer type resolution: optional fixed-width int and comptime_int" {
18161863 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
18171864
18181865 var a: ?i32 = 42;
1866 _ = &a;
18191867 const b: comptime_int = 50;
18201868 comptime assert(@TypeOf(a, b) == ?i32);
18211869 comptime assert(@TypeOf(b, a) == ?i32);
18221870
18231871 var t = true;
1872 _ = &t;
18241873 const r1 = if (t) a else b;
18251874 const r2 = if (t) b else a;
18261875
......@@ -1836,12 +1885,14 @@ test "peer type resolution: array and tuple" {
18361885 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
18371886
18381887 var arr: [3]i32 = .{ 1, 2, 3 };
1888 _ = &arr;
18391889 const tup = .{ 4, 5, 6 };
18401890
18411891 comptime assert(@TypeOf(arr, tup) == [3]i32);
18421892 comptime assert(@TypeOf(tup, arr) == [3]i32);
18431893
18441894 var t = true;
1895 _ = &t;
18451896 const r1 = if (t) arr else tup;
18461897 const r2 = if (t) tup else arr;
18471898
......@@ -1858,12 +1909,14 @@ test "peer type resolution: vector and tuple" {
18581909 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
18591910
18601911 var vec: @Vector(3, i32) = .{ 1, 2, 3 };
1912 _ = &vec;
18611913 const tup = .{ 4, 5, 6 };
18621914
18631915 comptime assert(@TypeOf(vec, tup) == @Vector(3, i32));
18641916 comptime assert(@TypeOf(tup, vec) == @Vector(3, i32));
18651917
18661918 var t = true;
1919 _ = &t;
18671920 const r1 = if (t) vec else tup;
18681921 const r2 = if (t) tup else vec;
18691922
......@@ -1881,6 +1934,7 @@ test "peer type resolution: vector and array and tuple" {
18811934
18821935 var vec: @Vector(2, i8) = .{ 10, 20 };
18831936 var arr: [2]i8 = .{ 30, 40 };
1937 _ = .{ &vec, &arr };
18841938 const tup = .{ 50, 60 };
18851939
18861940 comptime assert(@TypeOf(vec, arr, tup) == @Vector(2, i8));
......@@ -1891,6 +1945,7 @@ test "peer type resolution: vector and array and tuple" {
18911945 comptime assert(@TypeOf(tup, arr, vec) == @Vector(2, i8));
18921946
18931947 var x: u8 = 0;
1948 _ = &x;
18941949 const r1 = switch (x) {
18951950 0 => vec,
18961951 1 => arr,
......@@ -1921,11 +1976,13 @@ test "peer type resolution: empty tuple pointer and slice" {
19211976
19221977 var a: [:0]const u8 = "Hello";
19231978 var b = &.{};
1979 _ = .{ &a, &b };
19241980
19251981 comptime assert(@TypeOf(a, b) == []const u8);
19261982 comptime assert(@TypeOf(b, a) == []const u8);
19271983
19281984 var t = true;
1985 _ = &t;
19291986 const r1 = if (t) a else b;
19301987 const r2 = if (t) b else a;
19311988
......@@ -1940,11 +1997,13 @@ test "peer type resolution: tuple pointer and slice" {
19401997
19411998 var a: [:0]const u8 = "Hello";
19421999 var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') };
2000 _ = .{ &a, &b };
19432001
19442002 comptime assert(@TypeOf(a, b) == []const u8);
19452003 comptime assert(@TypeOf(b, a) == []const u8);
19462004
19472005 var t = true;
2006 _ = &t;
19482007 const r1 = if (t) a else b;
19492008 const r2 = if (t) b else a;
19502009
......@@ -1959,11 +2018,13 @@ test "peer type resolution: tuple pointer and optional slice" {
19592018
19602019 var a: ?[:0]const u8 = null;
19612020 var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') };
2021 _ = .{ &a, &b };
19622022
19632023 comptime assert(@TypeOf(a, b) == ?[]const u8);
19642024 comptime assert(@TypeOf(b, a) == ?[]const u8);
19652025
19662026 var t = true;
2027 _ = &t;
19672028 const r1 = if (t) a else b;
19682029 const r2 = if (t) b else a;
19692030
......@@ -1986,6 +2047,7 @@ test "peer type resolution: many compatible pointers" {
19862047 @as([*]u8, &buf),
19872048 @as(*const [5]u8, "foo-4"),
19882049 };
2050 _ = &vals;
19892051
19902052 // Check every possible permutation of types in @TypeOf
19912053 @setEvalBranchQuota(5000);
......@@ -2015,6 +2077,7 @@ test "peer type resolution: many compatible pointers" {
20152077 comptime assert(perms == 5 * 4 * 3 * 2 * 1);
20162078
20172079 var x: u8 = 0;
2080 _ = &x;
20182081 inline for (0..5) |i| {
20192082 const r = switch (x) {
20202083 0 => vals[i],
......@@ -2057,6 +2120,7 @@ test "peer type resolution: tuples with comptime fields" {
20572120 }
20582121
20592122 var t = true;
2123 _ = &t;
20602124 const r1 = if (t) a else b;
20612125 const r2 = if (t) b else a;
20622126
......@@ -2074,13 +2138,15 @@ test "peer type resolution: C pointer and many pointer" {
20742138
20752139 var buf = "hello".*;
20762140
2077 var a: [*c]u8 = &buf;
2141 const a: [*c]u8 = &buf;
20782142 var b: [*:0]const u8 = "world";
2143 _ = &b;
20792144
20802145 comptime assert(@TypeOf(a, b) == [*c]const u8);
20812146 comptime assert(@TypeOf(b, a) == [*c]const u8);
20822147
20832148 var t = true;
2149 _ = &t;
20842150 const r1 = if (t) a else b;
20852151 const r2 = if (t) b else a;
20862152
......@@ -2097,9 +2163,9 @@ test "peer type resolution: pointer attributes are combined correctly" {
20972163 var buf_b align(4) = "bar".*;
20982164 var buf_c align(4) = "baz".*;
20992165
2100 var a: [*:0]align(4) const u8 = &buf_a;
2101 var b: *align(2) volatile [3:0]u8 = &buf_b;
2102 var c: [*:0]align(4) u8 = &buf_c;
2166 const a: [*:0]align(4) const u8 = &buf_a;
2167 const b: *align(2) volatile [3:0]u8 = &buf_b;
2168 const c: [*:0]align(4) u8 = &buf_c;
21032169
21042170 comptime assert(@TypeOf(a, b, c) == [*:0]align(2) const volatile u8);
21052171 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" {
21092175 comptime assert(@TypeOf(c, b, a) == [*:0]align(2) const volatile u8);
21102176
21112177 var x: u8 = 0;
2178 _ = &x;
21122179 const r1 = switch (x) {
21132180 0 => a,
21142181 1 => b,
......@@ -2254,6 +2321,7 @@ test "@floatCast on vector" {
22542321 const S = struct {
22552322 fn doTheTest() !void {
22562323 var a: @Vector(3, f64) = .{ 1.5, 2.5, 3.5 };
2324 _ = &a;
22572325 const b: @Vector(3, f32) = @floatCast(a);
22582326 try expectEqual(@Vector(3, f32){ 1.5, 2.5, 3.5 }, b);
22592327 }
......@@ -2274,6 +2342,7 @@ test "@ptrFromInt on vector" {
22742342 const S = struct {
22752343 fn doTheTest() !void {
22762344 var a: @Vector(3, usize) = .{ 0x1000, 0x2000, 0x3000 };
2345 _ = &a;
22772346 const b: @Vector(3, *anyopaque) = @ptrFromInt(a);
22782347 try expectEqual(@Vector(3, *anyopaque){
22792348 @ptrFromInt(0x1000),
......@@ -2302,6 +2371,7 @@ test "@intFromPtr on vector" {
23022371 @ptrFromInt(0x2000),
23032372 @ptrFromInt(0x3000),
23042373 };
2374 _ = &a;
23052375 const b: @Vector(3, usize) = @intFromPtr(a);
23062376 try expectEqual(@Vector(3, usize){ 0x1000, 0x2000, 0x3000 }, b);
23072377 }
......@@ -2322,6 +2392,7 @@ test "@floatFromInt on vector" {
23222392 const S = struct {
23232393 fn doTheTest() !void {
23242394 var a: @Vector(3, u32) = .{ 10, 20, 30 };
2395 _ = &a;
23252396 const b: @Vector(3, f32) = @floatFromInt(a);
23262397 try expectEqual(@Vector(3, f32){ 10.0, 20.0, 30.0 }, b);
23272398 }
......@@ -2342,6 +2413,7 @@ test "@intFromFloat on vector" {
23422413 const S = struct {
23432414 fn doTheTest() !void {
23442415 var a: @Vector(3, f32) = .{ 10.3, 20.5, 30.7 };
2416 _ = &a;
23452417 const b: @Vector(3, u32) = @intFromFloat(a);
23462418 try expectEqual(@Vector(3, u32){ 10, 20, 30 }, b);
23472419 }
......@@ -2362,6 +2434,7 @@ test "@intFromBool on vector" {
23622434 const S = struct {
23632435 fn doTheTest() !void {
23642436 var a: @Vector(3, bool) = .{ false, true, false };
2437 _ = &a;
23652438 const b: @Vector(3, u1) = @intFromBool(a);
23662439 try expectEqual(@Vector(3, u1){ 0, 1, 0 }, b);
23672440 }
......@@ -2385,7 +2458,8 @@ test "15-bit int to float" {
23852458 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
23862459
23872460 var a: u15 = 42;
2388 var b: f32 = @floatFromInt(a);
2461 _ = &a;
2462 const b: f32 = @floatFromInt(a);
23892463 try expect(b == 42.0);
23902464}
23912465
......@@ -2417,6 +2491,7 @@ test "result information is preserved through many nested structures" {
24172491 const T = *const ?E!struct { x: ?*const E!?u8 };
24182492
24192493 var val: T = &.{ .x = &@truncate(0x1234) };
2494 _ = &val;
24202495
24212496 const struct_val = val.*.? catch unreachable;
24222497 const int_val = (struct_val.x.?.* catch unreachable).?;
......@@ -2439,6 +2514,7 @@ test "@intCast vector of signed integer" {
24392514 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
24402515
24412516 var x: @Vector(4, i32) = .{ 1, 2, 3, 4 };
2517 _ = &x;
24422518 const y: @Vector(4, i8) = @intCast(x);
24432519
24442520 try expect(y[0] == 1);
test/behavior/cast_int.zig+17-2
......@@ -12,7 +12,8 @@ test "@intCast i32 to u7" {
1212
1313 var x: u128 = maxInt(u128);
1414 var y: i32 = 120;
15 var z = x >> @as(u7, @intCast(y));
15 _ = .{ &x, &y };
16 const z = x >> @as(u7, @intCast(y));
1617 try expect(z == 0xff);
1718}
1819
......@@ -23,20 +24,24 @@ test "coerce i8 to i32 and @intCast back" {
2324
2425 var x: i8 = -5;
2526 var y: i32 = -5;
27 _ = .{ &x, &y };
2628 try expect(y == x);
2729
2830 var x2: i32 = -5;
2931 var y2: i8 = -5;
32 _ = .{ &x2, &y2 };
3033 try expect(y2 == @as(i8, @intCast(x2)));
3134}
3235
3336test "coerce non byte-sized integers accross 32bits boundary" {
3437 {
3538 var v: u21 = 6417;
39 _ = &v;
3640 const a: u32 = v;
3741 const b: u64 = v;
3842 const c: u64 = a;
3943 var w: u64 = 0x1234567812345678;
44 _ = &w;
4045 const d: u21 = @truncate(w);
4146 const e: u60 = d;
4247 try expectEqual(@as(u32, 6417), a);
......@@ -48,10 +53,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {
4853
4954 {
5055 var v: u10 = 234;
56 _ = &v;
5157 const a: u32 = v;
5258 const b: u64 = v;
5359 const c: u64 = a;
5460 var w: u64 = 0x1234567812345678;
61 _ = &w;
5562 const d: u10 = @truncate(w);
5663 const e: u60 = d;
5764 try expectEqual(@as(u32, 234), a);
......@@ -62,10 +69,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {
6269 }
6370 {
6471 var v: u7 = 11;
72 _ = &v;
6573 const a: u32 = v;
6674 const b: u64 = v;
6775 const c: u64 = a;
6876 var w: u64 = 0x1234567812345678;
77 _ = &w;
6978 const d: u7 = @truncate(w);
7079 const e: u60 = d;
7180 try expectEqual(@as(u32, 11), a);
......@@ -77,10 +86,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {
7786
7887 {
7988 var v: i21 = -6417;
89 _ = &v;
8090 const a: i32 = v;
8191 const b: i64 = v;
8292 const c: i64 = a;
8393 var w: i64 = -12345;
94 _ = &w;
8495 const d: i21 = @intCast(w);
8596 const e: i60 = d;
8697 try expectEqual(@as(i32, -6417), a);
......@@ -92,10 +103,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {
92103
93104 {
94105 var v: i10 = -234;
106 _ = &v;
95107 const a: i32 = v;
96108 const b: i64 = v;
97109 const c: i64 = a;
98110 var w: i64 = -456;
111 _ = &w;
99112 const d: i10 = @intCast(w);
100113 const e: i60 = d;
101114 try expectEqual(@as(i32, -234), a);
......@@ -106,10 +119,12 @@ test "coerce non byte-sized integers accross 32bits boundary" {
106119 }
107120 {
108121 var v: i7 = -11;
122 _ = &v;
109123 const a: i32 = v;
110124 const b: i64 = v;
111125 const c: i64 = a;
112126 var w: i64 = -42;
127 _ = &w;
113128 const d: i7 = @intCast(w);
114129 const e: i60 = d;
115130 try expectEqual(@as(i32, -11), a);
......@@ -152,7 +167,7 @@ test "load non byte-sized optional value" {
152167 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
153168
154169 // note: this bug is triggered by the == operator, expectEqual will hide it
155 var opt: ?Piece = try Piece.charToPiece('p');
170 const opt: ?Piece = try Piece.charToPiece('p');
156171 try expect(opt.?.type == .PAWN);
157172 try expect(opt.?.color == .BLACK);
158173
test/behavior/comptime_memory.zig+1-1
......@@ -280,7 +280,7 @@ test "dance on linker values" {
280280 if (ptr_size > @sizeOf(Bits))
281281 try doTypePunBitsTest(&weird_ptr[1]);
282282
283 var arr_bytes = @as(*[2][ptr_size]u8, @ptrCast(&arr));
283 const arr_bytes: *[2][ptr_size]u8 = @ptrCast(&arr);
284284
285285 var rebuilt_bytes: [ptr_size]u8 = undefined;
286286 var i: usize = 0;
test/behavior/destructure.zig+4
......@@ -7,6 +7,7 @@ test "simple destructure" {
77 fn doTheTest() !void {
88 var x: u32 = undefined;
99 x, const y, var z: u64 = .{ 1, @as(u16, 2), 3 };
10 _ = &z;
1011
1112 comptime assert(@TypeOf(y) == u16);
1213
......@@ -25,6 +26,7 @@ test "destructure with comptime syntax" {
2526 fn doTheTest() void {
2627 comptime var x: f32 = undefined;
2728 comptime x, const y, var z = .{ 0.5, 123, 456 }; // z is a comptime var
29 _ = &z;
2830
2931 comptime assert(@TypeOf(y) == comptime_int);
3032 comptime assert(@TypeOf(z) == comptime_int);
......@@ -112,6 +114,7 @@ test "destructure of comptime-known tuple is comptime-known" {
112114test "destructure of comptime-known tuple where some destinations are runtime-known is comptime-known" {
113115 var z: u32 = undefined;
114116 var x: u8, const y, z = .{ 1, 2, 3 };
117 _ = &x;
115118
116119 comptime assert(@TypeOf(y) == comptime_int);
117120 comptime assert(y == 2);
......@@ -122,6 +125,7 @@ test "destructure of comptime-known tuple where some destinations are runtime-kn
122125
123126test "destructure of tuple with comptime fields results in some comptime-known values" {
124127 var runtime: u32 = 42;
128 _ = &runtime;
125129 const a, const b, const c, const d = .{ 123, runtime, 456, runtime };
126130
127131 // a, c are comptime-known
test/behavior/empty_union.zig+4
......@@ -5,12 +5,14 @@ const expect = std.testing.expect;
55test "switch on empty enum" {
66 const E = enum {};
77 var e: E = undefined;
8 _ = &e;
89 switch (e) {}
910}
1011
1112test "switch on empty enum with a specified tag type" {
1213 const E = enum(u8) {};
1314 var e: E = undefined;
15 _ = &e;
1416 switch (e) {}
1517}
1618
......@@ -19,6 +21,7 @@ test "switch on empty auto numbered tagged union" {
1921
2022 const U = union(enum(u8)) {};
2123 var u: U = undefined;
24 _ = &u;
2225 switch (u) {}
2326}
2427
......@@ -28,6 +31,7 @@ test "switch on empty tagged union" {
2831 const E = enum {};
2932 const U = union(E) {};
3033 var u: U = undefined;
34 _ = &u;
3135 switch (u) {}
3236}
3337
test/behavior/enum.zig+11-4
......@@ -579,6 +579,7 @@ test "enum literal cast to enum" {
579579
580580 var color1: Color = .Auto;
581581 var color2 = Color.Auto;
582 _ = .{ &color1, &color2 };
582583 try expect(color1 == color2);
583584}
584585
......@@ -663,7 +664,8 @@ test "empty non-exhaustive enum" {
663664 const E = enum(u8) { _ };
664665
665666 fn doTheTest(y: u8) !void {
666 var e = @as(E, @enumFromInt(y));
667 var e: E = @enumFromInt(y);
668 _ = &e;
667669 try expect(switch (e) {
668670 _ => true,
669671 });
......@@ -858,6 +860,7 @@ test "comparison operator on enum with one member is comptime-known" {
858860const State = enum { Start };
859861test "switch on enum with one member is comptime-known" {
860862 var state = State.Start;
863 _ = &state;
861864 switch (state) {
862865 State.Start => return,
863866 }
......@@ -917,7 +920,8 @@ test "enum literal casting to tagged union" {
917920
918921 var t = true;
919922 var x: Arch = .x86_64;
920 var y = if (t) x else .x86_64;
923 _ = .{ &t, &x };
924 const y = if (t) x else .x86_64;
921925 switch (y) {
922926 .x86_64 => {},
923927 else => @panic("fail"),
......@@ -1031,6 +1035,7 @@ test "tag name with assigned enum values" {
10311035 B = 0,
10321036 };
10331037 var b = LocalFoo.B;
1038 _ = &b;
10341039 try expect(mem.eql(u8, @tagName(b), "B"));
10351040}
10361041
......@@ -1055,6 +1060,7 @@ test "tag name with signed enum values" {
10551060 delta = 65,
10561061 };
10571062 var b = LocalFoo.bravo;
1063 _ = &b;
10581064 try expect(mem.eql(u8, @tagName(b), "bravo"));
10591065}
10601066
......@@ -1135,13 +1141,13 @@ test "tag name functions are unique" {
11351141 const E = enum { a, b };
11361142 var b = E.a;
11371143 var a = @tagName(b);
1138 _ = a;
1144 _ = .{ &a, &b };
11391145 }
11401146 {
11411147 const E = enum { a, b, c, d, e, f };
11421148 var b = E.a;
11431149 var a = @tagName(b);
1144 _ = a;
1150 _ = .{ &a, &b };
11451151 }
11461152}
11471153
......@@ -1189,6 +1195,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" {
11891195test "runtime int to enum with one possible value" {
11901196 const E = enum { one };
11911197 var runtime: usize = 0;
1198 _ = &runtime;
11921199 if (@as(E, @enumFromInt(runtime)) != .one) {
11931200 @compileError("test failed");
11941201 }
test/behavior/error.zig+14-8
......@@ -102,8 +102,7 @@ test "widen cast integer payload of error union function call" {
102102
103103 const S = struct {
104104 fn errorable() !u64 {
105 var x = @as(u64, try number());
106 return x;
105 return @as(u64, try number());
107106 }
108107
109108 fn number() anyerror!u32 {
......@@ -119,7 +118,7 @@ test "debug info for optional error set" {
119118
120119 const SomeError = error{ Hello, Hello2 };
121120 var a_local_variable: ?SomeError = null;
122 _ = a_local_variable;
121 _ = &a_local_variable;
123122}
124123
125124test "implicit cast to optional to error union to return result loc" {
......@@ -160,6 +159,7 @@ fn entry() void {
160159
161160fn entryPtr() void {
162161 var ptr = &bar2;
162 _ = &ptr;
163163 fooPtr(ptr);
164164}
165165
......@@ -226,9 +226,9 @@ const Set1 = error{ A, B };
226226const Set2 = error{ A, C };
227227
228228fn testExplicitErrorSetCast(set1: Set1) !void {
229 var x = @as(Set2, @errorCast(set1));
229 const x: Set2 = @errorCast(set1);
230230 try expect(@TypeOf(x) == Set2);
231 var y = @as(Set1, @errorCast(x));
231 const y: Set1 = @errorCast(x);
232232 try expect(@TypeOf(y) == Set1);
233233 try expect(y == error.A);
234234}
......@@ -408,17 +408,17 @@ test "nested error union function call in optional unwrap" {
408408 };
409409
410410 fn errorable() !i32 {
411 var x: Foo = (try getFoo()) orelse return error.Other;
411 const x: Foo = (try getFoo()) orelse return error.Other;
412412 return x.a;
413413 }
414414
415415 fn errorable2() !i32 {
416 var x: Foo = (try getFoo2()) orelse return error.Other;
416 const x: Foo = (try getFoo2()) orelse return error.Other;
417417 return x.a;
418418 }
419419
420420 fn errorable3() !i32 {
421 var x: Foo = (try getFoo3()) orelse return error.Other;
421 const x: Foo = (try getFoo3()) orelse return error.Other;
422422 return x.a;
423423 }
424424
......@@ -673,6 +673,7 @@ test "peer type resolution of two different error unions" {
673673 const a: error{B}!void = {};
674674 const b: error{A}!void = {};
675675 var cond = true;
676 _ = &cond;
676677 const err = if (cond) a else b;
677678 try err;
678679}
......@@ -681,6 +682,7 @@ test "coerce error set to the current inferred error set" {
681682 const S = struct {
682683 fn foo() !void {
683684 var a = false;
685 _ = &a;
684686 if (a) {
685687 const b: error{A}!void = error.A;
686688 return b;
......@@ -831,6 +833,7 @@ test "alignment of wrapping an error union payload" {
831833
832834 fn foo() anyerror!I {
833835 var i: I = .{ .x = 1234 };
836 _ = &i;
834837 return i;
835838 }
836839 };
......@@ -842,6 +845,7 @@ test "compare error union and error set" {
842845
843846 var a: anyerror = error.Foo;
844847 var b: anyerror!u32 = error.Bar;
848 _ = &a;
845849
846850 try expect(a != b);
847851 try expect(b != a);
......@@ -863,6 +867,7 @@ fn non_errorable() void {
863867 // This test is needed because stage 2's fix for #1923 means that catch blocks interact
864868 // with the error return trace index.
865869 var x: error{Foo}!void = {};
870 _ = &x;
866871 return x catch {};
867872}
868873
......@@ -902,6 +907,7 @@ test "optional error union return type" {
902907 const S = struct {
903908 fn foo() ?anyerror!u32 {
904909 var x: u32 = 1234;
910 _ = &x;
905911 return @as(anyerror!u32, x);
906912 }
907913 };
test/behavior/eval.zig+39-20
......@@ -37,6 +37,7 @@ fn gimme1or2(comptime a: bool) i32 {
3737 const x: i32 = 1;
3838 const y: i32 = 2;
3939 comptime var z: i32 = if (a) x else y;
40 _ = &z;
4041 return z;
4142}
4243test "inline variable gets result of const if" {
......@@ -74,6 +75,7 @@ test "constant expressions" {
7475 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
7576
7677 var array: [array_size]u8 = undefined;
78 _ = &array;
7779 try expect(@sizeOf(@TypeOf(array)) == 20);
7880}
7981const array_size: u8 = 20;
......@@ -129,7 +131,7 @@ test "pointer to type" {
129131 comptime {
130132 var T: type = i32;
131133 try expect(T == i32);
132 var ptr = &T;
134 const ptr = &T;
133135 try expect(@TypeOf(ptr) == *type);
134136 ptr.* = f32;
135137 try expect(T == f32);
......@@ -372,6 +374,7 @@ fn doNothingWithType(comptime T: type) void {
372374test "zero extend from u0 to u1" {
373375 var zero_u0: u0 = 0;
374376 var zero_u1: u1 = zero_u0;
377 _ = .{ &zero_u0, &zero_u1 };
375378 try expect(zero_u1 == 0);
376379}
377380
......@@ -408,6 +411,7 @@ test "inline for with same type but different values" {
408411 var res: usize = 0;
409412 inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| {
410413 var a: T = undefined;
414 _ = &a;
411415 res += a.len;
412416 }
413417 try expect(res == 5);
......@@ -460,9 +464,9 @@ test "comptime shl" {
460464 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
461465 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
462466
463 var a: u128 = 3;
464 var b: u7 = 63;
465 var c: u128 = 3 << 63;
467 const a: u128 = 3;
468 const b: u7 = 63;
469 const c: u128 = 3 << 63;
466470 try expect((a << b) == c);
467471}
468472
......@@ -489,6 +493,7 @@ test "comptime shlWithOverflow" {
489493
490494 const ct_shifted = @shlWithOverflow(~@as(u64, 0), 16)[0];
491495 var a = ~@as(u64, 0);
496 _ = &a;
492497 const rt_shifted = @shlWithOverflow(a, 16)[0];
493498
494499 try expect(ct_shifted == rt_shifted);
......@@ -521,7 +526,8 @@ test "runtime 128 bit integer division" {
521526
522527 var a: u128 = 152313999999999991610955792383;
523528 var b: u128 = 10000000000000000000;
524 var c = a / b;
529 _ = .{ &a, &b };
530 const c = a / b;
525531 try expect(c == 15231399999);
526532}
527533
......@@ -555,6 +561,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio
555561 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
556562
557563 var runtime = [1]i32{3};
564 _ = &runtime;
558565 comptime var i: usize = 0;
559566 inline while (i < 2) : (i += 1) {
560567 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" {
692699 };
693700
694701 const s = S{ .a = 2 };
695 var b = s.b();
702 const b = s.b();
696703 try expect(b == 2);
697704}
698705
......@@ -759,7 +766,8 @@ test "array concatenation peer resolves element types - value" {
759766
760767 var a = [2]u3{ 1, 7 };
761768 var b = [3]u8{ 200, 225, 255 };
762 var c = a ++ b;
769 _ = .{ &a, &b };
770 const c = a ++ b;
763771 comptime assert(@TypeOf(c) == [5]u8);
764772 try expect(c[0] == 1);
765773 try expect(c[1] == 7);
......@@ -775,7 +783,7 @@ test "array concatenation peer resolves element types - pointer" {
775783
776784 var a = [2]u3{ 1, 7 };
777785 var b = [3]u8{ 200, 225, 255 };
778 var c = &a ++ &b;
786 const c = &a ++ &b;
779787 comptime assert(@TypeOf(c) == *[5]u8);
780788 try expect(c[0] == 1);
781789 try expect(c[1] == 7);
......@@ -791,14 +799,15 @@ test "array concatenation sets the sentinel - value" {
791799
792800 var a = [2]u3{ 1, 7 };
793801 var b = [3:69]u8{ 200, 225, 255 };
794 var c = a ++ b;
802 _ = .{ &a, &b };
803 const c = a ++ b;
795804 comptime assert(@TypeOf(c) == [5:69]u8);
796805 try expect(c[0] == 1);
797806 try expect(c[1] == 7);
798807 try expect(c[2] == 200);
799808 try expect(c[3] == 225);
800809 try expect(c[4] == 255);
801 var ptr: [*]const u8 = &c;
810 const ptr: [*]const u8 = &c;
802811 try expect(ptr[5] == 69);
803812}
804813
......@@ -808,14 +817,14 @@ test "array concatenation sets the sentinel - pointer" {
808817
809818 var a = [2]u3{ 1, 7 };
810819 var b = [3:69]u8{ 200, 225, 255 };
811 var c = &a ++ &b;
820 const c = &a ++ &b;
812821 comptime assert(@TypeOf(c) == *[5:69]u8);
813822 try expect(c[0] == 1);
814823 try expect(c[1] == 7);
815824 try expect(c[2] == 200);
816825 try expect(c[3] == 225);
817826 try expect(c[4] == 255);
818 var ptr: [*]const u8 = c;
827 const ptr: [*]const u8 = c;
819828 try expect(ptr[5] == 69);
820829}
821830
......@@ -825,13 +834,14 @@ test "array multiplication sets the sentinel - value" {
825834 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
826835
827836 var a = [2:7]u3{ 1, 6 };
828 var b = a ** 2;
837 _ = &a;
838 const b = a ** 2;
829839 comptime assert(@TypeOf(b) == [4:7]u3);
830840 try expect(b[0] == 1);
831841 try expect(b[1] == 6);
832842 try expect(b[2] == 1);
833843 try expect(b[3] == 6);
834 var ptr: [*]const u3 = &b;
844 const ptr: [*]const u3 = &b;
835845 try expect(ptr[4] == 7);
836846}
837847
......@@ -841,13 +851,13 @@ test "array multiplication sets the sentinel - pointer" {
841851 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
842852
843853 var a = [2:7]u3{ 1, 6 };
844 var b = &a ** 2;
854 const b = &a ** 2;
845855 comptime assert(@TypeOf(b) == *[4:7]u3);
846856 try expect(b[0] == 1);
847857 try expect(b[1] == 6);
848858 try expect(b[2] == 1);
849859 try expect(b[3] == 6);
850 var ptr: [*]const u3 = b;
860 const ptr: [*]const u3 = b;
851861 try expect(ptr[4] == 7);
852862}
853863
......@@ -913,8 +923,8 @@ test "comptime pointer load through elem_ptr" {
913923 .x = i,
914924 };
915925 }
916 var ptr = @as([*]S, @ptrCast(&array));
917 var x = ptr[0].x;
926 var ptr: [*]S = @ptrCast(&array);
927 const x = ptr[0].x;
918928 assert(x == 0);
919929 ptr += 1;
920930 assert(ptr[1].x == 2);
......@@ -953,11 +963,12 @@ test "closure capture type of runtime-known parameter" {
953963 const S = struct {
954964 fn b(c: anytype) !void {
955965 const D = struct { c: @TypeOf(c) };
956 var d = D{ .c = c };
966 const d: D = .{ .c = c };
957967 try expect(d.c == 1234);
958968 }
959969 };
960970 var c: i32 = 1234;
971 _ = &c;
961972 try S.b(c);
962973}
963974
......@@ -966,6 +977,7 @@ test "closure capture type of runtime-known var" {
966977 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
967978
968979 var x: u32 = 1234;
980 _ = &x;
969981 const S = struct { val: @TypeOf(x + 100) };
970982 const s: S = .{ .val = x };
971983 try expect(s.val == 1234);
......@@ -977,6 +989,7 @@ test "comptime break passing through runtime condition converted to runtime brea
977989 const S = struct {
978990 fn doTheTest() !void {
979991 var runtime: u8 = 'b';
992 _ = &runtime;
980993 inline for ([3]u8{ 'a', 'b', 'c' }) |byte| {
981994 bar();
982995 if (byte == runtime) {
......@@ -1010,6 +1023,7 @@ test "comptime break to outer loop passing through runtime condition converted t
10101023 const S = struct {
10111024 fn doTheTest() !void {
10121025 var runtime: u8 = 'b';
1026 _ = &runtime;
10131027 outer: inline for ([3]u8{ 'A', 'B', 'C' }) |outer_byte| {
10141028 inline for ([3]u8{ 'a', 'b', 'c' }) |byte| {
10151029 bar(outer_byte);
......@@ -1387,6 +1401,7 @@ test "break from inline loop depends on runtime condition" {
13871401
13881402test "inline for inside a runtime condition" {
13891403 var a = false;
1404 _ = &a;
13901405 if (a) {
13911406 const arr = .{ 1, 2, 3 };
13921407 inline for (arr) |val| {
......@@ -1522,6 +1537,7 @@ test "non-optional and optional array elements concatenated" {
15221537
15231538 const array = [1]u8{'A'} ++ [1]?u8{null};
15241539 var index: usize = 0;
1540 _ = &index;
15251541 try expect(array[index].? == 'A');
15261542}
15271543
......@@ -1556,6 +1572,7 @@ test "container level const and var have unique addresses" {
15561572 var v: @This() = c;
15571573 };
15581574 var p = &S.c;
1575 _ = &p;
15591576 try std.testing.expect(p.x == S.c.x);
15601577 S.v.x = 2;
15611578 try std.testing.expect(p.x == S.c.x);
......@@ -1625,7 +1642,8 @@ test "inline for loop of functions returning error unions" {
16251642test "if inside a switch" {
16261643 var condition = true;
16271644 var wave_type: u32 = 0;
1628 var sample: i32 = switch (wave_type) {
1645 _ = .{ &condition, &wave_type };
1646 const sample: i32 = switch (wave_type) {
16291647 0 => if (condition) 2 else 3,
16301648 1 => 100,
16311649 2 => 200,
......@@ -1673,6 +1691,7 @@ test "@inComptime" {
16731691comptime {
16741692 var foo = [3]u8{ 0x55, 0x55, 0x55 };
16751693 var bar = [2]u8{ 1, 2 };
1694 _ = .{ &foo, &bar };
16761695 foo[0..2].* = bar;
16771696 assert(foo[0] == 1);
16781697 assert(foo[1] == 2);
test/behavior/extern_struct_zero_size_fields.zig+1-1
......@@ -17,5 +17,5 @@ const T = extern struct {
1717
1818test {
1919 var t: T = .{};
20 _ = t;
20 _ = &t;
2121}
test/behavior/floatop.zig+150-14
......@@ -42,6 +42,8 @@ test "add f80/f128/c_longdouble" {
4242fn testAdd(comptime T: type) !void {
4343 var one_point_two_five: T = 1.25;
4444 var two_point_seven_five: T = 2.75;
45 _ = &one_point_two_five;
46 _ = &two_point_seven_five;
4547 try expect(one_point_two_five + two_point_seven_five == 4);
4648}
4749
......@@ -74,6 +76,8 @@ test "sub f80/f128/c_longdouble" {
7476fn testSub(comptime T: type) !void {
7577 var one_point_two_five: T = 1.25;
7678 var two_point_seven_five: T = 2.75;
79 _ = &one_point_two_five;
80 _ = &two_point_seven_five;
7781 try expect(one_point_two_five - two_point_seven_five == -1.5);
7882}
7983
......@@ -106,6 +110,8 @@ test "mul f80/f128/c_longdouble" {
106110fn testMul(comptime T: type) !void {
107111 var one_point_two_five: T = 1.25;
108112 var two_point_seven_five: T = 2.75;
113 _ = &one_point_two_five;
114 _ = &two_point_seven_five;
109115 try expect(one_point_two_five * two_point_seven_five == 3.4375);
110116}
111117
......@@ -152,6 +158,7 @@ fn testCmp(comptime T: type) !void {
152158 {
153159 // No decimal part
154160 var x: T = 1.0;
161 _ = &x;
155162 try expect(x == 1.0);
156163 try expect(x != 0.0);
157164 try expect(x > 0.0);
......@@ -162,6 +169,7 @@ fn testCmp(comptime T: type) !void {
162169 {
163170 // Non-zero decimal part
164171 var x: T = 1.5;
172 _ = &x;
165173 try expect(x != 1.0);
166174 try expect(x != 2.0);
167175 try expect(x > 1.0);
......@@ -184,6 +192,7 @@ fn testCmp(comptime T: type) !void {
184192 math.floatMax(T),
185193 math.inf(T),
186194 };
195 _ = &edges;
187196 for (edges, 0..) |rhs, rhs_i| {
188197 for (edges, 0..) |lhs, lhs_i| {
189198 const no_nan = lhs_i != 5 and rhs_i != 5;
......@@ -212,6 +221,7 @@ test "different sized float comparisons" {
212221fn testDifferentSizedFloatComparisons() !void {
213222 var a: f16 = 1;
214223 var b: f64 = 2;
224 _ = .{ &a, &b };
215225 try expect(a < b);
216226}
217227
......@@ -240,7 +250,8 @@ test "negative f128 intFromFloat at compile-time" {
240250 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
241251
242252 const a: f128 = -2;
243 var b = @as(i64, @intFromFloat(a));
253 var b: i64 = @intFromFloat(a);
254 _ = &b;
244255 try expect(@as(i64, -2) == b);
245256}
246257
......@@ -331,6 +342,28 @@ fn testSqrt(comptime T: type) !void {
331342 try expect(math.isNan(@sqrt(neg_one)));
332343 var nan: T = math.nan(T);
333344 try expect(math.isNan(@sqrt(nan)));
345
346 _ = .{
347 &four,
348 &nine,
349 &twenty_five,
350 &sixty_four,
351 &one_point_one,
352 &two,
353 &three_point_six,
354 &sixty_four_point_one,
355 &twelve,
356 &thirteen,
357 &fourteen,
358 &a,
359 &b,
360 &c,
361 &inf,
362 &zero,
363 &neg_zero,
364 &neg_one,
365 &nan,
366 };
334367}
335368
336369test "@sqrt with vectors" {
......@@ -345,7 +378,8 @@ test "@sqrt with vectors" {
345378
346379fn testSqrtWithVectors() !void {
347380 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
348 var result = @sqrt(v);
381 _ = &v;
382 const result = @sqrt(v);
349383 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon));
350384 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon));
351385 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon));
......@@ -394,8 +428,10 @@ test "@sin f80/f128/c_longdouble" {
394428fn testSin(comptime T: type) !void {
395429 const eps = epsForType(T);
396430 var zero: T = 0;
431 _ = &zero;
397432 try expect(@sin(zero) == 0);
398433 var pi: T = math.pi;
434 _ = &pi;
399435 try expect(math.approxEqAbs(T, @sin(pi), 0, eps));
400436 try expect(math.approxEqAbs(T, @sin(pi / 2.0), 1, eps));
401437 try expect(math.approxEqAbs(T, @sin(pi / 4.0), 0.7071067811865475, eps));
......@@ -414,7 +450,8 @@ test "@sin with vectors" {
414450
415451fn testSinWithVectors() !void {
416452 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
417 var result = @sin(v);
453 _ = &v;
454 const result = @sin(v);
418455 try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon));
419456 try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon));
420457 try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon));
......@@ -463,8 +500,10 @@ test "@cos f80/f128/c_longdouble" {
463500fn testCos(comptime T: type) !void {
464501 const eps = epsForType(T);
465502 var zero: T = 0;
503 _ = &zero;
466504 try expect(@cos(zero) == 1);
467505 var pi: T = math.pi;
506 _ = &pi;
468507 try expect(math.approxEqAbs(T, @cos(pi), -1, eps));
469508 try expect(math.approxEqAbs(T, @cos(pi / 2.0), 0, eps));
470509 try expect(math.approxEqAbs(T, @cos(pi / 4.0), 0.7071067811865475, eps));
......@@ -483,7 +522,8 @@ test "@cos with vectors" {
483522
484523fn testCosWithVectors() !void {
485524 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
486 var result = @cos(v);
525 _ = &v;
526 const result = @cos(v);
487527 try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon));
488528 try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon));
489529 try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon));
......@@ -532,8 +572,10 @@ test "@tan f80/f128/c_longdouble" {
532572fn testTan(comptime T: type) !void {
533573 const eps = epsForType(T);
534574 var zero: T = 0;
575 _ = &zero;
535576 try expect(@tan(zero) == 0);
536577 var pi: T = math.pi;
578 _ = &pi;
537579 try expect(math.approxEqAbs(T, @tan(pi), 0, eps));
538580 try expect(math.approxEqAbs(T, @tan(pi / 3.0), 1.732050807568878, eps));
539581 try expect(math.approxEqAbs(T, @tan(pi / 4.0), 1, eps));
......@@ -552,7 +594,8 @@ test "@tan with vectors" {
552594
553595fn testTanWithVectors() !void {
554596 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
555 var result = @tan(v);
597 _ = &v;
598 const result = @tan(v);
556599 try expect(math.approxEqAbs(f32, @tan(@as(f32, 1.1)), result[0], epsilon));
557600 try expect(math.approxEqAbs(f32, @tan(@as(f32, 2.2)), result[1], epsilon));
558601 try expect(math.approxEqAbs(f32, @tan(@as(f32, 3.3)), result[2], epsilon));
......@@ -600,11 +643,17 @@ test "@exp f80/f128/c_longdouble" {
600643
601644fn testExp(comptime T: type) !void {
602645 const eps = epsForType(T);
646
603647 var zero: T = 0;
648 _ = &zero;
604649 try expect(@exp(zero) == 1);
650
605651 var two: T = 2;
652 _ = &two;
606653 try expect(math.approxEqAbs(T, @exp(two), 7.389056098930650, eps));
654
607655 var five: T = 5;
656 _ = &five;
608657 try expect(math.approxEqAbs(T, @exp(five), 148.4131591025766, eps));
609658}
610659
......@@ -621,7 +670,8 @@ test "@exp with vectors" {
621670
622671fn testExpWithVectors() !void {
623672 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
624 var result = @exp(v);
673 _ = &v;
674 const result = @exp(v);
625675 try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon));
626676 try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon));
627677 try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon));
......@@ -675,6 +725,7 @@ fn testExp2(comptime T: type) !void {
675725 try expect(math.approxEqAbs(T, @exp2(one_point_five), 2.8284271247462, eps));
676726 var four_point_five: T = 4.5;
677727 try expect(math.approxEqAbs(T, @exp2(four_point_five), 22.627416997969, eps));
728 _ = .{ &two, &one_point_five, &four_point_five };
678729}
679730
680731test "@exp2 with @vectors" {
......@@ -690,7 +741,8 @@ test "@exp2 with @vectors" {
690741
691742fn testExp2WithVectors() !void {
692743 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
693 var result = @exp2(v);
744 _ = &v;
745 const result = @exp2(v);
694746 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon));
695747 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon));
696748 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon));
......@@ -744,6 +796,7 @@ fn testLog(comptime T: type) !void {
744796 try expect(math.approxEqAbs(T, @log(two), 0.6931471805599, eps));
745797 var five: T = 5;
746798 try expect(math.approxEqAbs(T, @log(five), 1.6094379124341, eps));
799 _ = .{ &e, &two, &five };
747800}
748801
749802test "@log with @vectors" {
......@@ -756,7 +809,8 @@ test "@log with @vectors" {
756809
757810 {
758811 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
759 var result = @log(v);
812 _ = &v;
813 const result = @log(v);
760814 try expect(@log(@as(f32, 1.1)) == result[0]);
761815 try expect(@log(@as(f32, 2.2)) == result[1]);
762816 try expect(@log(@as(f32, 0.3)) == result[2]);
......@@ -811,6 +865,7 @@ fn testLog2(comptime T: type) !void {
811865 try expect(math.approxEqAbs(T, @log2(six), 2.5849625007212, eps));
812866 var ten: T = 10;
813867 try expect(math.approxEqAbs(T, @log2(ten), 3.3219280948874, eps));
868 _ = .{ &four, &six, &ten };
814869}
815870
816871test "@log2 with vectors" {
......@@ -830,7 +885,8 @@ test "@log2 with vectors" {
830885
831886fn testLog2WithVectors() !void {
832887 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
833 var result = @log2(v);
888 _ = &v;
889 const result = @log2(v);
834890 try expect(@log2(@as(f32, 1.1)) == result[0]);
835891 try expect(@log2(@as(f32, 2.2)) == result[1]);
836892 try expect(@log2(@as(f32, 0.3)) == result[2]);
......@@ -884,6 +940,7 @@ fn testLog10(comptime T: type) !void {
884940 try expect(math.approxEqAbs(T, @log10(fifteen), 1.176091259056, eps));
885941 var fifty: T = 50;
886942 try expect(math.approxEqAbs(T, @log10(fifty), 1.698970004336, eps));
943 _ = .{ &hundred, &fifteen, &fifty };
887944}
888945
889946test "@log10 with vectors" {
......@@ -899,7 +956,8 @@ test "@log10 with vectors" {
899956
900957fn testLog10WithVectors() !void {
901958 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
902 var result = @log10(v);
959 _ = &v;
960 const result = @log10(v);
903961 try expect(@log10(@as(f32, 1.1)) == result[0]);
904962 try expect(@log10(@as(f32, 2.2)) == result[1]);
905963 try expect(@log10(@as(f32, 0.3)) == result[2]);
......@@ -987,6 +1045,26 @@ fn testFabs(comptime T: type) !void {
9871045 try expect(math.isPositiveInf(@abs(neg_inf)));
9881046 var nan: T = math.nan(T);
9891047 try expect(math.isNan(@abs(nan)));
1048
1049 _ = .{
1050 &two_point_five,
1051 &neg_two_point_five,
1052 &twelve,
1053 &neg_fourteen,
1054 &one,
1055 &neg_one,
1056 &min,
1057 &neg_min,
1058 &max,
1059 &neg_max,
1060 &zero,
1061 &neg_zero,
1062 &true_min,
1063 &neg_true_min,
1064 &inf,
1065 &neg_inf,
1066 &nan,
1067 };
9901068}
9911069
9921070test "@abs with vectors" {
......@@ -1001,7 +1079,8 @@ test "@abs with vectors" {
10011079
10021080fn testFabsWithVectors() !void {
10031081 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
1004 var result = @abs(v);
1082 _ = &v;
1083 const result = @abs(v);
10051084 try expect(math.approxEqAbs(f32, @abs(@as(f32, 1.1)), result[0], epsilon));
10061085 try expect(math.approxEqAbs(f32, @abs(@as(f32, -2.2)), result[1], epsilon));
10071086 try expect(math.approxEqAbs(f32, @abs(@as(f32, 0.3)), result[2], epsilon));
......@@ -1070,6 +1149,17 @@ fn testFloor(comptime T: type) !void {
10701149 try expect(@floor(fourteen_point_seven) == 14.0);
10711150 var neg_fourteen_point_seven: T = -14.7;
10721151 try expect(@floor(neg_fourteen_point_seven) == -15.0);
1152
1153 _ = .{
1154 &two_point_one,
1155 &neg_two_point_one,
1156 &three_point_five,
1157 &neg_three_point_five,
1158 &twelve,
1159 &neg_twelve,
1160 &fourteen_point_seven,
1161 &neg_fourteen_point_seven,
1162 };
10731163}
10741164
10751165test "@floor with vectors" {
......@@ -1086,7 +1176,8 @@ test "@floor with vectors" {
10861176
10871177fn testFloorWithVectors() !void {
10881178 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
1089 var result = @floor(v);
1179 _ = &v;
1180 const result = @floor(v);
10901181 try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon));
10911182 try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon));
10921183 try expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon));
......@@ -1155,6 +1246,17 @@ fn testCeil(comptime T: type) !void {
11551246 try expect(@ceil(fourteen_point_seven) == 15.0);
11561247 var neg_fourteen_point_seven: T = -14.7;
11571248 try expect(@ceil(neg_fourteen_point_seven) == -14.0);
1249
1250 _ = .{
1251 &two_point_one,
1252 &neg_two_point_one,
1253 &three_point_five,
1254 &neg_three_point_five,
1255 &twelve,
1256 &neg_twelve,
1257 &fourteen_point_seven,
1258 &neg_fourteen_point_seven,
1259 };
11581260}
11591261
11601262test "@ceil with vectors" {
......@@ -1171,7 +1273,8 @@ test "@ceil with vectors" {
11711273
11721274fn testCeilWithVectors() !void {
11731275 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
1174 var result = @ceil(v);
1276 _ = &v;
1277 const result = @ceil(v);
11751278 try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon));
11761279 try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon));
11771280 try expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon));
......@@ -1250,6 +1353,17 @@ fn testTrunc(comptime T: type) !void {
12501353 try expect(@trunc(fourteen_point_seven) == 14.0);
12511354 var neg_fourteen_point_seven: T = -14.7;
12521355 try expect(@trunc(neg_fourteen_point_seven) == -14.0);
1356
1357 _ = .{
1358 &two_point_one,
1359 &neg_two_point_one,
1360 &three_point_five,
1361 &neg_three_point_five,
1362 &twelve,
1363 &neg_twelve,
1364 &fourteen_point_seven,
1365 &neg_fourteen_point_seven,
1366 };
12531367}
12541368
12551369test "@trunc with vectors" {
......@@ -1266,7 +1380,8 @@ test "@trunc with vectors" {
12661380
12671381fn testTruncWithVectors() !void {
12681382 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
1269 var result = @trunc(v);
1383 _ = &v;
1384 const result = @trunc(v);
12701385 try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon));
12711386 try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon));
12721387 try expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon));
......@@ -1365,6 +1480,27 @@ fn testNeg(comptime T: type) !void {
13651480 var neg_nan: T = -math.nan(T);
13661481 try expect(math.isNan(-neg_nan));
13671482 try expect(!math.signbit(-neg_nan));
1483
1484 _ = .{
1485 &two_point_five,
1486 &neg_two_point_five,
1487 &twelve,
1488 &neg_fourteen,
1489 &one,
1490 &neg_one,
1491 &min,
1492 &neg_min,
1493 &max,
1494 &neg_max,
1495 &zero,
1496 &neg_zero,
1497 &true_min,
1498 &neg_true_min,
1499 &inf,
1500 &neg_inf,
1501 &nan,
1502 &neg_nan,
1503 };
13681504}
13691505
13701506test "eval @setFloatMode at compile-time" {
test/behavior/fn.zig+9-4
......@@ -21,6 +21,7 @@ fn testLocVars(b: i32) void {
2121
2222test "mutable local variables" {
2323 var zero: i32 = 0;
24 _ = &zero;
2425 try expect(zero == 0);
2526
2627 var i = @as(i32, 0);
......@@ -70,7 +71,7 @@ fn outer(y: u32) *const fn (u32) u32 {
7071test "return inner function which references comptime variable of outer function" {
7172 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
7273
73 var func = outer(10);
74 const func = outer(10);
7475 try expect(func(3) == 7);
7576}
7677
......@@ -259,7 +260,7 @@ test "implicit cast fn call result to optional in field result" {
259260
260261 const S = struct {
261262 fn entry() !void {
262 var x = Foo{
263 const x = Foo{
263264 .field = optionalPtr(),
264265 };
265266 try expect(x.field.?.* == 999);
......@@ -386,6 +387,7 @@ test "ability to give comptime types and non comptime types to same parameter" {
386387 const S = struct {
387388 fn doTheTest() !void {
388389 var x: i32 = 1;
390 _ = &x;
389391 try expect(foo(x) == 10);
390392 try expect(foo(i32) == 20);
391393 }
......@@ -413,11 +415,11 @@ test "import passed byref to function in return type" {
413415
414416 const S = struct {
415417 fn get() @import("std").ArrayListUnmanaged(i32) {
416 var x: @import("std").ArrayListUnmanaged(i32) = .{};
418 const x: @import("std").ArrayListUnmanaged(i32) = .{};
417419 return x;
418420 }
419421 };
420 var list = S.get();
422 const list = S.get();
421423 try expect(list.items.len == 0);
422424}
423425
......@@ -434,11 +436,13 @@ test "implicit cast function to function ptr" {
434436 }
435437 };
436438 var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue;
439 _ = &fnPtr1;
437440 try expect(fnPtr1() == 123);
438441 const S2 = struct {
439442 extern fn someFunctionThatReturnsAValue() c_int;
440443 };
441444 var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue;
445 _ = &fnPtr2;
442446 try expect(fnPtr2() == 123);
443447}
444448
......@@ -588,5 +592,6 @@ test "pointer to alias behaves same as pointer to function" {
588592 const bar = foo;
589593 };
590594 var a = &S.bar;
595 _ = &a;
591596 try std.testing.expect(S.foo() == a());
592597}
test/behavior/fn_in_struct_in_comptime.zig+1-2
......@@ -5,8 +5,7 @@ fn get_foo() fn (*u8) usize {
55 comptime {
66 return struct {
77 fn func(ptr: *u8) usize {
8 var u = @intFromPtr(ptr);
9 return u;
8 return @intFromPtr(ptr);
109 }
1110 }.func;
1211 }
test/behavior/for.zig+13-6
......@@ -26,7 +26,7 @@ test "break from outer for loop" {
2626}
2727
2828fn testBreakOuter() !void {
29 var array = "aoeu";
29 const array = "aoeu";
3030 var count: usize = 0;
3131 outer: for (array) |_| {
3232 for (array) |_| {
......@@ -43,7 +43,7 @@ test "continue outer for loop" {
4343}
4444
4545fn testContinueOuter() !void {
46 var array = "aoeu";
46 const array = "aoeu";
4747 var counter: usize = 0;
4848 outer: for (array) |_| {
4949 for (array) |_| {
......@@ -137,7 +137,7 @@ test "2 break statements and an else" {
137137 fn entry(t: bool, f: bool) !void {
138138 var buf: [10]u8 = undefined;
139139 var ok = false;
140 ok = for (buf) |item| {
140 ok = for (&buf) |*item| {
141141 _ = item;
142142 if (f) break false;
143143 if (t) break true;
......@@ -201,7 +201,7 @@ test "for on slice with allowzero ptr" {
201201
202202 const S = struct {
203203 fn doTheTest(slice: []const u8) !void {
204 var ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len];
204 const ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len];
205205 for (ptr, 0..) |x, i| try expect(x == i + 1);
206206 for (ptr, 0..) |*x, i| try expect(x.* == i + 1);
207207 }
......@@ -230,6 +230,7 @@ test "for loop with else branch" {
230230
231231 {
232232 var x = [_]u32{ 1, 2 };
233 _ = &x;
233234 const q = for (x) |y| {
234235 if ((y & 1) != 0) continue;
235236 break y * 2;
......@@ -238,6 +239,7 @@ test "for loop with else branch" {
238239 }
239240 {
240241 var x = [_]u32{ 1, 2 };
242 _ = &x;
241243 const q = for (x) |y| {
242244 if ((y & 1) != 0) continue;
243245 break y * 2;
......@@ -310,6 +312,7 @@ test "slice and two counters, one is offset and one is runtime" {
310312
311313 const slice: []const u8 = "blah";
312314 var start: usize = 0;
315 _ = &start;
313316
314317 for (slice, start..4, 1..5) |a, b, c| {
315318 if (a == 'b') {
......@@ -394,6 +397,7 @@ test "inline for with slice as the comptime-known" {
394397
395398 const comptime_slice = "hello";
396399 var runtime_i: usize = 3;
400 _ = &runtime_i;
397401
398402 const S = struct {
399403 var ok: usize = 0;
......@@ -424,6 +428,7 @@ test "inline for with counter as the comptime-known" {
424428
425429 var runtime_slice = "hello";
426430 var runtime_i: usize = 3;
431 _ = &runtime_i;
427432
428433 const S = struct {
429434 var ok: usize = 0;
......@@ -484,14 +489,16 @@ test "inferred alloc ptr of for loop" {
484489
485490 {
486491 var cond = false;
487 var opt = for (0..1) |_| {
492 _ = &cond;
493 const opt = for (0..1) |_| {
488494 if (cond) break cond;
489495 } else null;
490496 try expectEqual(@as(?bool, null), opt);
491497 }
492498 {
493499 var cond = true;
494 var opt = for (0..1) |_| {
500 _ = &cond;
501 const opt = for (0..1) |_| {
495502 if (cond) break cond;
496503 } else null;
497504 try expectEqual(@as(?bool, true), opt);
test/behavior/generics.zig+2
......@@ -102,6 +102,7 @@ test "type constructed by comptime function call" {
102102
103103fn SimpleList(comptime L: usize) type {
104104 var mutable_T = u8;
105 _ = &mutable_T;
105106 const T = mutable_T;
106107 return struct {
107108 array: [L]T,
......@@ -238,6 +239,7 @@ test "function parameter is generic" {
238239 }
239240 };
240241 var rng: u32 = 2;
242 _ = &rng;
241243 S.init(rng, S.fill);
242244}
243245
test/behavior/if.zig+12-5
......@@ -61,6 +61,7 @@ test "unwrap mutable global var" {
6161test "labeled break inside comptime if inside runtime if" {
6262 var answer: i32 = 0;
6363 var c = true;
64 _ = &c;
6465 if (c) {
6566 answer = if (true) blk: {
6667 break :blk @as(i32, 42);
......@@ -73,6 +74,7 @@ test "const result loc, runtime if cond, else unreachable" {
7374 const Num = enum { One, Two };
7475
7576 var t = true;
77 _ = &t;
7678 const x = if (t) Num.Two else unreachable;
7779 try expect(x == .Two);
7880}
......@@ -103,6 +105,7 @@ test "if prongs cast to expected type instead of peer type resolution" {
103105 try expect(x == 2);
104106
105107 var b = true;
108 _ = &b;
106109 const y: i32 = if (b) 1 else 2;
107110 try expect(y == 1);
108111 }
......@@ -118,10 +121,11 @@ test "if peer expressions inferred optional type" {
118121
119122 var self: []const u8 = "abcdef";
120123 var index: usize = 0;
121 var left_index = (index << 1) + 1;
122 var right_index = left_index + 1;
123 var left = if (left_index < self.len) self[left_index] else null;
124 var right = if (right_index < self.len) self[right_index] else null;
124 _ = .{ &self, &index };
125 const left_index = (index << 1) + 1;
126 const right_index = left_index + 1;
127 const left = if (left_index < self.len) self[left_index] else null;
128 const right = if (right_index < self.len) self[right_index] else null;
125129 try expect(left_index < self.len);
126130 try expect(right_index < self.len);
127131 try expect(left.? == 98);
......@@ -135,6 +139,7 @@ test "if-else expression with runtime condition result location is inferred opti
135139
136140 const A = struct { b: u64, c: u64 };
137141 var d: bool = true;
142 _ = &d;
138143 const e = if (d) A{ .b = 15, .c = 30 } else null;
139144 try expect(e != null);
140145}
......@@ -142,7 +147,8 @@ test "if-else expression with runtime condition result location is inferred opti
142147test "result location with inferred type ends up being pointer to comptime_int" {
143148 var a: ?u32 = 1234;
144149 var b: u32 = 2000;
145 var c = if (a) |d| blk: {
150 _ = .{ &a, &b };
151 const c = if (a) |d| blk: {
146152 if (d < b) break :blk @as(u32, 1);
147153 break :blk 0;
148154 } else @as(u32, 0);
......@@ -152,6 +158,7 @@ test "result location with inferred type ends up being pointer to comptime_int"
152158test "if-@as-if chain" {
153159 var fast = true;
154160 var very_fast = false;
161 _ = .{ &fast, &very_fast };
155162
156163 const num_frames = if (fast)
157164 @as(u32, if (very_fast) 16 else 4)
test/behavior/inline_switch.zig+8
......@@ -22,6 +22,7 @@ test "inline prong ranges" {
2222 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
2323
2424 var x: usize = 0;
25 _ = &x;
2526 switch (x) {
2627 inline 0...20, 24 => |item| {
2728 if (item > 25) @compileError("bad");
......@@ -36,6 +37,7 @@ test "inline switch enums" {
3637 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3738
3839 var x: E = .a;
40 _ = &x;
3941 switch (x) {
4042 inline .a, .b => |aorb| if (aorb != .a and aorb != .b) @compileError("bad"),
4143 inline .c, .d => |cord| if (cord != .c and cord != .d) @compileError("bad"),
......@@ -49,6 +51,7 @@ test "inline switch unions" {
4951 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
5052
5153 var x: U = .a;
54 _ = &x;
5255 switch (x) {
5356 inline .a, .b => |aorb, tag| {
5457 if (tag == .a) {
......@@ -74,6 +77,7 @@ test "inline else bool" {
7477 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
7578
7679 var a = true;
80 _ = &a;
7781 switch (a) {
7882 true => {},
7983 inline else => |val| if (val != false) @compileError("bad"),
......@@ -86,6 +90,7 @@ test "inline else error" {
8690
8791 const Err = error{ a, b, c };
8892 var a = Err.a;
93 _ = &a;
8994 switch (a) {
9095 error.a => {},
9196 inline else => |val| comptime if (val == error.a) @compileError("bad"),
......@@ -98,6 +103,7 @@ test "inline else enum" {
98103
99104 const E2 = enum(u8) { a = 2, b = 3, c = 4, d = 5 };
100105 var a: E2 = .a;
106 _ = &a;
101107 switch (a) {
102108 .a, .b => {},
103109 inline else => |val| comptime if (@intFromEnum(val) < 4) @compileError("bad"),
......@@ -109,6 +115,7 @@ test "inline else int with gaps" {
109115 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
110116
111117 var a: u8 = 0;
118 _ = &a;
112119 switch (a) {
113120 1...125, 128...254 => {},
114121 inline else => |val| {
......@@ -126,6 +133,7 @@ test "inline else int all values" {
126133 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
127134
128135 var a: u2 = 0;
136 _ = &a;
129137 switch (a) {
130138 inline else => |val| {
131139 if (val != 0 and
test/behavior/int128.zig+3
......@@ -39,6 +39,7 @@ test "undefined 128 bit int" {
3939
4040 var undef: u128 = undefined;
4141 var undef_signed: i128 = undefined;
42 _ = .{ &undef, &undef_signed };
4243 try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @as(u128, @bitCast(undef_signed)) == undef);
4344}
4445
......@@ -73,6 +74,7 @@ test "truncate int128" {
7374
7475 {
7576 var buff: u128 = maxInt(u128);
77 _ = &buff;
7678 try expect(@as(u64, @truncate(buff)) == maxInt(u64));
7779 try expect(@as(u90, @truncate(buff)) == maxInt(u90));
7880 try expect(@as(u128, @truncate(buff)) == maxInt(u128));
......@@ -80,6 +82,7 @@ test "truncate int128" {
8082
8183 {
8284 var buff: i128 = maxInt(i128);
85 _ = &buff;
8386 try expect(@as(i64, @truncate(buff)) == -1);
8487 try expect(@as(i90, @truncate(buff)) == -1);
8588 try expect(@as(i128, @truncate(buff)) == maxInt(i128));
test/behavior/int_comparison_elision.zig+1
......@@ -30,6 +30,7 @@ fn testIntEdges(comptime T: type) void {
3030 const max = maxInt(T);
3131
3232 var runtime_val: T = undefined;
33 _ = &runtime_val;
3334
3435 if (min > runtime_val) @compileError("analyzed impossible branch");
3536 if (min <= runtime_val) {} else @compileError("analyzed impossible branch");
test/behavior/int_div.zig+2
......@@ -100,11 +100,13 @@ test "large integer division" {
100100 {
101101 var numerator: u256 = 99999999999999999997315645440;
102102 var divisor: u256 = 10000000000000000000000000000;
103 _ = .{ &numerator, &divisor };
103104 try expect(numerator / divisor == 9);
104105 }
105106 {
106107 var numerator: u256 = 99999999999999999999000000000000000000000;
107108 var divisor: u256 = 10000000000000000000000000000000000000000;
109 _ = .{ &numerator, &divisor };
108110 try expect(numerator / divisor == 9);
109111 }
110112}
test/behavior/math.zig+53-5
......@@ -624,7 +624,8 @@ const DivResult = struct {
624624
625625test "bit shift a u1" {
626626 var x: u1 = 1;
627 var y = x << 0;
627 _ = &x;
628 const y = x << 0;
628629 try expect(y == 1);
629630}
630631
......@@ -692,7 +693,8 @@ test "128-bit multiplication" {
692693 {
693694 var a: u128 = 0xffffffffffffffff;
694695 var b: u128 = 100;
695 var c = a * b;
696 _ = .{ &a, &b };
697 const c = a * b;
696698 try expect(c == 0x63ffffffffffffff9c);
697699 }
698700}
......@@ -704,18 +706,21 @@ test "@addWithOverflow" {
704706
705707 {
706708 var a: u8 = 250;
709 _ = &a;
707710 const ov = @addWithOverflow(a, 100);
708711 try expect(ov[0] == 94);
709712 try expect(ov[1] == 1);
710713 }
711714 {
712715 var a: u8 = 100;
716 _ = &a;
713717 const ov = @addWithOverflow(a, 150);
714718 try expect(ov[0] == 250);
715719 try expect(ov[1] == 0);
716720 }
717721 {
718722 var a: u8 = 200;
723 _ = &a;
719724 var b: u8 = 99;
720725 var ov = @addWithOverflow(a, b);
721726 try expect(ov[0] == 43);
......@@ -729,6 +734,7 @@ test "@addWithOverflow" {
729734 {
730735 var a: usize = 6;
731736 var b: usize = 6;
737 _ = .{ &a, &b };
732738 const ov = @addWithOverflow(a, b);
733739 try expect(ov[0] == 12);
734740 try expect(ov[1] == 0);
......@@ -737,6 +743,7 @@ test "@addWithOverflow" {
737743 {
738744 var a: isize = -6;
739745 var b: isize = -6;
746 _ = .{ &a, &b };
740747 const ov = @addWithOverflow(a, b);
741748 try expect(ov[0] == -12);
742749 try expect(ov[1] == 0);
......@@ -772,18 +779,21 @@ test "basic @mulWithOverflow" {
772779
773780 {
774781 var a: u8 = 86;
782 _ = &a;
775783 const ov = @mulWithOverflow(a, 3);
776784 try expect(ov[0] == 2);
777785 try expect(ov[1] == 1);
778786 }
779787 {
780788 var a: u8 = 85;
789 _ = &a;
781790 const ov = @mulWithOverflow(a, 3);
782791 try expect(ov[0] == 255);
783792 try expect(ov[1] == 0);
784793 }
785794
786795 var a: u8 = 123;
796 _ = &a;
787797 var b: u8 = 2;
788798 var ov = @mulWithOverflow(a, b);
789799 try expect(ov[0] == 246);
......@@ -802,6 +812,7 @@ test "extensive @mulWithOverflow" {
802812
803813 {
804814 var a: u5 = 3;
815 _ = &a;
805816 var b: u5 = 10;
806817 var ov = @mulWithOverflow(a, b);
807818 try expect(ov[0] == 30);
......@@ -815,6 +826,7 @@ test "extensive @mulWithOverflow" {
815826
816827 {
817828 var a: i5 = 3;
829 _ = &a;
818830 var b: i5 = -5;
819831 var ov = @mulWithOverflow(a, b);
820832 try expect(ov[0] == -15);
......@@ -828,6 +840,7 @@ test "extensive @mulWithOverflow" {
828840
829841 {
830842 var a: u8 = 3;
843 _ = &a;
831844 var b: u8 = 85;
832845
833846 var ov = @mulWithOverflow(a, b);
......@@ -842,6 +855,7 @@ test "extensive @mulWithOverflow" {
842855
843856 {
844857 var a: i8 = 3;
858 _ = &a;
845859 var b: i8 = -42;
846860 var ov = @mulWithOverflow(a, b);
847861 try expect(ov[0] == -126);
......@@ -855,6 +869,7 @@ test "extensive @mulWithOverflow" {
855869
856870 {
857871 var a: u14 = 3;
872 _ = &a;
858873 var b: u14 = 0x1555;
859874 var ov = @mulWithOverflow(a, b);
860875 try expect(ov[0] == 0x3fff);
......@@ -868,6 +883,7 @@ test "extensive @mulWithOverflow" {
868883
869884 {
870885 var a: i14 = 3;
886 _ = &a;
871887 var b: i14 = -0xaaa;
872888 var ov = @mulWithOverflow(a, b);
873889 try expect(ov[0] == -0x1ffe);
......@@ -880,6 +896,7 @@ test "extensive @mulWithOverflow" {
880896
881897 {
882898 var a: u16 = 3;
899 _ = &a;
883900 var b: u16 = 0x5555;
884901 var ov = @mulWithOverflow(a, b);
885902 try expect(ov[0] == 0xffff);
......@@ -893,6 +910,7 @@ test "extensive @mulWithOverflow" {
893910
894911 {
895912 var a: i16 = 3;
913 _ = &a;
896914 var b: i16 = -0x2aaa;
897915 var ov = @mulWithOverflow(a, b);
898916 try expect(ov[0] == -0x7ffe);
......@@ -906,6 +924,7 @@ test "extensive @mulWithOverflow" {
906924
907925 {
908926 var a: u30 = 3;
927 _ = &a;
909928 var b: u30 = 0x15555555;
910929 var ov = @mulWithOverflow(a, b);
911930 try expect(ov[0] == 0x3fffffff);
......@@ -919,6 +938,7 @@ test "extensive @mulWithOverflow" {
919938
920939 {
921940 var a: i30 = 3;
941 _ = &a;
922942 var b: i30 = -0xaaaaaaa;
923943 var ov = @mulWithOverflow(a, b);
924944 try expect(ov[0] == -0x1ffffffe);
......@@ -932,6 +952,7 @@ test "extensive @mulWithOverflow" {
932952
933953 {
934954 var a: u32 = 3;
955 _ = &a;
935956 var b: u32 = 0x55555555;
936957 var ov = @mulWithOverflow(a, b);
937958 try expect(ov[0] == 0xffffffff);
......@@ -945,6 +966,7 @@ test "extensive @mulWithOverflow" {
945966
946967 {
947968 var a: i32 = 3;
969 _ = &a;
948970 var b: i32 = -0x2aaaaaaa;
949971 var ov = @mulWithOverflow(a, b);
950972 try expect(ov[0] == -0x7ffffffe);
......@@ -967,6 +989,7 @@ test "@mulWithOverflow bitsize > 32" {
967989
968990 {
969991 var a: u62 = 3;
992 _ = &a;
970993 var b: u62 = 0x1555555555555555;
971994 var ov = @mulWithOverflow(a, b);
972995 try expect(ov[0] == 0x3fffffffffffffff);
......@@ -980,6 +1003,7 @@ test "@mulWithOverflow bitsize > 32" {
9801003
9811004 {
9821005 var a: i62 = 3;
1006 _ = &a;
9831007 var b: i62 = -0xaaaaaaaaaaaaaaa;
9841008 var ov = @mulWithOverflow(a, b);
9851009 try expect(ov[0] == -0x1ffffffffffffffe);
......@@ -993,6 +1017,7 @@ test "@mulWithOverflow bitsize > 32" {
9931017
9941018 {
9951019 var a: u64 = 3;
1020 _ = &a;
9961021 var b: u64 = 0x5555555555555555;
9971022 var ov = @mulWithOverflow(a, b);
9981023 try expect(ov[0] == 0xffffffffffffffff);
......@@ -1006,6 +1031,7 @@ test "@mulWithOverflow bitsize > 32" {
10061031
10071032 {
10081033 var a: i64 = 3;
1034 _ = &a;
10091035 var b: i64 = -0x2aaaaaaaaaaaaaaa;
10101036 var ov = @mulWithOverflow(a, b);
10111037 try expect(ov[0] == -0x7ffffffffffffffe);
......@@ -1025,12 +1051,14 @@ test "@subWithOverflow" {
10251051
10261052 {
10271053 var a: u8 = 1;
1054 _ = &a;
10281055 const ov = @subWithOverflow(a, 2);
10291056 try expect(ov[0] == 255);
10301057 try expect(ov[1] == 1);
10311058 }
10321059 {
10331060 var a: u8 = 1;
1061 _ = &a;
10341062 const ov = @subWithOverflow(a, 1);
10351063 try expect(ov[0] == 0);
10361064 try expect(ov[1] == 0);
......@@ -1038,6 +1066,7 @@ test "@subWithOverflow" {
10381066
10391067 {
10401068 var a: u8 = 1;
1069 _ = &a;
10411070 var b: u8 = 2;
10421071 var ov = @subWithOverflow(a, b);
10431072 try expect(ov[0] == 255);
......@@ -1051,6 +1080,7 @@ test "@subWithOverflow" {
10511080 {
10521081 var a: usize = 6;
10531082 var b: usize = 6;
1083 _ = .{ &a, &b };
10541084 const ov = @subWithOverflow(a, b);
10551085 try expect(ov[0] == 0);
10561086 try expect(ov[1] == 0);
......@@ -1059,6 +1089,7 @@ test "@subWithOverflow" {
10591089 {
10601090 var a: isize = -6;
10611091 var b: isize = -6;
1092 _ = .{ &a, &b };
10621093 const ov = @subWithOverflow(a, b);
10631094 try expect(ov[0] == 0);
10641095 try expect(ov[1] == 0);
......@@ -1072,6 +1103,7 @@ test "@shlWithOverflow" {
10721103
10731104 {
10741105 var a: u4 = 2;
1106 _ = &a;
10751107 var b: u2 = 1;
10761108 var ov = @shlWithOverflow(a, b);
10771109 try expect(ov[0] == 4);
......@@ -1085,6 +1117,7 @@ test "@shlWithOverflow" {
10851117
10861118 {
10871119 var a: i9 = 127;
1120 _ = &a;
10881121 var b: u4 = 1;
10891122 var ov = @shlWithOverflow(a, b);
10901123 try expect(ov[0] == 254);
......@@ -1108,6 +1141,7 @@ test "@shlWithOverflow" {
11081141 }
11091142 {
11101143 var a: u16 = 0b0000_0000_0000_0011;
1144 _ = &a;
11111145 var b: u4 = 15;
11121146 var ov = @shlWithOverflow(a, b);
11131147 try expect(ov[0] == 0b1000_0000_0000_0000);
......@@ -1124,24 +1158,28 @@ test "overflow arithmetic with u0 values" {
11241158
11251159 {
11261160 var a: u0 = 0;
1161 _ = &a;
11271162 const ov = @addWithOverflow(a, 0);
11281163 try expect(ov[1] == 0);
11291164 try expect(ov[1] == 0);
11301165 }
11311166 {
11321167 var a: u0 = 0;
1168 _ = &a;
11331169 const ov = @subWithOverflow(a, 0);
11341170 try expect(ov[1] == 0);
11351171 try expect(ov[1] == 0);
11361172 }
11371173 {
11381174 var a: u0 = 0;
1175 _ = &a;
11391176 const ov = @mulWithOverflow(a, 0);
11401177 try expect(ov[1] == 0);
11411178 try expect(ov[1] == 0);
11421179 }
11431180 {
11441181 var a: u0 = 0;
1182 _ = &a;
11451183 const ov = @shlWithOverflow(a, 0);
11461184 try expect(ov[1] == 0);
11471185 try expect(ov[1] == 0);
......@@ -1157,6 +1195,7 @@ test "allow signed integer division/remainder when values are comptime-known and
11571195 try expect(-6 % 3 == 0);
11581196
11591197 var undef: i32 = undefined;
1198 _ = &undef;
11601199 if (0 % undef != 0) {
11611200 @compileError("0 as numerator should return comptime zero independent of denominator");
11621201 }
......@@ -1183,18 +1222,22 @@ test "quad hex float literal parsing accurate" {
11831222 fn doTheTest() !void {
11841223 {
11851224 var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;
1225 _ = &f;
11861226 try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234);
11871227 }
11881228 {
11891229 var f: f128 = 0x1.edcb34a235253948765432134674fp-1;
1230 _ = &f;
11901231 try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even
11911232 }
11921233 {
11931234 var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50;
1235 _ = &f;
11941236 try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
11951237 }
11961238 {
11971239 var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;
1240 _ = &f;
11981241 try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568);
11991242 }
12001243 const exp2ft = [_]f64{
......@@ -1294,6 +1337,7 @@ test "shift left/right on u0 operand" {
12941337 fn doTheTest() !void {
12951338 var x: u0 = 0;
12961339 var y: u0 = 0;
1340 _ = .{ &x, &y };
12971341 try expectEqual(@as(u0, 0), x << 0);
12981342 try expectEqual(@as(u0, 0), x >> 0);
12991343 try expectEqual(@as(u0, 0), x << y);
......@@ -1310,7 +1354,7 @@ test "shift left/right on u0 operand" {
13101354
13111355test "comptime float rem int" {
13121356 comptime {
1313 var x = @as(f32, 1) % 2;
1357 const x = @as(f32, 1) % 2;
13141358 try expect(x == 1.0);
13151359 }
13161360}
......@@ -1511,7 +1555,8 @@ test "vector integer addition" {
15111555 fn doTheTest() !void {
15121556 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
15131557 var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
1514 var result = a + b;
1558 _ = .{ &a, &b };
1559 const result = a + b;
15151560 var result_array: [4]i32 = result;
15161561 const expected = [_]i32{ 6, 8, 10, 12 };
15171562 try expectEqualSlices(i32, &expected, &result_array);
......@@ -1552,6 +1597,7 @@ test "NaN comparison f80" {
15521597fn testNanEqNan(comptime F: type) !void {
15531598 var nan1 = math.nan(F);
15541599 var nan2 = math.nan(F);
1600 _ = .{ &nan1, &nan2 };
15551601 try expect(nan1 != nan2);
15561602 try expect(!(nan1 == nan2));
15571603 try expect(!(nan1 > nan2));
......@@ -1571,6 +1617,7 @@ test "vector comparison" {
15711617 fn doTheTest() !void {
15721618 var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };
15731619 var b: @Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 };
1620 _ = .{ &a, &b };
15741621 try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false }));
15751622 try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false }));
15761623 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" {
16091656 fn testOne(comptime T: type) !void {
16101657 const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
16111658 var as_fp_val = -@as(T, 0.0);
1612 var as_uint_val = @as(ST, @bitCast(as_fp_val));
1659 _ = &as_fp_val;
1660 const as_uint_val: ST = @bitCast(as_fp_val);
16131661 // Ensure the sign bit is set.
16141662 try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
16151663 }
test/behavior/maximum_minimum.zig+23-6
......@@ -15,6 +15,7 @@ test "@max" {
1515 var x: i32 = 10;
1616 var y: f32 = 0.68;
1717 var nan: f32 = std.math.nan(f32);
18 _ = .{ &x, &y, &nan };
1819 try expect(@as(i32, 10) == @max(@as(i32, -3), x));
1920 try expect(@as(f32, 3.2) == @max(@as(f32, 3.2), y));
2021 try expect(y == @max(nan, y));
......@@ -38,17 +39,20 @@ test "@max on vectors" {
3839 fn doTheTest() !void {
3940 var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
4041 var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
41 var x = @max(a, b);
42 const x = @max(a, b);
43 _ = .{ &a, &b };
4244 try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 2147483647, 2147483647, 30, 40 }));
4345
4446 var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 };
4547 var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 };
46 var y = @max(c, d);
48 const y = @max(c, d);
49 _ = .{ &c, &d };
4750 try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ 0, 0.42, -0.64, 7.8 }));
4851
4952 var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) };
5053 var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 };
51 var z = @max(e, f);
54 const z = @max(e, f);
55 _ = .{ &e, &f };
5256 try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 }));
5357 }
5458 };
......@@ -66,6 +70,7 @@ test "@min" {
6670 var x: i32 = 10;
6771 var y: f32 = 0.68;
6872 var nan: f32 = std.math.nan(f32);
73 _ = .{ &x, &y, &nan };
6974 try expect(@as(i32, -3) == @min(@as(i32, -3), x));
7075 try expect(@as(f32, 0.68) == @min(@as(f32, 3.2), y));
7176 try expect(y == @min(nan, y));
......@@ -89,17 +94,20 @@ test "@min for vectors" {
8994 fn doTheTest() !void {
9095 var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
9196 var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
92 var x = @min(a, b);
97 _ = .{ &a, &b };
98 const x = @min(a, b);
9399 try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 1, -2, 3, 4 }));
94100
95101 var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 };
96102 var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 };
97 var y = @min(c, d);
103 _ = .{ &c, &d };
104 const y = @min(c, d);
98105 try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ -0.23, 0.4, -2.4, 0.9 }));
99106
100107 var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) };
101108 var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 };
102 var z = @max(e, f);
109 _ = .{ &e, &f };
110 const z = @max(e, f);
103111 try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 }));
104112 }
105113 };
......@@ -119,6 +127,7 @@ test "@min/max for floats" {
119127 fn doTheTest(comptime T: type) !void {
120128 var x: T = -3.14;
121129 var y: T = 5.27;
130 _ = .{ &x, &y };
122131 try expectEqual(x, @min(x, y));
123132 try expectEqual(x, @min(y, x));
124133 try expectEqual(y, @max(x, y));
......@@ -126,6 +135,7 @@ test "@min/max for floats" {
126135
127136 if (T != comptime_float) {
128137 var nan: T = std.math.nan(T);
138 _ = &nan;
129139 try expectEqual(y, @max(nan, y));
130140 try expectEqual(y, @max(y, nan));
131141 }
......@@ -175,6 +185,7 @@ test "@min/@max notices bounds" {
175185 var x: u16 = 20;
176186 const y = 30;
177187 var z: u32 = 100;
188 _ = .{ &x, &z };
178189 const min = @min(x, y, z);
179190 const max = @max(x, y, z);
180191 try expectEqual(x, min);
......@@ -194,6 +205,7 @@ test "@min/@max notices vector bounds" {
194205 var x: @Vector(2, u16) = .{ 140, 40 };
195206 const y: @Vector(2, u64) = .{ 5, 100 };
196207 var z: @Vector(2, u32) = .{ 10, 300 };
208 _ = .{ &x, &z };
197209 const min = @min(x, y, z);
198210 const max = @max(x, y, z);
199211 try expectEqual(@Vector(2, u32){ 5, 40 }, min);
......@@ -224,6 +236,7 @@ test "@min/@max notices bounds from types" {
224236 var x: u16 = 123;
225237 var y: u32 = 456;
226238 var z: u8 = 10;
239 _ = .{ &x, &y, &z };
227240
228241 const min = @min(x, y, z);
229242 const max = @max(x, y, z);
......@@ -246,6 +259,7 @@ test "@min/@max notices bounds from vector types" {
246259 var x: @Vector(2, u16) = .{ 30, 67 };
247260 var y: @Vector(2, u32) = .{ 20, 500 };
248261 var z: @Vector(2, u8) = .{ 60, 15 };
262 _ = .{ &x, &y, &z };
249263
250264 const min = @min(x, y, z);
251265 const max = @max(x, y, z);
......@@ -263,6 +277,7 @@ test "@min/@max notices bounds from types when comptime-known value is undef" {
263277 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
264278
265279 var x: u32 = 1_000_000;
280 _ = &x;
266281 const y: u16 = undefined;
267282 // y is comptime-known, but is undef, so bounds cannot be refined using its value
268283
......@@ -285,6 +300,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known
285300 !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx)) return error.SkipZigTest;
286301
287302 var x: @Vector(2, u32) = .{ 1_000_000, 12345 };
303 _ = &x;
288304 const y: @Vector(2, u16) = .{ 10, undefined };
289305 // y is comptime-known, but an element is undef, so bounds cannot be refined using its value
290306
......@@ -302,6 +318,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known
302318test "@min/@max of signed and unsigned runtime integers" {
303319 var x: i32 = -1;
304320 var y: u31 = 1;
321 _ = .{ &x, &y };
305322
306323 const min = @min(x, y);
307324 const max = @max(x, y);
test/behavior/memcpy.zig+1
......@@ -57,6 +57,7 @@ fn testMemcpyDestManyPtr() !void {
5757 var str = "hello".*;
5858 var buf: [5]u8 = undefined;
5959 var len: usize = 5;
60 _ = &len;
6061 @memcpy(@as([*]u8, @ptrCast(&buf)), @as([*]const u8, @ptrCast(&str))[0..len]);
6162 try expect(buf[0] == 'h');
6263 try expect(buf[1] == 'e');
test/behavior/memset.zig+5-2
......@@ -46,7 +46,8 @@ fn testMemsetSlice() !void {
4646 // memset slice to non-undefined, ABI size == 1
4747 var array: [20]u8 = undefined;
4848 var len = array.len;
49 var slice = array[0..len];
49 _ = &len;
50 const slice = array[0..len];
5051 @memset(slice, 'A');
5152 try expect(slice[0] == 'A');
5253 try expect(slice[11] == 'A');
......@@ -56,7 +57,8 @@ fn testMemsetSlice() !void {
5657 // memset slice to non-undefined, ABI size > 1
5758 var array: [20]u32 = undefined;
5859 var len = array.len;
59 var slice = array[0..len];
60 _ = &len;
61 const slice = array[0..len];
6062 @memset(slice, 1234);
6163 try expect(slice[0] == 1234);
6264 try expect(slice[11] == 1234);
......@@ -111,6 +113,7 @@ test "memset with large array element, runtime known" {
111113 const A = [128]u64;
112114 var buf: [5]A = undefined;
113115 var runtime_known_element = [_]u64{0} ** 128;
116 _ = &runtime_known_element;
114117 @memset(&buf, runtime_known_element);
115118 for (buf[0]) |elem| try expect(elem == 0);
116119 for (buf[1]) |elem| try expect(elem == 0);
test/behavior/muladd.zig+15-5
......@@ -21,12 +21,14 @@ fn testMulAdd() !void {
2121 var a: f32 = 5.5;
2222 var b: f32 = 2.5;
2323 var c: f32 = 6.25;
24 _ = .{ &a, &b, &c };
2425 try expect(@mulAdd(f32, a, b, c) == 20);
2526 }
2627 {
2728 var a: f64 = 5.5;
2829 var b: f64 = 2.5;
2930 var c: f64 = 6.25;
31 _ = .{ &a, &b, &c };
3032 try expect(@mulAdd(f64, a, b, c) == 20);
3133 }
3234}
......@@ -46,6 +48,7 @@ fn testMulAdd16() !void {
4648 var a: f16 = 5.5;
4749 var b: f16 = 2.5;
4850 var c: f16 = 6.25;
51 _ = .{ &a, &b, &c };
4952 try expect(@mulAdd(f16, a, b, c) == 20);
5053}
5154
......@@ -65,6 +68,7 @@ fn testMulAdd80() !void {
6568 var a: f16 = 5.5;
6669 var b: f80 = 2.5;
6770 var c: f80 = 6.25;
71 _ = .{ &a, &b, &c };
6872 try expect(@mulAdd(f80, a, b, c) == 20);
6973}
7074
......@@ -84,6 +88,7 @@ fn testMulAdd128() !void {
8488 var a: f16 = 5.5;
8589 var b: f128 = 2.5;
8690 var c: f128 = 6.25;
91 _ = .{ &a, &b, &c };
8792 try expect(@mulAdd(f128, a, b, c) == 20);
8893}
8994
......@@ -91,7 +96,8 @@ fn vector16() !void {
9196 var a = @Vector(4, f16){ 5.5, 5.5, 5.5, 5.5 };
9297 var b = @Vector(4, f16){ 2.5, 2.5, 2.5, 2.5 };
9398 var c = @Vector(4, f16){ 6.25, 6.25, 6.25, 6.25 };
94 var x = @mulAdd(@Vector(4, f16), a, b, c);
99 _ = .{ &a, &b, &c };
100 const x = @mulAdd(@Vector(4, f16), a, b, c);
95101
96102 try expect(x[0] == 20);
97103 try expect(x[1] == 20);
......@@ -115,7 +121,8 @@ fn vector32() !void {
115121 var a = @Vector(4, f32){ 5.5, 5.5, 5.5, 5.5 };
116122 var b = @Vector(4, f32){ 2.5, 2.5, 2.5, 2.5 };
117123 var c = @Vector(4, f32){ 6.25, 6.25, 6.25, 6.25 };
118 var x = @mulAdd(@Vector(4, f32), a, b, c);
124 _ = .{ &a, &b, &c };
125 const x = @mulAdd(@Vector(4, f32), a, b, c);
119126
120127 try expect(x[0] == 20);
121128 try expect(x[1] == 20);
......@@ -139,7 +146,8 @@ fn vector64() !void {
139146 var a = @Vector(4, f64){ 5.5, 5.5, 5.5, 5.5 };
140147 var b = @Vector(4, f64){ 2.5, 2.5, 2.5, 2.5 };
141148 var c = @Vector(4, f64){ 6.25, 6.25, 6.25, 6.25 };
142 var x = @mulAdd(@Vector(4, f64), a, b, c);
149 _ = .{ &a, &b, &c };
150 const x = @mulAdd(@Vector(4, f64), a, b, c);
143151
144152 try expect(x[0] == 20);
145153 try expect(x[1] == 20);
......@@ -163,7 +171,8 @@ fn vector80() !void {
163171 var a = @Vector(4, f80){ 5.5, 5.5, 5.5, 5.5 };
164172 var b = @Vector(4, f80){ 2.5, 2.5, 2.5, 2.5 };
165173 var c = @Vector(4, f80){ 6.25, 6.25, 6.25, 6.25 };
166 var x = @mulAdd(@Vector(4, f80), a, b, c);
174 _ = .{ &a, &b, &c };
175 const x = @mulAdd(@Vector(4, f80), a, b, c);
167176 try expect(x[0] == 20);
168177 try expect(x[1] == 20);
169178 try expect(x[2] == 20);
......@@ -187,7 +196,8 @@ fn vector128() !void {
187196 var a = @Vector(4, f128){ 5.5, 5.5, 5.5, 5.5 };
188197 var b = @Vector(4, f128){ 2.5, 2.5, 2.5, 2.5 };
189198 var c = @Vector(4, f128){ 6.25, 6.25, 6.25, 6.25 };
190 var x = @mulAdd(@Vector(4, f128), a, b, c);
199 _ = .{ &a, &b, &c };
200 const x = @mulAdd(@Vector(4, f128), a, b, c);
191201
192202 try expect(x[0] == 20);
193203 try expect(x[1] == 20);
test/behavior/null.zig+1
......@@ -134,6 +134,7 @@ test "optional pointer to 0 bit type null value at runtime" {
134134
135135 const EmptyStruct = struct {};
136136 var x: ?*EmptyStruct = null;
137 _ = &x;
137138 try expect(x == null);
138139}
139140
test/behavior/optional.zig+13-6
......@@ -11,7 +11,7 @@ test "passing an optional integer as a parameter" {
1111
1212 const S = struct {
1313 fn entry() bool {
14 var x: i32 = 1234;
14 const x: i32 = 1234;
1515 return foo(x);
1616 }
1717
......@@ -29,7 +29,7 @@ test "optional pointer to size zero struct" {
2929 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3030
3131 var e = EmptyStruct{};
32 var o: ?*EmptyStruct = &e;
32 const o: ?*EmptyStruct = &e;
3333 try expect(o != null);
3434}
3535
......@@ -63,6 +63,7 @@ test "optional with void type" {
6363 x: ?void,
6464 };
6565 var x = Foo{ .x = null };
66 _ = &x;
6667 try expect(x.x == null);
6768}
6869
......@@ -102,6 +103,7 @@ test "nested optional field in struct" {
102103 var s = S1{
103104 .x = S2{ .y = 127 },
104105 };
106 _ = &s;
105107 try expect(s.x.?.y == 127);
106108}
107109
......@@ -120,6 +122,8 @@ fn test_cmp_optional_non_optional() !void {
120122 var five: i32 = 5;
121123 var int_n: ?i32 = null;
122124
125 _ = .{ &ten, &opt_ten, &five, &int_n };
126
123127 try expect(int_n != ten);
124128 try expect(opt_ten == ten);
125129 try expect(opt_ten != five);
......@@ -208,7 +212,7 @@ test "self-referential struct through a slice of optional" {
208212 };
209213 };
210214
211 var n = S.Node.new();
215 const n = S.Node.new();
212216 try expect(n.data == null);
213217}
214218
......@@ -252,7 +256,7 @@ test "0-bit child type coerced to optional return ptr result location" {
252256 const S = struct {
253257 fn doTheTest() !void {
254258 var y = Foo{};
255 var z = y.thing();
259 const z = y.thing();
256260 try expect(z != null);
257261 }
258262
......@@ -425,6 +429,7 @@ test "alignment of wrapping an optional payload" {
425429
426430 fn foo() ?I {
427431 var i: I = .{ .x = 1234 };
432 _ = &i;
428433 return i;
429434 }
430435 };
......@@ -450,15 +455,16 @@ test "peer type resolution in nested if expressions" {
450455 const Thing = struct { n: i32 };
451456 var a = false;
452457 var b = false;
458 _ = .{ &a, &b };
453459
454 var result1 = if (a)
460 const result1 = if (a)
455461 Thing{ .n = 1 }
456462 else
457463 null;
458464 try expect(result1 == null);
459465 try expect(@TypeOf(result1) == ?Thing);
460466
461 var result2 = if (a)
467 const result2 = if (a)
462468 Thing{ .n = 0 }
463469 else if (b)
464470 Thing{ .n = 1 }
......@@ -486,5 +492,6 @@ test "cast slice to const slice nested in error union and optional" {
486492
487493test "variable of optional of noreturn" {
488494 var null_opv: ?noreturn = null;
495 _ = &null_opv;
489496 try std.testing.expectEqual(@as(?noreturn, null), null_opv);
490497}
test/behavior/packed-struct.zig+10-5
......@@ -479,10 +479,9 @@ test "load pointer from packed struct" {
479479 y: u32,
480480 };
481481 var a: A = .{ .index = 123 };
482 var b_list: []const B = &.{.{ .x = &a, .y = 99 }};
482 const b_list: []const B = &.{.{ .x = &a, .y = 99 }};
483483 for (b_list) |b| {
484 var i = b.x.index;
485 try expect(i == 123);
484 try expect(b.x.index == 123);
486485 }
487486}
488487
......@@ -770,6 +769,7 @@ test "nested packed struct field access test" {
770769 };
771770
772771 var arg = a{ .b = hld{ .c = 1, .d = 2 }, .g = mld{ .h = 6, .i = 8 } };
772 _ = &arg;
773773 try std.testing.expect(arg.b.c == 1);
774774 try std.testing.expect(arg.b.d == 2);
775775 try std.testing.expect(arg.g.h == 6);
......@@ -790,6 +790,7 @@ test "nested packed struct at non-zero offset" {
790790 };
791791
792792 var k: u8 = 123;
793 _ = &k;
793794 var v: A = .{
794795 .p1 = .{ .a = k + 1, .b = k },
795796 .p2 = .{ .a = k + 1, .b = k },
......@@ -833,6 +834,7 @@ test "nested packed struct at non-zero offset 2" {
833834
834835 fn doTheTest() !void {
835836 var k: u8 = 123;
837 _ = &k;
836838 var v: A = .{
837839 .p1 = .{ .a = k + 1, .b = k },
838840 .p2 = .{ .a = k + 1, .b = k },
......@@ -877,6 +879,7 @@ test "runtime init of unnamed packed struct type" {
877879 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
878880
879881 var z: u8 = 123;
882 _ = &z;
880883 try (packed struct {
881884 x: u8,
882885 pub fn m(s: @This()) !void {
......@@ -941,6 +944,7 @@ test "packed struct initialized in bitcast" {
941944
942945 const T = packed struct { val: u8 };
943946 var val: u8 = 123;
947 _ = &val;
944948 const t = @as(u8, @bitCast(T{ .val = val }));
945949 try expect(t == val);
946950}
......@@ -976,7 +980,8 @@ test "store undefined to packed result location" {
976980 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
977981
978982 var x: u4 = 0;
979 var s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined };
983 _ = &x;
984 const s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined };
980985 try expectEqual(x, s.x);
981986}
982987
......@@ -1004,7 +1009,7 @@ test "field access of packed struct smaller than its abi size inside struct init
10041009 }
10051010 };
10061011
1007 var s = S.init(true);
1012 const s = S.init(true);
10081013 // note: this bug is triggered by the == operator, expectEqual will hide it
10091014 try expect(@as(i2, 0) == s.ps.x);
10101015 try expect(@as(i2, 1) == s.ps.y);
test/behavior/pointers.zig+37-23
......@@ -11,7 +11,7 @@ test "dereference pointer" {
1111
1212fn testDerefPtr() !void {
1313 var x: i32 = 1234;
14 var y = &x;
14 const y = &x;
1515 y.* += 1;
1616 try expect(x == 1235);
1717}
......@@ -53,8 +53,8 @@ test "implicit cast single item pointer to C pointer and back" {
5353 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
5454
5555 var y: u8 = 11;
56 var x: [*c]u8 = &y;
57 var z: *u8 = x;
56 const x: [*c]u8 = &y;
57 const z: *u8 = x;
5858 z.* += 1;
5959 try expect(y == 12);
6060}
......@@ -74,6 +74,7 @@ test "assigning integer to C pointer" {
7474 var ptr2: [*c]u8 = x;
7575 var ptr3: [*c]u8 = 1;
7676 var ptr4: [*c]u8 = y;
77 _ = .{ &x, &y, &ptr, &ptr2, &ptr3, &ptr4 };
7778
7879 try expect(ptr == ptr2);
7980 try expect(ptr3 == ptr4);
......@@ -88,6 +89,7 @@ test "C pointer comparison and arithmetic" {
8889 fn doTheTest() !void {
8990 var ptr1: [*c]u32 = 0;
9091 var ptr2 = ptr1 + 10;
92 _ = &ptr1;
9193 try expect(ptr1 == 0);
9294 try expect(ptr1 >= 0);
9395 try expect(ptr1 <= 0);
......@@ -125,14 +127,15 @@ fn testDerefPtrOneVal() !void {
125127}
126128
127129test "peer type resolution with C pointers" {
128 var ptr_one: *u8 = undefined;
129 var ptr_many: [*]u8 = undefined;
130 var ptr_c: [*c]u8 = undefined;
130 const ptr_one: *u8 = undefined;
131 const ptr_many: [*]u8 = undefined;
132 const ptr_c: [*c]u8 = undefined;
131133 var t = true;
132 var x1 = if (t) ptr_one else ptr_c;
133 var x2 = if (t) ptr_many else ptr_c;
134 var x3 = if (t) ptr_c else ptr_one;
135 var x4 = if (t) ptr_c else ptr_many;
134 _ = &t;
135 const x1 = if (t) ptr_one else ptr_c;
136 const x2 = if (t) ptr_many else ptr_c;
137 const x3 = if (t) ptr_c else ptr_one;
138 const x4 = if (t) ptr_c else ptr_many;
136139 try expect(@TypeOf(x1) == [*c]u8);
137140 try expect(@TypeOf(x2) == [*c]u8);
138141 try expect(@TypeOf(x3) == [*c]u8);
......@@ -141,8 +144,9 @@ test "peer type resolution with C pointers" {
141144
142145test "peer type resolution with C pointer and const pointer" {
143146 var ptr_c: [*c]u8 = undefined;
144 const ptr_const: u8 = undefined;
145 try expect(@TypeOf(ptr_c, &ptr_const) == [*c]const u8);
147 var ptr_const: *const u8 = &undefined;
148 _ = .{ &ptr_c, &ptr_const };
149 try expect(@TypeOf(ptr_c, ptr_const) == [*c]const u8);
146150}
147151
148152test "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" {
151155 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
152156
153157 var slice: []const u8 = "aoeu";
158 _ = &slice;
154159 const opt_many_ptr: ?[*]const u8 = slice.ptr;
155160 var ptr_opt_many_ptr = &opt_many_ptr;
156 var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
161 const c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
157162 try expect(c_ptr.*.* == 'a');
158163 ptr_opt_many_ptr = c_ptr;
159164 try expect(ptr_opt_many_ptr.*.?[1] == 'o');
......@@ -192,11 +197,12 @@ test "allowzero pointer and slice" {
192197 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
193198 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
194199
195 var ptr = @as([*]allowzero i32, @ptrFromInt(0));
196 var opt_ptr: ?[*]allowzero i32 = ptr;
200 var ptr: [*]allowzero i32 = @ptrFromInt(0);
201 const opt_ptr: ?[*]allowzero i32 = ptr;
197202 try expect(opt_ptr != null);
198203 try expect(@intFromPtr(ptr) == 0);
199204 var runtime_zero: usize = 0;
205 _ = &runtime_zero;
200206 var slice = ptr[runtime_zero..10];
201207 try comptime expect(@TypeOf(slice) == []allowzero i32);
202208 try expect(@intFromPtr(&slice[5]) == 20);
......@@ -211,6 +217,7 @@ test "assign null directly to C pointer and test null equality" {
211217 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
212218
213219 var x: [*c]i32 = null;
220 _ = &x;
214221 try expect(x == null);
215222 try expect(null == x);
216223 try expect(!(x != null));
......@@ -236,7 +243,7 @@ test "assign null directly to C pointer and test null equality" {
236243 try comptime expect((y orelse ptr_othery) == ptr_othery);
237244
238245 var n: i32 = 1234;
239 var x1: [*c]i32 = &n;
246 const x1: [*c]i32 = &n;
240247 try expect(!(x1 == null));
241248 try expect(!(null == x1));
242249 try expect(x1 != null);
......@@ -279,9 +286,9 @@ test "null terminated pointer" {
279286 const S = struct {
280287 fn doTheTest() !void {
281288 var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' };
282 var zero_ptr: [*:0]const u8 = @as([*:0]const u8, @ptrCast(&array_with_zero));
283 var no_zero_ptr: [*]const u8 = zero_ptr;
284 var zero_ptr_again = @as([*:0]const u8, @ptrCast(no_zero_ptr));
289 const zero_ptr: [*:0]const u8 = @ptrCast(&array_with_zero);
290 const no_zero_ptr: [*]const u8 = zero_ptr;
291 const zero_ptr_again: [*:0]const u8 = @ptrCast(no_zero_ptr);
285292 try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello"));
286293 }
287294 };
......@@ -296,7 +303,7 @@ test "allow any sentinel" {
296303 const S = struct {
297304 fn doTheTest() !void {
298305 var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 };
299 var ptr: [*:std.math.minInt(i32)]i32 = &array;
306 const ptr: [*:std.math.minInt(i32)]i32 = &array;
300307 try expect(ptr[4] == std.math.minInt(i32));
301308 }
302309 };
......@@ -317,6 +324,7 @@ test "pointer sentinel with enums" {
317324
318325 fn doTheTest() !void {
319326 var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one };
327 _ = &ptr;
320328 try expect(ptr[4] == .sentinel); // TODO this should be try comptime expect, see #3731
321329 }
322330 };
......@@ -332,6 +340,7 @@ test "pointer sentinel with optional element" {
332340 const S = struct {
333341 fn doTheTest() !void {
334342 var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 };
343 _ = &ptr;
335344 try expect(ptr[4] == null); // TODO this should be try comptime expect, see #3731
336345 }
337346 };
......@@ -348,6 +357,7 @@ test "pointer sentinel with +inf" {
348357 fn doTheTest() !void {
349358 const inf_f32 = comptime std.math.inf(f32);
350359 var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 };
360 _ = &ptr;
351361 try expect(ptr[4] == inf_f32); // TODO this should be try comptime expect, see #3731
352362 }
353363 };
......@@ -366,6 +376,7 @@ test "pointer arithmetic affects the alignment" {
366376 {
367377 var ptr: [*]align(8) u32 = undefined;
368378 var x: usize = 1;
379 _ = .{ &ptr, &x };
369380
370381 try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8);
371382 const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4
......@@ -380,6 +391,7 @@ test "pointer arithmetic affects the alignment" {
380391 {
381392 var ptr: [*]align(8) [3]u8 = undefined;
382393 var x: usize = 1;
394 _ = .{ &ptr, &x };
383395
384396 const ptr1 = ptr + 17; // 3 * 17 = 51
385397 try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1);
......@@ -467,8 +479,8 @@ test "array slicing to slice" {
467479 const S = struct {
468480 fn doTheTest() !void {
469481 var str: [5]i32 = [_]i32{ 1, 2, 3, 4, 5 };
470 var sub: *[2]i32 = str[1..3];
471 var slice: []i32 = sub; // used to cause failures
482 const sub: *[2]i32 = str[1..3];
483 const slice: []i32 = sub; // used to cause failures
472484 try testing.expect(slice.len == 2);
473485 try testing.expect(slice[0] == 2);
474486 }
......@@ -495,7 +507,8 @@ test "ptrCast comptime known slice to C pointer" {
495507 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
496508
497509 const s: [:0]const u8 = "foo";
498 var p = @as([*c]const u8, @ptrCast(s));
510 var p: [*c]const u8 = @ptrCast(s);
511 _ = &p;
499512 try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0));
500513}
501514
......@@ -527,6 +540,7 @@ test "pointer to array has explicit alignment" {
527540test "result type preserved through multiple references" {
528541 const S = struct { x: u32 };
529542 var my_u64: u64 = 12345;
543 _ = &my_u64;
530544 const foo: *const *const *const S = &&&.{
531545 .x = @intCast(my_u64),
532546 };
test/behavior/popcount.zig+10
......@@ -26,6 +26,7 @@ test "@popCount 128bit integer" {
2626
2727 {
2828 var x: u128 = 0b11111111000110001100010000100001000011000011100101010001;
29 _ = &x;
2930 try expect(@popCount(x) == 24);
3031 }
3132
......@@ -35,30 +36,37 @@ test "@popCount 128bit integer" {
3536fn testPopCountIntegers() !void {
3637 {
3738 var x: u32 = 0xffffffff;
39 _ = &x;
3840 try expect(@popCount(x) == 32);
3941 }
4042 {
4143 var x: u5 = 0x1f;
44 _ = &x;
4245 try expect(@popCount(x) == 5);
4346 }
4447 {
4548 var x: u32 = 0xaa;
49 _ = &x;
4650 try expect(@popCount(x) == 4);
4751 }
4852 {
4953 var x: u32 = 0xaaaaaaaa;
54 _ = &x;
5055 try expect(@popCount(x) == 16);
5156 }
5257 {
5358 var x: u32 = 0xaaaaaaaa;
59 _ = &x;
5460 try expect(@popCount(x) == 16);
5561 }
5662 {
5763 var x: i16 = -1;
64 _ = &x;
5865 try expect(@popCount(x) == 16);
5966 }
6067 {
6168 var x: i8 = -120;
69 _ = &x;
6270 try expect(@popCount(x) == 2);
6371 }
6472 comptime {
......@@ -81,12 +89,14 @@ test "@popCount vectors" {
8189fn testPopCountVectors() !void {
8290 {
8391 var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8;
92 _ = &x;
8493 const expected = [1]u6{32} ** 8;
8594 const result: [8]u6 = @popCount(x);
8695 try expect(std.mem.eql(u6, &expected, &result));
8796 }
8897 {
8998 var x: @Vector(8, i16) = [1]i16{-1} ** 8;
99 _ = &x;
90100 const expected = [1]u5{16} ** 8;
91101 const result: [8]u5 = @popCount(x);
92102 try expect(std.mem.eql(u5, &expected, &result));
test/behavior/prefetch.zig+1
......@@ -6,6 +6,7 @@ test "@prefetch()" {
66
77 var a: [2]u32 = .{ 42, 42 };
88 var a_len = a.len;
9 _ = &a_len;
910
1011 @prefetch(&a, .{});
1112
test/behavior/ptrcast.zig+14-14
......@@ -71,8 +71,8 @@ fn testReinterpretBytesAsExternStruct() !void {
7171 c: u8,
7272 };
7373
74 var ptr = @as(*const S, @ptrCast(&bytes));
75 var val = ptr.c;
74 const ptr: *const S = @ptrCast(&bytes);
75 const val = ptr.c;
7676 try expect(val == 5);
7777}
7878
......@@ -95,8 +95,8 @@ fn testReinterpretExternStructAsExternStruct() !void {
9595 a: u32 align(2),
9696 c: u8,
9797 };
98 var ptr = @as(*const S2, @ptrCast(&bytes));
99 var val = ptr.c;
98 const ptr: *const S2 = @ptrCast(&bytes);
99 const val = ptr.c;
100100 try expect(val == 5);
101101}
102102
......@@ -121,8 +121,8 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void {
121121 a2: u16,
122122 c: u8,
123123 };
124 var ptr = @as(*const S2, @ptrCast(&bytes));
125 var val = ptr.c;
124 const ptr: *const S2 = @ptrCast(&bytes);
125 const val = ptr.c;
126126 try expect(val == 5);
127127}
128128
......@@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" {
138138 c: u8,
139139 };
140140 comptime var ptr = @as(*const S, @ptrCast(&bytes));
141 var val = &ptr.c;
141 const val = &ptr.c;
142142 try expect(val.* == 5);
143143
144144 // Test lowering an elem ptr
145145 comptime var src_value = S{ .a = 15, .c = 5 };
146146 comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value));
147 var val2 = &ptr2[4];
147 const val2 = &ptr2[4];
148148 try expect(val2.* == 5);
149149}
150150
......@@ -160,13 +160,13 @@ test "lower reinterpreted comptime field ptr" {
160160 c: u8,
161161 };
162162 comptime var ptr = @as(*const S, @ptrCast(&bytes));
163 var val = &ptr.c;
163 const val = &ptr.c;
164164 try expect(val.* == 5);
165165
166166 // Test lowering an elem ptr
167167 comptime var src_value = S{ .a = 15, .c = 5 };
168168 comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value));
169 var val2 = &ptr2[4];
169 const val2 = &ptr2[4];
170170 try expect(val2.* == 5);
171171}
172172
......@@ -233,9 +233,9 @@ test "implicit optional pointer to optional anyopaque pointer" {
233233 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
234234
235235 var buf: [4]u8 = "aoeu".*;
236 var x: ?[*]u8 = &buf;
237 var y: ?*anyopaque = x;
238 var z = @as(*[4]u8, @ptrCast(y));
236 const x: ?[*]u8 = &buf;
237 const y: ?*anyopaque = x;
238 const z: *[4]u8 = @ptrCast(y);
239239 try expect(std.mem.eql(u8, z, "aoeu"));
240240}
241241
......@@ -276,7 +276,7 @@ test "@ptrCast undefined value at comptime" {
276276 }
277277 };
278278 comptime {
279 var x = S.transmute([]u8, i32, undefined);
279 const x = S.transmute([]u8, i32, undefined);
280280 _ = x;
281281 }
282282}
test/behavior/ptrfromint.zig+1
......@@ -9,6 +9,7 @@ test "casting integer address to function pointer" {
99
1010fn addressToFunction() void {
1111 var addr: usize = 0xdeadbee0;
12 _ = &addr;
1213 _ = @as(*const fn () void, @ptrFromInt(addr));
1314}
1415
test/behavior/saturating_arithmetic.zig+2
......@@ -246,9 +246,11 @@ test "saturating shl uses the LHS type" {
246246
247247 const lhs_const: u8 = 1;
248248 var lhs_var: u8 = 1;
249 _ = &lhs_var;
249250
250251 const rhs_const: usize = 8;
251252 var rhs_var: usize = 8;
253 _ = &rhs_var;
252254
253255 try expect((lhs_const <<| 8) == 255);
254256 try expect((lhs_const <<| rhs_const) == 255);
test/behavior/select.zig+8-4
......@@ -19,7 +19,8 @@ fn selectVectors() !void {
1919 var a = @Vector(4, bool){ true, false, true, false };
2020 var b = @Vector(4, i32){ -1, 4, 999, -31 };
2121 var c = @Vector(4, i32){ -5, 1, 0, 1234 };
22 var abc = @select(i32, a, b, c);
22 _ = .{ &a, &b, &c };
23 const abc = @select(i32, a, b, c);
2324 try expect(abc[0] == -1);
2425 try expect(abc[1] == 1);
2526 try expect(abc[2] == 999);
......@@ -28,7 +29,8 @@ fn selectVectors() !void {
2829 var x = @Vector(4, bool){ false, false, false, true };
2930 var y = @Vector(4, f32){ 0.001, 33.4, 836, -3381.233 };
3031 var z = @Vector(4, f32){ 0.0, 312.1, -145.9, 9993.55 };
31 var xyz = @select(f32, x, y, z);
32 _ = .{ &x, &y, &z };
33 const xyz = @select(f32, x, y, z);
3234 try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 }));
3335}
3436
......@@ -48,7 +50,8 @@ fn selectArrays() !void {
4850 var a = [4]bool{ false, true, false, true };
4951 var b = [4]usize{ 0, 1, 2, 3 };
5052 var c = [4]usize{ 4, 5, 6, 7 };
51 var abc = @select(usize, a, b, c);
53 _ = .{ &a, &b, &c };
54 const abc = @select(usize, a, b, c);
5255 try expect(abc[0] == 4);
5356 try expect(abc[1] == 1);
5457 try expect(abc[2] == 6);
......@@ -57,6 +60,7 @@ fn selectArrays() !void {
5760 var x = [4]bool{ false, false, false, true };
5861 var y = [4]f32{ 0.001, 33.4, 836, -3381.233 };
5962 var z = [4]f32{ 0.0, 312.1, -145.9, 9993.55 };
60 var xyz = @select(f32, x, y, z);
63 _ = .{ &x, &y, &z };
64 const xyz = @select(f32, x, y, z);
6165 try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 }));
6266}
test/behavior/shuffle.zig+10-2
......@@ -13,7 +13,9 @@ test "@shuffle int" {
1313 const S = struct {
1414 fn doTheTest() !void {
1515 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
16 _ = &v;
1617 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
18 _ = &x;
1719 const mask = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
1820 var res = @shuffle(i32, v, x, mask);
1921 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
......@@ -29,12 +31,14 @@ test "@shuffle int" {
2931
3032 // Upcasting of b
3133 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };
34 _ = &v2;
3235 const mask3 = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
3336 res = @shuffle(i32, x, v2, mask3);
3437 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 }));
3538
3639 // Upcasting of a
3740 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };
41 _ = &v3;
3842 const mask4 = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
3943 res = @shuffle(i32, v3, x, mask4);
4044 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 }));
......@@ -55,9 +59,11 @@ test "@shuffle bool 1" {
5559 const S = struct {
5660 fn doTheTest() !void {
5761 var x: @Vector(4, bool) = [4]bool{ false, true, false, true };
62 _ = &x;
5863 var v: @Vector(2, bool) = [2]bool{ true, false };
64 _ = &v;
5965 const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
60 var res = @shuffle(bool, x, v, mask);
66 const res = @shuffle(bool, x, v, mask);
6167 try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false }));
6268 }
6369 };
......@@ -81,9 +87,11 @@ test "@shuffle bool 2" {
8187 const S = struct {
8288 fn doTheTest() !void {
8389 var x: @Vector(3, bool) = [3]bool{ false, true, false };
90 _ = &x;
8491 var v: @Vector(2, bool) = [2]bool{ true, false };
92 _ = &v;
8593 const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
86 var res = @shuffle(bool, x, v, mask);
94 const res = @shuffle(bool, x, v, mask);
8795 try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false }));
8896 }
8997 };
test/behavior/sizeof_and_typeof.zig+6
......@@ -22,20 +22,24 @@ test "@TypeOf() with multiple arguments" {
2222 var var_1: u32 = undefined;
2323 var var_2: u8 = undefined;
2424 var var_3: u64 = undefined;
25 _ = .{ &var_1, &var_2, &var_3 };
2526 try comptime expect(@TypeOf(var_1, var_2, var_3) == u64);
2627 }
2728 {
2829 var var_1: f16 = undefined;
2930 var var_2: f32 = undefined;
3031 var var_3: f64 = undefined;
32 _ = .{ &var_1, &var_2, &var_3 };
3133 try comptime expect(@TypeOf(var_1, var_2, var_3) == f64);
3234 }
3335 {
3436 var var_1: u16 = undefined;
37 _ = &var_1;
3538 try comptime expect(@TypeOf(var_1, 0xffff) == u16);
3639 }
3740 {
3841 var var_1: f32 = undefined;
42 _ = &var_1;
3943 try comptime expect(@TypeOf(var_1, 3.1415) == f32);
4044 }
4145}
......@@ -269,6 +273,7 @@ test "runtime instructions inside typeof in comptime only scope" {
269273
270274 {
271275 var y: i8 = 2;
276 _ = &y;
272277 const i: [2]i8 = [_]i8{ 1, y };
273278 const T = struct {
274279 a: @TypeOf(i) = undefined, // causes crash
......@@ -279,6 +284,7 @@ test "runtime instructions inside typeof in comptime only scope" {
279284 }
280285 {
281286 var y: i8 = 2;
287 _ = &y;
282288 const i = .{ 1, y };
283289 const T = struct {
284290 b: @TypeOf(i[1]) = undefined,
test/behavior/slice.zig+44-32
......@@ -23,7 +23,7 @@ comptime {
2323 };
2424 const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong };
2525 const list: []const type = &unsigned;
26 var pos = S.indexOfScalar(type, list, c_ulong).?;
26 const pos = S.indexOfScalar(type, list, c_ulong).?;
2727 if (pos != 1) @compileError("bad pos");
2828}
2929
......@@ -36,13 +36,14 @@ test "slicing" {
3636
3737 var slice = array[5..10];
3838
39 if (slice.len != 5) unreachable;
39 try expect(slice.len == 5);
4040
4141 const ptr = &slice[0];
42 if (ptr.* != 1234) unreachable;
42 try expect(ptr.* == 1234);
4343
4444 var slice_rest = array[10..];
45 if (slice_rest.len != 10) unreachable;
45 _ = &slice_rest;
46 try expect(slice_rest.len == 10);
4647}
4748
4849test "const slice" {
......@@ -79,7 +80,7 @@ test "access len index of sentinel-terminated slice" {
7980 const S = struct {
8081 fn doTheTest() !void {
8182 var slice: [:0]const u8 = "hello";
82
83 _ = &slice;
8384 try expect(slice.len == 5);
8485 try expect(slice[5] == 0);
8586 }
......@@ -208,6 +209,7 @@ test "slice string literal has correct type" {
208209 try expect(@TypeOf(array[0..]) == *const [4]i32);
209210 }
210211 var runtime_zero: usize = 0;
212 _ = &runtime_zero;
211213 try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8);
212214 const array = [_]i32{ 1, 2, 3, 4 };
213215 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
219221 const E = struct {
220222 entries: []u32,
221223 };
222 var foo = E{ .entries = &[_]u32{} };
224 var foo: E = .{ .entries = &[_]u32{} };
225 _ = &foo;
223226 try expect(foo.entries.len == 0);
224227}
225228
......@@ -242,7 +245,8 @@ test "C pointer" {
242245
243246 var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf";
244247 var len: u32 = 10;
245 var slice = buf[0..len];
248 _ = &len;
249 const slice = buf[0..len];
246250 try expect(mem.eql(u8, "kjdhfkjdhf", slice));
247251}
248252
......@@ -255,6 +259,7 @@ test "C pointer slice access" {
255259 const c_ptr = @as([*c]const u32, @ptrCast(&buf));
256260
257261 var runtime_zero: usize = 0;
262 _ = &runtime_zero;
258263 try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));
259264 try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1]));
260265
......@@ -306,11 +311,13 @@ test "obtaining a null terminated slice" {
306311 _ = ptr;
307312
308313 var runtime_len: usize = 3;
314 _ = &runtime_len;
309315 const ptr2 = buf[0..runtime_len :0];
310316 // ptr2 is a null-terminated slice
311317 try comptime expect(@TypeOf(ptr2) == [:0]u8);
312318 try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8);
313319 var runtime_zero: usize = 0;
320 _ = &runtime_zero;
314321 try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8);
315322}
316323
......@@ -338,8 +345,8 @@ test "@ptrCast slice to pointer" {
338345 const S = struct {
339346 fn doTheTest() !void {
340347 var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff };
341 var slice: []align(@alignOf(u16)) u8 = &array;
342 var ptr = @as(*u16, @ptrCast(slice));
348 const slice: []align(@alignOf(u16)) u8 = &array;
349 const ptr: *u16 = @ptrCast(slice);
343350 try expect(ptr.* == 65535);
344351 }
345352 };
......@@ -357,8 +364,8 @@ test "slice multi-pointer without end" {
357364
358365 fn testPointer() !void {
359366 var array = [5]u8{ 1, 2, 3, 4, 5 };
360 var pointer: [*]u8 = &array;
361 var slice = pointer[1..];
367 const pointer: [*]u8 = &array;
368 const slice = pointer[1..];
362369 try comptime expect(@TypeOf(slice) == [*]u8);
363370 try expect(slice[0] == 2);
364371 try expect(slice[1] == 3);
......@@ -366,13 +373,13 @@ test "slice multi-pointer without end" {
366373
367374 fn testPointerZ() !void {
368375 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
369 var pointer: [*:0]u8 = &array;
376 const pointer: [*:0]u8 = &array;
370377
371378 try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8);
372379 try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
373380 try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8);
374381
375 var slice = pointer[1..];
382 const slice = pointer[1..];
376383 try comptime expect(@TypeOf(slice) == [*:0]u8);
377384 try expect(slice[0] == 2);
378385 try expect(slice[1] == 3);
......@@ -413,7 +420,7 @@ test "slice syntax resulting in pointer-to-array" {
413420
414421 fn testArray() !void {
415422 var array = [5]u8{ 1, 2, 3, 4, 5 };
416 var slice = array[1..3];
423 const slice = array[1..3];
417424 try comptime expect(@TypeOf(slice) == *[2]u8);
418425 try expect(slice[0] == 2);
419426 try expect(slice[1] == 3);
......@@ -430,12 +437,12 @@ test "slice syntax resulting in pointer-to-array" {
430437 fn testArray0() !void {
431438 {
432439 var array = [0]u8{};
433 var slice = array[0..0];
440 const slice = array[0..0];
434441 try comptime expect(@TypeOf(slice) == *[0]u8);
435442 }
436443 {
437444 var array = [0:0]u8{};
438 var slice = array[0..0];
445 const slice = array[0..0];
439446 try comptime expect(@TypeOf(slice) == *[0:0]u8);
440447 try expect(slice[0] == 0);
441448 }
......@@ -443,7 +450,7 @@ test "slice syntax resulting in pointer-to-array" {
443450
444451 fn testArrayAlign() !void {
445452 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
446 var slice = array[4..5];
453 const slice = array[4..5];
447454 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);
448455 try expect(slice[0] == 5);
449456 try comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8);
......@@ -452,7 +459,7 @@ test "slice syntax resulting in pointer-to-array" {
452459 fn testPointer() !void {
453460 var array = [5]u8{ 1, 2, 3, 4, 5 };
454461 var pointer: [*]u8 = &array;
455 var slice = pointer[1..3];
462 const slice = pointer[1..3];
456463 try comptime expect(@TypeOf(slice) == *[2]u8);
457464 try expect(slice[0] == 2);
458465 try expect(slice[1] == 3);
......@@ -467,7 +474,7 @@ test "slice syntax resulting in pointer-to-array" {
467474
468475 fn testPointer0() !void {
469476 var pointer: [*]const u0 = &[1]u0{0};
470 var slice = pointer[0..1];
477 const slice = pointer[0..1];
471478 try comptime expect(@TypeOf(slice) == *const [1]u0);
472479 try expect(slice[0] == 0);
473480 }
......@@ -475,7 +482,7 @@ test "slice syntax resulting in pointer-to-array" {
475482 fn testPointerAlign() !void {
476483 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
477484 var pointer: [*]align(4) u8 = &array;
478 var slice = pointer[4..5];
485 const slice = pointer[4..5];
479486 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);
480487 try expect(slice[0] == 5);
481488 try comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8);
......@@ -484,7 +491,7 @@ test "slice syntax resulting in pointer-to-array" {
484491 fn testSlice() !void {
485492 var array = [5]u8{ 1, 2, 3, 4, 5 };
486493 var src_slice: []u8 = &array;
487 var slice = src_slice[1..3];
494 const slice = src_slice[1..3];
488495 try comptime expect(@TypeOf(slice) == *[2]u8);
489496 try expect(slice[0] == 2);
490497 try expect(slice[1] == 3);
......@@ -513,7 +520,7 @@ test "slice syntax resulting in pointer-to-array" {
513520 fn testSliceAlign() !void {
514521 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
515522 var src_slice: []align(4) u8 = &array;
516 var slice = src_slice[4..5];
523 const slice = src_slice[4..5];
517524 try comptime expect(@TypeOf(slice) == *align(4) [1]u8);
518525 try expect(slice[0] == 5);
519526 try comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8);
......@@ -616,13 +623,13 @@ test "slice pointer-to-array zero length" {
616623 {
617624 var array = [0]u8{};
618625 var src_slice: []u8 = &array;
619 var slice = src_slice[0..0];
626 const slice = src_slice[0..0];
620627 try expect(@TypeOf(slice) == *[0]u8);
621628 }
622629 {
623630 var array = [0:0]u8{};
624631 var src_slice: [:0]u8 = &array;
625 var slice = src_slice[0..0];
632 const slice = src_slice[0..0];
626633 try expect(@TypeOf(slice) == *[0:0]u8);
627634 }
628635 }
......@@ -630,13 +637,13 @@ test "slice pointer-to-array zero length" {
630637 {
631638 var array = [0]u8{};
632639 var src_slice: []u8 = &array;
633 var slice = src_slice[0..0];
640 const slice = src_slice[0..0];
634641 try comptime expect(@TypeOf(slice) == *[0]u8);
635642 }
636643 {
637644 var array = [0:0]u8{};
638645 var src_slice: [:0]u8 = &array;
639 var slice = src_slice[0..0];
646 const slice = src_slice[0..0];
640647 try comptime expect(@TypeOf(slice) == *[0]u8);
641648 }
642649}
......@@ -655,17 +662,19 @@ test "type coercion of pointer to anon struct literal to pointer to slice" {
655662
656663 fn doTheTest() !void {
657664 var x1: u8 = 42;
665 _ = &x1;
658666 const t1 = &.{ x1, 56, 54 };
659 var slice1: []const u8 = t1;
667 const slice1: []const u8 = t1;
660668 try expect(slice1.len == 3);
661669 try expect(slice1[0] == 42);
662670 try expect(slice1[1] == 56);
663671 try expect(slice1[2] == 54);
664672
665673 var x2: []const u8 = "hello";
674 _ = &x2;
666675 const t2 = &.{ x2, ", ", "world!" };
667676 // @compileLog(@TypeOf(t2));
668 var slice2: []const []const u8 = t2;
677 const slice2: []const []const u8 = t2;
669678 try expect(slice2.len == 3);
670679 try expect(mem.eql(u8, slice2[0], "hello"));
671680 try expect(mem.eql(u8, slice2[1], ", "));
......@@ -680,6 +689,7 @@ test "array concat of slices gives ptr to array" {
680689 comptime {
681690 var a: []const u8 = "aoeu";
682691 var b: []const u8 = "asdf";
692 _ = .{ &a, &b };
683693 const c = a ++ b;
684694 try expect(std.mem.eql(u8, c, "aoeuasdf"));
685695 try expect(@TypeOf(c) == *const [8]u8);
......@@ -689,6 +699,7 @@ test "array concat of slices gives ptr to array" {
689699test "array mult of slice gives ptr to array" {
690700 comptime {
691701 var a: []const u8 = "aoeu";
702 _ = &a;
692703 const c = a ** 2;
693704 try expect(std.mem.eql(u8, c, "aoeuaoeu"));
694705 try expect(@TypeOf(c) == *const [8]u8);
......@@ -736,7 +747,7 @@ test "slicing array with sentinel as end index" {
736747 const S = struct {
737748 fn do() !void {
738749 var array = [_:0]u8{ 1, 2, 3, 4 };
739 var slice = array[4..5];
750 const slice = array[4..5];
740751 try expect(slice.len == 1);
741752 try expect(slice[0] == 0);
742753 try expect(@TypeOf(slice) == *[1]u8);
......@@ -754,8 +765,8 @@ test "slicing slice with sentinel as end index" {
754765 const S = struct {
755766 fn do() !void {
756767 var array = [_:0]u8{ 1, 2, 3, 4 };
757 var src_slice: [:0]u8 = &array;
758 var slice = src_slice[4..5];
768 const src_slice: [:0]u8 = &array;
769 const slice = src_slice[4..5];
759770 try expect(slice.len == 1);
760771 try expect(slice[0] == 0);
761772 try expect(@TypeOf(slice) == *[1]u8);
......@@ -820,6 +831,7 @@ test "global slice field access" {
820831
821832test "slice of void" {
822833 var n: usize = 10;
834 _ = &n;
823835 var arr: [12]void = undefined;
824836 const slice = @as([]void, &arr)[0..n];
825837 try expect(slice.len == n);
......@@ -827,7 +839,7 @@ test "slice of void" {
827839
828840test "slice with dereferenced value" {
829841 var a: usize = 0;
830 var idx: *usize = &a;
842 const idx: *usize = &a;
831843 _ = blk: {
832844 var array = [_]u8{};
833845 break :blk array[idx.*..];
test/behavior/struct.zig+44-21
......@@ -254,7 +254,8 @@ test "struct field init with catch" {
254254 const S = struct {
255255 fn doTheTest() !void {
256256 var x: anyerror!isize = 1;
257 var req = Foo{
257 _ = &x;
258 const req = Foo{
258259 .field = x catch undefined,
259260 };
260261 try expect(req.field == 1);
......@@ -505,7 +506,7 @@ test "packed struct fields are ordered from LSB to MSB" {
505506 var all: u64 = 0x7765443322221111;
506507 var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined;
507508 @memcpy(bytes[0..8], @as([*]u8, @ptrCast(&all)));
508 var bitfields = @as(*Bitfields, @ptrCast(&bytes)).*;
509 const bitfields = @as(*Bitfields, @ptrCast(&bytes)).*;
509510
510511 try expect(bitfields.f1 == 0x1111);
511512 try expect(bitfields.f2 == 0x2222);
......@@ -545,7 +546,7 @@ test "zero-bit field in packed struct" {
545546 y: void,
546547 };
547548 var x: S = undefined;
548 _ = x;
549 _ = &x;
549550}
550551
551552test "packed struct with non-ABI-aligned field" {
......@@ -624,6 +625,7 @@ test "default struct initialization fields" {
624625 .b = 5,
625626 };
626627 var five: i32 = 5;
628 _ = &five;
627629 const y = S{
628630 .b = five,
629631 };
......@@ -714,7 +716,7 @@ test "pointer to packed struct member in a stack variable" {
714716 };
715717
716718 var s = S{ .a = 2, .b = 0 };
717 var b_ptr = &s.b;
719 const b_ptr = &s.b;
718720 try expect(s.b == 0);
719721 b_ptr.* = 2;
720722 try expect(s.b == 2);
......@@ -727,6 +729,7 @@ test "packed struct with u0 field access" {
727729 f0: u0,
728730 };
729731 var s = S{ .f0 = 0 };
732 _ = &s;
730733 try comptime expect(s.f0 == 0);
731734}
732735
......@@ -788,7 +791,7 @@ test "fn with C calling convention returns struct by value" {
788791
789792 const S = struct {
790793 fn entry() !void {
791 var x = makeBar(10);
794 const x = makeBar(10);
792795 try expect(@as(i32, 10) == x.handle);
793796 }
794797
......@@ -827,6 +830,7 @@ test "non-packed struct with u128 entry in union" {
827830 var s = &sx;
828831 try expect(@intFromPtr(&s.f2) - @intFromPtr(&s.f1) == @offsetOf(S, "f2"));
829832 var v2 = U{ .Num = 123 };
833 _ = &v2;
830834 s.f2 = v2;
831835 try expect(s.f2.Num == 123);
832836}
......@@ -852,7 +856,7 @@ test "packed struct field passed to generic function" {
852856
853857 var p: S.P = undefined;
854858 p.b = 29;
855 var loaded = S.genericReadPackedField(&p.b);
859 const loaded = S.genericReadPackedField(&p.b);
856860 try expect(loaded == 29);
857861}
858862
......@@ -871,6 +875,7 @@ test "anonymous struct literal syntax" {
871875 .x = 1,
872876 .y = 2,
873877 };
878 _ = &p;
874879 try expect(p.x == 1);
875880 try expect(p.y == 2);
876881 }
......@@ -920,6 +925,7 @@ test "fully anonymous list literal" {
920925
921926test "tuple assigned to variable" {
922927 var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) };
928 _ = &vec;
923929 try expect(vec.@"0" == 22);
924930 try expect(vec.@"1" == 55);
925931 try expect(vec.@"2" == 99);
......@@ -940,6 +946,7 @@ test "comptime struct field" {
940946 comptime std.debug.assert(@sizeOf(T) == 4);
941947
942948 var foo: T = undefined;
949 _ = &foo;
943950 try comptime expect(foo.b == 1234);
944951}
945952
......@@ -950,7 +957,7 @@ test "tuple element initialized with fn call" {
950957
951958 const S = struct {
952959 fn doTheTest() !void {
953 var x = .{foo()};
960 const x = .{foo()};
954961 try expectEqualSlices(u8, x[0], "hi");
955962 }
956963 fn foo() []const u8 {
......@@ -977,6 +984,7 @@ test "struct with union field" {
977984 var True = Value{
978985 .kind = .{ .Bool = true },
979986 };
987 _ = &True;
980988 try expect(@as(u32, 2) == True.ref);
981989 try expect(True.kind.Bool);
982990}
......@@ -996,6 +1004,7 @@ test "struct with 0-length union array field" {
9961004 };
9971005
9981006 var s: S = undefined;
1007 _ = &s;
9991008 try expectEqual(@as(usize, 0), s.zero_length.len);
10001009}
10011010
......@@ -1019,10 +1028,11 @@ test "type coercion of anon struct literal to struct" {
10191028
10201029 fn doTheTest() !void {
10211030 var y: u32 = 42;
1031 _ = &y;
10221032 const t0 = .{ .A = 123, .B = "foo", .C = {} };
10231033 const t1 = .{ .A = y, .B = "foo", .C = {} };
10241034 const y0: S2 = t0;
1025 var y1: S2 = t1;
1035 const y1: S2 = t1;
10261036 try expect(y0.A == 123);
10271037 try expect(std.mem.eql(u8, y0.B, "foo"));
10281038 try expect(y0.C == {});
......@@ -1057,10 +1067,11 @@ test "type coercion of pointer to anon struct literal to pointer to struct" {
10571067
10581068 fn doTheTest() !void {
10591069 var y: u32 = 42;
1070 _ = &y;
10601071 const t0 = &.{ .A = 123, .B = "foo", .C = {} };
10611072 const t1 = &.{ .A = y, .B = "foo", .C = {} };
10621073 const y0: *const S2 = t0;
1063 var y1: *const S2 = t1;
1074 const y1: *const S2 = t1;
10641075 try expect(y0.A == 123);
10651076 try expect(std.mem.eql(u8, y0.B, "foo"));
10661077 try expect(y0.C == {});
......@@ -1161,8 +1172,8 @@ test "anon init through error unions and optionals" {
11611172 }
11621173
11631174 fn doTheTest() !void {
1164 var a = try (try foo()).?;
1165 var b = try bar().?;
1175 const a = try (try foo()).?;
1176 const b = try bar().?;
11661177 try expect(a.a + b[1] == 3);
11671178 }
11681179 };
......@@ -1227,8 +1238,8 @@ test "typed init through error unions and optionals" {
12271238 }
12281239
12291240 fn doTheTest() !void {
1230 var a = try (try foo()).?;
1231 var b = try bar().?;
1241 const a = try (try foo()).?;
1242 const b = try bar().?;
12321243 try expect(a.a + b[1] == 3);
12331244 }
12341245 };
......@@ -1243,6 +1254,7 @@ test "initialize struct with empty literal" {
12431254
12441255 const S = struct { x: i32 = 1234 };
12451256 var s: S = .{};
1257 _ = &s;
12461258 try expect(s.x == 1234);
12471259}
12481260
......@@ -1301,10 +1313,10 @@ test "packed struct field access via pointer" {
13011313 fn doTheTest() !void {
13021314 const S = packed struct { a: u30 };
13031315 var s1: S = .{ .a = 1 };
1304 var s2 = &s1;
1316 const s2 = &s1;
13051317 try expect(s2.a == 1);
13061318 var s3: S = undefined;
1307 var s4 = &s3;
1319 const s4 = &s3;
13081320 _ = s4;
13091321 }
13101322 };
......@@ -1343,6 +1355,7 @@ test "struct field init value is size of the struct" {
13431355 };
13441356 };
13451357 var s: namespace.S = .{ .blah = 1234 };
1358 _ = &s;
13461359 try expect(s.size == 4);
13471360}
13481361
......@@ -1362,6 +1375,7 @@ test "under-aligned struct field" {
13621375 data: U align(4),
13631376 };
13641377 var runtime: usize = 1234;
1378 _ = &runtime;
13651379 const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } };
13661380 const array = @as(*const [12]u8, @ptrCast(ptr));
13671381 const result = std.mem.readInt(u64, array[4..12], native_endian);
......@@ -1509,6 +1523,7 @@ test "function pointer in struct returns the struct" {
15091523 }
15101524 };
15111525 var a = A.f();
1526 _ = &a;
15121527 try expect(a.f == A.f);
15131528}
15141529
......@@ -1538,7 +1553,8 @@ test "optional field init with tuple" {
15381553 a: ?struct { b: u32 },
15391554 };
15401555 var a: u32 = 0;
1541 var b = S{
1556 _ = &a;
1557 const b = S{
15421558 .a = .{ .b = a },
15431559 };
15441560 try expect(b.a.?.b == a);
......@@ -1550,7 +1566,8 @@ test "if inside struct init inside if" {
15501566 const MyStruct = struct { x: u32 };
15511567 const b: u32 = 5;
15521568 var i: u32 = 1;
1553 var my_var = if (i < 5)
1569 _ = &i;
1570 const my_var = if (i < 5)
15541571 MyStruct{
15551572 .x = 1 + if (i > 0) b else 0,
15561573 }
......@@ -1599,7 +1616,7 @@ test "instantiate struct with comptime field" {
15991616 var things = struct {
16001617 comptime foo: i8 = 1,
16011618 }{};
1602
1619 _ = &things;
16031620 comptime std.debug.assert(things.foo == 1);
16041621 }
16051622
......@@ -1608,7 +1625,7 @@ test "instantiate struct with comptime field" {
16081625 comptime foo: i8 = 1,
16091626 };
16101627 var things = T{};
1611
1628 _ = &things;
16121629 comptime std.debug.assert(things.foo == 1);
16131630 }
16141631
......@@ -1616,7 +1633,7 @@ test "instantiate struct with comptime field" {
16161633 var things: struct {
16171634 comptime foo: i8 = 1,
16181635 } = .{};
1619
1636 _ = &things;
16201637 comptime std.debug.assert(things.foo == 1);
16211638 }
16221639
......@@ -1624,7 +1641,7 @@ test "instantiate struct with comptime field" {
16241641 var things: struct {
16251642 comptime foo: i8 = 1,
16261643 } = undefined; // Segmentation fault at address 0x0
1627
1644 _ = &things;
16281645 comptime std.debug.assert(things.foo == 1);
16291646 }
16301647}
......@@ -1755,6 +1772,7 @@ test "runtime side-effects in comptime-known struct init" {
17551772test "pointer to struct initialized through reference to anonymous initializer provides result types" {
17561773 const S = struct { a: u8, b: u16, c: *const anyopaque };
17571774 var my_u16: u16 = 0xABCD;
1775 _ = &my_u16;
17581776 const s: *const S = &.{
17591777 // intentionally out of order
17601778 .c = @ptrCast("hello"),
......@@ -1792,6 +1810,7 @@ test "initializer uses own alignment" {
17921810 };
17931811
17941812 var s: S = .{};
1813 _ = &s;
17951814 try expectEqual(4, @alignOf(S));
17961815 try expectEqual(@as(usize, 5), s.x);
17971816}
......@@ -1802,6 +1821,7 @@ test "initializer uses own size" {
18021821 };
18031822
18041823 var s: S = .{};
1824 _ = &s;
18051825 try expectEqual(4, @sizeOf(S));
18061826 try expectEqual(@as(usize, 5), s.x);
18071827}
......@@ -1815,6 +1835,7 @@ test "initializer takes a pointer to a variable inside its struct" {
18151835
18161836 fn doTheTest() !void {
18171837 var foo: S = .{};
1838 _ = &foo;
18181839 try expectEqual(&S.instance, foo.s);
18191840 }
18201841 };
......@@ -1839,6 +1860,7 @@ test "circular dependency through pointer field of a struct" {
18391860 };
18401861 };
18411862 var outer: S.StructOuter = .{};
1863 _ = &outer;
18421864 try expect(outer.middle.outer == null);
18431865 try expect(outer.middle.inner == null);
18441866}
......@@ -1855,5 +1877,6 @@ test "field calls do not force struct field init resolution" {
18551877 }
18561878 };
18571879 var s: S = .{};
1880 _ = &s;
18581881 try expect(s.x == 123);
18591882}
test/behavior/struct_contains_null_ptr_itself.zig+1
......@@ -7,6 +7,7 @@ test "struct contains null pointer which contains original struct" {
77 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
88
99 var x: ?*NodeLineComment = null;
10 _ = &x;
1011 try expect(x == null);
1112}
1213
test/behavior/switch.zig+17-9
......@@ -157,6 +157,7 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool {
157157
158158test "u0" {
159159 var val: u0 = 0;
160 _ = &val;
160161 switch (val) {
161162 0 => try expect(val == 0),
162163 }
......@@ -164,6 +165,7 @@ test "u0" {
164165
165166test "undefined.u0" {
166167 var val: u0 = undefined;
168 _ = &val;
167169 switch (val) {
168170 0 => try expect(val == 0),
169171 }
......@@ -173,6 +175,7 @@ test "switch with disjoint range" {
173175 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
174176
175177 var q: u8 = 0;
178 _ = &q;
176179 switch (q) {
177180 0...125 => {},
178181 127...255 => {},
......@@ -183,12 +186,8 @@ test "switch with disjoint range" {
183186test "switch variable for range and multiple prongs" {
184187 const S = struct {
185188 fn doTheTest() !void {
186 var u: u8 = 16;
187 try doTheSwitch(u);
188 try comptime doTheSwitch(u);
189 var v: u8 = 42;
190 try doTheSwitch(v);
191 try comptime doTheSwitch(v);
189 try doTheSwitch(16);
190 try doTheSwitch(42);
192191 }
193192 fn doTheSwitch(q: u8) !void {
194193 switch (q) {
......@@ -198,7 +197,8 @@ test "switch variable for range and multiple prongs" {
198197 }
199198 }
200199 };
201 _ = S;
200 try S.doTheTest();
201 try comptime S.doTheTest();
202202}
203203
204204var state: u32 = 0;
......@@ -322,7 +322,8 @@ test "switch on union with some prongs capturing" {
322322 };
323323
324324 var x: X = X{ .b = 10 };
325 var y: i32 = switch (x) {
325 _ = &x;
326 const y: i32 = switch (x) {
326327 .a => unreachable,
327328 .b => |b| b + 1,
328329 };
......@@ -357,6 +358,7 @@ test "anon enum literal used in switch on union enum" {
357358 };
358359
359360 var foo = Foo{ .a = 1234 };
361 _ = &foo;
360362 switch (foo) {
361363 .a => |x| {
362364 try expect(x == 1234);
......@@ -406,6 +408,7 @@ test "switch on integer with else capturing expr" {
406408 const S = struct {
407409 fn doTheTest() !void {
408410 var x: i32 = 5;
411 _ = &x;
409412 switch (x + 10) {
410413 14 => @panic("fail"),
411414 16 => @panic("fail"),
......@@ -606,6 +609,7 @@ test "switch on error set with single else" {
606609 const S = struct {
607610 fn doTheTest() !void {
608611 var some: error{Foo} = error.Foo;
612 _ = &some;
609613 try expect(switch (some) {
610614 else => blk: {
611615 break :blk true;
......@@ -672,7 +676,8 @@ test "enum value without tag name used as switch item" {
672676 b = 2,
673677 _,
674678 };
675 var e: E = @as(E, @enumFromInt(0));
679 var e: E = @enumFromInt(0);
680 _ = &e;
676681 switch (e) {
677682 @as(E, @enumFromInt(0)) => {},
678683 .a => return error.TestFailed,
......@@ -685,6 +690,7 @@ test "switch item sizeof" {
685690 const S = struct {
686691 fn doTheTest() !void {
687692 var a: usize = 0;
693 _ = &a;
688694 switch (a) {
689695 @sizeOf(struct {}) => {},
690696 else => return error.TestFailed,
......@@ -699,6 +705,7 @@ test "comptime inline switch" {
699705 const U = union(enum) { a: type, b: type };
700706 const value = comptime blk: {
701707 var u: U = .{ .a = u32 };
708 _ = &u;
702709 break :blk switch (u) {
703710 inline .a, .b => |v| v,
704711 };
......@@ -814,6 +821,7 @@ test "peer type resolution on switch captures ignores unused payload bits" {
814821
815822 // This is runtime-known so the following store isn't comptime-known.
816823 var rt: u32 = 123;
824 _ = &rt;
817825 val = .{ .a = rt }; // will not necessarily zero remaning payload memory
818826
819827 // Fields intentionally backwards here
test/behavior/truncate.zig+17-12
......@@ -4,58 +4,62 @@ const expect = std.testing.expect;
44
55test "truncate u0 to larger integer allowed and has comptime-known result" {
66 var x: u0 = 0;
7 _ = &x;
78 const y = @as(u8, @truncate(x));
89 try comptime expect(y == 0);
910}
1011
1112test "truncate.u0.literal" {
12 var z = @as(u0, @truncate(0));
13 const z: u0 = @truncate(0);
1314 try expect(z == 0);
1415}
1516
1617test "truncate.u0.const" {
1718 const c0: usize = 0;
18 var z = @as(u0, @truncate(c0));
19 const z: u0 = @truncate(c0);
1920 try expect(z == 0);
2021}
2122
2223test "truncate.u0.var" {
2324 var d: u8 = 2;
24 var z = @as(u0, @truncate(d));
25 _ = &d;
26 const z: u0 = @truncate(d);
2527 try expect(z == 0);
2628}
2729
2830test "truncate i0 to larger integer allowed and has comptime-known result" {
2931 var x: i0 = 0;
30 const y = @as(i8, @truncate(x));
32 _ = &x;
33 const y: i8 = @truncate(x);
3134 try comptime expect(y == 0);
3235}
3336
3437test "truncate.i0.literal" {
35 var z = @as(i0, @truncate(0));
38 const z: i0 = @truncate(0);
3639 try expect(z == 0);
3740}
3841
3942test "truncate.i0.const" {
4043 const c0: isize = 0;
41 var z = @as(i0, @truncate(c0));
44 const z: i0 = @truncate(c0);
4245 try expect(z == 0);
4346}
4447
4548test "truncate.i0.var" {
4649 var d: i8 = 2;
47 var z = @as(i0, @truncate(d));
50 _ = &d;
51 const z: i0 = @truncate(d);
4852 try expect(z == 0);
4953}
5054
5155test "truncate on comptime integer" {
52 var x = @as(u16, @truncate(9999));
56 const x: u16 = @truncate(9999);
5357 try expect(x == 9999);
54 var y = @as(u16, @truncate(-21555));
58 const y: u16 = @truncate(-21555);
5559 try expect(y == 0xabcd);
56 var z = @as(i16, @truncate(-65537));
60 const z: i16 = @truncate(-65537);
5761 try expect(z == -1);
58 var w = @as(u1, @truncate(1 << 100));
62 const w: u1 = @truncate(1 << 100);
5963 try expect(w == 0);
6064}
6165
......@@ -69,7 +73,8 @@ test "truncate on vectors" {
6973 const S = struct {
7074 fn doTheTest() !void {
7175 var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 };
72 var v2: @Vector(4, u8) = @truncate(v1);
76 _ = &v1;
77 const v2: @Vector(4, u8) = @truncate(v1);
7378 try expect(std.mem.eql(u8, &@as([4]u8, v2), &[4]u8{ 0xbb, 0xdd, 0xff, 0x22 }));
7479 }
7580 };
test/behavior/tuple.zig+25-8
......@@ -15,9 +15,10 @@ test "tuple concatenation" {
1515 fn doTheTest() !void {
1616 var a: i32 = 1;
1717 var b: i32 = 2;
18 var x = .{a};
19 var y = .{b};
20 var c = x ++ y;
18 _ = .{ &a, &b };
19 const x = .{a};
20 const y = .{b};
21 const c = x ++ y;
2122 try expect(@as(i32, 1) == c[0]);
2223 try expect(@as(i32, 2) == c[1]);
2324 }
......@@ -119,7 +120,7 @@ test "tuple initializer for var" {
119120 .id = @as(usize, 2),
120121 .name = Bytes{ .id = 20 },
121122 };
122 _ = tmp;
123 _ = &tmp;
123124 }
124125 };
125126
......@@ -157,6 +158,7 @@ test "array-like initializer for tuple types" {
157158 const S = struct {
158159 fn doTheTest() !void {
159160 var obj: T = .{ -1234, 128 };
161 _ = &obj;
160162 try expect(@as(i32, -1234) == obj[0]);
161163 try expect(@as(u8, 128) == obj[1]);
162164 }
......@@ -171,6 +173,7 @@ test "anon struct as the result from a labeled block" {
171173 fn doTheTest() !void {
172174 const precomputed = comptime blk: {
173175 var x: i32 = 1234;
176 _ = &x;
174177 break :blk .{
175178 .x = x,
176179 };
......@@ -188,6 +191,7 @@ test "tuple as the result from a labeled block" {
188191 fn doTheTest() !void {
189192 const precomputed = comptime blk: {
190193 var x: i32 = 1234;
194 _ = &x;
191195 break :blk .{x};
192196 };
193197 try expect(precomputed[0] == 1234);
......@@ -201,13 +205,13 @@ test "tuple as the result from a labeled block" {
201205test "initializing tuple with explicit type" {
202206 const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });
203207 var a = T{ 0, 0 };
204 _ = a;
208 _ = &a;
205209}
206210
207211test "initializing anon struct with explicit type" {
208212 const T = @TypeOf(.{ .foo = @as(i32, 1), .bar = @as(i32, 2) });
209213 var a = T{ .foo = 1, .bar = 2 };
210 _ = a;
214 _ = &a;
211215}
212216
213217test "fieldParentPtr of tuple" {
......@@ -216,6 +220,7 @@ test "fieldParentPtr of tuple" {
216220 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
217221
218222 var x: u32 = 0;
223 _ = &x;
219224 const tuple = .{ x, x };
220225 try testing.expect(&tuple == @fieldParentPtr(@TypeOf(tuple), "1", &tuple[1]));
221226}
......@@ -226,18 +231,21 @@ test "fieldParentPtr of anon struct" {
226231 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
227232
228233 var x: u32 = 0;
234 _ = &x;
229235 const anon_st = .{ .foo = x, .bar = x };
230236 try testing.expect(&anon_st == @fieldParentPtr(@TypeOf(anon_st), "bar", &anon_st.bar));
231237}
232238
233239test "offsetOf tuple" {
234240 var x: u32 = 0;
241 _ = &x;
235242 const T = @TypeOf(.{ x, x });
236243 try expect(@offsetOf(T, "1") == @sizeOf(u32));
237244}
238245
239246test "offsetOf anon struct" {
240247 var x: u32 = 0;
248 _ = &x;
241249 const T = @TypeOf(.{ .foo = x, .bar = x });
242250 try expect(@offsetOf(T, "bar") == @sizeOf(u32));
243251}
......@@ -247,8 +255,10 @@ test "initializing tuple with mixed comptime-runtime fields" {
247255 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
248256
249257 var x: u32 = 15;
258 _ = &x;
250259 const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
251260 var a: T = .{ -1234, 5678, x + 1 };
261 _ = &a;
252262 try expect(a[2] == 16);
253263}
254264
......@@ -257,8 +267,10 @@ test "initializing anon struct with mixed comptime-runtime fields" {
257267 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
258268
259269 var x: u32 = 15;
270 _ = &x;
260271 const T = @TypeOf(.{ .foo = @as(i32, -1234), .bar = x });
261272 var a: T = .{ .foo = -1234, .bar = x + 1 };
273 _ = &a;
262274 try expect(a.bar == 16);
263275}
264276
......@@ -338,6 +350,7 @@ test "tuple type with void field and a runtime field" {
338350
339351 const T = std.meta.Tuple(&[_]type{ usize, void });
340352 var t: T = .{ 5, {} };
353 _ = &t;
341354 try expect(t[0] == 5);
342355}
343356
......@@ -352,6 +365,7 @@ test "branching inside tuple literal" {
352365 }
353366 };
354367 var a = false;
368 _ = &a;
355369 try S.foo(.{if (a) @as(u32, 5678) else @as(u32, 1234)});
356370}
357371
......@@ -363,6 +377,7 @@ test "tuple initialized with a runtime known value" {
363377 const E = union(enum) { e: []const u8 };
364378 const W = union(enum) { w: E };
365379 var e = E{ .e = "test" };
380 _ = &e;
366381 const w = .{W{ .w = e }};
367382 try expectEqualStrings(w[0].w.e, "test");
368383}
......@@ -388,6 +403,7 @@ test "nested runtime conditionals in tuple initializer" {
388403 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
389404
390405 var data: u8 = 0;
406 _ = &data;
391407 const x = .{
392408 if (data != 0) "" else switch (@as(u1, @truncate(data))) {
393409 0 => "up",
......@@ -446,8 +462,9 @@ test "coerce anon tuple to tuple" {
446462
447463 var x: u8 = 1;
448464 var y: u16 = 2;
449 var t = .{ x, y };
450 var s: struct { u8, u16 } = t;
465 _ = .{ &x, &y };
466 const t = .{ x, y };
467 const s: struct { u8, u16 } = t;
451468 try expectEqual(x, s[0]);
452469 try expectEqual(y, s[1]);
453470}
test/behavior/tuple_declarations.zig+4-2
......@@ -38,17 +38,19 @@ test "Tuple declaration usage" {
3838
3939 const T = struct { u32, []const u8 };
4040 var t: T = .{ 1, "foo" };
41 _ = &t;
4142 try expect(t[0] == 1);
4243 try expectEqualStrings(t[1], "foo");
4344
44 var mul = t ** 3;
45 const mul = t ** 3;
4546 try expect(@TypeOf(mul) != T);
4647 try expect(mul.len == 6);
4748 try expect(mul[2] == 1);
4849 try expectEqualStrings(mul[3], "foo");
4950
5051 var t2: T = .{ 2, "bar" };
51 var cat = t ++ t2;
52 _ = &t2;
53 const cat = t ++ t2;
5254 try expect(@TypeOf(cat) != T);
5355 try expect(cat.len == 4);
5456 try expect(cat[2] == 2);
test/behavior/type.zig+3-2
......@@ -410,7 +410,8 @@ test "Type.Union" {
410410 .decls = &.{},
411411 },
412412 });
413 var packed_untagged = PackedUntagged{ .signed = -1 };
413 var packed_untagged: PackedUntagged = .{ .signed = -1 };
414 _ = &packed_untagged;
414415 try testing.expectEqual(@as(i32, -1), packed_untagged.signed);
415416 try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned);
416417
......@@ -529,7 +530,7 @@ test "reified struct field name from optional payload" {
529530 .decls = &.{},
530531 .is_tuple = false,
531532 } });
532 var t: T = .{ .a = 123 };
533 const t: T = .{ .a = 123 };
533534 try std.testing.expect(t.a == 123);
534535 }
535536 }
test/behavior/type_info.zig+1-1
......@@ -417,7 +417,7 @@ test "typeInfo with comptime parameter in struct fn def" {
417417 }
418418 };
419419 comptime var info = @typeInfo(S);
420 _ = info;
420 _ = &info;
421421}
422422
423423test "type info: vectors" {
test/behavior/union.zig+46-5
......@@ -171,6 +171,7 @@ test "constant tagged union with payload" {
171171
172172 var empty = TaggedUnionWithPayload{ .Empty = {} };
173173 var full = TaggedUnionWithPayload{ .Full = 13 };
174 _ = .{ &empty, &full };
174175 shouldBeEmpty(empty);
175176 shouldBeNotEmpty(full);
176177}
......@@ -254,6 +255,7 @@ fn bar(value: Payload) error{TestUnexpectedResult}!i32 {
254255
255256fn testComparison() !void {
256257 var x = Payload{ .A = 42 };
258 _ = &x;
257259 try expect(x == .A);
258260 try expect(x != .B);
259261 try expect(x != .C);
......@@ -288,6 +290,7 @@ test "cast union to tag type of union" {
288290
289291fn testCastUnionToTag() !void {
290292 var u = TheUnion{ .B = 1234 };
293 _ = &u;
291294 try expect(@as(TheTag, u) == TheTag.B);
292295}
293296
......@@ -303,6 +306,7 @@ test "cast tag type of union to union" {
303306 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
304307
305308 var x: Value2 = Letter2.B;
309 _ = &x;
306310 try expect(@as(Letter2, x) == Letter2.B);
307311}
308312const Letter2 = enum { A, B, C };
......@@ -318,6 +322,7 @@ test "implicit cast union to its tag type" {
318322 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
319323
320324 var x: Value2 = Letter2.B;
325 _ = &x;
321326 try expect(x == Letter2.B);
322327 try giveMeLetterB(x);
323328}
......@@ -356,6 +361,7 @@ test "simple union(enum(u32))" {
356361 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
357362
358363 var x = MultipleChoice.C;
364 _ = &x;
359365 try expect(x == MultipleChoice.C);
360366 try expect(@intFromEnum(@as(Tag(MultipleChoice), x)) == 60);
361367}
......@@ -420,9 +426,11 @@ test "union with only 1 field casted to its enum type" {
420426 };
421427
422428 var e = Expr{ .Literal = Literal{ .Bool = true } };
429 _ = &e;
423430 const ExprTag = Tag(Expr);
424431 try comptime expect(Tag(ExprTag) == u0);
425432 var t = @as(ExprTag, e);
433 _ = &t;
426434 try expect(t == Expr.Literal);
427435}
428436
......@@ -494,6 +502,7 @@ test "union initializer generates padding only if needed" {
494502 };
495503
496504 var v = U{ .A = 532 };
505 _ = &v;
497506 try expect(v.A == 532);
498507}
499508
......@@ -506,6 +515,7 @@ test "runtime tag name with single field" {
506515 };
507516
508517 var v = U{ .A = 42 };
518 _ = &v;
509519 try expect(std.mem.eql(u8, @tagName(v), "A"));
510520}
511521
......@@ -698,8 +708,9 @@ test "union with only 1 field casted to its enum type which has enum value speci
698708 };
699709
700710 var e = Expr{ .Literal = Literal{ .Bool = true } };
711 _ = &e;
701712 try comptime expect(Tag(ExprTag) == comptime_int);
702 comptime var t = @as(ExprTag, e);
713 const t = comptime @as(ExprTag, e);
703714 try expect(t == Expr.Literal);
704715 try expect(@intFromEnum(t) == 33);
705716 try comptime expect(@intFromEnum(t) == 33);
......@@ -719,6 +730,7 @@ test "@intFromEnum works on unions" {
719730 const a = Bar{ .A = true };
720731 var b = Bar{ .B = undefined };
721732 var c = Bar.C;
733 _ = .{ &b, &c };
722734 try expect(@intFromEnum(a) == 0);
723735 try expect(@intFromEnum(b) == 1);
724736 try expect(@intFromEnum(c) == 2);
......@@ -800,11 +812,13 @@ test "@unionInit stored to a const" {
800812 fn doTheTest() !void {
801813 {
802814 var t = true;
815 _ = &t;
803816 const u = @unionInit(U, "boolean", t);
804817 try expect(u.boolean);
805818 }
806819 {
807820 var byte: u8 = 69;
821 _ = &byte;
808822 const u = @unionInit(U, "byte", byte);
809823 try expect(u.byte == 69);
810824 }
......@@ -849,7 +863,7 @@ test "@unionInit can modify a pointer value" {
849863 };
850864
851865 var value: UnionInitEnum = undefined;
852 var value_ptr = &value;
866 const value_ptr = &value;
853867
854868 value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true);
855869 try expect(value.Boolean == true);
......@@ -906,7 +920,8 @@ test "anonymous union literal syntax" {
906920
907921 fn doTheTest() !void {
908922 var i: Number = .{ .int = 42 };
909 var f = makeNumber();
923 _ = &i;
924 const f = makeNumber();
910925 try expect(i.int == 42);
911926 try expect(f.float == 12.34);
912927 }
......@@ -934,9 +949,11 @@ test "function call result coerces from tagged union to the tag" {
934949
935950 fn doTheTest() !void {
936951 var x: ArchTag = getArch1();
952 _ = &x;
937953 try expect(x == .One);
938954
939955 var y: ArchTag = getArch2();
956 _ = &y;
940957 try expect(y == .Two);
941958 }
942959
......@@ -965,14 +982,17 @@ test "cast from anonymous struct to union" {
965982 };
966983 fn doTheTest() !void {
967984 var y: u32 = 42;
985 _ = &y;
968986 const t0 = .{ .A = 123 };
969987 const t1 = .{ .B = "foo" };
970988 const t2 = .{ .C = {} };
971989 const t3 = .{ .A = y };
972990 const x0: U = t0;
973991 var x1: U = t1;
992 _ = &x1;
974993 const x2: U = t2;
975994 var x3: U = t3;
995 _ = &x3;
976996 try expect(x0.A == 123);
977997 try expect(std.mem.eql(u8, x1.B, "foo"));
978998 try expect(x2 == .C);
......@@ -996,14 +1016,17 @@ test "cast from pointer to anonymous struct to pointer to union" {
9961016 };
9971017 fn doTheTest() !void {
9981018 var y: u32 = 42;
1019 _ = &y;
9991020 const t0 = &.{ .A = 123 };
10001021 const t1 = &.{ .B = "foo" };
10011022 const t2 = &.{ .C = {} };
10021023 const t3 = &.{ .A = y };
10031024 const x0: *const U = t0;
10041025 var x1: *const U = t1;
1026 _ = &x1;
10051027 const x2: *const U = t2;
10061028 var x3: *const U = t3;
1029 _ = &x3;
10071030 try expect(x0.A == 123);
10081031 try expect(std.mem.eql(u8, x1.B, "foo"));
10091032 try expect(x2.* == .C);
......@@ -1031,6 +1054,7 @@ test "switching on non exhaustive union" {
10311054 };
10321055 fn doTheTest() !void {
10331056 var a = U{ .a = 2 };
1057 _ = &a;
10341058 switch (a) {
10351059 .a => |val| try expect(val == 2),
10361060 .b => return error.Fail,
......@@ -1055,11 +1079,13 @@ test "containers with single-field enums" {
10551079 fn doTheTest() !void {
10561080 var array1 = [1]A{A{ .f1 = {} }};
10571081 var array2 = [1]B{B{ .f1 = {} }};
1082 _ = .{ &array1, &array2 };
10581083 try expect(array1[0] == .f1);
10591084 try expect(array2[0] == .f1);
10601085
10611086 var struct1 = C{ .a = A{ .f1 = {} } };
10621087 var struct2 = D{ .a = B{ .f1 = {} } };
1088 _ = .{ &struct1, &struct2 };
10631089 try expect(struct1.a == .f1);
10641090 try expect(struct2.a == .f1);
10651091 }
......@@ -1092,8 +1118,9 @@ test "@unionInit on union with tag but no fields" {
10921118
10931119 fn doTheTest() !void {
10941120 var data: Data = .{ .no_op = {} };
1095 _ = data;
1121 _ = &data;
10961122 var o = Data.decode(&[_]u8{});
1123 _ = &o;
10971124 try expectEqual(Type.no_op, o);
10981125 }
10991126 };
......@@ -1156,6 +1183,7 @@ test "union with no result loc initiated with a runtime value" {
11561183 }
11571184 };
11581185 var a: u32 = 1;
1186 _ = &a;
11591187 U.foo(U{ .a = a });
11601188}
11611189
......@@ -1174,6 +1202,7 @@ test "union with a large struct field" {
11741202 fn foo(_: @This()) void {}
11751203 };
11761204 var s: S = undefined;
1205 _ = &s;
11771206 U.foo(U{ .s = s });
11781207}
11791208
......@@ -1207,6 +1236,7 @@ test "union tag is set when initiated as a temporary value at runtime" {
12071236 }
12081237 };
12091238 var b: u32 = 1;
1239 _ = &b;
12101240 try (U{ .b = b }).doTheTest();
12111241}
12121242
......@@ -1226,6 +1256,7 @@ test "extern union most-aligned field is smaller" {
12261256 un: [110]u8,
12271257 };
12281258 var a: ?U = .{ .un = [_]u8{0} ** 110 };
1259 _ = &a;
12291260 try expect(a != null);
12301261}
12311262
......@@ -1246,6 +1277,7 @@ test "return an extern union from C calling convention" {
12461277
12471278 fn bar(arg_u: U) callconv(.C) U {
12481279 var u = arg_u;
1280 _ = &u;
12491281 return u;
12501282 }
12511283 };
......@@ -1324,13 +1356,16 @@ test "@unionInit uses tag value instead of field index" {
13241356 a: usize,
13251357 };
13261358 var i: isize = -1;
1359 _ = &i;
13271360 var u = @unionInit(U, "b", i);
13281361 {
13291362 var a = u.b;
1363 _ = &a;
13301364 try expect(a == i);
13311365 }
13321366 {
13331367 var a = &u.b;
1368 _ = &a;
13341369 try expect(a.* == i);
13351370 }
13361371 try expect(@intFromEnum(u) == 255);
......@@ -1508,7 +1543,7 @@ test "coerce enum literal to union in result loc" {
15081543 b: u8,
15091544
15101545 fn doTest(c: bool) !void {
1511 var u = if (c) .a else @This(){ .b = 0 };
1546 const u = if (c) .a else @This(){ .b = 0 };
15121547 try expect(u == .a);
15131548 }
15141549 };
......@@ -1947,6 +1982,7 @@ test "packed union initialized via reintepreted struct field initializer" {
19471982 };
19481983
19491984 var s: S = .{};
1985 _ = &s;
19501986 try expect(s.u.a == littleToNativeEndian(u32, 0xddccbbaa));
19511987 try expect(s.u.b == if (endian == .little) 0xaa else 0xdd);
19521988}
......@@ -1966,6 +2002,7 @@ test "store of comptime reinterpreted memory to extern union" {
19662002 };
19672003
19682004 var u: U = reinterpreted;
2005 _ = &u;
19692006 try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa));
19702007 try expect(u.b == 0xaa);
19712008}
......@@ -1985,6 +2022,7 @@ test "store of comptime reinterpreted memory to packed union" {
19852022 };
19862023
19872024 var u: U = reinterpreted;
2025 _ = &u;
19882026 try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa));
19892027 try expect(u.b == if (endian == .little) 0xaa else 0xdd);
19902028}
......@@ -2018,6 +2056,7 @@ test "pass register-sized field as non-register-sized union" {
20182056 };
20192057
20202058 var x: usize = 42;
2059 _ = &x;
20212060 try S.taggedUnion(.{ .x = x });
20222061 try S.untaggedUnion(.{ .x = x });
20232062 try S.externUnion(.{ .x = x });
......@@ -2039,6 +2078,7 @@ test "circular dependency through pointer field of a union" {
20392078 };
20402079 };
20412080 var outer: S.UnionOuter = .{};
2081 _ = &outer;
20422082 try expect(outer.u.outer == null);
20432083 try expect(outer.u.inner == null);
20442084}
......@@ -2057,5 +2097,6 @@ test "pass nested union with rls" {
20572097 };
20582098
20592099 var c: u7 = 32;
2100 _ = &c;
20602101 try expectEqual(@as(u7, 32), Union.getC(.{ .b = .{ .c = c } }));
20612102}
test/behavior/var_args.zig+1
......@@ -147,6 +147,7 @@ test "simple variadic function" {
147147 var runtime: bool = true;
148148 var a: i32 = 1;
149149 var b: i32 = 2;
150 _ = .{ &runtime, &a, &b };
150151 try expect(1 == S.add(1, if (runtime) a else b));
151152 }
152153}
test/behavior/vector.zig+99-55
......@@ -40,6 +40,7 @@ test "vector wrap operators" {
4040 try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
4141 var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };
4242 try expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 }));
43 _ = .{ &v, &x, &z };
4344 }
4445 };
4546 try S.doTheTest();
......@@ -57,6 +58,7 @@ test "vector bin compares with mem.eql" {
5758 fn doTheTest() !void {
5859 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
5960 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };
61 _ = .{ &v, &x };
6062 try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false }));
6163 try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true }));
6264 try expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false }));
......@@ -81,6 +83,7 @@ test "vector int operators" {
8183 fn doTheTest() !void {
8284 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
8385 var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };
86 _ = .{ &v, &x };
8487 try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 }));
8588 try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 }));
8689 try expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 }));
......@@ -105,6 +108,7 @@ test "vector float operators" {
105108 fn doTheTest() !void {
106109 var v: @Vector(4, T) = [4]T{ 10, 20, 30, 40 };
107110 var x: @Vector(4, T) = [4]T{ 1, 2, 3, 4 };
111 _ = .{ &v, &x };
108112 try expect(mem.eql(T, &@as([4]T, v + x), &[4]T{ 11, 22, 33, 44 }));
109113 try expect(mem.eql(T, &@as([4]T, v - x), &[4]T{ 9, 18, 27, 36 }));
110114 try expect(mem.eql(T, &@as([4]T, v * x), &[4]T{ 10, 40, 90, 160 }));
......@@ -126,6 +130,7 @@ test "vector bit operators" {
126130 fn doTheTest() !void {
127131 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
128132 var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };
133 _ = .{ &v, &x };
129134 try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
130135 try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
131136 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" {
143148 const S = struct {
144149 fn doTheTest() !void {
145150 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
151 _ = &a;
146152 var result_array: [4]i32 = a;
147153 result_array = a;
148154 try expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 }));
......@@ -160,8 +166,9 @@ test "array to vector" {
160166 const S = struct {
161167 fn doTheTest() !void {
162168 var foo: f32 = 3.14;
163 var arr = [4]f32{ foo, 1.5, 0.0, 0.0 };
164 var vec: @Vector(4, f32) = arr;
169 _ = &foo;
170 const arr = [4]f32{ foo, 1.5, 0.0, 0.0 };
171 const vec: @Vector(4, f32) = arr;
165172 try expect(mem.eql(f32, &@as([4]f32, vec), &arr));
166173 }
167174 };
......@@ -180,25 +187,28 @@ test "array vector coercion - odd sizes" {
180187 const S = struct {
181188 fn doTheTest() !void {
182189 var foo1: i48 = 124578;
183 var vec1: @Vector(2, i48) = [2]i48{ foo1, 1 };
184 var arr1: [2]i48 = vec1;
190 _ = &foo1;
191 const vec1: @Vector(2, i48) = [2]i48{ foo1, 1 };
192 const arr1: [2]i48 = vec1;
185193 try expect(vec1[0] == foo1 and vec1[1] == 1);
186194 try expect(arr1[0] == foo1 and arr1[1] == 1);
187195
188196 var foo2: u4 = 5;
189 var vec2: @Vector(2, u4) = [2]u4{ foo2, 1 };
190 var arr2: [2]u4 = vec2;
197 _ = &foo2;
198 const vec2: @Vector(2, u4) = [2]u4{ foo2, 1 };
199 const arr2: [2]u4 = vec2;
191200 try expect(vec2[0] == foo2 and vec2[1] == 1);
192201 try expect(arr2[0] == foo2 and arr2[1] == 1);
193202
194203 var foo3: u13 = 13;
195 var vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 };
196 var arr3: [3]u13 = vec3;
204 _ = &foo3;
205 const vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 };
206 const arr3: [3]u13 = vec3;
197207 try expect(vec3[0] == foo3 and vec3[1] == 0 and vec3[2] == 1);
198208 try expect(arr3[0] == foo3 and arr3[1] == 0 and arr3[2] == 1);
199209
200 var arr4 = [4:0]u24{ foo3, foo2, 0, 1 };
201 var vec4: @Vector(4, u24) = arr4;
210 const arr4 = [4:0]u24{ foo3, foo2, 0, 1 };
211 const vec4: @Vector(4, u24) = arr4;
202212 try expect(vec4[0] == foo3 and vec4[1] == foo2 and vec4[2] == 0 and vec4[3] == 1);
203213 }
204214 };
......@@ -217,8 +227,9 @@ test "array to vector with element type coercion" {
217227 const S = struct {
218228 fn doTheTest() !void {
219229 var foo: f16 = 3.14;
220 var arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 };
221 var vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 };
230 _ = &foo;
231 const arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 };
232 const vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 };
222233 try std.testing.expect(std.mem.eql(f32, &@as([4]f32, vec), &arr32));
223234 }
224235 };
......@@ -237,7 +248,8 @@ test "peer type resolution with coercible element types" {
237248 var b: @Vector(2, u8) = .{ 1, 2 };
238249 var a: @Vector(2, u16) = .{ 2, 1 };
239250 var t: bool = true;
240 var c = if (t) a else b;
251 _ = .{ &a, &b, &t };
252 const c = if (t) a else b;
241253 try std.testing.expect(@TypeOf(c) == @Vector(2, u16));
242254 }
243255 };
......@@ -285,22 +297,26 @@ test "vector casts of sizes not divisible by 8" {
285297 fn doTheTest() !void {
286298 {
287299 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
288 var x: [4]u3 = v;
300 _ = &v;
301 const x: [4]u3 = v;
289302 try expect(mem.eql(u3, &x, &@as([4]u3, v)));
290303 }
291304 {
292305 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
293 var x: [4]u2 = v;
306 _ = &v;
307 const x: [4]u2 = v;
294308 try expect(mem.eql(u2, &x, &@as([4]u2, v)));
295309 }
296310 {
297311 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
298 var x: [4]u1 = v;
312 _ = &v;
313 const x: [4]u1 = v;
299314 try expect(mem.eql(u1, &x, &@as([4]u1, v)));
300315 }
301316 {
302317 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };
303 var x: [4]bool = v;
318 _ = &v;
319 const x: [4]bool = v;
304320 try expect(mem.eql(bool, &x, &@as([4]bool, v)));
305321 }
306322 }
......@@ -327,7 +343,8 @@ test "vector @splat" {
327343 fn testForT(comptime N: comptime_int, v: anytype) !void {
328344 const T = @TypeOf(v);
329345 var vec: @Vector(N, T) = @splat(v);
330 var as_array = @as([N]T, vec);
346 _ = &vec;
347 const as_array = @as([N]T, vec);
331348 for (as_array) |elem| try expect(v == elem);
332349 }
333350 fn doTheTest() !void {
......@@ -412,6 +429,7 @@ test "load vector elements via runtime index" {
412429 const S = struct {
413430 fn doTheTest() !void {
414431 var v: @Vector(4, i32) = [_]i32{ 1, 2, 3, undefined };
432 _ = &v;
415433 var i: u32 = 0;
416434 try expect(v[i] == 1);
417435 i += 1;
......@@ -461,7 +479,7 @@ test "initialize vector which is a struct field" {
461479 var foo = Vec4Obj{
462480 .data = [_]f32{ 1, 2, 3, 4 },
463481 };
464 _ = foo;
482 _ = &foo;
465483 }
466484 };
467485 try S.doTheTest();
......@@ -481,6 +499,7 @@ test "vector comparison operators" {
481499 const V = @Vector(4, bool);
482500 var v1: V = [_]bool{ true, false, true, false };
483501 var v2: V = [_]bool{ false, true, false, true };
502 _ = .{ &v1, &v2 };
484503 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v1)));
485504 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v2)));
486505 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" {
491510 var v1: @Vector(4, u32) = @splat(0xc0ffeeee);
492511 var v2: @Vector(4, c_uint) = v1;
493512 var v3: @Vector(4, u32) = @splat(0xdeadbeef);
513 _ = .{ &v1, &v2, &v3 };
494514 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v2)));
495515 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v3)));
496516 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" {
499519 {
500520 // Comptime-known LHS/RHS
501521 var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 };
522 _ = &v1;
502523 const v2: @Vector(4, u32) = @splat(2);
503524 const v3: @Vector(4, bool) = [_]bool{ true, false, true, false };
504525 try expect(mem.eql(bool, &@as([4]bool, v3), &@as([4]bool, v1 == v2)));
......@@ -604,7 +625,7 @@ test "vector bitwise not operator" {
604625
605626 const S = struct {
606627 fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void {
607 var y = ~x;
628 const y = ~x;
608629 for (@as([4]T, y), 0..) |v, i| {
609630 try expect(~x[i] == v);
610631 }
......@@ -640,14 +661,14 @@ test "vector shift operators" {
640661 const TX = @typeInfo(@TypeOf(x)).Array.child;
641662 const TY = @typeInfo(@TypeOf(y)).Array.child;
642663
643 var xv = @as(@Vector(N, TX), x);
644 var yv = @as(@Vector(N, TY), y);
664 const xv = @as(@Vector(N, TX), x);
665 const yv = @as(@Vector(N, TY), y);
645666
646 var z0 = xv >> yv;
667 const z0 = xv >> yv;
647668 for (@as([N]TX, z0), 0..) |v, i| {
648669 try expect(x[i] >> y[i] == v);
649670 }
650 var z1 = xv << yv;
671 const z1 = xv << yv;
651672 for (@as([N]TX, z1), 0..) |v, i| {
652673 try expect(x[i] << y[i] == v);
653674 }
......@@ -657,10 +678,10 @@ test "vector shift operators" {
657678 const TX = @typeInfo(@TypeOf(x)).Array.child;
658679 const TY = @typeInfo(@TypeOf(y)).Array.child;
659680
660 var xv = @as(@Vector(N, TX), x);
661 var yv = @as(@Vector(N, TY), y);
681 const xv = @as(@Vector(N, TX), x);
682 const yv = @as(@Vector(N, TY), y);
662683
663 var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv);
684 const z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv);
664685 for (@as([N]TX, z), 0..) |v, i| {
665686 const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i];
666687 try expect(check == v);
......@@ -734,7 +755,7 @@ test "vector reduce operation" {
734755 const N = @typeInfo(@TypeOf(x)).Array.len;
735756 const TX = @typeInfo(@TypeOf(x)).Array.child;
736757
737 var r = @reduce(op, @as(@Vector(N, TX), x));
758 const r = @reduce(op, @as(@Vector(N, TX), x));
738759 switch (@typeInfo(TX)) {
739760 .Int, .Bool => try expect(expected == r),
740761 .Float => {
......@@ -892,7 +913,8 @@ test "mask parameter of @shuffle is comptime scope" {
892913 const __v4hi = @Vector(4, i16);
893914 var v4_a = __v4hi{ 0, 0, 0, 0 };
894915 var v4_b = __v4hi{ 0, 0, 0, 0 };
895 var shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){
916 _ = .{ &v4_a, &v4_b };
917 const shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){
896918 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
897919 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
898920 std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
......@@ -915,7 +937,8 @@ test "saturating add" {
915937 const u8x3 = @Vector(3, u8);
916938 var lhs = u8x3{ 255, 254, 1 };
917939 var rhs = u8x3{ 1, 2, 255 };
918 var result = lhs +| rhs;
940 _ = .{ &lhs, &rhs };
941 const result = lhs +| rhs;
919942 const expected = u8x3{ 255, 255, 255 };
920943 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));
921944 }
......@@ -923,7 +946,8 @@ test "saturating add" {
923946 const i8x3 = @Vector(3, i8);
924947 var lhs = i8x3{ 127, 126, 1 };
925948 var rhs = i8x3{ 1, 2, 127 };
926 var result = lhs +| rhs;
949 _ = .{ &lhs, &rhs };
950 const result = lhs +| rhs;
927951 const expected = i8x3{ 127, 127, 127 };
928952 try expect(mem.eql(i8, &@as([3]i8, expected), &@as([3]i8, result)));
929953 }
......@@ -947,7 +971,8 @@ test "saturating subtraction" {
947971 const u8x3 = @Vector(3, u8);
948972 var lhs = u8x3{ 0, 0, 0 };
949973 var rhs = u8x3{ 255, 255, 255 };
950 var result = lhs -| rhs;
974 _ = .{ &lhs, &rhs };
975 const result = lhs -| rhs;
951976 const expected = u8x3{ 0, 0, 0 };
952977 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));
953978 }
......@@ -973,7 +998,8 @@ test "saturating multiplication" {
973998 const u8x3 = @Vector(3, u8);
974999 var lhs = u8x3{ 2, 2, 2 };
9751000 var rhs = u8x3{ 255, 255, 255 };
976 var result = lhs *| rhs;
1001 _ = .{ &lhs, &rhs };
1002 const result = lhs *| rhs;
9771003 const expected = u8x3{ 255, 255, 255 };
9781004 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));
9791005 }
......@@ -997,7 +1023,8 @@ test "saturating shift-left" {
9971023 const u8x3 = @Vector(3, u8);
9981024 var lhs = u8x3{ 1, 1, 1 };
9991025 var rhs = u8x3{ 255, 255, 255 };
1000 var result = lhs <<| rhs;
1026 _ = .{ &lhs, &rhs };
1027 const result = lhs <<| rhs;
10011028 const expected = u8x3{ 255, 255, 255 };
10021029 try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result)));
10031030 }
......@@ -1040,29 +1067,33 @@ test "@addWithOverflow" {
10401067 {
10411068 var lhs = @Vector(4, u8){ 250, 250, 250, 250 };
10421069 var rhs = @Vector(4, u8){ 0, 5, 6, 10 };
1043 var overflow = @addWithOverflow(lhs, rhs)[1];
1044 var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 };
1070 _ = .{ &lhs, &rhs };
1071 const overflow = @addWithOverflow(lhs, rhs)[1];
1072 const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 };
10451073 try expectEqual(expected, overflow);
10461074 }
10471075 {
10481076 var lhs = @Vector(4, i8){ -125, -125, 125, 125 };
10491077 var rhs = @Vector(4, i8){ -3, -4, 2, 3 };
1050 var overflow = @addWithOverflow(lhs, rhs)[1];
1051 var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };
1078 _ = .{ &lhs, &rhs };
1079 const overflow = @addWithOverflow(lhs, rhs)[1];
1080 const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };
10521081 try expectEqual(expected, overflow);
10531082 }
10541083 {
10551084 var lhs = @Vector(4, u1){ 0, 0, 1, 1 };
10561085 var rhs = @Vector(4, u1){ 0, 1, 0, 1 };
1057 var overflow = @addWithOverflow(lhs, rhs)[1];
1058 var expected: @Vector(4, u1) = .{ 0, 0, 0, 1 };
1086 _ = .{ &lhs, &rhs };
1087 const overflow = @addWithOverflow(lhs, rhs)[1];
1088 const expected: @Vector(4, u1) = .{ 0, 0, 0, 1 };
10591089 try expectEqual(expected, overflow);
10601090 }
10611091 {
10621092 var lhs = @Vector(4, u0){ 0, 0, 0, 0 };
10631093 var rhs = @Vector(4, u0){ 0, 0, 0, 0 };
1064 var overflow = @addWithOverflow(lhs, rhs)[1];
1065 var expected: @Vector(4, u1) = .{ 0, 0, 0, 0 };
1094 _ = .{ &lhs, &rhs };
1095 const overflow = @addWithOverflow(lhs, rhs)[1];
1096 const expected: @Vector(4, u1) = .{ 0, 0, 0, 0 };
10661097 try expectEqual(expected, overflow);
10671098 }
10681099 }
......@@ -1084,15 +1115,17 @@ test "@subWithOverflow" {
10841115 {
10851116 var lhs = @Vector(2, u8){ 5, 5 };
10861117 var rhs = @Vector(2, u8){ 5, 6 };
1087 var overflow = @subWithOverflow(lhs, rhs)[1];
1088 var expected: @Vector(2, u1) = .{ 0, 1 };
1118 _ = .{ &lhs, &rhs };
1119 const overflow = @subWithOverflow(lhs, rhs)[1];
1120 const expected: @Vector(2, u1) = .{ 0, 1 };
10891121 try expectEqual(expected, overflow);
10901122 }
10911123 {
10921124 var lhs = @Vector(4, i8){ -120, -120, 120, 120 };
10931125 var rhs = @Vector(4, i8){ 8, 9, -7, -8 };
1094 var overflow = @subWithOverflow(lhs, rhs)[1];
1095 var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };
1126 _ = .{ &lhs, &rhs };
1127 const overflow = @subWithOverflow(lhs, rhs)[1];
1128 const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };
10961129 try expectEqual(expected, overflow);
10971130 }
10981131 }
......@@ -1113,8 +1146,9 @@ test "@mulWithOverflow" {
11131146 fn doTheTest() !void {
11141147 var lhs = @Vector(4, u8){ 10, 10, 10, 10 };
11151148 var rhs = @Vector(4, u8){ 25, 26, 0, 30 };
1116 var overflow = @mulWithOverflow(lhs, rhs)[1];
1117 var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };
1149 _ = .{ &lhs, &rhs };
1150 const overflow = @mulWithOverflow(lhs, rhs)[1];
1151 const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 };
11181152 try expectEqual(expected, overflow);
11191153 }
11201154 };
......@@ -1134,8 +1168,9 @@ test "@shlWithOverflow" {
11341168 fn doTheTest() !void {
11351169 var lhs = @Vector(4, u8){ 0, 1, 8, 255 };
11361170 var rhs = @Vector(4, u3){ 7, 7, 7, 7 };
1137 var overflow = @shlWithOverflow(lhs, rhs)[1];
1138 var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 };
1171 _ = .{ &lhs, &rhs };
1172 const overflow = @shlWithOverflow(lhs, rhs)[1];
1173 const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 };
11391174 try expectEqual(expected, overflow);
11401175 }
11411176 };
......@@ -1161,8 +1196,8 @@ test "loading the second vector from a slice of vectors" {
11611196 @Vector(2, u8){ 0, 1 },
11621197 @Vector(2, u8){ 2, 3 },
11631198 };
1164 var a: []const @Vector(2, u8) = &small_bases;
1165 var a4 = a[1][1];
1199 const a: []const @Vector(2, u8) = &small_bases;
1200 const a4 = a[1][1];
11661201 try expect(a4 == 3);
11671202}
11681203
......@@ -1183,6 +1218,7 @@ test "array of vectors is copied" {
11831218 Vec3{ -345, -311, 381 },
11841219 Vec3{ -661, -816, -575 },
11851220 };
1221 _ = &points;
11861222 var points2: [20]Vec3 = undefined;
11871223 points2[0..points.len].* = points;
11881224 try std.testing.expectEqual(points2[6], Vec3{ -345, -311, 381 });
......@@ -1244,6 +1280,7 @@ test "zero multiplicand" {
12441280
12451281 const zeros = @Vector(2, u32){ 0.0, 0.0 };
12461282 var ones = @Vector(2, u32){ 1.0, 1.0 };
1283 _ = &ones;
12471284
12481285 _ = (ones * zeros)[0];
12491286 _ = (zeros * zeros)[0];
......@@ -1266,6 +1303,7 @@ test "@intCast to u0" {
12661303 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
12671304
12681305 var zeros = @Vector(2, u32){ 0, 0 };
1306 _ = &zeros;
12691307 const casted = @as(@Vector(2, u0), @intCast(zeros));
12701308
12711309 _ = casted[0];
......@@ -1292,7 +1330,8 @@ test "array operands to shuffle are coerced to vectors" {
12921330 const mask = [5]i32{ -1, 0, 1, 2, 3 };
12931331
12941332 var a = [5]u32{ 3, 5, 7, 9, 0 };
1295 var b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask);
1333 _ = &a;
1334 const b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask);
12961335 try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b);
12971336}
12981337
......@@ -1320,6 +1359,7 @@ test "store packed vector element" {
13201359 var v = @Vector(4, u1){ 1, 1, 1, 1 };
13211360 try expectEqual(@Vector(4, u1){ 1, 1, 1, 1 }, v);
13221361 var index: usize = 0;
1362 _ = &index;
13231363 v[index] = 0;
13241364 try expectEqual(@Vector(4, u1){ 0, 1, 1, 1 }, v);
13251365}
......@@ -1337,6 +1377,7 @@ test "store to vector in slice" {
13371377 };
13381378 var s: []@Vector(3, f32) = &v;
13391379 var i: usize = 1;
1380 _ = &i;
13401381 s[i] = s[0];
13411382 try expectEqual(v[1], v[0]);
13421383}
......@@ -1378,6 +1419,7 @@ test "store vector with memset" {
13781419 var kc = @Vector(2, i4){ 2, 3 };
13791420 var kd = @Vector(2, u8){ 4, 5 };
13801421 var ke = @Vector(2, i9){ 6, 7 };
1422 _ = .{ &ka, &kb, &kc, &kd, &ke };
13811423 @memset(&a, ka);
13821424 @memset(&b, kb);
13831425 @memset(&c, kc);
......@@ -1410,6 +1452,7 @@ test "compare vectors with different element types" {
14101452
14111453 var a: @Vector(2, u8) = .{ 1, 2 };
14121454 var b: @Vector(2, u9) = .{ 3, 0 };
1455 _ = .{ &a, &b };
14131456 try expectEqual(@Vector(2, bool){ true, false }, a < b);
14141457}
14151458
......@@ -1465,8 +1508,9 @@ test "bitcast to vector with different child type" {
14651508 const VecB = @Vector(4, u32);
14661509
14671510 var vec_a = VecA{ 1, 1, 1, 1, 1, 1, 1, 1 };
1468 var vec_b: VecB = @bitCast(vec_a);
1469 var vec_c: VecA = @bitCast(vec_b);
1511 _ = &vec_a;
1512 const vec_b: VecB = @bitCast(vec_a);
1513 const vec_c: VecA = @bitCast(vec_b);
14701514 try expectEqual(vec_a, vec_c);
14711515 }
14721516 };
test/behavior/void.zig+3-1
......@@ -38,16 +38,18 @@ test "void optional" {
3838 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3939
4040 var x: ?void = {};
41 _ = &x;
4142 try expect(x != null);
4243}
4344
4445test "void array as a local variable initializer" {
4546 var x = [_]void{{}} ** 1004;
47 _ = &x[0];
4648 _ = x[0];
4749}
4850
4951const void_constant = {};
5052test "reference to void constants" {
5153 var a = void_constant;
52 _ = a;
54 _ = &a;
5355}
test/behavior/wasm.zig+1
......@@ -4,6 +4,7 @@ const builtin = @import("builtin");
44
55test "memory size and grow" {
66 var prev = @wasmMemorySize(0);
7 _ = &prev;
78 try expect(prev == @wasmMemoryGrow(0, 1));
89 try expect(prev + 1 == @wasmMemorySize(0));
910}
test/behavior/widening.zig+5
......@@ -15,6 +15,7 @@ test "integer widening" {
1515 var d: u64 = c;
1616 var e: u64 = d;
1717 var f: u128 = e;
18 _ = .{ &a, &b, &c, &d, &e, &f };
1819 try expect(f == a);
1920}
2021
......@@ -33,6 +34,7 @@ test "implicit unsigned integer to signed integer" {
3334
3435 var a: u8 = 250;
3536 var b: i16 = a;
37 _ = .{ &a, &b };
3638 try expect(b == 250);
3739}
3840
......@@ -47,10 +49,12 @@ test "float widening" {
4749 var b: f32 = a;
4850 var c: f64 = b;
4951 var d: f128 = c;
52 _ = .{ &a, &b, &c, &d };
5053 try expect(a == b);
5154 try expect(b == c);
5255 try expect(c == d);
5356 var e: f80 = c;
57 _ = &e;
5458 try expect(c == e);
5559}
5660
......@@ -63,6 +67,7 @@ test "float widening f16 to f128" {
6367
6468 var x: f16 = 12.34;
6569 var y: f128 = x;
70 _ = .{ &x, &y };
6671 try expect(x == y);
6772}
6873