authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-19 16:19:06+00:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-11-19 16:19:06+00:00
log6b1a823b2b30d9318c9877dbdbd3d02fa939fba0
tree6e5afdad2397ac7224119811583d19107b6e517a
parent325e0f5f0e8a9ce2540ec3ec5b7cbbecac15257a
parent9cf6c1ad11bb5f0247ff3458cba5f3bd156d1fb9
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #18017 from mlugg/var-never-mutated

compiler: add error for unnecessary use of 'var'

633 files changed, 3309 insertions(+), 2039 deletions(-)

doc/langref.html.in+121-94
......@@ -2609,16 +2609,17 @@ test "Basic vector usage" {
26092609
26102610test "Conversion between vectors, arrays, and slices" {
26112611 // Vectors and fixed-length arrays can be automatically assigned back and forth
2612 var arr1: [4]f32 = [_]f32{ 1.1, 3.2, 4.5, 5.6 };
2613 var vec: @Vector(4, f32) = arr1;
2614 var arr2: [4]f32 = vec;
2612 const arr1: [4]f32 = [_]f32{ 1.1, 3.2, 4.5, 5.6 };
2613 const vec: @Vector(4, f32) = arr1;
2614 const arr2: [4]f32 = vec;
26152615 try expectEqual(arr1, arr2);
26162616
26172617 // You can also assign from a slice with comptime-known length to a vector using .*
26182618 const vec2: @Vector(2, f32) = arr1[1..3].*;
26192619
2620 var slice: []const f32 = &arr1;
2621 var offset: u32 = 1;
2620 const slice: []const f32 = &arr1;
2621 var offset: u32 = 1; // var to make it runtime-known
2622 _ = &offset; // suppress 'var is never mutated' error
26222623 // To extract a comptime-known length from a runtime-known offset,
26232624 // first extract a new slice from the starting offset, then an array of
26242625 // comptime-known length
......@@ -2732,7 +2733,8 @@ test "pointer arithmetic with many-item pointer" {
27322733
27332734test "pointer arithmetic with slices" {
27342735 var array = [_]i32{ 1, 2, 3, 4 };
2735 var length: usize = 0;
2736 var length: usize = 0; // var to make it runtime-known
2737 _ = &length; // suppress 'var is never mutated' error
27362738 var slice = array[length..array.len];
27372739
27382740 try expect(slice[0] == 1);
......@@ -2759,7 +2761,8 @@ const expect = @import("std").testing.expect;
27592761
27602762test "pointer slicing" {
27612763 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
2762 var start: usize = 2;
2764 var start: usize = 2; // var to make it runtime-known
2765 _ = &start; // suppress 'var is never mutated' error
27632766 const slice = array[start..4];
27642767 try expect(slice.len == 2);
27652768
......@@ -2961,8 +2964,9 @@ const std = @import("std");
29612964const expect = std.testing.expect;
29622965
29632966test "allowzero" {
2964 var zero: usize = 0;
2965 var ptr: *allowzero i32 = @ptrFromInt(zero);
2967 var zero: usize = 0; // var to make to runtime-known
2968 _ = &zero; // suppress 'var is never mutated' error
2969 const ptr: *allowzero i32 = @ptrFromInt(zero);
29662970 try expect(@intFromPtr(ptr) == 0);
29672971}
29682972 {#code_end#}
......@@ -3006,6 +3010,7 @@ const expect = @import("std").testing.expect;
30063010test "basic slices" {
30073011 var array = [_]i32{ 1, 2, 3, 4 };
30083012 var known_at_runtime_zero: usize = 0;
3013 _ = &known_at_runtime_zero;
30093014 const slice = array[known_at_runtime_zero..array.len];
30103015 try expect(@TypeOf(slice) == []i32);
30113016 try expect(&slice[0] == &array[0]);
......@@ -3020,6 +3025,7 @@ test "basic slices" {
30203025 // to perform some optimisations like recognising a comptime-known length when
30213026 // the start position is only known at runtime.
30223027 var runtime_start: usize = 1;
3028 _ = &runtime_start;
30233029 const length = 2;
30243030 const array_ptr_len = array[runtime_start..][0..length];
30253031 try expect(@TypeOf(array_ptr_len) == *[length]i32);
......@@ -3056,7 +3062,8 @@ test "using slices for strings" {
30563062 var all_together: [100]u8 = undefined;
30573063 // You can use slice syntax with at least one runtime-known index on an
30583064 // array to convert an array into a slice.
3059 var start : usize = 0;
3065 var start: usize = 0;
3066 _ = &start;
30603067 const all_together_slice = all_together[start..];
30613068 // String concatenation example.
30623069 const hello_world = try fmt.bufPrint(all_together_slice, "{s} {s}", .{ hello, world });
......@@ -3075,6 +3082,7 @@ test "slice pointer" {
30753082 // A pointer to an array can be sliced just like an array:
30763083 var start: usize = 0;
30773084 var end: usize = 5;
3085 _ = .{ &start, &end };
30783086 const slice = ptr[start..end];
30793087 // The slice is mutable because we sliced a mutable pointer.
30803088 try expect(@TypeOf(slice) == []u8);
......@@ -3121,6 +3129,7 @@ const expect = std.testing.expect;
31213129test "0-terminated slicing" {
31223130 var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 };
31233131 var runtime_length: usize = 3;
3132 _ = &runtime_length;
31243133 const slice = array[0..runtime_length :0];
31253134
31263135 try expect(@TypeOf(slice) == [:0]u8);
......@@ -3143,6 +3152,7 @@ test "sentinel mismatch" {
31433152 // This does not match the indicated sentinel value of `0` and will lead
31443153 // to a runtime panic.
31453154 var runtime_length: usize = 2;
3155 _ = &runtime_length;
31463156 const slice = array[0..runtime_length :0];
31473157
31483158 _ = slice;
......@@ -3266,7 +3276,7 @@ test "linked list" {
32663276 // do this:
32673277 try expect(LinkedList(i32) == LinkedList(i32));
32683278
3269 var list = LinkedList(i32) {
3279 const list = LinkedList(i32){
32703280 .first = null,
32713281 .last = null,
32723282 .len = 0,
......@@ -3278,12 +3288,12 @@ test "linked list" {
32783288 const ListOfInts = LinkedList(i32);
32793289 try expect(ListOfInts == LinkedList(i32));
32803290
3281 var node = ListOfInts.Node {
3291 var node = ListOfInts.Node{
32823292 .prev = null,
32833293 .next = null,
32843294 .data = 1234,
32853295 };
3286 var list2 = LinkedList(i32) {
3296 const list2 = LinkedList(i32){
32873297 .first = &node,
32883298 .last = &node,
32893299 .len = 1,
......@@ -3372,13 +3382,13 @@ test "@bitCast between packed structs" {
33723382fn doTheTest() !void {
33733383 try expect(@sizeOf(Full) == 2);
33743384 try expect(@sizeOf(Divided) == 2);
3375 var full = Full{ .number = 0x1234 };
3376 var divided: Divided = @bitCast(full);
3385 const full = Full{ .number = 0x1234 };
3386 const divided: Divided = @bitCast(full);
33773387 try expect(divided.half1 == 0x34);
33783388 try expect(divided.quarter3 == 0x2);
33793389 try expect(divided.quarter4 == 0x1);
33803390
3381 var ordered: [2]u8 = @bitCast(full);
3391 const ordered: [2]u8 = @bitCast(full);
33823392 switch (native_endian) {
33833393 .big => {
33843394 try expect(ordered[0] == 0x12);
......@@ -3586,7 +3596,7 @@ const expect = std.testing.expect;
35863596const Point = struct {x: i32, y: i32};
35873597
35883598test "anonymous struct literal" {
3589 var pt: Point = .{
3599 const pt: Point = .{
35903600 .x = 13,
35913601 .y = 67,
35923602 };
......@@ -4051,14 +4061,14 @@ const Number = union {
40514061};
40524062
40534063test "anonymous union literal syntax" {
4054 var i: Number = .{.int = 42};
4055 var f = makeNumber();
4064 const i: Number = .{ .int = 42 };
4065 const f = makeNumber();
40564066 try expect(i.int == 42);
40574067 try expect(f.float == 12.34);
40584068}
40594069
40604070fn makeNumber() Number {
4061 return .{.float = 12.34};
4071 return .{ .float = 12.34 };
40624072}
40634073 {#code_end#}
40644074 {#header_close#}
......@@ -4098,7 +4108,7 @@ test "call foo" {
40984108test "access variable after block scope" {
40994109 {
41004110 var x: i32 = 1;
4101 _ = x;
4111 _ = &x;
41024112 }
41034113 x += 1;
41044114}
......@@ -4149,7 +4159,7 @@ test "separate scopes" {
41494159 }
41504160 {
41514161 var pi: bool = true;
4152 _ = pi;
4162 _ = &pi;
41534163 }
41544164}
41554165 {#code_end#}
......@@ -4423,7 +4433,7 @@ fn withSwitch(any: AnySlice) usize {
44234433}
44244434
44254435test "inline for and inline else similarity" {
4426 var any = AnySlice{ .c = "hello" };
4436 const any = AnySlice{ .c = "hello" };
44274437 try expect(withFor(any) == 5);
44284438 try expect(withSwitch(any) == 5);
44294439}
......@@ -4455,7 +4465,7 @@ fn getNum(u: U) u32 {
44554465}
44564466
44574467test "test" {
4458 var u = U{ .b = 42 };
4468 const u = U{ .b = 42 };
44594469 try expect(getNum(u) == 42);
44604470}
44614471 {#code_end#}
......@@ -4762,7 +4772,7 @@ test "multi object for" {
47624772}
47634773
47644774test "for reference" {
4765 var items = [_]i32 { 3, 4, 2 };
4775 var items = [_]i32{ 3, 4, 2 };
47664776
47674777 // Iterate over the slice by reference by
47684778 // specifying that the capture value is a pointer.
......@@ -4777,7 +4787,7 @@ test "for reference" {
47774787
47784788test "for else" {
47794789 // For allows an else attached to it, the same as a while loop.
4780 var items = [_]?i32 { 3, 4, null, 5 };
4790 const items = [_]?i32{ 3, 4, null, 5 };
47814791
47824792 // For loops can also be used as expressions.
47834793 // Similar to while loops, when you break from a for loop, the else branch is not evaluated.
......@@ -5347,7 +5357,7 @@ fn addFortyTwo(x: anytype) @TypeOf(x) {
53475357test "fn type inference" {
53485358 try expect(addFortyTwo(1) == 43);
53495359 try expect(@TypeOf(addFortyTwo(1)) == comptime_int);
5350 var y: i64 = 2;
5360 const y: i64 = 2;
53515361 try expect(addFortyTwo(y) == 44);
53525362 try expect(@TypeOf(addFortyTwo(y)) == i64);
53535363}
......@@ -5795,7 +5805,7 @@ fn getData() !u32 {
57955805}
57965806
57975807fn genFoos(allocator: Allocator, num: usize) ![]Foo {
5798 var foos = try allocator.alloc(Foo, num);
5808 const foos = try allocator.alloc(Foo, num);
57995809 errdefer allocator.free(foos);
58005810
58015811 for (foos, 0..) |*foo, i| {
......@@ -5833,7 +5843,7 @@ fn getData() !u32 {
58335843}
58345844
58355845fn genFoos(allocator: Allocator, num: usize) ![]Foo {
5836 var foos = try allocator.alloc(Foo, num);
5846 const foos = try allocator.alloc(Foo, num);
58375847 errdefer allocator.free(foos);
58385848
58395849 // Used to track how many foos have been initialized
......@@ -6325,13 +6335,13 @@ test "optional pointers" {
63256335 </p>
63266336 {#code_begin|test|test_type_coercion#}
63276337test "type coercion - variable declaration" {
6328 var a: u8 = 1;
6329 var b: u16 = a;
6338 const a: u8 = 1;
6339 const b: u16 = a;
63306340 _ = b;
63316341}
63326342
63336343test "type coercion - function call" {
6334 var a: u8 = 1;
6344 const a: u8 = 1;
63356345 foo(a);
63366346}
63376347
......@@ -6340,8 +6350,8 @@ fn foo(b: u16) void {
63406350}
63416351
63426352test "type coercion - @as builtin" {
6343 var a: u8 = 1;
6344 var b = @as(u16, a);
6353 const a: u8 = 1;
6354 const b = @as(u16, a);
63456355 _ = b;
63466356}
63476357 {#code_end#}
......@@ -6366,7 +6376,7 @@ test "type coercion - @as builtin" {
63666376 {#code_begin|test|test_no_op_casts#}
63676377test "type coercion - const qualification" {
63686378 var a: i32 = 1;
6369 var b: *i32 = &a;
6379 const b: *i32 = &a;
63706380 foo(b);
63716381}
63726382
......@@ -6399,26 +6409,26 @@ const expect = std.testing.expect;
63996409const mem = std.mem;
64006410
64016411test "integer widening" {
6402 var a: u8 = 250;
6403 var b: u16 = a;
6404 var c: u32 = b;
6405 var d: u64 = c;
6406 var e: u64 = d;
6407 var f: u128 = e;
6412 const a: u8 = 250;
6413 const b: u16 = a;
6414 const c: u32 = b;
6415 const d: u64 = c;
6416 const e: u64 = d;
6417 const f: u128 = e;
64086418 try expect(f == a);
64096419}
64106420
64116421test "implicit unsigned integer to signed integer" {
6412 var a: u8 = 250;
6413 var b: i16 = a;
6422 const a: u8 = 250;
6423 const b: i16 = a;
64146424 try expect(b == 250);
64156425}
64166426
64176427test "float widening" {
6418 var a: f16 = 12.34;
6419 var b: f32 = a;
6420 var c: f64 = b;
6421 var d: f128 = c;
6428 const a: f16 = 12.34;
6429 const b: f32 = a;
6430 const c: f64 = b;
6431 const d: f128 = c;
64226432 try expect(d == a);
64236433}
64246434 {#code_end#}
......@@ -6435,7 +6445,7 @@ test "float widening" {
64356445 {#code_begin|test_err|test_ambiguous_coercion#}
64366446// Compile time coercion of float to int
64376447test "implicit cast to comptime_int" {
6438 var f: f32 = 54.0 / 5;
6448 const f: f32 = 54.0 / 5;
64396449 _ = f;
64406450}
64416451 {#code_end#}
......@@ -6449,31 +6459,31 @@ const expect = std.testing.expect;
64496459// const modifier on the element type. Useful in particular for
64506460// String literals.
64516461test "*const [N]T to []const T" {
6452 var x1: []const u8 = "hello";
6453 var x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
6462 const x1: []const u8 = "hello";
6463 const x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
64546464 try expect(std.mem.eql(u8, x1, x2));
64556465
6456 var y: []const f32 = &[2]f32{ 1.2, 3.4 };
6466 const y: []const f32 = &[2]f32{ 1.2, 3.4 };
64576467 try expect(y[0] == 1.2);
64586468}
64596469
64606470// Likewise, it works when the destination type is an error union.
64616471test "*const [N]T to E![]const T" {
6462 var x1: anyerror![]const u8 = "hello";
6463 var x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
6472 const x1: anyerror![]const u8 = "hello";
6473 const x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
64646474 try expect(std.mem.eql(u8, try x1, try x2));
64656475
6466 var y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };
6476 const y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };
64676477 try expect((try y)[0] == 1.2);
64686478}
64696479
64706480// Likewise, it works when the destination type is an optional.
64716481test "*const [N]T to ?[]const T" {
6472 var x1: ?[]const u8 = "hello";
6473 var x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
6482 const x1: ?[]const u8 = "hello";
6483 const x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
64746484 try expect(std.mem.eql(u8, x1.?, x2.?));
64756485
6476 var y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
6486 const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
64776487 try expect(y.?[0] == 1.2);
64786488}
64796489
......@@ -6609,18 +6619,18 @@ const U2 = union(enum) {
66096619};
66106620
66116621test "coercion between unions and enums" {
6612 var u = U{ .two = 12.34 };
6613 var e: E = u; // coerce union to enum
6622 const u = U{ .two = 12.34 };
6623 const e: E = u; // coerce union to enum
66146624 try expect(e == E.two);
66156625
66166626 const three = E.three;
6617 var u_2: U = three; // coerce enum to union
6627 const u_2: U = three; // coerce enum to union
66186628 try expect(u_2 == E.three);
66196629
6620 var u_3: U = .three; // coerce enum literal to union
6630 const u_3: U = .three; // coerce enum literal to union
66216631 try expect(u_3 == E.three);
66226632
6623 var u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type.
6633 const u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type.
66246634 try expect(u_4.tag() == 1);
66256635
66266636 // The following example is invalid.
......@@ -6698,9 +6708,9 @@ const expect = std.testing.expect;
66986708const mem = std.mem;
66996709
67006710test "peer resolve int widening" {
6701 var a: i8 = 12;
6702 var b: i16 = 34;
6703 var c = a + b;
6711 const a: i8 = 12;
6712 const b: i16 = 34;
6713 const c = a + b;
67046714 try expect(c == 46);
67056715 try expect(@TypeOf(c) == i16);
67066716}
......@@ -6809,6 +6819,7 @@ export fn entry() void {
68096819 var x: void = {};
68106820 var y: void = {};
68116821 x = y;
6822 y = x;
68126823}
68136824 {#code_end#}
68146825 <p>When this turns into machine code, there is no code generated in the
......@@ -7121,6 +7132,7 @@ fn performFn(start_value: i32) i32 {
71217132// expect(performFn('w', 99) == 99);
71227133fn performFn(start_value: i32) i32 {
71237134 var result: i32 = start_value;
7135 _ = &result;
71247136 return result;
71257137}
71267138 {#end_syntax_block#}
......@@ -8664,8 +8676,9 @@ test "@hasDecl" {
86648676 </p>
86658677 {#code_begin|test_err|test_intCast_builtin|cast truncated bits#}
86668678test "integer cast panic" {
8667 var a: u16 = 0xabcd;
8668 var b: u8 = @intCast(a);
8679 var a: u16 = 0xabcd; // runtime-known
8680 _ = &a;
8681 const b: u8 = @intCast(a);
86698682 _ = b;
86708683}
86718684 {#code_end#}
......@@ -8825,7 +8838,7 @@ const expect = std.testing.expect;
88258838test "@wasmMemoryGrow" {
88268839 if (native_arch != .wasm32) return error.SkipZigTest;
88278840
8828 var prev = @wasmMemorySize(0);
8841 const prev = @wasmMemorySize(0);
88298842 try expect(prev == @wasmMemoryGrow(0, 1));
88308843 try expect(prev + 1 == @wasmMemorySize(0));
88318844}
......@@ -9560,8 +9573,8 @@ const std = @import("std");
95609573const expect = std.testing.expect;
95619574
95629575test "integer truncation" {
9563 var a: u16 = 0xabcd;
9564 var b: u8 = @truncate(a);
9576 const a: u16 = 0xabcd;
9577 const b: u8 = @truncate(a);
95659578 try expect(b == 0xcd);
95669579}
95679580 {#code_end#}
......@@ -9845,7 +9858,7 @@ comptime {
98459858 <p>At runtime:</p>
98469859 {#code_begin|exe_err|runtime_index_out_of_bounds#}
98479860pub fn main() void {
9848 var x = foo("hello");
9861 const x = foo("hello");
98499862 _ = x;
98509863}
98519864
......@@ -9858,7 +9871,7 @@ fn foo(x: []const u8) u8 {
98589871 <p>At compile-time:</p>
98599872 {#code_begin|test_err|test_comptime_invalid_cast|type 'u32' cannot represent integer value '-1'#}
98609873comptime {
9861 var value: i32 = -1;
9874 const value: i32 = -1;
98629875 const unsigned: u32 = @intCast(value);
98639876 _ = unsigned;
98649877}
......@@ -9868,8 +9881,9 @@ comptime {
98689881const std = @import("std");
98699882
98709883pub fn main() void {
9871 var value: i32 = -1;
9872 var unsigned: u32 = @intCast(value);
9884 var value: i32 = -1; // runtime-known
9885 _ = &value;
9886 const unsigned: u32 = @intCast(value);
98739887 std.debug.print("value: {}\n", .{unsigned});
98749888}
98759889 {#code_end#}
......@@ -9891,7 +9905,8 @@ comptime {
98919905const std = @import("std");
98929906
98939907pub fn main() void {
9894 var spartan_count: u16 = 300;
9908 var spartan_count: u16 = 300; // runtime-known
9909 _ = &spartan_count;
98959910 const byte: u8 = @intCast(spartan_count);
98969911 std.debug.print("value: {}\n", .{byte});
98979912}
......@@ -9975,7 +9990,7 @@ pub fn main() !void {
99759990 {#code_begin|exe|addWithOverflow_builtin#}
99769991const print = @import("std").debug.print;
99779992pub fn main() void {
9978 var byte: u8 = 255;
9993 const byte: u8 = 255;
99799994
99809995 const ov = @addWithOverflow(byte, 10);
99819996 if (ov[1] != 0) {
......@@ -10025,8 +10040,9 @@ comptime {
1002510040const std = @import("std");
1002610041
1002710042pub fn main() void {
10028 var x: u8 = 0b01010101;
10029 var y = @shlExact(x, 2);
10043 var x: u8 = 0b01010101; // runtime-known
10044 _ = &x;
10045 const y = @shlExact(x, 2);
1003010046 std.debug.print("value: {}\n", .{y});
1003110047}
1003210048 {#code_end#}
......@@ -10044,8 +10060,9 @@ comptime {
1004410060const std = @import("std");
1004510061
1004610062pub fn main() void {
10047 var x: u8 = 0b10101010;
10048 var y = @shrExact(x, 2);
10063 var x: u8 = 0b10101010; // runtime-known
10064 _ = &x;
10065 const y = @shrExact(x, 2);
1004910066 std.debug.print("value: {}\n", .{y});
1005010067}
1005110068 {#code_end#}
......@@ -10067,7 +10084,8 @@ const std = @import("std");
1006710084pub fn main() void {
1006810085 var a: u32 = 1;
1006910086 var b: u32 = 0;
10070 var c = a / b;
10087 _ = .{ &a, &b };
10088 const c = a / b;
1007110089 std.debug.print("value: {}\n", .{c});
1007210090}
1007310091 {#code_end#}
......@@ -10089,7 +10107,8 @@ const std = @import("std");
1008910107pub fn main() void {
1009010108 var a: u32 = 10;
1009110109 var b: u32 = 0;
10092 var c = a % b;
10110 _ = .{ &a, &b };
10111 const c = a % b;
1009310112 std.debug.print("value: {}\n", .{c});
1009410113}
1009510114 {#code_end#}
......@@ -10111,7 +10130,8 @@ const std = @import("std");
1011110130pub fn main() void {
1011210131 var a: u32 = 10;
1011310132 var b: u32 = 3;
10114 var c = @divExact(a, b);
10133 _ = .{ &a, &b };
10134 const c = @divExact(a, b);
1011510135 std.debug.print("value: {}\n", .{c});
1011610136}
1011710137 {#code_end#}
......@@ -10131,7 +10151,8 @@ const std = @import("std");
1013110151
1013210152pub fn main() void {
1013310153 var optional_number: ?i32 = null;
10134 var number = optional_number.?;
10154 _ = &optional_number;
10155 const number = optional_number.?;
1013510156 std.debug.print("value: {}\n", .{number});
1013610157}
1013710158 {#code_end#}
......@@ -10212,9 +10233,10 @@ comptime {
1021210233const std = @import("std");
1021310234
1021410235pub fn main() void {
10215 var err = error.AnError;
10236 const err = error.AnError;
1021610237 var number = @intFromError(err) + 500;
10217 var invalid_err = @errorFromInt(number);
10238 _ = &number;
10239 const invalid_err = @errorFromInt(number);
1021810240 std.debug.print("value: {}\n", .{invalid_err});
1021910241}
1022010242 {#code_end#}
......@@ -10245,7 +10267,8 @@ const Foo = enum {
1024510267
1024610268pub fn main() void {
1024710269 var a: u2 = 3;
10248 var b: Foo = @enumFromInt(a);
10270 _ = &a;
10271 const b: Foo = @enumFromInt(a);
1024910272 std.debug.print("value: {s}\n", .{@tagName(b)});
1025010273}
1025110274 {#code_end#}
......@@ -10402,17 +10425,18 @@ fn bar(f: *Foo) void {
1040210425 <p>At compile-time:</p>
1040310426 {#code_begin|test_err|test_comptime_out_of_bounds_float_to_integer_cast|float value '4294967296' cannot be stored in integer type 'i32'#}
1040410427comptime {
10405 const float: f32 = 4294967296;
10406 const int: i32 = @intFromFloat(float);
10407 _ = int;
10428 const float: f32 = 4294967296;
10429 const int: i32 = @intFromFloat(float);
10430 _ = int;
1040810431}
1040910432 {#code_end#}
1041010433 <p>At runtime:</p>
1041110434 {#code_begin|exe_err|runtime_out_of_bounds_float_to_integer_cast#}
1041210435pub fn main() void {
10413 var float: f32 = 4294967296;
10414 var int: i32 = @intFromFloat(float);
10415 _ = int;
10436 var float: f32 = 4294967296; // runtime-known
10437 _ = &float;
10438 const int: i32 = @intFromFloat(float);
10439 _ = int;
1041610440}
1041710441 {#code_end#}
1041810442 {#header_close#}
......@@ -10435,7 +10459,8 @@ comptime {
1043510459 {#code_begin|exe_err|runtime_invalid_null_pointer_cast#}
1043610460pub fn main() void {
1043710461 var opt_ptr: ?*i32 = null;
10438 var ptr: *i32 = @ptrCast(opt_ptr);
10462 _ = &opt_ptr;
10463 const ptr: *i32 = @ptrCast(opt_ptr);
1043910464 _ = ptr;
1044010465}
1044110466 {#code_end#}
......@@ -11120,7 +11145,9 @@ int foo(void) {
1112011145 {#code_begin|syntax|macro#}
1112111146pub export fn foo() c_int {
1112211147 var a: c_int = 1;
11148 _ = &a;
1112311149 var b: c_int = 2;
11150 _ = &b;
1112411151 return a + b;
1112511152}
1112611153pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected token .Equal"); // macro.c:1:9
lib/build_runner.zig+1-1
......@@ -24,7 +24,7 @@ pub fn main() !void {
2424 };
2525 const arena = thread_safe_arena.allocator();
2626
27 var args = try process.argsAlloc(arena);
27 const args = try process.argsAlloc(arena);
2828
2929 // skip my own exe name
3030 var arg_idx: usize = 1;
lib/compiler_rt/absvdi2_test.zig+1-1
......@@ -3,7 +3,7 @@ const testing = @import("std").testing;
33const __absvdi2 = @import("absvdi2.zig").__absvdi2;
44
55fn test__absvdi2(a: i64, expected: i64) !void {
6 var result = __absvdi2(a);
6 const result = __absvdi2(a);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/absvsi2_test.zig+1-1
......@@ -3,7 +3,7 @@ const testing = @import("std").testing;
33const __absvsi2 = @import("absvsi2.zig").__absvsi2;
44
55fn test__absvsi2(a: i32, expected: i32) !void {
6 var result = __absvsi2(a);
6 const result = __absvsi2(a);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/absvti2_test.zig+1-1
......@@ -3,7 +3,7 @@ const testing = @import("std").testing;
33const __absvti2 = @import("absvti2.zig").__absvti2;
44
55fn test__absvti2(a: i128, expected: i128) !void {
6 var result = __absvti2(a);
6 const result = __absvti2(a);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/addo.zig+1-1
......@@ -18,7 +18,7 @@ comptime {
1818inline fn addoXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
1919 @setRuntimeSafety(builtin.is_test);
2020 overflow.* = 0;
21 var sum: ST = a +% b;
21 const sum: ST = a +% b;
2222 // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract
2323 // Let sum = a +% b == a + b + carry == wraparound addition.
2424 // Overflow in a+b+carry occurs, iff a and b have opposite signs
lib/compiler_rt/addodi4_test.zig+2-2
......@@ -6,8 +6,8 @@ const math = std.math;
66fn test__addodi4(a: i64, b: i64) !void {
77 var result_ov: c_int = undefined;
88 var expected_ov: c_int = undefined;
9 var result = addv.__addodi4(a, b, &result_ov);
10 var expected: i64 = simple_addodi4(a, b, &expected_ov);
9 const result = addv.__addodi4(a, b, &result_ov);
10 const expected: i64 = simple_addodi4(a, b, &expected_ov);
1111 try testing.expectEqual(expected, result);
1212 try testing.expectEqual(expected_ov, result_ov);
1313}
lib/compiler_rt/addosi4_test.zig+2-2
......@@ -4,8 +4,8 @@ const testing = @import("std").testing;
44fn test__addosi4(a: i32, b: i32) !void {
55 var result_ov: c_int = undefined;
66 var expected_ov: c_int = undefined;
7 var result = addv.__addosi4(a, b, &result_ov);
8 var expected: i32 = simple_addosi4(a, b, &expected_ov);
7 const result = addv.__addosi4(a, b, &result_ov);
8 const expected: i32 = simple_addosi4(a, b, &expected_ov);
99 try testing.expectEqual(expected, result);
1010 try testing.expectEqual(expected_ov, result_ov);
1111}
lib/compiler_rt/addoti4_test.zig+2-2
......@@ -6,8 +6,8 @@ const math = std.math;
66fn test__addoti4(a: i128, b: i128) !void {
77 var result_ov: c_int = undefined;
88 var expected_ov: c_int = undefined;
9 var result = addv.__addoti4(a, b, &result_ov);
10 var expected: i128 = simple_addoti4(a, b, &expected_ov);
9 const result = addv.__addoti4(a, b, &result_ov);
10 const expected: i128 = simple_addoti4(a, b, &expected_ov);
1111 try testing.expectEqual(expected, result);
1212 try testing.expectEqual(expected_ov, result_ov);
1313}
lib/compiler_rt/bswapdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");
22const testing = @import("std").testing;
33
44fn test__bswapdi2(a: u64, expected: u64) !void {
5 var result = bswap.__bswapdi2(a);
5 const result = bswap.__bswapdi2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/bswapsi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");
22const testing = @import("std").testing;
33
44fn test__bswapsi2(a: u32, expected: u32) !void {
5 var result = bswap.__bswapsi2(a);
5 const result = bswap.__bswapsi2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/bswapti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");
22const testing = @import("std").testing;
33
44fn test__bswapti2(a: u128, expected: u128) !void {
5 var result = bswap.__bswapti2(a);
5 const result = bswap.__bswapti2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/ceil.zig+1-1
......@@ -32,7 +32,7 @@ pub fn __ceilh(x: f16) callconv(.C) f16 {
3232
3333pub fn ceilf(x: f32) callconv(.C) f32 {
3434 var u: u32 = @bitCast(x);
35 var e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
35 const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
3636 var m: u32 = undefined;
3737
3838 // TODO: Shouldn't need this explicit check.
lib/compiler_rt/clzdi2_test.zig+2-2
......@@ -2,8 +2,8 @@ const clz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__clzdi2(a: u64, expected: i64) !void {
5 var x: i64 = @bitCast(a);
6 var result = clz.__clzdi2(x);
5 const x: i64 = @bitCast(a);
6 const result = clz.__clzdi2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/clzti2_test.zig+2-2
......@@ -2,8 +2,8 @@ const clz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__clzti2(a: u128, expected: i64) !void {
5 var x: i128 = @bitCast(a);
6 var result = clz.__clzti2(x);
5 const x: i128 = @bitCast(a);
6 const result = clz.__clzti2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/cmpdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__cmpdi2(a: i64, b: i64, expected: i64) !void {
5 var result = cmp.__cmpdi2(a, b);
5 const result = cmp.__cmpdi2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/cmpsi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__cmpsi2(a: i32, b: i32, expected: i32) !void {
5 var result = cmp.__cmpsi2(a, b);
5 const result = cmp.__cmpsi2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/cmpti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__cmpti2(a: i128, b: i128, expected: i128) !void {
5 var result = cmp.__cmpti2(a, b);
5 const result = cmp.__cmpti2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/ctzdi2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzdi2(a: u64, expected: i32) !void {
5 var x: i64 = @bitCast(a);
6 var result = ctz.__ctzdi2(x);
5 const x: i64 = @bitCast(a);
6 const result = ctz.__ctzdi2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/ctzsi2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzsi2(a: u32, expected: i32) !void {
5 var x: i32 = @bitCast(a);
6 var result = ctz.__ctzsi2(x);
5 const x: i32 = @bitCast(a);
6 const result = ctz.__ctzsi2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/ctzti2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzti2(a: u128, expected: i32) !void {
5 var x: i128 = @bitCast(a);
6 var result = ctz.__ctzti2(x);
5 const x: i128 = @bitCast(a);
6 const result = ctz.__ctzti2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/divc3_test.zig+20-20
......@@ -19,20 +19,20 @@ test {
1919
2020fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void {
2121 {
22 var a: T = 1.0;
23 var b: T = 0.0;
24 var c: T = -1.0;
25 var d: T = 0.0;
22 const a: T = 1.0;
23 const b: T = 0.0;
24 const c: T = -1.0;
25 const d: T = 0.0;
2626
2727 const result = f(a, b, c, d);
2828 try expect(result.real == -1.0);
2929 try expect(result.imag == 0.0);
3030 }
3131 {
32 var a: T = 1.0;
33 var b: T = 0.0;
34 var c: T = -4.0;
35 var d: T = 0.0;
32 const a: T = 1.0;
33 const b: T = 0.0;
34 const c: T = -4.0;
35 const d: T = 0.0;
3636
3737 const result = f(a, b, c, d);
3838 try expect(result.real == -0.25);
......@@ -41,10 +41,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
4141 {
4242 // if the first operand is an infinity and the second operand is a finite number, then the
4343 // result of the / operator is an infinity;
44 var a: T = -math.inf(T);
45 var b: T = 0.0;
46 var c: T = -4.0;
47 var d: T = 1.0;
44 const a: T = -math.inf(T);
45 const b: T = 0.0;
46 const c: T = -4.0;
47 const d: T = 1.0;
4848
4949 const result = f(a, b, c, d);
5050 try expect(result.real == math.inf(T));
......@@ -53,10 +53,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
5353 {
5454 // if the first operand is a finite number and the second operand is an infinity, then the
5555 // result of the / operator is a zero;
56 var a: T = 17.2;
57 var b: T = 0.0;
58 var c: T = -math.inf(T);
59 var d: T = 0.0;
56 const a: T = 17.2;
57 const b: T = 0.0;
58 const c: T = -math.inf(T);
59 const d: T = 0.0;
6060
6161 const result = f(a, b, c, d);
6262 try expect(result.real == -0.0);
......@@ -65,10 +65,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
6565 {
6666 // if the first operand is a nonzero finite number or an infinity and the second operand is
6767 // a zero, then the result of the / operator is an infinity
68 var a: T = 1.1;
69 var b: T = 0.1;
70 var c: T = 0.0;
71 var d: T = 0.0;
68 const a: T = 1.1;
69 const b: T = 0.1;
70 const c: T = 0.0;
71 const d: T = 0.0;
7272
7373 const result = f(a, b, c, d);
7474 try expect(result.real == math.inf(T));
lib/compiler_rt/divxf3.zig+2-2
......@@ -162,7 +162,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
162162 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
163163 // Right shift the quotient if it falls in the [1,2) range and adjust the
164164 // exponent accordingly.
165 var quotient: u64 = if (quotient128 < (integerBit << 1)) b: {
165 const quotient: u64 = if (quotient128 < (integerBit << 1)) b: {
166166 quotientExponent -= 1;
167167 break :b @intCast(quotient128);
168168 } else @intCast(quotient128 >> 1);
......@@ -177,7 +177,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
177177 //
178178 // If r is greater than 1/2 ulp(q)*b, then q rounds up. Otherwise, we
179179 // already have the correct result. The exact halfway case cannot occur.
180 var residual: u64 = -%(quotient *% q63b);
180 const residual: u64 = -%(quotient *% q63b);
181181
182182 const writtenExponent = quotientExponent + exponentBias;
183183 if (writtenExponent >= maxExponent) {
lib/compiler_rt/emutls.zig+11-11
......@@ -57,8 +57,8 @@ const simple_allocator = struct {
5757
5858 /// Resize a slice.
5959 pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T {
60 var c_ptr: *anyopaque = @ptrCast(slice.ptr);
61 var new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort()));
60 const c_ptr: *anyopaque = @ptrCast(slice.ptr);
61 const new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort()));
6262 return new_array[0..len];
6363 }
6464
......@@ -78,7 +78,7 @@ const ObjectArray = struct {
7878
7979 /// create a new ObjectArray with n slots. must call deinit() to deallocate.
8080 pub fn init(n: usize) *ObjectArray {
81 var array = simple_allocator.alloc(ObjectArray);
81 const array = simple_allocator.alloc(ObjectArray);
8282
8383 array.* = ObjectArray{
8484 .slots = simple_allocator.allocSlice(?ObjectPointer, n),
......@@ -166,7 +166,7 @@ const current_thread_storage = struct {
166166 const size = @max(16, index);
167167
168168 // create a new array and store it.
169 var array: *ObjectArray = ObjectArray.init(size);
169 const array: *ObjectArray = ObjectArray.init(size);
170170 current_thread_storage.setspecific(array);
171171 return array;
172172 }
......@@ -304,13 +304,13 @@ const emutls_control = extern struct {
304304test "simple_allocator" {
305305 if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;
306306
307 var data1: *[64]u8 = simple_allocator.alloc([64]u8);
307 const data1: *[64]u8 = simple_allocator.alloc([64]u8);
308308 defer simple_allocator.free(data1);
309309 for (data1) |*c| {
310310 c.* = 0xff;
311311 }
312312
313 var data2: [*]u8 = simple_allocator.advancedAlloc(@alignOf(u8), 64);
313 const data2: [*]u8 = simple_allocator.advancedAlloc(@alignOf(u8), 64);
314314 defer simple_allocator.free(data2);
315315 for (data2[0..63]) |*c| {
316316 c.* = 0xff;
......@@ -324,7 +324,7 @@ test "__emutls_get_address zeroed" {
324324 try expect(ctl.object.index == 0);
325325
326326 // retrieve a variable from ctl
327 var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
327 const x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
328328 try expect(ctl.object.index != 0); // index has been allocated for this ctl
329329 try expect(x.* == 0); // storage has been zeroed
330330
......@@ -332,7 +332,7 @@ test "__emutls_get_address zeroed" {
332332 x.* = 1234;
333333
334334 // retrieve a variable from ctl (same ctl)
335 var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
335 const y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
336336
337337 try expect(y.* == 1234); // same content that x.*
338338 try expect(x == y); // same pointer
......@@ -345,7 +345,7 @@ test "__emutls_get_address with default_value" {
345345 var ctl = emutls_control.init(usize, &value);
346346 try expect(ctl.object.index == 0);
347347
348 var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
348 const x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
349349 try expect(ctl.object.index != 0);
350350 try expect(x.* == 5678); // storage initialized with default value
351351
......@@ -354,7 +354,7 @@ test "__emutls_get_address with default_value" {
354354
355355 try expect(value == 5678); // the default value didn't change
356356
357 var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
357 const y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
358358 try expect(y.* == 9012); // the modified storage persists
359359}
360360
......@@ -364,7 +364,7 @@ test "test default_value with differents sizes" {
364364 const testType = struct {
365365 fn _testType(comptime T: type, value: T) !void {
366366 var ctl = emutls_control.init(T, &value);
367 var x = ctl.get_typed_pointer(T);
367 const x = ctl.get_typed_pointer(T);
368368 try expect(x.* == value);
369369 }
370370 }._testType;
lib/compiler_rt/exp.zig+1-1
......@@ -117,7 +117,7 @@ pub fn exp(x_: f64) callconv(.C) f64 {
117117 const P5: f64 = 4.13813679705723846039e-08;
118118
119119 var x = x_;
120 var ux: u64 = @bitCast(x);
120 const ux: u64 = @bitCast(x);
121121 var hx = ux >> 32;
122122 const sign: i32 = @intCast(hx >> 31);
123123 hx &= 0x7FFFFFFF;
lib/compiler_rt/exp2.zig+1-1
......@@ -38,7 +38,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
3838 const P3: f32 = 0x1.c6b348p-5;
3939 const P4: f32 = 0x1.3b2c9cp-7;
4040
41 var u: u32 = @bitCast(x);
41 const u: u32 = @bitCast(x);
4242 const ix = u & 0x7FFFFFFF;
4343
4444 // |x| > 126
lib/compiler_rt/ffsdi2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ffsdi2(a: u64, expected: i32) !void {
5 var x = @as(i64, @bitCast(a));
6 var result = ffs.__ffsdi2(x);
5 const x = @as(i64, @bitCast(a));
6 const result = ffs.__ffsdi2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/ffssi2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ffssi2(a: u32, expected: i32) !void {
5 var x = @as(i32, @bitCast(a));
6 var result = ffs.__ffssi2(x);
5 const x = @as(i32, @bitCast(a));
6 const result = ffs.__ffssi2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/ffsti2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ffsti2(a: u128, expected: i32) !void {
5 var x = @as(i128, @bitCast(a));
6 var result = ffs.__ffsti2(x);
5 const x = @as(i128, @bitCast(a));
6 const result = ffs.__ffsti2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/float_from_int.zig+3-3
......@@ -18,12 +18,12 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
1818 const max_exp = exp_bias;
1919
2020 // Sign
21 var abs_val = if (@TypeOf(x) == comptime_int or @typeInfo(@TypeOf(x)).Int.signedness == .signed) @abs(x) else x;
21 const abs_val = if (@TypeOf(x) == comptime_int or @typeInfo(@TypeOf(x)).Int.signedness == .signed) @abs(x) else x;
2222 const sign_bit = if (x < 0) @as(uT, 1) << (float_bits - 1) else 0;
2323 var result: uT = sign_bit;
2424
2525 // Compute significand
26 var exp = int_bits - @clz(abs_val) - 1;
26 const exp = int_bits - @clz(abs_val) - 1;
2727 if (int_bits <= fractional_bits or exp <= fractional_bits) {
2828 const shift_amt = fractional_bits - @as(math.Log2Int(uT), @intCast(exp));
2929
......@@ -31,7 +31,7 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
3131 result = @as(uT, @intCast(abs_val)) << shift_amt;
3232 result ^= implicit_bit; // Remove implicit integer bit
3333 } else {
34 var shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits);
34 const shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits);
3535 const exact_tie: bool = @ctz(abs_val) == shift_amt - 1;
3636
3737 // Shift down result and remove implicit integer bit
lib/compiler_rt/fma.zig+16-16
......@@ -59,13 +59,13 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 {
5959 }
6060
6161 const x1 = math.frexp(x);
62 var ex = x1.exponent;
63 var xs = x1.significand;
62 const ex = x1.exponent;
63 const xs = x1.significand;
6464 const x2 = math.frexp(y);
65 var ey = x2.exponent;
66 var ys = x2.significand;
65 const ey = x2.exponent;
66 const ys = x2.significand;
6767 const x3 = math.frexp(z);
68 var ez = x3.exponent;
68 const ez = x3.exponent;
6969 var zs = x3.significand;
7070
7171 var spread = ex + ey - ez;
......@@ -118,13 +118,13 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.C) f128 {
118118 }
119119
120120 const x1 = math.frexp(x);
121 var ex = x1.exponent;
122 var xs = x1.significand;
121 const ex = x1.exponent;
122 const xs = x1.significand;
123123 const x2 = math.frexp(y);
124 var ey = x2.exponent;
125 var ys = x2.significand;
124 const ey = x2.exponent;
125 const ys = x2.significand;
126126 const x3 = math.frexp(z);
127 var ez = x3.exponent;
127 const ez = x3.exponent;
128128 var zs = x3.significand;
129129
130130 var spread = ex + ey - ez;
......@@ -181,15 +181,15 @@ fn dd_mul(a: f64, b: f64) dd {
181181 var p = a * split;
182182 var ha = a - p;
183183 ha += p;
184 var la = a - ha;
184 const la = a - ha;
185185
186186 p = b * split;
187187 var hb = b - p;
188188 hb += p;
189 var lb = b - hb;
189 const lb = b - hb;
190190
191191 p = ha * hb;
192 var q = ha * lb + la * hb;
192 const q = ha * lb + la * hb;
193193
194194 ret.hi = p + q;
195195 ret.lo = p - ret.hi + q + la * lb;
......@@ -301,15 +301,15 @@ fn dd_mul128(a: f128, b: f128) dd128 {
301301 var p = a * split;
302302 var ha = a - p;
303303 ha += p;
304 var la = a - ha;
304 const la = a - ha;
305305
306306 p = b * split;
307307 var hb = b - p;
308308 hb += p;
309 var lb = b - hb;
309 const lb = b - hb;
310310
311311 p = ha * hb;
312 var q = ha * lb + la * hb;
312 const q = ha * lb + la * hb;
313313
314314 ret.hi = p + q;
315315 ret.lo = p - ret.hi + q + la * lb;
lib/compiler_rt/fmod.zig+8-8
......@@ -81,13 +81,13 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
8181 if (expB == 0) expB = normalize(f80, &bRep);
8282
8383 var highA: u64 = 0;
84 var highB: u64 = 0;
84 const highB: u64 = 0;
8585 var lowA: u64 = @truncate(aRep);
86 var lowB: u64 = @truncate(bRep);
86 const lowB: u64 = @truncate(bRep);
8787
8888 while (expA > expB) : (expA -= 1) {
8989 var high = highA -% highB;
90 var low = lowA -% lowB;
90 const low = lowA -% lowB;
9191 if (lowA < lowB) {
9292 high -%= 1;
9393 }
......@@ -104,7 +104,7 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
104104 }
105105
106106 var high = highA -% highB;
107 var low = lowA -% lowB;
107 const low = lowA -% lowB;
108108 if (lowA < lowB) {
109109 high -%= 1;
110110 }
......@@ -194,13 +194,13 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
194194
195195 // OR in extra non-stored mantissa digit
196196 var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
197 var highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
197 const highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
198198 var lowA: u64 = aPtr_u64[low_index];
199 var lowB: u64 = bPtr_u64[low_index];
199 const lowB: u64 = bPtr_u64[low_index];
200200
201201 while (expA > expB) : (expA -= 1) {
202202 var high = highA -% highB;
203 var low = lowA -% lowB;
203 const low = lowA -% lowB;
204204 if (lowA < lowB) {
205205 high -%= 1;
206206 }
......@@ -217,7 +217,7 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
217217 }
218218
219219 var high = highA -% highB;
220 var low = lowA -% lowB;
220 const low = lowA -% lowB;
221221 if (lowA < lowB) {
222222 high -= 1;
223223 }
lib/compiler_rt/mulc3.zig+1-1
......@@ -25,7 +25,7 @@ pub inline fn mulc3(comptime T: type, a_in: T, b_in: T, c_in: T, d_in: T) Comple
2525 const zero: T = 0.0;
2626 const one: T = 1.0;
2727
28 var z = Complex(T){
28 const z: Complex(T) = .{
2929 .real = ac - bd,
3030 .imag = ad + bc,
3131 };
lib/compiler_rt/mulc3_test.zig+16-16
......@@ -19,20 +19,20 @@ test {
1919
2020fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void {
2121 {
22 var a: T = 1.0;
23 var b: T = 0.0;
24 var c: T = -1.0;
25 var d: T = 0.0;
22 const a: T = 1.0;
23 const b: T = 0.0;
24 const c: T = -1.0;
25 const d: T = 0.0;
2626
2727 const result = f(a, b, c, d);
2828 try expect(result.real == -1.0);
2929 try expect(result.imag == 0.0);
3030 }
3131 {
32 var a: T = 1.0;
33 var b: T = 0.0;
34 var c: T = -4.0;
35 var d: T = 0.0;
32 const a: T = 1.0;
33 const b: T = 0.0;
34 const c: T = -4.0;
35 const d: T = 0.0;
3636
3737 const result = f(a, b, c, d);
3838 try expect(result.real == -4.0);
......@@ -41,10 +41,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
4141 {
4242 // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,
4343 // then the result of the * operator is an infinity;
44 var a: T = math.inf(T);
45 var b: T = -math.inf(T);
46 var c: T = 1.0;
47 var d: T = 0.0;
44 const a: T = math.inf(T);
45 const b: T = -math.inf(T);
46 const c: T = 1.0;
47 const d: T = 0.0;
4848
4949 const result = f(a, b, c, d);
5050 try expect(result.real == math.inf(T));
......@@ -53,10 +53,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
5353 {
5454 // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,
5555 // then the result of the * operator is an infinity;
56 var a: T = math.inf(T);
57 var b: T = -1.0;
58 var c: T = 1.0;
59 var d: T = math.inf(T);
56 const a: T = math.inf(T);
57 const b: T = -1.0;
58 const c: T = 1.0;
59 const d: T = math.inf(T);
6060
6161 const result = f(a, b, c, d);
6262 try expect(result.real == math.inf(T));
lib/compiler_rt/mulo.zig+2-2
......@@ -20,7 +20,7 @@ comptime {
2020inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
2121 overflow.* = 0;
2222 const min = math.minInt(ST);
23 var res: ST = a *% b;
23 const res: ST = a *% b;
2424 // Hacker's Delight section Overflow subsection Multiplication
2525 // case a=-2^{31}, b=-1 problem, because
2626 // on some machines a*b = -2^{31} with overflow
......@@ -41,7 +41,7 @@ inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int)
4141 };
4242 const min = math.minInt(ST);
4343 const max = math.maxInt(ST);
44 var res: EST = @as(EST, a) * @as(EST, b);
44 const res: EST = @as(EST, a) * @as(EST, b);
4545 //invariant: -2^{bitwidth(EST)} < res < 2^{bitwidth(EST)-1}
4646 if (res < min or max < res)
4747 overflow.* = 1;
lib/compiler_rt/negdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const neg = @import("negXi2.zig");
22const testing = @import("std").testing;
33
44fn test__negdi2(a: i64, expected: i64) !void {
5 var result = neg.__negdi2(a);
5 const result = neg.__negdi2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/negsi2_test.zig+1-1
......@@ -5,7 +5,7 @@ const testing = std.testing;
55const print = std.debug.print;
66
77fn test__negsi2(a: i32, expected: i32) !void {
8 var result = neg.__negsi2(a);
8 const result = neg.__negsi2(a);
99 try testing.expectEqual(expected, result);
1010}
1111
lib/compiler_rt/negti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const neg = @import("negXi2.zig");
22const testing = @import("std").testing;
33
44fn test__negti2(a: i128, expected: i128) !void {
5 var result = neg.__negti2(a);
5 const result = neg.__negti2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/negvdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const negv = @import("negv.zig");
22const testing = @import("std").testing;
33
44fn test__negvdi2(a: i64, expected: i64) !void {
5 var result = negv.__negvdi2(a);
5 const result = negv.__negvdi2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/negvsi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const negv = @import("negv.zig");
22const testing = @import("std").testing;
33
44fn test__negvsi2(a: i32, expected: i32) !void {
5 var result = negv.__negvsi2(a);
5 const result = negv.__negvsi2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/negvti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const negv = @import("negv.zig");
22const testing = @import("std").testing;
33
44fn test__negvti2(a: i128, expected: i128) !void {
5 var result = negv.__negvti2(a);
5 const result = negv.__negvti2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/paritydi2_test.zig+3-3
......@@ -13,8 +13,8 @@ fn paritydi2Naive(a: i64) i32 {
1313}
1414
1515fn test__paritydi2(a: i64) !void {
16 var x = parity.__paritydi2(a);
17 var expected: i64 = paritydi2Naive(a);
16 const x = parity.__paritydi2(a);
17 const expected: i64 = paritydi2Naive(a);
1818 try testing.expectEqual(expected, x);
1919}
2020
......@@ -30,7 +30,7 @@ test "paritydi2" {
3030 var rnd = RndGen.init(42);
3131 var i: u32 = 0;
3232 while (i < 10_000) : (i += 1) {
33 var rand_num = rnd.random().int(i64);
33 const rand_num = rnd.random().int(i64);
3434 try test__paritydi2(rand_num);
3535 }
3636}
lib/compiler_rt/paritysi2_test.zig+3-3
......@@ -13,8 +13,8 @@ fn paritysi2Naive(a: i32) i32 {
1313}
1414
1515fn test__paritysi2(a: i32) !void {
16 var x = parity.__paritysi2(a);
17 var expected: i32 = paritysi2Naive(a);
16 const x = parity.__paritysi2(a);
17 const expected: i32 = paritysi2Naive(a);
1818 try testing.expectEqual(expected, x);
1919}
2020
......@@ -30,7 +30,7 @@ test "paritysi2" {
3030 var rnd = RndGen.init(42);
3131 var i: u32 = 0;
3232 while (i < 10_000) : (i += 1) {
33 var rand_num = rnd.random().int(i32);
33 const rand_num = rnd.random().int(i32);
3434 try test__paritysi2(rand_num);
3535 }
3636}
lib/compiler_rt/parityti2_test.zig+3-3
......@@ -13,8 +13,8 @@ fn parityti2Naive(a: i128) i32 {
1313}
1414
1515fn test__parityti2(a: i128) !void {
16 var x = parity.__parityti2(a);
17 var expected: i128 = parityti2Naive(a);
16 const x = parity.__parityti2(a);
17 const expected: i128 = parityti2Naive(a);
1818 try testing.expectEqual(expected, x);
1919}
2020
......@@ -30,7 +30,7 @@ test "parityti2" {
3030 var rnd = RndGen.init(42);
3131 var i: u32 = 0;
3232 while (i < 10_000) : (i += 1) {
33 var rand_num = rnd.random().int(i128);
33 const rand_num = rnd.random().int(i128);
3434 try test__parityti2(rand_num);
3535 }
3636}
lib/compiler_rt/popcountdi2_test.zig+1-1
......@@ -29,7 +29,7 @@ test "popcountdi2" {
2929 var rnd = RndGen.init(42);
3030 var i: u32 = 0;
3131 while (i < 10_000) : (i += 1) {
32 var rand_num = rnd.random().int(i64);
32 const rand_num = rnd.random().int(i64);
3333 try test__popcountdi2(rand_num);
3434 }
3535}
lib/compiler_rt/popcountsi2_test.zig+1-1
......@@ -29,7 +29,7 @@ test "popcountsi2" {
2929 var rnd = RndGen.init(42);
3030 var i: u32 = 0;
3131 while (i < 10_000) : (i += 1) {
32 var rand_num = rnd.random().int(i32);
32 const rand_num = rnd.random().int(i32);
3333 try test__popcountsi2(rand_num);
3434 }
3535}
lib/compiler_rt/popcountti2_test.zig+1-1
......@@ -29,7 +29,7 @@ test "popcountti2" {
2929 var rnd = RndGen.init(42);
3030 var i: u32 = 0;
3131 while (i < 10_000) : (i += 1) {
32 var rand_num = rnd.random().int(i128);
32 const rand_num = rnd.random().int(i128);
3333 try test__popcountti2(rand_num);
3434 }
3535}
lib/compiler_rt/powiXf2_test.zig+5-5
......@@ -9,27 +9,27 @@ const testing = std.testing;
99const math = std.math;
1010
1111fn test__powihf2(a: f16, b: i32, expected: f16) !void {
12 var result = powiXf2.__powihf2(a, b);
12 const result = powiXf2.__powihf2(a, b);
1313 try testing.expectEqual(expected, result);
1414}
1515
1616fn test__powisf2(a: f32, b: i32, expected: f32) !void {
17 var result = powiXf2.__powisf2(a, b);
17 const result = powiXf2.__powisf2(a, b);
1818 try testing.expectEqual(expected, result);
1919}
2020
2121fn test__powidf2(a: f64, b: i32, expected: f64) !void {
22 var result = powiXf2.__powidf2(a, b);
22 const result = powiXf2.__powidf2(a, b);
2323 try testing.expectEqual(expected, result);
2424}
2525
2626fn test__powitf2(a: f128, b: i32, expected: f128) !void {
27 var result = powiXf2.__powitf2(a, b);
27 const result = powiXf2.__powitf2(a, b);
2828 try testing.expectEqual(expected, result);
2929}
3030
3131fn test__powixf2(a: f80, b: i32, expected: f80) !void {
32 var result = powiXf2.__powixf2(a, b);
32 const result = powiXf2.__powixf2(a, b);
3333 try testing.expectEqual(expected, result);
3434}
3535
lib/compiler_rt/subo.zig+1-1
......@@ -27,7 +27,7 @@ pub fn __suboti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
2727
2828inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
2929 overflow.* = 0;
30 var sum: ST = a -% b;
30 const sum: ST = a -% b;
3131 // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract
3232 // Let sum = a -% b == a - b - carry == wraparound subtraction.
3333 // Overflow in a-b-carry occurs, iff a and b have opposite signs
lib/compiler_rt/subodi4_test.zig+2-2
......@@ -6,8 +6,8 @@ const math = std.math;
66fn test__subodi4(a: i64, b: i64) !void {
77 var result_ov: c_int = undefined;
88 var expected_ov: c_int = undefined;
9 var result = subo.__subodi4(a, b, &result_ov);
10 var expected: i64 = simple_subodi4(a, b, &expected_ov);
9 const result = subo.__subodi4(a, b, &result_ov);
10 const expected: i64 = simple_subodi4(a, b, &expected_ov);
1111 try testing.expectEqual(expected, result);
1212 try testing.expectEqual(expected_ov, result_ov);
1313}
lib/compiler_rt/subosi4_test.zig+2-2
......@@ -4,8 +4,8 @@ const testing = @import("std").testing;
44fn test__subosi4(a: i32, b: i32) !void {
55 var result_ov: c_int = undefined;
66 var expected_ov: c_int = undefined;
7 var result = subo.__subosi4(a, b, &result_ov);
8 var expected: i32 = simple_subosi4(a, b, &expected_ov);
7 const result = subo.__subosi4(a, b, &result_ov);
8 const expected: i32 = simple_subosi4(a, b, &expected_ov);
99 try testing.expectEqual(expected, result);
1010 try testing.expectEqual(expected_ov, result_ov);
1111}
lib/compiler_rt/suboti4_test.zig+2-2
......@@ -6,8 +6,8 @@ const math = std.math;
66fn test__suboti4(a: i128, b: i128) !void {
77 var result_ov: c_int = undefined;
88 var expected_ov: c_int = undefined;
9 var result = subo.__suboti4(a, b, &result_ov);
10 var expected: i128 = simple_suboti4(a, b, &expected_ov);
9 const result = subo.__suboti4(a, b, &result_ov);
10 const expected: i128 = simple_suboti4(a, b, &expected_ov);
1111 try testing.expectEqual(expected, result);
1212 try testing.expectEqual(expected_ov, result_ov);
1313}
lib/compiler_rt/ucmpdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__ucmpdi2(a: u64, b: u64, expected: i32) !void {
5 var result = cmp.__ucmpdi2(a, b);
5 const result = cmp.__ucmpdi2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/ucmpsi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__ucmpsi2(a: u32, b: u32, expected: i32) !void {
5 var result = cmp.__ucmpsi2(a, b);
5 const result = cmp.__ucmpsi2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/ucmpti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__ucmpti2(a: u128, b: u128, expected: i32) !void {
5 var result = cmp.__ucmpti2(a, b);
5 const result = cmp.__ucmpti2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/udivmod.zig+4-4
......@@ -52,7 +52,7 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T {
5252 if (rhat >= b) break;
5353 }
5454
55 var un21 = un64 *% b +% un1 -% q1 *% v;
55 const un21 = un64 *% b +% un1 -% q1 *% v;
5656
5757 // Compute the second quotient digit
5858 var q0 = un21 / vn1;
......@@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
101101 return 0;
102102 }
103103
104 var a: [2]HalfT = @bitCast(a_);
105 var b: [2]HalfT = @bitCast(b_);
104 const a: [2]HalfT = @bitCast(a_);
105 const b: [2]HalfT = @bitCast(b_);
106106 var q: [2]HalfT = undefined;
107107 var r: [2]HalfT = undefined;
108108
......@@ -125,7 +125,7 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
125125 }
126126
127127 // 0 <= shift <= 63
128 var shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]);
128 const shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]);
129129 var af: T = @bitCast(a);
130130 var bf = @as(T, @bitCast(b)) << shift;
131131 q = @bitCast(@as(T, 0));
lib/compiler_rt/udivmodei4.zig+2-2
......@@ -116,7 +116,7 @@ pub fn __udivei4(r_q: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize)
116116 @setRuntimeSafety(builtin.is_test);
117117 const u = u_p[0 .. bits / 32];
118118 const v = v_p[0 .. bits / 32];
119 var q = r_q[0 .. bits / 32];
119 const q = r_q[0 .. bits / 32];
120120 @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable;
121121}
122122
......@@ -124,7 +124,7 @@ pub fn __umodei4(r_p: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize)
124124 @setRuntimeSafety(builtin.is_test);
125125 const u = u_p[0 .. bits / 32];
126126 const v = v_p[0 .. bits / 32];
127 var r = r_p[0 .. bits / 32];
127 const r = r_p[0 .. bits / 32];
128128 @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable;
129129}
130130
lib/std/Build/Cache.zig+1-1
......@@ -141,7 +141,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath {
141141 var i: u8 = 1; // Start at 1 to skip over checking the null prefix.
142142 while (i < prefixes_slice.len) : (i += 1) {
143143 const p = prefixes_slice[i].path.?;
144 var sub_path = getPrefixSubpath(gpa, p, resolved_path) catch |err| switch (err) {
144 const sub_path = getPrefixSubpath(gpa, p, resolved_path) catch |err| switch (err) {
145145 error.NotASubPath => continue,
146146 else => |e| return e,
147147 };
lib/std/Build/Cache/DepTokenizer.zig+3-3
......@@ -950,7 +950,7 @@ fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void {
950950
951951fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {
952952 var buf: [80]u8 = undefined;
953 var text = try std.fmt.bufPrint(buf[0..], "{s} {d} bytes ", .{ label, bytes.len });
953 const text = try std.fmt.bufPrint(buf[0..], "{s} {d} bytes ", .{ label, bytes.len });
954954 try out.writeAll(text);
955955 var i: usize = text.len;
956956 const end = 79;
......@@ -983,12 +983,12 @@ fn hexDump(out: anytype, bytes: []const u8) !void {
983983 try printDecValue(out, offset, 8);
984984 try out.writeAll(":");
985985 try out.writeAll(" ");
986 var end1 = @min(offset + n, offset + 8);
986 const end1 = @min(offset + n, offset + 8);
987987 for (bytes[offset..end1]) |b| {
988988 try out.writeAll(" ");
989989 try printHexValue(out, b, 2);
990990 }
991 var end2 = offset + n;
991 const end2 = offset + n;
992992 if (end2 > end1) {
993993 try out.writeAll(" ");
994994 for (bytes[end1..end2]) |b| {
lib/std/Build/Step/CheckObject.zig+1-1
......@@ -293,7 +293,7 @@ const Check = struct {
293293
294294/// Creates a new empty sequence of actions.
295295pub fn checkStart(self: *CheckObject) void {
296 var new_check = Check.create(self.step.owner.allocator);
296 const new_check = Check.create(self.step.owner.allocator);
297297 self.checks.append(new_check) catch @panic("OOM");
298298}
299299
lib/std/Build/Step/ConfigHeader.zig+2-2
......@@ -307,8 +307,8 @@ fn render_cmake(
307307 values: std.StringArrayHashMap(Value),
308308 src_path: []const u8,
309309) !void {
310 var build = step.owner;
311 var allocator = build.allocator;
310 const build = step.owner;
311 const allocator = build.allocator;
312312
313313 var values_copy = try values.clone();
314314 defer values_copy.deinit();
lib/std/Build/Step/Run.zig+1-1
......@@ -301,7 +301,7 @@ pub fn addPathDir(self: *Run, search_path: []const u8) void {
301301 const env_map = getEnvMapInternal(self);
302302
303303 const key = "PATH";
304 var prev_path = env_map.get(key);
304 const prev_path = env_map.get(key);
305305
306306 if (prev_path) |pp| {
307307 const new_path = b.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path });
lib/std/Progress.zig+1
......@@ -397,6 +397,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any
397397
398398test "basic functionality" {
399399 var disable = true;
400 _ = &disable;
400401 if (disable) {
401402 // This test is disabled because it uses time.sleep() and is therefore slow. It also
402403 // prints bogus progress data to stderr.
lib/std/Thread/WaitGroup.zig+1-1
......@@ -25,7 +25,7 @@ pub fn finish(self: *WaitGroup) void {
2525}
2626
2727pub fn wait(self: *WaitGroup) void {
28 var state = self.state.fetchAdd(is_waiting, .Acquire);
28 const state = self.state.fetchAdd(is_waiting, .Acquire);
2929 assert(state & is_waiting == 0);
3030
3131 if ((state / one_pending) > 0) {
lib/std/array_hash_map.zig+3-3
......@@ -2076,11 +2076,11 @@ test "iterator hash map" {
20762076 try reset_map.putNoClobber(1, 22);
20772077 try reset_map.putNoClobber(2, 33);
20782078
2079 var keys = [_]i32{
2079 const keys = [_]i32{
20802080 0, 2, 1,
20812081 };
20822082
2083 var values = [_]i32{
2083 const values = [_]i32{
20842084 11, 33, 22,
20852085 };
20862086
......@@ -2116,7 +2116,7 @@ test "iterator hash map" {
21162116 }
21172117
21182118 it.reset();
2119 var entry = it.next().?;
2119 const entry = it.next().?;
21202120 try testing.expect(entry.key_ptr.* == first_entry.key_ptr.*);
21212121 try testing.expect(entry.value_ptr.* == first_entry.value_ptr.*);
21222122}
lib/std/array_list.zig+2-2
......@@ -979,7 +979,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
979979 pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
980980 if (self.capacity >= new_capacity) return;
981981
982 var better_capacity = growCapacity(self.capacity, new_capacity);
982 const better_capacity = growCapacity(self.capacity, new_capacity);
983983 return self.ensureTotalCapacityPrecise(allocator, better_capacity);
984984 }
985985
......@@ -1159,7 +1159,7 @@ test "std.ArrayList/ArrayListUnmanaged.init" {
11591159 }
11601160
11611161 {
1162 var list = ArrayListUnmanaged(i32){};
1162 const list = ArrayListUnmanaged(i32){};
11631163
11641164 try testing.expect(list.items.len == 0);
11651165 try testing.expect(list.capacity == 0);
lib/std/atomic/Atomic.zig+1-1
......@@ -125,7 +125,7 @@ pub fn Atomic(comptime T: type) type {
125125 @compileError(@tagName(Ordering.Unordered) ++ " is only allowed on atomic loads and stores");
126126 }
127127
128 comptime var success_is_stronger = switch (failure) {
128 const success_is_stronger = switch (failure) {
129129 .SeqCst => success == .SeqCst,
130130 .AcqRel => @compileError(@tagName(failure) ++ " implies " ++ @tagName(Ordering.Release) ++ " which is only allowed on success"),
131131 .Acquire => success == .SeqCst or success == .AcqRel or success == .Acquire,
lib/std/atomic/queue.zig+2-2
......@@ -175,11 +175,11 @@ const puts_per_thread = 500;
175175const put_thread_count = 3;
176176
177177test "std.atomic.Queue" {
178 var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);
178 const plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);
179179 defer std.heap.page_allocator.free(plenty_of_memory);
180180
181181 var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory);
182 var a = fixed_buffer_allocator.threadSafeAllocator();
182 const a = fixed_buffer_allocator.threadSafeAllocator();
183183
184184 var queue = Queue(i32).init();
185185 var context = Context{
lib/std/atomic/stack.zig+2-2
......@@ -85,11 +85,11 @@ const puts_per_thread = 500;
8585const put_thread_count = 3;
8686
8787test "std.atomic.stack" {
88 var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);
88 const plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);
8989 defer std.heap.page_allocator.free(plenty_of_memory);
9090
9191 var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory);
92 var a = fixed_buffer_allocator.threadSafeAllocator();
92 const a = fixed_buffer_allocator.threadSafeAllocator();
9393
9494 var stack = Stack(i32).init();
9595 var context = Context{
lib/std/base64.zig+11-11
......@@ -239,7 +239,7 @@ pub const Base64Decoder = struct {
239239 if ((bits & invalid_char_tst) != 0) return error.InvalidCharacter;
240240 std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .little);
241241 }
242 var remaining = source[fast_src_idx..];
242 const remaining = source[fast_src_idx..];
243243 for (remaining, fast_src_idx..) |c, src_idx| {
244244 const d = decoder.char_to_index[c];
245245 if (d == invalid_char) {
......@@ -259,7 +259,7 @@ pub const Base64Decoder = struct {
259259 return error.InvalidPadding;
260260 }
261261 if (leftover_idx == null) return;
262 var leftover = source[leftover_idx.?..];
262 const leftover = source[leftover_idx.?..];
263263 if (decoder.pad_char) |pad_char| {
264264 const padding_len = acc_len / 2;
265265 var padding_chars: usize = 0;
......@@ -338,7 +338,7 @@ pub const Base64DecoderWithIgnore = struct {
338338 if (decoder.pad_char != null and padding_len != 0) return error.InvalidPadding;
339339 return dest_idx;
340340 }
341 var leftover = source[leftover_idx.?..];
341 const leftover = source[leftover_idx.?..];
342342 if (decoder.pad_char) |pad_char| {
343343 var padding_chars: usize = 0;
344344 for (leftover) |c| {
......@@ -483,7 +483,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
483483 // Base64Decoder
484484 {
485485 var buffer: [0x100]u8 = undefined;
486 var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];
486 const decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];
487487 try codecs.Decoder.decode(decoded, expected_encoded);
488488 try testing.expectEqualSlices(u8, expected_decoded, decoded);
489489 }
......@@ -492,8 +492,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
492492 {
493493 const decoder_ignore_nothing = codecs.decoderWithIgnore("");
494494 var buffer: [0x100]u8 = undefined;
495 var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
496 var written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
495 const decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
496 const written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
497497 try testing.expect(written <= decoded.len);
498498 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
499499 }
......@@ -502,8 +502,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
502502fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void {
503503 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
504504 var buffer: [0x100]u8 = undefined;
505 var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
506 var written = try decoder_ignore_space.decode(decoded, encoded);
505 const decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
506 const written = try decoder_ignore_space.decode(decoded, encoded);
507507 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
508508}
509509
......@@ -511,7 +511,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void
511511 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
512512 var buffer: [0x100]u8 = undefined;
513513 if (codecs.Decoder.calcSizeForSlice(encoded)) |decoded_size| {
514 var decoded = buffer[0..decoded_size];
514 const decoded = buffer[0..decoded_size];
515515 if (codecs.Decoder.decode(decoded, encoded)) |_| {
516516 return error.ExpectedError;
517517 } else |err| if (err != expected_err) return err;
......@@ -525,7 +525,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void
525525fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {
526526 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
527527 var buffer: [0x100]u8 = undefined;
528 var decoded = buffer[0 .. (try codecs.Decoder.calcSizeForSlice(encoded)) - 1];
528 const decoded = buffer[0 .. (try codecs.Decoder.calcSizeForSlice(encoded)) - 1];
529529 if (decoder_ignore_space.decode(decoded, encoded)) |_| {
530530 return error.ExpectedError;
531531 } else |err| if (err != error.NoSpaceLeft) return err;
......@@ -534,7 +534,7 @@ fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {
534534fn testFourBytesDestNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {
535535 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
536536 var buffer: [0x100]u8 = undefined;
537 var decoded = buffer[0..4];
537 const decoded = buffer[0..4];
538538 if (decoder_ignore_space.decode(decoded, encoded)) |_| {
539539 return error.ExpectedError;
540540 } else |err| if (err != error.NoSpaceLeft) return err;
lib/std/buf_map.zig+1-2
......@@ -15,8 +15,7 @@ pub const BufMap = struct {
1515 /// That allocator will be used for both backing allocations
1616 /// and string deduplication.
1717 pub fn init(allocator: Allocator) BufMap {
18 var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) };
19 return self;
18 return .{ .hash_map = BufMapHashMap.init(allocator) };
2019 }
2120
2221 /// Free the backing storage of the map, as well as all
lib/std/buf_set.zig+4-5
......@@ -17,8 +17,7 @@ pub const BufSet = struct {
1717 /// be used internally for both backing allocations and
1818 /// string duplication.
1919 pub fn init(a: Allocator) BufSet {
20 var self = BufSet{ .hash_map = BufSetHashMap.init(a) };
21 return self;
20 return .{ .hash_map = BufSetHashMap.init(a) };
2221 }
2322
2423 /// Free a BufSet along with all stored keys.
......@@ -76,8 +75,8 @@ pub const BufSet = struct {
7675 self: *const BufSet,
7776 new_allocator: Allocator,
7877 ) Allocator.Error!BufSet {
79 var cloned_hashmap = try self.hash_map.cloneWithAllocator(new_allocator);
80 var cloned = BufSet{ .hash_map = cloned_hashmap };
78 const cloned_hashmap = try self.hash_map.cloneWithAllocator(new_allocator);
79 const cloned = BufSet{ .hash_map = cloned_hashmap };
8180 var it = cloned.hash_map.keyIterator();
8281 while (it.next()) |key_ptr| {
8382 key_ptr.* = try cloned.copy(key_ptr.*);
......@@ -134,7 +133,7 @@ test "BufSet clone" {
134133}
135134
136135test "BufSet.clone with arena" {
137 var allocator = std.testing.allocator;
136 const allocator = std.testing.allocator;
138137 var arena = std.heap.ArenaAllocator.init(allocator);
139138 defer arena.deinit();
140139
lib/std/builtin.zig+3-4
......@@ -777,9 +777,8 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr
777777 }
778778
779779 var fmt: [256]u8 = undefined;
780 var slice = try std.fmt.bufPrint(&fmt, "\r\nerr: {s}\r\n", .{exit_msg});
781
782 var len = try std.unicode.utf8ToUtf16Le(utf16, slice);
780 const slice = try std.fmt.bufPrint(&fmt, "\r\nerr: {s}\r\n", .{exit_msg});
781 const len = try std.unicode.utf8ToUtf16Le(utf16, slice);
783782
784783 utf16[len] = 0;
785784
......@@ -790,7 +789,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr
790789 };
791790
792791 var exit_size: usize = 0;
793 var exit_data = ExitData.create_exit_data(msg, &exit_size) catch null;
792 const exit_data = ExitData.create_exit_data(msg, &exit_size) catch null;
794793
795794 if (exit_data) |data| {
796795 if (uefi.system_table.std_err) |out| {
lib/std/child_process.zig+1-1
......@@ -847,7 +847,7 @@ pub const ChildProcess = struct {
847847 }
848848
849849 windowsCreateProcessPathExt(self.allocator, &dir_buf, &app_buf, PATHEXT, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {
850 var original_err = switch (no_path_err) {
850 const original_err = switch (no_path_err) {
851851 error.FileNotFound, error.InvalidExe, error.AccessDenied => |e| e,
852852 error.UnrecoverableInvalidExe => return error.InvalidExe,
853853 else => |e| return e,
lib/std/coff.zig+1-1
......@@ -1075,7 +1075,7 @@ pub const Coff = struct {
10751075 var stream = std.io.fixedBufferStream(data);
10761076 const reader = stream.reader();
10771077 try stream.seekTo(pe_pointer_offset);
1078 var coff_header_offset = try reader.readInt(u32, .little);
1078 const coff_header_offset = try reader.readInt(u32, .little);
10791079 try stream.seekTo(coff_header_offset);
10801080 var buf: [4]u8 = undefined;
10811081 try reader.readNoEof(&buf);
lib/std/compress/deflate/bits_utils.zig+2-2
......@@ -15,7 +15,7 @@ test "bitReverse" {
1515 out: u16,
1616 };
1717
18 var reverse_bits_tests = [_]ReverseBitsTest{
18 const reverse_bits_tests = [_]ReverseBitsTest{
1919 .{ .in = 1, .bit_count = 1, .out = 1 },
2020 .{ .in = 1, .bit_count = 2, .out = 2 },
2121 .{ .in = 1, .bit_count = 3, .out = 4 },
......@@ -27,7 +27,7 @@ test "bitReverse" {
2727 };
2828
2929 for (reverse_bits_tests) |h| {
30 var v = bitReverse(u16, h.in, h.bit_count);
30 const v = bitReverse(u16, h.in, h.bit_count);
3131 try std.testing.expectEqual(h.out, v);
3232 }
3333}
lib/std/compress/deflate/compressor.zig+25-25
......@@ -156,8 +156,8 @@ fn levels(compression: Compression) CompressionLevel {
156156// up to length 'max'. Both slices must be at least 'max'
157157// bytes in size.
158158fn matchLen(a: []u8, b: []u8, max: u32) u32 {
159 var bounded_a = a[0..max];
160 var bounded_b = b[0..max];
159 const bounded_a = a[0..max];
160 const bounded_b = b[0..max];
161161 for (bounded_a, 0..) |av, i| {
162162 if (bounded_b[i] != av) {
163163 return @as(u32, @intCast(i));
......@@ -191,7 +191,7 @@ fn bulkHash4(b: []u8, dst: []u32) u32 {
191191 @as(u32, b[0]) << 24;
192192
193193 dst[0] = (hb *% hash_mul) >> (32 - hash_bits);
194 var end = b.len - min_match_length + 1;
194 const end = b.len - min_match_length + 1;
195195 var i: u32 = 1;
196196 while (i < end) : (i += 1) {
197197 hb = (hb << 8) | @as(u32, b[i + 3]);
......@@ -305,7 +305,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
305305 }
306306 self.hash_offset += window_size;
307307 if (self.hash_offset > max_hash_offset) {
308 var delta = self.hash_offset - 1;
308 const delta = self.hash_offset - 1;
309309 self.hash_offset -= delta;
310310 self.chain_head -|= delta;
311311
......@@ -369,31 +369,31 @@ pub fn Compressor(comptime WriterType: anytype) type {
369369 }
370370 // Add all to window.
371371 @memcpy(self.window[0..b.len], b);
372 var n = b.len;
372 const n = b.len;
373373
374374 // Calculate 256 hashes at the time (more L1 cache hits)
375 var loops = (n + 256 - min_match_length) / 256;
375 const loops = (n + 256 - min_match_length) / 256;
376376 var j: usize = 0;
377377 while (j < loops) : (j += 1) {
378 var index = j * 256;
378 const index = j * 256;
379379 var end = index + 256 + min_match_length - 1;
380380 if (end > n) {
381381 end = n;
382382 }
383 var to_check = self.window[index..end];
384 var dst_size = to_check.len - min_match_length + 1;
383 const to_check = self.window[index..end];
384 const dst_size = to_check.len - min_match_length + 1;
385385
386386 if (dst_size <= 0) {
387387 continue;
388388 }
389389
390 var dst = self.hash_match[0..dst_size];
390 const dst = self.hash_match[0..dst_size];
391391 _ = self.bulk_hasher(to_check, dst);
392392 var new_h: u32 = 0;
393393 for (dst, 0..) |val, i| {
394 var di = i + index;
394 const di = i + index;
395395 new_h = val;
396 var hh = &self.hash_head[new_h & hash_mask];
396 const hh = &self.hash_head[new_h & hash_mask];
397397 // Get previous value with the same hash.
398398 // Our chain should point to the previous value.
399399 self.hash_prev[di & window_mask] = hh.*;
......@@ -447,13 +447,13 @@ pub fn Compressor(comptime WriterType: anytype) type {
447447 }
448448
449449 var w_end = win[pos + length];
450 var w_pos = win[pos..];
451 var min_index = pos -| window_size;
450 const w_pos = win[pos..];
451 const min_index = pos -| window_size;
452452
453453 var i = prev_head;
454454 while (tries > 0) : (tries -= 1) {
455455 if (w_end == win[i + length]) {
456 var n = matchLen(win[i..], w_pos, min_match_look);
456 const n = matchLen(win[i..], w_pos, min_match_look);
457457
458458 if (n > length and (n > min_match_length or pos - i <= 4096)) {
459459 length = n;
......@@ -565,7 +565,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
565565 while (true) {
566566 assert(self.index <= self.window_end);
567567
568 var lookahead = self.window_end -| self.index;
568 const lookahead = self.window_end -| self.index;
569569 if (lookahead < min_match_length + max_match_length) {
570570 if (!self.sync) {
571571 break;
......@@ -590,16 +590,16 @@ pub fn Compressor(comptime WriterType: anytype) type {
590590 if (self.index < self.max_insert_index) {
591591 // Update the hash
592592 self.hash = hash4(self.window[self.index .. self.index + min_match_length]);
593 var hh = &self.hash_head[self.hash & hash_mask];
593 const hh = &self.hash_head[self.hash & hash_mask];
594594 self.chain_head = @as(u32, @intCast(hh.*));
595595 self.hash_prev[self.index & window_mask] = @as(u32, @intCast(self.chain_head));
596596 hh.* = @as(u32, @intCast(self.index + self.hash_offset));
597597 }
598 var prev_length = self.length;
599 var prev_offset = self.offset;
598 const prev_length = self.length;
599 const prev_offset = self.offset;
600600 self.length = min_match_length - 1;
601601 self.offset = 0;
602 var min_index = self.index -| window_size;
602 const min_index = self.index -| window_size;
603603
604604 if (self.hash_offset <= self.chain_head and
605605 self.chain_head - self.hash_offset >= min_index and
......@@ -610,7 +610,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
610610 prev_length < self.compression_level.lazy))
611611 {
612612 {
613 var fmatch = self.findMatch(
613 const fmatch = self.findMatch(
614614 self.index,
615615 self.chain_head -| self.hash_offset,
616616 min_match_length - 1,
......@@ -658,7 +658,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
658658 self.hash = hash4(self.window[index .. index + min_match_length]);
659659 // Get previous value with the same hash.
660660 // Our chain should point to the previous value.
661 var hh = &self.hash_head[self.hash & hash_mask];
661 const hh = &self.hash_head[self.hash & hash_mask];
662662 self.hash_prev[index & window_mask] = hh.*;
663663 // Set the head of the hash chain to us.
664664 hh.* = @as(u32, @intCast(index + self.hash_offset));
......@@ -740,7 +740,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
740740 // compressed form of data to its underlying writer.
741741 while (buf.len > 0) {
742742 try self.step();
743 var filled = self.fill(buf);
743 const filled = self.fill(buf);
744744 buf = buf[filled..];
745745 }
746746
......@@ -1097,12 +1097,12 @@ test "bulkHash4" {
10971097 while (j < out.len) : (j += 1) {
10981098 var y = out[0..j];
10991099
1100 var dst = try testing.allocator.alloc(u32, y.len - min_match_length + 1);
1100 const dst = try testing.allocator.alloc(u32, y.len - min_match_length + 1);
11011101 defer testing.allocator.free(dst);
11021102
11031103 _ = bulkHash4(y, dst);
11041104 for (dst, 0..) |got, i| {
1105 var want = hash4(y[i..]);
1105 const want = hash4(y[i..]);
11061106 try testing.expectEqual(want, got);
11071107 }
11081108 }
lib/std/compress/deflate/compressor_test.zig+16-16
......@@ -27,7 +27,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
2727 var whole_buf = std.ArrayList(u8).init(testing.allocator);
2828 defer whole_buf.deinit();
2929
30 var multi_writer = io.multiWriter(.{
30 const multi_writer = io.multiWriter(.{
3131 divided_buf.writer(),
3232 whole_buf.writer(),
3333 }).writer();
......@@ -48,7 +48,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
4848 defer decomp.deinit();
4949
5050 // Write first half of the input and flush()
51 var half: usize = (input.len + 1) / 2;
51 const half: usize = (input.len + 1) / 2;
5252 var half_len: usize = half - 0;
5353 {
5454 _ = try comp.writer().writeAll(input[0..half]);
......@@ -57,10 +57,10 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
5757 try comp.flush();
5858
5959 // Read back
60 var decompressed = try testing.allocator.alloc(u8, half_len);
60 const decompressed = try testing.allocator.alloc(u8, half_len);
6161 defer testing.allocator.free(decompressed);
6262
63 var read = try decomp.reader().readAll(decompressed); // read at least half
63 const read = try decomp.reader().readAll(decompressed); // read at least half
6464 try testing.expectEqual(half_len, read);
6565 try testing.expectEqualSlices(u8, input[0..half], decompressed);
6666 }
......@@ -74,7 +74,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
7474 try comp.close();
7575
7676 // Read back
77 var decompressed = try testing.allocator.alloc(u8, half_len);
77 const decompressed = try testing.allocator.alloc(u8, half_len);
7878 defer testing.allocator.free(decompressed);
7979
8080 var read = try decomp.reader().readAll(decompressed);
......@@ -94,11 +94,11 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
9494 try comp.close();
9595
9696 // stream should work for ordinary reader too (reading whole_buf in one go)
97 var whole_buf_reader = io.fixedBufferStream(whole_buf.items).reader();
97 const whole_buf_reader = io.fixedBufferStream(whole_buf.items).reader();
9898 var decomp = try decompressor(testing.allocator, whole_buf_reader, null);
9999 defer decomp.deinit();
100100
101 var decompressed = try testing.allocator.alloc(u8, input.len);
101 const decompressed = try testing.allocator.alloc(u8, input.len);
102102 defer testing.allocator.free(decompressed);
103103
104104 _ = try decomp.reader().readAll(decompressed);
......@@ -125,10 +125,10 @@ fn testToFromWithLevelAndLimit(level: deflate.Compression, input: []const u8, li
125125 var decomp = try decompressor(testing.allocator, fib.reader(), null);
126126 defer decomp.deinit();
127127
128 var decompressed = try testing.allocator.alloc(u8, input.len);
128 const decompressed = try testing.allocator.alloc(u8, input.len);
129129 defer testing.allocator.free(decompressed);
130130
131 var read: usize = try decomp.reader().readAll(decompressed);
131 const read: usize = try decomp.reader().readAll(decompressed);
132132 try testing.expectEqual(input.len, read);
133133 try testing.expectEqualSlices(u8, input, decompressed);
134134
......@@ -153,7 +153,7 @@ fn testToFromWithLimit(input: []const u8, limit: [11]u32) !void {
153153}
154154
155155test "deflate/inflate" {
156 var limits = [_]u32{0} ** 11;
156 const limits = [_]u32{0} ** 11;
157157
158158 var test0 = [_]u8{};
159159 var test1 = [_]u8{0x11};
......@@ -313,7 +313,7 @@ test "decompressor dictionary" {
313313 try comp.writer().writeAll(text);
314314 try comp.close();
315315
316 var decompressed = try testing.allocator.alloc(u8, text.len);
316 const decompressed = try testing.allocator.alloc(u8, text.len);
317317 defer testing.allocator.free(decompressed);
318318
319319 var decomp = try decompressor(
......@@ -432,7 +432,7 @@ test "deflate/inflate string" {
432432 };
433433
434434 inline for (deflate_inflate_string_tests) |t| {
435 var golden = @embedFile("testdata/" ++ t.filename);
435 const golden = @embedFile("testdata/" ++ t.filename);
436436 try testToFromWithLimit(golden, t.limit);
437437 }
438438}
......@@ -466,14 +466,14 @@ test "inflate reset" {
466466 var decomp = try decompressor(testing.allocator, fib.reader(), null);
467467 defer decomp.deinit();
468468
469 var decompressed_0: []u8 = try decomp.reader()
469 const decompressed_0: []u8 = try decomp.reader()
470470 .readAllAlloc(testing.allocator, math.maxInt(usize));
471471 defer testing.allocator.free(decompressed_0);
472472
473473 fib = io.fixedBufferStream(compressed_strings[1].items);
474474 try decomp.reset(fib.reader(), null);
475475
476 var decompressed_1: []u8 = try decomp.reader()
476 const decompressed_1: []u8 = try decomp.reader()
477477 .readAllAlloc(testing.allocator, math.maxInt(usize));
478478 defer testing.allocator.free(decompressed_1);
479479
......@@ -513,14 +513,14 @@ test "inflate reset dictionary" {
513513 var decomp = try decompressor(testing.allocator, fib.reader(), dict);
514514 defer decomp.deinit();
515515
516 var decompressed_0: []u8 = try decomp.reader()
516 const decompressed_0: []u8 = try decomp.reader()
517517 .readAllAlloc(testing.allocator, math.maxInt(usize));
518518 defer testing.allocator.free(decompressed_0);
519519
520520 fib = io.fixedBufferStream(compressed_strings[1].items);
521521 try decomp.reset(fib.reader(), dict);
522522
523 var decompressed_1: []u8 = try decomp.reader()
523 const decompressed_1: []u8 = try decomp.reader()
524524 .readAllAlloc(testing.allocator, math.maxInt(usize));
525525 defer testing.allocator.free(decompressed_1);
526526
lib/std/compress/deflate/decompressor.zig+25-25
......@@ -136,11 +136,11 @@ const HuffmanDecoder = struct {
136136
137137 self.min = min;
138138 if (max > huffman_chunk_bits) {
139 var num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits));
139 const num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits));
140140 self.link_mask = @as(u32, @intCast(num_links - 1));
141141
142142 // create link tables
143 var link = next_code[huffman_chunk_bits + 1] >> 1;
143 const link = next_code[huffman_chunk_bits + 1] >> 1;
144144 self.links = try self.allocator.alloc([]u16, huffman_num_chunks - link);
145145 self.sub_chunks = ArrayList(u32).init(self.allocator);
146146 self.initialized = true;
......@@ -148,7 +148,7 @@ const HuffmanDecoder = struct {
148148 while (j < huffman_num_chunks) : (j += 1) {
149149 var reverse = @as(u32, @intCast(bu.bitReverse(u16, @as(u16, @intCast(j)), 16)));
150150 reverse >>= @as(u32, @intCast(16 - huffman_chunk_bits));
151 var off = j - @as(u32, @intCast(link));
151 const off = j - @as(u32, @intCast(link));
152152 if (sanity) {
153153 // check we are not overwriting an existing chunk
154154 assert(self.chunks[reverse] == 0);
......@@ -168,9 +168,9 @@ const HuffmanDecoder = struct {
168168 if (n == 0) {
169169 continue;
170170 }
171 var ncode = next_code[n];
171 const ncode = next_code[n];
172172 next_code[n] += 1;
173 var chunk = @as(u16, @intCast((li << huffman_value_shift) | n));
173 const chunk = @as(u16, @intCast((li << huffman_value_shift) | n));
174174 var reverse = @as(u16, @intCast(bu.bitReverse(u16, @as(u16, @intCast(ncode)), 16)));
175175 reverse >>= @as(u4, @intCast(16 - n));
176176 if (n <= huffman_chunk_bits) {
......@@ -187,14 +187,14 @@ const HuffmanDecoder = struct {
187187 self.chunks[off] = chunk;
188188 }
189189 } else {
190 var j = reverse & (huffman_num_chunks - 1);
190 const j = reverse & (huffman_num_chunks - 1);
191191 if (sanity) {
192192 // Expect an indirect chunk
193193 assert(self.chunks[j] & huffman_count_mask == huffman_chunk_bits + 1);
194194 // Longer codes should have been
195195 // associated with a link table above.
196196 }
197 var value = self.chunks[j] >> huffman_value_shift;
197 const value = self.chunks[j] >> huffman_value_shift;
198198 var link_tab = self.links[value];
199199 reverse >>= huffman_chunk_bits;
200200 var off = reverse;
......@@ -354,8 +354,8 @@ pub fn Decompressor(comptime ReaderType: type) type {
354354 fn init(allocator: Allocator, in_reader: ReaderType, dict: ?[]const u8) !Self {
355355 fixed_huffman_decoder = try fixedHuffmanDecoderInit(allocator);
356356
357 var bits = try allocator.create([max_num_lit + max_num_dist]u32);
358 var codebits = try allocator.create([num_codes]u32);
357 const bits = try allocator.create([max_num_lit + max_num_dist]u32);
358 const codebits = try allocator.create([num_codes]u32);
359359
360360 var dd = ddec.DictDecoder{};
361361 try dd.init(allocator, max_match_offset, dict);
......@@ -416,7 +416,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
416416 }
417417 self.final = self.b & 1 == 1;
418418 self.b >>= 1;
419 var typ = self.b & 3;
419 const typ = self.b & 3;
420420 self.b >>= 2;
421421 self.nb -= 1 + 2;
422422 switch (typ) {
......@@ -494,21 +494,21 @@ pub fn Decompressor(comptime ReaderType: type) type {
494494 while (self.nb < 5 + 5 + 4) {
495495 try self.moreBits();
496496 }
497 var nlit = @as(u32, @intCast(self.b & 0x1F)) + 257;
497 const nlit = @as(u32, @intCast(self.b & 0x1F)) + 257;
498498 if (nlit > max_num_lit) {
499499 corrupt_input_error_offset = self.roffset;
500500 self.err = InflateError.CorruptInput;
501501 return InflateError.CorruptInput;
502502 }
503503 self.b >>= 5;
504 var ndist = @as(u32, @intCast(self.b & 0x1F)) + 1;
504 const ndist = @as(u32, @intCast(self.b & 0x1F)) + 1;
505505 if (ndist > max_num_dist) {
506506 corrupt_input_error_offset = self.roffset;
507507 self.err = InflateError.CorruptInput;
508508 return InflateError.CorruptInput;
509509 }
510510 self.b >>= 5;
511 var nclen = @as(u32, @intCast(self.b & 0xF)) + 4;
511 const nclen = @as(u32, @intCast(self.b & 0xF)) + 4;
512512 // num_codes is 19, so nclen is always valid.
513513 self.b >>= 4;
514514 self.nb -= 5 + 5 + 4;
......@@ -536,9 +536,9 @@ pub fn Decompressor(comptime ReaderType: type) type {
536536 // HLIT + 257 code lengths, HDIST + 1 code lengths,
537537 // using the code length Huffman code.
538538 i = 0;
539 var n = nlit + ndist;
539 const n = nlit + ndist;
540540 while (i < n) {
541 var x = try self.huffSym(&self.hd1);
541 const x = try self.huffSym(&self.hd1);
542542 if (x < 16) {
543543 // Actual length.
544544 self.bits[i] = x;
......@@ -618,7 +618,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
618618 switch (self.step_state) {
619619 .init => {
620620 // Read literal and/or (length, distance) according to RFC section 3.2.3.
621 var v = try self.huffSym(self.hl.?);
621 const v = try self.huffSym(self.hl.?);
622622 var n: u32 = 0; // number of bits extra
623623 var length: u32 = 0;
624624 switch (v) {
......@@ -699,7 +699,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
699699 switch (dist) {
700700 0...3 => dist += 1,
701701 4...max_num_dist - 1 => { // 4...29
702 var nb = @as(u32, @intCast(dist - 2)) >> 1;
702 const nb = @as(u32, @intCast(dist - 2)) >> 1;
703703 // have 1 bit in bottom of dist, need nb more.
704704 var extra = (dist & 1) << @as(u5, @intCast(nb));
705705 while (self.nb < nb) {
......@@ -757,14 +757,14 @@ pub fn Decompressor(comptime ReaderType: type) type {
757757 self.b = 0;
758758
759759 // Length then ones-complement of length.
760 var nr: u32 = 4;
760 const nr: u32 = 4;
761761 self.inner_reader.readNoEof(self.buf[0..nr]) catch {
762762 self.err = InflateError.UnexpectedEndOfStream;
763763 return InflateError.UnexpectedEndOfStream;
764764 };
765765 self.roffset += @as(u64, @intCast(nr));
766 var n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8;
767 var nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8;
766 const n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8;
767 const nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8;
768768 if (@as(u16, @intCast(nn)) != @as(u16, @truncate(~n))) {
769769 corrupt_input_error_offset = self.roffset;
770770 self.err = InflateError.CorruptInput;
......@@ -789,7 +789,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
789789 buf = buf[0..self.copy_len];
790790 }
791791
792 var cnt = try self.inner_reader.read(buf);
792 const cnt = try self.inner_reader.read(buf);
793793 if (cnt < buf.len) {
794794 self.err = InflateError.UnexpectedEndOfStream;
795795 }
......@@ -819,7 +819,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
819819 }
820820
821821 fn moreBits(self: *Self) InflateError!void {
822 var c = self.inner_reader.readByte() catch |e| {
822 const c = self.inner_reader.readByte() catch |e| {
823823 if (e == error.EndOfStream) {
824824 return InflateError.UnexpectedEndOfStream;
825825 }
......@@ -845,7 +845,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
845845 var b = self.b;
846846 while (true) {
847847 while (nb < n) {
848 var c = self.inner_reader.readByte() catch |e| {
848 const c = self.inner_reader.readByte() catch |e| {
849849 self.b = b;
850850 self.nb = nb;
851851 if (e == error.EndOfStream) {
......@@ -1053,7 +1053,7 @@ test "inflate A Tale of Two Cities (1859) intro" {
10531053 defer decomp.deinit();
10541054
10551055 var got: [700]u8 = undefined;
1056 var got_len = try decomp.reader().read(&got);
1056 const got_len = try decomp.reader().read(&got);
10571057 try testing.expectEqual(@as(usize, 616), got_len);
10581058 try testing.expectEqualSlices(u8, expected, got[0..expected.len]);
10591059}
......@@ -1117,6 +1117,6 @@ fn decompress(input: []const u8) !void {
11171117 const reader = fib.reader();
11181118 var decomp = try decompressor(allocator, reader, null);
11191119 defer decomp.deinit();
1120 var output = try decomp.reader().readAllAlloc(allocator, math.maxInt(usize));
1120 const output = try decomp.reader().readAllAlloc(allocator, math.maxInt(usize));
11211121 defer std.testing.allocator.free(output);
11221122}
lib/std/compress/deflate/deflate_fast.zig+32-32
......@@ -30,7 +30,7 @@ const table_size = 1 << table_bits; // Size of the table.
3030const buffer_reset = math.maxInt(i32) - max_store_block_size * 2;
3131
3232fn load32(b: []u8, i: i32) u32 {
33 var s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4];
33 const s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4];
3434 return @as(u32, @intCast(s[0])) |
3535 @as(u32, @intCast(s[1])) << 8 |
3636 @as(u32, @intCast(s[2])) << 16 |
......@@ -38,7 +38,7 @@ fn load32(b: []u8, i: i32) u32 {
3838}
3939
4040fn load64(b: []u8, i: i32) u64 {
41 var s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))];
41 const s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))];
4242 return @as(u64, @intCast(s[0])) |
4343 @as(u64, @intCast(s[1])) << 8 |
4444 @as(u64, @intCast(s[2])) << 16 |
......@@ -117,7 +117,7 @@ pub const DeflateFast = struct {
117117 // s_limit is when to stop looking for offset/length copies. The input_margin
118118 // lets us use a fast path for emitLiteral in the main loop, while we are
119119 // looking for copies.
120 var s_limit = @as(i32, @intCast(src.len - input_margin));
120 const s_limit = @as(i32, @intCast(src.len - input_margin));
121121
122122 // next_emit is where in src the next emitLiteral should start from.
123123 var next_emit: i32 = 0;
......@@ -147,18 +147,18 @@ pub const DeflateFast = struct {
147147 var candidate: TableEntry = undefined;
148148 while (true) {
149149 s = next_s;
150 var bytes_between_hash_lookups = skip >> 5;
150 const bytes_between_hash_lookups = skip >> 5;
151151 next_s = s + bytes_between_hash_lookups;
152152 skip += bytes_between_hash_lookups;
153153 if (next_s > s_limit) {
154154 break :outer;
155155 }
156156 candidate = self.table[next_hash & table_mask];
157 var now = load32(src, next_s);
157 const now = load32(src, next_s);
158158 self.table[next_hash & table_mask] = .{ .offset = s + self.cur, .val = cv };
159159 next_hash = hash(now);
160160
161 var offset = s - (candidate.offset - self.cur);
161 const offset = s - (candidate.offset - self.cur);
162162 if (offset > max_match_offset or cv != candidate.val) {
163163 // Out of range or not matched.
164164 cv = now;
......@@ -187,8 +187,8 @@ pub const DeflateFast = struct {
187187 // Extend the 4-byte match as long as possible.
188188 //
189189 s += 4;
190 var t = candidate.offset - self.cur + 4;
191 var l = self.matchLen(s, t, src);
190 const t = candidate.offset - self.cur + 4;
191 const l = self.matchLen(s, t, src);
192192
193193 // matchToken is flate's equivalent of Snappy's emitCopy. (length,offset)
194194 dst[tokens_count.*] = token.matchToken(
......@@ -209,20 +209,20 @@ pub const DeflateFast = struct {
209209 // are faster as one load64 call (with some shifts) instead of
210210 // three load32 calls.
211211 var x = load64(src, s - 1);
212 var prev_hash = hash(@as(u32, @truncate(x)));
212 const prev_hash = hash(@as(u32, @truncate(x)));
213213 self.table[prev_hash & table_mask] = TableEntry{
214214 .offset = self.cur + s - 1,
215215 .val = @as(u32, @truncate(x)),
216216 };
217217 x >>= 8;
218 var curr_hash = hash(@as(u32, @truncate(x)));
218 const curr_hash = hash(@as(u32, @truncate(x)));
219219 candidate = self.table[curr_hash & table_mask];
220220 self.table[curr_hash & table_mask] = TableEntry{
221221 .offset = self.cur + s,
222222 .val = @as(u32, @truncate(x)),
223223 };
224224
225 var offset = s - (candidate.offset - self.cur);
225 const offset = s - (candidate.offset - self.cur);
226226 if (offset > max_match_offset or @as(u32, @truncate(x)) != candidate.val) {
227227 cv = @as(u32, @truncate(x >> 8));
228228 next_hash = hash(cv);
......@@ -261,7 +261,7 @@ pub const DeflateFast = struct {
261261 // If we are inside the current block
262262 if (t >= 0) {
263263 var b = src[@as(usize, @intCast(t))..];
264 var a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))];
264 const a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))];
265265 b = b[0..a.len];
266266 // Extend the match to be as long as possible.
267267 for (a, 0..) |_, i| {
......@@ -273,7 +273,7 @@ pub const DeflateFast = struct {
273273 }
274274
275275 // We found a match in the previous block.
276 var tp = @as(i32, @intCast(self.prev_len)) + t;
276 const tp = @as(i32, @intCast(self.prev_len)) + t;
277277 if (tp < 0) {
278278 return 0;
279279 }
......@@ -293,7 +293,7 @@ pub const DeflateFast = struct {
293293
294294 // If we reached our limit, we matched everything we are
295295 // allowed to in the previous block and we return.
296 var n = @as(i32, @intCast(b.len));
296 const n = @as(i32, @intCast(b.len));
297297 if (@as(u32, @intCast(s + n)) == s1) {
298298 return n;
299299 }
......@@ -366,7 +366,7 @@ test "best speed match 1/3" {
366366 .cur = 0,
367367 };
368368 var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 };
369 var got: i32 = e.matchLen(3, -3, &current);
369 const got: i32 = e.matchLen(3, -3, &current);
370370 try expectEqual(@as(i32, 6), got);
371371 }
372372 {
......@@ -379,7 +379,7 @@ test "best speed match 1/3" {
379379 .cur = 0,
380380 };
381381 var current = [_]u8{ 2, 4, 5, 0, 1, 2, 3, 4, 5 };
382 var got: i32 = e.matchLen(3, -3, &current);
382 const got: i32 = e.matchLen(3, -3, &current);
383383 try expectEqual(@as(i32, 3), got);
384384 }
385385 {
......@@ -392,7 +392,7 @@ test "best speed match 1/3" {
392392 .cur = 0,
393393 };
394394 var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 };
395 var got: i32 = e.matchLen(3, -3, &current);
395 const got: i32 = e.matchLen(3, -3, &current);
396396 try expectEqual(@as(i32, 2), got);
397397 }
398398 {
......@@ -405,7 +405,7 @@ test "best speed match 1/3" {
405405 .cur = 0,
406406 };
407407 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
408 var got: i32 = e.matchLen(0, -1, &current);
408 const got: i32 = e.matchLen(0, -1, &current);
409409 try expectEqual(@as(i32, 4), got);
410410 }
411411 {
......@@ -418,7 +418,7 @@ test "best speed match 1/3" {
418418 .cur = 0,
419419 };
420420 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
421 var got: i32 = e.matchLen(4, -7, &current);
421 const got: i32 = e.matchLen(4, -7, &current);
422422 try expectEqual(@as(i32, 5), got);
423423 }
424424 {
......@@ -431,7 +431,7 @@ test "best speed match 1/3" {
431431 .cur = 0,
432432 };
433433 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
434 var got: i32 = e.matchLen(0, -1, &current);
434 const got: i32 = e.matchLen(0, -1, &current);
435435 try expectEqual(@as(i32, 0), got);
436436 }
437437 {
......@@ -444,7 +444,7 @@ test "best speed match 1/3" {
444444 .cur = 0,
445445 };
446446 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };
447 var got: i32 = e.matchLen(1, 0, &current);
447 const got: i32 = e.matchLen(1, 0, &current);
448448 try expectEqual(@as(i32, 0), got);
449449 }
450450}
......@@ -462,7 +462,7 @@ test "best speed match 2/3" {
462462 .cur = 0,
463463 };
464464 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };
465 var got: i32 = e.matchLen(1, -5, &current);
465 const got: i32 = e.matchLen(1, -5, &current);
466466 try expectEqual(@as(i32, 0), got);
467467 }
468468 {
......@@ -475,7 +475,7 @@ test "best speed match 2/3" {
475475 .cur = 0,
476476 };
477477 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };
478 var got: i32 = e.matchLen(1, -1, &current);
478 const got: i32 = e.matchLen(1, -1, &current);
479479 try expectEqual(@as(i32, 0), got);
480480 }
481481 {
......@@ -488,7 +488,7 @@ test "best speed match 2/3" {
488488 .cur = 0,
489489 };
490490 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
491 var got: i32 = e.matchLen(1, 0, &current);
491 const got: i32 = e.matchLen(1, 0, &current);
492492 try expectEqual(@as(i32, 3), got);
493493 }
494494 {
......@@ -501,7 +501,7 @@ test "best speed match 2/3" {
501501 .cur = 0,
502502 };
503503 var current = [_]u8{ 3, 4, 5 };
504 var got: i32 = e.matchLen(0, -3, &current);
504 const got: i32 = e.matchLen(0, -3, &current);
505505 try expectEqual(@as(i32, 3), got);
506506 }
507507}
......@@ -564,11 +564,11 @@ test "best speed match 2/2" {
564564 };
565565
566566 for (cases) |c| {
567 var previous = try testing.allocator.alloc(u8, c.previous);
567 const previous = try testing.allocator.alloc(u8, c.previous);
568568 defer testing.allocator.free(previous);
569569 @memset(previous, 0);
570570
571 var current = try testing.allocator.alloc(u8, c.current);
571 const current = try testing.allocator.alloc(u8, c.current);
572572 defer testing.allocator.free(current);
573573 @memset(current, 0);
574574
......@@ -579,7 +579,7 @@ test "best speed match 2/2" {
579579 .allocator = undefined,
580580 .cur = 0,
581581 };
582 var got: i32 = e.matchLen(c.s, c.t, current);
582 const got: i32 = e.matchLen(c.s, c.t, current);
583583 try expectEqual(@as(i32, c.expected), got);
584584 }
585585}
......@@ -609,10 +609,10 @@ test "best speed shift offsets" {
609609 // Second part should pick up matches from the first block.
610610 tokens_count = 0;
611611 enc.encode(&tokens, &tokens_count, &test_data);
612 var want_first_tokens = tokens_count;
612 const want_first_tokens = tokens_count;
613613 tokens_count = 0;
614614 enc.encode(&tokens, &tokens_count, &test_data);
615 var want_second_tokens = tokens_count;
615 const want_second_tokens = tokens_count;
616616
617617 try expect(want_first_tokens > want_second_tokens);
618618
......@@ -657,7 +657,7 @@ test "best speed reset" {
657657 const ArrayList = std.ArrayList;
658658
659659 const input_size = 65536;
660 var input = try testing.allocator.alloc(u8, input_size);
660 const input = try testing.allocator.alloc(u8, input_size);
661661 defer testing.allocator.free(input);
662662
663663 var i: usize = 0;
......@@ -699,7 +699,7 @@ test "best speed reset" {
699699 // Reset until we are right before the wraparound.
700700 // Each reset adds max_match_offset to the offset.
701701 i = 0;
702 var limit = (buffer_reset - input.len - o - max_match_offset) / max_match_offset;
702 const limit = (buffer_reset - input.len - o - max_match_offset) / max_match_offset;
703703 while (i < limit) : (i += 1) {
704704 // skip ahead to where we are close to wrap around...
705705 comp.reset(discard.writer());
lib/std/compress/deflate/deflate_fast_test.zig+9-9
......@@ -39,18 +39,18 @@ test "best speed" {
3939 var tc_15 = [_]u32{ 65536, 129 };
4040 var tc_16 = [_]u32{ 65536, 65536, 256 };
4141 var tc_17 = [_]u32{ 65536, 65536, 65536 };
42 var test_cases = [_][]u32{
42 const test_cases = [_][]u32{
4343 &tc_01, &tc_02, &tc_03, &tc_04, &tc_05, &tc_06, &tc_07, &tc_08, &tc_09, &tc_10,
4444 &tc_11, &tc_12, &tc_13, &tc_14, &tc_15, &tc_16, &tc_17,
4545 };
4646
4747 for (test_cases) |tc| {
48 var firsts = [_]u32{ 1, 65534, 65535, 65536, 65537, 131072 };
48 const firsts = [_]u32{ 1, 65534, 65535, 65536, 65537, 131072 };
4949
5050 for (firsts) |first_n| {
5151 tc[0] = first_n;
5252
53 var to_flush = [_]bool{ false, true };
53 const to_flush = [_]bool{ false, true };
5454 for (to_flush) |flush| {
5555 var compressed = ArrayList(u8).init(testing.allocator);
5656 defer compressed.deinit();
......@@ -75,14 +75,14 @@ test "best speed" {
7575
7676 try comp.close();
7777
78 var decompressed = try testing.allocator.alloc(u8, want.items.len);
78 const decompressed = try testing.allocator.alloc(u8, want.items.len);
7979 defer testing.allocator.free(decompressed);
8080
8181 var fib = io.fixedBufferStream(compressed.items);
8282 var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null);
8383 defer decomp.deinit();
8484
85 var read = try decomp.reader().readAll(decompressed);
85 const read = try decomp.reader().readAll(decompressed);
8686 _ = decomp.close();
8787
8888 try testing.expectEqual(want.items.len, read);
......@@ -109,7 +109,7 @@ test "best speed max match offset" {
109109 for (extras) |extra| {
110110 var offset_adj: i32 = -5;
111111 while (offset_adj <= 5) : (offset_adj += 1) {
112 var offset = deflate_const.max_match_offset + offset_adj;
112 const offset = deflate_const.max_match_offset + offset_adj;
113113
114114 // Make src to be a []u8 of the form
115115 // fmt("{s}{s}{s}{s}{s}", .{abc, zeros0, xyzMaybe, abc, zeros1})
......@@ -119,7 +119,7 @@ test "best speed max match offset" {
119119 // zeros1 is between 0 and 30 zeros.
120120 // The difference between the two abc's will be offset, which
121121 // is max_match_offset plus or minus a small adjustment.
122 var src_len: usize = @as(usize, @intCast(offset + @as(i32, abc.len) + @as(i32, @intCast(extra))));
122 const src_len: usize = @as(usize, @intCast(offset + @as(i32, abc.len) + @as(i32, @intCast(extra))));
123123 var src = try testing.allocator.alloc(u8, src_len);
124124 defer testing.allocator.free(src);
125125
......@@ -143,13 +143,13 @@ test "best speed max match offset" {
143143 try comp.writer().writeAll(src);
144144 _ = try comp.close();
145145
146 var decompressed = try testing.allocator.alloc(u8, src.len);
146 const decompressed = try testing.allocator.alloc(u8, src.len);
147147 defer testing.allocator.free(decompressed);
148148
149149 var fib = io.fixedBufferStream(compressed.items);
150150 var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null);
151151 defer decomp.deinit();
152 var read = try decomp.reader().readAll(decompressed);
152 const read = try decomp.reader().readAll(decompressed);
153153 _ = decomp.close();
154154
155155 try testing.expectEqual(src.len, read);
lib/std/compress/deflate/dict_decoder.zig+7-7
......@@ -123,7 +123,7 @@ pub const DictDecoder = struct {
123123 // This invariant must be kept: 0 < dist <= histSize()
124124 pub fn writeCopy(self: *Self, dist: u32, length: u32) u32 {
125125 assert(0 < dist and dist <= self.histSize());
126 var dst_base = self.wr_pos;
126 const dst_base = self.wr_pos;
127127 var dst_pos = dst_base;
128128 var src_pos: i32 = @as(i32, @intCast(dst_pos)) - @as(i32, @intCast(dist));
129129 var end_pos = dst_pos + length;
......@@ -175,12 +175,12 @@ pub const DictDecoder = struct {
175175 // This invariant must be kept: 0 < dist <= histSize()
176176 pub fn tryWriteCopy(self: *Self, dist: u32, length: u32) u32 {
177177 var dst_pos = self.wr_pos;
178 var end_pos = dst_pos + length;
178 const end_pos = dst_pos + length;
179179 if (dst_pos < dist or end_pos > self.hist.len) {
180180 return 0;
181181 }
182 var dst_base = dst_pos;
183 var src_pos = dst_pos - dist;
182 const dst_base = dst_pos;
183 const src_pos = dst_pos - dist;
184184
185185 // Copy possibly overlapping section before destination position.
186186 while (dst_pos < end_pos) {
......@@ -195,7 +195,7 @@ pub const DictDecoder = struct {
195195 // emitted to the user. The data returned by readFlush must be fully consumed
196196 // before calling any other DictDecoder methods.
197197 pub fn readFlush(self: *Self) []u8 {
198 var to_read = self.hist[self.rd_pos..self.wr_pos];
198 const to_read = self.hist[self.rd_pos..self.wr_pos];
199199 self.rd_pos = self.wr_pos;
200200 if (self.wr_pos == self.hist.len) {
201201 self.wr_pos = 0;
......@@ -279,7 +279,7 @@ test "dictionary decoder" {
279279 length: u32, // Length of copy or insertion
280280 };
281281
282 var poem_refs = [_]PoemRefs{
282 const poem_refs = [_]PoemRefs{
283283 .{ .dist = 0, .length = 38 }, .{ .dist = 33, .length = 3 }, .{ .dist = 0, .length = 48 },
284284 .{ .dist = 79, .length = 3 }, .{ .dist = 0, .length = 11 }, .{ .dist = 34, .length = 5 },
285285 .{ .dist = 0, .length = 6 }, .{ .dist = 23, .length = 7 }, .{ .dist = 0, .length = 8 },
......@@ -368,7 +368,7 @@ test "dictionary decoder" {
368368 fn writeString(dst_dd: *DictDecoder, dst: anytype, str: []const u8) !void {
369369 var string = str;
370370 while (string.len > 0) {
371 var cnt = DictDecoder.copy(dst_dd.writeSlice(), string);
371 const cnt = DictDecoder.copy(dst_dd.writeSlice(), string);
372372 dst_dd.writeMark(cnt);
373373 string = string[cnt..];
374374 if (dst_dd.availWrite() == 0) {
lib/std/compress/deflate/huffman_bit_writer.zig+43-43
......@@ -134,7 +134,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
134134 self.bits |= @as(u64, @intCast(b)) << @as(u6, @intCast(self.nbits));
135135 self.nbits += nb;
136136 if (self.nbits >= 48) {
137 var bits = self.bits;
137 const bits = self.bits;
138138 self.bits >>= 48;
139139 self.nbits -= 48;
140140 var n = self.nbytes;
......@@ -224,7 +224,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
224224 while (size != bad_code) : (in_index += 1) {
225225 // INVARIANT: We have seen "count" copies of size that have not yet
226226 // had output generated for them.
227 var next_size = codegen[in_index];
227 const next_size = codegen[in_index];
228228 if (next_size == size) {
229229 count += 1;
230230 continue;
......@@ -295,12 +295,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
295295 while (num_codegens > 4 and self.codegen_freq[codegen_order[num_codegens - 1]] == 0) {
296296 num_codegens -= 1;
297297 }
298 var header = 3 + 5 + 5 + 4 + (3 * num_codegens) +
298 const header = 3 + 5 + 5 + 4 + (3 * num_codegens) +
299299 self.codegen_encoding.bitLength(self.codegen_freq[0..]) +
300300 self.codegen_freq[16] * 2 +
301301 self.codegen_freq[17] * 3 +
302302 self.codegen_freq[18] * 7;
303 var size = header +
303 const size = header +
304304 lit_enc.bitLength(self.literal_freq) +
305305 off_enc.bitLength(self.offset_freq) +
306306 extra_bits;
......@@ -339,7 +339,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
339339 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));
340340 self.nbits += @as(u32, @intCast(c.len));
341341 if (self.nbits >= 48) {
342 var bits = self.bits;
342 const bits = self.bits;
343343 self.bits >>= 48;
344344 self.nbits -= 48;
345345 var n = self.nbytes;
......@@ -386,13 +386,13 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
386386
387387 var i: u32 = 0;
388388 while (i < num_codegens) : (i += 1) {
389 var value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len));
389 const value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len));
390390 try self.writeBits(@as(u32, @intCast(value)), 3);
391391 }
392392
393393 i = 0;
394394 while (true) {
395 var code_word: u32 = @as(u32, @intCast(self.codegen[i]));
395 const code_word: u32 = @as(u32, @intCast(self.codegen[i]));
396396 i += 1;
397397 if (code_word == bad_code) {
398398 break;
......@@ -458,14 +458,14 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
458458 return;
459459 }
460460
461 var lit_and_off = self.indexTokens(tokens);
462 var num_literals = lit_and_off.num_literals;
463 var num_offsets = lit_and_off.num_offsets;
461 const lit_and_off = self.indexTokens(tokens);
462 const num_literals = lit_and_off.num_literals;
463 const num_offsets = lit_and_off.num_offsets;
464464
465465 var extra_bits: u32 = 0;
466 var ret = storedSizeFits(input);
467 var stored_size = ret.size;
468 var storable = ret.storable;
466 const ret = storedSizeFits(input);
467 const stored_size = ret.size;
468 const storable = ret.storable;
469469
470470 if (storable) {
471471 // We only bother calculating the costs of the extra bits required by
......@@ -504,12 +504,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
504504 &self.offset_encoding,
505505 );
506506 self.codegen_encoding.generate(self.codegen_freq[0..], 7);
507 var dynamic_size = self.dynamicSize(
507 const dynamic_size = self.dynamicSize(
508508 &self.literal_encoding,
509509 &self.offset_encoding,
510510 extra_bits,
511511 );
512 var dyn_size = dynamic_size.size;
512 const dyn_size = dynamic_size.size;
513513 num_codegens = dynamic_size.num_codegens;
514514
515515 if (dyn_size < size) {
......@@ -551,9 +551,9 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
551551 return;
552552 }
553553
554 var total_tokens = self.indexTokens(tokens);
555 var num_literals = total_tokens.num_literals;
556 var num_offsets = total_tokens.num_offsets;
554 const total_tokens = self.indexTokens(tokens);
555 const num_literals = total_tokens.num_literals;
556 const num_offsets = total_tokens.num_offsets;
557557
558558 // Generate codegen and codegenFrequencies, which indicates how to encode
559559 // the literal_encoding and the offset_encoding.
......@@ -564,15 +564,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
564564 &self.offset_encoding,
565565 );
566566 self.codegen_encoding.generate(self.codegen_freq[0..], 7);
567 var dynamic_size = self.dynamicSize(&self.literal_encoding, &self.offset_encoding, 0);
568 var size = dynamic_size.size;
569 var num_codegens = dynamic_size.num_codegens;
567 const dynamic_size = self.dynamicSize(&self.literal_encoding, &self.offset_encoding, 0);
568 const size = dynamic_size.size;
569 const num_codegens = dynamic_size.num_codegens;
570570
571571 // Store bytes, if we don't get a reasonable improvement.
572572
573 var stored_size = storedSizeFits(input);
574 var ssize = stored_size.size;
575 var storable = stored_size.storable;
573 const stored_size = storedSizeFits(input);
574 const ssize = stored_size.size;
575 const storable = stored_size.storable;
576576 if (storable and ssize < (size + (size >> 4))) {
577577 try self.writeStoredHeader(input.?.len, eof);
578578 try self.writeBytes(input.?);
......@@ -611,8 +611,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
611611 self.literal_freq[token.literal(t)] += 1;
612612 continue;
613613 }
614 var length = token.length(t);
615 var offset = token.offset(t);
614 const length = token.length(t);
615 const offset = token.offset(t);
616616 self.literal_freq[length_codes_start + token.lengthCode(length)] += 1;
617617 self.offset_freq[token.offsetCode(offset)] += 1;
618618 }
......@@ -660,21 +660,21 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
660660 continue;
661661 }
662662 // Write the length
663 var length = token.length(t);
664 var length_code = token.lengthCode(length);
663 const length = token.length(t);
664 const length_code = token.lengthCode(length);
665665 try self.writeCode(le_codes[length_code + length_codes_start]);
666 var extra_length_bits = @as(u32, @intCast(length_extra_bits[length_code]));
666 const extra_length_bits = @as(u32, @intCast(length_extra_bits[length_code]));
667667 if (extra_length_bits > 0) {
668 var extra_length = @as(u32, @intCast(length - length_base[length_code]));
668 const extra_length = @as(u32, @intCast(length - length_base[length_code]));
669669 try self.writeBits(extra_length, extra_length_bits);
670670 }
671671 // Write the offset
672 var offset = token.offset(t);
673 var offset_code = token.offsetCode(offset);
672 const offset = token.offset(t);
673 const offset_code = token.offsetCode(offset);
674674 try self.writeCode(oe_codes[offset_code]);
675 var extra_offset_bits = @as(u32, @intCast(offset_extra_bits[offset_code]));
675 const extra_offset_bits = @as(u32, @intCast(offset_extra_bits[offset_code]));
676676 if (extra_offset_bits > 0) {
677 var extra_offset = @as(u32, @intCast(offset - offset_base[offset_code]));
677 const extra_offset = @as(u32, @intCast(offset - offset_base[offset_code]));
678678 try self.writeBits(extra_offset, extra_offset_bits);
679679 }
680680 }
......@@ -718,15 +718,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
718718 &self.huff_offset,
719719 );
720720 self.codegen_encoding.generate(self.codegen_freq[0..], 7);
721 var dynamic_size = self.dynamicSize(&self.literal_encoding, &self.huff_offset, 0);
722 var size = dynamic_size.size;
721 const dynamic_size = self.dynamicSize(&self.literal_encoding, &self.huff_offset, 0);
722 const size = dynamic_size.size;
723723 num_codegens = dynamic_size.num_codegens;
724724
725725 // Store bytes, if we don't get a reasonable improvement.
726726
727 var stored_size_ret = storedSizeFits(input);
728 var ssize = stored_size_ret.size;
729 var storable = stored_size_ret.storable;
727 const stored_size_ret = storedSizeFits(input);
728 const ssize = stored_size_ret.size;
729 const storable = stored_size_ret.storable;
730730
731731 if (storable and ssize < (size + (size >> 4))) {
732732 try self.writeStoredHeader(input.len, eof);
......@@ -736,18 +736,18 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
736736
737737 // Huffman.
738738 try self.writeDynamicHeader(num_literals, num_offsets, num_codegens, eof);
739 var encoding = self.literal_encoding.codes[0..257];
739 const encoding = self.literal_encoding.codes[0..257];
740740 var n = self.nbytes;
741741 for (input) |t| {
742742 // Bitwriting inlined, ~30% speedup
743 var c = encoding[t];
743 const c = encoding[t];
744744 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));
745745 self.nbits += @as(u32, @intCast(c.len));
746746 if (self.nbits < 48) {
747747 continue;
748748 }
749749 // Store 6 bytes
750 var bits = self.bits;
750 const bits = self.bits;
751751 self.bits >>= 48;
752752 self.nbits -= 48;
753753 var bytes = self.bytes[n..][0..6];
......@@ -1679,7 +1679,7 @@ fn testWriterEOF(ttype: TestType, ht_tokens: []const token.Token, input: []const
16791679
16801680 try bw.flush();
16811681
1682 var b = buf.items;
1682 const b = buf.items;
16831683 try expect(b.len > 0);
16841684 try expect(b[0] & 1 == 1);
16851685}
lib/std/compress/deflate/huffman_code.zig+8-8
......@@ -96,7 +96,7 @@ pub const HuffmanEncoder = struct {
9696 mem.sort(LiteralNode, self.lfs, {}, byFreq);
9797
9898 // Get the number of literals for each bit count
99 var bit_count = self.bitCounts(list, max_bits);
99 const bit_count = self.bitCounts(list, max_bits);
100100 // And do the assignment
101101 self.assignEncodingAndSize(bit_count, list);
102102 }
......@@ -128,7 +128,7 @@ pub const HuffmanEncoder = struct {
128128 // that should be encoded in i bits.
129129 fn bitCounts(self: *HuffmanEncoder, list: []LiteralNode, max_bits_to_use: usize) []u32 {
130130 var max_bits = max_bits_to_use;
131 var n = list.len;
131 const n = list.len;
132132
133133 assert(max_bits < max_bits_limit);
134134
......@@ -184,10 +184,10 @@ pub const HuffmanEncoder = struct {
184184 continue;
185185 }
186186
187 var prev_freq = l.last_freq;
187 const prev_freq = l.last_freq;
188188 if (l.next_char_freq < l.next_pair_freq) {
189189 // The next item on this row is a leaf node.
190 var next = leaf_counts[level][level] + 1;
190 const next = leaf_counts[level][level] + 1;
191191 l.last_freq = l.next_char_freq;
192192 // Lower leaf_counts are the same of the previous node.
193193 leaf_counts[level][level] = next;
......@@ -236,7 +236,7 @@ pub const HuffmanEncoder = struct {
236236
237237 var bit_count = self.bit_count[0 .. max_bits + 1];
238238 var bits: u32 = 1;
239 var counts = &leaf_counts[max_bits];
239 const counts = &leaf_counts[max_bits];
240240 {
241241 var level = max_bits;
242242 while (level > 0) : (level -= 1) {
......@@ -267,7 +267,7 @@ pub const HuffmanEncoder = struct {
267267 // are encoded using "bits" bits, and get the values
268268 // code, code + 1, .... The code values are
269269 // assigned in literal order (not frequency order).
270 var chunk = list[list.len - @as(u32, @intCast(bits)) ..];
270 const chunk = list[list.len - @as(u32, @intCast(bits)) ..];
271271
272272 self.lns = chunk;
273273 mem.sort(LiteralNode, self.lns, {}, byLiteral);
......@@ -303,7 +303,7 @@ pub fn newHuffmanEncoder(allocator: Allocator, size: u32) !HuffmanEncoder {
303303
304304// Generates a HuffmanCode corresponding to the fixed literal table
305305pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder {
306 var h = try newHuffmanEncoder(allocator, deflate_const.max_num_frequencies);
306 const h = try newHuffmanEncoder(allocator, deflate_const.max_num_frequencies);
307307 var codes = h.codes;
308308 var ch: u16 = 0;
309309
......@@ -338,7 +338,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder {
338338}
339339
340340pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder {
341 var h = try newHuffmanEncoder(allocator, 30);
341 const h = try newHuffmanEncoder(allocator, 30);
342342 var codes = h.codes;
343343 for (codes, 0..) |_, ch| {
344344 codes[ch] = HuffCode{ .code = bu.bitReverse(u16, @as(u16, @intCast(ch)), 5), .len = 5 };
lib/std/compress/zstandard.zig+1-1
......@@ -268,7 +268,7 @@ test "zstandard decompression" {
268268 const compressed3 = @embedFile("testdata/rfc8478.txt.zst.3");
269269 const compressed19 = @embedFile("testdata/rfc8478.txt.zst.19");
270270
271 var buffer = try std.testing.allocator.alloc(u8, uncompressed.len);
271 const buffer = try std.testing.allocator.alloc(u8, uncompressed.len);
272272 defer std.testing.allocator.free(buffer);
273273
274274 const res3 = try decompress.decode(buffer, compressed3, true);
lib/std/compress/zstandard/decode/huffman.zig+1-1
......@@ -54,7 +54,7 @@ fn decodeFseHuffmanTreeSlice(src: []const u8, compressed_size: usize, weights: *
5454
5555 const start_index = std.math.cast(usize, counting_reader.bytes_read) orelse
5656 return error.MalformedHuffmanTree;
57 var huff_data = src[start_index..compressed_size];
57 const huff_data = src[start_index..compressed_size];
5858 var huff_bits: readers.ReverseBitReader = undefined;
5959 huff_bits.init(huff_data) catch return error.MalformedHuffmanTree;
6060
lib/std/compress/zstandard/decompress.zig+2-2
......@@ -304,7 +304,7 @@ pub fn decodeZstandardFrame(
304304
305305 var frame_context = context: {
306306 var fbs = std.io.fixedBufferStream(src[consumed_count..]);
307 var source = fbs.reader();
307 const source = fbs.reader();
308308 const frame_header = try decodeZstandardHeader(source);
309309 consumed_count += fbs.pos;
310310 break :context FrameContext.init(
......@@ -447,7 +447,7 @@ pub fn decodeZstandardFrameArrayList(
447447
448448 var frame_context = context: {
449449 var fbs = std.io.fixedBufferStream(src[consumed_count..]);
450 var source = fbs.reader();
450 const source = fbs.reader();
451451 const frame_header = try decodeZstandardHeader(source);
452452 consumed_count += fbs.pos;
453453 break :context try FrameContext.init(frame_header, window_size_max, verify_checksum);
lib/std/crypto/25519/curve25519.zig+1-1
......@@ -129,7 +129,7 @@ test "non-affine edwards25519 to curve25519 projection" {
129129 const skh = "90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e";
130130 var sk: [32]u8 = undefined;
131131 _ = std.fmt.hexToBytes(&sk, skh) catch unreachable;
132 var edp = try crypto.ecc.Edwards25519.basePoint.mul(sk);
132 const edp = try crypto.ecc.Edwards25519.basePoint.mul(sk);
133133 const xp = try Curve25519.fromEdwards25519(edp);
134134 const expected_hex = "cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378";
135135 var expected: [32]u8 = undefined;
lib/std/crypto/25519/field.zig+1-1
......@@ -416,7 +416,7 @@ pub const Fe = struct {
416416
417417 /// Compute the square root of `x2`, returning `error.NotSquare` if `x2` was not a square
418418 pub fn sqrt(x2: Fe) NotSquareError!Fe {
419 var x2_copy = x2;
419 const x2_copy = x2;
420420 const x = x2.uncheckedSqrt();
421421 const check = x.sq().sub(x2_copy);
422422 if (check.isZero()) {
lib/std/crypto/Certificate.zig+1-1
......@@ -982,7 +982,7 @@ pub const rsa = struct {
982982 if (mgf_len > mgf_out_buf.len) { // Modulus > 4096 bits
983983 return error.InvalidSignature;
984984 }
985 var mgf_out = mgf_out_buf[0 .. ((mgf_len - 1) / Hash.digest_length + 1) * Hash.digest_length];
985 const mgf_out = mgf_out_buf[0 .. ((mgf_len - 1) / Hash.digest_length + 1) * Hash.digest_length];
986986 var dbMask = try MGF1(Hash, mgf_out, h, mgf_len);
987987
988988 // 8. Let DB = maskedDB \xor dbMask.
lib/std/crypto/aes.zig+1-1
......@@ -47,7 +47,7 @@ test "ctr" {
4747 };
4848
4949 var out: [exp_out.len]u8 = undefined;
50 var ctx = Aes128.initEnc(key);
50 const ctx = Aes128.initEnc(key);
5151 ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.big);
5252 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
5353}
lib/std/crypto/aes_ocb.zig+1-1
......@@ -95,7 +95,7 @@ fn AesOcb(comptime Aes: anytype) type {
9595 var ktop_: Block = undefined;
9696 aes_enc_ctx.encrypt(&ktop_, &nx);
9797 const ktop = mem.readInt(u128, &ktop_, .big);
98 var stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56)));
98 const stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56)));
9999 var offset: Block = undefined;
100100 mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .big);
101101 return offset;
lib/std/crypto/argon2.zig+1-1
......@@ -565,7 +565,7 @@ const PhcFormatHasher = struct {
565565 const expected_hash = hash_result.hash.constSlice();
566566 var hash_buf: [max_hash_len]u8 = undefined;
567567 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;
568 var hash = hash_buf[0..expected_hash.len];
568 const hash = hash_buf[0..expected_hash.len];
569569
570570 try kdf(allocator, hash, password, hash_result.salt.constSlice(), params, mode);
571571 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;
lib/std/crypto/ascon.zig+1-2
......@@ -42,8 +42,7 @@ pub fn State(comptime endian: std.builtin.Endian) type {
4242
4343 /// Initialize the state from u64 words in native endianness.
4444 pub fn initFromWords(initial_state: [5]u64) Self {
45 var state = Self{ .st = initial_state };
46 return state;
45 return .{ .st = initial_state };
4746 }
4847
4948 /// Initialize the state for Ascon XOF
lib/std/crypto/bcrypt.zig+1-1
......@@ -431,7 +431,7 @@ pub fn bcrypt(
431431 const trimmed_len = @min(password.len, password_buf.len - 1);
432432 @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]);
433433 password_buf[trimmed_len] = 0;
434 var passwordZ = password_buf[0 .. trimmed_len + 1];
434 const passwordZ = password_buf[0 .. trimmed_len + 1];
435435 state.expand(salt[0..], passwordZ);
436436
437437 const rounds: u64 = @as(u64, 1) << params.rounds_log;
lib/std/crypto/blake3.zig+1-1
......@@ -241,7 +241,7 @@ const Output = struct {
241241 var out_block_it = ChunkIterator.init(output, 2 * OUT_LEN);
242242 var output_block_counter: usize = 0;
243243 while (out_block_it.next()) |out_block| {
244 var words = compress(
244 const words = compress(
245245 self.input_chaining_value,
246246 self.block_words,
247247 self.block_len,
lib/std/crypto/ecdsa.zig+1-1
......@@ -201,7 +201,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
201201 const scalar_encoded_length = Curve.scalar.encoded_length;
202202 const h_len = @max(Hash.digest_length, scalar_encoded_length);
203203 var h: [h_len]u8 = [_]u8{0} ** h_len;
204 var h_slice = h[h_len - Hash.digest_length .. h_len];
204 const h_slice = h[h_len - Hash.digest_length .. h_len];
205205 self.h.final(h_slice);
206206
207207 std.debug.assert(h.len >= scalar_encoded_length);
lib/std/crypto/pbkdf2.zig+2-4
......@@ -255,10 +255,8 @@ test "Very large dk_len" {
255255 const c = 1;
256256 const dk_len = 1 << 33;
257257
258 var dk = try std.testing.allocator.alloc(u8, dk_len);
259 defer {
260 std.testing.allocator.free(dk);
261 }
258 const dk = try std.testing.allocator.alloc(u8, dk_len);
259 defer std.testing.allocator.free(dk);
262260
263261 // Just verify this doesn't crash with an overflow
264262 try pbkdf2(dk, p, s, c, HmacSha1);
lib/std/crypto/pcurves/common.zig+1-1
......@@ -71,7 +71,7 @@ pub fn Field(comptime params: FieldParams) type {
7171
7272 /// Unpack a field element.
7373 pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe {
74 var s = if (endian == .little) s_ else orderSwap(s_);
74 const s = if (endian == .little) s_ else orderSwap(s_);
7575 try rejectNonCanonical(s, .little);
7676 var limbs_z: NonMontgomeryDomainFieldElement = undefined;
7777 fiat.fromBytes(&limbs_z, s);
lib/std/crypto/poly1305.zig+3-3
......@@ -90,8 +90,8 @@ pub const Poly1305 = struct {
9090 h2 = t2 & 3;
9191
9292 // Add c*(4+1)
93 var cclo = t2 & ~@as(u64, 3);
94 var cchi = t3;
93 const cclo = t2 & ~@as(u64, 3);
94 const cchi = t3;
9595 v = @addWithOverflow(h0, cclo);
9696 h0 = v[0];
9797 v = add(h1, cchi, v[1]);
......@@ -163,7 +163,7 @@ pub const Poly1305 = struct {
163163
164164 var h0 = st.h[0];
165165 var h1 = st.h[1];
166 var h2 = st.h[2];
166 const h2 = st.h[2];
167167
168168 // H - (2^130 - 5)
169169 var v = @subWithOverflow(h0, 0xfffffffffffffffb);
lib/std/crypto/salsa20.zig+3-3
......@@ -605,8 +605,8 @@ test "xsalsa20poly1305 box" {
605605 crypto.random.bytes(&msg);
606606 crypto.random.bytes(&nonce);
607607
608 var kp1 = try Box.KeyPair.create(null);
609 var kp2 = try Box.KeyPair.create(null);
608 const kp1 = try Box.KeyPair.create(null);
609 const kp2 = try Box.KeyPair.create(null);
610610 try Box.seal(boxed[0..], msg[0..], nonce, kp1.public_key, kp2.secret_key);
611611 try Box.open(msg2[0..], boxed[0..], nonce, kp2.public_key, kp1.secret_key);
612612}
......@@ -617,7 +617,7 @@ test "xsalsa20poly1305 sealedbox" {
617617 var boxed: [msg.len + SealedBox.seal_length]u8 = undefined;
618618 crypto.random.bytes(&msg);
619619
620 var kp = try Box.KeyPair.create(null);
620 const kp = try Box.KeyPair.create(null);
621621 try SealedBox.seal(boxed[0..], msg[0..], kp.public_key);
622622 try SealedBox.open(msg2[0..], boxed[0..], kp);
623623}
lib/std/crypto/scrypt.zig+7-7
......@@ -87,8 +87,8 @@ fn integerify(b: []align(16) const u32, r: u30) u64 {
8787}
8888
8989fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void {
90 var x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]);
91 var y: []align(16) u32 = @alignCast(xy[32 * r ..]);
90 const x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]);
91 const y: []align(16) u32 = @alignCast(xy[32 * r ..]);
9292
9393 for (x, 0..) |*v1, j| {
9494 v1.* = mem.readInt(u32, b[4 * j ..][0..4], .little);
......@@ -191,9 +191,9 @@ pub fn kdf(
191191 params.r > max_int / 256 or
192192 n > max_int / 128 / @as(u64, params.r)) return KdfError.WeakParameters;
193193
194 var xy = try allocator.alignedAlloc(u32, 16, 64 * params.r);
194 const xy = try allocator.alignedAlloc(u32, 16, 64 * params.r);
195195 defer allocator.free(xy);
196 var v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r);
196 const v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r);
197197 defer allocator.free(v);
198198 var dk = try allocator.alignedAlloc(u8, 16, params.p * 128 * params.r);
199199 defer allocator.free(dk);
......@@ -263,7 +263,7 @@ const crypt_format = struct {
263263 const value = self.constSlice();
264264 const len = Codec.encodedLen(value.len);
265265 if (len > buf.len) return EncodingError.NoSpaceLeft;
266 var encoded = buf[0..len];
266 const encoded = buf[0..len];
267267 Codec.encode(encoded, value);
268268 return encoded;
269269 }
......@@ -439,7 +439,7 @@ const PhcFormatHasher = struct {
439439 const expected_hash = hash_result.hash.constSlice();
440440 var hash_buf: [max_hash_len]u8 = undefined;
441441 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;
442 var hash = hash_buf[0..expected_hash.len];
442 const hash = hash_buf[0..expected_hash.len];
443443 try kdf(allocator, hash, password, hash_result.salt.constSlice(), params);
444444 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;
445445 }
......@@ -487,7 +487,7 @@ const CryptFormatHasher = struct {
487487 const expected_hash = hash_result.hash.constSlice();
488488 var hash_buf: [max_hash_len]u8 = undefined;
489489 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;
490 var hash = hash_buf[0..expected_hash.len];
490 const hash = hash_buf[0..expected_hash.len];
491491 try kdf(allocator, hash, password, hash_result.salt, params);
492492 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;
493493 }
lib/std/crypto/tls/Client.zig+3-3
......@@ -491,7 +491,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
491491 try all_extd.ensure(4);
492492 const et = all_extd.decode(tls.ExtensionType);
493493 const ext_size = all_extd.decode(u16);
494 var extd = try all_extd.sub(ext_size);
494 const extd = try all_extd.sub(ext_size);
495495 _ = extd;
496496 switch (et) {
497497 .server_name => {},
......@@ -516,7 +516,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
516516 while (!certs_decoder.eof()) {
517517 try certs_decoder.ensure(3);
518518 const cert_size = certs_decoder.decode(u24);
519 var certd = try certs_decoder.sub(cert_size);
519 const certd = try certs_decoder.sub(cert_size);
520520
521521 const subject_cert: Certificate = .{
522522 .buffer = certd.buf,
......@@ -552,7 +552,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
552552
553553 try certs_decoder.ensure(2);
554554 const total_ext_size = certs_decoder.decode(u16);
555 var all_extd = try certs_decoder.sub(total_ext_size);
555 const all_extd = try certs_decoder.sub(total_ext_size);
556556 _ = all_extd;
557557 }
558558 },
lib/std/debug.zig+4-4
......@@ -812,7 +812,7 @@ pub fn writeStackTraceWindows(
812812 var addr_buf: [1024]usize = undefined;
813813 const n = walkStackWindows(addr_buf[0..], context);
814814 const addrs = addr_buf[0..n];
815 var start_i: usize = if (start_addr) |saddr| blk: {
815 const start_i: usize = if (start_addr) |saddr| blk: {
816816 for (addrs, 0..) |addr, i| {
817817 if (addr == saddr) break :blk i;
818818 }
......@@ -1158,7 +1158,7 @@ pub fn readElfDebugInfo(
11581158 var zlib_stream = std.compress.zlib.decompressStream(allocator, section_stream.reader()) catch continue;
11591159 defer zlib_stream.deinit();
11601160
1161 var decompressed_section = try allocator.alloc(u8, chdr.ch_size);
1161 const decompressed_section = try allocator.alloc(u8, chdr.ch_size);
11621162 errdefer allocator.free(decompressed_section);
11631163
11641164 const read = zlib_stream.reader().readAll(decompressed_section) catch continue;
......@@ -2046,7 +2046,7 @@ pub const ModuleDebugInfo = switch (native_os) {
20462046 };
20472047
20482048 try DW.openDwarfDebugInfo(&di, allocator);
2049 var info = OFileInfo{
2049 const info = OFileInfo{
20502050 .di = di,
20512051 .addr_table = addr_table,
20522052 };
......@@ -2122,7 +2122,7 @@ pub const ModuleDebugInfo = switch (native_os) {
21222122
21232123 // Check if its debug infos are already in the cache
21242124 const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0);
2125 var o_file_info = self.ofiles.getPtr(o_file_path) orelse
2125 const o_file_info = self.ofiles.getPtr(o_file_path) orelse
21262126 (self.loadOFile(allocator, o_file_path) catch |err| switch (err) {
21272127 error.FileNotFound,
21282128 error.MissingDebugInfo,
lib/std/dwarf.zig+5-5
......@@ -622,7 +622,7 @@ fn parseFormValue(allocator: mem.Allocator, in_stream: anytype, form_id: u64, en
622622 return parseFormValue(allocator, in_stream, child_form_id, endian, is_64);
623623 }
624624 const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64));
625 var frame = try allocator.create(F);
625 const frame = try allocator.create(F);
626626 defer allocator.destroy(frame);
627627 return await @asyncCall(frame, {}, parseFormValue, .{ allocator, in_stream, child_form_id, endian, is_64 });
628628 },
......@@ -1034,7 +1034,7 @@ pub const DwarfInfo = struct {
10341034 // specified by DW_AT.low_pc or to some other value encoded
10351035 // in the list itself.
10361036 // If no starting value is specified use zero.
1037 var base_address = compile_unit.die.getAttrAddr(di, AT.low_pc, compile_unit.*) catch |err| switch (err) {
1037 const base_address = compile_unit.die.getAttrAddr(di, AT.low_pc, compile_unit.*) catch |err| switch (err) {
10381038 error.MissingDebugInfo => @as(u64, 0), // TODO https://github.com/ziglang/zig/issues/11135
10391039 else => return err,
10401040 };
......@@ -1438,7 +1438,7 @@ pub const DwarfInfo = struct {
14381438 if (opcode == LNS.extended_op) {
14391439 const op_size = try leb.readULEB128(u64, in);
14401440 if (op_size < 1) return badDwarf();
1441 var sub_op = try in.readByte();
1441 const sub_op = try in.readByte();
14421442 switch (sub_op) {
14431443 LNE.end_sequence => {
14441444 prog.end_sequence = true;
......@@ -2308,7 +2308,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo
23082308 else => return badDwarf(),
23092309 };
23102310
2311 var base = switch (enc & EH.PE.rel_mask) {
2311 const base = switch (enc & EH.PE.rel_mask) {
23122312 EH.PE.pcrel => ctx.pc_rel_base,
23132313 EH.PE.textrel => ctx.text_rel_base orelse return error.PointerBaseNotSpecified,
23142314 EH.PE.datarel => ctx.data_rel_base orelse return error.PointerBaseNotSpecified,
......@@ -2624,7 +2624,7 @@ pub const CommonInformationEntry = struct {
26242624 var has_aug_data = false;
26252625
26262626 var aug_str_len: usize = 0;
2627 var aug_str_start = stream.pos;
2627 const aug_str_start = stream.pos;
26282628 var aug_byte = try reader.readByte();
26292629 while (aug_byte != 0) : (aug_byte = try reader.readByte()) {
26302630 switch (aug_byte) {
lib/std/dwarf/expressions.zig+4-4
......@@ -443,7 +443,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
443443 OP.xderef_type,
444444 => {
445445 if (self.stack.items.len == 0) return error.InvalidExpression;
446 var addr = try self.stack.items[self.stack.items.len - 1].asIntegral();
446 const addr = try self.stack.items[self.stack.items.len - 1].asIntegral();
447447 const addr_space_identifier: ?usize = switch (opcode) {
448448 OP.xderef,
449449 OP.xderef_size,
......@@ -1350,7 +1350,7 @@ test "DWARF expressions" {
13501350
13511351 // Arithmetic and Logical Operations
13521352 {
1353 var context = ExpressionContext{};
1353 const context = ExpressionContext{};
13541354
13551355 stack_machine.reset();
13561356 program.clearRetainingCapacity();
......@@ -1474,7 +1474,7 @@ test "DWARF expressions" {
14741474
14751475 // Control Flow Operations
14761476 {
1477 var context = ExpressionContext{};
1477 const context = ExpressionContext{};
14781478 const expected = .{
14791479 .{ OP.le, 1, 1, 0 },
14801480 .{ OP.ge, 1, 0, 1 },
......@@ -1531,7 +1531,7 @@ test "DWARF expressions" {
15311531
15321532 // Type conversions
15331533 {
1534 var context = ExpressionContext{};
1534 const context = ExpressionContext{};
15351535 stack_machine.reset();
15361536 program.clearRetainingCapacity();
15371537
lib/std/enums.zig+4-1
......@@ -123,6 +123,7 @@ pub fn directEnumArray(
123123test "std.enums.directEnumArray" {
124124 const E = enum(i4) { a = 4, b = 6, c = 2 };
125125 var runtime_false: bool = false;
126 _ = &runtime_false;
126127 const array = directEnumArray(E, bool, 4, .{
127128 .a = true,
128129 .b = runtime_false,
......@@ -165,6 +166,7 @@ pub fn directEnumArrayDefault(
165166test "std.enums.directEnumArrayDefault" {
166167 const E = enum(i4) { a = 4, b = 6, c = 2 };
167168 var runtime_false: bool = false;
169 _ = &runtime_false;
168170 const array = directEnumArrayDefault(E, bool, false, 4, .{
169171 .a = true,
170172 .b = runtime_false,
......@@ -179,6 +181,7 @@ test "std.enums.directEnumArrayDefault" {
179181test "std.enums.directEnumArrayDefault slice" {
180182 const E = enum(i4) { a = 4, b = 6, c = 2 };
181183 var runtime_b = "b";
184 _ = &runtime_b;
182185 const array = directEnumArrayDefault(E, []const u8, "default", 4, .{
183186 .a = "a",
184187 .b = runtime_b,
......@@ -196,7 +199,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
196199 return comptime blk: {
197200 const V = @TypeOf(value);
198201 if (V == E) break :blk value;
199 var name: ?[]const u8 = switch (@typeInfo(V)) {
202 const name: ?[]const u8 = switch (@typeInfo(V)) {
200203 .EnumLiteral, .Enum => @tagName(value),
201204 .Pointer => if (std.meta.trait.isZigString(V)) value else null,
202205 else => null,
lib/std/event/group.zig+1-1
......@@ -66,7 +66,7 @@ pub fn Group(comptime ReturnType: type) type {
6666 /// `func` must be async and have return type `ReturnType`.
6767 /// Thread-safe.
6868 pub fn call(self: *Self, comptime func: anytype, args: anytype) error{OutOfMemory}!void {
69 var frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args)));
69 const frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args)));
7070 errdefer self.allocator.destroy(frame);
7171 const node = try self.allocator.create(AllocStack.Node);
7272 errdefer self.allocator.destroy(node);
lib/std/event/loop.zig+1-1
......@@ -753,7 +753,7 @@ pub const Loop = struct {
753753 }
754754 };
755755
756 var run_frame = try alloc.create(@Frame(Wrapper.run));
756 const run_frame = try alloc.create(@Frame(Wrapper.run));
757757 run_frame.* = async Wrapper.run(args, self, alloc);
758758 }
759759
lib/std/event/rwlock.zig+4-4
......@@ -228,7 +228,7 @@ test "std.event.RwLock" {
228228}
229229fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {
230230 var read_nodes: [100]Loop.NextTickNode = undefined;
231 for (read_nodes) |*read_node| {
231 for (&read_nodes) |*read_node| {
232232 const frame = allocator.create(@Frame(readRunner)) catch @panic("memory");
233233 read_node.data = frame;
234234 frame.* = async readRunner(lock);
......@@ -236,19 +236,19 @@ fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {
236236 }
237237
238238 var write_nodes: [shared_it_count]Loop.NextTickNode = undefined;
239 for (write_nodes) |*write_node| {
239 for (&write_nodes) |*write_node| {
240240 const frame = allocator.create(@Frame(writeRunner)) catch @panic("memory");
241241 write_node.data = frame;
242242 frame.* = async writeRunner(lock);
243243 Loop.instance.?.onNextTick(write_node);
244244 }
245245
246 for (write_nodes) |*write_node| {
246 for (&write_nodes) |*write_node| {
247247 const casted = @as(*const @Frame(writeRunner), @ptrCast(write_node.data));
248248 await casted;
249249 allocator.destroy(casted);
250250 }
251 for (read_nodes) |*read_node| {
251 for (&read_nodes) |*read_node| {
252252 const casted = @as(*const @Frame(readRunner), @ptrCast(read_node.data));
253253 await casted;
254254 allocator.destroy(casted);
lib/std/fmt.zig+11-9
......@@ -1296,10 +1296,10 @@ pub fn formatFloatDecimal(
12961296 errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal);
12971297
12981298 // exp < 0 means the leading is always 0 as errol result is normalized.
1299 var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
1299 const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
13001300
13011301 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
1302 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
1302 const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
13031303
13041304 if (num_digits_whole > 0) {
13051305 // We may have to zero pad, for instance 1e4 requires zero padding.
......@@ -1354,10 +1354,10 @@ pub fn formatFloatDecimal(
13541354 }
13551355 } else {
13561356 // exp < 0 means the leading is always 0 as errol result is normalized.
1357 var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
1357 const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
13581358
13591359 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
1360 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
1360 const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
13611361
13621362 if (num_digits_whole > 0) {
13631363 // We may have to zero pad, for instance 1e4 requires zero padding.
......@@ -2218,6 +2218,7 @@ test "slice" {
22182218 }
22192219 {
22202220 var runtime_zero: usize = 0;
2221 _ = &runtime_zero;
22212222 const value = @as([*]align(1) const []const u8, @ptrFromInt(0xdeadbeef))[runtime_zero..runtime_zero];
22222223 try expectFmt("slice: []const u8@deadbeef\n", "slice: {*}\n", .{value});
22232224 }
......@@ -2232,6 +2233,7 @@ test "slice" {
22322233 {
22332234 var int_slice = [_]u32{ 1, 4096, 391891, 1111111111 };
22342235 var runtime_zero: usize = 0;
2236 _ = &runtime_zero;
22352237 try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {any}", .{int_slice[runtime_zero..]});
22362238 try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {d}", .{int_slice[runtime_zero..]});
22372239 try expectFmt("int: { 1, 1000, 5fad3, 423a35c7 }", "int: {x}", .{int_slice[runtime_zero..]});
......@@ -2794,14 +2796,14 @@ test "padding" {
27942796}
27952797
27962798test "decimal float padding" {
2797 var number: f32 = 3.1415;
2799 const number: f32 = 3.1415;
27982800 try expectFmt("left-pad: **3.141\n", "left-pad: {d:*>7.3}\n", .{number});
27992801 try expectFmt("center-pad: *3.141*\n", "center-pad: {d:*^7.3}\n", .{number});
28002802 try expectFmt("right-pad: 3.141**\n", "right-pad: {d:*<7.3}\n", .{number});
28012803}
28022804
28032805test "sci float padding" {
2804 var number: f32 = 3.1415;
2806 const number: f32 = 3.1415;
28052807 try expectFmt("left-pad: **3.141e+00\n", "left-pad: {e:*>11.3}\n", .{number});
28062808 try expectFmt("center-pad: *3.141e+00*\n", "center-pad: {e:*^11.3}\n", .{number});
28072809 try expectFmt("right-pad: 3.141e+00**\n", "right-pad: {e:*<11.3}\n", .{number});
......@@ -2825,7 +2827,7 @@ test "named arguments" {
28252827}
28262828
28272829test "runtime width specifier" {
2828 var width: usize = 9;
2830 const width: usize = 9;
28292831 try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });
28302832 try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });
28312833 try expectFmt(" hello", "{s:[1]}", .{ "hello", width });
......@@ -2833,8 +2835,8 @@ test "runtime width specifier" {
28332835}
28342836
28352837test "runtime precision specifier" {
2836 var number: f32 = 3.1415;
2837 var precision: usize = 2;
2838 const number: f32 = 3.1415;
2839 const precision: usize = 2;
28382840 try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });
28392841 try expectFmt("3.14e+00", "{:1.[precision]}", .{ .number = number, .precision = precision });
28402842}
lib/std/fmt/errol.zig+2-2
......@@ -367,8 +367,8 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
367367 var lo = ((fpprev(val) - n) + mid) / 2.0;
368368 var hi = ((fpnext(val) - n) + mid) / 2.0;
369369
370 var buf_index = u64toa(u, buffer);
371 var exp = @as(i32, @intCast(buf_index));
370 const buf_index = u64toa(u, buffer);
371 const exp: i32 = @intCast(buf_index);
372372 var j = buf_index;
373373 buffer[j] = 0;
374374
lib/std/fmt/parse_float/parse.zig+2-2
......@@ -105,7 +105,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
105105 // parse initial digits before dot
106106 var mantissa: MantissaT = 0;
107107 tryParseDigits(MantissaT, stream, &mantissa, info.base);
108 var int_end = stream.offsetTrue();
108 const int_end = stream.offsetTrue();
109109 var n_digits = @as(isize, @intCast(stream.offsetTrue()));
110110 // the base being 16 implies a 0x prefix, which shouldn't be included in the digit count
111111 if (info.base == 16) n_digits -= 2;
......@@ -188,7 +188,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
188188 // than 19 digits. That means we must have a decimal
189189 // point, and at least 1 fractional digit.
190190 stream.advance(1);
191 var marker = stream.offsetTrue();
191 const marker = stream.offsetTrue();
192192 tryParseNDigits(MantissaT, stream, &mantissa, info.base, info.max_mantissa_digits);
193193 break :blk @as(i64, @intCast(marker)) - @as(i64, @intCast(stream.offsetTrue()));
194194 }
lib/std/fs.zig+2-2
......@@ -1689,7 +1689,7 @@ pub const Dir = struct {
16891689 }
16901690 if (builtin.os.tag == .windows) {
16911691 var dir_path_buffer: [os.windows.PATH_MAX_WIDE]u16 = undefined;
1692 var dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer);
1692 const dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer);
16931693 if (builtin.link_libc) {
16941694 return os.chdirW(dir_path);
16951695 }
......@@ -1810,7 +1810,7 @@ pub const Dir = struct {
18101810 const base_flags = w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA |
18111811 w.SYNCHRONIZE | w.FILE_TRAVERSE;
18121812 const flags: u32 = if (iterable) base_flags | w.FILE_LIST_DIRECTORY else base_flags;
1813 var dir = try self.makeOpenDirAccessMaskW(sub_path_w, flags, .{
1813 const dir = try self.makeOpenDirAccessMaskW(sub_path_w, flags, .{
18141814 .no_follow = args.no_follow,
18151815 .create_disposition = w.FILE_OPEN,
18161816 });
lib/std/fs/get_app_data_dir.zig+4
......@@ -57,6 +57,10 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi
5757 },
5858 .haiku => {
5959 var dir_path_ptr: [*:0]u8 = undefined;
60 if (true) {
61 _ = &dir_path_ptr;
62 @compileError("TODO: init dir_path_ptr");
63 }
6064 // TODO look into directory_which
6165 const be_user_settings = 0xbbe;
6266 const rc = os.system.find_directory(be_user_settings, -1, true, dir_path_ptr, 1);
lib/std/fs/test.zig+1-1
......@@ -80,7 +80,7 @@ const TestContext = struct {
8080 transform_fn: *const PathType.TransformFn,
8181
8282 pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext {
83 var tmp = tmpIterableDir(.{});
83 const tmp = tmpIterableDir(.{});
8484 return .{
8585 .path_type = path_type,
8686 .arena = ArenaAllocator.init(allocator),
lib/std/fs/watch.zig+3-3
......@@ -116,7 +116,7 @@ pub fn Watch(comptime V: type) type {
116116 },
117117 };
118118
119 var buf = try allocator.alloc(Event.Error!Event, event_buf_count);
119 const buf = try allocator.alloc(Event.Error!Event, event_buf_count);
120120 self.channel.init(buf);
121121 self.os_data.putter_frame = async self.linuxEventPutter();
122122 return self;
......@@ -132,7 +132,7 @@ pub fn Watch(comptime V: type) type {
132132 },
133133 };
134134
135 var buf = try allocator.alloc(Event.Error!Event, event_buf_count);
135 const buf = try allocator.alloc(Event.Error!Event, event_buf_count);
136136 self.channel.init(buf);
137137 return self;
138138 },
......@@ -147,7 +147,7 @@ pub fn Watch(comptime V: type) type {
147147 },
148148 };
149149
150 var buf = try allocator.alloc(Event.Error!Event, event_buf_count);
150 const buf = try allocator.alloc(Event.Error!Event, event_buf_count);
151151 self.channel.init(buf);
152152 return self;
153153 },
lib/std/hash/auto_hash.zig+1
......@@ -280,6 +280,7 @@ test "hash slice shallow" {
280280 const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 };
281281 // TODO audit deep/shallow - maybe it has the wrong behavior with respect to array pointers and slices
282282 var runtime_zero: usize = 0;
283 _ = &runtime_zero;
283284 const a = array1[runtime_zero..];
284285 const b = array2[runtime_zero..];
285286 const c = array1[runtime_zero..3];
lib/std/hash/cityhash.zig+1-1
......@@ -271,7 +271,7 @@ pub const CityHash64 = struct {
271271 var b1: u64 = b;
272272 a1 +%= w;
273273 b1 = rotr64(b1 +% a1 +% z, 21);
274 var c: u64 = a1;
274 const c: u64 = a1;
275275 a1 +%= x;
276276 a1 +%= y;
277277 b1 +%= rotr64(a1, 44);
lib/std/hash/murmur.zig+25-31
......@@ -134,7 +134,7 @@ pub const Murmur2_64 = struct {
134134 const m: u64 = 0xc6a4a7935bd1e995;
135135 const len: u64 = 4;
136136 var h1: u64 = seed ^ (len *% m);
137 var k1: u64 = v;
137 const k1: u64 = v;
138138 h1 ^= k1;
139139 h1 *%= m;
140140 h1 ^= h1 >> 47;
......@@ -282,16 +282,14 @@ pub const Murmur3_32 = struct {
282282const verify = @import("verify.zig");
283283
284284test "murmur2_32" {
285 var v0: u32 = 0x12345678;
286 var v1: u64 = 0x1234567812345678;
287 var v0le: u32 = v0;
288 var v1le: u64 = v1;
289 if (native_endian == .big) {
290 v0le = @byteSwap(v0le);
291 v1le = @byteSwap(v1le);
292 }
293 try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0));
294 try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1));
285 const v0: u32 = 0x12345678;
286 const v1: u64 = 0x1234567812345678;
287 const v0le: u32, const v1le: u64 = switch (native_endian) {
288 .little => .{ v0, v1 },
289 .big => .{ @byteSwap(v0), @byteSwap(v1) },
290 };
291 try testing.expectEqual(Murmur2_32.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0));
292 try testing.expectEqual(Murmur2_32.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1));
295293}
296294
297295test "murmur2_32 smhasher" {
......@@ -306,16 +304,14 @@ test "murmur2_32 smhasher" {
306304}
307305
308306test "murmur2_64" {
309 var v0: u32 = 0x12345678;
310 var v1: u64 = 0x1234567812345678;
311 var v0le: u32 = v0;
312 var v1le: u64 = v1;
313 if (native_endian == .big) {
314 v0le = @byteSwap(v0le);
315 v1le = @byteSwap(v1le);
316 }
317 try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0));
318 try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1));
307 const v0: u32 = 0x12345678;
308 const v1: u64 = 0x1234567812345678;
309 const v0le: u32, const v1le: u64 = switch (native_endian) {
310 .little => .{ v0, v1 },
311 .big => .{ @byteSwap(v0), @byteSwap(v1) },
312 };
313 try testing.expectEqual(Murmur2_64.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0));
314 try testing.expectEqual(Murmur2_64.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1));
319315}
320316
321317test "mumur2_64 smhasher" {
......@@ -330,16 +326,14 @@ test "mumur2_64 smhasher" {
330326}
331327
332328test "murmur3_32" {
333 var v0: u32 = 0x12345678;
334 var v1: u64 = 0x1234567812345678;
335 var v0le: u32 = v0;
336 var v1le: u64 = v1;
337 if (native_endian == .big) {
338 v0le = @byteSwap(v0le);
339 v1le = @byteSwap(v1le);
340 }
341 try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0));
342 try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1));
329 const v0: u32 = 0x12345678;
330 const v1: u64 = 0x1234567812345678;
331 const v0le: u32, const v1le: u64 = switch (native_endian) {
332 .little => .{ v0, v1 },
333 .big => .{ @byteSwap(v0), @byteSwap(v1) },
334 };
335 try testing.expectEqual(Murmur3_32.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0));
336 try testing.expectEqual(Murmur3_32.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1));
343337}
344338
345339test "mumur3_32 smhasher" {
lib/std/hash_map.zig+4-4
......@@ -1484,8 +1484,8 @@ pub fn HashMapUnmanaged(
14841484
14851485 var i: Size = 0;
14861486 var metadata = self.metadata.?;
1487 var keys_ptr = self.keys();
1488 var values_ptr = self.values();
1487 const keys_ptr = self.keys();
1488 const values_ptr = self.values();
14891489 while (i < self.capacity()) : (i += 1) {
14901490 if (metadata[i].isUsed()) {
14911491 other.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], new_ctx);
......@@ -1521,8 +1521,8 @@ pub fn HashMapUnmanaged(
15211521 const old_capacity = self.capacity();
15221522 var i: Size = 0;
15231523 var metadata = self.metadata.?;
1524 var keys_ptr = self.keys();
1525 var values_ptr = self.values();
1524 const keys_ptr = self.keys();
1525 const values_ptr = self.values();
15261526 while (i < old_capacity) : (i += 1) {
15271527 if (metadata[i].isUsed()) {
15281528 map.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], ctx);
lib/std/heap.zig+9-9
......@@ -81,10 +81,10 @@ const CAllocator = struct {
8181 // Thin wrapper around regular malloc, overallocate to account for
8282 // alignment padding and store the original malloc()'ed pointer before
8383 // the aligned address.
84 var unaligned_ptr = @as([*]u8, @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null));
84 const unaligned_ptr = @as([*]u8, @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null));
8585 const unaligned_addr = @intFromPtr(unaligned_ptr);
8686 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment);
87 var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
87 const aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
8888 getHeader(aligned_ptr).* = unaligned_ptr;
8989
9090 return aligned_ptr;
......@@ -661,12 +661,12 @@ test "FixedBufferAllocator.reset" {
661661 const X = 0xeeeeeeeeeeeeeeee;
662662 const Y = 0xffffffffffffffff;
663663
664 var x = try allocator.create(u64);
664 const x = try allocator.create(u64);
665665 x.* = X;
666666 try testing.expectError(error.OutOfMemory, allocator.create(u64));
667667
668668 fba.reset();
669 var y = try allocator.create(u64);
669 const y = try allocator.create(u64);
670670 y.* = Y;
671671
672672 // we expect Y to have overwritten X.
......@@ -691,9 +691,9 @@ test "FixedBufferAllocator Reuse memory on realloc" {
691691 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);
692692 const allocator = fixed_buffer_allocator.allocator();
693693
694 var slice0 = try allocator.alloc(u8, 5);
694 const slice0 = try allocator.alloc(u8, 5);
695695 try testing.expect(slice0.len == 5);
696 var slice1 = try allocator.realloc(slice0, 10);
696 const slice1 = try allocator.realloc(slice0, 10);
697697 try testing.expect(slice1.ptr == slice0.ptr);
698698 try testing.expect(slice1.len == 10);
699699 try testing.expectError(error.OutOfMemory, allocator.realloc(slice1, 11));
......@@ -706,8 +706,8 @@ test "FixedBufferAllocator Reuse memory on realloc" {
706706 var slice0 = try allocator.alloc(u8, 2);
707707 slice0[0] = 1;
708708 slice0[1] = 2;
709 var slice1 = try allocator.alloc(u8, 2);
710 var slice2 = try allocator.realloc(slice0, 4);
709 const slice1 = try allocator.alloc(u8, 2);
710 const slice2 = try allocator.realloc(slice0, 4);
711711 try testing.expect(slice0.ptr != slice2.ptr);
712712 try testing.expect(slice1.ptr != slice2.ptr);
713713 try testing.expect(slice2[0] == 1);
......@@ -757,7 +757,7 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void {
757757 allocator.free(slice);
758758
759759 // Zero-length allocation
760 var empty = try allocator.alloc(u8, 0);
760 const empty = try allocator.alloc(u8, 0);
761761 allocator.free(empty);
762762 // Allocation with zero-sized types
763763 const zero_bit_ptr = try allocator.create(u0);
lib/std/heap/arena_allocator.zig+1-1
......@@ -257,7 +257,7 @@ test "ArenaAllocator (reset with preheating)" {
257257 rounds -= 1;
258258 _ = arena_allocator.reset(.retain_capacity);
259259 var alloced_bytes: usize = 0;
260 var total_size: usize = random.intRangeAtMost(usize, 256, 16384);
260 const total_size: usize = random.intRangeAtMost(usize, 256, 16384);
261261 while (alloced_bytes < total_size) {
262262 const size = random.intRangeAtMost(usize, 16, 256);
263263 const alignment = 32;
lib/std/heap/general_purpose_allocator.zig+3-3
......@@ -512,7 +512,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
512512 var buckets = &self.buckets[bucket_index];
513513 const slot_count = @divExact(page_size, size_class);
514514 if (self.cur_buckets[bucket_index] == null or self.cur_buckets[bucket_index].?.alloc_cursor == slot_count) {
515 var new_bucket = try self.createBucket(size_class);
515 const new_bucket = try self.createBucket(size_class);
516516 errdefer self.freeBucket(new_bucket, size_class);
517517 const node = try self.bucket_node_pool.create();
518518 node.key = new_bucket;
......@@ -526,7 +526,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
526526 const slot_index = bucket.alloc_cursor;
527527 bucket.alloc_cursor += 1;
528528
529 var used_bits_byte = bucket.usedBits(slot_index / 8);
529 const used_bits_byte = bucket.usedBits(slot_index / 8);
530530 const used_bit_index: u3 = @as(u3, @intCast(slot_index % 8)); // TODO cast should be unnecessary
531531 used_bits_byte.* |= (@as(u8, 1) << used_bit_index);
532532 bucket.used_count += 1;
......@@ -915,7 +915,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
915915 if (bucket.used_count == 0) {
916916 var entry = self.buckets[bucket_index].getEntryFor(bucket);
917917 // save the node for destruction/insertion into in empty_buckets
918 var node = entry.node.?;
918 const node = entry.node.?;
919919 entry.set(null);
920920 if (self.cur_buckets[bucket_index] == bucket) {
921921 self.cur_buckets[bucket_index] = null;
lib/std/heap/memory_pool.zig+1-1
......@@ -172,7 +172,7 @@ test "memory pool: preheating (success)" {
172172}
173173
174174test "memory pool: preheating (failure)" {
175 var failer = std.testing.failing_allocator;
175 const failer = std.testing.failing_allocator;
176176 try std.testing.expectError(error.OutOfMemory, MemoryPool(u32).initPreheated(failer, 5));
177177}
178178
lib/std/http/Client.zig+1-1
......@@ -144,7 +144,7 @@ pub const ConnectionPool = struct {
144144 pool.mutex.lock();
145145 defer pool.mutex.unlock();
146146
147 var next = pool.free.first;
147 const next = pool.free.first;
148148 _ = next;
149149 while (pool.free_len > new_size) {
150150 const popped = pool.free.popFirst() orelse unreachable;
lib/std/http/protocol.zig+6-9
......@@ -765,10 +765,9 @@ test "HeadersParser.read length" {
765765 var r = HeadersParser.initDynamic(256);
766766 defer r.header_bytes.deinit(std.testing.allocator);
767767 const data = "GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 5\r\n\r\nHello";
768 var fbs = std.io.fixedBufferStream(data);
769768
770 var conn = MockBufferedConnection{
771 .conn = fbs,
769 var conn: MockBufferedConnection = .{
770 .conn = std.io.fixedBufferStream(data),
772771 };
773772
774773 while (true) { // read headers
......@@ -796,10 +795,9 @@ test "HeadersParser.read chunked" {
796795 var r = HeadersParser.initDynamic(256);
797796 defer r.header_bytes.deinit(std.testing.allocator);
798797 const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\n\r\n";
799 var fbs = std.io.fixedBufferStream(data);
800798
801 var conn = MockBufferedConnection{
802 .conn = fbs,
799 var conn: MockBufferedConnection = .{
800 .conn = std.io.fixedBufferStream(data),
803801 };
804802
805803 while (true) { // read headers
......@@ -826,10 +824,9 @@ test "HeadersParser.read chunked trailer" {
826824 var r = HeadersParser.initDynamic(256);
827825 defer r.header_bytes.deinit(std.testing.allocator);
828826 const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\nContent-Type: text/plain\r\n\r\n";
829 var fbs = std.io.fixedBufferStream(data);
830827
831 var conn = MockBufferedConnection{
832 .conn = fbs,
828 var conn: MockBufferedConnection = .{
829 .conn = std.io.fixedBufferStream(data),
833830 };
834831
835832 while (true) { // read headers
lib/std/io/Reader/test.zig+8-8
......@@ -91,13 +91,13 @@ test "Reader.readUntilDelimiterAlloc returns ArrayLists with bytes read until th
9191 const reader = fis.reader();
9292
9393 {
94 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
94 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
9595 defer a.free(result);
9696 try std.testing.expectEqualStrings("0000", result);
9797 }
9898
9999 {
100 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
100 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
101101 defer a.free(result);
102102 try std.testing.expectEqualStrings("1234", result);
103103 }
......@@ -112,7 +112,7 @@ test "Reader.readUntilDelimiterAlloc returns an empty ArrayList" {
112112 const reader = fis.reader();
113113
114114 {
115 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
115 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
116116 defer a.free(result);
117117 try std.testing.expectEqualStrings("", result);
118118 }
......@@ -126,7 +126,7 @@ test "Reader.readUntilDelimiterAlloc returns StreamTooLong, then an ArrayList wi
126126
127127 try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterAlloc(a, '\n', 5));
128128
129 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
129 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
130130 defer a.free(result);
131131 try std.testing.expectEqualStrings("67", result);
132132}
......@@ -219,13 +219,13 @@ test "Reader.readUntilDelimiterOrEofAlloc returns ArrayLists with bytes read unt
219219 const reader = fis.reader();
220220
221221 {
222 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
222 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
223223 defer a.free(result);
224224 try std.testing.expectEqualStrings("0000", result);
225225 }
226226
227227 {
228 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
228 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
229229 defer a.free(result);
230230 try std.testing.expectEqualStrings("1234", result);
231231 }
......@@ -240,7 +240,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns an empty ArrayList" {
240240 const reader = fis.reader();
241241
242242 {
243 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
243 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
244244 defer a.free(result);
245245 try std.testing.expectEqualStrings("", result);
246246 }
......@@ -254,7 +254,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns StreamTooLong, then an ArrayLi
254254
255255 try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterOrEofAlloc(a, '\n', 5));
256256
257 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
257 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
258258 defer a.free(result);
259259 try std.testing.expectEqualStrings("67", result);
260260}
lib/std/io/buffered_reader.zig+15-10
......@@ -131,8 +131,9 @@ test "io.BufferedReader Block" {
131131
132132 // len out == block
133133 {
134 var block_reader = BlockReader.init(block, 2);
135 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };
134 var test_buf_reader: BufferedReader(4, BlockReader) = .{
135 .unbuffered_reader = BlockReader.init(block, 2),
136 };
136137 var out_buf: [4]u8 = undefined;
137138 _ = try test_buf_reader.read(&out_buf);
138139 try testing.expectEqualSlices(u8, &out_buf, block);
......@@ -143,8 +144,9 @@ test "io.BufferedReader Block" {
143144
144145 // len out < block
145146 {
146 var block_reader = BlockReader.init(block, 2);
147 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };
147 var test_buf_reader: BufferedReader(4, BlockReader) = .{
148 .unbuffered_reader = BlockReader.init(block, 2),
149 };
148150 var out_buf: [3]u8 = undefined;
149151 _ = try test_buf_reader.read(&out_buf);
150152 try testing.expectEqualSlices(u8, &out_buf, "012");
......@@ -157,8 +159,9 @@ test "io.BufferedReader Block" {
157159
158160 // len out > block
159161 {
160 var block_reader = BlockReader.init(block, 2);
161 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };
162 var test_buf_reader: BufferedReader(4, BlockReader) = .{
163 .unbuffered_reader = BlockReader.init(block, 2),
164 };
162165 var out_buf: [5]u8 = undefined;
163166 _ = try test_buf_reader.read(&out_buf);
164167 try testing.expectEqualSlices(u8, &out_buf, "01230");
......@@ -169,8 +172,9 @@ test "io.BufferedReader Block" {
169172
170173 // len out == 0
171174 {
172 var block_reader = BlockReader.init(block, 2);
173 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };
175 var test_buf_reader: BufferedReader(4, BlockReader) = .{
176 .unbuffered_reader = BlockReader.init(block, 2),
177 };
174178 var out_buf: [0]u8 = undefined;
175179 _ = try test_buf_reader.read(&out_buf);
176180 try testing.expectEqualSlices(u8, &out_buf, "");
......@@ -178,8 +182,9 @@ test "io.BufferedReader Block" {
178182
179183 // len bufreader buf > block
180184 {
181 var block_reader = BlockReader.init(block, 2);
182 var test_buf_reader = BufferedReader(5, BlockReader){ .unbuffered_reader = block_reader };
185 var test_buf_reader: BufferedReader(5, BlockReader) = .{
186 .unbuffered_reader = BlockReader.init(block, 2),
187 };
183188 var out_buf: [4]u8 = undefined;
184189 _ = try test_buf_reader.read(&out_buf);
185190 try testing.expectEqualSlices(u8, &out_buf, block);
lib/std/io/test.zig+2-2
......@@ -167,13 +167,13 @@ test "updateTimes" {
167167 file.close();
168168 tmp.dir.deleteFile(tmp_file_name) catch {};
169169 }
170 var stat_old = try file.stat();
170 const stat_old = try file.stat();
171171 // Set atime and mtime to 5s before
172172 try file.updateTimes(
173173 stat_old.atime - 5 * std.time.ns_per_s,
174174 stat_old.mtime - 5 * std.time.ns_per_s,
175175 );
176 var stat_new = try file.stat();
176 const stat_new = try file.stat();
177177 try expect(stat_new.atime < stat_old.atime);
178178 try expect(stat_new.mtime < stat_old.mtime);
179179}
lib/std/json/dynamic_test.zig+9-9
......@@ -190,15 +190,15 @@ test "Value.jsonStringify" {
190190 var obj = ObjectMap.init(testing.allocator);
191191 defer obj.deinit();
192192 try obj.putNoClobber("a", .{ .string = "b" });
193 var array = [_]Value{
194 Value.null,
195 Value{ .bool = true },
196 Value{ .integer = 42 },
197 Value{ .number_string = "43" },
198 Value{ .float = 42 },
199 Value{ .string = "weeee" },
200 Value{ .array = Array.fromOwnedSlice(undefined, &vals) },
201 Value{ .object = obj },
193 const array = [_]Value{
194 .null,
195 .{ .bool = true },
196 .{ .integer = 42 },
197 .{ .number_string = "43" },
198 .{ .float = 42 },
199 .{ .string = "weeee" },
200 .{ .array = Array.fromOwnedSlice(undefined, &vals) },
201 .{ .object = obj },
202202 };
203203 var buffer: [0x1000]u8 = undefined;
204204 var fbs = std.io.fixedBufferStream(&buffer);
lib/std/json/static_test.zig+9-9
......@@ -533,7 +533,7 @@ test "parse into struct with misc fields" {
533533 string: []const u8,
534534 };
535535 };
536 var document_str =
536 const document_str =
537537 \\{
538538 \\ "int": 420,
539539 \\ "float": 3.14,
......@@ -588,7 +588,7 @@ test "parse into struct with strings and arrays with sentinels" {
588588 data: [:99]const i32,
589589 simple_data: []const i32,
590590 };
591 var document_str =
591 const document_str =
592592 \\{
593593 \\ "language": "zig",
594594 \\ "language_without_sentinel": "zig again!",
......@@ -634,7 +634,7 @@ test "parse into struct ignoring unknown fields" {
634634 language: []const u8,
635635 };
636636
637 var str =
637 const str =
638638 \\{
639639 \\ "int": 420,
640640 \\ "float": 3.14,
......@@ -685,7 +685,7 @@ test "parse into tuple" {
685685 std.meta.Tuple(&.{ u8, []const u8, u8 }),
686686 Union,
687687 });
688 var str =
688 const str =
689689 \\[
690690 \\ 420,
691691 \\ 3.14,
......@@ -789,7 +789,7 @@ test "parse into vector" {
789789 vec_i32: @Vector(4, i32),
790790 vec_f32: @Vector(2, f32),
791791 };
792 var s =
792 const s =
793793 \\{
794794 \\ "vec_f32": [1.5, 2.5],
795795 \\ "vec_i32": [4, 5, 6, 7]
......@@ -821,7 +821,7 @@ test "json parse partial" {
821821 num: u32,
822822 yes: bool,
823823 };
824 var str =
824 const str =
825825 \\{
826826 \\ "outer": {
827827 \\ "key1": {
......@@ -835,7 +835,7 @@ test "json parse partial" {
835835 \\ }
836836 \\}
837837 ;
838 var allocator = testing.allocator;
838 const allocator = testing.allocator;
839839 var scanner = JsonScanner.initCompleteInput(allocator, str);
840840 defer scanner.deinit();
841841
......@@ -876,13 +876,13 @@ test "json parse allocate when streaming" {
876876 not_const: []u8,
877877 is_const: []const u8,
878878 };
879 var str =
879 const str =
880880 \\{
881881 \\ "not_const": "non const string",
882882 \\ "is_const": "const string"
883883 \\}
884884 ;
885 var allocator = testing.allocator;
885 const allocator = testing.allocator;
886886 var arena = ArenaAllocator.init(allocator);
887887 defer arena.deinit();
888888
lib/std/math.zig+2-1
......@@ -427,6 +427,7 @@ test "clamp" {
427427
428428 // Mix of comptime and non-comptime
429429 var i: i32 = 1;
430 _ = &i;
430431 try testing.expect(std.math.clamp(i, 0, 1) == 1);
431432}
432433
......@@ -1113,7 +1114,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
11131114 comptime assert(info.signedness == .unsigned);
11141115 const PromotedType = std.meta.Int(info.signedness, info.bits + 1);
11151116 const overflowBit = @as(PromotedType, 1) << info.bits;
1116 var x = ceilPowerOfTwoPromote(T, value);
1117 const x = ceilPowerOfTwoPromote(T, value);
11171118 if (overflowBit & x != 0) {
11181119 return error.Overflow;
11191120 }
lib/std/math/atan.zig+2-2
......@@ -143,8 +143,8 @@ fn atan64(x_: f64) f64 {
143143 };
144144
145145 var x = x_;
146 var ux = @as(u64, @bitCast(x));
147 var ix = @as(u32, @intCast(ux >> 32));
146 const ux: u64 = @bitCast(x);
147 var ix: u32 = @intCast(ux >> 32);
148148 const sign = ix >> 31;
149149 ix &= 0x7FFFFFFF;
150150
lib/std/math/atan2.zig+8-8
......@@ -104,7 +104,7 @@ fn atan2_32(y: f32, x: f32) f32 {
104104 }
105105
106106 // z = atan(|y / x|) with correct underflow
107 var z = z: {
107 const z = z: {
108108 if ((m & 2) != 0 and iy + (26 << 23) < ix) {
109109 break :z 0.0;
110110 } else {
......@@ -129,13 +129,13 @@ fn atan2_64(y: f64, x: f64) f64 {
129129 return x + y;
130130 }
131131
132 var ux = @as(u64, @bitCast(x));
133 var ix = @as(u32, @intCast(ux >> 32));
134 var lx = @as(u32, @intCast(ux & 0xFFFFFFFF));
132 const ux: u64 = @bitCast(x);
133 var ix: u32 = @intCast(ux >> 32);
134 const lx: u32 = @intCast(ux & 0xFFFFFFFF);
135135
136 var uy = @as(u64, @bitCast(y));
137 var iy = @as(u32, @intCast(uy >> 32));
138 var ly = @as(u32, @intCast(uy & 0xFFFFFFFF));
136 const uy: u64 = @bitCast(y);
137 var iy: u32 = @intCast(uy >> 32);
138 const ly: u32 = @intCast(uy & 0xFFFFFFFF);
139139
140140 // x = 1.0
141141 if ((ix -% 0x3FF00000) | lx == 0) {
......@@ -194,7 +194,7 @@ fn atan2_64(y: f64, x: f64) f64 {
194194 }
195195
196196 // z = atan(|y / x|) with correct underflow
197 var z = z: {
197 const z = z: {
198198 if ((m & 2) != 0 and iy +% (64 << 20) < ix) {
199199 break :z 0.0;
200200 } else {
lib/std/math/big/int.zig+5-5
......@@ -797,7 +797,7 @@ pub const Mutable = struct {
797797 // 0b0..01..1000 with @log2(@sizeOf(Limb)) consecutive ones
798798 const endian_mask: usize = (@sizeOf(Limb) - 1) << 3;
799799
800 var bytes = std.mem.sliceAsBytes(r.limbs);
800 const bytes = std.mem.sliceAsBytes(r.limbs);
801801 var bits = std.packed_int_array.PackedIntSliceEndian(u1, .little).init(bytes, limbs_required * @bitSizeOf(Limb));
802802
803803 var k: usize = 0;
......@@ -1407,7 +1407,7 @@ pub const Mutable = struct {
14071407 }
14081408
14091409 // Avoid copying u to s by swapping u and s
1410 var tmp_s = s;
1410 const tmp_s = s;
14111411 s = u;
14121412 u = tmp_s;
14131413 }
......@@ -1911,7 +1911,7 @@ pub const Mutable = struct {
19111911 var positive = true;
19121912 if (signedness == .signed) {
19131913 const total_bits = bit_offset + bit_count;
1914 var last_byte = switch (endian) {
1914 const last_byte = switch (endian) {
19151915 .little => ((total_bits + 7) / 8) - 1,
19161916 .big => buffer.len - ((total_bits + 7) / 8),
19171917 };
......@@ -3161,7 +3161,7 @@ pub const Managed = struct {
31613161
31623162 /// r = a ^ b
31633163 pub fn bitXor(r: *Managed, a: *const Managed, b: *const Managed) !void {
3164 var cap = @max(a.len(), b.len()) + @intFromBool(a.isPositive() != b.isPositive());
3164 const cap = @max(a.len(), b.len()) + @intFromBool(a.isPositive() != b.isPositive());
31653165 try r.ensureCapacity(cap);
31663166
31673167 var m = r.toMutable();
......@@ -4178,7 +4178,7 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
41784178 // most significant bit set.
41794179 // Square the result if the current bit is zero, square and multiply by a if
41804180 // it is one.
4181 var exp_bits = 32 - 1 - b_leading_zeros;
4181 const exp_bits = 32 - 1 - b_leading_zeros;
41824182 var exp = b << @as(u5, @intCast(1 + b_leading_zeros));
41834183
41844184 var i: usize = 0;
lib/std/math/big/int_test.zig+28-9
......@@ -300,20 +300,18 @@ test "big.int twos complement limit set" {
300300 };
301301
302302 inline for (test_types) |T| {
303 // To work around 'control flow attempts to use compile-time variable at runtime'
304 const U = T;
305 const int_info = @typeInfo(U).Int;
303 const int_info = @typeInfo(T).Int;
306304
307305 var a = try Managed.init(testing.allocator);
308306 defer a.deinit();
309307
310308 try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits);
311 var max: U = maxInt(U);
312 try testing.expect(max == try a.to(U));
309 const max: T = maxInt(T);
310 try testing.expect(max == try a.to(T));
313311
314312 try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits);
315 var min: U = minInt(U);
316 try testing.expect(min == try a.to(U));
313 const min: T = minInt(T);
314 try testing.expect(min == try a.to(T));
317315 }
318316}
319317
......@@ -519,6 +517,9 @@ test "big.int add multi-single" {
519517test "big.int add multi-multi" {
520518 var op1: u128 = 0xefefefef7f7f7f7f;
521519 var op2: u128 = 0xfefefefe9f9f9f9f;
520 // These must be runtime-known to prevent this comparison being tautological, as the
521 // compiler uses `std.math.big.int` internally to add these values at comptime.
522 _ = .{ &op1, &op2 };
522523 var a = try Managed.initSet(testing.allocator, op1);
523524 defer a.deinit();
524525 var b = try Managed.initSet(testing.allocator, op2);
......@@ -833,6 +834,7 @@ test "big.int sub multi-single" {
833834test "big.int sub multi-multi" {
834835 var op1: u128 = 0xefefefefefefefefefefefef;
835836 var op2: u128 = 0xabababababababababababab;
837 _ = .{ &op1, &op2 };
836838
837839 var a = try Managed.initSet(testing.allocator, op1);
838840 defer a.deinit();
......@@ -920,6 +922,8 @@ test "big.int mul multi-multi" {
920922
921923 var op1: u256 = 0x998888efefefefefefefef;
922924 var op2: u256 = 0x333000abababababababab;
925 _ = .{ &op1, &op2 };
926
923927 var a = try Managed.initSet(testing.allocator, op1);
924928 defer a.deinit();
925929 var b = try Managed.initSet(testing.allocator, op2);
......@@ -1042,6 +1046,8 @@ test "big.int mulWrap multi-multi unsigned" {
10421046
10431047 var op1: u256 = 0x998888efefefefefefefef;
10441048 var op2: u256 = 0x333000abababababababab;
1049 _ = .{ &op1, &op2 };
1050
10451051 var a = try Managed.initSet(testing.allocator, op1);
10461052 defer a.deinit();
10471053 var b = try Managed.initSet(testing.allocator, op2);
......@@ -1164,6 +1170,7 @@ test "big.int div single-single with rem" {
11641170test "big.int div multi-single no rem" {
11651171 var op1: u128 = 0xffffeeeeddddcccc;
11661172 var op2: u128 = 34;
1173 _ = .{ &op1, &op2 };
11671174
11681175 var a = try Managed.initSet(testing.allocator, op1);
11691176 defer a.deinit();
......@@ -1183,6 +1190,7 @@ test "big.int div multi-single no rem" {
11831190test "big.int div multi-single with rem" {
11841191 var op1: u128 = 0xffffeeeeddddcccf;
11851192 var op2: u128 = 34;
1193 _ = .{ &op1, &op2 };
11861194
11871195 var a = try Managed.initSet(testing.allocator, op1);
11881196 defer a.deinit();
......@@ -1202,6 +1210,7 @@ test "big.int div multi-single with rem" {
12021210test "big.int div multi>2-single" {
12031211 var op1: u128 = 0xfefefefefefefefefefefefefefefefe;
12041212 var op2: u128 = 0xefab8;
1213 _ = .{ &op1, &op2 };
12051214
12061215 var a = try Managed.initSet(testing.allocator, op1);
12071216 defer a.deinit();
......@@ -2106,6 +2115,8 @@ test "big.int sat shift-left signed multi positive" {
21062115 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
21072116
21082117 var x: SignedDoubleLimb = 1;
2118 _ = &x;
2119
21092120 const shift = @bitSizeOf(SignedDoubleLimb) - 1;
21102121
21112122 var a = try Managed.initSet(testing.allocator, x);
......@@ -2119,6 +2130,8 @@ test "big.int sat shift-left signed multi negative" {
21192130 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
21202131
21212132 var x: SignedDoubleLimb = -1;
2133 _ = &x;
2134
21222135 const shift = @bitSizeOf(SignedDoubleLimb) - 1;
21232136
21242137 var a = try Managed.initSet(testing.allocator, x);
......@@ -2130,6 +2143,8 @@ test "big.int sat shift-left signed multi negative" {
21302143
21312144test "big.int bitNotWrap unsigned simple" {
21322145 var x: u10 = 123;
2146 _ = &x;
2147
21332148 var a = try Managed.initSet(testing.allocator, x);
21342149 defer a.deinit();
21352150
......@@ -2149,6 +2164,8 @@ test "big.int bitNotWrap unsigned multi" {
21492164
21502165test "big.int bitNotWrap signed simple" {
21512166 var x: i11 = -456;
2167 _ = &x;
2168
21522169 var a = try Managed.initSet(testing.allocator, -456);
21532170 defer a.deinit();
21542171
......@@ -2306,6 +2323,8 @@ test "big.int bitwise xor simple" {
23062323test "big.int bitwise xor multi-limb" {
23072324 var x: DoubleLimb = maxInt(Limb) + 1;
23082325 var y: DoubleLimb = maxInt(Limb);
2326 _ = .{ &x, &y };
2327
23092328 var a = try Managed.initSet(testing.allocator, x);
23102329 defer a.deinit();
23112330 var b = try Managed.initSet(testing.allocator, y);
......@@ -2548,7 +2567,7 @@ test "big.int gcd one large" {
25482567
25492568test "big.int mutable to managed" {
25502569 const allocator = testing.allocator;
2551 var limbs_buf = try allocator.alloc(Limb, 8);
2570 const limbs_buf = try allocator.alloc(Limb, 8);
25522571 defer allocator.free(limbs_buf);
25532572
25542573 var a = Mutable.init(limbs_buf, 0xdeadbeef);
......@@ -2965,7 +2984,7 @@ test "big int conversion write twos complement zero" {
29652984 // (2) should correctly interpret bytes based on the provided endianness
29662985 // (3) should ignore any bits from bit_count to 8 * abi_size
29672986
2968 var bit_count: usize = 12 * 8 + 1;
2987 const bit_count: usize = 12 * 8 + 1;
29692988 var buffer: []const u8 = undefined;
29702989
29712990 buffer = &([_]u8{0} ** 13);
lib/std/math/cbrt.zig+2-2
......@@ -102,7 +102,7 @@ fn cbrt64(x: f64) f64 {
102102
103103 // cbrt to 23 bits
104104 // cbrt(x) = t * cbrt(x / t^3) ~= t * P(t^3 / x)
105 var r = (t * t) * (t / x);
105 const r = (t * t) * (t / x);
106106 t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4));
107107
108108 // Round t away from 0 to 23 bits
......@@ -113,7 +113,7 @@ fn cbrt64(x: f64) f64 {
113113 // one step newton to 53 bits
114114 const s = t * t;
115115 var q = x / s;
116 var w = t + t;
116 const w = t + t;
117117 q = (q - t) / (w + q);
118118
119119 return t + t * q;
lib/std/math/complex/atan.zig+2-2
......@@ -55,7 +55,7 @@ fn atan32(z: Complex(f32)) Complex(f32) {
5555 }
5656
5757 var t = 0.5 * math.atan2(f32, 2.0 * x, a);
58 var w = redupif32(t);
58 const w = redupif32(t);
5959
6060 t = y - 1.0;
6161 a = x2 + t * t;
......@@ -104,7 +104,7 @@ fn atan64(z: Complex(f64)) Complex(f64) {
104104 }
105105
106106 var t = 0.5 * math.atan2(f64, 2.0 * x, a);
107 var w = redupif64(t);
107 const w = redupif64(t);
108108
109109 t = y - 1.0;
110110 a = x2 + t * t;
lib/std/math/ilogb.zig+2-2
......@@ -38,8 +38,8 @@ fn ilogbX(comptime T: type, x: T) i32 {
3838
3939 const absMask = signBit - 1;
4040
41 var u = @as(Z, @bitCast(x)) & absMask;
42 var e = @as(i32, @intCast(u >> significandBits));
41 const u = @as(Z, @bitCast(x)) & absMask;
42 const e: i32 = @intCast(u >> significandBits);
4343
4444 if (e == 0) {
4545 if (u == 0) {
lib/std/math/log1p.zig+4-4
......@@ -33,8 +33,8 @@ fn log1p_32(x: f32) f32 {
3333 const Lg3: f32 = 0x91e9ee.0p-25;
3434 const Lg4: f32 = 0xf89e26.0p-26;
3535
36 const u = @as(u32, @bitCast(x));
37 var ix = u;
36 const u: u32 = @bitCast(x);
37 const ix = u;
3838 var k: i32 = 1;
3939 var f: f32 = undefined;
4040 var c: f32 = undefined;
......@@ -112,8 +112,8 @@ fn log1p_64(x: f64) f64 {
112112 const Lg6: f64 = 1.531383769920937332e-01;
113113 const Lg7: f64 = 1.479819860511658591e-01;
114114
115 var ix = @as(u64, @bitCast(x));
116 var hx = @as(u32, @intCast(ix >> 32));
115 const ix: u64 = @bitCast(x);
116 const hx: u32 = @intCast(ix >> 32);
117117 var k: i32 = 1;
118118 var c: f64 = undefined;
119119 var f: f64 = undefined;
lib/std/math/sqrt.zig+1-1
......@@ -50,7 +50,7 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
5050 }
5151
5252 while (one != 0) {
53 var c = op >= res + one;
53 const c = op >= res + one;
5454 if (c) op -= res + one;
5555 res >>= 1;
5656 if (c) res += one;
lib/std/mem.zig+13-12
......@@ -403,11 +403,11 @@ test "zeroes" {
403403 b: u32,
404404 };
405405
406 var c = zeroes(C_union);
406 const c = zeroes(C_union);
407407 try testing.expectEqual(@as(u8, 0), c.a);
408408 try testing.expectEqual(@as(u32, 0), c.b);
409409
410 comptime var comptime_union = zeroes(C_union);
410 const comptime_union = comptime zeroes(C_union);
411411 try testing.expectEqual(@as(u8, 0), comptime_union.a);
412412 try testing.expectEqual(@as(u32, 0), comptime_union.b);
413413
......@@ -3399,7 +3399,7 @@ test "reverseIterator" {
33993399 try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*);
34003400 try testing.expectEqual(@as(?*const i32, null), it.nextPtr());
34013401
3402 var mut_slice: []i32 = &array;
3402 const mut_slice: []i32 = &array;
34033403 var mut_it = reverseIterator(mut_slice);
34043404 mut_it.nextPtr().?.* += 1;
34053405 mut_it.nextPtr().?.* += 2;
......@@ -3419,7 +3419,7 @@ test "reverseIterator" {
34193419 try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*);
34203420 try testing.expectEqual(@as(?*const i32, null), it.nextPtr());
34213421
3422 var mut_ptr_to_array: *[2]i32 = &array;
3422 const mut_ptr_to_array: *[2]i32 = &array;
34233423 var mut_it = reverseIterator(mut_ptr_to_array);
34243424 mut_it.nextPtr().?.* += 1;
34253425 mut_it.nextPtr().?.* += 2;
......@@ -3581,7 +3581,7 @@ test "replacementSize" {
35813581
35823582/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.
35833583pub fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, needle: []const T, replacement: []const T) Allocator.Error![]T {
3584 var output = try allocator.alloc(T, replacementSize(T, input, needle, replacement));
3584 const output = try allocator.alloc(T, replacementSize(T, input, needle, replacement));
35853585 _ = replace(T, input, needle, replacement, output);
35863586 return output;
35873587}
......@@ -3693,8 +3693,8 @@ pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) {
36933693test "alignPointer" {
36943694 const S = struct {
36953695 fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void {
3696 var ptr = @as(T, @ptrFromInt(base));
3697 var aligned = alignPointer(ptr, align_to);
3696 const ptr: T = @ptrFromInt(base);
3697 const aligned = alignPointer(ptr, align_to);
36983698 try testing.expectEqual(expected, @intFromPtr(aligned));
36993699 }
37003700 };
......@@ -3848,7 +3848,7 @@ test "bytesAsValue" {
38483848 .big => "\xC0\xDE\xFA\xCE",
38493849 .little => "\xCE\xFA\xDE\xC0",
38503850 }.*;
3851 var codeface = bytesAsValue(u32, &codeface_bytes);
3851 const codeface = bytesAsValue(u32, &codeface_bytes);
38523852 try testing.expect(codeface.* == 0xC0DEFACE);
38533853 codeface.* = 0;
38543854 for (codeface_bytes) |b|
......@@ -3941,6 +3941,7 @@ test "bytesAsSlice" {
39413941 {
39423942 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
39433943 var runtime_zero: usize = 0;
3944 _ = &runtime_zero;
39443945 const slice = bytesAsSlice(u16, bytes[runtime_zero..]);
39453946 try testing.expect(slice.len == 2);
39463947 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
......@@ -3957,6 +3958,7 @@ test "bytesAsSlice keeps pointer alignment" {
39573958 {
39583959 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
39593960 var runtime_zero: usize = 0;
3961 _ = &runtime_zero;
39603962 const numbers = bytesAsSlice(u32, bytes[runtime_zero..]);
39613963 try comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
39623964 }
......@@ -3967,8 +3969,8 @@ test "bytesAsSlice on a packed struct" {
39673969 a: u8,
39683970 };
39693971
3970 var b = [1]u8{9};
3971 var f = bytesAsSlice(F, &b);
3972 const b: [1]u8 = .{9};
3973 const f = bytesAsSlice(F, &b);
39723974 try testing.expect(f[0].a == 9);
39733975}
39743976
......@@ -4120,8 +4122,7 @@ pub const alignForwardGeneric = @compileError("renamed to alignForward");
41204122/// result eventually gets discarded.
41214123// TODO: use @declareSideEffect() when it is available - https://github.com/ziglang/zig/issues/6168
41224124pub fn doNotOptimizeAway(val: anytype) void {
4123 var a: u8 = 0;
4124 if (@typeInfo(@TypeOf(.{a})).Struct.fields[0].is_comptime) return;
4125 if (@inComptime()) return;
41254126
41264127 const max_gp_register_bits = @bitSizeOf(c_long);
41274128 const t = @typeInfo(@TypeOf(val));
lib/std/meta.zig+9-8
......@@ -738,7 +738,7 @@ test "std.meta.TagPayload" {
738738 },
739739 };
740740 const MovedEvent = TagPayload(Event, Event.Moved);
741 var e: Event = undefined;
741 const e: Event = .{ .Moved = undefined };
742742 try testing.expect(MovedEvent == @TypeOf(e.Moved));
743743}
744744
......@@ -839,13 +839,12 @@ test "std.meta.eql" {
839839 try testing.expect(eql(u_1, u_3));
840840 try testing.expect(!eql(u_1, u_2));
841841
842 var a1 = "abcdef".*;
843 var a2 = "abcdef".*;
844 var a3 = "ghijkl".*;
842 const a1 = "abcdef".*;
843 const a2 = "abcdef".*;
844 const a3 = "ghijkl".*;
845845
846846 try testing.expect(eql(a1, a2));
847847 try testing.expect(!eql(a1, a3));
848 try testing.expect(!eql(a1[0..], a2[0..]));
849848
850849 const EU = struct {
851850 fn tst(err: bool) !u8 {
......@@ -859,9 +858,9 @@ test "std.meta.eql" {
859858 try testing.expect(!eql(EU.tst(false), EU.tst(true)));
860859
861860 const V = @Vector(4, u32);
862 var v1: V = @splat(1);
863 var v2: V = @splat(1);
864 var v3: V = @splat(2);
861 const v1: V = @splat(1);
862 const v2: V = @splat(1);
863 const v3: V = @splat(2);
865864
866865 try testing.expect(eql(v1, v2));
867866 try testing.expect(!eql(v1, v3));
......@@ -879,6 +878,8 @@ test "intToEnum with error return" {
879878
880879 var zero: u8 = 0;
881880 var one: u16 = 1;
881 _ = &zero;
882 _ = &one;
882883 try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
883884 try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
884885 try testing.expect(intToEnum(E3, zero) catch unreachable == E3.A);
lib/std/meta/trait.zig+5-2
......@@ -225,6 +225,7 @@ test "isSingleItemPtr" {
225225 try comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
226226 try comptime testing.expect(!isSingleItemPtr(@TypeOf(array)));
227227 var runtime_zero: usize = 0;
228 _ = &runtime_zero;
228229 try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
229230}
230231
......@@ -253,6 +254,7 @@ pub fn isSlice(comptime T: type) bool {
253254test "isSlice" {
254255 const array = [_]u8{0} ** 10;
255256 var runtime_zero: usize = 0;
257 _ = &runtime_zero;
256258 try testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
257259 try testing.expect(!isSlice(@TypeOf(array)));
258260 try testing.expect(!isSlice(@TypeOf(&array[0])));
......@@ -341,8 +343,9 @@ pub fn isConstPtr(comptime T: type) bool {
341343}
342344
343345test "isConstPtr" {
344 var t = @as(u8, 0);
345 const c = @as(u8, 0);
346 var t: u8 = 0;
347 t = t;
348 const c: u8 = 0;
346349 try testing.expect(isConstPtr(*const @TypeOf(t)));
347350 try testing.expect(isConstPtr(@TypeOf(&c)));
348351 try testing.expect(!isConstPtr(*@TypeOf(t)));
lib/std/net.zig+4-4
......@@ -662,7 +662,7 @@ pub fn connectUnixSocket(path: []const u8) !Stream {
662662fn if_nametoindex(name: []const u8) !u32 {
663663 if (builtin.target.os.tag == .linux) {
664664 var ifr: os.ifreq = undefined;
665 var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
665 const sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
666666 defer os.closeSocket(sockfd);
667667
668668 @memcpy(ifr.ifrn.name[0..name.len], name);
......@@ -1375,7 +1375,7 @@ fn linuxLookupNameFromDns(
13751375 rc: ResolvConf,
13761376 port: u16,
13771377) !void {
1378 var ctx = dpc_ctx{
1378 const ctx = dpc_ctx{
13791379 .addrs = addrs,
13801380 .canon = canon,
13811381 .port = port,
......@@ -1591,8 +1591,8 @@ fn resMSendRc(
15911591 }};
15921592 const retry_interval = timeout / attempts;
15931593 var next: u32 = 0;
1594 var t2: u64 = @as(u64, @bitCast(std.time.milliTimestamp()));
1595 var t0 = t2;
1594 var t2: u64 = @bitCast(std.time.milliTimestamp());
1595 const t0 = t2;
15961596 var t1 = t2 - retry_interval;
15971597
15981598 var servfail_retry: usize = undefined;
lib/std/net/test.zig+5-5
......@@ -33,12 +33,12 @@ test "parse and render IPv6 addresses" {
3333 "::ffff:123.5.123.5",
3434 };
3535 for (ips, 0..) |ip, i| {
36 var addr = net.Address.parseIp6(ip, 0) catch unreachable;
36 const addr = net.Address.parseIp6(ip, 0) catch unreachable;
3737 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
3838 try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
3939
4040 if (builtin.os.tag == .linux) {
41 var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
41 const addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
4242 var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;
4343 try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));
4444 }
......@@ -80,7 +80,7 @@ test "parse and render IPv4 addresses" {
8080 "123.255.0.91",
8181 "127.0.0.1",
8282 }) |ip| {
83 var addr = net.Address.parseIp4(ip, 0) catch unreachable;
83 const addr = net.Address.parseIp4(ip, 0) catch unreachable;
8484 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
8585 try std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
8686 }
......@@ -303,10 +303,10 @@ test "listen on a unix socket, send bytes, receive bytes" {
303303 var server = net.StreamServer.init(.{});
304304 defer server.deinit();
305305
306 var socket_path = try generateFileName("socket.unix");
306 const socket_path = try generateFileName("socket.unix");
307307 defer testing.allocator.free(socket_path);
308308
309 var socket_addr = try net.Address.initUnix(socket_path);
309 const socket_addr = try net.Address.initUnix(socket_path);
310310 defer std.fs.cwd().deleteFile(socket_path) catch {};
311311 try server.listen(socket_addr);
312312
lib/std/os.zig+6-6
......@@ -4642,7 +4642,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr
46424642 const path_w = try windows.sliceToPrefixedFileW(dirfd, path);
46434643 return faccessatW(dirfd, path_w.span().ptr, mode, flags);
46444644 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {
4645 var resolved = RelativePathWasi{ .dir_fd = dirfd, .relative_path = path };
4645 const resolved = RelativePathWasi{ .dir_fd = dirfd, .relative_path = path };
46464646
46474647 const file = blk: {
46484648 break :blk fstatat(dirfd, path, flags);
......@@ -4775,7 +4775,7 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
47754775 }
47764776 }
47774777
4778 var fds: [2]fd_t = try pipe();
4778 const fds: [2]fd_t = try pipe();
47794779 errdefer {
47804780 close(fds[0]);
47814781 close(fds[1]);
......@@ -6709,7 +6709,7 @@ pub fn dn_expand(
67096709 // loop invariants: p<end, dest<dend
67106710 if ((p[0] & 0xc0) != 0) {
67116711 if (p + 1 == end) return error.InvalidDnsPacket;
6712 var j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1];
6712 const j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1];
67136713 if (len == std.math.maxInt(usize)) len = @intFromPtr(p) + 2 - @intFromPtr(comp_dn.ptr);
67146714 if (j >= msg.len) return error.InvalidDnsPacket;
67156715 p = msg.ptr + j;
......@@ -7285,7 +7285,7 @@ pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError;
72857285pub const TimerFdSetError = TimerFdGetError || error{Canceled};
72867286
72877287pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t {
7288 var rc = linux.timerfd_create(clokid, flags);
7288 const rc = linux.timerfd_create(clokid, flags);
72897289 return switch (errno(rc)) {
72907290 .SUCCESS => @as(fd_t, @intCast(rc)),
72917291 .INVAL => unreachable,
......@@ -7299,7 +7299,7 @@ pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t {
72997299}
73007300
73017301pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec, old_value: ?*linux.itimerspec) TimerFdSetError!void {
7302 var rc = linux.timerfd_settime(fd, flags, new_value, old_value);
7302 const rc = linux.timerfd_settime(fd, flags, new_value, old_value);
73037303 return switch (errno(rc)) {
73047304 .SUCCESS => {},
73057305 .BADF => error.InvalidHandle,
......@@ -7312,7 +7312,7 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec,
73127312
73137313pub fn timerfd_gettime(fd: i32) TimerFdGetError!linux.itimerspec {
73147314 var curr_value: linux.itimerspec = undefined;
7315 var rc = linux.timerfd_gettime(fd, &curr_value);
7315 const rc = linux.timerfd_gettime(fd, &curr_value);
73167316 return switch (errno(rc)) {
73177317 .SUCCESS => return curr_value,
73187318 .BADF => error.InvalidHandle,
lib/std/os/linux.zig+1
......@@ -1326,6 +1326,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
13261326 next_unsent = i + 1;
13271327 break;
13281328 }
1329 size += iov.iov_len;
13291330 }
13301331 }
13311332 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR)
lib/std/os/linux/io_uring.zig+20-19
......@@ -137,7 +137,7 @@ pub const IO_Uring = struct {
137137 // We must therefore use wrapping addition and subtraction to avoid a runtime crash.
138138 const next = self.sq.sqe_tail +% 1;
139139 if (next -% head > self.sq.sqes.len) return error.SubmissionQueueFull;
140 var sqe = &self.sq.sqes[self.sq.sqe_tail & self.sq.mask];
140 const sqe = &self.sq.sqes[self.sq.sqe_tail & self.sq.mask];
141141 self.sq.sqe_tail = next;
142142 return sqe;
143143 }
......@@ -279,7 +279,7 @@ pub const IO_Uring = struct {
279279 const ready = self.cq_ready();
280280 const count = @min(cqes.len, ready);
281281 var head = self.cq.head.*;
282 var tail = head +% count;
282 const tail = head +% count;
283283 // TODO Optimize this by using 1 or 2 memcpy's (if the tail wraps) rather than a loop.
284284 var i: usize = 0;
285285 // Do not use "less-than" operator since head and tail may wrap:
......@@ -1916,7 +1916,7 @@ test "splice/read" {
19161916 var buffer_read = [_]u8{98} ** 20;
19171917 _ = try file_src.write(&buffer_write);
19181918
1919 var fds = try os.pipe();
1919 const fds = try os.pipe();
19201920 const pipe_offset: u64 = std.math.maxInt(u64);
19211921
19221922 const sqe_splice_to_pipe = try ring.splice(0x11111111, fd_src, 0, fds[1], pipe_offset, buffer_write.len);
......@@ -2045,6 +2045,7 @@ test "openat" {
20452045 // Workaround for LLVM bug: https://github.com/ziglang/zig/issues/12014
20462046 const path_addr = if (builtin.zig_backend == .stage2_llvm) p: {
20472047 var workaround = path;
2048 _ = &workaround;
20482049 break :p @intFromPtr(workaround);
20492050 } else @intFromPtr(path);
20502051
......@@ -2199,7 +2200,7 @@ test "sendmsg/recvmsg" {
21992200 var iovecs_recv = [_]os.iovec{
22002201 os.iovec{ .iov_base = &buffer_recv, .iov_len = buffer_recv.len },
22012202 };
2202 var addr = [_]u8{0} ** 4;
2203 const addr = [_]u8{0} ** 4;
22032204 var address_recv = net.Address.initIp4(addr, 0);
22042205 var msg_recv: os.msghdr = os.msghdr{
22052206 .name = &address_recv.any,
......@@ -2676,7 +2677,7 @@ test "shutdown" {
26762677 var slen: os.socklen_t = address.getOsSockLen();
26772678 try os.getsockname(server, &address.any, &slen);
26782679
2679 var shutdown_sqe = try ring.shutdown(0x445445445, server, os.linux.SHUT.RD);
2680 const shutdown_sqe = try ring.shutdown(0x445445445, server, os.linux.SHUT.RD);
26802681 try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode);
26812682 try testing.expectEqual(@as(i32, server), shutdown_sqe.fd);
26822683
......@@ -2702,7 +2703,7 @@ test "shutdown" {
27022703 const server = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);
27032704 defer os.close(server);
27042705
2705 var shutdown_sqe = ring.shutdown(0x445445445, server, os.linux.SHUT.RD) catch |err| switch (err) {
2706 const shutdown_sqe = ring.shutdown(0x445445445, server, os.linux.SHUT.RD) catch |err| switch (err) {
27062707 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
27072708 };
27082709 try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode);
......@@ -2740,7 +2741,7 @@ test "renameat" {
27402741
27412742 // Submit renameat
27422743
2743 var sqe = try ring.renameat(
2744 const sqe = try ring.renameat(
27442745 0x12121212,
27452746 tmp.dir.fd,
27462747 old_path,
......@@ -2807,7 +2808,7 @@ test "unlinkat" {
28072808
28082809 // Submit unlinkat
28092810
2810 var sqe = try ring.unlinkat(
2811 const sqe = try ring.unlinkat(
28112812 0x12121212,
28122813 tmp.dir.fd,
28132814 path,
......@@ -2854,7 +2855,7 @@ test "mkdirat" {
28542855
28552856 // Submit mkdirat
28562857
2857 var sqe = try ring.mkdirat(
2858 const sqe = try ring.mkdirat(
28582859 0x12121212,
28592860 tmp.dir.fd,
28602861 path,
......@@ -2902,7 +2903,7 @@ test "symlinkat" {
29022903
29032904 // Submit symlinkat
29042905
2905 var sqe = try ring.symlinkat(
2906 const sqe = try ring.symlinkat(
29062907 0x12121212,
29072908 path,
29082909 tmp.dir.fd,
......@@ -2953,7 +2954,7 @@ test "linkat" {
29532954
29542955 // Submit linkat
29552956
2956 var sqe = try ring.linkat(
2957 const sqe = try ring.linkat(
29572958 0x12121212,
29582959 tmp.dir.fd,
29592960 first_path,
......@@ -3032,7 +3033,7 @@ test "provide_buffers: read" {
30323033
30333034 var i: usize = 0;
30343035 while (i < buffers.len) : (i += 1) {
3035 var sqe = try ring.read(0xdededede, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3036 const sqe = try ring.read(0xdededede, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
30363037 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);
30373038 try testing.expectEqual(@as(i32, fd), sqe.fd);
30383039 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3058,7 +3059,7 @@ test "provide_buffers: read" {
30583059 // This read should fail
30593060
30603061 {
3061 var sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3062 const sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
30623063 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);
30633064 try testing.expectEqual(@as(i32, fd), sqe.fd);
30643065 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3097,7 +3098,7 @@ test "provide_buffers: read" {
30973098 // Final read which should work
30983099
30993100 {
3100 var sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3101 const sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
31013102 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);
31023103 try testing.expectEqual(@as(i32, fd), sqe.fd);
31033104 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3158,7 +3159,7 @@ test "remove_buffers" {
31583159 // Remove 3 buffers
31593160
31603161 {
3161 var sqe = try ring.remove_buffers(0xbababababa, 3, group_id);
3162 const sqe = try ring.remove_buffers(0xbababababa, 3, group_id);
31623163 try testing.expectEqual(linux.IORING_OP.REMOVE_BUFFERS, sqe.opcode);
31633164 try testing.expectEqual(@as(i32, 3), sqe.fd);
31643165 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3270,7 +3271,7 @@ test "provide_buffers: accept/connect/send/recv" {
32703271
32713272 var i: usize = 0;
32723273 while (i < buffers.len) : (i += 1) {
3273 var sqe = try ring.recv(0xdededede, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3274 const sqe = try ring.recv(0xdededede, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
32743275 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);
32753276 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);
32763277 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3299,7 +3300,7 @@ test "provide_buffers: accept/connect/send/recv" {
32993300 // This recv should fail
33003301
33013302 {
3302 var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3303 const sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
33033304 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);
33043305 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);
33053306 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3349,7 +3350,7 @@ test "provide_buffers: accept/connect/send/recv" {
33493350 @memset(mem.sliceAsBytes(&buffers), 1);
33503351
33513352 {
3352 var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3353 const sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
33533354 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);
33543355 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);
33553356 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3477,7 +3478,7 @@ test "accept multishot" {
34773478 var nr: usize = 4; // number of clients to connect
34783479 while (nr > 0) : (nr -= 1) {
34793480 // connect client
3480 var client = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);
3481 const client = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);
34813482 errdefer os.closeSocket(client);
34823483 try os.connect(client, &address.any, address.getOsSockLen());
34833484
lib/std/os/plan9.zig+1-1
......@@ -278,7 +278,7 @@ pub fn sbrk(n: usize) usize {
278278 bloc = @intFromPtr(&ExecData.end);
279279 bloc_max = @intFromPtr(&ExecData.end);
280280 }
281 var bl = std.mem.alignForward(usize, bloc, std.mem.page_size);
281 const bl = std.mem.alignForward(usize, bloc, std.mem.page_size);
282282 const n_aligned = std.mem.alignForward(usize, n, std.mem.page_size);
283283 if (bl + n_aligned > bloc_max) {
284284 // we need to allocate
lib/std/os/test.zig+15-15
......@@ -58,7 +58,7 @@ test "chdir smoke test" {
5858 {
5959 // Create a tmp directory
6060 var tmp_dir_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
61 var tmp_dir_path = path: {
61 const tmp_dir_path = path: {
6262 var allocator = std.heap.FixedBufferAllocator.init(&tmp_dir_buf);
6363 break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{ old_cwd, "zig-test-tmp" });
6464 };
......@@ -72,7 +72,7 @@ test "chdir smoke test" {
7272
7373 // On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase
7474 var resolved_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
75 var resolved_cwd = path: {
75 const resolved_cwd = path: {
7676 var allocator = std.heap.FixedBufferAllocator.init(&resolved_cwd_buf);
7777 break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{new_cwd});
7878 };
......@@ -523,7 +523,7 @@ test "pipe" {
523523 if (native_os == .windows or native_os == .wasi)
524524 return error.SkipZigTest;
525525
526 var fds = try os.pipe();
526 const fds = try os.pipe();
527527 try expect((try os.write(fds[1], "hello")) == 5);
528528 var buf: [16]u8 = undefined;
529529 try expect((try os.read(fds[0], buf[0..])) == 5);
......@@ -533,7 +533,7 @@ test "pipe" {
533533}
534534
535535test "argsAlloc" {
536 var args = try std.process.argsAlloc(std.testing.allocator);
536 const args = try std.process.argsAlloc(std.testing.allocator);
537537 std.process.argsFree(std.testing.allocator, args);
538538}
539539
......@@ -1087,7 +1087,7 @@ test "timerfd" {
10871087 return error.SkipZigTest;
10881088
10891089 const linux = os.linux;
1090 var tfd = try os.timerfd_create(linux.CLOCK.MONOTONIC, linux.TFD.CLOEXEC);
1090 const tfd = try os.timerfd_create(linux.CLOCK.MONOTONIC, linux.TFD.CLOEXEC);
10911091 defer os.close(tfd);
10921092
10931093 // Fire event 10_000_000ns = 10ms after the os.timerfd_settime call.
......@@ -1097,8 +1097,8 @@ test "timerfd" {
10971097 var fds: [1]os.pollfd = .{.{ .fd = tfd, .events = os.linux.POLL.IN, .revents = 0 }};
10981098 try expectEqual(@as(usize, 1), try os.poll(&fds, -1)); // -1 => infinite waiting
10991099
1100 var git = try os.timerfd_gettime(tfd);
1101 var expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } };
1100 const git = try os.timerfd_gettime(tfd);
1101 const expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } };
11021102 try expectEqual(expect_disarmed_timer, git);
11031103}
11041104
......@@ -1128,11 +1128,11 @@ test "read with empty buffer" {
11281128 break :blk try fs.realpathAlloc(allocator, relative_path);
11291129 };
11301130
1131 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1131 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
11321132 var file = try fs.cwd().createFile(file_path, .{ .read = true });
11331133 defer file.close();
11341134
1135 var bytes = try allocator.alloc(u8, 0);
1135 const bytes = try allocator.alloc(u8, 0);
11361136
11371137 _ = try os.read(file.handle, bytes);
11381138}
......@@ -1153,11 +1153,11 @@ test "pread with empty buffer" {
11531153 break :blk try fs.realpathAlloc(allocator, relative_path);
11541154 };
11551155
1156 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1156 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
11571157 var file = try fs.cwd().createFile(file_path, .{ .read = true });
11581158 defer file.close();
11591159
1160 var bytes = try allocator.alloc(u8, 0);
1160 const bytes = try allocator.alloc(u8, 0);
11611161
11621162 _ = try os.pread(file.handle, bytes, 0);
11631163}
......@@ -1178,11 +1178,11 @@ test "write with empty buffer" {
11781178 break :blk try fs.realpathAlloc(allocator, relative_path);
11791179 };
11801180
1181 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1181 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
11821182 var file = try fs.cwd().createFile(file_path, .{});
11831183 defer file.close();
11841184
1185 var bytes = try allocator.alloc(u8, 0);
1185 const bytes = try allocator.alloc(u8, 0);
11861186
11871187 _ = try os.write(file.handle, bytes);
11881188}
......@@ -1203,11 +1203,11 @@ test "pwrite with empty buffer" {
12031203 break :blk try fs.realpathAlloc(allocator, relative_path);
12041204 };
12051205
1206 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1206 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
12071207 var file = try fs.cwd().createFile(file_path, .{});
12081208 defer file.close();
12091209
1210 var bytes = try allocator.alloc(u8, 0);
1210 const bytes = try allocator.alloc(u8, 0);
12111211
12121212 _ = try os.pwrite(file.handle, bytes, 0);
12131213}
lib/std/os/uefi.zig+3-4
......@@ -149,11 +149,10 @@ pub const TimeCapabilities = extern struct {
149149pub const FileHandle = *opaque {};
150150
151151test "GUID formatting" {
152 var bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 };
152 const bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 };
153 const guid: Guid = @bitCast(bytes);
153154
154 var guid = @as(Guid, @bitCast(bytes));
155
156 var str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid});
155 const str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid});
157156 defer std.testing.allocator.free(str);
158157
159158 try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));
lib/std/os/uefi/device_path.zig+2-2
......@@ -213,7 +213,7 @@ pub const DevicePath = union(Type) {
213213 // multiple adr entries can optionally follow
214214 pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 {
215215 // self.length is a minimum of 8 with one adr which is size 4.
216 var entries = (self.length - 4) / @sizeOf(u32);
216 const entries = (self.length - 4) / @sizeOf(u32);
217217 return @as([*]align(1) const u32, @ptrCast(&self.adr))[0..entries];
218218 }
219219 };
......@@ -431,7 +431,7 @@ pub const DevicePath = union(Type) {
431431 device_product_id: u16 align(1),
432432
433433 pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 {
434 var serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16);
434 const serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16);
435435 return @as([*]align(1) const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(UsbWwidDevicePath)))[0..serial_len];
436436 }
437437 };
lib/std/os/uefi/pool_allocator.zig+1-1
......@@ -34,7 +34,7 @@ const UefiPoolAllocator = struct {
3434 const unaligned_addr = @intFromPtr(unaligned_ptr);
3535 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), ptr_align);
3636
37 var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
37 const aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
3838 getHeader(aligned_ptr).* = unaligned_ptr;
3939
4040 return aligned_ptr;
lib/std/os/uefi/protocol/device_path.zig+2-3
......@@ -43,7 +43,7 @@ pub const DevicePath = extern struct {
4343
4444 /// Creates a file device path from the existing device path and a file path.
4545 pub fn create_file_device_path(self: *DevicePath, allocator: Allocator, path: [:0]align(1) const u16) !*DevicePath {
46 var path_size = self.size();
46 const path_size = self.size();
4747
4848 // 2 * (path.len + 1) for the path and its null terminator, which are u16s
4949 // DevicePath for the extra node before the end
......@@ -82,8 +82,7 @@ pub const DevicePath = extern struct {
8282 // Got the associated union type for self.type, now
8383 // we need to initialize it and its subtype
8484 if (self.type == enum_value) {
85 var subtype = self.initSubtype(ufield.type);
86
85 const subtype = self.initSubtype(ufield.type);
8786 if (subtype) |sb| {
8887 // e.g. return .{ .Hardware = .{ .Pci = @ptrCast(...) } }
8988 return @unionInit(uefi.DevicePath, ufield.name, sb);
lib/std/os/windows.zig+3-3
......@@ -1166,7 +1166,7 @@ test "QueryObjectName" {
11661166 const handle = tmp.dir.fd;
11671167 var out_buffer: [PATH_MAX_WIDE]u16 = undefined;
11681168
1169 var result_path = try QueryObjectName(handle, &out_buffer);
1169 const result_path = try QueryObjectName(handle, &out_buffer);
11701170 const required_len_in_u16 = result_path.len + @divExact(@intFromPtr(result_path.ptr) - @intFromPtr(&out_buffer), 2) + 1;
11711171 //insufficient size
11721172 try std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));
......@@ -2045,8 +2045,8 @@ pub fn eqlIgnoreCaseUtf8(a: []const u8, b: []const u8) bool {
20452045 };
20462046
20472047 while (true) {
2048 var a_cp = a_utf8_it.nextCodepoint() orelse break;
2049 var b_cp = b_utf8_it.nextCodepoint() orelse return false;
2048 const a_cp = a_utf8_it.nextCodepoint() orelse break;
2049 const b_cp = b_utf8_it.nextCodepoint() orelse return false;
20502050
20512051 if (a_cp <= std.math.maxInt(u16) and b_cp <= std.math.maxInt(u16)) {
20522052 if (a_cp != b_cp and upcaseImpl(@intCast(a_cp)) != upcaseImpl(@intCast(b_cp))) {
lib/std/pdb.zig+1-1
......@@ -897,7 +897,7 @@ const Msf = struct {
897897 return error.UnhandledBigDirectoryStream; // cf. BlockMapAddr comment.
898898
899899 try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr);
900 var dir_blocks = try allocator.alloc(u32, dir_block_count);
900 const dir_blocks = try allocator.alloc(u32, dir_block_count);
901901 for (dir_blocks) |*b| {
902902 b.* = try in.readInt(u32, .little);
903903 }
lib/std/priority_dequeue.zig+5-5
......@@ -82,8 +82,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar
8282 };
8383
8484 fn getStartForSiftUp(self: Self, child: T, index: usize) StartIndexAndLayer {
85 var child_index = index;
86 var parent_index = parentIndex(child_index);
85 const child_index = index;
86 const parent_index = parentIndex(child_index);
8787 const parent = self.items[parent_index];
8888
8989 const min_layer = self.nextIsMinLayer();
......@@ -115,7 +115,7 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar
115115 fn doSiftUp(self: *Self, start_index: usize, target_order: Order) void {
116116 var child_index = start_index;
117117 while (child_index > 2) {
118 var grandparent_index = grandparentIndex(child_index);
118 const grandparent_index = grandparentIndex(child_index);
119119 const child = self.items[child_index];
120120 const grandparent = self.items[grandparent_index];
121121
......@@ -286,8 +286,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar
286286 }
287287
288288 fn bestItemAtIndices(self: Self, index1: usize, index2: usize, target_order: Order) ItemAndIndex {
289 var item1 = self.getItem(index1);
290 var item2 = self.getItem(index2);
289 const item1 = self.getItem(index1);
290 const item2 = self.getItem(index2);
291291 return self.bestItem(item1, item2, target_order);
292292 }
293293
lib/std/priority_queue.zig+1-1
......@@ -470,7 +470,7 @@ test "std.PriorityQueue: remove at index" {
470470 break idx;
471471 idx += 1;
472472 } else unreachable;
473 var sorted_items = [_]u32{ 1, 3, 4, 5, 8, 9 };
473 const sorted_items = [_]u32{ 1, 3, 4, 5, 8, 9 };
474474 try expectEqual(queue.removeIndex(two_idx), 2);
475475
476476 var i: usize = 0;
lib/std/process.zig+12-12
......@@ -298,9 +298,9 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap {
298298 return result;
299299 }
300300
301 var environ = try allocator.alloc([*:0]u8, environ_count);
301 const environ = try allocator.alloc([*:0]u8, environ_count);
302302 defer allocator.free(environ);
303 var environ_buf = try allocator.alloc(u8, environ_buf_size);
303 const environ_buf = try allocator.alloc(u8, environ_buf_size);
304304 defer allocator.free(environ_buf);
305305
306306 const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr);
......@@ -412,7 +412,7 @@ pub fn hasEnvVar(allocator: Allocator, key: []const u8) error{OutOfMemory}!bool
412412}
413413
414414test "os.getEnvVarOwned" {
415 var ga = std.testing.allocator;
415 const ga = std.testing.allocator;
416416 try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
417417}
418418
......@@ -477,10 +477,10 @@ pub const ArgIteratorWasi = struct {
477477 return &[_][:0]u8{};
478478 }
479479
480 var argv = try allocator.alloc([*:0]u8, count);
480 const argv = try allocator.alloc([*:0]u8, count);
481481 defer allocator.free(argv);
482482
483 var argv_buf = try allocator.alloc(u8, buf_size);
483 const argv_buf = try allocator.alloc(u8, buf_size);
484484
485485 switch (w.args_get(argv.ptr, argv_buf.ptr)) {
486486 .SUCCESS => {},
......@@ -551,7 +551,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
551551
552552 /// cmd_line_utf8 MUST remain valid and constant while using this instance
553553 pub fn init(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self {
554 var buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);
554 const buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);
555555 errdefer allocator.free(buffer);
556556
557557 return Self{
......@@ -564,7 +564,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
564564
565565 /// cmd_line_utf8 will be free'd (with the allocator) on deinit()
566566 pub fn initTakeOwnership(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self {
567 var buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);
567 const buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);
568568 errdefer allocator.free(buffer);
569569
570570 return Self{
......@@ -577,8 +577,8 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
577577
578578 /// cmd_line_utf16le MUST be encoded UTF16-LE, and is converted to UTF-8 in an internal buffer
579579 pub fn initUtf16le(allocator: Allocator, cmd_line_utf16le: [*:0]const u16) InitUtf16leError!Self {
580 var utf16le_slice = mem.sliceTo(cmd_line_utf16le, 0);
581 var cmd_line = std.unicode.utf16leToUtf8Alloc(allocator, utf16le_slice) catch |err| switch (err) {
580 const utf16le_slice = mem.sliceTo(cmd_line_utf16le, 0);
581 const cmd_line = std.unicode.utf16leToUtf8Alloc(allocator, utf16le_slice) catch |err| switch (err) {
582582 error.ExpectedSecondSurrogateHalf,
583583 error.DanglingSurrogateHalf,
584584 error.UnexpectedSecondSurrogateHalf,
......@@ -588,7 +588,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
588588 };
589589 errdefer allocator.free(cmd_line);
590590
591 var buffer = try allocator.alloc(u8, cmd_line.len + 1);
591 const buffer = try allocator.alloc(u8, cmd_line.len + 1);
592592 errdefer allocator.free(buffer);
593593
594594 return Self{
......@@ -681,7 +681,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
681681 0 => {
682682 self.emitBackslashes(backslash_count);
683683 self.buffer[self.end] = 0;
684 var token = self.buffer[self.start..self.end :0];
684 const token = self.buffer[self.start..self.end :0];
685685 self.end += 1;
686686 self.start = self.end;
687687 return token;
......@@ -713,7 +713,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
713713 self.emitCharacter(character);
714714 } else {
715715 self.buffer[self.end] = 0;
716 var token = self.buffer[self.start..self.end :0];
716 const token = self.buffer[self.start..self.end :0];
717717 self.end += 1;
718718 self.start = self.end;
719719 return token;
lib/std/rand/test.zig+2-2
......@@ -332,13 +332,13 @@ test "Random float chi-square goodness of fit" {
332332 while (i < num_numbers) : (i += 1) {
333333 const rand_f32 = random.float(f32);
334334 const rand_f64 = random.float(f64);
335 var f32_put = try f32_hist.getOrPut(@as(u32, @intFromFloat(rand_f32 * @as(f32, @floatFromInt(num_buckets)))));
335 const f32_put = try f32_hist.getOrPut(@as(u32, @intFromFloat(rand_f32 * @as(f32, @floatFromInt(num_buckets)))));
336336 if (f32_put.found_existing) {
337337 f32_put.value_ptr.* += 1;
338338 } else {
339339 f32_put.value_ptr.* = 1;
340340 }
341 var f64_put = try f64_hist.getOrPut(@as(u32, @intFromFloat(rand_f64 * @as(f64, @floatFromInt(num_buckets)))));
341 const f64_put = try f64_hist.getOrPut(@as(u32, @intFromFloat(rand_f64 * @as(f64, @floatFromInt(num_buckets)))));
342342 if (f64_put.found_existing) {
343343 f64_put.value_ptr.* += 1;
344344 } else {
lib/std/sort.zig+1-1
......@@ -387,7 +387,7 @@ test "sort fuzz testing" {
387387 var i: usize = 0;
388388 while (i < test_case_count) : (i += 1) {
389389 const array_size = random.intRangeLessThan(usize, 0, 1000);
390 var array = try testing.allocator.alloc(i32, array_size);
390 const array = try testing.allocator.alloc(i32, array_size);
391391 defer testing.allocator.free(array);
392392 // populate with random data
393393 for (array) |*item| {
lib/std/sort/block.zig+2-2
......@@ -302,8 +302,8 @@ pub fn block(
302302 } else {
303303 iterator.begin();
304304 while (!iterator.finished()) {
305 var A = iterator.nextRange();
306 var B = iterator.nextRange();
305 const A = iterator.nextRange();
306 const B = iterator.nextRange();
307307
308308 if (lessThan(context, items[B.end - 1], items[A.start])) {
309309 // the two ranges are in reverse order, so a simple rotation should fix it
lib/std/sort/pdq.zig+4-4
......@@ -276,10 +276,10 @@ fn chosePivot(a: usize, b: usize, pivot: *usize, context: anytype) Hint {
276276 // max_swaps is the maximum number of swaps allowed in this function
277277 const max_swaps = 4 * 3;
278278
279 var len = b - a;
280 var i = a + len / 4 * 1;
281 var j = a + len / 4 * 2;
282 var k = a + len / 4 * 3;
279 const len = b - a;
280 const i = a + len / 4 * 1;
281 const j = a + len / 4 * 2;
282 const k = a + len / 4 * 3;
283283 var swaps: usize = 0;
284284
285285 if (len >= 8) {
lib/std/tar.zig+1-1
......@@ -218,7 +218,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
218218 if (file_size == 0 and unstripped_file_name.len == 0) return;
219219 const file_name = try stripComponents(unstripped_file_name, options.strip_components);
220220
221 var file = dir.createFile(file_name, .{}) catch |err| switch (err) {
221 const file = dir.createFile(file_name, .{}) catch |err| switch (err) {
222222 error.FileNotFound => again: {
223223 const code = code: {
224224 if (std.fs.path.dirname(file_name)) |dir_name| {
lib/std/testing.zig+10-10
......@@ -399,7 +399,7 @@ fn SliceDiffer(comptime T: type) type {
399399
400400 pub fn write(self: Self, writer: anytype) !void {
401401 for (self.expected, 0..) |value, i| {
402 var full_index = self.start_index + i;
402 const full_index = self.start_index + i;
403403 const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true;
404404 if (diff) try self.ttyconf.setColor(writer, .red);
405405 if (@typeInfo(T) == .Pointer) {
......@@ -424,7 +424,7 @@ const BytesDiffer = struct {
424424 // to avoid having to calculate diffs twice per chunk
425425 var diffs: std.bit_set.IntegerBitSet(16) = .{ .mask = 0 };
426426 for (chunk, 0..) |byte, i| {
427 var absolute_byte_index = (expected_iterator.index - chunk.len) + i;
427 const absolute_byte_index = (expected_iterator.index - chunk.len) + i;
428428 const diff = if (absolute_byte_index < self.actual.len) self.actual[absolute_byte_index] != byte else true;
429429 if (diff) diffs.set(i);
430430 try self.writeByteDiff(writer, "{X:0>2} ", byte, diff);
......@@ -565,13 +565,13 @@ pub fn tmpDir(opts: std.fs.Dir.OpenDirOptions) TmpDir {
565565 var sub_path: [TmpDir.sub_path_len]u8 = undefined;
566566 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
567567
568 var cwd = std.fs.cwd();
568 const cwd = std.fs.cwd();
569569 var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch
570570 @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir");
571571 defer cache_dir.close();
572 var parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
572 const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
573573 @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir");
574 var dir = parent_dir.makeOpenPath(&sub_path, opts) catch
574 const dir = parent_dir.makeOpenPath(&sub_path, opts) catch
575575 @panic("unable to make tmp dir for testing: unable to make and open the tmp dir");
576576
577577 return .{
......@@ -587,13 +587,13 @@ pub fn tmpIterableDir(opts: std.fs.Dir.OpenDirOptions) TmpIterableDir {
587587 var sub_path: [TmpIterableDir.sub_path_len]u8 = undefined;
588588 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
589589
590 var cwd = std.fs.cwd();
590 const cwd = std.fs.cwd();
591591 var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch
592592 @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir");
593593 defer cache_dir.close();
594 var parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
594 const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
595595 @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir");
596 var dir = parent_dir.makeOpenPathIterable(&sub_path, opts) catch
596 const dir = parent_dir.makeOpenPathIterable(&sub_path, opts) catch
597597 @panic("unable to make tmp dir for testing: unable to make and open the tmp dir");
598598
599599 return .{
......@@ -618,8 +618,8 @@ test "expectEqual nested array" {
618618}
619619
620620test "expectEqual vector" {
621 var a: @Vector(4, u32) = @splat(4);
622 var b: @Vector(4, u32) = @splat(4);
621 const a: @Vector(4, u32) = @splat(4);
622 const b: @Vector(4, u32) = @splat(4);
623623
624624 try expectEqual(a, b);
625625}
lib/std/treap.zig+1-1
......@@ -379,7 +379,7 @@ test "std.Treap: insert, find, replace, remove" {
379379 const key = node.key;
380380
381381 // find the entry by-key and by-node after having been inserted.
382 var entry = treap.getEntryFor(node.key);
382 const entry = treap.getEntryFor(node.key);
383383 try testing.expectEqual(entry.key, key);
384384 try testing.expectEqual(entry.node, node);
385385 try testing.expectEqual(entry.node, treap.getEntryForExisting(node).node);
lib/std/unicode.zig+1-1
......@@ -242,7 +242,7 @@ pub fn utf8ValidateSlice(input: []const u8) bool {
242242 s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
243243 };
244244
245 var n = remaining.len;
245 const n = remaining.len;
246246 var i: usize = 0;
247247 while (i < n) {
248248 const first_byte = remaining[i];
lib/std/zig/Parse.zig+1-2
......@@ -3516,7 +3516,6 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers {
35163516 var saw_const = false;
35173517 var saw_volatile = false;
35183518 var saw_allowzero = false;
3519 var saw_addrspace = false;
35203519 while (true) {
35213520 switch (p.token_tags[p.tok_i]) {
35223521 .keyword_align => {
......@@ -3557,7 +3556,7 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers {
35573556 saw_allowzero = true;
35583557 },
35593558 .keyword_addrspace => {
3560 if (saw_addrspace) {
3559 if (result.addrspace_node != 0) {
35613560 try p.warn(.extra_addrspace_qualifier);
35623561 }
35633562 result.addrspace_node = try p.parseAddrSpace();
lib/std/zig/c_translation.zig+8-7
......@@ -129,6 +129,7 @@ test "cast" {
129129 try testing.expectEqual(@as(?*anyopaque, @ptrFromInt(2)), cast(?*anyopaque, @as(*u8, @ptrFromInt(2))));
130130
131131 var foo: c_int = -1;
132 _ = &foo;
132133 try testing.expect(cast(*anyopaque, -1) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
133134 try testing.expect(cast(*anyopaque, foo) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
134135 try testing.expect(cast(?*anyopaque, -1) == @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
......@@ -601,22 +602,22 @@ test "WL_CONTAINER_OF" {
601602 a: u32 = 0,
602603 b: u32 = 0,
603604 };
604 var x = S{};
605 var y = S{};
606 var ptr = Macros.WL_CONTAINER_OF(&x.b, &y, "b");
605 const x = S{};
606 const y = S{};
607 const ptr = Macros.WL_CONTAINER_OF(&x.b, &y, "b");
607608 try testing.expectEqual(&x, ptr);
608609}
609610
610611test "CAST_OR_CALL casting" {
611 var arg = @as(c_int, 1000);
612 var casted = Macros.CAST_OR_CALL(u8, arg);
612 const arg: c_int = 1000;
613 const casted = Macros.CAST_OR_CALL(u8, arg);
613614 try testing.expectEqual(cast(u8, arg), casted);
614615
615616 const S = struct {
616617 x: u32 = 0,
617618 };
618 var s = S{};
619 var casted_ptr = Macros.CAST_OR_CALL(*u8, &s);
619 var s: S = .{};
620 const casted_ptr = Macros.CAST_OR_CALL(*u8, &s);
620621 try testing.expectEqual(cast(*u8, &s), casted_ptr);
621622}
622623
lib/std/zig/perf_test.zig+1-1
......@@ -32,7 +32,7 @@ pub fn main() !void {
3232
3333fn testOnce() usize {
3434 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
35 var allocator = fixed_buf_alloc.allocator();
35 const allocator = fixed_buf_alloc.allocator();
3636 _ = std.zig.Ast.parse(allocator, source, .zig) catch @panic("parse failure");
3737 return fixed_buf_alloc.end_index;
3838}
lib/std/zig/render.zig+1-1
......@@ -3495,7 +3495,7 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
34953495 /// Turns all one-shot indents into regular indents
34963496 /// Returns number of indents that must now be manually popped
34973497 pub fn lockOneShotIndent(self: *Self) usize {
3498 var locked_count = self.indent_one_shot_count;
3498 const locked_count = self.indent_one_shot_count;
34993499 self.indent_one_shot_count = 0;
35003500 return locked_count;
35013501 }
lib/std/zig/string_literal.zig+1-1
......@@ -288,7 +288,7 @@ test "parse" {
288288
289289 var fixed_buf_mem: [64]u8 = undefined;
290290 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(&fixed_buf_mem);
291 var alloc = fixed_buf_alloc.allocator();
291 const alloc = fixed_buf_alloc.allocator();
292292
293293 try expectError(error.InvalidLiteral, parseAlloc(alloc, "\"\\x6\""));
294294 try expect(eql(u8, "foo\nbar", try parseAlloc(alloc, "\"foo\\nbar\"")));
lib/std/zig/system/NativeTargetInfo.zig+1-1
......@@ -189,7 +189,7 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {
189189 // native CPU architecture as being different than the current target), we use this:
190190 const cpu_arch = cross_target.getCpuArch();
191191
192 var cpu = switch (cross_target.cpu_model) {
192 const cpu = switch (cross_target.cpu_model) {
193193 .native => detectNativeCpuAndFeatures(cpu_arch, os, cross_target),
194194 .baseline => Target.Cpu.baseline(cpu_arch),
195195 .determined_by_cpu_arch => if (cross_target.cpu_arch == null)
src/Air.zig+1-1
......@@ -1787,7 +1787,7 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
17871787 => false,
17881788
17891789 .assembly => {
1790 var extra = air.extraData(Air.Asm, data.ty_pl.payload);
1790 const extra = air.extraData(Air.Asm, data.ty_pl.payload);
17911791 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
17921792 return is_volatile or if (extra.data.outputs_len == 1)
17931793 @as(Air.Inst.Ref, @enumFromInt(air.extra[extra.end])) != .none
src/AstGen.zig+44-16
......@@ -1226,7 +1226,7 @@ fn awaitExpr(
12261226 try astgen.errNoteNode(gz.suspend_node, "suspend block here", .{}),
12271227 });
12281228 }
1229 const operand = try expr(gz, scope, .{ .rl = .none }, rhs_node);
1229 const operand = try expr(gz, scope, .{ .rl = .ref }, rhs_node);
12301230 const result = if (gz.nosuspend_node != 0)
12311231 try gz.addExtendedPayload(.await_nosuspend, Zir.Inst.UnNode{
12321232 .node = gz.nodeIndexToRelative(node),
......@@ -1248,7 +1248,7 @@ fn resumeExpr(
12481248 const tree = astgen.tree;
12491249 const node_datas = tree.nodes.items(.data);
12501250 const rhs_node = node_datas[node].lhs;
1251 const operand = try expr(gz, scope, .{ .rl = .none }, rhs_node);
1251 const operand = try expr(gz, scope, .{ .rl = .ref }, rhs_node);
12521252 const result = try gz.addUnNode(.@"resume", operand, node);
12531253 return rvalue(gz, ri, result, node);
12541254}
......@@ -1971,6 +1971,17 @@ fn comptimeExpr(
19711971 .block_two, .block_two_semicolon, .block, .block_semicolon => {
19721972 const token_tags = tree.tokens.items(.tag);
19731973 const lbrace = main_tokens[node];
1974 // Careful! We can't pass in the real result location here, since it may
1975 // refer to runtime memory. A runtime-to-comptime boundary has to remove
1976 // result location information, compute the result, and copy it to the true
1977 // result location at runtime. We do this below as well.
1978 const ty_only_ri: ResultInfo = .{
1979 .ctx = ri.ctx,
1980 .rl = if (try ri.rl.resultType(gz, node)) |res_ty|
1981 .{ .coerced_ty = res_ty }
1982 else
1983 .none,
1984 };
19741985 if (token_tags[lbrace - 1] == .colon and
19751986 token_tags[lbrace - 2] == .identifier)
19761987 {
......@@ -1985,17 +1996,13 @@ fn comptimeExpr(
19851996 else
19861997 stmts[0..2];
19871998
1988 // Careful! We can't pass in the real result location here, since it may
1989 // refer to runtime memory. A runtime-to-comptime boundary has to remove
1990 // result location information, compute the result, and copy it to the true
1991 // result location at runtime. We do this below as well.
1992 const block_ref = try labeledBlockExpr(gz, scope, .{ .rl = .none }, node, stmt_slice, true);
1999 const block_ref = try labeledBlockExpr(gz, scope, ty_only_ri, node, stmt_slice, true);
19932000 return rvalue(gz, ri, block_ref, node);
19942001 },
19952002 .block, .block_semicolon => {
19962003 const stmts = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs];
19972004 // Replace result location and copy back later - see above.
1998 const block_ref = try labeledBlockExpr(gz, scope, .{ .rl = .none }, node, stmts, true);
2005 const block_ref = try labeledBlockExpr(gz, scope, ty_only_ri, node, stmts, true);
19992006 return rvalue(gz, ri, block_ref, node);
20002007 },
20012008 else => unreachable,
......@@ -2013,7 +2020,14 @@ fn comptimeExpr(
20132020
20142021 const block_inst = try gz.makeBlockInst(.block_comptime, node);
20152022 // Replace result location and copy back later - see above.
2016 const block_result = try expr(&block_scope, scope, .{ .rl = .none }, node);
2023 const ty_only_ri: ResultInfo = .{
2024 .ctx = ri.ctx,
2025 .rl = if (try ri.rl.resultType(gz, node)) |res_ty|
2026 .{ .coerced_ty = res_ty }
2027 else
2028 .none,
2029 };
2030 const block_result = try expr(&block_scope, scope, ty_only_ri, node);
20172031 if (!gz.refIsNoReturn(block_result)) {
20182032 _ = try block_scope.addBreak(.@"break", block_inst, block_result);
20192033 }
......@@ -2941,11 +2955,19 @@ fn checkUsed(gz: *GenZir, outer_scope: *Scope, inner_scope: *Scope) InnerError!v
29412955 const s = scope.cast(Scope.LocalPtr).?;
29422956 if (s.used == 0 and s.discarded == 0) {
29432957 try astgen.appendErrorTok(s.token_src, "unused {s}", .{@tagName(s.id_cat)});
2944 } else if (s.used != 0 and s.discarded != 0) {
2945 try astgen.appendErrorTokNotes(s.discarded, "pointless discard of {s}", .{@tagName(s.id_cat)}, &[_]u32{
2946 try gz.astgen.errNoteTok(s.used, "used here", .{}),
2947 });
2958 } else {
2959 if (s.used != 0 and s.discarded != 0) {
2960 try astgen.appendErrorTokNotes(s.discarded, "pointless discard of {s}", .{@tagName(s.id_cat)}, &[_]u32{
2961 try astgen.errNoteTok(s.used, "used here", .{}),
2962 });
2963 }
2964 if (s.id_cat == .@"local variable" and !s.used_as_lvalue) {
2965 try astgen.appendErrorTokNotes(s.token_src, "local variable is never mutated", .{}, &.{
2966 try astgen.errNoteTok(s.token_src, "consider using 'const'", .{}),
2967 });
2968 }
29482969 }
2970
29492971 scope = s.parent;
29502972 },
29512973 .defer_normal, .defer_error => scope = scope.cast(Scope.Defer).?.parent,
......@@ -6699,7 +6721,7 @@ fn forExpr(
66996721 };
67006722 }
67016723
6702 var then_node = for_full.ast.then_expr;
6724 const then_node = for_full.ast.then_expr;
67036725 var then_scope = parent_gz.makeSubBlock(&cond_scope.base);
67046726 defer then_scope.unstack();
67056727
......@@ -7579,7 +7601,10 @@ fn localVarRef(
75797601 );
75807602
75817603 switch (ri.rl) {
7582 .ref, .ref_coerced_ty => return ptr_inst,
7604 .ref, .ref_coerced_ty => {
7605 local_ptr.used_as_lvalue = true;
7606 return ptr_inst;
7607 },
75837608 else => {
75847609 const loaded = try gz.addUnNode(.load, ptr_inst, ident);
75857610 return rvalueNoCoercePreRef(gz, ri, loaded, ident);
......@@ -8149,7 +8174,7 @@ fn typeOf(
81498174 }
81508175 const payload_size: u32 = std.meta.fields(Zir.Inst.TypeOfPeer).len;
81518176 const payload_index = try reserveExtra(astgen, payload_size + args.len);
8152 var args_index = payload_index + payload_size;
8177 const args_index = payload_index + payload_size;
81538178
81548179 const typeof_inst = try gz.addExtendedMultiOpPayloadIndex(.typeof_peer, payload_index, args.len);
81558180
......@@ -10948,6 +10973,9 @@ const Scope = struct {
1094810973 /// Track the identifier where it is discarded, like this `_ = foo;`.
1094910974 /// 0 means never discarded.
1095010975 discarded: Ast.TokenIndex = 0,
10976 /// Whether this value is used as an lvalue after inititialization.
10977 /// If not, we know it can be `const`, so will emit a compile error if it is `var`.
10978 used_as_lvalue: bool = false,
1095110979 /// String table index.
1095210980 name: u32,
1095310981 id_cat: IdCat,
src/Autodoc.zig+50-50
......@@ -985,7 +985,7 @@ fn walkInstruction(
985985 },
986986 .import => {
987987 const str_tok = data[@intFromEnum(inst)].str_tok;
988 var path = str_tok.get(file.zir);
988 const path = str_tok.get(file.zir);
989989
990990 // importFile cannot error out since all files
991991 // are already loaded at this point
......@@ -1210,7 +1210,7 @@ fn walkInstruction(
12101210 .compile_error => {
12111211 const un_node = data[@intFromEnum(inst)].un_node;
12121212
1213 var operand: DocData.WalkResult = try self.walkRef(
1213 const operand: DocData.WalkResult = try self.walkRef(
12141214 file,
12151215 parent_scope,
12161216 parent_src,
......@@ -1252,7 +1252,7 @@ fn walkInstruction(
12521252 const byte_count = str.len * @sizeOf(std.math.big.Limb);
12531253 const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count];
12541254
1255 var limbs = try self.arena.alloc(std.math.big.Limb, str.len);
1255 const limbs = try self.arena.alloc(std.math.big.Limb, str.len);
12561256 @memcpy(std.mem.sliceAsBytes(limbs)[0..limb_bytes.len], limb_bytes);
12571257
12581258 const big_int = std.math.big.int.Const{
......@@ -1281,7 +1281,7 @@ fn walkInstruction(
12811281 const slice_index = self.exprs.items.len;
12821282 try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } });
12831283
1284 var lhs: DocData.WalkResult = try self.walkRef(
1284 const lhs: DocData.WalkResult = try self.walkRef(
12851285 file,
12861286 parent_scope,
12871287 parent_src,
......@@ -1289,7 +1289,7 @@ fn walkInstruction(
12891289 false,
12901290 call_ctx,
12911291 );
1292 var start: DocData.WalkResult = try self.walkRef(
1292 const start: DocData.WalkResult = try self.walkRef(
12931293 file,
12941294 parent_scope,
12951295 parent_src,
......@@ -1321,7 +1321,7 @@ fn walkInstruction(
13211321 const slice_index = self.exprs.items.len;
13221322 try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } });
13231323
1324 var lhs: DocData.WalkResult = try self.walkRef(
1324 const lhs: DocData.WalkResult = try self.walkRef(
13251325 file,
13261326 parent_scope,
13271327 parent_src,
......@@ -1329,7 +1329,7 @@ fn walkInstruction(
13291329 false,
13301330 call_ctx,
13311331 );
1332 var start: DocData.WalkResult = try self.walkRef(
1332 const start: DocData.WalkResult = try self.walkRef(
13331333 file,
13341334 parent_scope,
13351335 parent_src,
......@@ -1337,7 +1337,7 @@ fn walkInstruction(
13371337 false,
13381338 call_ctx,
13391339 );
1340 var end: DocData.WalkResult = try self.walkRef(
1340 const end: DocData.WalkResult = try self.walkRef(
13411341 file,
13421342 parent_scope,
13431343 parent_src,
......@@ -1371,7 +1371,7 @@ fn walkInstruction(
13711371 const slice_index = self.exprs.items.len;
13721372 try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } });
13731373
1374 var lhs: DocData.WalkResult = try self.walkRef(
1374 const lhs: DocData.WalkResult = try self.walkRef(
13751375 file,
13761376 parent_scope,
13771377 parent_src,
......@@ -1379,7 +1379,7 @@ fn walkInstruction(
13791379 false,
13801380 call_ctx,
13811381 );
1382 var start: DocData.WalkResult = try self.walkRef(
1382 const start: DocData.WalkResult = try self.walkRef(
13831383 file,
13841384 parent_scope,
13851385 parent_src,
......@@ -1387,7 +1387,7 @@ fn walkInstruction(
13871387 false,
13881388 call_ctx,
13891389 );
1390 var end: DocData.WalkResult = try self.walkRef(
1390 const end: DocData.WalkResult = try self.walkRef(
13911391 file,
13921392 parent_scope,
13931393 parent_src,
......@@ -1395,7 +1395,7 @@ fn walkInstruction(
13951395 false,
13961396 call_ctx,
13971397 );
1398 var sentinel: DocData.WalkResult = try self.walkRef(
1398 const sentinel: DocData.WalkResult = try self.walkRef(
13991399 file,
14001400 parent_scope,
14011401 parent_src,
......@@ -1436,7 +1436,7 @@ fn walkInstruction(
14361436 const slice_index = self.exprs.items.len;
14371437 try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } });
14381438
1439 var lhs: DocData.WalkResult = try self.walkRef(
1439 const lhs: DocData.WalkResult = try self.walkRef(
14401440 file,
14411441 parent_scope,
14421442 parent_src,
......@@ -1444,7 +1444,7 @@ fn walkInstruction(
14441444 false,
14451445 call_ctx,
14461446 );
1447 var start: DocData.WalkResult = try self.walkRef(
1447 const start: DocData.WalkResult = try self.walkRef(
14481448 file,
14491449 parent_scope,
14501450 parent_src,
......@@ -1452,7 +1452,7 @@ fn walkInstruction(
14521452 false,
14531453 call_ctx,
14541454 );
1455 var len: DocData.WalkResult = try self.walkRef(
1455 const len: DocData.WalkResult = try self.walkRef(
14561456 file,
14571457 parent_scope,
14581458 parent_src,
......@@ -1460,7 +1460,7 @@ fn walkInstruction(
14601460 false,
14611461 call_ctx,
14621462 );
1463 var sentinel_opt: ?DocData.WalkResult = if (extra.data.sentinel != .none)
1463 const sentinel_opt: ?DocData.WalkResult = if (extra.data.sentinel != .none)
14641464 try self.walkRef(
14651465 file,
14661466 parent_scope,
......@@ -1574,7 +1574,7 @@ fn walkInstruction(
15741574 const binop_index = self.exprs.items.len;
15751575 try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } });
15761576
1577 var lhs: DocData.WalkResult = try self.walkRef(
1577 const lhs: DocData.WalkResult = try self.walkRef(
15781578 file,
15791579 parent_scope,
15801580 parent_src,
......@@ -1582,7 +1582,7 @@ fn walkInstruction(
15821582 false,
15831583 call_ctx,
15841584 );
1585 var rhs: DocData.WalkResult = try self.walkRef(
1585 const rhs: DocData.WalkResult = try self.walkRef(
15861586 file,
15871587 parent_scope,
15881588 parent_src,
......@@ -1620,7 +1620,7 @@ fn walkInstruction(
16201620 const binop_index = self.exprs.items.len;
16211621 try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } });
16221622
1623 var lhs: DocData.WalkResult = try self.walkRef(
1623 const lhs: DocData.WalkResult = try self.walkRef(
16241624 file,
16251625 parent_scope,
16261626 parent_src,
......@@ -1628,7 +1628,7 @@ fn walkInstruction(
16281628 false,
16291629 call_ctx,
16301630 );
1631 var rhs: DocData.WalkResult = try self.walkRef(
1631 const rhs: DocData.WalkResult = try self.walkRef(
16321632 file,
16331633 parent_scope,
16341634 parent_src,
......@@ -1786,7 +1786,7 @@ fn walkInstruction(
17861786 const pl_node = data[@intFromEnum(inst)].pl_node;
17871787 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
17881788
1789 var rhs: DocData.WalkResult = try self.walkRef(
1789 const rhs: DocData.WalkResult = try self.walkRef(
17901790 file,
17911791 parent_scope,
17921792 parent_src,
......@@ -1801,7 +1801,7 @@ fn walkInstruction(
18011801 const rhs_index = self.exprs.items.len;
18021802 try self.exprs.append(self.arena, rhs.expr);
18031803
1804 var lhs: DocData.WalkResult = try self.walkRef(
1804 const lhs: DocData.WalkResult = try self.walkRef(
18051805 file,
18061806 parent_scope,
18071807 parent_src,
......@@ -1850,7 +1850,7 @@ fn walkInstruction(
18501850 const binop_index = self.exprs.items.len;
18511851 try self.exprs.append(self.arena, .{ .builtinBin = .{ .lhs = 0, .rhs = 0 } });
18521852
1853 var lhs: DocData.WalkResult = try self.walkRef(
1853 const lhs: DocData.WalkResult = try self.walkRef(
18541854 file,
18551855 parent_scope,
18561856 parent_src,
......@@ -1858,7 +1858,7 @@ fn walkInstruction(
18581858 false,
18591859 call_ctx,
18601860 );
1861 var rhs: DocData.WalkResult = try self.walkRef(
1861 const rhs: DocData.WalkResult = try self.walkRef(
18621862 file,
18631863 parent_scope,
18641864 parent_src,
......@@ -1882,7 +1882,7 @@ fn walkInstruction(
18821882 const pl_node = data[@intFromEnum(inst)].pl_node;
18831883 const extra = file.zir.extraData(Zir.Inst.MulAdd, pl_node.payload_index);
18841884
1885 var mul1: DocData.WalkResult = try self.walkRef(
1885 const mul1: DocData.WalkResult = try self.walkRef(
18861886 file,
18871887 parent_scope,
18881888 parent_src,
......@@ -1890,7 +1890,7 @@ fn walkInstruction(
18901890 false,
18911891 call_ctx,
18921892 );
1893 var mul2: DocData.WalkResult = try self.walkRef(
1893 const mul2: DocData.WalkResult = try self.walkRef(
18941894 file,
18951895 parent_scope,
18961896 parent_src,
......@@ -1898,7 +1898,7 @@ fn walkInstruction(
18981898 false,
18991899 call_ctx,
19001900 );
1901 var add: DocData.WalkResult = try self.walkRef(
1901 const add: DocData.WalkResult = try self.walkRef(
19021902 file,
19031903 parent_scope,
19041904 parent_src,
......@@ -1914,7 +1914,7 @@ fn walkInstruction(
19141914 const add_index = self.exprs.items.len;
19151915 try self.exprs.append(self.arena, add.expr);
19161916
1917 var type_index: usize = self.exprs.items.len;
1917 const type_index: usize = self.exprs.items.len;
19181918 try self.exprs.append(self.arena, add.typeRef orelse .{ .type = @intFromEnum(Ref.type_type) });
19191919
19201920 return DocData.WalkResult{
......@@ -1933,7 +1933,7 @@ fn walkInstruction(
19331933 const pl_node = data[@intFromEnum(inst)].pl_node;
19341934 const extra = file.zir.extraData(Zir.Inst.UnionInit, pl_node.payload_index);
19351935
1936 var union_type: DocData.WalkResult = try self.walkRef(
1936 const union_type: DocData.WalkResult = try self.walkRef(
19371937 file,
19381938 parent_scope,
19391939 parent_src,
......@@ -1941,7 +1941,7 @@ fn walkInstruction(
19411941 false,
19421942 call_ctx,
19431943 );
1944 var field_name: DocData.WalkResult = try self.walkRef(
1944 const field_name: DocData.WalkResult = try self.walkRef(
19451945 file,
19461946 parent_scope,
19471947 parent_src,
......@@ -1949,7 +1949,7 @@ fn walkInstruction(
19491949 false,
19501950 call_ctx,
19511951 );
1952 var init: DocData.WalkResult = try self.walkRef(
1952 const init: DocData.WalkResult = try self.walkRef(
19531953 file,
19541954 parent_scope,
19551955 parent_src,
......@@ -1980,7 +1980,7 @@ fn walkInstruction(
19801980 const pl_node = data[@intFromEnum(inst)].pl_node;
19811981 const extra = file.zir.extraData(Zir.Inst.BuiltinCall, pl_node.payload_index);
19821982
1983 var modifier: DocData.WalkResult = try self.walkRef(
1983 const modifier: DocData.WalkResult = try self.walkRef(
19841984 file,
19851985 parent_scope,
19861986 parent_src,
......@@ -1989,7 +1989,7 @@ fn walkInstruction(
19891989 call_ctx,
19901990 );
19911991
1992 var callee: DocData.WalkResult = try self.walkRef(
1992 const callee: DocData.WalkResult = try self.walkRef(
19931993 file,
19941994 parent_scope,
19951995 parent_src,
......@@ -1998,7 +1998,7 @@ fn walkInstruction(
19981998 call_ctx,
19991999 );
20002000
2001 var args: DocData.WalkResult = try self.walkRef(
2001 const args: DocData.WalkResult = try self.walkRef(
20022002 file,
20032003 parent_scope,
20042004 parent_src,
......@@ -2028,7 +2028,7 @@ fn walkInstruction(
20282028 const pl_node = data[@intFromEnum(inst)].pl_node;
20292029 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
20302030
2031 var lhs: DocData.WalkResult = try self.walkRef(
2031 const lhs: DocData.WalkResult = try self.walkRef(
20322032 file,
20332033 parent_scope,
20342034 parent_src,
......@@ -2036,7 +2036,7 @@ fn walkInstruction(
20362036 false,
20372037 call_ctx,
20382038 );
2039 var rhs: DocData.WalkResult = try self.walkRef(
2039 const rhs: DocData.WalkResult = try self.walkRef(
20402040 file,
20412041 parent_scope,
20422042 parent_src,
......@@ -2060,7 +2060,7 @@ fn walkInstruction(
20602060 const pl_node = data[@intFromEnum(inst)].pl_node;
20612061 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
20622062
2063 var lhs: DocData.WalkResult = try self.walkRef(
2063 const lhs: DocData.WalkResult = try self.walkRef(
20642064 file,
20652065 parent_scope,
20662066 parent_src,
......@@ -2068,7 +2068,7 @@ fn walkInstruction(
20682068 false,
20692069 call_ctx,
20702070 );
2071 var rhs: DocData.WalkResult = try self.walkRef(
2071 const rhs: DocData.WalkResult = try self.walkRef(
20722072 file,
20732073 parent_scope,
20742074 parent_src,
......@@ -2090,7 +2090,7 @@ fn walkInstruction(
20902090 // .elem_type => {
20912091 // const un_node = data[@intFromEnum(inst)].un_node;
20922092
2093 // var operand: DocData.WalkResult = try self.walkRef(
2093 // const operand: DocData.WalkResult = try self.walkRef(
20942094 // file,
20952095 // parent_scope, parent_src,
20962096 // un_node.operand,
......@@ -2158,7 +2158,7 @@ fn walkInstruction(
21582158 address_space = ref_result.expr;
21592159 extra_index += 1;
21602160 }
2161 var bit_start: ?DocData.Expr = null;
2161 const bit_start: ?DocData.Expr = null;
21622162 if (ptr.flags.has_bit_range) {
21632163 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
21642164 const ref_result = try self.walkRef(
......@@ -2292,7 +2292,7 @@ fn walkInstruction(
22922292 const array_data = try self.arena.alloc(usize, operands.len - 1);
22932293
22942294 std.debug.assert(operands.len > 0);
2295 var array_type = try self.walkRef(
2295 const array_type = try self.walkRef(
22962296 file,
22972297 parent_scope,
22982298 parent_src,
......@@ -2352,7 +2352,7 @@ fn walkInstruction(
23522352 const array_data = try self.arena.alloc(usize, operands.len - 1);
23532353
23542354 std.debug.assert(operands.len > 0);
2355 var array_type = try self.walkRef(
2355 const array_type = try self.walkRef(
23562356 file,
23572357 parent_scope,
23582358 parent_src,
......@@ -2578,7 +2578,7 @@ fn walkInstruction(
25782578 const pl_node = data[@intFromEnum(inst)].pl_node;
25792579 const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index);
25802580 const body = file.zir.extra[extra.end..][extra.data.body_len - 1];
2581 var operand: DocData.WalkResult = try self.walkRef(
2581 const operand: DocData.WalkResult = try self.walkRef(
25822582 file,
25832583 parent_scope,
25842584 parent_src,
......@@ -2903,7 +2903,7 @@ fn walkInstruction(
29032903 => {
29042904 const un_node = data[@intFromEnum(inst)].un_node;
29052905
2906 var operand: DocData.WalkResult = try self.walkRef(
2906 const operand: DocData.WalkResult = try self.walkRef(
29072907 file,
29082908 parent_scope,
29092909 parent_src,
......@@ -2920,7 +2920,7 @@ fn walkInstruction(
29202920 .struct_init_empty_ref_result => {
29212921 const un_node = data[@intFromEnum(inst)].un_node;
29222922
2923 var operand: DocData.WalkResult = try self.walkRef(
2923 const operand: DocData.WalkResult = try self.walkRef(
29242924 file,
29252925 parent_scope,
29262926 parent_src,
......@@ -3937,7 +3937,7 @@ fn walkInstruction(
39373937 try self.exprs.append(self.arena, last_type);
39383938
39393939 const ptr_index = self.exprs.items.len;
3940 var ptr: DocData.WalkResult = try self.walkRef(
3940 const ptr: DocData.WalkResult = try self.walkRef(
39413941 file,
39423942 parent_scope,
39433943 parent_src,
......@@ -3948,7 +3948,7 @@ fn walkInstruction(
39483948 try self.exprs.append(self.arena, ptr.expr);
39493949
39503950 const expected_value_index = self.exprs.items.len;
3951 var expected_value: DocData.WalkResult = try self.walkRef(
3951 const expected_value: DocData.WalkResult = try self.walkRef(
39523952 file,
39533953 parent_scope,
39543954 parent_src,
......@@ -3959,7 +3959,7 @@ fn walkInstruction(
39593959 try self.exprs.append(self.arena, expected_value.expr);
39603960
39613961 const new_value_index = self.exprs.items.len;
3962 var new_value: DocData.WalkResult = try self.walkRef(
3962 const new_value: DocData.WalkResult = try self.walkRef(
39633963 file,
39643964 parent_scope,
39653965 parent_src,
......@@ -3970,7 +3970,7 @@ fn walkInstruction(
39703970 try self.exprs.append(self.arena, new_value.expr);
39713971
39723972 const success_order_index = self.exprs.items.len;
3973 var success_order: DocData.WalkResult = try self.walkRef(
3973 const success_order: DocData.WalkResult = try self.walkRef(
39743974 file,
39753975 parent_scope,
39763976 parent_src,
......@@ -3981,7 +3981,7 @@ fn walkInstruction(
39813981 try self.exprs.append(self.arena, success_order.expr);
39823982
39833983 const failure_order_index = self.exprs.items.len;
3984 var failure_order: DocData.WalkResult = try self.walkRef(
3984 const failure_order: DocData.WalkResult = try self.walkRef(
39853985 file,
39863986 parent_scope,
39873987 parent_src,
src/Compilation.zig+6-6
......@@ -1759,7 +1759,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
17591759
17601760 const digest = hash.final();
17611761 const artifact_sub_dir = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });
1762 var artifact_dir = try options.local_cache_directory.handle.makeOpenPath(artifact_sub_dir, .{});
1762 const artifact_dir = try options.local_cache_directory.handle.makeOpenPath(artifact_sub_dir, .{});
17631763 owned_link_dir = artifact_dir;
17641764 const link_artifact_directory: Directory = .{
17651765 .handle = artifact_dir,
......@@ -2173,7 +2173,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
21732173 // LLD might drop some symbols as unused during LTO and GCing, therefore,
21742174 // we force mark them for resolution here.
21752175
2176 var tls_index_sym = switch (comp.getTarget().cpu.arch) {
2176 const tls_index_sym = switch (comp.getTarget().cpu.arch) {
21772177 .x86 => "__tls_index",
21782178 else => "_tls_index",
21792179 };
......@@ -2576,7 +2576,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
25762576 var artifact_dir = try comp.local_cache_directory.handle.openDir(o_sub_path, .{});
25772577 defer artifact_dir.close();
25782578
2579 var dir_path = try comp.local_cache_directory.join(comp.gpa, &.{o_sub_path});
2579 const dir_path = try comp.local_cache_directory.join(comp.gpa, &.{o_sub_path});
25802580 defer comp.gpa.free(dir_path);
25812581
25822582 module.zig_cache_artifact_directory = .{
......@@ -4961,7 +4961,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
49614961
49624962 var cli_diagnostics = resinator.cli.Diagnostics.init(comp.gpa);
49634963 defer cli_diagnostics.deinit();
4964 var options = resinator.cli.parse(comp.gpa, resinator_args.items, &cli_diagnostics) catch |err| switch (err) {
4964 const options = resinator.cli.parse(comp.gpa, resinator_args.items, &cli_diagnostics) catch |err| switch (err) {
49654965 error.ParseError => {
49664966 return comp.failWin32ResourceCli(win32_resource, &cli_diagnostics);
49674967 },
......@@ -5062,7 +5062,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
50625062 log.warn("failed to delete '{s}': {s}", .{ out_dep_path, @errorName(err) });
50635063 };
50645064
5065 var full_input = std.fs.cwd().readFileAlloc(arena, out_rcpp_path, std.math.maxInt(usize)) catch |err| switch (err) {
5065 const full_input = std.fs.cwd().readFileAlloc(arena, out_rcpp_path, std.math.maxInt(usize)) catch |err| switch (err) {
50665066 error.OutOfMemory => return error.OutOfMemory,
50675067 else => |e| {
50685068 return comp.failWin32Resource(win32_resource, "failed to read preprocessed file '{s}': {s}", .{ out_rcpp_path, @errorName(e) });
......@@ -5072,7 +5072,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
50725072 var mapping_results = try resinator.source_mapping.parseAndRemoveLineCommands(arena, full_input, full_input, .{ .initial_filename = rc_src.src_path });
50735073 defer mapping_results.mappings.deinit(arena);
50745074
5075 var final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings);
5075 const final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings);
50765076
50775077 var output_file = zig_cache_tmp_dir.createFile(out_res_path, .{}) catch |err| {
50785078 return comp.failWin32Resource(win32_resource, "failed to create output file '{s}': {s}", .{ out_res_path, @errorName(err) });
src/Package/Fetch/git.zig+9-9
......@@ -83,7 +83,7 @@ pub const Repository = struct {
8383 ) !void {
8484 try repository.odb.seekOid(commit_oid);
8585 const tree_oid = tree_oid: {
86 var commit_object = try repository.odb.readObject();
86 const commit_object = try repository.odb.readObject();
8787 if (commit_object.type != .commit) return error.NotACommit;
8888 break :tree_oid try getCommitTree(commit_object.data);
8989 };
......@@ -122,14 +122,14 @@ pub const Repository = struct {
122122 var file = try dir.createFile(entry.name, .{});
123123 defer file.close();
124124 try repository.odb.seekOid(entry.oid);
125 var file_object = try repository.odb.readObject();
125 const file_object = try repository.odb.readObject();
126126 if (file_object.type != .blob) return error.InvalidFile;
127127 try file.writeAll(file_object.data);
128128 try file.sync();
129129 },
130130 .symlink => {
131131 try repository.odb.seekOid(entry.oid);
132 var symlink_object = try repository.odb.readObject();
132 const symlink_object = try repository.odb.readObject();
133133 if (symlink_object.type != .blob) return error.InvalidFile;
134134 const link_name = symlink_object.data;
135135 dir.symLink(link_name, entry.name, .{}) catch |e| {
......@@ -1230,7 +1230,7 @@ fn resolveDeltaChain(
12301230 const delta_offset = delta_offsets[i];
12311231 try pack.seekTo(delta_offset);
12321232 const delta_header = try EntryHeader.read(pack.reader());
1233 var delta_data = try readObjectRaw(allocator, pack.reader(), delta_header.uncompressedLength());
1233 const delta_data = try readObjectRaw(allocator, pack.reader(), delta_header.uncompressedLength());
12341234 defer allocator.free(delta_data);
12351235 var delta_stream = std.io.fixedBufferStream(delta_data);
12361236 const delta_reader = delta_stream.reader();
......@@ -1238,7 +1238,7 @@ fn resolveDeltaChain(
12381238 const expanded_size = try readSizeVarInt(delta_reader);
12391239
12401240 const expanded_alloc_size = std.math.cast(usize, expanded_size) orelse return error.ObjectTooLarge;
1241 var expanded_data = try allocator.alloc(u8, expanded_alloc_size);
1241 const expanded_data = try allocator.alloc(u8, expanded_alloc_size);
12421242 errdefer allocator.free(expanded_data);
12431243 var expanded_delta_stream = std.io.fixedBufferStream(expanded_data);
12441244 var base_stream = std.io.fixedBufferStream(base_data);
......@@ -1259,7 +1259,7 @@ fn readObjectRaw(allocator: Allocator, reader: anytype, size: u64) ![]u8 {
12591259 var buffered_reader = std.io.bufferedReader(reader);
12601260 var decompress_stream = try std.compress.zlib.decompressStream(allocator, buffered_reader.reader());
12611261 defer decompress_stream.deinit();
1262 var data = try allocator.alloc(u8, alloc_size);
1262 const data = try allocator.alloc(u8, alloc_size);
12631263 errdefer allocator.free(data);
12641264 try decompress_stream.reader().readNoEof(data);
12651265 _ = decompress_stream.reader().readByte() catch |e| switch (e) {
......@@ -1290,14 +1290,14 @@ fn expandDelta(base_object: anytype, delta_reader: anytype, writer: anytype) !vo
12901290 size2: bool,
12911291 size3: bool,
12921292 } = @bitCast(inst.value);
1293 var offset_parts: packed struct { offset1: u8, offset2: u8, offset3: u8, offset4: u8 } = .{
1293 const offset_parts: packed struct { offset1: u8, offset2: u8, offset3: u8, offset4: u8 } = .{
12941294 .offset1 = if (available.offset1) try delta_reader.readByte() else 0,
12951295 .offset2 = if (available.offset2) try delta_reader.readByte() else 0,
12961296 .offset3 = if (available.offset3) try delta_reader.readByte() else 0,
12971297 .offset4 = if (available.offset4) try delta_reader.readByte() else 0,
12981298 };
12991299 const offset: u32 = @bitCast(offset_parts);
1300 var size_parts: packed struct { size1: u8, size2: u8, size3: u8 } = .{
1300 const size_parts: packed struct { size1: u8, size2: u8, size3: u8 } = .{
13011301 .size1 = if (available.size1) try delta_reader.readByte() else 0,
13021302 .size2 = if (available.size2) try delta_reader.readByte() else 0,
13031303 .size3 = if (available.size3) try delta_reader.readByte() else 0,
......@@ -1414,7 +1414,7 @@ test "packfile indexing and checkout" {
14141414 defer walker.deinit();
14151415 while (try walker.next()) |entry| {
14161416 if (entry.kind != .file) continue;
1417 var path = try testing.allocator.dupe(u8, entry.path);
1417 const path = try testing.allocator.dupe(u8, entry.path);
14181418 errdefer testing.allocator.free(path);
14191419 mem.replaceScalar(u8, path, std.fs.path.sep, '/');
14201420 try actual_files.append(testing.allocator, path);
src/Sema.zig+9-9
......@@ -22899,7 +22899,7 @@ fn checkSimdBinOp(
2289922899 const rhs_ty = sema.typeOf(uncasted_rhs);
2290022900
2290122901 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
22902 var vec_len: ?usize = if (lhs_ty.zigTypeTag(mod) == .Vector) lhs_ty.vectorLen(mod) else null;
22902 const vec_len: ?usize = if (lhs_ty.zigTypeTag(mod) == .Vector) lhs_ty.vectorLen(mod) else null;
2290322903 const result_ty = try sema.resolvePeerTypes(block, src, &.{ uncasted_lhs, uncasted_rhs }, .{
2290422904 .override = &[_]?LazySrcLoc{ lhs_src, rhs_src },
2290522905 });
......@@ -23286,8 +23286,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2328623286
2328723287 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
2328823288 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
23289 var a = try sema.resolveInst(extra.a);
23290 var b = try sema.resolveInst(extra.b);
23289 const a = try sema.resolveInst(extra.a);
23290 const b = try sema.resolveInst(extra.b);
2329123291 var mask = try sema.resolveInst(extra.mask);
2329223292 var mask_ty = sema.typeOf(mask);
2329323293
......@@ -23328,7 +23328,7 @@ fn analyzeShuffle(
2332823328 .child = elem_ty.toIntern(),
2332923329 });
2333023330
23331 var maybe_a_len = switch (sema.typeOf(a).zigTypeTag(mod)) {
23331 const maybe_a_len = switch (sema.typeOf(a).zigTypeTag(mod)) {
2333223332 .Array, .Vector => sema.typeOf(a).arrayLen(mod),
2333323333 .Undefined => null,
2333423334 else => return sema.fail(block, a_src, "expected vector or array with element type '{}', found '{}'", .{
......@@ -23336,7 +23336,7 @@ fn analyzeShuffle(
2333623336 sema.typeOf(a).fmt(sema.mod),
2333723337 }),
2333823338 };
23339 var maybe_b_len = switch (sema.typeOf(b).zigTypeTag(mod)) {
23339 const maybe_b_len = switch (sema.typeOf(b).zigTypeTag(mod)) {
2334023340 .Array, .Vector => sema.typeOf(b).arrayLen(mod),
2334123341 .Undefined => null,
2334223342 else => return sema.fail(block, b_src, "expected vector or array with element type '{}', found '{}'", .{
......@@ -23801,7 +23801,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2380123801 const call_src = inst_data.src();
2380223802
2380323803 const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
23804 var func = try sema.resolveInst(extra.callee);
23804 const func = try sema.resolveInst(extra.callee);
2380523805
2380623806 const modifier_ty = try sema.getBuiltinType("CallModifier");
2380723807 const air_ref = try sema.resolveInst(extra.modifier);
......@@ -23859,7 +23859,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2385923859 return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(sema.mod)});
2386023860 }
2386123861
23862 var resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod));
23862 const resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod));
2386323863 for (resolved_args, 0..) |*resolved, i| {
2386423864 resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(i), args_ty);
2386523865 }
......@@ -33274,8 +33274,8 @@ fn resolvePeerTypes(
3327433274 else => {},
3327533275 }
3327633276
33277 var peer_tys = try sema.arena.alloc(?Type, instructions.len);
33278 var peer_vals = try sema.arena.alloc(?Value, instructions.len);
33277 const peer_tys = try sema.arena.alloc(?Type, instructions.len);
33278 const peer_vals = try sema.arena.alloc(?Value, instructions.len);
3327933279
3328033280 for (instructions, peer_tys, peer_vals) |inst, *ty, *val| {
3328133281 ty.* = sema.typeOf(inst);
src/arch/riscv64/CodeGen.zig+5
......@@ -2648,6 +2648,11 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
26482648 // conventions
26492649 var next_register: usize = 0;
26502650 var next_stack_offset: u32 = 0;
2651 // TODO: this is never assigned, which is a bug, but I don't know how this code works
2652 // well enough to try and fix it. I *think* `next_register += next_stack_offset` is
2653 // supposed to be `next_stack_offset += param_size` in every case where it appears.
2654 _ = &next_stack_offset;
2655
26512656 const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 };
26522657
26532658 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
src/arch/sparc64/CodeGen.zig+4
......@@ -4481,6 +4481,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
44814481
44824482 var next_register: usize = 0;
44834483 var next_stack_offset: u32 = 0;
4484 // TODO: this is never assigned, which is a bug, but I don't know how this code works
4485 // well enough to try and fix it. I *think* `next_register += next_stack_offset` is
4486 // supposed to be `next_stack_offset += param_size` in every case where it appears.
4487 _ = &next_stack_offset;
44844488
44854489 // The caller puts the argument in %o0-%o5, which becomes %i0-%i5 inside the callee.
44864490 const argument_registers = switch (role) {
src/arch/wasm/CodeGen.zig+4-4
......@@ -2139,7 +2139,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21392139 const mod = func.bin_file.base.options.module.?;
21402140 const child_type = func.typeOfIndex(inst).childType(mod);
21412141
2142 var result = result: {
2142 const result = result: {
21432143 if (!child_type.isFnOrHasRuntimeBitsIgnoreComptime(mod)) {
21442144 break :result try func.allocStack(Type.usize); // create pointer to void
21452145 }
......@@ -5001,7 +5001,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50015001 return func.finishAir(inst, try WValue.toLocal(.stack, func, elem_ty), &.{ bin_op.lhs, bin_op.rhs });
50025002 },
50035003 else => {
5004 var stack_vec = try func.allocStack(array_ty);
5004 const stack_vec = try func.allocStack(array_ty);
50055005 try func.store(stack_vec, array, array_ty, 0);
50065006
50075007 // Is a non-unrolled vector (v128)
......@@ -5944,7 +5944,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
59445944 rhs.free(func);
59455945 };
59465946
5947 var bin_op = try (try func.binOp(lhs, rhs, lhs_ty, op)).toLocal(func, lhs_ty);
5947 const bin_op = try (try func.binOp(lhs, rhs, lhs_ty, op)).toLocal(func, lhs_ty);
59485948 var result = if (wasm_bits != int_info.bits) blk: {
59495949 break :blk try (try func.wrapOperand(bin_op, lhs_ty)).toLocal(func, lhs_ty);
59505950 } else bin_op;
......@@ -6335,7 +6335,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63356335 const lhs_ext = try func.fpext(lhs, ty, Type.f32);
63366336 const addend_ext = try func.fpext(addend, ty, Type.f32);
63376337 // call to compiler-rt `fn fmaf(f32, f32, f32) f32`
6338 var result = try func.callIntrinsic(
6338 const result = try func.callIntrinsic(
63396339 "fmaf",
63406340 &.{ .f32_type, .f32_type, .f32_type },
63416341 Type.f32,
src/arch/x86_64/CodeGen.zig+1-1
......@@ -2181,7 +2181,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
21812181 const ret_reg = param_regs[0];
21822182 const enum_mcv = MCValue{ .register = param_regs[1] };
21832183
2184 var exitlude_jump_relocs = try self.gpa.alloc(Mir.Inst.Index, enum_ty.enumFieldCount(mod));
2184 const exitlude_jump_relocs = try self.gpa.alloc(Mir.Inst.Index, enum_ty.enumFieldCount(mod));
21852185 defer self.gpa.free(exitlude_jump_relocs);
21862186
21872187 const data_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
src/arch/x86_64/Disassembler.zig+1-2
......@@ -234,13 +234,12 @@ fn inst(encoding: Encoding, args: struct {
234234 op3: Instruction.Operand = .none,
235235 op4: Instruction.Operand = .none,
236236}) Instruction {
237 var i = Instruction{ .encoding = encoding, .prefix = args.prefix, .ops = .{
237 return .{ .encoding = encoding, .prefix = args.prefix, .ops = .{
238238 args.op1,
239239 args.op2,
240240 args.op3,
241241 args.op4,
242242 } };
243 return i;
244243}
245244
246245const Prefixes = struct {
src/arch/x86_64/Lower.zig+1-1
......@@ -342,7 +342,7 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand)
342342 .Lib => lower.bin_file.options.link_mode == .Static,
343343 };
344344
345 var emit_prefix = prefix;
345 const emit_prefix = prefix;
346346 var emit_mnemonic = mnemonic;
347347 var emit_ops_storage: [4]Operand = undefined;
348348 const emit_ops = emit_ops_storage[0..ops.len];
src/arch/x86_64/encoder.zig+2-2
......@@ -244,7 +244,7 @@ pub const Instruction = struct {
244244 }),
245245 },
246246 .imm => |imm| if (enc_op.isSigned()) {
247 var imms = imm.asSigned(enc_op.immBitSize());
247 const imms = imm.asSigned(enc_op.immBitSize());
248248 if (imms < 0) try writer.writeByte('-');
249249 try writer.print("0x{x}", .{@abs(imms)});
250250 } else try writer.print("0x{x}", .{imm.asUnsigned(enc_op.immBitSize())}),
......@@ -1077,7 +1077,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8, assembly: []co
10771077 const given_fmt = try std.fmt.allocPrint(testing.allocator, "{x}", .{std.fmt.fmtSliceHexLower(given)});
10781078 defer testing.allocator.free(given_fmt);
10791079 const idx = std.mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
1080 var padding = try testing.allocator.alloc(u8, idx + 5);
1080 const padding = try testing.allocator.alloc(u8, idx + 5);
10811081 defer testing.allocator.free(padding);
10821082 @memset(padding, ' ');
10831083 std.debug.print("\nASM: {s}\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{
src/aro_translate_c.zig+2-2
......@@ -346,7 +346,7 @@ fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void {
346346 defer block_scope.deinit();
347347
348348 var scope = &block_scope.base;
349 _ = scope;
349 _ = &scope;
350350
351351 var param_id: c_uint = 0;
352352 for (proto_payload.data.params, fn_ty.data.func.params) |*param, param_info| {
......@@ -534,7 +534,7 @@ fn transFnType(
534534 ctx: FnProtoContext,
535535) !ZigNode {
536536 const param_count: usize = fn_ty.data.func.params.len;
537 var fn_params = try c.arena.alloc(ast.Payload.Param, param_count);
537 const fn_params = try c.arena.alloc(ast.Payload.Param, param_count);
538538
539539 for (fn_ty.data.func.params, fn_params) |param_info, *param_node| {
540540 const param_ty = param_info.ty;
src/codegen.zig+1-1
......@@ -368,7 +368,7 @@ pub fn generateSymbol(
368368 .bytes => |bytes| try code.appendSlice(bytes),
369369 .elems, .repeated_elem => {
370370 var index: u64 = 0;
371 var len_including_sentinel =
371 const len_including_sentinel =
372372 array_type.len + @intFromBool(array_type.sentinel != .none);
373373 while (index < len_including_sentinel) : (index += 1) {
374374 switch (try generateSymbol(bin_file, src_loc, .{
src/codegen/llvm/BitcodeReader.zig+1-1
......@@ -410,7 +410,7 @@ fn readVbr(bc: *BitcodeReader, comptime T: type, bits: u7) !T {
410410 var result: u64 = 0;
411411 var shift: u6 = 0;
412412 while (true) {
413 var chunk = try bc.readFixed(u64, bits);
413 const chunk = try bc.readFixed(u64, bits);
414414 result |= (chunk & (chunk_msb - 1)) << shift;
415415 if (chunk & chunk_msb == 0) break;
416416 shift += chunk_bits;
src/codegen/spirv.zig+4-4
......@@ -1284,7 +1284,7 @@ const DeclGen = struct {
12841284
12851285 const elem_ty = ty.childType(mod);
12861286 const elem_ty_ref = try self.resolveType(elem_ty, .indirect);
1287 var total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel(mod)) orelse {
1287 const total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel(mod)) orelse {
12881288 return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(mod)});
12891289 };
12901290 const ty_ref = if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) blk: {
......@@ -2115,7 +2115,7 @@ const DeclGen = struct {
21152115 const child_ty = ty.childType(mod);
21162116 const vector_len = ty.vectorLen(mod);
21172117
2118 var constituents = try self.gpa.alloc(IdRef, vector_len);
2118 const constituents = try self.gpa.alloc(IdRef, vector_len);
21192119 defer self.gpa.free(constituents);
21202120
21212121 for (constituents, 0..) |*constituent, i| {
......@@ -2312,7 +2312,7 @@ const DeclGen = struct {
23122312 if (ty.isVector(mod)) {
23132313 const child_ty = ty.childType(mod);
23142314 const vector_len = ty.vectorLen(mod);
2315 var constituents = try self.gpa.alloc(IdRef, vector_len);
2315 const constituents = try self.gpa.alloc(IdRef, vector_len);
23162316 defer self.gpa.free(constituents);
23172317
23182318 for (constituents, 0..) |*constituent, i| {
......@@ -2727,7 +2727,7 @@ const DeclGen = struct {
27272727 const child_ty = ty.childType(mod);
27282728 const vector_len = ty.vectorLen(mod);
27292729
2730 var constituents = try self.gpa.alloc(IdRef, vector_len);
2730 const constituents = try self.gpa.alloc(IdRef, vector_len);
27312731 defer self.gpa.free(constituents);
27322732
27332733 for (constituents, 0..) |*constituent, i| {
src/link/C.zig+1-1
......@@ -103,7 +103,7 @@ pub fn openPath(gpa: Allocator, sub_path: []const u8, options: link.Options) !*C
103103 });
104104 errdefer file.close();
105105
106 var c_file = try gpa.create(C);
106 const c_file = try gpa.create(C);
107107 errdefer gpa.destroy(c_file);
108108
109109 c_file.* = .{
src/link/Coff.zig+5-5
......@@ -563,7 +563,7 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme
563563
564564 // First we look for an appropriately sized free list node.
565565 // The list is unordered. We'll just take the first thing that works.
566 var vaddr = blk: {
566 const vaddr = blk: {
567567 var i: usize = 0;
568568 while (i < free_list.items.len) {
569569 const big_atom_index = free_list.items[i];
......@@ -815,7 +815,7 @@ fn writeAtom(self: *Coff, atom_index: Atom.Index, code: []u8) !void {
815815}
816816
817817fn debugMem(allocator: Allocator, handle: std.ChildProcess.Id, pvaddr: std.os.windows.LPVOID, code: []const u8) !void {
818 var buffer = try allocator.alloc(u8, code.len);
818 const buffer = try allocator.alloc(u8, code.len);
819819 defer allocator.free(buffer);
820820 const memread = try std.os.windows.ReadProcessMemory(handle, pvaddr, buffer);
821821 log.debug("to write: {x}", .{std.fmt.fmtSliceHexLower(code)});
......@@ -1071,7 +1071,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
10711071 &code_buffer,
10721072 .none,
10731073 );
1074 var code = switch (res) {
1074 const code = switch (res) {
10751075 .ok => code_buffer.items,
10761076 .fail => |em| {
10771077 decl.analysis = .codegen_failure;
......@@ -1132,7 +1132,7 @@ fn lowerConst(self: *Coff, name: []const u8, tv: TypedValue, required_alignment:
11321132 const res = try codegen.generateSymbol(&self.base, src_loc, tv, &code_buffer, .none, .{
11331133 .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?,
11341134 });
1135 var code = switch (res) {
1135 const code = switch (res) {
11361136 .ok => code_buffer.items,
11371137 .fail => |em| return .{ .fail = em },
11381138 };
......@@ -1196,7 +1196,7 @@ pub fn updateDecl(
11961196 }, &code_buffer, .none, .{
11971197 .parent_atom_index = atom.getSymbolIndex().?,
11981198 });
1199 var code = switch (res) {
1199 const code = switch (res) {
12001200 .ok => code_buffer.items,
12011201 .fail => |em| {
12021202 decl.analysis = .codegen_failure;
src/link/Dwarf.zig+3-3
......@@ -303,7 +303,7 @@ pub const DeclState = struct {
303303 // DW.AT.name, DW.FORM.string
304304 try dbg_info_buffer.writer().print("{d}\x00", .{field_index});
305305 // DW.AT.type, DW.FORM.ref4
306 var index = dbg_info_buffer.items.len;
306 const index = dbg_info_buffer.items.len;
307307 try dbg_info_buffer.resize(index + 4);
308308 try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index));
309309 // DW.AT.data_member_location, DW.FORM.udata
......@@ -329,7 +329,7 @@ pub const DeclState = struct {
329329 // DW.AT.name, DW.FORM.string
330330 try dbg_info_buffer.writer().print("{d}\x00", .{field_index});
331331 // DW.AT.type, DW.FORM.ref4
332 var index = dbg_info_buffer.items.len;
332 const index = dbg_info_buffer.items.len;
333333 try dbg_info_buffer.resize(index + 4);
334334 try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index));
335335 // DW.AT.data_member_location, DW.FORM.udata
......@@ -350,7 +350,7 @@ pub const DeclState = struct {
350350 dbg_info_buffer.appendSliceAssumeCapacity(field_name);
351351 dbg_info_buffer.appendAssumeCapacity(0);
352352 // DW.AT.type, DW.FORM.ref4
353 var index = dbg_info_buffer.items.len;
353 const index = dbg_info_buffer.items.len;
354354 try dbg_info_buffer.resize(index + 4);
355355 try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index));
356356 // DW.AT.data_member_location, DW.FORM.udata
src/link/Elf.zig+5-5
......@@ -967,7 +967,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
967967 // --verbose-link
968968 if (self.base.options.verbose_link) try self.dumpArgv(comp);
969969
970 var csu = try CsuObjects.init(arena, self.base.options, comp);
970 const csu = try CsuObjects.init(arena, self.base.options, comp);
971971 const compiler_rt_path: ?[]const u8 = blk: {
972972 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
973973 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
......@@ -1493,7 +1493,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
14931493 } else null;
14941494 const gc_sections = self.base.options.gc_sections orelse false;
14951495
1496 var csu = try CsuObjects.init(arena, self.base.options, comp);
1496 const csu = try CsuObjects.init(arena, self.base.options, comp);
14971497 const compiler_rt_path: ?[]const u8 = blk: {
14981498 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
14991499 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
......@@ -2599,7 +2599,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
25992599 try argv.append(full_out_path);
26002600
26012601 // csu prelude
2602 var csu = try CsuObjects.init(arena, self.base.options, comp);
2602 const csu = try CsuObjects.init(arena, self.base.options, comp);
26032603 if (csu.crt0) |v| try argv.append(v);
26042604 if (csu.crti) |v| try argv.append(v);
26052605 if (csu.crtbegin) |v| try argv.append(v);
......@@ -3852,7 +3852,7 @@ fn sortPhdrs(self: *Elf) error{OutOfMemory}!void {
38523852 backlinks[entry.phndx] = @as(u16, @intCast(i));
38533853 }
38543854
3855 var slice = try self.phdrs.toOwnedSlice(gpa);
3855 const slice = try self.phdrs.toOwnedSlice(gpa);
38563856 defer gpa.free(slice);
38573857
38583858 try self.phdrs.ensureTotalCapacityPrecise(gpa, slice.len);
......@@ -3957,7 +3957,7 @@ fn sortShdrs(self: *Elf) !void {
39573957 backlinks[entry.shndx] = @as(u16, @intCast(i));
39583958 }
39593959
3960 var slice = try self.shdrs.toOwnedSlice(gpa);
3960 const slice = try self.shdrs.toOwnedSlice(gpa);
39613961 defer gpa.free(slice);
39623962
39633963 try self.shdrs.ensureTotalCapacityPrecise(gpa, slice.len);
src/link/Elf/eh_frame.zig+1-1
......@@ -217,7 +217,7 @@ pub const Iterator = struct {
217217 var stream = std.io.fixedBufferStream(it.data[it.pos..]);
218218 const reader = stream.reader();
219219
220 var size = try reader.readInt(u32, .little);
220 const size = try reader.readInt(u32, .little);
221221 if (size == 0xFFFFFFFF) @panic("TODO");
222222
223223 const id = try reader.readInt(u32, .little);
src/link/MachO.zig+9-7
......@@ -1923,6 +1923,8 @@ fn resolveBoundarySymbols(self: *MachO) !void {
19231923 _ = self.unresolved.swapRemove(global_index);
19241924 continue;
19251925 }
1926
1927 next_sym += 1;
19261928 }
19271929}
19281930
......@@ -2250,7 +2252,7 @@ pub fn updateFunc(self: *MachO, mod: *Module, func_index: InternPool.Index, air:
22502252 else
22512253 try codegen.generateFunction(&self.base, decl.srcLoc(mod), func_index, air, liveness, &code_buffer, .none);
22522254
2253 var code = switch (res) {
2255 const code = switch (res) {
22542256 .ok => code_buffer.items,
22552257 .fail => |em| {
22562258 decl.analysis = .codegen_failure;
......@@ -2330,7 +2332,7 @@ fn lowerConst(
23302332 const res = try codegen.generateSymbol(&self.base, src_loc, tv, &code_buffer, .none, .{
23312333 .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?,
23322334 });
2333 var code = switch (res) {
2335 const code = switch (res) {
23342336 .ok => code_buffer.items,
23352337 .fail => |em| return .{ .fail = em },
23362338 };
......@@ -2416,7 +2418,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo
24162418 .parent_atom_index = sym_index,
24172419 });
24182420
2419 var code = switch (res) {
2421 const code = switch (res) {
24202422 .ok => code_buffer.items,
24212423 .fail => |em| {
24222424 decl.analysis = .codegen_failure;
......@@ -2585,7 +2587,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D
25852587 .parent_atom_index = init_sym_index,
25862588 });
25872589
2588 var code = switch (res) {
2590 const code = switch (res) {
25892591 .ok => code_buffer.items,
25902592 .fail => |em| {
25912593 decl.analysis = .codegen_failure;
......@@ -3425,7 +3427,7 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm
34253427
34263428 // First we look for an appropriately sized free list node.
34273429 // The list is unordered. We'll just take the first thing that works.
3428 var vaddr = blk: {
3430 const vaddr = blk: {
34293431 var i: usize = 0;
34303432 while (i < free_list.items.len) {
34313433 const big_atom_index = free_list.items[i];
......@@ -3969,7 +3971,7 @@ fn writeDyldInfoData(self: *MachO) !void {
39693971 link_seg.filesize = needed_size;
39703972 assert(mem.isAlignedGeneric(u64, link_seg.fileoff + link_seg.filesize, @alignOf(u64)));
39713973
3972 var buffer = try gpa.alloc(u8, needed_size);
3974 const buffer = try gpa.alloc(u8, needed_size);
39733975 defer gpa.free(buffer);
39743976 @memset(buffer, 0);
39753977
......@@ -5226,7 +5228,7 @@ fn reportMissingLibraryError(
52265228) error{OutOfMemory}!void {
52275229 const gpa = self.base.allocator;
52285230 try self.misc_errors.ensureUnusedCapacity(gpa, 1);
5229 var notes = try gpa.alloc(File.ErrorMsg, checked_paths.len);
5231 const notes = try gpa.alloc(File.ErrorMsg, checked_paths.len);
52305232 errdefer gpa.free(notes);
52315233 for (checked_paths, notes) |path, *note| {
52325234 note.* = .{ .msg = try std.fmt.allocPrint(gpa, "tried {s}", .{path}) };
src/link/MachO/Archive.zig+3-3
......@@ -98,7 +98,7 @@ pub fn parse(self: *Archive, allocator: Allocator, reader: anytype) !void {
9898 _ = try reader.readBytesNoEof(SARMAG);
9999 self.header = try reader.readStruct(ar_hdr);
100100 const name_or_length = try self.header.nameOrLength();
101 var embedded_name = try parseName(allocator, name_or_length, reader);
101 const embedded_name = try parseName(allocator, name_or_length, reader);
102102 log.debug("parsing archive '{s}' at '{s}'", .{ embedded_name, self.name });
103103 defer allocator.free(embedded_name);
104104
......@@ -124,7 +124,7 @@ fn parseName(allocator: Allocator, name_or_length: ar_hdr.NameOrLength, reader:
124124
125125fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !void {
126126 const symtab_size = try reader.readInt(u32, .little);
127 var symtab = try allocator.alloc(u8, symtab_size);
127 const symtab = try allocator.alloc(u8, symtab_size);
128128 defer allocator.free(symtab);
129129
130130 reader.readNoEof(symtab) catch {
......@@ -133,7 +133,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !
133133 };
134134
135135 const strtab_size = try reader.readInt(u32, .little);
136 var strtab = try allocator.alloc(u8, strtab_size);
136 const strtab = try allocator.alloc(u8, strtab_size);
137137 defer allocator.free(strtab);
138138
139139 reader.readNoEof(strtab) catch {
src/link/MachO/Dylib.zig+3-3
......@@ -167,7 +167,7 @@ pub fn parseFromBinary(
167167 .REEXPORT_DYLIB => {
168168 if (should_lookup_reexports) {
169169 // Parse install_name to dependent dylib.
170 var id = try Id.fromLoadCommand(
170 const id = try Id.fromLoadCommand(
171171 allocator,
172172 cmd.cast(macho.dylib_command).?,
173173 cmd.getDylibPathName(),
......@@ -410,7 +410,7 @@ pub fn parseFromStub(
410410
411411 log.debug(" (found re-export '{s}')", .{lib});
412412
413 var dep_id = try Id.default(allocator, lib);
413 const dep_id = try Id.default(allocator, lib);
414414 try dependent_libs.writeItem(.{ .id = dep_id, .parent = dylib_id });
415415 }
416416 }
......@@ -527,7 +527,7 @@ pub fn parseFromStub(
527527
528528 log.debug(" (found re-export '{s}')", .{lib});
529529
530 var dep_id = try Id.default(allocator, lib);
530 const dep_id = try Id.default(allocator, lib);
531531 try dependent_libs.writeItem(.{ .id = dep_id, .parent = dylib_id });
532532 }
533533 }
src/link/MachO/Trie.zig+8-8
......@@ -150,7 +150,7 @@ pub fn deinit(self: *Trie, allocator: Allocator) void {
150150}
151151
152152test "Trie node count" {
153 var gpa = testing.allocator;
153 const gpa = testing.allocator;
154154 var trie: Trie = .{};
155155 defer trie.deinit(gpa);
156156 try trie.init(gpa);
......@@ -196,7 +196,7 @@ test "Trie node count" {
196196}
197197
198198test "Trie basic" {
199 var gpa = testing.allocator;
199 const gpa = testing.allocator;
200200 var trie: Trie = .{};
201201 defer trie.deinit(gpa);
202202 try trie.init(gpa);
......@@ -254,7 +254,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void {
254254 const given_fmt = try std.fmt.allocPrint(testing.allocator, "{x}", .{std.fmt.fmtSliceHexLower(given)});
255255 defer testing.allocator.free(given_fmt);
256256 const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
257 var padding = try testing.allocator.alloc(u8, idx + 5);
257 const padding = try testing.allocator.alloc(u8, idx + 5);
258258 defer testing.allocator.free(padding);
259259 @memset(padding, ' ');
260260 std.debug.print("\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ expected_fmt, given_fmt, padding });
......@@ -292,7 +292,7 @@ test "write Trie to a byte stream" {
292292 0x3, 0x0, 0x80, 0x20, 0x0, // terminal node
293293 };
294294
295 var buffer = try gpa.alloc(u8, trie.size);
295 const buffer = try gpa.alloc(u8, trie.size);
296296 defer gpa.free(buffer);
297297 var stream = std.io.fixedBufferStream(buffer);
298298 {
......@@ -331,7 +331,7 @@ test "parse Trie from byte stream" {
331331
332332 try trie.finalize(gpa);
333333
334 var out_buffer = try gpa.alloc(u8, trie.size);
334 const out_buffer = try gpa.alloc(u8, trie.size);
335335 defer gpa.free(out_buffer);
336336 var out_stream = std.io.fixedBufferStream(out_buffer);
337337 _ = try trie.write(out_stream.writer());
......@@ -362,7 +362,7 @@ test "ordering bug" {
362362 0x00, 0x12, 0x03, 0x00, 0xD8, 0x0A, 0x00,
363363 };
364364
365 var buffer = try gpa.alloc(u8, trie.size);
365 const buffer = try gpa.alloc(u8, trie.size);
366366 defer gpa.free(buffer);
367367 var stream = std.io.fixedBufferStream(buffer);
368368 // Writing finalized trie again should yield the same result.
......@@ -426,7 +426,7 @@ pub const Node = struct {
426426 // To: A -> C -> B
427427 const mid = try allocator.create(Node);
428428 mid.* = .{ .base = self.base };
429 var to_label = try allocator.dupe(u8, edge.label[match..]);
429 const to_label = try allocator.dupe(u8, edge.label[match..]);
430430 allocator.free(edge.label);
431431 const to_node = edge.to;
432432 edge.to = mid;
......@@ -573,7 +573,7 @@ pub const Node = struct {
573573 /// Updates offset of this node in the output byte stream.
574574 fn finalize(self: *Node, offset_in_trie: u64) !FinalizeResult {
575575 var stream = std.io.countingWriter(std.io.null_writer);
576 var writer = stream.writer();
576 const writer = stream.writer();
577577
578578 var node_size: u64 = 0;
579579 if (self.terminal_info) |info| {
src/link/MachO/UnwindInfo.zig+1-1
......@@ -417,7 +417,7 @@ pub fn collect(info: *UnwindInfo, macho_file: *MachO) !void {
417417 gop.value_ptr.count += 1;
418418 }
419419
420 var slice = common_encodings_counts.values();
420 const slice = common_encodings_counts.values();
421421 mem.sort(CommonEncWithCount, slice, {}, CommonEncWithCount.greaterThan);
422422
423423 var i: u7 = 0;
src/link/MachO/eh_frame.zig+1-1
......@@ -586,7 +586,7 @@ pub const Iterator = struct {
586586 var stream = std.io.fixedBufferStream(it.data[it.pos..]);
587587 const reader = stream.reader();
588588
589 var size = try reader.readInt(u32, .little);
589 const size = try reader.readInt(u32, .little);
590590 if (size == 0xFFFFFFFF) {
591591 log.debug("MachO doesn't support 64bit DWARF CFI __eh_frame records", .{});
592592 return error.BadDwarfCfi;
src/link/MachO/load_commands.zig+1-1
......@@ -112,7 +112,7 @@ pub fn calcMinHeaderPad(gpa: Allocator, options: *const link.Options, ctx: CalcL
112112 log.debug("minimum requested headerpad size 0x{x}", .{padding + @sizeOf(macho.mach_header_64)});
113113
114114 if (options.headerpad_max_install_names) {
115 var min_headerpad_size: u32 = try calcLCsSize(gpa, options, ctx, true);
115 const min_headerpad_size: u32 = try calcLCsSize(gpa, options, ctx, true);
116116 log.debug("headerpad_max_install_names minimum headerpad size 0x{x}", .{
117117 min_headerpad_size + @sizeOf(macho.mach_header_64),
118118 });
src/link/MachO/zld.zig+1-1
......@@ -503,7 +503,7 @@ pub fn linkWithZld(
503503 const size = math.cast(usize, linkedit.fileoff - start) orelse return error.Overflow;
504504 if (size > 0) {
505505 log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start });
506 var padding = try gpa.alloc(u8, size);
506 const padding = try gpa.alloc(u8, size);
507507 defer gpa.free(padding);
508508 @memset(padding, 0);
509509 try macho_file.base.file.?.pwriteAll(padding, start);
src/link/Plan9.zig+6-6
......@@ -300,7 +300,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Plan9 {
300300 else => return error.UnsupportedP9Architecture,
301301 };
302302
303 var arena_allocator = std.heap.ArenaAllocator.init(gpa);
303 const arena_allocator = std.heap.ArenaAllocator.init(gpa);
304304
305305 const self = try gpa.create(Plan9);
306306 self.* = .{
......@@ -467,7 +467,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I
467467
468468 const sym_index = try self.allocateSymbolIndex();
469469 const new_atom_idx = try self.createAtom();
470 var info: Atom = .{
470 const info: Atom = .{
471471 .type = .d,
472472 .offset = null,
473473 .sym_index = sym_index,
......@@ -496,7 +496,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I
496496 },
497497 };
498498 // duped_code is freed when the unnamed const is freed
499 var duped_code = try self.base.allocator.dupe(u8, code);
499 const duped_code = try self.base.allocator.dupe(u8, code);
500500 errdefer self.base.allocator.free(duped_code);
501501 const new_atom = self.getAtomPtr(new_atom_idx);
502502 new_atom.* = info;
......@@ -1024,7 +1024,7 @@ pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void {
10241024 const decl = mod.declPtr(decl_index);
10251025 const is_fn = decl.val.isFuncBody(mod);
10261026 if (is_fn) {
1027 var symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(mod)).?;
1027 const symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(mod)).?;
10281028 var submap = symidx_and_submap.functions;
10291029 if (submap.fetchSwapRemove(decl_index)) |removed_entry| {
10301030 self.base.allocator.free(removed_entry.value.code);
......@@ -1204,7 +1204,7 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind
12041204 },
12051205 };
12061206 // duped_code is freed when the atom is freed
1207 var duped_code = try self.base.allocator.dupe(u8, code);
1207 const duped_code = try self.base.allocator.dupe(u8, code);
12081208 errdefer self.base.allocator.free(duped_code);
12091209 self.getAtomPtr(atom_index).code = .{
12101210 .code_ptr = duped_code.ptr,
......@@ -1489,7 +1489,7 @@ pub fn lowerAnonDecl(self: *Plan9, decl_val: InternPool.Index, src_loc: Module.S
14891489 // to put it in some location.
14901490 // ...
14911491 const gpa = self.base.allocator;
1492 var gop = try self.anon_decls.getOrPut(gpa, decl_val);
1492 const gop = try self.anon_decls.getOrPut(gpa, decl_val);
14931493 const mod = self.base.options.module.?;
14941494 if (!gop.found_existing) {
14951495 const ty = mod.intern_pool.typeOf(decl_val).toType();
src/link/Wasm.zig+5-5
......@@ -860,7 +860,7 @@ fn resolveSymbolsInArchives(wasm: *Wasm) !void {
860860 // Parse object and and resolve symbols again before we check remaining
861861 // undefined symbols.
862862 const object_file_index = @as(u16, @intCast(wasm.objects.items.len));
863 var object = try archive.parseObject(wasm.base.allocator, offset.items[0]);
863 const object = try archive.parseObject(wasm.base.allocator, offset.items[0]);
864864 try wasm.objects.append(wasm.base.allocator, object);
865865 try wasm.resolveSymbolsInObject(object_file_index);
866866
......@@ -1344,7 +1344,7 @@ pub fn deinit(wasm: *Wasm) void {
13441344/// Will re-use slots when a symbol was freed at an earlier stage.
13451345pub fn allocateSymbol(wasm: *Wasm) !u32 {
13461346 try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1);
1347 var symbol: Symbol = .{
1347 const symbol: Symbol = .{
13481348 .name = std.math.maxInt(u32), // will be set after updateDecl as well as during atom creation for decls
13491349 .flags = @intFromEnum(Symbol.Flag.WASM_SYM_BINDING_LOCAL),
13501350 .tag = .undefined, // will be set after updateDecl
......@@ -1655,7 +1655,7 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !u3
16551655 symbol.setUndefined(true);
16561656
16571657 const sym_index = if (wasm.symbols_free_list.popOrNull()) |index| index else blk: {
1658 var index = @as(u32, @intCast(wasm.symbols.items.len));
1658 const index: u32 = @intCast(wasm.symbols.items.len);
16591659 try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1);
16601660 wasm.symbols.items.len += 1;
16611661 break :blk index;
......@@ -2632,7 +2632,7 @@ fn setupImports(wasm: *Wasm) !void {
26322632
26332633 // We copy the import to a new import to ensure the names contain references
26342634 // to the internal string table, rather than of the object file.
2635 var new_imp: types.Import = .{
2635 const new_imp: types.Import = .{
26362636 .module_name = try wasm.string_table.put(wasm.base.allocator, object.string_table.get(import.module_name)),
26372637 .name = try wasm.string_table.put(wasm.base.allocator, object.string_table.get(import.name)),
26382638 .kind = import.kind,
......@@ -3800,7 +3800,7 @@ fn writeToFile(
38003800 const table_loc = wasm.findGlobalSymbol("__indirect_function_table").?;
38013801 const table_sym = table_loc.getSymbol(wasm);
38023802
3803 var flags: u32 = if (table_sym.index == 0) 0x0 else 0x02; // passive with implicit 0-index table or set table index manually
3803 const flags: u32 = if (table_sym.index == 0) 0x0 else 0x02; // passive with implicit 0-index table or set table index manually
38043804 try leb.writeULEB128(binary_writer, flags);
38053805 if (flags == 0x02) {
38063806 try leb.writeULEB128(binary_writer, table_sym.index);
src/link/Wasm/Object.zig+3-3
......@@ -252,7 +252,7 @@ fn checkLegacyIndirectFunctionTable(object: *Object) !?Symbol {
252252 return error.MissingTableSymbols;
253253 }
254254
255 var table_import: types.Import = for (object.imports) |imp| {
255 const table_import: types.Import = for (object.imports) |imp| {
256256 if (imp.kind == .table) {
257257 break imp;
258258 }
......@@ -512,7 +512,7 @@ fn Parser(comptime ReaderType: type) type {
512512 try assertEnd(reader);
513513 },
514514 .code => {
515 var start = reader.context.bytes_left;
515 const start = reader.context.bytes_left;
516516 var index: u32 = 0;
517517 const count = try readLeb(u32, reader);
518518 while (index < count) : (index += 1) {
......@@ -532,7 +532,7 @@ fn Parser(comptime ReaderType: type) type {
532532 }
533533 },
534534 .data => {
535 var start = reader.context.bytes_left;
535 const start = reader.context.bytes_left;
536536 var index: u32 = 0;
537537 const count = try readLeb(u32, reader);
538538 while (index < count) : (index += 1) {
src/link/tapi/yaml.zig+1-1
......@@ -491,7 +491,7 @@ pub fn stringify(allocator: Allocator, input: anytype, writer: anytype) !void {
491491 var arena = ArenaAllocator.init(allocator);
492492 defer arena.deinit();
493493
494 var maybe_value = try Value.encode(arena.allocator(), input);
494 const maybe_value = try Value.encode(arena.allocator(), input);
495495
496496 if (maybe_value) |value| {
497497 // TODO should we output as an explicit doc?
src/main.zig+7-7
......@@ -4479,7 +4479,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
44794479 try stdout_writer.writeByte('\n');
44804480 }
44814481
4482 var full_input = full_input: {
4482 const full_input = full_input: {
44834483 if (options.preprocess != .no) {
44844484 if (!build_options.have_llvm) {
44854485 fatal("clang not available: compiler built without LLVM extensions", .{});
......@@ -4526,7 +4526,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
45264526 }
45274527
45284528 if (process.can_spawn) {
4529 var result = std.ChildProcess.run(.{
4529 const result = std.ChildProcess.run(.{
45304530 .allocator = gpa,
45314531 .argv = argv.items,
45324532 .max_output_bytes = std.math.maxInt(u32),
......@@ -4593,7 +4593,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
45934593 var mapping_results = try resinator.source_mapping.parseAndRemoveLineCommands(gpa, full_input, full_input, .{ .initial_filename = options.input_filename });
45944594 defer mapping_results.mappings.deinit(gpa);
45954595
4596 var final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings);
4596 const final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings);
45974597
45984598 var output_file = std.fs.cwd().createFile(options.output_filename, .{}) catch |err| {
45994599 try resinator.utils.renderErrorMessage(stderr.writer(), stderr_config, .err, "unable to create output file '{s}': {s}", .{ options.output_filename, @errorName(err) });
......@@ -4762,7 +4762,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
47624762
47634763 const libc_installation: ?*LibCInstallation = libc: {
47644764 if (input_file) |libc_file| {
4765 var libc = try arena.create(LibCInstallation);
4765 const libc = try arena.create(LibCInstallation);
47664766 libc.* = LibCInstallation.parse(arena, libc_file, cross_target) catch |err| {
47674767 fatal("unable to parse libc file at path {s}: {s}", .{ libc_file, @errorName(err) });
47684768 };
......@@ -4781,7 +4781,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
47814781 const target = cross_target.toTarget();
47824782 const is_native_abi = cross_target.isNativeAbi();
47834783
4784 var libc_dirs = Compilation.detectLibCIncludeDirs(
4784 const libc_dirs = Compilation.detectLibCIncludeDirs(
47854785 arena,
47864786 zig_lib_directory.path.?,
47874787 target,
......@@ -4960,7 +4960,7 @@ pub const usage_build =
49604960pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
49614961 const work_around_btrfs_bug = builtin.os.tag == .linux and
49624962 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
4963 var color: Color = .auto;
4963 const color: Color = .auto;
49644964
49654965 // We want to release all the locks before executing the child process, so we make a nice
49664966 // big block here to ensure the cleanup gets run when we extract out our argv.
......@@ -6001,7 +6001,7 @@ const ArgIteratorResponseFile = process.ArgIteratorGeneral(.{ .comments = true,
60016001/// Initialize the arguments from a Response File. "*.rsp"
60026002fn initArgIteratorResponseFile(allocator: Allocator, resp_file_path: []const u8) !ArgIteratorResponseFile {
60036003 const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit
6004 var cmd_line = try fs.cwd().readFileAlloc(allocator, resp_file_path, max_bytes);
6004 const cmd_line = try fs.cwd().readFileAlloc(allocator, resp_file_path, max_bytes);
60056005 errdefer allocator.free(cmd_line);
60066006
60076007 return ArgIteratorResponseFile.initTakeOwnership(allocator, cmd_line);
src/resinator/bmp.zig+1-1
......@@ -120,7 +120,7 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo {
120120 var dib_header_buf: [@sizeOf(BITMAPCOREHEADER)]u8 align(@alignOf(BITMAPCOREHEADER)) = undefined;
121121 std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .little);
122122 reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF;
123 var dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf);
123 const dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf);
124124 structFieldsLittleToNative(BITMAPCOREHEADER, dib_header);
125125
126126 // > The size of the color palette is calculated from the BitsPerPixel value.
src/resinator/cli.zig+5-5
......@@ -163,15 +163,15 @@ pub const Options = struct {
163163 // we shouldn't change anything.
164164 if (val_ptr.* == .undefine) return;
165165 // Otherwise, the new value takes precedence.
166 var duped_value = try self.allocator.dupe(u8, value);
166 const duped_value = try self.allocator.dupe(u8, value);
167167 errdefer self.allocator.free(duped_value);
168168 val_ptr.deinit(self.allocator);
169169 val_ptr.* = .{ .define = duped_value };
170170 return;
171171 }
172 var duped_key = try self.allocator.dupe(u8, identifier);
172 const duped_key = try self.allocator.dupe(u8, identifier);
173173 errdefer self.allocator.free(duped_key);
174 var duped_value = try self.allocator.dupe(u8, value);
174 const duped_value = try self.allocator.dupe(u8, value);
175175 errdefer self.allocator.free(duped_value);
176176 try self.symbols.put(self.allocator, duped_key, .{ .define = duped_value });
177177 }
......@@ -183,7 +183,7 @@ pub const Options = struct {
183183 action.* = .{ .undefine = {} };
184184 return;
185185 }
186 var duped_key = try self.allocator.dupe(u8, identifier);
186 const duped_key = try self.allocator.dupe(u8, identifier);
187187 errdefer self.allocator.free(duped_key);
188188 try self.symbols.put(self.allocator, duped_key, .{ .undefine = {} });
189189 }
......@@ -828,7 +828,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn
828828 }
829829 }
830830
831 var positionals = args[arg_i..];
831 const positionals = args[arg_i..];
832832
833833 if (positionals.len < 1) {
834834 var err_details = Diagnostics.ErrorDetails{ .print_args = false, .arg_index = arg_i };
src/resinator/code_pages.zig+3-3
......@@ -302,8 +302,8 @@ pub const Utf8 = struct {
302302
303303 pub fn decode(bytes: []const u8) Codepoint {
304304 std.debug.assert(bytes.len > 0);
305 var first_byte = bytes[0];
306 var expected_len = sequenceLength(first_byte) orelse {
305 const first_byte = bytes[0];
306 const expected_len = sequenceLength(first_byte) orelse {
307307 return .{ .value = Codepoint.invalid, .byte_len = 1 };
308308 };
309309 if (expected_len == 1) return .{ .value = first_byte, .byte_len = 1 };
......@@ -367,7 +367,7 @@ pub const Utf8 = struct {
367367
368368test "Utf8.WellFormedDecoder" {
369369 const invalid_utf8 = "\xF0\x80";
370 var decoded = Utf8.WellFormedDecoder.decode(invalid_utf8);
370 const decoded = Utf8.WellFormedDecoder.decode(invalid_utf8);
371371 try std.testing.expectEqual(Codepoint.invalid, decoded.value);
372372 try std.testing.expectEqual(@as(usize, 2), decoded.byte_len);
373373}
src/resinator/comments.zig+4-4
......@@ -206,9 +206,9 @@ inline fn handleMultilineCarriageReturn(
206206}
207207
208208pub fn removeCommentsAlloc(allocator: Allocator, source: []const u8, source_mappings: ?*SourceMappings) ![]u8 {
209 var buf = try allocator.alloc(u8, source.len);
209 const buf = try allocator.alloc(u8, source.len);
210210 errdefer allocator.free(buf);
211 var result = removeComments(source, buf, source_mappings);
211 const result = removeComments(source, buf, source_mappings);
212212 return allocator.realloc(buf, result.len);
213213}
214214
......@@ -326,7 +326,7 @@ test "remove comments with mappings" {
326326 try mappings.set(allocator, 3, .{ .start_line = 3, .end_line = 3, .filename_offset = 0 });
327327 defer mappings.deinit(allocator);
328328
329 var result = removeComments(&mut_source, &mut_source, &mappings);
329 const result = removeComments(&mut_source, &mut_source, &mappings);
330330
331331 try std.testing.expectEqualStrings("blahblah", result);
332332 try std.testing.expectEqual(@as(usize, 1), mappings.mapping.items.len);
......@@ -335,6 +335,6 @@ test "remove comments with mappings" {
335335
336336test "in place" {
337337 var mut_source = "blah /* comment */ blah".*;
338 var result = removeComments(&mut_source, &mut_source, null);
338 const result = removeComments(&mut_source, &mut_source, null);
339339 try std.testing.expectEqualStrings("blah blah", result);
340340}
src/resinator/compile.zig+4-4
......@@ -666,7 +666,7 @@ pub const Compiler = struct {
666666 },
667667 },
668668 .dib => {
669 var bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes));
669 const bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes));
670670 if (native_endian == .big) {
671671 std.mem.byteSwapAllFields(ico.BitmapHeader, bitmap_header);
672672 }
......@@ -1773,13 +1773,13 @@ pub const Compiler = struct {
17731773 }
17741774 try data_writer.writeByteNTimes(0, num_padding);
17751775
1776 var style = if (control.style) |style_expression|
1776 const style = if (control.style) |style_expression|
17771777 // Certain styles are implied by the control type
17781778 evaluateFlagsExpressionWithDefault(res.ControlClass.getImpliedStyle(control_type), style_expression, self.source, self.input_code_pages)
17791779 else
17801780 res.ControlClass.getImpliedStyle(control_type);
17811781
1782 var exstyle = if (control.exstyle) |exstyle_expression|
1782 const exstyle = if (control.exstyle) |exstyle_expression|
17831783 evaluateFlagsExpressionWithDefault(0, exstyle_expression, self.source, self.input_code_pages)
17841784 else
17851785 0;
......@@ -3205,7 +3205,7 @@ pub const StringTable = struct {
32053205 const trimmed_string = trim: {
32063206 // Two NUL characters in a row act as a terminator
32073207 // Note: This is only the case for STRINGTABLE strings
3208 var trimmed = trimToDoubleNUL(u16, utf16_string);
3208 const trimmed = trimToDoubleNUL(u16, utf16_string);
32093209 // We also want to trim any trailing NUL characters
32103210 break :trim std.mem.trimRight(u16, trimmed, &[_]u16{0});
32113211 };
src/resinator/lang.zig+1-1
......@@ -98,7 +98,7 @@ pub fn tagToId(tag: []const u8) error{InvalidLanguageTag}!?LanguageId {
9898 var normalized_buf: [longest_known_tag]u8 = undefined;
9999 // To allow e.g. `de-de_phoneb` to get looked up as `de-de`, we need to
100100 // omit the suffix, but only if the tag contains a valid alternate sort order.
101 var tag_to_normalize = if (parsed.isSuffixValidSortOrder()) tag[0 .. tag.len - (parsed.suffix.?.len + 1)] else tag;
101 const tag_to_normalize = if (parsed.isSuffixValidSortOrder()) tag[0 .. tag.len - (parsed.suffix.?.len + 1)] else tag;
102102 const normalized_tag = normalizeTag(tag_to_normalize, &normalized_buf);
103103 return std.meta.stringToEnum(LanguageId, normalized_tag) orelse {
104104 // special case for a tag that has been mapped to the same ID
src/resinator/parse.zig+6-6
......@@ -100,7 +100,7 @@ pub const Parser = struct {
100100 // because it almost always leads to unhelpful error messages
101101 // (usually it will end up with bogus things like 'file
102102 // not found: {')
103 var statement = try self.parseStatement();
103 const statement = try self.parseStatement();
104104 try statements.append(statement);
105105 }
106106 }
......@@ -698,7 +698,7 @@ pub const Parser = struct {
698698 .dlginclude => {
699699 const common_resource_attributes = try self.parseCommonResourceAttributes();
700700
701 var filename_expression = try self.parseExpression(.{
701 const filename_expression = try self.parseExpression(.{
702702 .allowed_types = .{ .string = true },
703703 });
704704
......@@ -756,7 +756,7 @@ pub const Parser = struct {
756756 return &node.base;
757757 }
758758
759 var filename_expression = try self.parseExpression(.{
759 const filename_expression = try self.parseExpression(.{
760760 // Don't tell the user that numbers are accepted since we error on
761761 // number expressions and regular number literals are treated as unquoted
762762 // literals rather than numbers, so from the users perspective
......@@ -934,8 +934,8 @@ pub const Parser = struct {
934934 style = try optional_param_parser.parse(.{ .not_expression_allowed = true });
935935 }
936936
937 var exstyle: ?*Node = try optional_param_parser.parse(.{ .not_expression_allowed = true });
938 var help_id: ?*Node = switch (resource) {
937 const exstyle: ?*Node = try optional_param_parser.parse(.{ .not_expression_allowed = true });
938 const help_id: ?*Node = switch (resource) {
939939 .dialogex => try optional_param_parser.parse(.{}),
940940 else => null,
941941 };
......@@ -1526,7 +1526,7 @@ pub const Parser = struct {
15261526
15271527 pub fn toErrorDetails(options: ParseExpressionOptions, token: Token) ErrorDetails {
15281528 // TODO: expected_types_override interaction with is_known_to_be_number_expression?
1529 var expected_types = options.expected_types_override orelse ErrorDetails.ExpectedTypes{
1529 const expected_types = options.expected_types_override orelse ErrorDetails.ExpectedTypes{
15301530 .number = options.allowed_types.number,
15311531 .number_expression = options.allowed_types.number,
15321532 .string_literal = options.allowed_types.string and !options.is_known_to_be_number_expression,
src/resinator/res.zig+2-2
......@@ -357,7 +357,7 @@ pub const NameOrOrdinal = union(enum) {
357357 /// RC compiler would have allowed them, so that a proper warning/error
358358 /// can be emitted.
359359 pub fn maybeNonAsciiOrdinalFromString(bytes: SourceBytes) ?NameOrOrdinal {
360 var buf = bytes.slice;
360 const buf = bytes.slice;
361361 const radix = 10;
362362 if (buf.len > 2 and buf[0] == '0') {
363363 switch (buf[1]) {
......@@ -514,7 +514,7 @@ test "NameOrOrdinal" {
514514 {
515515 var expected = blk: {
516516 // the input before the 𐐷 character, but uppercased
517 var expected_u8_bytes = "00614982008907933748980730280674788429543776231864944218790698304852300002973622122844631429099469274282385299397783838528QFFL7SHNSIETG0QKLR1UYPBTUV1PMFQRRA0VJDG354GQEDJMUPGPP1W1EXVNTZVEIZ6K3IPQM1AWGEYALMEODYVEZGOD3MFMGEY8FNR4JUETTB1PZDEWSNDRGZUA8SNXP3NGO";
517 const expected_u8_bytes = "00614982008907933748980730280674788429543776231864944218790698304852300002973622122844631429099469274282385299397783838528QFFL7SHNSIETG0QKLR1UYPBTUV1PMFQRRA0VJDG354GQEDJMUPGPP1W1EXVNTZVEIZ6K3IPQM1AWGEYALMEODYVEZGOD3MFMGEY8FNR4JUETTB1PZDEWSNDRGZUA8SNXP3NGO";
518518 var buf: [256:0]u16 = undefined;
519519 for (expected_u8_bytes, 0..) |byte, i| {
520520 buf[i] = std.mem.nativeToLittle(u16, byte);
src/resinator/source_mapping.zig+2-2
......@@ -251,7 +251,7 @@ pub fn handleLineCommand(allocator: Allocator, line_command: []const u8, current
251251}
252252
253253pub fn parseAndRemoveLineCommandsAlloc(allocator: Allocator, source: []const u8, options: ParseAndRemoveLineCommandsOptions) !ParseLineCommandsResult {
254 var buf = try allocator.alloc(u8, source.len);
254 const buf = try allocator.alloc(u8, source.len);
255255 errdefer allocator.free(buf);
256256 var result = try parseAndRemoveLineCommands(allocator, source, buf, options);
257257 result.result = try allocator.realloc(buf, result.result.len);
......@@ -440,7 +440,7 @@ pub const SourceMappings = struct {
440440 }
441441
442442 pub fn set(self: *SourceMappings, allocator: Allocator, line_num: usize, span: SourceSpan) !void {
443 var ptr = try self.expandAndGet(allocator, line_num);
443 const ptr = try self.expandAndGet(allocator, line_num);
444444 ptr.* = span;
445445 }
446446
src/translate_c.zig+5-5
......@@ -456,7 +456,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
456456 block_scope.return_type = return_qt;
457457 defer block_scope.deinit();
458458
459 var scope = &block_scope.base;
459 const scope = &block_scope.base;
460460
461461 var param_id: c_uint = 0;
462462 for (proto_node.data.params) |*param| {
......@@ -1363,7 +1363,7 @@ fn transSimpleOffsetOfExpr(c: *Context, expr: *const clang.OffsetOfExpr) TransEr
13631363 if (c.decl_table.get(@intFromPtr(record_decl.getCanonicalDecl()))) |type_name| {
13641364 const type_node = try Tag.type.create(c.arena, type_name);
13651365
1366 var raw_field_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(field_decl)).getName_bytes_begin());
1366 const raw_field_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(field_decl)).getName_bytes_begin());
13671367 const quoted_field_name = try std.fmt.allocPrint(c.arena, "\"{s}\"", .{raw_field_name});
13681368 const field_name_node = try Tag.string_literal.create(c.arena, quoted_field_name);
13691369
......@@ -1967,7 +1967,7 @@ fn transBoolExpr(
19671967 return Node{ .tag_if_small_enough = @intFromEnum(([2]Tag{ .true_literal, .false_literal })[@intFromBool(is_zero)]) };
19681968 }
19691969
1970 var res = try transExpr(c, scope, expr, used);
1970 const res = try transExpr(c, scope, expr, used);
19711971 if (isBoolRes(res)) {
19721972 return maybeSuppressResult(c, used, res);
19731973 }
......@@ -3477,7 +3477,7 @@ fn cIsFunctionDeclRef(expr: *const clang.Expr) bool {
34773477
34783478fn transCallExpr(c: *Context, scope: *Scope, stmt: *const clang.CallExpr, result_used: ResultUsed) TransError!Node {
34793479 const callee = stmt.getCallee();
3480 var raw_fn_expr = try transExpr(c, scope, callee, .used);
3480 const raw_fn_expr = try transExpr(c, scope, callee, .used);
34813481
34823482 var is_ptr = false;
34833483 const fn_ty = qualTypeGetFnProto(callee.getType(), &is_ptr);
......@@ -5889,7 +5889,7 @@ fn escapeUnprintables(ctx: *Context, m: *MacroCtx) ![]const u8 {
58895889
58905890 const formatter = std.fmt.fmtSliceEscapeLower(zigified);
58915891 const encoded_size = @as(usize, @intCast(std.fmt.count("{s}", .{formatter})));
5892 var output = try ctx.arena.alloc(u8, encoded_size);
5892 const output = try ctx.arena.alloc(u8, encoded_size);
58935893 return std.fmt.bufPrint(output, "{s}", .{formatter}) catch |err| switch (err) {
58945894 error.NoSpaceLeft => unreachable,
58955895 else => |e| return e,
src/translate_c/ast.zig+7-2
......@@ -1625,13 +1625,18 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
16251625 });
16261626 const main_token = try c.addToken(.equal, "=");
16271627 if (payload.value.tag() == .identifier) {
1628 // Render as `_ = @TypeOf(foo);` to avoid tripping "pointless discard" error.
1628 // Render as `_ = &foo;` to avoid tripping "pointless discard" and "local variable never mutated" errors.
1629 var addr_of_pl: Payload.UnOp = .{
1630 .base = .{ .tag = .address_of },
1631 .data = payload.value,
1632 };
1633 const addr_of: Node = .{ .ptr_otherwise = &addr_of_pl.base };
16291634 return c.addNode(.{
16301635 .tag = .assign,
16311636 .main_token = main_token,
16321637 .data = .{
16331638 .lhs = lhs,
1634 .rhs = try renderBuiltinCall(c, "@TypeOf", &.{payload.value}),
1639 .rhs = try renderNode(c, addr_of),
16351640 },
16361641 });
16371642 } else {
src/translate_c/common.zig+8
......@@ -291,6 +291,14 @@ pub fn ScopeExtra(comptime Context: type, comptime Type: type) type {
291291 }
292292
293293 pub fn skipVariableDiscard(inner: *Scope, name: []const u8) void {
294 if (true) {
295 // TODO: due to 'local variable is never mutated' errors, we can
296 // only skip discards if a variable is used as an lvalue, which
297 // we don't currently have detection for in translate-c.
298 // Once #17584 is completed, perhaps we can do away with this
299 // logic entirely, and instead rely on render to fixup code.
300 return;
301 }
294302 var scope = inner;
295303 while (true) {
296304 switch (scope.id) {
src/value.zig+3-3
......@@ -2136,7 +2136,7 @@ pub const Value = struct {
21362136 lhs_bigint.limbs.len + rhs_bigint.limbs.len,
21372137 );
21382138 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
2139 var limbs_buffer = try arena.alloc(
2139 const limbs_buffer = try arena.alloc(
21402140 std.math.big.Limb,
21412141 std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1),
21422142 );
......@@ -2249,7 +2249,7 @@ pub const Value = struct {
22492249 ),
22502250 );
22512251 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
2252 var limbs_buffer = try arena.alloc(
2252 const limbs_buffer = try arena.alloc(
22532253 std.math.big.Limb,
22542254 std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1),
22552255 );
......@@ -2788,7 +2788,7 @@ pub const Value = struct {
27882788 lhs_bigint.limbs.len + rhs_bigint.limbs.len,
27892789 );
27902790 var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
2791 var limbs_buffer = try allocator.alloc(
2791 const limbs_buffer = try allocator.alloc(
27922792 std.math.big.Limb,
27932793 std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1),
27942794 );
src/windows_sdk.zig+9-9
......@@ -69,7 +69,7 @@ fn iterateAndFilterBySemVer(iterator: *std.fs.IterableDir.Iterator, allocator: s
6969 try dirs_filtered_list.append(subfolder_name_allocated);
7070 }
7171
72 var dirs_filtered_slice = try dirs_filtered_list.toOwnedSlice();
72 const dirs_filtered_slice = try dirs_filtered_list.toOwnedSlice();
7373 // Keep in mind that order of these names is not guaranteed by Windows,
7474 // so we cannot just reverse or "while (popOrNull())" this ArrayList.
7575 std.mem.sortUnstable([]const u8, dirs_filtered_slice, {}, struct {
......@@ -129,7 +129,7 @@ const RegistryUtf8 = struct {
129129 const value_utf16le = try registry_utf16le.getString(allocator, subkey_utf16le, value_name_utf16le);
130130 defer allocator.free(value_utf16le);
131131
132 var value_utf8: []u8 = std.unicode.utf16leToUtf8Alloc(allocator, value_utf16le) catch |err| switch (err) {
132 const value_utf8: []u8 = std.unicode.utf16leToUtf8Alloc(allocator, value_utf16le) catch |err| switch (err) {
133133 error.OutOfMemory => return error.OutOfMemory,
134134 else => return error.StringNotFound,
135135 };
......@@ -246,7 +246,7 @@ const RegistryUtf16Le = struct {
246246 else => return error.NotAString,
247247 }
248248
249 var value_utf16le_buf: []u16 = try allocator.alloc(u16, std.math.divCeil(u32, value_utf16le_buf_size, 2) catch unreachable);
249 const value_utf16le_buf: []u16 = try allocator.alloc(u16, std.math.divCeil(u32, value_utf16le_buf_size, 2) catch unreachable);
250250 errdefer allocator.free(value_utf16le_buf);
251251
252252 return_code_int = windows.advapi32.RegGetValueW(
......@@ -354,7 +354,7 @@ pub const Windows10Sdk = struct {
354354 defer v10_key.closeKey();
355355
356356 const path: []const u8 = path10: {
357 var path_maybe_with_trailing_slash = v10_key.getString(allocator, "", "InstallationFolder") catch |err| switch (err) {
357 const path_maybe_with_trailing_slash = v10_key.getString(allocator, "", "InstallationFolder") catch |err| switch (err) {
358358 error.NotAString => return error.Windows10SdkNotFound,
359359 error.ValueNameNotFound => return error.Windows10SdkNotFound,
360360 error.StringNotFound => return error.Windows10SdkNotFound,
......@@ -381,7 +381,7 @@ pub const Windows10Sdk = struct {
381381 const version: []const u8 = version10: {
382382
383383 // note(dimenus): Microsoft doesn't include the .0 in the ProductVersion key....
384 var version_without_0 = v10_key.getString(allocator, "", "ProductVersion") catch |err| switch (err) {
384 const version_without_0 = v10_key.getString(allocator, "", "ProductVersion") catch |err| switch (err) {
385385 error.NotAString => return error.Windows10SdkNotFound,
386386 error.ValueNameNotFound => return error.Windows10SdkNotFound,
387387 error.StringNotFound => return error.Windows10SdkNotFound,
......@@ -445,7 +445,7 @@ pub const Windows81Sdk = struct {
445445 /// After finishing work, call `free(allocator)`.
446446 fn find(allocator: std.mem.Allocator, roots_key: *const RegistryUtf8) error{ OutOfMemory, Windows81SdkNotFound, PathTooLong, VersionTooLong }!Windows81Sdk {
447447 const path: []const u8 = path81: {
448 var path_maybe_with_trailing_slash = roots_key.getString(allocator, "", "KitsRoot81") catch |err| switch (err) {
448 const path_maybe_with_trailing_slash = roots_key.getString(allocator, "", "KitsRoot81") catch |err| switch (err) {
449449 error.NotAString => return error.Windows81SdkNotFound,
450450 error.ValueNameNotFound => return error.Windows81SdkNotFound,
451451 error.StringNotFound => return error.Windows81SdkNotFound,
......@@ -752,7 +752,7 @@ const MsvcLibDir = struct {
752752
753753 const config_subkey = std.fmt.bufPrint(config_subkey_buf[0..], "Software\\Microsoft\\VisualStudio\\{s}_Config", .{vs_version}) catch unreachable;
754754
755 var source_directories_value = visualstudio_registry.getString(allocator, config_subkey, "Source Directories") catch |err| switch (err) {
755 const source_directories_value = visualstudio_registry.getString(allocator, config_subkey, "Source Directories") catch |err| switch (err) {
756756 error.OutOfMemory => return error.OutOfMemory,
757757 else => continue,
758758 };
......@@ -768,7 +768,7 @@ const MsvcLibDir = struct {
768768 var source_directories_splitted = std.mem.splitScalar(u8, source_directories, ';');
769769
770770 const msvc_dir: []const u8 = msvc_dir: {
771 var msvc_include_dir_maybe_with_trailing_slash = try allocator.dupe(u8, source_directories_splitted.first());
771 const msvc_include_dir_maybe_with_trailing_slash = try allocator.dupe(u8, source_directories_splitted.first());
772772
773773 if (msvc_include_dir_maybe_with_trailing_slash.len > std.fs.MAX_PATH_BYTES or !std.fs.path.isAbsolute(msvc_include_dir_maybe_with_trailing_slash)) {
774774 allocator.free(msvc_include_dir_maybe_with_trailing_slash);
......@@ -833,7 +833,7 @@ const MsvcLibDir = struct {
833833 const vs7_key = RegistryUtf8.openKey("SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7") catch return error.PathNotFound;
834834 defer vs7_key.closeKey();
835835 try_vs7_key: {
836 var path_maybe_with_trailing_slash = vs7_key.getString(allocator, "", "14.0") catch |err| switch (err) {
836 const path_maybe_with_trailing_slash = vs7_key.getString(allocator, "", "14.0") catch |err| switch (err) {
837837 error.OutOfMemory => return error.OutOfMemory,
838838 else => break :try_vs7_key,
839839 };
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+12-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
......@@ -577,12 +581,16 @@ test "comptime alloc alignment" {
577581 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
578582 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
579583 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
584 if (builtin.zig_backend == .stage2_llvm and builtin.target.cpu.arch == .x86) {
585 // https://github.com/ziglang/zig/issues/18034
586 return error.SkipZigTest;
587 }
580588
581589 comptime var bytes1 = [_]u8{0};
582 _ = bytes1;
590 _ = &bytes1;
583591
584592 comptime var bytes2 align(256) = [_]u8{0};
585 var bytes2_addr = @intFromPtr(&bytes2);
593 const bytes2_addr = @intFromPtr(&bytes2);
586594 try expect(bytes2_addr & 0xff == 0);
587595}
588596
......@@ -591,6 +599,7 @@ test "@alignCast null" {
591599 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
592600
593601 var ptr: ?*anyopaque = null;
602 _ = &ptr;
594603 const aligned: ?*anyopaque = @alignCast(ptr);
595604 try expect(aligned == null);
596605}
......@@ -637,6 +646,7 @@ test "alignment of zero-bit types is respected" {
637646 var s32: S align(32) = .{};
638647
639648 var zero: usize = 0;
649 _ = &zero;
640650
641651 try expect(@intFromPtr(&s) % @alignOf(usize) == 0);
642652 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+123-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);
......@@ -2446,3 +2522,8 @@ test "@intCast vector of signed integer" {
24462522 try expect(y[2] == 3);
24472523 try expect(y[3] == 4);
24482524}
2525
2526test "result type is preserved into comptime block" {
2527 const x: u32 = comptime @intCast(123);
2528 try expect(x == 123);
2529}
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
test/c_abi/main.zig+32-31
......@@ -278,7 +278,7 @@ test "C ABI big struct" {
278278 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
279279 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
280280
281 var s = BigStruct{
281 const s = BigStruct{
282282 .a = 1,
283283 .b = 2,
284284 .c = 3,
......@@ -304,7 +304,7 @@ extern fn c_big_union(BigUnion) void;
304304test "C ABI big union" {
305305 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
306306
307 var x = BigUnion{
307 const x = BigUnion{
308308 .a = BigStruct{
309309 .a = 1,
310310 .b = 2,
......@@ -339,13 +339,13 @@ test "C ABI medium struct of ints and floats" {
339339 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
340340 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
341341
342 var s = MedStructMixed{
342 const s = MedStructMixed{
343343 .a = 1234,
344344 .b = 100.0,
345345 .c = 1337.0,
346346 };
347347 c_med_struct_mixed(s);
348 var s2 = c_ret_med_struct_mixed();
348 const s2 = c_ret_med_struct_mixed();
349349 try expect(s2.a == 1234);
350350 try expect(s2.b == 100.0);
351351 try expect(s2.c == 1337.0);
......@@ -372,14 +372,14 @@ test "C ABI small struct of ints" {
372372 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
373373 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
374374
375 var s = SmallStructInts{
375 const s = SmallStructInts{
376376 .a = 1,
377377 .b = 2,
378378 .c = 3,
379379 .d = 4,
380380 };
381381 c_small_struct_ints(s);
382 var s2 = c_ret_small_struct_ints();
382 const s2 = c_ret_small_struct_ints();
383383 try expect(s2.a == 1);
384384 try expect(s2.b == 2);
385385 try expect(s2.c == 3);
......@@ -407,13 +407,13 @@ test "C ABI medium struct of ints" {
407407 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
408408 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
409409
410 var s = MedStructInts{
410 const s = MedStructInts{
411411 .x = 1,
412412 .y = 2,
413413 .z = 3,
414414 };
415415 c_med_struct_ints(s);
416 var s2 = c_ret_med_struct_ints();
416 const s2 = c_ret_med_struct_ints();
417417 try expect(s2.x == 1);
418418 try expect(s2.y == 2);
419419 try expect(s2.z == 3);
......@@ -442,9 +442,9 @@ export fn zig_small_packed_struct(x: SmallPackedStruct) void {
442442}
443443
444444test "C ABI small packed struct" {
445 var s = SmallPackedStruct{ .a = 0, .b = 1, .c = 2, .d = 3 };
445 const s = SmallPackedStruct{ .a = 0, .b = 1, .c = 2, .d = 3 };
446446 c_small_packed_struct(s);
447 var s2 = c_ret_small_packed_struct();
447 const s2 = c_ret_small_packed_struct();
448448 try expect(s2.a == 0);
449449 try expect(s2.b == 1);
450450 try expect(s2.c == 2);
......@@ -466,9 +466,9 @@ export fn zig_big_packed_struct(x: BigPackedStruct) void {
466466test "C ABI big packed struct" {
467467 if (!has_i128) return error.SkipZigTest;
468468
469 var s = BigPackedStruct{ .a = 1, .b = 2 };
469 const s = BigPackedStruct{ .a = 1, .b = 2 };
470470 c_big_packed_struct(s);
471 var s2 = c_ret_big_packed_struct();
471 const s2 = c_ret_big_packed_struct();
472472 try expect(s2.a == 1);
473473 try expect(s2.b == 2);
474474}
......@@ -486,7 +486,7 @@ test "C ABI split struct of ints" {
486486 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
487487 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
488488
489 var s = SplitStructInt{
489 const s = SplitStructInt{
490490 .a = 1234,
491491 .b = 100,
492492 .c = 1337,
......@@ -514,13 +514,13 @@ test "C ABI split struct of ints and floats" {
514514 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
515515 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
516516
517 var s = SplitStructMixed{
517 const s = SplitStructMixed{
518518 .a = 1234,
519519 .b = 100,
520520 .c = 1337.0,
521521 };
522522 c_split_struct_mixed(s);
523 var s2 = c_ret_split_struct_mixed();
523 const s2 = c_ret_split_struct_mixed();
524524 try expect(s2.a == 1234);
525525 try expect(s2.b == 100);
526526 try expect(s2.c == 1337.0);
......@@ -541,14 +541,14 @@ test "C ABI sret and byval together" {
541541 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
542542 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
543543
544 var s = BigStruct{
544 const s = BigStruct{
545545 .a = 1,
546546 .b = 2,
547547 .c = 3,
548548 .d = 4,
549549 .e = 5,
550550 };
551 var y = c_big_struct_both(s);
551 const y = c_big_struct_both(s);
552552 try expect(y.a == 10);
553553 try expect(y.b == 11);
554554 try expect(y.c == 12);
......@@ -562,7 +562,7 @@ export fn zig_big_struct_both(x: BigStruct) BigStruct {
562562 expect(x.c == 32) catch @panic("test failure");
563563 expect(x.d == 33) catch @panic("test failure");
564564 expect(x.e == 34) catch @panic("test failure");
565 var s = BigStruct{
565 const s = BigStruct{
566566 .a = 20,
567567 .b = 21,
568568 .c = 22,
......@@ -594,7 +594,7 @@ test "C ABI structs of floats as parameter" {
594594 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
595595 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
596596
597 var v3 = Vector3{
597 const v3 = Vector3{
598598 .x = 3.0,
599599 .y = 6.0,
600600 .z = 12.0,
......@@ -602,7 +602,7 @@ test "C ABI structs of floats as parameter" {
602602 c_small_struct_floats(v3);
603603 c_small_struct_floats_extra(v3, "hello");
604604
605 var v5 = Vector5{
605 const v5 = Vector5{
606606 .x = 76.0,
607607 .y = -1.0,
608608 .z = -12.0,
......@@ -634,13 +634,13 @@ test "C ABI structs of ints as multiple parameters" {
634634 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
635635 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
636636
637 var r1 = Rect{
637 const r1 = Rect{
638638 .left = 1,
639639 .right = 21,
640640 .top = 16,
641641 .bottom = 4,
642642 };
643 var r2 = Rect{
643 const r2 = Rect{
644644 .left = 178,
645645 .right = 189,
646646 .top = 21,
......@@ -671,13 +671,13 @@ test "C ABI structs of floats as multiple parameters" {
671671 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
672672 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
673673
674 var r1 = FloatRect{
674 const r1 = FloatRect{
675675 .left = 1,
676676 .right = 21,
677677 .top = 16,
678678 .bottom = 4,
679679 };
680 var r2 = FloatRect{
680 const r2 = FloatRect{
681681 .left = 178,
682682 .right = 189,
683683 .top = 21,
......@@ -787,7 +787,7 @@ test "Struct with array as padding." {
787787
788788 c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 });
789789
790 var x = c_ret_struct_with_array();
790 const x = c_ret_struct_with_array();
791791 try expect(x.a == 4);
792792 try expect(x.b == 155);
793793}
......@@ -822,7 +822,7 @@ test "Float array like struct" {
822822 },
823823 });
824824
825 var x = c_ret_float_array_struct();
825 const x = c_ret_float_array_struct();
826826 try expect(x.origin.x == 1);
827827 try expect(x.origin.y == 2);
828828 try expect(x.size.width == 3);
......@@ -840,7 +840,7 @@ test "small simd vector" {
840840
841841 c_small_vec(.{ 1, 2 });
842842
843 var x = c_ret_small_vec();
843 const x = c_ret_small_vec();
844844 try expect(x[0] == 3);
845845 try expect(x[1] == 4);
846846}
......@@ -858,7 +858,7 @@ test "medium simd vector" {
858858
859859 c_medium_vec(.{ 1, 2, 3, 4 });
860860
861 var x = c_ret_medium_vec();
861 const x = c_ret_medium_vec();
862862 try expect(x[0] == 5);
863863 try expect(x[1] == 6);
864864 try expect(x[2] == 7);
......@@ -879,7 +879,7 @@ test "big simd vector" {
879879
880880 c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 });
881881
882 var x = c_ret_big_vec();
882 const x = c_ret_big_vec();
883883 try expect(x[0] == 9);
884884 try expect(x[1] == 10);
885885 try expect(x[2] == 11);
......@@ -903,7 +903,7 @@ test "C ABI pointer sized float struct" {
903903
904904 c_ptr_size_float_struct(.{ .x = 1, .y = 2 });
905905
906 var x = c_ret_ptr_size_float_struct();
906 const x = c_ret_ptr_size_float_struct();
907907 try expect(x.x == 3);
908908 try expect(x.y == 4);
909909}
......@@ -1102,6 +1102,7 @@ test "C function that takes byval struct called via function pointer" {
11021102 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
11031103
11041104 var fn_ptr = &c_func_ptr_byval;
1105 _ = &fn_ptr;
11051106 fn_ptr(
11061107 @as(*anyopaque, @ptrFromInt(1)),
11071108 @as(*anyopaque, @ptrFromInt(2)),
......@@ -1224,7 +1225,7 @@ extern fn stdcall_big_union(BigUnion) callconv(stdcall_callconv) void;
12241225test "Stdcall ABI big union" {
12251226 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
12261227
1227 var x = BigUnion{
1228 const x = BigUnion{
12281229 .a = BigStruct{
12291230 .a = 1,
12301231 .b = 2,
test/cases/adding_numbers_at_runtime_and_comptime.2.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var x: usize = 3;
3 _ = &x;
34 const y = add(1, 2, x);
45 if (y - 6 != 0) unreachable;
56}
test/cases/array_in_anon_struct.zig+1
......@@ -2,6 +2,7 @@ const std = @import("std");
22
33noinline fn outer() u32 {
44 var a: u32 = 42;
5 _ = &a;
56 return inner(.{
67 .unused = a,
78 .value = [1]u32{0},
test/cases/assert_function.17.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var i: u64 = 0xFFEEDDCCBBAA9988;
3 _ = &i;
34 assert(i == 0xFFEEDDCCBBAA9988);
45}
56
test/cases/bad_inferred_variable_type.zig+1-1
......@@ -1,6 +1,6 @@
11pub fn main() void {
22 var x = null;
3 _ = x;
3 _ = &x;
44}
55
66// error
test/cases/binary_operands.1.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var i: i32 = 2147483647;
3 _ = &i;
34 if (i +% 1 != -2147483648) unreachable;
45 return;
56}
test/cases/binary_operands.10.zig+1
......@@ -2,6 +2,7 @@ pub fn main() void {
22 var i: u32 = 5;
33 i *= 7;
44 var result: u32 = foo(i, 10);
5 _ = &result;
56 if (result != 350) unreachable;
67 return;
78}
test/cases/binary_operands.11.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var i: i32 = 2147483647;
3 _ = &i;
34 const result = i *% 2;
45 if (result != -2) unreachable;
56 return;
test/cases/binary_operands.12.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var i: u3 = 3;
3 _ = &i;
34 if (i *% 3 != 1) unreachable;
45 return;
56}
test/cases/binary_operands.13.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var i: i4 = 3;
3 _ = &i;
34 if (i *% 3 != -7) unreachable;
45 return;
56}
test/cases/binary_operands.14.zig+1-1
......@@ -1,7 +1,7 @@
11pub fn main() void {
22 var i: u32 = 352;
33 i /= 7; // i = 50
4 var result: u32 = foo(i, 7);
4 const result: u32 = foo(i, 7);
55 if (result != 7) unreachable;
66 return;
77}
test/cases/binary_operands.2.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var i: i4 = 7;
3 _ = &i;
34 if (i +% 1 != -8) unreachable;
45 return;
56}
test/cases/binary_operands.3.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() u8 {
22 var i: u8 = 255;
3 _ = &i;
34 return i +% 1;
45}
56
test/cases/binary_operands.4.zig+1-1
......@@ -1,7 +1,7 @@
11pub fn main() u8 {
22 var i: u8 = 5;
33 i += 20;
4 var result: u8 = foo(i, 10);
4 const result: u8 = foo(i, 10);
55 return result - 35;
66}
77fn foo(x: u8, y: u8) u8 {
test/cases/binary_operands.6.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var i: i32 = -2147483648;
3 _ = &i;
34 if (i -% 1 != 2147483647) unreachable;
45 return;
56}
test/cases/binary_operands.7.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var i: i7 = -64;
3 _ = &i;
34 if (i -% 1 != 63) unreachable;
45 return;
56}
test/cases/binary_operands.8.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var i: u4 = 0;
3 _ = &i;
34 if (i -% 1 != 15) unreachable;
45}
56
test/cases/binary_operands.9.zig+1
......@@ -2,6 +2,7 @@ pub fn main() u8 {
22 var i: u8 = 5;
33 i -= 3;
44 var result: u8 = foo(i, 10);
5 _ = &result;
56 return result - 8;
67}
78fn foo(x: u8, y: u8) u8 {
test/cases/comparison_of_non-tagged_union_and_enum_literal.zig+2-1
......@@ -2,7 +2,8 @@ export fn entry() void {
22 const U = union { A: u32, B: u64 };
33 var u = U{ .A = 42 };
44 var ok = u == .A;
5 _ = ok;
5 _ = &u;
6 _ = &ok;
67}
78
89// error
test/cases/compile_errors/AstGen_comptime_known_struct_is_resolved_before_error.zig+1-1
......@@ -6,7 +6,7 @@ const S2 = struct {
66};
77pub export fn entry() void {
88 var s: S1 = undefined;
9 _ = s;
9 _ = &s;
1010}
1111
1212// error
test/cases/compile_errors/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig+1-1
......@@ -1,7 +1,7 @@
11const Foo = struct { a: u32 };
22export fn a() void {
33 const T = [*c]Foo;
4 var t: T = undefined;
4 const t: T = undefined;
55 _ = t;
66}
77
test/cases/compile_errors/C_pointer_to_anyopaque.zig+1-1
......@@ -1,7 +1,7 @@
11export fn a() void {
22 var x: *anyopaque = undefined;
33 var y: [*c]anyopaque = x;
4 _ = y;
4 _ = .{ &x, &y };
55}
66
77// error
test/cases/compile_errors/accessing_runtime_parameter_from_outer_function.zig+2-2
......@@ -7,8 +7,8 @@ fn outer(y: u32) *const fn (u32) u32 {
77 return st.get;
88}
99export fn entry() void {
10 var func = outer(10);
11 var x = func(3);
10 const func = outer(10);
11 const x = func(3);
1212 _ = x;
1313}
1414
test/cases/compile_errors/add_on_undefined_value.zig+1-1
......@@ -1,5 +1,5 @@
11comptime {
2 var a: i64 = undefined;
2 const a: i64 = undefined;
33 _ = a + a;
44}
55
test/cases/compile_errors/alignment_of_enum_field_specified.zig+1-1
......@@ -6,7 +6,7 @@ const Number = enum {
66// zig fmt: on
77
88export fn entry1() void {
9 var x: Number = undefined;
9 const x: Number = undefined;
1010 _ = x;
1111}
1212
test/cases/compile_errors/ambiguous_coercion_of_division_operands.zig+6-6
......@@ -1,17 +1,17 @@
11export fn entry1() void {
2 var f: f32 = 54.0 / 5;
2 const f: f32 = 54.0 / 5;
33 _ = f;
44}
55export fn entry2() void {
6 var f: f32 = 54 / 5.0;
6 const f: f32 = 54 / 5.0;
77 _ = f;
88}
99export fn entry3() void {
10 var f: f32 = 55.0 / 5;
10 const f: f32 = 55.0 / 5;
1111 _ = f;
1212}
1313export fn entry4() void {
14 var f: f32 = 55 / 5.0;
14 const f: f32 = 55 / 5.0;
1515 _ = f;
1616}
1717
......@@ -19,5 +19,5 @@ export fn entry4() void {
1919// backend=stage2
2020// target=native
2121//
22// :2:23: error: ambiguous coercion of division operands 'comptime_float' and 'comptime_int'; non-zero remainder '4'
23// :6:21: error: ambiguous coercion of division operands 'comptime_int' and 'comptime_float'; non-zero remainder '4'
22// :2:25: error: ambiguous coercion of division operands 'comptime_float' and 'comptime_int'; non-zero remainder '4'
23// :6:23: error: ambiguous coercion of division operands 'comptime_int' and 'comptime_float'; non-zero remainder '4'
test/cases/compile_errors/and_on_undefined_value.zig+2-1
......@@ -1,5 +1,6 @@
11comptime {
22 var a: bool = undefined;
3 _ = &a;
34 _ = a and a;
45}
56
......@@ -7,4 +8,4 @@ comptime {
78// backend=stage2
89// target=native
910//
10// :3:9: error: use of undefined value here causes undefined behavior
11// :4:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/array_access_of_non_array.zig+1-1
......@@ -3,7 +3,7 @@ export fn f() void {
33 bad[0] = bad[0];
44}
55export fn g() void {
6 var bad: bool = undefined;
6 const bad: bool = undefined;
77 _ = bad[0];
88}
99
test/cases/compile_errors/array_access_of_type.zig+1-1
......@@ -1,6 +1,6 @@
11export fn foo() void {
22 var b: u8[40] = undefined;
3 _ = b;
3 _ = &b;
44}
55
66// error
test/cases/compile_errors/array_access_with_non_integer_index.zig+3-1
......@@ -2,11 +2,13 @@ export fn f() void {
22 var array = "aoeu";
33 var bad = false;
44 array[bad] = array[bad];
5 _ = &bad;
56}
67export fn g() void {
78 var array = "aoeu";
89 var bad = false;
910 _ = array[bad];
11 _ = .{ &array, &bad };
1012}
1113
1214// error
......@@ -14,4 +16,4 @@ export fn g() void {
1416// target=native
1517//
1618// :4:11: error: expected type 'usize', found 'bool'
17// :9:15: error: expected type 'usize', found 'bool'
19// :10:15: error: expected type 'usize', found 'bool'
test/cases/compile_errors/array_init_invalid_elem_count.zig+6-6
......@@ -2,27 +2,27 @@ const V = @Vector(8, u8);
22const A = [8]u8;
33comptime {
44 var v: V = V{1};
5 _ = v;
5 _ = &v;
66}
77comptime {
88 var v: V = V{};
9 _ = v;
9 _ = &v;
1010}
1111comptime {
1212 var a: A = A{1};
13 _ = a;
13 _ = &a;
1414}
1515comptime {
1616 var a: A = A{};
17 _ = a;
17 _ = &a;
1818}
1919pub export fn entry1() void {
2020 var bla: V = .{ 1, 2, 3, 4 };
21 _ = bla;
21 _ = &bla;
2222}
2323pub export fn entry2() void {
2424 var bla: A = .{ 1, 2, 3, 4 };
25 _ = bla;
25 _ = &bla;
2626}
2727const S = struct {
2828 list: [2]u8 = .{0},
test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig+1-1
......@@ -1,6 +1,6 @@
11export fn entry() void {
22 var a = &b;
3 _ = a;
3 _ = &a;
44}
55inline fn b() void {}
66
test/cases/compile_errors/assign_local_bad_coercion.zig+1-1
......@@ -9,7 +9,7 @@ export fn constEntry() u32 {
99
1010export fn varEntry() u32 {
1111 var x: u32 = g();
12 return x;
12 return (&x).*;
1313}
1414
1515// error
test/cases/compile_errors/assign_too_big_number_to_u16.zig+2-2
......@@ -1,5 +1,5 @@
11export fn foo() void {
2 var vga_mem: u16 = 0xB8000;
2 const vga_mem: u16 = 0xB8000;
33 _ = vga_mem;
44}
55
......@@ -7,4 +7,4 @@ export fn foo() void {
77// backend=stage2
88// target=native
99//
10// :2:24: error: type 'u16' cannot represent integer value '753664'
10// :2:26: error: type 'u16' cannot represent integer value '753664'
test/cases/compile_errors/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig+2-2
......@@ -10,8 +10,8 @@ const S = struct {
1010export fn entry() void {
1111 var u = U{ .Ye = maybe(false) };
1212 var s = S{ .num = maybe(false) };
13 _ = u;
14 _ = s;
13 _ = &u;
14 _ = &s;
1515}
1616
1717// error
test/cases/compile_errors/async/Frame_of_generic_function.zig+2-2
......@@ -1,10 +1,10 @@
11export fn entry() void {
22 var frame: @Frame(func) = undefined;
3 _ = frame;
3 _ = &frame;
44}
55fn func(comptime T: type) void {
66 var x: T = undefined;
7 _ = x;
7 _ = &x;
88}
99
1010// error
test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig+1-1
......@@ -3,7 +3,7 @@ export fn entry() void {
33}
44fn amain() callconv(.Async) void {
55 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
6 _ = x;
6 _ = &x;
77}
88
99// error
test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig+1-1
......@@ -6,7 +6,7 @@ fn amain() callconv(.Async) void {
66}
77fn other() void {
88 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
9 _ = x;
9 _ = &x;
1010}
1111
1212// error
test/cases/compile_errors/async/bad_alignment_in_asynccall.zig+1
......@@ -2,6 +2,7 @@ export fn entry() void {
22 var ptr: fn () callconv(.Async) void = func;
33 var bytes: [64]u8 = undefined;
44 _ = @asyncCall(&bytes, {}, ptr, .{});
5 _ = &ptr;
56}
67fn func() callconv(.Async) void {}
78
test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig+1-1
......@@ -5,7 +5,7 @@ export fn a() void {
55export fn b() void {
66 const f = async func();
77 var x: anyframe = &f;
8 _ = x;
8 _ = &x;
99}
1010fn func() void {
1111 suspend {}
test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig+4-4
......@@ -12,7 +12,7 @@ fn rangeSum(x: i32) i32 {
1212 frame = null;
1313
1414 if (x == 0) return 0;
15 var child = rangeSumIndirect(x - 1);
15 const child = rangeSumIndirect(x - 1);
1616 return child + 1;
1717}
1818
......@@ -23,7 +23,7 @@ fn rangeSumIndirect(x: i32) i32 {
2323 frame = null;
2424
2525 if (x == 0) return 0;
26 var child = rangeSum(x - 1);
26 const child = rangeSum(x - 1);
2727 return child + 1;
2828}
2929
......@@ -32,5 +32,5 @@ fn rangeSumIndirect(x: i32) i32 {
3232// target=native
3333//
3434// tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself
35// tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here
36// tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here
35// tmp.zig:15:35: note: when analyzing type '@Frame(rangeSum)' here
36// tmp.zig:28:25: note: when analyzing type '@Frame(rangeSumIndirect)' here
test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig+1-1
......@@ -1,7 +1,7 @@
11export fn entry() void {
22 var frame = async func();
33 var result = await frame;
4 _ = result;
4 _ = &result;
55}
66fn func() void {
77 suspend {}
test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig+1
......@@ -2,6 +2,7 @@ export fn entry() void {
22 var ptr = afunc;
33 var bytes: [100]u8 align(16) = undefined;
44 _ = @asyncCall(&bytes, {}, ptr, .{});
5 _ = &ptr;
56}
67fn afunc() void {}
78
test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig+3-3
......@@ -1,17 +1,17 @@
11export fn a() void {
22 var x: anyframe = undefined;
33 var y: anyframe->i32 = x;
4 _ = y;
4 _ = .{ &x, &y };
55}
66export fn b() void {
77 var x: i32 = undefined;
88 var y: anyframe->i32 = x;
9 _ = y;
9 _ = .{ &x, &y };
1010}
1111export fn c() void {
1212 var x: @Frame(func) = undefined;
1313 var y: anyframe->i32 = &x;
14 _ = y;
14 _ = .{ &x, &y };
1515}
1616fn func() void {}
1717
test/cases/compile_errors/async/runtime-known_async_function_called.zig+1
......@@ -4,6 +4,7 @@ export fn entry() void {
44fn amain() void {
55 var ptr = afunc;
66 _ = ptr();
7 _ = &ptr;
78}
89fn afunc() callconv(.Async) void {}
910
test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig+1
......@@ -1,6 +1,7 @@
11export fn entry() void {
22 var ptr = afunc;
33 _ = async ptr();
4 _ = &ptr;
45}
56
67fn afunc() callconv(.Async) void {}
test/cases/compile_errors/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig+2-2
......@@ -1,9 +1,9 @@
1export fn entry(byte: u8) void {
1export fn entry() void {
22 const w: i32 = 1234;
33 var x: *const i32 = &w;
44 var y: *[1]i32 = x;
55 y[0] += 1;
6 _ = byte;
6 _ = &x;
77}
88
99// error
test/cases/compile_errors/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig+3-3
......@@ -1,6 +1,6 @@
11export fn a() void {
22 var x: [10]u8 = undefined;
3 var y: []align(16) u8 = &x;
3 const y: []align(16) u8 = &x;
44 _ = y;
55}
66
......@@ -8,5 +8,5 @@ export fn a() void {
88// backend=stage2
99// target=native
1010//
11// :3:29: error: expected type '[]align(16) u8', found '*[10]u8'
12// :3:29: note: pointer alignment '1' cannot cast into pointer alignment '16'
11// :3:31: error: expected type '[]align(16) u8', found '*[10]u8'
12// :3:31: note: pointer alignment '1' cannot cast into pointer alignment '16'
test/cases/compile_errors/bad_alignment_type.zig+4-4
......@@ -1,9 +1,9 @@
11export fn entry1() void {
2 var x: []align(true) i32 = undefined;
2 const x: []align(true) i32 = undefined;
33 _ = x;
44}
55export fn entry2() void {
6 var x: *align(@as(f64, 12.34)) i32 = undefined;
6 const x: *align(@as(f64, 12.34)) i32 = undefined;
77 _ = x;
88}
99
......@@ -11,5 +11,5 @@ export fn entry2() void {
1111// backend=stage2
1212// target=native
1313//
14// :2:20: error: expected type 'u32', found 'bool'
15// :6:19: error: fractional component prevents float value '12.34' from coercion to type 'u32'
14// :2:22: error: expected type 'u32', found 'bool'
15// :6:21: error: fractional component prevents float value '12.34' from coercion to type 'u32'
test/cases/compile_errors/bad_usage_of_call.zig+3-2
......@@ -11,7 +11,7 @@ export fn entry4() void {
1111 @call(.never_inline, bar, .{});
1212}
1313export fn entry5(c: bool) void {
14 var baz = if (c) &baz1 else &baz2;
14 const baz = if (c) &baz1 else &baz2;
1515 @call(.compile_time, baz, .{});
1616}
1717export fn entry6() void {
......@@ -22,6 +22,7 @@ export fn entry7() void {
2222}
2323pub export fn entry() void {
2424 var call_me: *const fn () void = undefined;
25 _ = &call_me;
2526 @call(.always_inline, call_me, .{});
2627}
2728
......@@ -45,4 +46,4 @@ noinline fn dummy2() void {}
4546// :15:26: error: modifier 'compile_time' requires a comptime-known function
4647// :18:9: error: 'always_inline' call of noinline function
4748// :21:9: error: 'always_inline' call of noinline function
48// :25:27: error: modifier 'always_inline' requires a comptime-known function
49// :26:27: error: modifier 'always_inline' requires a comptime-known function
test/cases/compile_errors/binary_OR_operator_on_error_sets.zig+1-1
......@@ -1,7 +1,7 @@
11pub const A = error.A;
22pub const AB = A | error.B;
33export fn entry() void {
4 var x: AB = undefined;
4 const x: AB = undefined;
55 _ = x;
66}
77
test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig+2-2
......@@ -1,5 +1,5 @@
11export fn entry(byte: u8) void {
2 var oops: u7 = @bitCast(byte);
2 const oops: u7 = @bitCast(byte);
33 _ = oops;
44}
55
......@@ -7,4 +7,4 @@ export fn entry(byte: u8) void {
77// backend=stage2
88// target=native
99//
10// :2:20: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits
10// :2:22: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits
test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig+3-2
......@@ -1,5 +1,6 @@
11export fn entry() void {
2 var foo = (@as(u8, @bitCast(@as(f32, 1.0))) == 0xf);
2 const f: f32 = 1.0;
3 const foo = (@as(u8, @bitCast(f)) == 0xf);
34 _ = foo;
45}
56
......@@ -7,4 +8,4 @@ export fn entry() void {
78// backend=stage2
89// target=native
910//
10// :2:24: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits
11// :3:26: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits
test/cases/compile_errors/branch_in_comptime_only_scope_uses_condbr_inline.zig+5-3
......@@ -1,5 +1,6 @@
11pub export fn entry1() void {
22 var x: u32 = 3;
3 _ = &x;
34 _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{
45 if (x > 1) 1 else -1,
56 });
......@@ -7,6 +8,7 @@ pub export fn entry1() void {
78
89pub export fn entry2() void {
910 var y: ?i8 = -1;
11 _ = &y;
1012 _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{
1113 y orelse 1,
1214 });
......@@ -16,6 +18,6 @@ pub export fn entry2() void {
1618// backend=stage2
1719// target=native
1820//
19// :4:15: error: unable to evaluate comptime expression
20// :4:13: note: operation is runtime due to this operand
21// :11:11: error: unable to evaluate comptime expression
21// :5:15: error: unable to evaluate comptime expression
22// :5:13: note: operation is runtime due to this operand
23// :13:11: error: unable to evaluate comptime expression
test/cases/compile_errors/break_void_result_location.zig+3-2
......@@ -10,6 +10,7 @@ export fn f2() void {
1010}
1111export fn f3() void {
1212 var t: bool = true;
13 _ = &t;
1314 const x: usize = while (t) {
1415 break;
1516 };
......@@ -28,5 +29,5 @@ export fn f4() void {
2829//
2930// :2:22: error: expected type 'usize', found 'void'
3031// :7:9: error: expected type 'usize', found 'void'
31// :14:9: error: expected type 'usize', found 'void'
32// :20:9: error: expected type 'usize', found 'void'
32// :15:9: error: expected type 'usize', found 'void'
33// :21:9: error: expected type 'usize', found 'void'
test/cases/compile_errors/c_pointer_to_void.zig+3-3
......@@ -1,5 +1,5 @@
11export fn entry() void {
2 var a: [*c]void = undefined;
2 const a: [*c]void = undefined;
33 _ = a;
44}
55
......@@ -7,5 +7,5 @@ export fn entry() void {
77// backend=stage2
88// target=native
99//
10// :2:16: error: C pointers cannot point to non-C-ABI-compatible type 'void'
11// :2:16: note: 'void' is a zero bit type; for C 'void' use 'anyopaque'
10// :2:18: error: C pointers cannot point to non-C-ABI-compatible type 'void'
11// :2:18: note: 'void' is a zero bit type; for C 'void' use 'anyopaque'
test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig+3-3
......@@ -2,15 +2,15 @@ const F1 = fn () callconv(.Stdcall) void;
22const F2 = fn () callconv(.Fastcall) void;
33const F3 = fn () callconv(.Thiscall) void;
44export fn entry1() void {
5 var a: F1 = undefined;
5 const a: F1 = undefined;
66 _ = a;
77}
88export fn entry2() void {
9 var a: F2 = undefined;
9 const a: F2 = undefined;
1010 _ = a;
1111}
1212export fn entry3() void {
13 var a: F3 = undefined;
13 const a: F3 = undefined;
1414 _ = a;
1515}
1616
test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig+5-3
......@@ -4,6 +4,7 @@ export fn entry1() void {
44 var a: fnty1 = undefined;
55 var b: fnty2 = undefined;
66 a = b;
7 _ = &b;
78}
89
910pub const fnty3 = ?*const fn (u63) void;
......@@ -11,6 +12,7 @@ export fn entry2() void {
1112 var a: fnty3 = undefined;
1213 var b: fnty2 = undefined;
1314 a = b;
15 _ = &b;
1416}
1517
1618// error
......@@ -21,6 +23,6 @@ export fn entry2() void {
2123// :6:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (i8) void'
2224// :6:9: note: parameter 0 'u64' cannot cast into 'i8'
2325// :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values
24// :13:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void'
25// :13:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void'
26// :13:9: note: parameter 0 'u64' cannot cast into 'u63'
26// :14:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void'
27// :14:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void'
28// :14:9: note: parameter 0 'u64' cannot cast into 'u63'
test/cases/compile_errors/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig+3-3
......@@ -1,6 +1,6 @@
11const SmallErrorSet = error{A};
22export fn entry() void {
3 var x: SmallErrorSet!i32 = foo();
3 const x: SmallErrorSet!i32 = foo();
44 _ = x;
55}
66fn foo() anyerror!i32 {
......@@ -11,5 +11,5 @@ fn foo() anyerror!i32 {
1111// backend=stage2
1212// target=native
1313//
14// :3:35: error: expected type 'error{A}!i32', found 'anyerror!i32'
15// :3:35: note: global error set cannot cast into a smaller set
14// :3:37: error: expected type 'error{A}!i32', found 'anyerror!i32'
15// :3:37: note: global error set cannot cast into a smaller set
test/cases/compile_errors/cast_global_error_set_to_error_set.zig+3-3
......@@ -1,6 +1,6 @@
11const SmallErrorSet = error{A};
22export fn entry() void {
3 var x: SmallErrorSet = foo();
3 const x: SmallErrorSet = foo();
44 _ = x;
55}
66fn foo() anyerror {
......@@ -11,5 +11,5 @@ fn foo() anyerror {
1111// backend=stage2
1212// target=native
1313//
14// :3:31: error: expected type 'error{A}', found 'anyerror'
15// :3:31: note: global error set cannot cast into a smaller set
14// :3:33: error: expected type 'error{A}', found 'anyerror'
15// :3:33: note: global error set cannot cast into a smaller set
test/cases/compile_errors/catch_on_undefined_value.zig+1-1
......@@ -1,5 +1,5 @@
11comptime {
2 var a: anyerror!bool = undefined;
2 const a: anyerror!bool = undefined;
33 if (a catch false) {}
44}
55
test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig+2-2
......@@ -1,6 +1,6 @@
11export fn entry() void {
2 var x: ?[3]i32 = undefined;
3 var y: [3]i32 = undefined;
2 const x: ?[3]i32 = undefined;
3 const y: [3]i32 = undefined;
44 _ = (x == y);
55}
66
test/cases/compile_errors/comparison_operators_with_undefined_value.zig+6-6
......@@ -1,36 +1,36 @@
11// operator ==
22comptime {
3 var a: i64 = undefined;
3 const a: i64 = undefined;
44 var x: i32 = 0;
55 if (a == a) x += 1;
66}
77// operator !=
88comptime {
9 var a: i64 = undefined;
9 const a: i64 = undefined;
1010 var x: i32 = 0;
1111 if (a != a) x += 1;
1212}
1313// operator >
1414comptime {
15 var a: i64 = undefined;
15 const a: i64 = undefined;
1616 var x: i32 = 0;
1717 if (a > a) x += 1;
1818}
1919// operator <
2020comptime {
21 var a: i64 = undefined;
21 const a: i64 = undefined;
2222 var x: i32 = 0;
2323 if (a < a) x += 1;
2424}
2525// operator >=
2626comptime {
27 var a: i64 = undefined;
27 const a: i64 = undefined;
2828 var x: i32 = 0;
2929 if (a >= a) x += 1;
3030}
3131// operator <=
3232comptime {
33 var a: i64 = undefined;
33 const a: i64 = undefined;
3434 var x: i32 = 0;
3535 if (a <= a) x += 1;
3636}
test/cases/compile_errors/compile_error_in_struct_init_expression.zig+1-1
......@@ -3,7 +3,7 @@ const Foo = struct {
33 b: i32,
44};
55export fn entry() void {
6 var x = Foo{
6 const x: Foo = .{
77 .b = 5,
88 };
99 _ = x;
test/cases/compile_errors/compile_time_null_ptr_cast.zig+1-1
......@@ -1,5 +1,5 @@
11comptime {
2 var opt_ptr: ?*i32 = null;
2 const opt_ptr: ?*i32 = null;
33 const ptr: *i32 = @ptrCast(opt_ptr);
44 _ = ptr;
55}
test/cases/compile_errors/compile_time_undef_ptr_cast.zig+1
......@@ -1,6 +1,7 @@
11comptime {
22 var undef_ptr: *i32 = undefined;
33 const ptr: *i32 = @ptrCast(undef_ptr);
4 _ = &undef_ptr;
45 _ = ptr;
56}
67
test/cases/compile_errors/comptime_cast_enum_to_union_but_field_has_payload.zig+1-1
......@@ -6,7 +6,7 @@ const Value = union(Letter) {
66};
77export fn entry() void {
88 var x: Value = Letter.A;
9 _ = x;
9 _ = &x;
1010}
1111
1212// error
test/cases/compile_errors/comptime_continue_inside_runtime_if_bool.zig+3-2
......@@ -1,5 +1,6 @@
11export fn entry() void {
22 var p: usize = undefined;
3 _ = &p;
34 comptime var q = true;
45 inline while (q) {
56 if (p == 11) continue;
......@@ -11,5 +12,5 @@ export fn entry() void {
1112// backend=stage2
1213// target=native
1314//
14// :5:22: error: comptime control flow inside runtime block
15// :5:15: note: runtime control flow here
15// :6:22: error: comptime control flow inside runtime block
16// :6:15: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_if_error.zig+3-2
......@@ -1,5 +1,6 @@
11export fn entry() void {
22 var p: anyerror!i32 = undefined;
3 _ = &p;
34 comptime var q = true;
45 inline while (q) {
56 if (p) |_| continue else |_| {}
......@@ -11,5 +12,5 @@ export fn entry() void {
1112// backend=stage2
1213// target=native
1314//
14// :5:20: error: comptime control flow inside runtime block
15// :5:13: note: runtime control flow here
15// :6:20: error: comptime control flow inside runtime block
16// :6:13: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_if_optional.zig+3-2
......@@ -1,5 +1,6 @@
11export fn entry() void {
22 var p: ?i32 = undefined;
3 _ = &p;
34 comptime var q = true;
45 inline while (q) {
56 if (p) |_| continue;
......@@ -11,5 +12,5 @@ export fn entry() void {
1112// backend=stage2
1213// target=native
1314//
14// :5:20: error: comptime control flow inside runtime block
15// :5:13: note: runtime control flow here
15// :6:20: error: comptime control flow inside runtime block
16// :6:13: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_switch.zig+3-2
......@@ -1,5 +1,6 @@
11export fn entry() void {
22 var p: i32 = undefined;
3 _ = &p;
34 comptime var q = true;
45 inline while (q) {
56 switch (p) {
......@@ -14,5 +15,5 @@ export fn entry() void {
1415// backend=stage2
1516// target=native
1617//
17// :6:19: error: comptime control flow inside runtime block
18// :5:17: note: runtime control flow here
18// :7:19: error: comptime control flow inside runtime block
19// :6:17: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_while_bool.zig+3-2
......@@ -1,5 +1,6 @@
11export fn entry() void {
22 var p: usize = undefined;
3 _ = &p;
34 comptime var q = true;
45 outer: inline while (q) {
56 while (p == 11) continue :outer;
......@@ -11,5 +12,5 @@ export fn entry() void {
1112// backend=stage2
1213// target=native
1314//
14// :5:25: error: comptime control flow inside runtime block
15// :5:18: note: runtime control flow here
15// :6:25: error: comptime control flow inside runtime block
16// :6:18: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_while_error.zig+3-2
......@@ -1,5 +1,6 @@
11export fn entry() void {
22 var p: anyerror!usize = undefined;
3 _ = &p;
34 comptime var q = true;
45 outer: inline while (q) {
56 while (p) |_| {
......@@ -13,5 +14,5 @@ export fn entry() void {
1314// backend=stage2
1415// target=native
1516//
16// :6:13: error: comptime control flow inside runtime block
17// :5:16: note: runtime control flow here
17// :7:13: error: comptime control flow inside runtime block
18// :6:16: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_while_optional.zig+3-2
......@@ -1,5 +1,6 @@
11export fn entry() void {
22 var p: ?usize = undefined;
3 _ = &p;
34 comptime var q = true;
45 outer: inline while (q) {
56 while (p) |_| continue :outer;
......@@ -11,5 +12,5 @@ export fn entry() void {
1112// backend=stage2
1213// target=native
1314//
14// :5:23: error: comptime control flow inside runtime block
15// :5:16: note: runtime control flow here
15// :6:23: error: comptime control flow inside runtime block
16// :6:16: note: runtime control flow here
test/cases/compile_errors/comptime_continue_to_outer_inline_loop.zig+3-2
......@@ -1,5 +1,6 @@
11pub export fn entry() void {
22 var a = false;
3 _ = &a;
34 const arr1 = .{ 1, 2, 3 };
45 loop: inline for (arr1) |val1| {
56 _ = val1;
......@@ -17,5 +18,5 @@ pub export fn entry() void {
1718// backend=stage2
1819// target=native
1920//
20// :9:30: error: comptime control flow inside runtime block
21// :6:13: note: runtime control flow here
21// :10:30: error: comptime control flow inside runtime block
22// :7:13: note: runtime control flow here
test/cases/compile_errors/comptime_if_inside_runtime_for.zig+4-3
......@@ -1,8 +1,9 @@
11export fn entry() void {
22 var x: u32 = 0;
3 _ = &x;
34 for (0..1, 1..2) |_, _| {
45 var y = x + if (x == 0) 1 else 0;
5 _ = y;
6 _ = &y;
67 }
78}
89
......@@ -10,5 +11,5 @@ export fn entry() void {
1011// backend=stage2
1112// target=native
1213//
13// :4:21: error: value with comptime-only type 'comptime_int' depends on runtime control flow
14// :3:10: note: runtime control flow here
14// :5:21: error: value with comptime-only type 'comptime_int' depends on runtime control flow
15// :4:10: note: runtime control flow here
test/cases/compile_errors/comptime_slice_of_an_undefined_slice.zig+1-1
......@@ -1,7 +1,7 @@
11comptime {
22 var a: []u8 = undefined;
33 var b = a[0..10];
4 _ = b;
4 _ = &b;
55}
66
77// error
test/cases/compile_errors/comptime_struct_field_no_init_value.zig+1-1
......@@ -3,7 +3,7 @@ const Foo = struct {
33};
44export fn entry() void {
55 var f: Foo = undefined;
6 _ = f;
6 _ = &f;
77}
88
99// error
test/cases/compile_errors/comptime_vector_overflow_shows_the_index.zig+1-1
......@@ -2,7 +2,7 @@ comptime {
22 var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };
33 var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };
44 var x = a + b;
5 _ = x;
5 _ = .{ &a, &b, &x };
66}
77
88// error
test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig+2-4
......@@ -1,9 +1,7 @@
11const ContextAllocator = MemoryPool(usize);
22
33pub fn MemoryPool(comptime T: type) type {
4 const free_list_t = @compileError(
5 "aoeu",
6 );
4 const free_list_t = @compileError("aoeu");
75 _ = T;
86
97 return struct {
......@@ -12,7 +10,7 @@ pub fn MemoryPool(comptime T: type) type {
1210}
1311
1412export fn entry() void {
15 var allocator: ContextAllocator = undefined;
13 const allocator: ContextAllocator = undefined;
1614 _ = allocator;
1715}
1816
test/cases/compile_errors/deref_on_undefined_value.zig+1-1
......@@ -1,5 +1,5 @@
11comptime {
2 var a: *u8 = undefined;
2 const a: *u8 = undefined;
33 _ = a.*;
44}
55
test/cases/compile_errors/deref_slice_and_get_len_field.zig+1
......@@ -1,6 +1,7 @@
11export fn entry() void {
22 var a: []u8 = undefined;
33 _ = a.*.len;
4 _ = &a;
45}
56
67// error
test/cases/compile_errors/dereference_an_array.zig+2-1
......@@ -1,6 +1,7 @@
11var s_buffer: [10]u8 = undefined;
22pub fn pass(in: []u8) []u8 {
33 var out = &s_buffer;
4 _ = &out;
45 out.*.* = in[0];
56 return out.*[0..1];
67}
......@@ -13,4 +14,4 @@ export fn entry() usize {
1314// backend=stage2
1415// target=native
1516//
16// :4:10: error: cannot dereference non-pointer type '[10]u8'
17// :5:10: error: cannot dereference non-pointer type '[10]u8'
test/cases/compile_errors/dereferencing_invalid_payload_ptr_at_comptime.zig+1-1
......@@ -16,7 +16,7 @@ comptime {
1616 _ = payload_ptr.*;
1717}
1818comptime {
19 var val: u8 = 15;
19 const val: u8 = 15;
2020 var err_union: anyerror!u8 = val;
2121
2222 const payload_ptr = &(err_union catch unreachable);
test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig+2-2
......@@ -8,11 +8,11 @@ const Bar = union {
88};
99export fn a() void {
1010 var foo: Foo = undefined;
11 _ = foo;
11 _ = &foo;
1212}
1313export fn b() void {
1414 var bar: Bar = undefined;
15 _ = bar;
15 _ = &bar;
1616}
1717export fn c() void {
1818 const baz = &@as(O, undefined);
test/cases/compile_errors/div_on_undefined_value.zig+1
......@@ -1,6 +1,7 @@
11comptime {
22 var a: i64 = undefined;
33 _ = a / a;
4 _ = &a;
45}
56
67// error
test/cases/compile_errors/double_pointer_to_anyopaque_pointer.zig+4-3
......@@ -11,12 +11,13 @@ pub export fn entry2() void {
1111fn func(_: ?*anyopaque) void {}
1212pub export fn entry3() void {
1313 var x: *?*usize = undefined;
14
14 _ = &x;
1515 const ptr: *const anyopaque = x;
1616 _ = ptr;
1717}
1818export fn entry4() void {
1919 var a: []*u32 = undefined;
20 _ = &a;
2021 var b: []anyopaque = undefined;
2122 b = a;
2223}
......@@ -32,5 +33,5 @@ export fn entry4() void {
3233// :11:12: note: parameter type declared here
3334// :15:35: error: expected type '*const anyopaque', found '*?*usize'
3435// :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque'
35// :21:9: error: expected type '[]anyopaque', found '[]*u32'
36// :21:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque'
36// :22:9: error: expected type '[]anyopaque', found '[]*u32'
37// :22:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque'
test/cases/compile_errors/empty_switch_on_an_integer.zig+1-1
......@@ -1,5 +1,5 @@
11export fn entry() void {
2 var x: u32 = 0;
2 const x: u32 = 0;
33 switch (x) {}
44}
55
test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig+1-1
......@@ -1,7 +1,7 @@
11pub export fn entry() void {
22 const E = enum(comptime_int) { a, b, c, _ };
33 var e: E = .a;
4 _ = e;
4 _ = &e;
55}
66
77// error
test/cases/compile_errors/enum_field_value_references_enum.zig+1-1
......@@ -3,7 +3,7 @@ pub const Foo = enum(c_int) {
33 C = D,
44};
55export fn entry() void {
6 var s: Foo = Foo.E;
6 const s: Foo = Foo.E;
77 _ = s;
88}
99const D = 1;
test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig+2-2
......@@ -3,7 +3,7 @@ const Foo = enum(u32) {
33 B = 11,
44};
55export fn entry() void {
6 var x: Foo = @enumFromInt(0);
6 const x: Foo = @enumFromInt(0);
77 _ = x;
88}
99
......@@ -11,5 +11,5 @@ export fn entry() void {
1111// backend=stage2
1212// target=native
1313//
14// :6:18: error: enum 'tmp.Foo' has no tag with value '0'
14// :6:20: error: enum 'tmp.Foo' has no tag with value '0'
1515// :1:13: note: enum declared here
test/cases/compile_errors/enum_value_already_taken.zig+1-1
......@@ -6,7 +6,7 @@ const MultipleChoice = enum(u32) {
66 E = 60,
77};
88export fn entry() void {
9 var x = MultipleChoice.C;
9 const x = MultipleChoice.C;
1010 _ = x;
1111}
1212
test/cases/compile_errors/error_in_struct_initializer_doesnt_crash_the_compiler.zig+1-1
......@@ -4,7 +4,7 @@ pub export fn entry() void {
44 e: u8,
55 };
66 var a = .{@sizeOf(bitfield)};
7 _ = a;
7 _ = &a;
88}
99
1010// error
test/cases/compile_errors/error_union_operator_with_non_error_set_LHS.zig+1-1
......@@ -1,6 +1,6 @@
11comptime {
22 const z = i32!i32;
3 var x: z = undefined;
3 const x: z = undefined;
44 _ = x;
55}
66
test/cases/compile_errors/error_when_evaluating_return_type.zig+1-1
......@@ -6,7 +6,7 @@ const Foo = struct {
66 }
77};
88export fn entry() void {
9 var rule_set = try Foo.init();
9 const rule_set = try Foo.init();
1010 _ = rule_set;
1111}
1212
test/cases/compile_errors/explain_why_generic_fn_is_called_at_comptime.zig+3-2
......@@ -11,12 +11,13 @@ fn foo(a: u8, comptime PtrTy: type) S(PtrTy) {
1111}
1212pub export fn entry() void {
1313 var a: u8 = 1;
14 _ = &a;
1415 _ = foo(a, fn () void);
1516}
1617// error
1718// backend=stage2
1819// target=native
1920//
20// :14:13: error: unable to resolve comptime value
21// :14:13: note: argument to function being called at comptime must be comptime-known
21// :15:13: error: unable to resolve comptime value
22// :15:13: note: argument to function being called at comptime must be comptime-known
2223// :9:38: note: expression is evaluated at comptime because the generic function was instantiated with a comptime-only return type
test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig+3-3
......@@ -1,8 +1,8 @@
11const Set1 = error{ A, B };
22const Set2 = error{ A, C };
33comptime {
4 var x = Set1.B;
5 var y: Set2 = @errorCast(x);
4 const x = Set1.B;
5 const y: Set2 = @errorCast(x);
66 _ = y;
77}
88
......@@ -10,4 +10,4 @@ comptime {
1010// backend=stage2
1111// target=native
1212//
13// :5:19: error: 'error.B' not a member of error set 'error{C,A}'
13// :5:21: error: 'error.B' not a member of error set 'error{C,A}'
test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig+2-2
......@@ -7,7 +7,7 @@ const Small = enum(u2) {
77
88export fn entry() void {
99 var y = @as(f32, 3);
10 var x: Small = @enumFromInt(y);
10 const x: Small = @enumFromInt((&y).*);
1111 _ = x;
1212}
1313
......@@ -15,4 +15,4 @@ export fn entry() void {
1515// backend=stage2
1616// target=native
1717//
18// :10:33: error: expected integer type, found 'f32'
18// :10:39: error: expected integer type, found 'f32'
test/cases/compile_errors/extern_union_field_missing_type.zig+1-1
......@@ -2,7 +2,7 @@ const Letter = extern union {
22 A,
33};
44export fn entry() void {
5 var a = Letter{ .A = {} };
5 const a: Letter = .{ .A = {} };
66 _ = a;
77}
88
test/cases/compile_errors/extern_union_given_enum_tag_type.zig+1-1
......@@ -9,7 +9,7 @@ const Payload = extern union(Letter) {
99 C: bool,
1010};
1111export fn entry() void {
12 var a = Payload{ .A = 1234 };
12 const a: Payload = .{ .A = 1234 };
1313 _ = a;
1414}
1515
test/cases/compile_errors/field_access_of_slices.zig+3-2
......@@ -1,5 +1,6 @@
11export fn entry() void {
22 var slice: []i32 = undefined;
3 _ = &slice;
34 const info = @TypeOf(slice).unknown;
45 _ = info;
56}
......@@ -8,5 +9,5 @@ export fn entry() void {
89// backend=stage2
910// target=native
1011//
11// :3:32: error: type '[]i32' has no members
12// :3:32: note: slice values have 'len' and 'ptr' members
12// :4:32: error: type '[]i32' has no members
13// :4:32: note: slice values have 'len' and 'ptr' members
test/cases/compile_errors/for.zig+4-3
......@@ -17,6 +17,7 @@ export fn c() void {
1717 for (buf) |*byte| {
1818 _ = byte;
1919 }
20 _ = &buf;
2021}
2122export fn d() void {
2223 const x: [*]const u8 = "hello";
......@@ -39,6 +40,6 @@ export fn d() void {
3940// :10:14: note: for loop operand must be a range, array, slice, tuple, or vector
4041// :17:16: error: pointer capture of non pointer type '[10]u8'
4142// :17:10: note: consider using '&' here
42// :24:5: error: unbounded for loop
43// :24:10: note: type '[*]const u8' has no upper bound
44// :24:18: note: type '[*]const u8' has no upper bound
43// :25:5: error: unbounded for loop
44// :25:10: note: type '[*]const u8' has no upper bound
45// :25:18: note: type '[*]const u8' has no upper bound
test/cases/compile_errors/for_loop_body_expression_ignored.zig+1-1
......@@ -7,7 +7,7 @@ export fn f1() void {
77export fn f2() void {
88 var x: anyerror!i32 = error.Bad;
99 for ("hello") |_| returns() else unreachable;
10 _ = x;
10 _ = &x;
1111}
1212export fn f3() void {
1313 for ("hello") |_| {} else true;
test/cases/compile_errors/function_ptr_alignment.zig+5-5
......@@ -1,24 +1,24 @@
11comptime {
22 var a: *align(2) @TypeOf(foo) = undefined;
3 _ = a;
3 _ = &a;
44}
55fn foo() void {}
66
77comptime {
88 var a: *align(1) fn () void = undefined;
9 _ = a;
9 _ = &a;
1010}
1111comptime {
1212 var a: *align(2) fn () align(2) void = undefined;
13 _ = a;
13 _ = &a;
1414}
1515comptime {
1616 var a: *align(2) fn () void = undefined;
17 _ = a;
17 _ = &a;
1818}
1919comptime {
2020 var a: *align(1) fn () align(2) void = undefined;
21 _ = a;
21 _ = &a;
2222}
2323
2424// error
test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig+2-1
......@@ -3,6 +3,7 @@ const std = @import("std");
33pub export fn entry() void {
44 var ohnoes: *usize = undefined;
55 _ = sliceAsBytes(ohnoes);
6 _ = &ohnoes;
67}
78fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) {}
89
......@@ -10,4 +11,4 @@ fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) {
1011// backend=llvm
1112// target=native
1213//
13// :7:63: error: expected type 'type', found 'bool'
14// :8:63: error: expected type 'type', found 'bool'
test/cases/compile_errors/generic_method_call_with_invalid_param.zig+5-4
......@@ -11,6 +11,7 @@ export fn callVoidMethodWithBool() void {
1111export fn callComptimeBoolMethodWithRuntimeBool() void {
1212 const s = S{};
1313 var arg = true;
14 _ = &arg;
1415 s.comptimeBoolMethod(arg);
1516}
1617
......@@ -25,8 +26,8 @@ const S = struct {
2526// target=native
2627//
2728// :3:18: error: expected type 'bool', found 'void'
28// :18:43: note: parameter type declared here
29// :8:18: error: expected type 'void', found 'bool'
3029// :19:43: note: parameter type declared here
31// :14:26: error: runtime-known argument passed to comptime parameter
32// :20:57: note: declared comptime here
30// :8:18: error: expected type 'void', found 'bool'
31// :20:43: note: parameter type declared here
32// :15:26: error: runtime-known argument passed to comptime parameter
33// :21:57: note: declared comptime here
test/cases/compile_errors/ignored_expression_in_while_continuation.zig+6-4
......@@ -3,10 +3,12 @@ export fn a() void {
33}
44export fn b() void {
55 var x: anyerror!i32 = 1234;
6 _ = &x;
67 while (x) |_| : (bad()) {} else |_| {}
78}
89export fn c() void {
910 var x: ?i32 = 1234;
11 _ = &x;
1012 while (x) |_| : (bad()) {}
1113}
1214fn bad() anyerror!void {
......@@ -19,7 +21,7 @@ fn bad() anyerror!void {
1921//
2022// :2:24: error: error is ignored
2123// :2:24: note: consider using 'try', 'catch', or 'if'
22// :6:25: error: error is ignored
23// :6:25: note: consider using 'try', 'catch', or 'if'
24// :10:25: error: error is ignored
25// :10:25: note: consider using 'try', 'catch', or 'if'
24// :7:25: error: error is ignored
25// :7:25: note: consider using 'try', 'catch', or 'if'
26// :12:25: error: error is ignored
27// :12:25: note: consider using 'try', 'catch', or 'if'
test/cases/compile_errors/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig+6-6
......@@ -1,32 +1,32 @@
11export fn a() void {
22 var x: [*c]u8 = undefined;
33 var y: *align(4) u8 = x;
4 _ = y;
4 _ = .{ &x, &y };
55}
66export fn b() void {
77 var x: [*c]const u8 = undefined;
88 var y: *u8 = x;
9 _ = y;
9 _ = .{ &x, &y };
1010}
1111export fn c() void {
1212 var x: [*c]u8 = undefined;
1313 var y: *u32 = x;
14 _ = y;
14 _ = .{ &x, &y };
1515}
1616export fn d() void {
1717 var y: *align(1) u32 = undefined;
1818 var x: [*c]u32 = y;
19 _ = x;
19 _ = .{ &x, &y };
2020}
2121export fn e() void {
2222 var y: *const u8 = undefined;
2323 var x: [*c]u8 = y;
24 _ = x;
24 _ = .{ &x, &y };
2525}
2626export fn f() void {
2727 var y: *u8 = undefined;
2828 var x: [*c]u32 = y;
29 _ = x;
29 _ = .{ &x, &y };
3030}
3131
3232// error
test/cases/compile_errors/implicit_cast_from_f64_to_f32.zig+1-1
......@@ -7,7 +7,7 @@ export fn entry() void {
77export fn entry2() void {
88 var x1: f64 = 1.0;
99 var y2: f32 = x1;
10 _ = y2;
10 _ = .{ &x1, &y2 };
1111}
1212
1313// error
test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig+3-3
......@@ -4,7 +4,7 @@ export fn entry() void {
44 foo(Set1.B);
55}
66fn foo(set1: Set1) void {
7 var x: Set2 = set1;
7 const x: Set2 = set1;
88 _ = x;
99}
1010
......@@ -12,5 +12,5 @@ fn foo(set1: Set1) void {
1212// backend=stage2
1313// target=native
1414//
15// :7:19: error: expected type 'error{C,A}', found 'error{A,B}'
16// :7:19: note: 'error.B' not a member of destination error set
15// :7:21: error: expected type 'error{C,A}', found 'error{A,B}'
16// :7:21: note: 'error.B' not a member of destination error set
test/cases/compile_errors/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig+9-4
......@@ -4,6 +4,9 @@ export fn entry() void {
44 var ptr_opt_many_ptr = &opt_many_ptr;
55 var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
66 ptr_opt_many_ptr = c_ptr;
7 _ = &slice;
8 _ = &ptr_opt_many_ptr;
9 _ = &c_ptr;
710}
811export fn entry2() void {
912 var buf: [4]u8 = "aoeu".*;
......@@ -11,7 +14,9 @@ export fn entry2() void {
1114 var opt_many_ptr: [*]u8 = slice.ptr;
1215 var ptr_opt_many_ptr = &opt_many_ptr;
1316 var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr;
14 _ = c_ptr;
17 _ = &slice;
18 _ = &ptr_opt_many_ptr;
19 _ = &c_ptr;
1520}
1621
1722// error
......@@ -21,6 +26,6 @@ export fn entry2() void {
2126// :6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'
2227// :6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'
2328// :6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'
24// :13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'
25// :13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'
26// :13:35: note: mutable '[*]u8' allows illegal null values stored to type '[*c]const u8'
29// :16:35: error: expected type '[*c][*c]const u8', found '*[*]u8'
30// :16:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'
31// :16:35: note: mutable '[*]u8' allows illegal null values stored to type '[*c]const u8'
test/cases/compile_errors/implicit_casting_null_c_pointer_to_zig_pointer.zig+3-2
......@@ -1,6 +1,7 @@
11comptime {
22 var c_ptr: [*c]u8 = 0;
3 var zig_ptr: *u8 = c_ptr;
3 const zig_ptr: *u8 = c_ptr;
4 _ = &c_ptr;
45 _ = zig_ptr;
56}
67
......@@ -8,4 +9,4 @@ comptime {
89// backend=stage2
910// target=native
1011//
11// :3:24: error: null pointer casted to type '*u8'
12// :3:26: error: null pointer casted to type '*u8'
test/cases/compile_errors/implicitly_casting_enum_to_tag_type.zig+1-1
......@@ -7,7 +7,7 @@ const Small = enum(u2) {
77
88export fn entry() void {
99 var x: u2 = Small.Two;
10 _ = x;
10 _ = &x;
1111}
1212
1313// error
test/cases/compile_errors/incompatible sub-byte fields.zig +4-3
......@@ -11,6 +11,7 @@ export fn entry() void {
1111 var a = A{ .a = 2, .b = 2 };
1212 var b = B{ .q = 22, .a = 3, .b = 2 };
1313 var t: usize = 0;
14 _ = &t;
1415 const ptr = switch (t) {
1516 0 => &a.a,
1617 1 => &b.a,
......@@ -24,6 +25,6 @@ export fn entry() void {
2425// backend=stage2
2526// target=native
2627//
27// :14:17: error: incompatible types: '*align(1:0:1) u2' and '*align(2:8:2) u2'
28// :15:14: note: type '*align(1:0:1) u2' here
29// :16:14: note: type '*align(2:8:2) u2' here
28// :15:17: error: incompatible types: '*align(1:0:1) u2' and '*align(2:8:2) u2'
29// :16:14: note: type '*align(1:0:1) u2' here
30// :17:14: note: type '*align(2:8:2) u2' here
test/cases/compile_errors/incompatible_sentinels.zig+2-2
......@@ -8,11 +8,11 @@ export fn entry2(ptr: [*]u8) [*:0]u8 {
88}
99export fn entry3() void {
1010 var array: [2:0]u8 = [_:255]u8{ 1, 2 };
11 _ = array;
11 _ = &array;
1212}
1313export fn entry4() void {
1414 var array: [2:0]u8 = [_]u8{ 1, 2 };
15 _ = array;
15 _ = &array;
1616}
1717
1818// error
test/cases/compile_errors/incorrect_pointer_dereference_syntax.zig+1
......@@ -1,6 +1,7 @@
11pub export fn entry() void {
22 var a: *u32 = undefined;
33 _ = *a;
4 _ = &a;
45}
56
67// error
test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig+4-4
......@@ -1,17 +1,17 @@
11pub export fn entry() void {
22 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
3 var slice: []u8 = &buf;
3 const slice: []u8 = &buf;
44 const a: u32 = 1234;
55 @memcpy(slice.ptr, @as([*]const u8, @ptrCast(&a)));
66}
77pub export fn entry1() void {
88 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
9 var ptr: *u8 = &buf[0];
9 const ptr: *u8 = &buf[0];
1010 @memcpy(ptr, 0);
1111}
1212pub export fn entry2() void {
1313 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
14 var ptr: *u8 = &buf[0];
14 const ptr: *u8 = &buf[0];
1515 @memset(ptr, 0);
1616}
1717pub export fn non_matching_lengths() void {
......@@ -29,7 +29,7 @@ pub export fn memcpy_const_dest_ptr() void {
2929 @memcpy(&buf1, &buf2);
3030}
3131pub export fn memset_array() void {
32 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
32 const buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
3333 @memcpy(buf, 1);
3434}
3535
test/cases/compile_errors/indexing_an_array_of_size_zero_with_runtime_index.zig+2-1
......@@ -1,6 +1,7 @@
11const array = [_]u8{};
22export fn foo() void {
33 var index: usize = 0;
4 _ = &index;
45 const pointer = &array[index];
56 _ = pointer;
67}
......@@ -9,4 +10,4 @@ export fn foo() void {
910// backend=stage2
1011// target=native
1112//
12// :4:27: error: indexing into empty array is not allowed
13// :5:27: error: indexing into empty array is not allowed
test/cases/compile_errors/inline_call_runtime_value_to_comptime_param.zig+1-1
......@@ -6,7 +6,7 @@ fn acceptRuntime(value: u64) void {
66}
77pub export fn entry() void {
88 var value: u64 = 0;
9 acceptRuntime(value);
9 acceptRuntime((&value).*);
1010}
1111
1212// error
test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig+6-4
......@@ -1,9 +1,11 @@
11export fn foo() void {
22 var a: f32 = 2;
3 _ = &a;
34 _ = @as(comptime_int, @intFromFloat(a));
45}
56export fn bar() void {
67 var a: u32 = 2;
8 _ = &a;
79 _ = @as(comptime_float, @floatFromInt(a));
810}
911
......@@ -11,7 +13,7 @@ export fn bar() void {
1113// backend=stage2
1214// target=native
1315//
14// :3:41: error: unable to resolve comptime value
15// :3:41: note: value being casted to 'comptime_int' must be comptime-known
16// :7:43: error: unable to resolve comptime value
17// :7:43: note: value being casted to 'comptime_float' must be comptime-known
16// :4:41: error: unable to resolve comptime value
17// :4:41: note: value being casted to 'comptime_int' must be comptime-known
18// :9:43: error: unable to resolve comptime value
19// :9:43: note: value being casted to 'comptime_float' must be comptime-known
test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig+2-2
......@@ -1,5 +1,5 @@
11export fn entry() void {
2 var b: *i32 = @ptrFromInt(0);
2 const b: *i32 = @ptrFromInt(0);
33 _ = b;
44}
55
......@@ -7,4 +7,4 @@ export fn entry() void {
77// backend=stage2
88// target=native
99//
10// :2:31: error: pointer type '*i32' does not allow address zero
10// :2:33: error: pointer type '*i32' does not allow address zero
test/cases/compile_errors/int_to_err_global_invalid_number.zig+1-1
......@@ -5,7 +5,7 @@ const Set1 = error{
55comptime {
66 var x: u16 = 3;
77 var y = @errorFromInt(x);
8 _ = y;
8 _ = .{ &x, &y };
99}
1010
1111// error
test/cases/compile_errors/int_to_err_non_global_invalid_number.zig+3-3
......@@ -7,8 +7,8 @@ const Set2 = error{
77 C,
88};
99comptime {
10 var x = @intFromError(Set1.B);
11 var y: Set2 = @errorCast(@errorFromInt(x));
10 const x = @intFromError(Set1.B);
11 const y: Set2 = @errorCast(@errorFromInt(x));
1212 _ = y;
1313}
1414
......@@ -16,4 +16,4 @@ comptime {
1616// backend=llvm
1717// target=native
1818//
19// :11:19: error: 'error.B' not a member of error set 'error{C,A}'
19// :11:21: error: 'error.B' not a member of error set 'error{C,A}'
test/cases/compile_errors/integer_cast_truncates_bits.zig+2-2
......@@ -11,12 +11,12 @@ export fn entry2() void {
1111export fn entry3() void {
1212 var spartan_count: u16 = 300;
1313 var byte: u8 = spartan_count;
14 _ = byte;
14 _ = .{ &spartan_count, &byte };
1515}
1616export fn entry4() void {
1717 var signed: i8 = -1;
1818 var unsigned: u64 = signed;
19 _ = unsigned;
19 _ = .{ &signed, &unsigned };
2020}
2121
2222// error
test/cases/compile_errors/invalid_compare_string.zig+4-4
......@@ -1,20 +1,20 @@
11comptime {
2 var a = "foo";
2 const a = "foo";
33 if (a == "foo") unreachable;
44}
55comptime {
6 var a = "foo";
6 const a = "foo";
77 if (a == ("foo")) unreachable; // intentionally allow
88}
99comptime {
10 var a = "foo";
10 const a = "foo";
1111 switch (a) {
1212 "foo" => unreachable,
1313 else => {},
1414 }
1515}
1616comptime {
17 var a = "foo";
17 const a = "foo";
1818 switch (a) {
1919 ("foo") => unreachable, // intentionally allow
2020 else => {},
test/cases/compile_errors/invalid_deref_on_switch_target.zig+1-1
......@@ -1,5 +1,5 @@
11comptime {
2 var tile = Tile.Empty;
2 const tile = Tile.Empty;
33 switch (tile.*) {
44 Tile.Empty => {},
55 Tile.Filled => {},
test/cases/compile_errors/invalid_float_casts.zig+8-4
......@@ -1,17 +1,21 @@
11export fn foo() void {
22 var a: f32 = 2;
3 _ = &a;
34 _ = @as(comptime_float, @floatCast(a));
45}
56export fn bar() void {
67 var a: f32 = 2;
8 _ = &a;
79 _ = @as(f32, @intFromFloat(a));
810}
911export fn baz() void {
1012 var a: f32 = 2;
13 _ = &a;
1114 _ = @as(f32, @floatFromInt(a));
1215}
1316export fn qux() void {
1417 var a: u32 = 2;
18 _ = &a;
1519 _ = @as(f32, @floatCast(a));
1620}
1721
......@@ -19,7 +23,7 @@ export fn qux() void {
1923// backend=stage2
2024// target=native
2125//
22// :3:40: error: unable to cast runtime value to 'comptime_float'
23// :7:18: error: expected integer type, found 'f32'
24// :11:32: error: expected integer type, found 'f32'
25// :15:29: error: expected float or vector type, found 'u32'
26// :4:40: error: unable to cast runtime value to 'comptime_float'
27// :9:18: error: expected integer type, found 'f32'
28// :14:32: error: expected integer type, found 'f32'
29// :19:29: error: expected float or vector type, found 'u32'
test/cases/compile_errors/invalid_inline_else_type.zig+6-3
......@@ -1,5 +1,6 @@
11pub export fn entry1() void {
22 var a: anyerror = undefined;
3 _ = &a;
34 switch (a) {
45 inline else => {},
56 }
......@@ -7,12 +8,14 @@ pub export fn entry1() void {
78const E = enum(u8) { a, _ };
89pub export fn entry2() void {
910 var a: E = undefined;
11 _ = &a;
1012 switch (a) {
1113 inline else => {},
1214 }
1315}
1416pub export fn entry3() void {
1517 var a: *u32 = undefined;
18 _ = &a;
1619 switch (a) {
1720 inline else => {},
1821 }
......@@ -22,6 +25,6 @@ pub export fn entry3() void {
2225// backend=stage2
2326// target=native
2427//
25// :4:21: error: cannot enumerate values of type 'anyerror' for 'inline else'
26// :11:21: error: cannot enumerate values of type 'tmp.E' for 'inline else'
27// :17:21: error: cannot enumerate values of type '*u32' for 'inline else'
28// :5:21: error: cannot enumerate values of type 'anyerror' for 'inline else'
29// :13:21: error: cannot enumerate values of type 'tmp.E' for 'inline else'
30// :20:21: error: cannot enumerate values of type '*u32' for 'inline else'
test/cases/compile_errors/invalid_int_casts.zig+8-4
......@@ -1,17 +1,21 @@
11export fn foo() void {
22 var a: u32 = 2;
3 _ = &a;
34 _ = @as(comptime_int, @intCast(a));
45}
56export fn bar() void {
67 var a: u32 = 2;
8 _ = &a;
79 _ = @as(u32, @floatFromInt(a));
810}
911export fn baz() void {
1012 var a: u32 = 2;
13 _ = &a;
1114 _ = @as(u32, @intFromFloat(a));
1215}
1316export fn qux() void {
1417 var a: f32 = 2;
18 _ = &a;
1519 _ = @as(u32, @intCast(a));
1620}
1721
......@@ -19,7 +23,7 @@ export fn qux() void {
1923// backend=stage2
2024// target=native
2125//
22// :3:36: error: unable to cast runtime value to 'comptime_int'
23// :7:18: error: expected float type, found 'u32'
24// :11:32: error: expected float type, found 'u32'
25// :15:27: error: expected integer or vector, found 'f32'
26// :4:36: error: unable to cast runtime value to 'comptime_int'
27// :9:18: error: expected float type, found 'u32'
28// :14:32: error: expected float type, found 'u32'
29// :19:27: error: expected integer or vector, found 'f32'
test/cases/compile_errors/invalid_multiple_dereferences.zig+5-4
......@@ -1,11 +1,12 @@
11export fn a() void {
22 var box = Box{ .field = 0 };
3 _ = &box;
34 box.*.field = 1;
45}
56export fn b() void {
67 var box = Box{ .field = 0 };
7 var boxPtr = &box;
8 boxPtr.*.*.field = 1;
8 const box_ptr = &box;
9 box_ptr.*.*.field = 1;
910}
1011pub const Box = struct {
1112 field: i32,
......@@ -15,5 +16,5 @@ pub const Box = struct {
1516// backend=stage2
1617// target=native
1718//
18// :3:8: error: cannot dereference non-pointer type 'tmp.Box'
19// :8:13: error: cannot dereference non-pointer type 'tmp.Box'
19// :4:8: error: cannot dereference non-pointer type 'tmp.Box'
20// :9:14: error: cannot dereference non-pointer type 'tmp.Box'
test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig+2-2
......@@ -10,12 +10,12 @@ const U = union(E) {
1010export fn foo() void {
1111 var e: E = @enumFromInt(15);
1212 var u: U = e;
13 _ = u;
13 _ = .{ &e, &u };
1414}
1515export fn bar() void {
1616 const e: E = @enumFromInt(15);
1717 var u: U = e;
18 _ = u;
18 _ = &u;
1919}
2020
2121// error
test/cases/compile_errors/invalid_peer_type_resolution.zig+20-18
......@@ -1,11 +1,13 @@
11export fn optionalVector() void {
22 var x: ?@Vector(10, i32) = undefined;
33 var y: @Vector(11, i32) = undefined;
4 _ = .{ &x, &y };
45 _ = @TypeOf(x, y);
56}
67export fn badTupleField() void {
78 var x = .{ @as(u8, 0), @as(u32, 1) };
89 var y = .{ @as(u8, 1), "hello" };
10 _ = .{ &x, &y };
911 _ = @TypeOf(x, y);
1012}
1113export fn badNestedField() void {
......@@ -30,21 +32,21 @@ export fn incompatiblePointers4() void {
3032// backend=llvm
3133// target=native
3234//
33// :4:9: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)'
34// :4:17: note: type '?@Vector(10, i32)' here
35// :4:20: note: type '@Vector(11, i32)' here
36// :9:9: error: struct field '1' has conflicting types
37// :9:9: note: incompatible types: 'u32' and '*const [5:0]u8'
38// :9:17: note: type 'u32' here
39// :9:20: note: type '*const [5:0]u8' here
40// :14:9: error: struct field 'bar' has conflicting types
41// :14:9: note: struct field '1' has conflicting types
42// :14:9: note: incompatible types: 'comptime_int' and '*const [2:0]u8'
43// :14:17: note: type 'comptime_int' here
44// :14:20: note: type '*const [2:0]u8' here
45// :19:9: error: incompatible types: '[]const u8' and '[*:0]const u8'
46// :19:17: note: type '[]const u8' here
47// :19:20: note: type '[*:0]const u8' here
48// :26:9: error: incompatible types: '[]const u8' and '[*]const u8'
49// :26:23: note: type '[]const u8' here
50// :26:26: note: type '[*]const u8' here
35// :5:9: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)'
36// :5:17: note: type '?@Vector(10, i32)' here
37// :5:20: note: type '@Vector(11, i32)' here
38// :11:9: error: struct field '1' has conflicting types
39// :11:9: note: incompatible types: 'u32' and '*const [5:0]u8'
40// :11:17: note: type 'u32' here
41// :11:20: note: type '*const [5:0]u8' here
42// :16:9: error: struct field 'bar' has conflicting types
43// :16:9: note: struct field '1' has conflicting types
44// :16:9: note: incompatible types: 'comptime_int' and '*const [2:0]u8'
45// :16:17: note: type 'comptime_int' here
46// :16:20: note: type '*const [2:0]u8' here
47// :21:9: error: incompatible types: '[]const u8' and '[*:0]const u8'
48// :21:17: note: type '[]const u8' here
49// :21:20: note: type '[*:0]const u8' here
50// :28:9: error: incompatible types: '[]const u8' and '[*]const u8'
51// :28:23: note: type '[]const u8' here
52// :28:26: note: type '[*]const u8' here
test/cases/compile_errors/invalid_store_to_comptime_field.zig+13-11
......@@ -17,8 +17,9 @@ pub export fn entry2() void {
1717 var list = .{ 1, 2, 3 };
1818 var list2 = @TypeOf(list){ .@"0" = 1, .@"1" = 2, .@"2" = 3 };
1919 var list3 = @TypeOf(list){ 1, 2, 4 };
20 _ = list2;
21 _ = list3;
20 _ = &list;
21 _ = &list2;
22 _ = &list3;
2223}
2324pub export fn entry3() void {
2425 const U = struct {
......@@ -46,6 +47,7 @@ pub export fn entry5() void {
4647}
4748pub export fn entry6() void {
4849 var x: u32 = 15;
50 _ = &x;
4951 const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
5052 const S = struct {
5153 fn foo(_: T) void {}
......@@ -74,12 +76,12 @@ pub export fn entry8() void {
7476// :6:9: error: value stored in comptime field does not match the default value of the field
7577// :14:9: error: value stored in comptime field does not match the default value of the field
7678// :19:38: error: value stored in comptime field does not match the default value of the field
77// :31:19: error: value stored in comptime field does not match the default value of the field
78// :25:29: note: default value set here
79// :41:19: error: value stored in comptime field does not match the default value of the field
80// :35:29: note: default value set here
81// :45:12: error: value stored in comptime field does not match the default value of the field
82// :53:25: error: value stored in comptime field does not match the default value of the field
83// :66:36: error: value stored in comptime field does not match the default value of the field
84// :59:30: error: value stored in comptime field does not match the default value of the field
85// :57:29: note: default value set here
79// :32:19: error: value stored in comptime field does not match the default value of the field
80// :26:29: note: default value set here
81// :42:19: error: value stored in comptime field does not match the default value of the field
82// :36:29: note: default value set here
83// :46:12: error: value stored in comptime field does not match the default value of the field
84// :55:25: error: value stored in comptime field does not match the default value of the field
85// :68:36: error: value stored in comptime field does not match the default value of the field
86// :61:30: error: value stored in comptime field does not match the default value of the field
87// :59:29: note: default value set here
test/cases/compile_errors/invalid_struct_field.zig+3-2
......@@ -8,6 +8,7 @@ export fn f() void {
88export fn g() void {
99 var a: A = undefined;
1010 const y = a.bar;
11 _ = &a;
1112 _ = y;
1213}
1314export fn e() void {
......@@ -26,5 +27,5 @@ export fn e() void {
2627// :1:11: note: struct declared here
2728// :10:17: error: no field named 'bar' in struct 'tmp.A'
2829// :1:11: note: struct declared here
29// :18:45: error: no field named 'f' in struct 'tmp.e.B'
30// :14:15: note: struct declared here
30// :19:45: error: no field named 'f' in struct 'tmp.e.B'
31// :15:15: note: struct declared here
test/cases/compile_errors/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig+2-2
......@@ -1,5 +1,5 @@
11export fn entry() void {
2 var foo: u32 = @This(){};
2 const foo: u32 = @This(){};
33 _ = foo;
44}
55
......@@ -7,5 +7,5 @@ export fn entry() void {
77// backend=stage2
88// target=native
99//
10// :2:27: error: expected type 'u32', found 'tmp'
10// :2:29: error: expected type 'u32', found 'tmp'
1111// :1:1: note: struct declared here
test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig+1-1
......@@ -4,7 +4,7 @@ export fn foo1() void {
44 _ = word;
55}
66export fn foo2() void {
7 var bytes: []const u8 = &[_]u8{ 1, 2 };
7 const bytes: []const u8 = &[_]u8{ 1, 2 };
88 const word: u16 = @bitCast(bytes);
99 _ = word;
1010}
test/cases/compile_errors/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig+5-5
......@@ -1,14 +1,14 @@
11export fn foo() void {
22 var u: ?*anyopaque = null;
33 var v: *anyopaque = undefined;
4 v = u;
4 v = (&u).*;
55}
66
77// error
88// backend=stage2
99// target=native
1010//
11// :4:9: error: expected type '*anyopaque', found '?*anyopaque'
12// :4:9: note: cannot convert optional to payload type
13// :4:9: note: consider using '.?', 'orelse', or 'if'
14// :4:9: note: '?*anyopaque' could have null values which are illegal in type '*anyopaque'
11// :4:13: error: expected type '*anyopaque', found '?*anyopaque'
12// :4:13: note: cannot convert optional to payload type
13// :4:13: note: consider using '.?', 'orelse', or 'if'
14// :4:13: note: '?*anyopaque' could have null values which are illegal in type '*anyopaque'
test/cases/compile_errors/lazy_pointer_with_undefined_element_type.zig+2-1
......@@ -1,5 +1,6 @@
11export fn foo() void {
22 comptime var T: type = undefined;
3 _ = &T;
34 const S = struct { x: *T };
45 const I = @typeInfo(S);
56 _ = I;
......@@ -9,4 +10,4 @@ export fn foo() void {
910// backend=stage2
1011// target=native
1112//
12// :3:28: error: use of undefined value here causes undefined behavior
13// :4:28: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/load_vector_pointer_with_unknown_runtime_index.zig+1-1
......@@ -3,7 +3,7 @@ export fn entry() void {
33
44 var i: u32 = 0;
55 var x = loadv(&v[i]);
6 _ = x;
6 _ = .{ &i, &x };
77}
88
99fn loadv(ptr: anytype) i31 {
test/cases/compile_errors/memset_no_length.zig+6-4
......@@ -1,9 +1,11 @@
11export fn foo() void {
22 var ptr: [*]u8 = undefined;
3 _ = &ptr;
34 @memset(ptr, 123);
45}
56export fn bar() void {
67 var ptr: [*c]bool = undefined;
8 _ = &ptr;
79 @memset(ptr, true);
810}
911
......@@ -11,7 +13,7 @@ export fn bar() void {
1113// backend=stage2
1214// target=native
1315//
14// :3:5: error: unknown @memset length
15// :3:13: note: destination type '[*]u8' provides no length
16// :7:5: error: unknown @memset length
17// :7:13: note: destination type '[*c]bool' provides no length
16// :4:5: error: unknown @memset length
17// :4:13: note: destination type '[*]u8' provides no length
18// :9:5: error: unknown @memset length
19// :9:13: note: destination type '[*c]bool' provides no length
test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig+1-1
......@@ -7,7 +7,7 @@ pub fn getGeo3DTex2D() Geo3DTex2D {
77 };
88}
99export fn entry() void {
10 var geo_data = getGeo3DTex2D();
10 const geo_data = getGeo3DTex2D();
1111 _ = geo_data;
1212}
1313
test/cases/compile_errors/missing_else_clause.zig+2-2
......@@ -14,7 +14,7 @@ fn h() void {
1414 // https://github.com/ziglang/zig/issues/12743
1515 const T = struct { oh_no: *u32 };
1616 var x: T = if (false) {};
17 _ = x;
17 _ = &x;
1818}
1919fn k(b: bool) void {
2020 // block_ptr case
......@@ -22,7 +22,7 @@ fn k(b: bool) void {
2222 var x = if (b) blk: {
2323 break :blk if (false) T{ .oh_no = 2 };
2424 } else T{ .oh_no = 1 };
25 _ = x;
25 _ = &x;
2626}
2727export fn entry() void {
2828 f(true);
test/cases/compile_errors/missing_parameter_name_of_generic_function.zig+1-1
......@@ -1,7 +1,7 @@
11fn dump(anytype) void {}
22export fn entry() void {
33 var a: u8 = 9;
4 dump(a);
4 dump((&a).*);
55}
66
77// error
test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig+1-1
......@@ -24,7 +24,7 @@ pub const JsonNode = struct {
2424fn foo() void {
2525 var jll: JasonList = undefined;
2626 jll.init(1234);
27 var jd = JsonNode{ .kind = JsonType.JSONArray, .jobject = JsonOA.JSONArray{jll} };
27 const jd = JsonNode{ .kind = JsonType.JSONArray, .jobject = JsonOA.JSONArray{jll} };
2828 _ = jd;
2929}
3030
test/cases/compile_errors/mod_on_undefined_value.zig+1
......@@ -1,6 +1,7 @@
11comptime {
22 var a: i64 = undefined;
33 _ = a % a;
4 _ = &a;
45}
56
67// error
test/cases/compile_errors/mult_on_undefined_value.zig+1-1
......@@ -1,5 +1,5 @@
11comptime {
2 var a: i64 = undefined;
2 const a: i64 = undefined;
33 _ = a * a;
44}
55
test/cases/compile_errors/negate_on_undefined_value.zig+1-1
......@@ -1,5 +1,5 @@
11comptime {
2 var a: i64 = undefined;
2 const a: i64 = undefined;
33 _ = -a;
44}
55
test/cases/compile_errors/nested_vectors.zig+1-1
......@@ -1,7 +1,7 @@
11export fn entry() void {
22 const V1 = @Vector(4, u8);
33 const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } });
4 var v: V2 = undefined;
4 const v: V2 = undefined;
55 _ = v;
66}
77
test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig+7-7
......@@ -1,30 +1,30 @@
11export fn entry1() void {
22 var m2 = &2;
3 _ = m2;
3 _ = &m2;
44}
55export fn entry2() void {
66 var a = undefined;
7 _ = a;
7 _ = &a;
88}
99export fn entry3() void {
1010 var b = 1;
11 _ = b;
11 _ = &b;
1212}
1313export fn entry4() void {
1414 var c = 1.0;
15 _ = c;
15 _ = &c;
1616}
1717export fn entry5() void {
1818 var d = null;
19 _ = d;
19 _ = &d;
2020}
2121export fn entry6(opaque_: *Opaque) void {
2222 var e = opaque_.*;
23 _ = e;
23 _ = &e;
2424}
2525export fn entry7() void {
2626 var f = i32;
27 _ = f;
27 _ = &f;
2828}
2929const Opaque = opaque {};
3030export fn entry8() void {
test/cases/compile_errors/non-integer_tag_type_to_enum.zig+1-1
......@@ -3,7 +3,7 @@ const Foo = enum(f32) {
33};
44export fn entry() void {
55 var f: Foo = undefined;
6 _ = f;
6 _ = &f;
77}
88
99// error
test/cases/compile_errors/non_void_error_union_payload_ignored.zig+4-2
......@@ -5,6 +5,7 @@ pub export fn entry1() void {
55 } else |_| {
66 // bar
77 }
8 _ = &x;
89}
910pub export fn entry2() void {
1011 var x: anyerror!usize = 5;
......@@ -13,6 +14,7 @@ pub export fn entry2() void {
1314 } else |_| {
1415 // bar
1516 }
17 _ = &x;
1618}
1719
1820// error
......@@ -21,5 +23,5 @@ pub export fn entry2() void {
2123//
2224// :3:5: error: error union payload is ignored
2325// :3:5: note: payload value can be explicitly ignored with '|_|'
24// :11:5: error: error union payload is ignored
25// :11:5: note: payload value can be explicitly ignored with '|_|'
26// :12:5: error: error union payload is ignored
27// :12:5: note: payload value can be explicitly ignored with '|_|'
test/cases/compile_errors/not_an_enum_type.zig+1-1
......@@ -1,6 +1,6 @@
11export fn entry() void {
22 var self: Error = undefined;
3 switch (self) {
3 switch ((&self).*) {
44 InvalidToken => |x| return x.token,
55 ExpectedVarDeclOrFn => |x| return x.token,
66 }
test/cases/compile_errors/or_on_undefined_value.zig+2-1
......@@ -1,5 +1,6 @@
11comptime {
22 var a: bool = undefined;
3 _ = &a;
34 _ = a or a;
45}
56
......@@ -7,4 +8,4 @@ comptime {
78// backend=stage2
89// target=native
910//
10// :3:9: error: use of undefined value here causes undefined behavior
11// :4:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/orelse_on_undefined_value.zig+1-1
......@@ -1,5 +1,5 @@
11comptime {
2 var a: ?bool = undefined;
2 const a: ?bool = undefined;
33 _ = a orelse false;
44}
55
test/cases/compile_errors/out_of_bounds_index.zig+8-8
......@@ -1,29 +1,29 @@
11comptime {
22 var array = [_:0]u8{ 1, 2, 3, 4 };
33 var src_slice: [:0]u8 = &array;
4 var slice = src_slice[2..6];
4 const slice = src_slice[2..6];
55 _ = slice;
66}
77comptime {
88 var array = [_:0]u8{ 1, 2, 3, 4 };
9 var slice = array[2..6];
9 const slice = array[2..6];
1010 _ = slice;
1111}
1212comptime {
1313 var array = [_]u8{ 1, 2, 3, 4 };
14 var slice = array[2..5];
14 const slice = array[2..5];
1515 _ = slice;
1616}
1717comptime {
1818 var array = [_:0]u8{ 1, 2, 3, 4 };
19 var slice = array[3..2];
19 const slice = array[3..2];
2020 _ = slice;
2121}
2222
2323// error
2424// target=native
2525//
26// :4:30: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)
27// :9:26: error: end index 6 out of bounds for array of length 4 +1 (sentinel)
28// :14:26: error: end index 5 out of bounds for array of length 4
29// :19:23: error: start index 3 is larger than end index 2
26// :4:32: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)
27// :9:28: error: end index 6 out of bounds for array of length 4 +1 (sentinel)
28// :14:28: error: end index 5 out of bounds for array of length 4
29// :19:25: error: start index 3 is larger than end index 2
test/cases/compile_errors/overflow_in_enum_value_allocation.zig+1-1
......@@ -3,7 +3,7 @@ const Moo = enum(u8) {
33 Over,
44};
55pub export fn entry() void {
6 var y = Moo.Last;
6 const y = Moo.Last;
77 _ = y;
88}
99
test/cases/compile_errors/packed_union_given_enum_tag_type.zig+1-1
......@@ -9,7 +9,7 @@ const Payload = packed union(Letter) {
99 C: bool,
1010};
1111export fn entry() void {
12 var a = Payload{ .A = 1234 };
12 const a: Payload = .{ .A = 1234 };
1313 _ = a;
1414}
1515
test/cases/compile_errors/packed_union_with_automatic_layout_field.zig+1-1
......@@ -7,7 +7,7 @@ const Payload = packed union {
77 B: bool,
88};
99export fn entry() void {
10 var a = Payload{ .B = true };
10 const a: Payload = .{ .B = true };
1111 _ = a;
1212}
1313
test/cases/compile_errors/pointer_arithmetic_on_pointer-to-array.zig+5-5
......@@ -1,7 +1,7 @@
11export fn foo() void {
22 var x: [10]u8 = undefined;
3 var y = &x;
4 var z = y + 1;
3 const y = &x;
4 const z = y + 1;
55 _ = z;
66}
77
......@@ -9,6 +9,6 @@ export fn foo() void {
99// backend=stage2
1010// target=native
1111//
12// :4:15: error: incompatible types: '*[10]u8' and 'comptime_int'
13// :4:13: note: type '*[10]u8' here
14// :4:17: note: type 'comptime_int' here
12// :4:17: error: incompatible types: '*[10]u8' and 'comptime_int'
13// :4:15: note: type '*[10]u8' here
14// :4:19: note: type 'comptime_int' here
test/cases/compile_errors/pointer_to_anyopaque_slice.zig+1
......@@ -2,6 +2,7 @@ export fn x() void {
22 var a: *u32 = undefined;
33 var b: []anyopaque = undefined;
44 b = a;
5 _ = &a;
56}
67
78// error
test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig+1-1
......@@ -1,6 +1,6 @@
11pub export fn entry() void {
22 var y: [*]align(4) u8 = @ptrFromInt(5);
3 _ = y;
3 _ = &y;
44}
55
66// error
test/cases/compile_errors/recursive_inline_fn.zig+2-1
......@@ -8,6 +8,7 @@ inline fn foo(x: i32) i32 {
88
99pub export fn entry() void {
1010 var x: i32 = 4;
11 _ = &x;
1112 _ = foo(x) == 20;
1213}
1314
......@@ -32,4 +33,4 @@ pub export fn entry2() void {
3233// target=native
3334//
3435// :5:27: error: inline call is recursive
35// :23:10: error: inline call is recursive
36// :24:10: error: inline call is recursive
test/cases/compile_errors/reference_to_const_data.zig+6-3
......@@ -5,10 +5,12 @@ export fn foo() void {
55export fn bar() void {
66 var ptr = &@as(u32, 2);
77 ptr.* = 2;
8 _ = &ptr;
89}
910export fn baz() void {
1011 var ptr = &true;
1112 ptr.* = false;
13 _ = &ptr;
1214}
1315export fn qux() void {
1416 const S = struct {
......@@ -21,6 +23,7 @@ export fn qux() void {
2123export fn quux() void {
2224 var x = &@returnAddress();
2325 x.* = 6;
26 _ = &x;
2427}
2528
2629// error
......@@ -29,6 +32,6 @@ export fn quux() void {
2932//
3033// :3:8: error: cannot assign to constant
3134// :7:8: error: cannot assign to constant
32// :11:8: error: cannot assign to constant
33// :19:8: error: cannot assign to constant
34// :23:6: error: cannot assign to constant
35// :12:8: error: cannot assign to constant
36// :21:8: error: cannot assign to constant
37// :25:6: error: cannot assign to constant
test/cases/compile_errors/reify_typeOf_with_incompatible_arguments.zig+1
......@@ -2,6 +2,7 @@ export fn entry() void {
22 var var_1: f32 = undefined;
33 var var_2: u32 = undefined;
44 _ = @TypeOf(var_1, var_2);
5 _ = .{ &var_1, &var_2 };
56}
67
78// error
test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr.zig+1-1
......@@ -1,5 +1,5 @@
11export fn entry() void {
2 var damn = Container{
2 const damn = Container{
33 .not_optional = getOptional(),
44 };
55 _ = damn;
test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig+1-1
......@@ -2,7 +2,7 @@ export fn entry() void {
22 var damn = Container{
33 .not_optional = getOptional(i32),
44 };
5 _ = damn;
5 _ = &damn;
66}
77pub fn getOptional(comptime T: type) ?T {
88 return 0;
test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig+1
......@@ -5,6 +5,7 @@ const Foo = struct {
55export fn f() void {
66 var x: u8 = 0;
77 const foo = Foo{ .Bar = x, .Baz = u8 };
8 _ = &x;
89 _ = foo;
910}
1011
test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig+3-2
......@@ -4,6 +4,7 @@ const Foo = union {
44};
55export fn f() void {
66 var x: u8 = 0;
7 _ = &x;
78 const foo = Foo{ .Bar = x };
89 _ = foo;
910}
......@@ -12,5 +13,5 @@ export fn f() void {
1213// backend=stage2
1314// target=native
1415//
15// :7:23: error: unable to resolve comptime value
16// :7:23: note: initializer of comptime only union must be comptime-known
16// :8:23: error: unable to resolve comptime value
17// :8:23: note: initializer of comptime only union must be comptime-known
test/cases/compile_errors/runtime_cast_to_union_which_has_non-void_fields.zig+2-2
......@@ -8,7 +8,7 @@ export fn entry() void {
88 foo(Letter.A);
99}
1010fn foo(l: Letter) void {
11 var x: Value = l;
11 const x: Value = l;
1212 _ = x;
1313}
1414
......@@ -16,6 +16,6 @@ fn foo(l: Letter) void {
1616// backend=stage2
1717// target=native
1818//
19// :11:20: error: runtime coercion from enum 'tmp.Letter' to union 'tmp.Value' which has non-void fields
19// :11:22: error: runtime coercion from enum 'tmp.Letter' to union 'tmp.Value' which has non-void fields
2020// :3:5: note: field 'A' has type 'i32'
2121// :2:15: note: union declared here
test/cases/compile_errors/runtime_indexing_comptime_array.zig+4-2
......@@ -13,12 +13,14 @@ pub export fn entry2() void {
1313 const test_fns = [_]TestFn{ foo, bar };
1414 var i: usize = 0;
1515 _ = test_fns[i];
16 _ = &i;
1617}
1718pub export fn entry3() void {
1819 const TestFn = fn () void;
1920 const test_fns = [_]TestFn{ foo, bar };
2021 var i: usize = 0;
2122 _ = &test_fns[i];
23 _ = &i;
2224}
2325// error
2426// target=native
......@@ -28,5 +30,5 @@ pub export fn entry3() void {
2830// :7:10: note: use '*const fn () void' for a function pointer type
2931// :15:18: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
3032// :15:17: note: use '*const fn () void' for a function pointer type
31// :21:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
32// :21:18: note: use '*const fn () void' for a function pointer type
33// :22:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
34// :22:18: note: use '*const fn () void' for a function pointer type
test/cases/compile_errors/runtime_to_comptime_num.zig+12-8
......@@ -1,19 +1,23 @@
11pub export fn entry() void {
22 var a: u32 = 0;
3 _ = &a;
34 _ = @as(comptime_int, a);
45}
56pub export fn entry2() void {
67 var a: u32 = 0;
8 _ = &a;
79 _ = @as(comptime_float, a);
810}
911pub export fn entry3() void {
1012 comptime var aa: comptime_float = 0.0;
1113 var a: f32 = 4;
14 _ = &a;
1215 aa = a;
1316}
1417pub export fn entry4() void {
1518 comptime var aa: comptime_int = 0.0;
1619 var a: f32 = 4;
20 _ = &a;
1721 aa = a;
1822}
1923
......@@ -21,11 +25,11 @@ pub export fn entry4() void {
2125// backend=stage2
2226// target=native
2327//
24// :3:27: error: unable to resolve comptime value
25// :3:27: note: value being casted to 'comptime_int' must be comptime-known
26// :7:29: error: unable to resolve comptime value
27// :7:29: note: value being casted to 'comptime_float' must be comptime-known
28// :12:10: error: unable to resolve comptime value
29// :12:10: note: value being casted to 'comptime_float' must be comptime-known
30// :17:10: error: unable to resolve comptime value
31// :17:10: note: value being casted to 'comptime_int' must be comptime-known
28// :4:27: error: unable to resolve comptime value
29// :4:27: note: value being casted to 'comptime_int' must be comptime-known
30// :9:29: error: unable to resolve comptime value
31// :9:29: note: value being casted to 'comptime_float' must be comptime-known
32// :15:10: error: unable to resolve comptime value
33// :15:10: note: value being casted to 'comptime_float' must be comptime-known
34// :21:10: error: unable to resolve comptime value
35// :21:10: note: value being casted to 'comptime_int' must be comptime-known
test/cases/compile_errors/runtime_value_in_switch_prong.zig+1-1
......@@ -1,6 +1,6 @@
11pub export fn entry() void {
22 var byte: u8 = 1;
3 switch (byte) {
3 switch ((&byte).*) {
44 byte => {},
55 else => {},
66 }
test/cases/compile_errors/self_referential_struct_requires_comptime.zig+1-1
......@@ -4,7 +4,7 @@ const S = struct {
44};
55pub export fn entry() void {
66 var s: S = undefined;
7 _ = s;
7 _ = &s;
88}
99
1010// error
test/cases/compile_errors/self_referential_union_requires_comptime.zig+1-1
......@@ -4,7 +4,7 @@ const U = union {
44};
55pub export fn entry() void {
66 var u: U = undefined;
7 _ = u;
7 _ = &u;
88}
99
1010// error
test/cases/compile_errors/shift_by_negative_comptime_integer.zig+2-2
......@@ -1,5 +1,5 @@
11comptime {
2 var a = 1 >> -1;
2 const a = 1 >> -1;
33 _ = a;
44}
55
......@@ -7,4 +7,4 @@ comptime {
77// backend=stage2
88// target=native
99//
10// :2:18: error: shift by negative amount '-1'
10// :2:20: error: shift by negative amount '-1'
test/cases/compile_errors/shift_on_type_with_non-power-of-two_size.zig+8-4
......@@ -2,18 +2,22 @@ export fn entry() void {
22 const S = struct {
33 fn a() void {
44 var x: u24 = 42;
5 _ = &x;
56 _ = x >> 24;
67 }
78 fn b() void {
89 var x: u24 = 42;
10 _ = &x;
911 _ = x << 24;
1012 }
1113 fn c() void {
1214 var x: u24 = 42;
15 _ = &x;
1316 _ = @shlExact(x, 24);
1417 }
1518 fn d() void {
1619 var x: u24 = 42;
20 _ = &x;
1721 _ = @shrExact(x, 24);
1822 }
1923 };
......@@ -27,7 +31,7 @@ export fn entry() void {
2731// backend=stage2
2832// target=native
2933//
30// :5:22: error: shift amount '24' is too large for operand type 'u24'
31// :9:22: error: shift amount '24' is too large for operand type 'u24'
32// :13:30: error: shift amount '24' is too large for operand type 'u24'
33// :17:30: error: shift amount '24' is too large for operand type 'u24'
34// :6:22: error: shift amount '24' is too large for operand type 'u24'
35// :11:22: error: shift amount '24' is too large for operand type 'u24'
36// :16:30: error: shift amount '24' is too large for operand type 'u24'
37// :21:30: error: shift amount '24' is too large for operand type 'u24'
test/cases/compile_errors/shifting_without_int_type_or_comptime_known.zig+4-2
......@@ -6,10 +6,12 @@ export fn entry1(x: u8) u8 {
66}
77export fn entry2() void {
88 var x: u5 = 1;
9 _ = &x;
910 _ = @shlExact(12345, x);
1011}
1112export fn entry3() void {
1213 var x: u5 = 1;
14 _ = &x;
1315 _ = @shrExact(12345, x);
1416}
1517
......@@ -19,5 +21,5 @@ export fn entry3() void {
1921//
2022// :2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
2123// :5:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
22// :9:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
23// :13:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
24// :10:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
25// :15:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
test/cases/compile_errors/shuffle_with_selected_index_past_first_vector_length.zig+4-4
......@@ -1,7 +1,7 @@
11export fn entry() void {
22 const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 };
33 const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 };
4 var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
4 const z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
55 _ = z;
66}
77
......@@ -9,6 +9,6 @@ export fn entry() void {
99// backend=stage2
1010// target=native
1111//
12// :4:39: error: mask index '4' has out-of-bounds selection
13// :4:27: note: selected index '7' out of bounds of '@Vector(4, u32)'
14// :4:30: note: selections from the second vector are specified with negative numbers
12// :4:41: error: mask index '4' has out-of-bounds selection
13// :4:29: note: selected index '7' out of bounds of '@Vector(4, u32)'
14// :4:32: note: selections from the second vector are specified with negative numbers
test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig+2-3
......@@ -1,11 +1,10 @@
11export fn foo() void {
22 const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16;
3 var value = @as(*const []const u8, @ptrCast(&bytes)).*;
4 _ = value;
3 _ = @as(*const []const u8, @ptrCast(&bytes)).*;
54}
65
76// error
87// backend=stage2
98// target=native
109//
11// :3:57: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not.
10// :3:49: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not.
test/cases/compile_errors/slice_of_null_pointer.zig+3-3
......@@ -1,11 +1,11 @@
11comptime {
22 var x: [*c]u8 = null;
33 var runtime_len: usize = 0;
4 var y = x[0..runtime_len];
5 _ = y;
4 _ = &runtime_len;
5 _ = x[0..runtime_len];
66}
77
88// error
99// target=native
1010//
11// :4:14: error: slice of null pointer
11// :5:10: error: slice of null pointer
test/cases/compile_errors/slice_sentinel_mismatch-2.zig+1-1
......@@ -1,5 +1,5 @@
11fn foo() [:0]u8 {
2 var x: []u8 = undefined;
2 const x: []u8 = undefined;
33 return x;
44}
55comptime {
test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig+1-2
......@@ -7,8 +7,7 @@ const Small = enum(u2) {
77};
88
99export fn entry() void {
10 var x = Small.One;
11 _ = x;
10 _ = Small.One;
1211}
1312
1413// error
test/cases/compile_errors/specify_non-integer_enum_tag_type.zig+1-1
......@@ -5,7 +5,7 @@ const Small = enum(f32) {
55};
66
77export fn entry() void {
8 var x = Small.One;
8 const x = Small.One;
99 _ = x;
1010}
1111
test/cases/compile_errors/stage1/obj/variable_in_inline_assembly_template_cannot_be_found.zig+1-1
......@@ -2,7 +2,7 @@ export fn entry() void {
22 var sp = asm volatile ("mov %[foo], sp"
33 : [bar] "=r" (-> usize),
44 );
5 _ = sp;
5 _ = &sp;
66}
77
88// error
test/cases/compile_errors/store_vector_pointer_with_unknown_runtime_index.zig+2-1
......@@ -2,6 +2,7 @@ export fn entry() void {
22 var v: @Vector(4, i31) = [_]i31{ 1, 5, 3, undefined };
33
44 var i: u32 = 0;
5 _ = &i;
56 storev(&v[i], 42);
67}
78
......@@ -13,4 +14,4 @@ fn storev(ptr: anytype, val: i31) void {
1314// backend=llvm
1415// target=native
1516//
16// :9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i31'
17// :10:8: error: unable to determine vector element index of type '*align(16:0:4:?) i31'
test/cases/compile_errors/sub_on_undefined_value.zig+1-1
......@@ -1,5 +1,5 @@
11comptime {
2 var a: i64 = undefined;
2 const a: i64 = undefined;
33 _ = a - a;
44}
55
test/cases/compile_errors/switch_capture_incompatible_types.zig+2-2
......@@ -1,7 +1,7 @@
11export fn f() void {
22 const U = union(enum) { a: u32, b: *u8 };
33 var u: U = undefined;
4 switch (u) {
4 switch ((&u).*) {
55 .a, .b => |val| _ = val,
66 }
77}
......@@ -9,7 +9,7 @@ export fn f() void {
99export fn g() void {
1010 const U = union(enum) { a: u64, b: u32 };
1111 var u: U = undefined;
12 switch (u) {
12 switch ((&u).*) {
1313 .a, .b => |*ptr| _ = ptr,
1414 }
1515}
test/cases/compile_errors/switch_on_enum_with_1_field_with_no_prongs.zig+1-1
......@@ -1,7 +1,7 @@
11const Foo = enum { M };
22
33export fn entry() void {
4 var f = Foo.M;
4 const f = Foo.M;
55 switch (f) {}
66}
77
test/cases/compile_errors/switch_on_slice.zig+2-1
......@@ -1,5 +1,6 @@
11pub export fn entry() void {
22 var a: [:0]const u8 = "foo";
3 _ = &a;
34 switch (a) {
45 ("--version"), ("version") => unreachable,
56 else => {},
......@@ -10,4 +11,4 @@ pub export fn entry() void {
1011// backend=stage2
1112// target=native
1213//
13// :3:13: error: switch on type '[:0]const u8'
14// :4:13: error: switch on type '[:0]const u8'
test/cases/compile_errors/switch_ranges_endpoints_are_validated.zig+2-2
......@@ -1,12 +1,12 @@
11pub export fn entry1() void {
2 var x: i32 = 0;
2 const x: i32 = 0;
33 switch (x) {
44 6...1 => {},
55 else => unreachable,
66 }
77}
88pub export fn entr2() void {
9 var x: i32 = 0;
9 const x: i32 = 0;
1010 switch (x) {
1111 -1...-5 => {},
1212 else => unreachable,
test/cases/compile_errors/switch_with_overlapping_case_ranges.zig+1-1
......@@ -1,6 +1,6 @@
11export fn entry() void {
22 var q: u8 = 0;
3 switch (q) {
3 switch ((&q).*) {
44 1...2 => {},
55 0...255 => {},
66 }
test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig+1-1
......@@ -3,7 +3,7 @@ const E = enum {
33 b,
44};
55pub export fn entry() void {
6 var e: E = .b;
6 const e: E = .b;
77 switch (e) {
88 .a => {},
99 .b => {},
test/cases/compile_errors/switching_with_non-exhaustive_enums.zig+3-3
......@@ -8,21 +8,21 @@ const U = union(E) {
88 b: u32,
99};
1010pub export fn entry1() void {
11 var e: E = .b;
11 const e: E = .b;
1212 switch (e) { // error: switch not handling the tag `b`
1313 .a => {},
1414 _ => {},
1515 }
1616}
1717pub export fn entry2() void {
18 var e: E = .b;
18 const e: E = .b;
1919 switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong
2020 .a => {},
2121 .b => {},
2222 }
2323}
2424pub export fn entry3() void {
25 var u = U{ .a = 2 };
25 const u = U{ .a = 2 };
2626 switch (u) { // error: `_` prong not allowed when switching on tagged union
2727 .a => {},
2828 .b => {},
test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig+3-4
......@@ -3,14 +3,13 @@ const FloatInt = extern union {
33 Int: i32,
44};
55export fn entry() void {
6 var fi = FloatInt{ .Float = 123.45 };
7 var tagName = @tagName(fi);
8 _ = tagName;
6 const fi: FloatInt = .{ .Float = 123.45 };
7 _ = @tagName(fi);
98}
109
1110// error
1211// backend=stage2
1312// target=native
1413//
15// :7:19: error: union 'tmp.FloatInt' is untagged
14// :7:9: error: union 'tmp.FloatInt' is untagged
1615// :1:25: note: union declared here
test/cases/compile_errors/truncate_sign_mismatch.zig+8-8
......@@ -1,25 +1,25 @@
11export fn entry1() i8 {
22 var x: u32 = 10;
3 return @truncate(x);
3 return @truncate((&x).*);
44}
55export fn entry2() u8 {
66 var x: i32 = -10;
7 return @truncate(x);
7 return @truncate((&x).*);
88}
99export fn entry3() i8 {
1010 comptime var x: u32 = 10;
11 return @truncate(x);
11 return @truncate((&x).*);
1212}
1313export fn entry4() u8 {
1414 comptime var x: i32 = -10;
15 return @truncate(x);
15 return @truncate((&x).*);
1616}
1717
1818// error
1919// backend=stage2
2020// target=native
2121//
22// :3:22: error: expected signed integer type, found 'u32'
23// :7:22: error: expected unsigned integer type, found 'i32'
24// :11:22: error: expected signed integer type, found 'u32'
25// :15:22: error: expected unsigned integer type, found 'i32'
22// :3:26: error: expected signed integer type, found 'u32'
23// :7:26: error: expected unsigned integer type, found 'i32'
24// :11:26: error: expected signed integer type, found 'u32'
25// :15:26: error: expected unsigned integer type, found 'i32'
test/cases/compile_errors/tuple_init_edge_cases.zig+23-18
......@@ -1,49 +1,54 @@
11pub export fn entry1() void {
22 const T = @TypeOf(.{ 123, 3 });
33 var b = T{ .@"1" = 3 };
4 _ = b;
4 _ = &b;
55 var c = T{ 123, 3 };
6 _ = c;
6 _ = &c;
77 var d = T{};
8 _ = d;
8 _ = &d;
99}
1010pub export fn entry2() void {
1111 var a: u32 = 2;
12 _ = &a;
1213 const T = @TypeOf(.{ 123, a });
1314 var b = T{ .@"1" = 3 };
14 _ = b;
15 _ = &b;
1516 var c = T{ 123, 3 };
16 _ = c;
17 _ = &c;
1718 var d = T{};
18 _ = d;
19 _ = &d;
1920}
2021pub export fn entry3() void {
2122 var a: u32 = 2;
23 _ = &a;
2224 const T = @TypeOf(.{ 123, a });
2325 var b = T{ .@"0" = 123 };
24 _ = b;
26 _ = &b;
2527}
2628comptime {
2729 var a: u32 = 2;
30 _ = &a;
2831 const T = @TypeOf(.{ 123, a });
2932 var b = T{ .@"0" = 123 };
30 _ = b;
33 _ = &b;
3134 var c = T{ 123, 2 };
32 _ = c;
35 _ = &c;
3336 var d = T{};
34 _ = d;
37 _ = &d;
3538}
3639pub export fn entry4() void {
3740 var a: u32 = 2;
41 _ = &a;
3842 const T = @TypeOf(.{ 123, a });
3943 var b = T{ 123, 4, 5 };
40 _ = b;
44 _ = &b;
4145}
4246pub export fn entry5() void {
4347 var a: u32 = 2;
48 _ = &a;
4449 const T = @TypeOf(.{ 123, a });
4550 var b = T{ .@"0" = 123, .@"2" = 123, .@"1" = 123 };
46 _ = b;
51 _ = &b;
4752}
4853pub const Consideration = struct {
4954 curve: Curve,
......@@ -64,9 +69,9 @@ pub export fn entry6() void {
6469// backend=stage2
6570// target=native
6671//
67// :17:14: error: missing tuple field with index 1
68// :23:14: error: missing tuple field with index 1
69// :39:14: error: expected at most 2 tuple fields; found 3
70// :45:30: error: index '2' out of bounds of tuple 'struct{comptime comptime_int = 123, u32}'
71// :58:37: error: missing tuple field with index 3
72// :53:32: note: struct declared here
72// :18:14: error: missing tuple field with index 1
73// :25:14: error: missing tuple field with index 1
74// :43:14: error: expected at most 2 tuple fields; found 3
75// :50:30: error: index '2' out of bounds of tuple 'struct{comptime comptime_int = 123, u32}'
76// :63:37: error: missing tuple field with index 3
77// :58:32: note: struct declared here
test/cases/compile_errors/uncreachable_else_prong_err_set.zig deleted-25
......@@ -1,25 +0,0 @@
1pub export fn complex() void {
2 var a: error{ Foo, Bar } = error.Foo;
3 switch (a) {
4 error.Foo => unreachable,
5 error.Bar => unreachable,
6 else => {
7 @compileError("<something complex here>");
8 },
9 }
10}
11
12pub export fn simple() void {
13 var a: error{ Foo, Bar } = error.Foo;
14 switch (a) {
15 error.Foo => unreachable,
16 error.Bar => unreachable,
17 else => |e| return e,
18 }
19}
20
21// error
22// backend=llvm
23// target=native
24//
25// :6:14: error: unreachable else prong; all cases already handled
test/cases/compile_errors/union_access_of_inactive_field.zig+1
......@@ -5,6 +5,7 @@ const U = union {
55comptime {
66 var u: U = .{ .a = {} };
77 const v = u.b;
8 _ = &u;
89 _ = v;
910}
1011
test/cases/compile_errors/union_auto-enum_value_already_taken.zig+1-1
......@@ -6,7 +6,7 @@ const MultipleChoice = union(enum(u32)) {
66 E = 60,
77};
88export fn entry() void {
9 var x = MultipleChoice{ .C = {} };
9 const x: MultipleChoice = .{ .C = {} };
1010 _ = x;
1111}
1212
test/cases/compile_errors/union_duplicate_enum_field.zig+1-1
......@@ -5,7 +5,7 @@ const U = union(E) {
55};
66
77export fn foo() void {
8 var u: U = .{ .a = 123 };
8 const u: U = .{ .a = 123 };
99 _ = u;
1010}
1111
test/cases/compile_errors/union_enum_field_does_not_match_enum.zig+1-1
......@@ -10,7 +10,7 @@ const Payload = union(Letter) {
1010 D: bool,
1111};
1212export fn entry() void {
13 var a = Payload{ .A = 1234 };
13 const a: Payload = .{ .A = 1234 };
1414 _ = a;
1515}
1616
test/cases/compile_errors/union_noreturn_field_initialized.zig+3-3
......@@ -9,7 +9,7 @@ pub export fn entry1() void {
99 };
1010
1111 var a = U{ .b = undefined };
12 _ = a;
12 _ = &a;
1313}
1414pub export fn entry2() void {
1515 const U = union(enum) {
......@@ -25,7 +25,7 @@ pub export fn entry3() void {
2525 };
2626 var e = @typeInfo(U).Union.tag_type.?.a;
2727 var u: U = undefined;
28 u = e;
28 u = (&e).*;
2929}
3030
3131// error
......@@ -38,6 +38,6 @@ pub export fn entry3() void {
3838// :19:10: error: cannot initialize 'noreturn' field of union
3939// :16:9: note: field 'a' declared here
4040// :15:15: note: union declared here
41// :28:9: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field
41// :28:13: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field
4242// :23:9: note: 'noreturn' field here
4343// :22:15: note: union declared here
test/cases/compile_errors/union_runtime_coercion_from_enum.zig+1-1
......@@ -11,7 +11,7 @@ fn foo() E {
1111}
1212export fn doTheTest() u64 {
1313 var u: U = foo();
14 return u.b;
14 return (&u).b;
1515}
1616
1717// error
test/cases/compile_errors/unreachable_else_prong_err_set.zig created+27
......@@ -0,0 +1,27 @@
1pub export fn complex() void {
2 var a: error{ Foo, Bar } = error.Foo;
3 _ = &a;
4 switch (a) {
5 error.Foo => unreachable,
6 error.Bar => unreachable,
7 else => {
8 @compileError("<something complex here>");
9 },
10 }
11}
12
13pub export fn simple() void {
14 var a: error{ Foo, Bar } = error.Foo;
15 _ = &a;
16 switch (a) {
17 error.Foo => unreachable,
18 error.Bar => unreachable,
19 else => |e| return e,
20 }
21}
22
23// error
24// backend=llvm
25// target=native
26//
27// :7:14: error: unreachable else prong; all cases already handled
test/cases/compile_errors/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig+5-6
......@@ -1,16 +1,15 @@
11export fn entry() void {
22 var x: i32 = 1234;
33 var p: *i32 = &x;
4 var pp: *?*i32 = &p;
4 const pp: *?*i32 = &p;
55 pp.* = null;
6 var y = p.*;
7 _ = y;
6 _ = p.*;
87}
98
109// error
1110// backend=stage2
1211// target=native
1312//
14// :4:22: error: expected type '*?*i32', found '**i32'
15// :4:22: note: pointer type child '*i32' cannot cast into pointer type child '?*i32'
16// :4:22: note: mutable '*i32' allows illegal null values stored to type '?*i32'
13// :4:24: error: expected type '*?*i32', found '**i32'
14// :4:24: note: pointer type child '*i32' cannot cast into pointer type child '?*i32'
15// :4:24: note: mutable '*i32' allows illegal null values stored to type '?*i32'
test/cases/compile_errors/use_invalid_number_literal_as_array_index.zig+1-1
......@@ -1,7 +1,7 @@
11var v = 25;
22export fn entry() void {
33 var arr: [v]u8 = undefined;
4 _ = arr;
4 _ = &arr;
55}
66
77// error
test/cases/compile_errors/var_never_mutated.zig created+28
......@@ -0,0 +1,28 @@
1fn entry0() void {
2 var a: u32 = 1 + 2;
3 _ = a;
4}
5
6fn entry1() void {
7 const a: u32 = 1;
8 const b: u32 = 2;
9 var c = a + b;
10 const d = c;
11 _ = d;
12}
13
14fn entry2() void {
15 var a: u32 = 123;
16 foo(a);
17}
18
19fn foo(_: u32) void {}
20
21// error
22//
23// :2:9: error: local variable is never mutated
24// :2:9: note: consider using 'const'
25// :9:9: error: local variable is never mutated
26// :9:9: note: consider using 'const'
27// :15:9: error: local variable is never mutated
28// :15:9: note: consider using 'const'
test/cases/compile_errors/variable_with_type_noreturn.zig+1-1
......@@ -1,6 +1,6 @@
11export fn entry9() void {
22 var z: noreturn = return;
3 _ = z;
3 _ = &z;
44}
55
66// error
test/cases/compile_errors/variadic_arg_validation.zig+5-4
......@@ -7,6 +7,7 @@ pub export fn entry() void {
77pub export fn entry1() void {
88 var arr: [2]u8 = undefined;
99 _ = printf("%d\n", arr);
10 _ = &arr;
1011}
1112
1213pub export fn entry2() void {
......@@ -23,7 +24,7 @@ pub export fn entry3() void {
2324//
2425// :4:33: error: integer and float literals passed to variadic function must be casted to a fixed-size number type
2526// :9:24: error: arrays must be passed by reference to variadic function
26// :13:24: error: cannot pass 'u48' to variadic function
27// :13:24: note: only integers with 0 or power of two bits are extern compatible
28// :17:24: error: cannot pass 'void' to variadic function
29// :17:24: note: 'void' is a zero bit type; for C 'void' use 'anyopaque'
27// :14:24: error: cannot pass 'u48' to variadic function
28// :14:24: note: only integers with 0 or power of two bits are extern compatible
29// :18:24: error: cannot pass 'void' to variadic function
30// :18:24: note: 'void' is a zero bit type; for C 'void' use 'anyopaque'
test/cases/compile_errors/while_loop_body_expression_ignored.zig+16-12
......@@ -6,18 +6,22 @@ export fn f1() void {
66}
77export fn f2() void {
88 var x: ?i32 = null;
9 _ = &x;
910 while (x) |_| returns();
1011}
1112export fn f3() void {
1213 var x: anyerror!i32 = error.Bad;
14 _ = &x;
1315 while (x) |_| returns() else |_| unreachable;
1416}
1517export fn f4() void {
1618 var a = true;
19 _ = &a;
1720 while (a) {} else true;
1821}
1922export fn f5() void {
2023 var a = true;
24 _ = &a;
2125 const foo = while (a) returns() else true;
2226 _ = foo;
2327}
......@@ -29,15 +33,15 @@ export fn f5() void {
2933// :5:25: error: value of type 'usize' ignored
3034// :5:25: note: all non-void values must be used
3135// :5:25: note: this error can be suppressed by assigning the value to '_'
32// :9:26: error: value of type 'usize' ignored
33// :9:26: note: all non-void values must be used
34// :9:26: note: this error can be suppressed by assigning the value to '_'
35// :13:26: error: value of type 'usize' ignored
36// :13:26: note: all non-void values must be used
37// :13:26: note: this error can be suppressed by assigning the value to '_'
38// :17:23: error: value of type 'bool' ignored
39// :17:23: note: all non-void values must be used
40// :17:23: note: this error can be suppressed by assigning the value to '_'
41// :21:34: error: value of type 'usize' ignored
42// :21:34: note: all non-void values must be used
43// :21:34: note: this error can be suppressed by assigning the value to '_'
36// :10:26: error: value of type 'usize' ignored
37// :10:26: note: all non-void values must be used
38// :10:26: note: this error can be suppressed by assigning the value to '_'
39// :15:26: error: value of type 'usize' ignored
40// :15:26: note: all non-void values must be used
41// :15:26: note: this error can be suppressed by assigning the value to '_'
42// :20:23: error: value of type 'bool' ignored
43// :20:23: note: all non-void values must be used
44// :20:23: note: this error can be suppressed by assigning the value to '_'
45// :25:34: error: value of type 'usize' ignored
46// :25:34: note: all non-void values must be used
47// :25:34: note: this error can be suppressed by assigning the value to '_'
test/cases/compile_errors/while_loop_break_value_ignored.zig+4-2
......@@ -7,6 +7,7 @@ export fn f1() void {
77 while (a) {
88 break returns();
99 }
10 _ = &a;
1011}
1112
1213export fn f2() void {
......@@ -16,6 +17,7 @@ export fn f2() void {
1617 break :outer returns();
1718 }
1819 }
20 _ = &x;
1921}
2022
2123// error
......@@ -24,5 +26,5 @@ export fn f2() void {
2426//
2527// :7:5: error: incompatible types: 'usize' and 'void'
2628// :8:22: note: type 'usize' here
27// :14:12: error: incompatible types: 'usize' and 'void'
28// :16:33: note: type 'usize' here
29// :15:12: error: incompatible types: 'usize' and 'void'
30// :17:33: note: type 'usize' here
test/cases/compile_errors/wrong_type_passed_to_panic.zig+1-1
......@@ -1,5 +1,5 @@
11export fn entry() void {
2 var e = error.Foo;
2 const e = error.Foo;
33 @panic(e);
44}
55
test/cases/compile_log.0.zig+1-1
......@@ -4,7 +4,7 @@ export fn _start() noreturn {
44 @compileLog(b, 20, f, x);
55 @compileLog(1000);
66 var bruh: usize = true;
7 _ = bruh;
7 _ = .{ &f, &bruh };
88 unreachable;
99}
1010export fn other() void {
test/cases/compile_log.1.zig+1
......@@ -1,6 +1,7 @@
11export fn _start() noreturn {
22 const b = true;
33 var f: u32 = 1;
4 _ = &f;
45 @compileLog(b, 20, f, x);
56 @compileLog(1000);
67 unreachable;
test/cases/comptime_var.0.zig+3-2
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var a: u32 = 0;
3 _ = &a;
34 comptime var b: u32 = 0;
45 if (a == 0) b = 3;
56}
......@@ -9,5 +10,5 @@ pub fn main() void {
910// target=x86_64-macos,x86_64-linux
1011// link_libc=true
1112//
12// :4:19: error: store to comptime variable depends on runtime condition
13// :4:11: note: runtime condition here
13// :5:19: error: store to comptime variable depends on runtime condition
14// :5:11: note: runtime condition here
test/cases/comptime_var.1.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var a: u32 = 0;
3 _ = &a;
34 comptime var b: u32 = 0;
45 switch (a) {
56 0 => {},
test/cases/comptime_var.5.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var a: u32 = 0;
3 _ = &a;
34 if (a == 0) {
45 comptime var b: u32 = 0;
56 b = 1;
test/cases/conditions.5.zig+1
......@@ -10,6 +10,7 @@ fn assert(ok: bool) void {
1010fn foo(ok: bool) i32 {
1111 const val: i32 = blk: {
1212 var x: i32 = 1;
13 _ = &x;
1314 if (!ok) break :blk x + @as(i32, 9);
1415 break :blk x + @as(i32, 19);
1516 };
test/cases/decl_value_arena.zig+1-1
......@@ -14,7 +14,7 @@ pub const Connection = struct {
1414
1515pub fn main() void {
1616 var conn: Connection = undefined;
17 _ = conn;
17 _ = &conn;
1818}
1919
2020// run
test/cases/enum_values.0.zig+2-2
......@@ -4,8 +4,8 @@ pub fn main() void {
44 var number1 = Number.One;
55 var number2: Number = .Two;
66 if (false) {
7 number1;
8 number2;
7 &number1;
8 &number2;
99 }
1010 const number3: Number = @enumFromInt(2);
1111 if (@intFromEnum(number3) != 2) {
test/cases/enum_values.1.zig+3
......@@ -2,7 +2,9 @@ const Number = enum { One, Two, Three };
22
33pub fn main() void {
44 var number1 = Number.One;
5 _ = &number1;
56 var number2: Number = .Two;
7 _ = &number2;
68 const number3: Number = @enumFromInt(2);
79 assert(number1 != number2);
810 assert(number2 != number3);
......@@ -10,6 +12,7 @@ pub fn main() void {
1012 assert(@intFromEnum(number2) == 1);
1113 assert(@intFromEnum(number3) == 2);
1214 var x: Number = .Two;
15 _ = &x;
1316 assert(number2 == x);
1417
1518 return;
test/cases/error_in_nested_declaration.zig+1-1
......@@ -19,7 +19,7 @@ const S2 = struct {
1919
2020pub export fn entry2() void {
2121 var s: S2 = undefined;
22 _ = s;
22 _ = &s;
2323}
2424
2525// error
test/cases/error_unions.0.zig+1
......@@ -1,6 +1,7 @@
11pub fn main() void {
22 var e1 = error.Foo;
33 var e2 = error.Bar;
4 _ = .{ &e1, &e2 };
45 assert(e1 != e2);
56 assert(e1 == error.Foo);
67 assert(e2 == error.Bar);
test/cases/error_unions.1.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() u8 {
22 var e: anyerror!u8 = 5;
3 _ = &e;
34 const i = e catch 10;
45 return i - 5;
56}
test/cases/error_unions.2.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() u8 {
22 var e: anyerror!u8 = error.Foo;
3 _ = &e;
34 const i = e catch 10;
45 return i - 10;
56}
test/cases/error_unions.3.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() u8 {
22 var e = foo();
3 _ = &e;
34 const i = e catch 69;
45 return i - 5;
56}
test/cases/error_unions.4.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() u8 {
22 var e = foo();
3 _ = &e;
34 const i = e catch 69;
45 return i - 69;
56}
test/cases/error_unions.5.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() u8 {
22 var e = foo();
3 _ = &e;
34 const i = e catch 42;
45 return i - 42;
56}
test/cases/f32_passed_to_variadic_fn.zig+2-2
......@@ -2,8 +2,8 @@ extern fn printf(format: [*:0]const u8, ...) c_int;
22pub fn main() void {
33 var a: f64 = 2.0;
44 var b: f32 = 10.0;
5 _ = printf("f64: %f\n", a);
6 _ = printf("f32: %f\n", b);
5 _ = printf("f64: %f\n", (&a).*);
6 _ = printf("f32: %f\n", (&b).*);
77}
88
99// run
test/cases/inner_func_accessing_outer_var.zig+3-2
......@@ -1,5 +1,6 @@
11pub fn f() void {
22 var bar: bool = true;
3 _ = &bar;
34 const S = struct {
45 fn baz() bool {
56 return bar;
......@@ -10,6 +11,6 @@ pub fn f() void {
1011
1112// error
1213//
13// :5:20: error: mutable 'bar' not accessible from here
14// :6:20: error: mutable 'bar' not accessible from here
1415// :2:9: note: declared mutable here
15// :3:15: note: crosses namespace boundary here
16// :4:15: note: crosses namespace boundary here
test/cases/llvm/blocks.zig+1
......@@ -5,6 +5,7 @@ fn assert(ok: bool) void {
55fn foo(ok: bool) i32 {
66 const val: i32 = blk: {
77 var x: i32 = 1;
8 _ = &x;
89 if (!ok) break :blk x + 9;
910 break :blk x + 19;
1011 };
test/cases/llvm/f_segment_address_space_reading_and_writing.zig+1
......@@ -35,6 +35,7 @@ pub fn main() void {
3535 assert(getFs() == @intFromPtr(&test_value));
3636
3737 var test_ptr: *allowzero addrspace(.fs) u64 = @ptrFromInt(0);
38 _ = &test_ptr;
3839 assert(test_ptr.* == 12345);
3940 test_ptr.* = 98765;
4041 assert(test_value == 98765);
test/cases/llvm/nested_blocks.zig+1-1
......@@ -10,7 +10,7 @@ fn foo(ok: bool) i32 {
1010 };
1111 break :blk val2 + 10;
1212 };
13 return val;
13 return (&val).*;
1414}
1515
1616pub fn main() void {
test/cases/llvm/optionals.zig+4
......@@ -7,8 +7,10 @@ pub fn main() void {
77 var null_val: ?i32 = null;
88
99 var val1: i32 = opt_val.?;
10 _ = &val1;
1011 const val1_1: i32 = opt_val.?;
1112 var ptr_val1 = &(opt_val.?);
13 _ = &ptr_val1;
1214 const ptr_val1_1 = &(opt_val.?);
1315
1416 var val2: i32 = null_val orelse 20;
......@@ -16,9 +18,11 @@ pub fn main() void {
1618
1719 var value: i32 = 20;
1820 var ptr_val2 = &(null_val orelse value);
21 _ = &ptr_val2;
1922
2023 const val3 = opt_val orelse 30;
2124 var val3_var = opt_val orelse 30;
25 _ = &val3_var;
2226
2327 assert(val1 == 10);
2428 assert(val1_1 == 10);
test/cases/llvm/simple_addition_and_subtraction.zig+1
......@@ -4,6 +4,7 @@ fn add(a: i32, b: i32) i32 {
44
55pub fn main() void {
66 var a: i32 = -5;
7 _ = &a;
78 const x = add(a, 7);
89 var y = add(2, 0);
910 y -= x;
test/cases/locals.0.zig+2-2
......@@ -3,8 +3,8 @@ pub fn main() void {
33 var y: f32 = 42.0;
44 var x: u8 = 10;
55 if (false) {
6 y;
7 x;
6 &y;
7 &x / &i;
88 }
99 if (i != 5) unreachable;
1010}
test/cases/locals.1.zig+2-1
......@@ -1,8 +1,9 @@
11pub fn main() void {
22 var i: u8 = 5;
33 var y: f32 = 42.0;
4 _ = y;
4 _ = &y;
55 var x: u8 = 10;
6 _ = &x;
67 foo(i, x);
78 i = x;
89 if (i != 10) unreachable;
test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var x: usize = 5;
3 _ = &x;
34 const y = mul(2, 3, x);
45 if (y - 30 != 0) unreachable;
56}
test/cases/only_1_function_and_it_gets_updated.1.zig+1-1
......@@ -1,6 +1,6 @@
11pub export fn _start() noreturn {
22 var dummy: u32 = 10;
3 _ = dummy;
3 _ = &dummy;
44 while (true) {}
55}
66
test/cases/optionals.0.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() u8 {
22 var x: ?u8 = 5;
3 _ = &x;
34 var y: u8 = 0;
45 if (x) |val| {
56 y = val;
test/cases/optionals.1.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() u8 {
22 var x: ?u8 = null;
3 _ = &x;
34 var y: u8 = 0;
45 if (x) |val| {
56 y = val;
test/cases/optionals.2.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() u8 {
22 var x: ?u8 = 5;
3 _ = &x;
34 return x.? - 5;
45}
56
test/cases/optionals.3.zig+1
......@@ -1,6 +1,7 @@
11pub fn main() u8 {
22 var x: u8 = 5;
33 var y: ?u8 = x;
4 _ = .{ &x, &y };
45 return y.? - 5;
56}
67
test/cases/runtime_bitwise_and.zig+1
......@@ -7,6 +7,7 @@ pub fn main() void {
77 var m2: u32 = 0b0000;
88 assert(m1 & 0b1010 == 0b1010);
99 assert(m2 & 0b1010 == 0b0000);
10 _ = .{ &i, &j, &m1, &m2 };
1011}
1112fn assert(b: bool) void {
1213 if (!b) unreachable;
test/cases/runtime_bitwise_or.zig+1
......@@ -7,6 +7,7 @@ pub fn main() void {
77 var m2: u32 = 0b0000;
88 assert(m1 | 0b1010 == 0b1111);
99 assert(m2 | 0b1010 == 0b1010);
10 _ = .{ &i, &j, &m1, &m2 };
1011}
1112fn assert(b: bool) void {
1213 if (!b) unreachable;
test/cases/safety/@asyncCall with too small a frame.zig +2-1
......@@ -13,8 +13,9 @@ pub fn main() !void {
1313 }
1414 var bytes: [1]u8 align(16) = undefined;
1515 var ptr = other;
16 _ = &ptr;
1617 var frame = @asyncCall(&bytes, {}, ptr, .{});
17 _ = frame;
18 _ = &frame;
1819 return error.TestFailed;
1920}
2021fn other() callconv(.Async) void {
test/cases/safety/@intCast to u0.zig +1-1
......@@ -14,7 +14,7 @@ pub fn main() !void {
1414}
1515
1616fn bar(one: u1, not_zero: i32) void {
17 var x = one << @as(u0, @intCast(not_zero));
17 const x = one << @intCast(not_zero);
1818 _ = x;
1919}
2020// run
test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig +2-1
......@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010pub fn main() !void {
1111 var zero: usize = 0;
12 var b: *u8 = @ptrFromInt(zero);
12 _ = &zero;
13 const b: *u8 = @ptrFromInt(zero);
1314 _ = b;
1415 return error.TestFailed;
1516}
test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig +2-1
......@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010pub fn main() !void {
1111 var zero: usize = 0;
12 var b: *i32 = @ptrFromInt(zero);
12 _ = &zero;
13 const b: *i32 = @ptrFromInt(zero);
1314 _ = b;
1415 return error.TestFailed;
1516}
test/cases/safety/@ptrFromInt with misaligned address.zig +2-1
......@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010pub fn main() !void {
1111 var x: usize = 5;
12 var y: [*]align(4) u8 = @ptrFromInt(x);
12 _ = &x;
13 const y: [*]align(4) u8 = @ptrFromInt(x);
1314 _ = y;
1415 return error.TestFailed;
1516}
test/cases/safety/@tagName on corrupted enum value.zig +1-1
......@@ -16,7 +16,7 @@ const E = enum(u32) {
1616pub fn main() !void {
1717 var e: E = undefined;
1818 @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55);
19 var n = @tagName(e);
19 const n = @tagName(e);
2020 _ = n;
2121 return error.TestFailed;
2222}
test/cases/safety/@tagName on corrupted union value.zig +2-2
......@@ -16,8 +16,8 @@ const U = union(enum(u32)) {
1616pub fn main() !void {
1717 var u: U = undefined;
1818 @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55);
19 var t: @typeInfo(U).Union.tag_type.? = u;
20 var n = @tagName(t);
19 const t: @typeInfo(U).Union.tag_type.? = u;
20 const n = @tagName(t);
2121 _ = n;
2222 return error.TestFailed;
2323}
test/cases/safety/array slice sentinel mismatch non-scalar.zig +1-1
......@@ -11,7 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1111pub fn main() !void {
1212 const S = struct { a: u32 };
1313 var arr = [_]S{ .{ .a = 1 }, .{ .a = 2 } };
14 var s = arr[0..1 :.{ .a = 1 }];
14 const s = arr[0..1 :.{ .a = 1 }];
1515 _ = s;
1616 return error.TestFailed;
1717}
test/cases/safety/exact division failure - vectors.zig +2-2
......@@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010
1111pub fn main() !void {
12 var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };
13 var b: @Vector(4, i32) = [4]i32{ 111, 222, 333, 441 };
12 const a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };
13 const b: @Vector(4, i32) = [4]i32{ 111, 222, 333, 441 };
1414 const x = divExact(a, b);
1515 _ = x;
1616 return error.TestFailed;
test/cases/safety/for_len_mismatch.zig+1
......@@ -12,6 +12,7 @@ pub fn main() !void {
1212 var runtime_i: usize = 1;
1313 var j: usize = 3;
1414 var slice = "too long";
15 _ = .{ &runtime_i, &j, &slice };
1516 for (runtime_i..j, slice) |a, b| {
1617 _ = a;
1718 _ = b;
test/cases/safety/for_len_mismatch_three.zig+1
......@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
1111pub fn main() !void {
1212 var slice: []const u8 = "hello";
13 _ = &slice;
1314 for (10..20, slice, 20..30) |a, b, c| {
1415 _ = a;
1516 _ = b;
test/cases/safety/integer division by zero - vectors.zig +2-2
......@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
88 std.process.exit(1);
99}
1010pub fn main() !void {
11 var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };
12 var b: @Vector(4, i32) = [4]i32{ 111, 0, 333, 444 };
11 const a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };
12 const b: @Vector(4, i32) = [4]i32{ 111, 0, 333, 444 };
1313 const x = div0(a, b);
1414 _ = x;
1515 return error.TestFailed;
test/cases/safety/memcpy_alias.zig+1
......@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010pub fn main() !void {
1111 var buffer = [2]u8{ 1, 2 } ** 5;
1212 var len: usize = 5;
13 _ = &len;
1314 @memcpy(buffer[0..len], buffer[4 .. 4 + len]);
1415}
1516// run
test/cases/safety/memcpy_len_mismatch.zig+1
......@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010pub fn main() !void {
1111 var buffer = [2]u8{ 1, 2 } ** 5;
1212 var len: usize = 5;
13 _ = &len;
1314 @memcpy(buffer[0..len], buffer[len .. len + 4]);
1415}
1516// run
test/cases/safety/memset_slice_undefined_bytes.zig+1
......@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010pub fn main() !void {
1111 var buffer = [6]u8{ 1, 2, 3, 4, 5, 6 };
1212 var len = buffer.len;
13 _ = &len;
1314 @memset(buffer[0..len], undefined);
1415 var x: u8 = buffer[1];
1516 x += buffer[2];
test/cases/safety/memset_slice_undefined_large.zig+1
......@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010pub fn main() !void {
1111 var buffer = [6]i32{ 1, 2, 3, 4, 5, 6 };
1212 var len = buffer.len;
13 _ = &len;
1314 @memset(buffer[0..len], undefined);
1415 var x: i32 = buffer[1];
1516 x += buffer[2];
test/cases/safety/optional unwrap operator on C pointer.zig +2-1
......@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010pub fn main() !void {
1111 var ptr: [*c]i32 = null;
12 var b = ptr.?;
12 _ = &ptr;
13 const b = ptr.?;
1314 _ = b;
1415 return error.TestFailed;
1516}
test/cases/safety/optional unwrap operator on null pointer.zig +2-1
......@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010pub fn main() !void {
1111 var ptr: ?*i32 = null;
12 var b = ptr.?;
12 _ = &ptr;
13 const b = ptr.?;
1314 _ = b;
1415 return error.TestFailed;
1516}
test/cases/safety/pointer casting null to non-optional pointer.zig +2-1
......@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
1111pub fn main() !void {
1212 var c_ptr: [*c]u8 = 0;
13 var zig_ptr: *u8 = c_ptr;
13 _ = &c_ptr;
14 const zig_ptr: *u8 = c_ptr;
1415 _ = zig_ptr;
1516 return error.TestFailed;
1617}
test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig +1-1
......@@ -10,7 +10,7 @@ fn foo() void {
1010 global_frame = @frame();
1111 }
1212 var f = async bar(@frame());
13 _ = f;
13 _ = &f;
1414 std.os.exit(1);
1515}
1616
test/cases/safety/resuming a non-suspended function which never been suspended.zig +1-1
......@@ -7,7 +7,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
77}
88fn foo() void {
99 var f = async bar(@frame());
10 _ = f;
10 _ = &f;
1111 std.os.exit(1);
1212}
1313
test/cases/safety/shift left by huge amount.zig +2-1
......@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1111pub fn main() !void {
1212 var x: u24 = 42;
1313 var y: u5 = 24;
14 var z = x >> y;
14 _ = .{ &x, &y };
15 const z = x >> y;
1516 _ = z;
1617 return error.TestFailed;
1718}
test/cases/safety/shift right by huge amount.zig +2-1
......@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1111pub fn main() !void {
1212 var x: u24 = 42;
1313 var y: u5 = 24;
14 var z = x << y;
14 _ = .{ &x, &y };
15 const z = x << y;
1516 _ = z;
1617 return error.TestFailed;
1718}
test/cases/safety/signed integer division overflow - vectors.zig +2-2
......@@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010
1111pub fn main() !void {
12 var a: @Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };
13 var b: @Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };
12 const a: @Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };
13 const b: @Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };
1414 const x = div(a, b);
1515 if (x[2] == 32767) return error.Whatever;
1616 return error.TestFailed;
test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig +2-1
......@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010pub fn main() !void {
1111 var value: c_short = -1;
12 var casted: u32 = @intCast(value);
12 _ = &value;
13 const casted: u32 = @intCast(value);
1314 _ = casted;
1415 return error.TestFailed;
1516}
test/cases/safety/signed-unsigned vector cast.zig +2-1
......@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
1111pub fn main() !void {
1212 var x: @Vector(4, i32) = @splat(-2147483647);
13 var y: @Vector(4, u32) = @intCast(x);
13 _ = &x;
14 const y: @Vector(4, u32) = @intCast(x);
1415 _ = y;
1516 return error.TestFailed;
1617}
test/cases/safety/slice start index greater than end index.zig +1
......@@ -11,6 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1111pub fn main() !void {
1212 var a: usize = 1;
1313 var b: usize = 10;
14 _ = .{ &a, &b };
1415 var buf: [16]u8 = undefined;
1516
1617 const slice = buf[b..a];
test/cases/safety/slice with sentinel out of bounds - runtime len.zig +1
......@@ -12,6 +12,7 @@ pub fn main() !void {
1212 var buf = [4]u8{ 'a', 'b', 'c', 0 };
1313 const input: []u8 = &buf;
1414 var len: usize = 4;
15 _ = &len;
1516 const slice = input[0..len :0];
1617 _ = slice;
1718 return error.TestFailed;
test/cases/safety/slicing null C pointer - runtime len.zig +2-1
......@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1111pub fn main() !void {
1212 var ptr: [*c]const u32 = null;
1313 var len: usize = 3;
14 var slice = ptr[0..len];
14 _ = &len;
15 const slice = ptr[0..len];
1516 _ = slice;
1617 return error.TestFailed;
1718}
test/cases/safety/slicing null C pointer.zig +2-1
......@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
1111pub fn main() !void {
1212 var ptr: [*c]const u32 = null;
13 var slice = ptr[0..3];
13 _ = &ptr;
14 const slice = ptr[0..3];
1415 _ = slice;
1516 return error.TestFailed;
1617}
test/cases/safety/truncating vector cast.zig +2-1
......@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
1111pub fn main() !void {
1212 var x: @Vector(4, u32) = @splat(0xdeadbeef);
13 var y: @Vector(4, u16) = @intCast(x);
13 _ = &x;
14 const y: @Vector(4, u16) = @intCast(x);
1415 _ = y;
1516 return error.TestFailed;
1617}
test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig +2-1
......@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010pub fn main() !void {
1111 var value: u8 = 245;
12 var casted: i8 = @intCast(value);
12 _ = &value;
13 const casted: i8 = @intCast(value);
1314 _ = casted;
1415 return error.TestFailed;
1516}
test/cases/safety/unsigned-signed vector cast.zig +2-1
......@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
1111pub fn main() !void {
1212 var x: @Vector(4, u32) = @splat(0x80000000);
13 var y: @Vector(4, i32) = @intCast(x);
13 _ = &x;
14 const y: @Vector(4, i32) = @intCast(x);
1415 _ = y;
1516 return error.TestFailed;
1617}
test/cases/safety/vector integer addition overflow.zig +2-2
......@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
88 std.process.exit(1);
99}
1010pub fn main() !void {
11 var a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
12 var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
11 const a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
12 const b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
1313 const x = add(a, b);
1414 _ = x;
1515 return error.TestFailed;
test/cases/safety/vector integer multiplication overflow.zig +2-2
......@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
88 std.process.exit(1);
99}
1010pub fn main() !void {
11 var a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
12 var b: @Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };
11 const a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
12 const b: @Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };
1313 const x = mul(b, a);
1414 _ = x;
1515 return error.TestFailed;
test/cases/safety/vector integer negation overflow.zig +1
......@@ -9,6 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010pub fn main() !void {
1111 var a: @Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };
12 _ = &a;
1213 const x = neg(a);
1314 _ = x;
1415 return error.TestFailed;
test/cases/safety/vector integer subtraction overflow.zig +2-2
......@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
88 std.process.exit(1);
99}
1010pub fn main() !void {
11 var a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
12 var b: @Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };
11 const a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
12 const b: @Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };
1313 const x = sub(b, a);
1414 _ = x;
1515 return error.TestFailed;
test/cases/structs.0.zig+1
......@@ -2,6 +2,7 @@ const Example = struct { x: u8 };
22
33pub fn main() u8 {
44 var example: Example = .{ .x = 5 };
5 _ = &example;
56 return example.x - 5;
67}
78
test/cases/structs.2.zig+1
......@@ -2,6 +2,7 @@ const Example = struct { x: u8, y: u8 };
22
33pub fn main() u8 {
44 var example: Example = .{ .x = 5, .y = 10 };
5 _ = &example;
56 return example.y + example.x - 15;
67}
78
test/cases/structs.3.zig+1
......@@ -3,6 +3,7 @@ const Example = struct { x: u8, y: u8 };
33pub fn main() u8 {
44 var example: Example = .{ .x = 5, .y = 10 };
55 var example2: Example = .{ .x = 10, .y = 20 };
6 _ = &example2;
67
78 example = example2;
89 return example.y + example.x - 30;
test/cases/switch.0.zig+2-1
......@@ -1,6 +1,7 @@
11pub fn main() u8 {
22 var val: u8 = 1;
3 var a: u8 = switch (val) {
3 _ = &val;
4 const a: u8 = switch (val) {
45 0, 1 => 2,
56 2 => 3,
67 3 => 4,
test/cases/switch.1.zig+2
......@@ -1,11 +1,13 @@
11pub fn main() u8 {
22 var val: u8 = 2;
3 _ = &val;
34 var a: u8 = switch (val) {
45 0, 1 => 2,
56 2 => 3,
67 3 => 4,
78 else => 5,
89 };
10 _ = &a;
911
1012 return a - 3;
1113}
test/cases/switch.2.zig+2-1
......@@ -1,6 +1,7 @@
11pub fn main() u8 {
22 var val: u8 = 10;
3 var a: u8 = switch (val) {
3 _ = &val;
4 const a: u8 = switch (val) {
45 0, 1 => 2,
56 2 => 3,
67 3 => 4,
test/cases/switch.3.zig+2-1
......@@ -2,7 +2,8 @@ const MyEnum = enum { One, Two, Three };
22
33pub fn main() u8 {
44 var val: MyEnum = .Two;
5 var a: u8 = switch (val) {
5 _ = &val;
6 const a: u8 = switch (val) {
67 .One => 1,
78 .Two => 2,
89 .Three => 3,
test/cases/type_of.0.zig+1
......@@ -1,5 +1,6 @@
11pub fn main() void {
22 var x: usize = 0;
3 _ = &x;
34 const z = @TypeOf(x, @as(u128, 5));
45 assert(z == u128);
56}
test/cases/while_loops.1.zig+1
......@@ -2,6 +2,7 @@ pub fn main() u8 {
22 var i: u8 = 0;
33 while (i < @as(u8, 10)) {
44 var x: u8 = 1;
5 _ = &x;
56 i += x;
67 }
78 return i - 10;
test/cases/while_loops.2.zig+1
......@@ -2,6 +2,7 @@ pub fn main() u8 {
22 var i: u8 = 0;
33 while (i < @as(u8, 10)) {
44 var x: u8 = 1;
5 _ = &x;
56 i += x;
67 if (i == @as(u8, 5)) break;
78 }
test/compare_output.zig+2-2
......@@ -165,7 +165,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
165165 \\const y : u16 = 5678;
166166 \\pub fn main() void {
167167 \\ var x_local : i32 = print_ok(x);
168 \\ _ = x_local;
168 \\ _ = &x_local;
169169 \\}
170170 \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) {
171171 \\ _ = val;
......@@ -504,7 +504,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
504504 \\
505505 \\pub fn main() !void {
506506 \\ var allocator_buf: [10]u8 = undefined;
507 \\ var fba = std.heap.FixedBufferAllocator.init(&allocator_buf);
507 \\ const fba = std.heap.FixedBufferAllocator.init(&allocator_buf);
508508 \\ var fba_wrapped = std.mem.validationWrap(fba);
509509 \\ var logging_allocator = std.heap.loggingAllocator(fba_wrapped.allocator());
510510 \\ const allocator = logging_allocator.allocator();
test/link/wasm/archive/main.zig+2-1
......@@ -1,6 +1,7 @@
11export fn foo() void {
22 var a: f16 = 2.2;
3 _ = &a;
34 // this will pull-in compiler-rt
4 var b = @trunc(a);
5 const b = @trunc(a);
56 _ = b;
67}
test/src/Cases.zig+2-5
......@@ -1161,10 +1161,7 @@ const TestManifest = struct {
11611161 fn getDefaultParser(comptime T: type) ParseFn(T) {
11621162 if (T == CrossTarget) return struct {
11631163 fn parse(str: []const u8) anyerror!T {
1164 var opts = CrossTarget.ParseOptions{
1165 .arch_os_abi = str,
1166 };
1167 return try CrossTarget.parse(opts);
1164 return CrossTarget.parse(.{ .arch_os_abi = str });
11681165 }
11691166 }.parse;
11701167
......@@ -1691,7 +1688,7 @@ fn runOneCase(
16911688 var argv = std.ArrayList([]const u8).init(allocator);
16921689 defer argv.deinit();
16931690
1694 var exec_result = x: {
1691 const exec_result = x: {
16951692 var exec_node = update_node.start("execute", 0);
16961693 exec_node.activate();
16971694 defer exec_node.end();
test/standalone/extern/main.zig+2-2
......@@ -6,8 +6,8 @@ const getHidden = @extern(*const fn () callconv(.C) u32, .{ .name = "getHidden"
66const T = extern struct { x: u32 };
77
88test {
9 var mut_val_ptr = @extern(*f64, .{ .name = "mut_val" });
10 var const_val_ptr = @extern(*const T, .{ .name = "const_val" });
9 const mut_val_ptr = @extern(*f64, .{ .name = "mut_val" });
10 const const_val_ptr = @extern(*const T, .{ .name = "const_val" });
1111
1212 assert(getHidden() == 0);
1313 updateHidden(123);
test/standalone/main_return_error/error_u8_non_zero.zig+1-2
......@@ -1,8 +1,7 @@
11const Err = error{Foo};
22
33fn foo() u8 {
4 var x = @as(u8, @intCast(9));
5 return x;
4 return @intCast(9);
65}
76
87pub fn main() !u8 {
test/standalone/stack_iterator/shared_lib_unwind.zig+1-1
......@@ -9,7 +9,7 @@ noinline fn frame4(expected: *[5]usize, unwound: *[5]usize) void {
99 var context: debug.ThreadContext = undefined;
1010 testing.expect(debug.getContext(&context)) catch @panic("failed to getContext");
1111
12 var debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo");
12 const debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo");
1313 var it = debug.StackIterator.initWithContext(expected[0], debug_info, &context) catch @panic("failed to initWithContext");
1414 defer it.deinit();
1515
test/standalone/stack_iterator/unwind.zig+2-2
......@@ -9,7 +9,7 @@ noinline fn frame3(expected: *[4]usize, unwound: *[4]usize) void {
99 var context: debug.ThreadContext = undefined;
1010 testing.expect(debug.getContext(&context)) catch @panic("failed to getContext");
1111
12 var debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo");
12 const debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo");
1313 var it = debug.StackIterator.initWithContext(expected[0], debug_info, &context) catch @panic("failed to initWithContext");
1414 defer it.deinit();
1515
......@@ -76,7 +76,7 @@ noinline fn frame1(expected: *[4]usize, unwound: *[4]usize) void {
7676 // Use a stack frame that is too big to encode in __unwind_info's stack-immediate encoding
7777 // to exercise the stack-indirect encoding path
7878 var pad: [std.math.maxInt(u8) * @sizeOf(usize) + 1]u8 = undefined;
79 _ = pad;
79 _ = std.mem.doNotOptimizeAway(&pad);
8080
8181 frame2(expected, unwound);
8282}
test/standalone/use_alias/main.zig+1
......@@ -6,5 +6,6 @@ test "symbol exists" {
66 .a = 1,
77 .b = 1,
88 };
9 _ = &foo;
910 try expect(foo.a + foo.b == 2);
1011}
test/standalone/windows_spawn/main.zig+1-1
......@@ -158,7 +158,7 @@ fn testExec(allocator: std.mem.Allocator, command: []const u8, expected_stdout:
158158}
159159
160160fn testExecWithCwd(allocator: std.mem.Allocator, command: []const u8, cwd: ?[]const u8, expected_stdout: []const u8) !void {
161 var result = try std.ChildProcess.run(.{
161 const result = try std.ChildProcess.run(.{
162162 .allocator = allocator,
163163 .argv = &[_][]const u8{command},
164164 .cwd = cwd,
test/standalone/zerolength_check/src/main.zig+3-3
......@@ -1,14 +1,14 @@
11const std = @import("std");
22
33test {
4 var dest = foo();
5 var source = foo();
4 const dest = foo();
5 const source = foo();
66
77 @memcpy(dest, source);
88 @memset(dest, 4);
99 @memset(dest, undefined);
1010
11 var dest2 = foo2();
11 const dest2 = foo2();
1212 @memset(dest2, 0);
1313}
1414
test/translate_c.zig+237-59
......@@ -37,6 +37,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3737 , &[_][]const u8{
3838 \\pub export fn foo(arg_a: c_int) void {
3939 \\ var a = arg_a;
40 \\ _ = &a;
4041 \\ while (true) {
4142 \\ if (a != 0) break;
4243 \\ }
......@@ -81,9 +82,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
8182 , &[_][]const u8{
8283 \\pub export fn foo(arg_x: c_ulong) c_ulong {
8384 \\ var x = arg_x;
85 \\ _ = &x;
8486 \\ const union_unnamed_1 = extern union {
8587 \\ _x: c_ulong,
8688 \\ };
89 \\ _ = &union_unnamed_1;
8790 \\ return (union_unnamed_1{
8891 \\ ._x = x,
8992 \\ })._x;
......@@ -123,10 +126,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
123126 \\pub export fn foo() void {
124127 \\ while (true) if (true) {
125128 \\ var a: c_int = 1;
126 \\ _ = @TypeOf(a);
129 \\ _ = &a;
127130 \\ } else {
128131 \\ var b: c_int = 2;
129 \\ _ = @TypeOf(b);
132 \\ _ = &b;
130133 \\ };
131134 \\ if (true) if (true) {};
132135 \\}
......@@ -142,6 +145,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
142145 \\pub extern fn bar(...) c_int;
143146 \\pub export fn foo() void {
144147 \\ var a: c_int = undefined;
148 \\ _ = &a;
145149 \\ if (a != 0) a = 2 else _ = bar();
146150 \\}
147151 });
......@@ -194,24 +198,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
194198 \\ B: c_int = @import("std").mem.zeroes(c_int),
195199 \\ C: c_int = @import("std").mem.zeroes(c_int),
196200 \\ };
201 \\ _ = &struct_Foo;
197202 \\ var a: struct_Foo = struct_Foo{
198203 \\ .A = @as(c_int, 0),
199204 \\ .B = 0,
200205 \\ .C = 0,
201206 \\ };
202 \\ _ = @TypeOf(a);
207 \\ _ = &a;
203208 \\ {
204209 \\ const struct_Foo_1 = extern struct {
205210 \\ A: c_int = @import("std").mem.zeroes(c_int),
206211 \\ B: c_int = @import("std").mem.zeroes(c_int),
207212 \\ C: c_int = @import("std").mem.zeroes(c_int),
208213 \\ };
214 \\ _ = &struct_Foo_1;
209215 \\ var a_2: struct_Foo_1 = struct_Foo_1{
210216 \\ .A = @as(c_int, 0),
211217 \\ .B = 0,
212218 \\ .C = 0,
213219 \\ };
214 \\ _ = @TypeOf(a_2);
220 \\ _ = &a_2;
215221 \\ }
216222 \\}
217223 });
......@@ -240,24 +246,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
240246 \\ B: c_int,
241247 \\ C: c_int,
242248 \\ };
243 \\ _ = @TypeOf(union_unnamed_1);
249 \\ _ = &union_unnamed_1;
244250 \\ const Foo = union_unnamed_1;
251 \\ _ = &Foo;
245252 \\ var a: Foo = Foo{
246253 \\ .A = @as(c_int, 0),
247254 \\ };
248 \\ _ = @TypeOf(a);
255 \\ _ = &a;
249256 \\ {
250257 \\ const union_unnamed_2 = extern union {
251258 \\ A: c_int,
252259 \\ B: c_int,
253260 \\ C: c_int,
254261 \\ };
255 \\ _ = @TypeOf(union_unnamed_2);
262 \\ _ = &union_unnamed_2;
256263 \\ const Foo_1 = union_unnamed_2;
264 \\ _ = &Foo_1;
257265 \\ var a_2: Foo_1 = Foo_1{
258266 \\ .A = @as(c_int, 0),
259267 \\ };
260 \\ _ = @TypeOf(a_2);
268 \\ _ = &a_2;
261269 \\ }
262270 \\}
263271 });
......@@ -268,6 +276,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
268276 \\#define MEM_PHYSICAL_TO_K0(x) (void*)((uint32_t)(x) + SYS_BASE_CACHED)
269277 , &[_][]const u8{
270278 \\pub inline fn MEM_PHYSICAL_TO_K0(x: anytype) ?*anyopaque {
279 \\ _ = &x;
271280 \\ return @import("std").zig.c_translation.cast(?*anyopaque, @import("std").zig.c_translation.cast(u32, x) + SYS_BASE_CACHED);
272281 \\}
273282 });
......@@ -310,6 +319,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
310319 \\pub const VALUE = ((((@as(c_int, 1) + (@as(c_int, 2) * @as(c_int, 3))) + (@as(c_int, 4) * @as(c_int, 5))) + @as(c_int, 6)) << @as(c_int, 7)) | @intFromBool(@as(c_int, 8) == @as(c_int, 9));
311320 ,
312321 \\pub inline fn _AL_READ3BYTES(p: anytype) @TypeOf((@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16))) {
322 \\ _ = &p;
313323 \\ return (@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16));
314324 \\}
315325 });
......@@ -325,7 +335,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
325335 \\ const bar_1 = struct {
326336 \\ threadlocal var static: c_int = 2;
327337 \\ };
328 \\ _ = @TypeOf(bar_1);
338 \\ _ = &bar_1;
329339 \\ return 0;
330340 \\}
331341 });
......@@ -344,7 +354,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
344354 \\}
345355 \\pub export fn bar() c_int {
346356 \\ var a: c_int = 2;
347 \\ _ = @TypeOf(a);
357 \\ _ = &a;
348358 \\ return 0;
349359 \\}
350360 \\pub export fn baz() c_int {
......@@ -359,7 +369,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
359369 , &[_][]const u8{
360370 \\pub export fn main() void {
361371 \\ var a: c_int = @as(c_int, @bitCast(@as(c_uint, @truncate(@alignOf(c_int)))));
362 \\ _ = @TypeOf(a);
372 \\ _ = &a;
363373 \\}
364374 });
365375
......@@ -390,6 +400,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
390400 \\pub const Color = struct_Color;
391401 ,
392402 \\pub inline fn CLITERAL(@"type": anytype) @TypeOf(@"type") {
403 \\ _ = &@"type";
393404 \\ return @"type";
394405 \\}
395406 ,
......@@ -407,6 +418,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
407418 \\};
408419 ,
409420 \\pub inline fn A(_x: anytype) MyCStruct {
421 \\ _ = &_x;
410422 \\ return @import("std").mem.zeroInit(MyCStruct, .{
411423 \\ .x = _x,
412424 \\ });
......@@ -438,6 +450,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
438450 \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0)
439451 , &[_][]const u8{
440452 \\pub inline fn __ferror_unlocked_body(_fp: anytype) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0)) {
453 \\ _ = &_fp;
441454 \\ return (_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0);
442455 \\}
443456 });
......@@ -447,6 +460,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
447460 \\#define BAR 1 && 2 > 4
448461 , &[_][]const u8{
449462 \\pub inline fn FOO(x: anytype) @TypeOf(@intFromBool(x >= @as(c_int, 0)) + @intFromBool(x >= @as(c_int, 0))) {
463 \\ _ = &x;
450464 \\ return @intFromBool(x >= @as(c_int, 0)) + @intFromBool(x >= @as(c_int, 0));
451465 \\}
452466 ,
......@@ -507,11 +521,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
507521 \\#define bar(x) (&x, +3, 4 == 4, 5 * 6, baz(1, 2), 2 % 2, baz(1,2))
508522 , &[_][]const u8{
509523 \\pub const foo = blk_1: {
510 \\ _ = @TypeOf(foo);
524 \\ _ = &foo;
511525 \\ break :blk_1 bar;
512526 \\};
513527 ,
514528 \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) {
529 \\ _ = &x;
515530 \\ return blk_1: {
516531 \\ _ = &x;
517532 \\ _ = @as(c_int, 3);
......@@ -642,6 +657,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
642657 \\};
643658 \\pub export fn foo(arg_x: [*c]outer) void {
644659 \\ var x = arg_x;
660 \\ _ = &x;
645661 \\ x.*.unnamed_0.unnamed_0.y = @as(c_int, @bitCast(@as(c_uint, x.*.unnamed_0.x)));
646662 \\}
647663 });
......@@ -728,8 +744,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
728744 \\pub const struct_opaque_2 = opaque {};
729745 \\pub export fn function(arg_opaque_1: ?*struct_opaque) void {
730746 \\ var opaque_1 = arg_opaque_1;
747 \\ _ = &opaque_1;
731748 \\ var cast: ?*struct_opaque_2 = @as(?*struct_opaque_2, @ptrCast(opaque_1));
732 \\ _ = @TypeOf(cast);
749 \\ _ = &cast;
733750 \\}
734751 });
735752
......@@ -764,7 +781,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
764781 \\pub export fn my_fn() align(128) void {}
765782 \\pub export fn other_fn() void {
766783 \\ var ARR: [16]u8 align(16) = undefined;
767 \\ _ = @TypeOf(ARR);
784 \\ _ = &ARR;
768785 \\}
769786 });
770787 }
......@@ -801,17 +818,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
801818 , &[_][]const u8{
802819 \\pub export fn foo() void {
803820 \\ var a: c_int = undefined;
804 \\ _ = @TypeOf(a);
821 \\ _ = &a;
805822 \\ var b: u8 = 123;
806 \\ _ = @TypeOf(b);
823 \\ _ = &b;
807824 \\ const c: c_int = undefined;
808 \\ _ = @TypeOf(c);
825 \\ _ = &c;
809826 \\ const d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440)));
810 \\ _ = @TypeOf(d);
827 \\ _ = &d;
811828 \\ var e: c_int = 10;
812 \\ _ = @TypeOf(e);
829 \\ _ = &e;
813830 \\ var f: c_uint = 10;
814 \\ _ = @TypeOf(f);
831 \\ _ = &f;
815832 \\}
816833 });
817834
......@@ -827,6 +844,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
827844 , &[_][]const u8{
828845 \\pub export fn foo() void {
829846 \\ var a: c_int = undefined;
847 \\ _ = &a;
830848 \\ _ = @as(c_int, 1);
831849 \\ _ = "hey";
832850 \\ _ = @as(c_int, 1) + @as(c_int, 1);
......@@ -870,7 +888,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
870888 \\ const v2 = struct {
871889 \\ const static: [5:0]u8 = "2.2.2".*;
872890 \\ };
873 \\ _ = @TypeOf(v2);
891 \\ _ = &v2;
874892 \\}
875893 });
876894
......@@ -912,8 +930,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
912930 \\pub extern fn foo() void;
913931 \\pub export fn bar() void {
914932 \\ var func_ptr: ?*anyopaque = @as(?*anyopaque, @ptrCast(&foo));
933 \\ _ = &func_ptr;
915934 \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @as(?*const fn () callconv(.C) void, @ptrFromInt(@as(c_ulong, @intCast(@intFromPtr(func_ptr)))));
916 \\ _ = @TypeOf(typed_func_ptr);
935 \\ _ = &typed_func_ptr;
917936 \\}
918937 });
919938
......@@ -953,8 +972,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
953972 , &[_][]const u8{
954973 \\pub export fn s() c_int {
955974 \\ var a: c_int = undefined;
975 \\ _ = &a;
956976 \\ var b: c_int = undefined;
977 \\ _ = &b;
957978 \\ var c: c_int = undefined;
979 \\ _ = &c;
958980 \\ c = a + b;
959981 \\ c = a - b;
960982 \\ c = a * b;
......@@ -964,8 +986,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
964986 \\}
965987 \\pub export fn u() c_uint {
966988 \\ var a: c_uint = undefined;
989 \\ _ = &a;
967990 \\ var b: c_uint = undefined;
991 \\ _ = &b;
968992 \\ var c: c_uint = undefined;
993 \\ _ = &c;
969994 \\ c = a +% b;
970995 \\ c = a -% b;
971996 \\ c = a *% b;
......@@ -1360,7 +1385,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13601385 , &[_][]const u8{
13611386 \\pub export fn foo() void {
13621387 \\ var a: c_int = undefined;
1363 \\ _ = @TypeOf(a);
1388 \\ _ = &a;
1389 \\ _ = &a;
13641390 \\}
13651391 });
13661392
......@@ -1372,6 +1398,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13721398 , &[_][]const u8{
13731399 \\pub export fn foo() ?*anyopaque {
13741400 \\ var x: [*c]c_ushort = undefined;
1401 \\ _ = &x;
13751402 \\ return @as(?*anyopaque, @ptrCast(x));
13761403 \\}
13771404 });
......@@ -1496,6 +1523,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14961523 \\pub export fn foo() void {
14971524 \\ {
14981525 \\ var i: c_int = 0;
1526 \\ _ = &i;
14991527 \\ while (i != 0) : (i += 1) {}
15001528 \\ }
15011529 \\}
......@@ -1519,6 +1547,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15191547 , &[_][]const u8{
15201548 \\pub export fn foo() void {
15211549 \\ var i: c_int = undefined;
1550 \\ _ = &i;
15221551 \\ {
15231552 \\ i = 3;
15241553 \\ while (i != 0) : (i -= 1) {}
......@@ -1562,6 +1591,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15621591 , &[_][]const u8{
15631592 \\pub export fn ptrcast() [*c]f32 {
15641593 \\ var a: [*c]c_int = undefined;
1594 \\ _ = &a;
15651595 \\ return @as([*c]f32, @ptrCast(@alignCast(a)));
15661596 \\}
15671597 });
......@@ -1574,6 +1604,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15741604 , &[_][]const u8{
15751605 \\pub export fn ptrptrcast() [*c][*c]f32 {
15761606 \\ var a: [*c][*c]c_int = undefined;
1607 \\ _ = &a;
15771608 \\ return @as([*c][*c]f32, @ptrCast(@alignCast(a)));
15781609 \\}
15791610 });
......@@ -1597,25 +1628,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15971628 , &[_][]const u8{
15981629 \\pub export fn test_ptr_cast() void {
15991630 \\ var p: ?*anyopaque = undefined;
1631 \\ _ = &p;
16001632 \\ {
16011633 \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p)));
1602 \\ _ = @TypeOf(to_char);
1634 \\ _ = &to_char;
16031635 \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p)));
1604 \\ _ = @TypeOf(to_short);
1636 \\ _ = &to_short;
16051637 \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p)));
1606 \\ _ = @TypeOf(to_int);
1638 \\ _ = &to_int;
16071639 \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p)));
1608 \\ _ = @TypeOf(to_longlong);
1640 \\ _ = &to_longlong;
16091641 \\ }
16101642 \\ {
16111643 \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p)));
1612 \\ _ = @TypeOf(to_char);
1644 \\ _ = &to_char;
16131645 \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p)));
1614 \\ _ = @TypeOf(to_short);
1646 \\ _ = &to_short;
16151647 \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p)));
1616 \\ _ = @TypeOf(to_int);
1648 \\ _ = &to_int;
16171649 \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p)));
1618 \\ _ = @TypeOf(to_longlong);
1650 \\ _ = &to_longlong;
16191651 \\ }
16201652 \\}
16211653 });
......@@ -1633,8 +1665,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16331665 , &[_][]const u8{
16341666 \\pub export fn while_none_bool() c_int {
16351667 \\ var a: c_int = undefined;
1668 \\ _ = &a;
16361669 \\ var b: f32 = undefined;
1670 \\ _ = &b;
16371671 \\ var c: ?*anyopaque = undefined;
1672 \\ _ = &c;
16381673 \\ while (a != 0) return 0;
16391674 \\ while (b != 0) return 1;
16401675 \\ while (c != null) return 2;
......@@ -1655,8 +1690,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16551690 , &[_][]const u8{
16561691 \\pub export fn for_none_bool() c_int {
16571692 \\ var a: c_int = undefined;
1693 \\ _ = &a;
16581694 \\ var b: f32 = undefined;
1695 \\ _ = &b;
16591696 \\ var c: ?*anyopaque = undefined;
1697 \\ _ = &c;
16601698 \\ while (a != 0) return 0;
16611699 \\ while (b != 0) return 1;
16621700 \\ while (c != null) return 2;
......@@ -1693,6 +1731,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16931731 , &[_][]const u8{
16941732 \\pub export fn foo() void {
16951733 \\ var x: [*c]c_int = undefined;
1734 \\ _ = &x;
16961735 \\ x.* = 1;
16971736 \\}
16981737 });
......@@ -1706,7 +1745,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17061745 , &[_][]const u8{
17071746 \\pub export fn foo() c_int {
17081747 \\ var x: c_int = 1234;
1748 \\ _ = &x;
17091749 \\ var ptr: [*c]c_int = &x;
1750 \\ _ = &ptr;
17101751 \\ return ptr.*;
17111752 \\}
17121753 });
......@@ -1719,6 +1760,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17191760 , &[_][]const u8{
17201761 \\pub export fn foo() c_int {
17211762 \\ var x: c_int = undefined;
1763 \\ _ = &x;
17221764 \\ return ~x;
17231765 \\}
17241766 });
......@@ -1736,8 +1778,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17361778 , &[_][]const u8{
17371779 \\pub export fn foo() c_int {
17381780 \\ var a: c_int = undefined;
1781 \\ _ = &a;
17391782 \\ var b: f32 = undefined;
1783 \\ _ = &b;
17401784 \\ var c: ?*anyopaque = undefined;
1785 \\ _ = &c;
17411786 \\ return @intFromBool(!(a == @as(c_int, 0)));
17421787 \\ return @intFromBool(!(a != 0));
17431788 \\ return @intFromBool(!(b != 0));
......@@ -1859,11 +1904,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18591904 \\ var arr: [10]u8 = [1]u8{
18601905 \\ 1,
18611906 \\ } ++ [1]u8{0} ** 9;
1862 \\ _ = @TypeOf(arr);
1907 \\ _ = &arr;
18631908 \\ var arr1: [10][*c]u8 = [1][*c]u8{
18641909 \\ null,
18651910 \\ } ++ [1][*c]u8{null} ** 9;
1866 \\ _ = @TypeOf(arr1);
1911 \\ _ = &arr1;
18671912 \\}
18681913 });
18691914
......@@ -2051,10 +2096,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
20512096 \\pub extern var c: c_int;
20522097 ,
20532098 \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * @as(c_int, 2)) {
2099 \\ _ = &c_1;
20542100 \\ return c_1 * @as(c_int, 2);
20552101 \\}
20562102 ,
20572103 \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) {
2104 \\ _ = &L;
2105 \\ _ = &b;
20582106 \\ return L + b;
20592107 \\}
20602108 ,
......@@ -2107,16 +2155,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
21072155 \\pub var c: c_int = 4;
21082156 \\pub export fn foo(arg_c_1: u8) void {
21092157 \\ var c_1 = arg_c_1;
2110 \\ _ = @TypeOf(c_1);
2158 \\ _ = &c_1;
21112159 \\ var a_2: c_int = undefined;
2160 \\ _ = &a_2;
21122161 \\ var b_3: u8 = 123;
2162 \\ _ = &b_3;
21132163 \\ b_3 = @as(u8, @bitCast(@as(i8, @truncate(a_2))));
21142164 \\ {
21152165 \\ var d: c_int = 5;
2116 \\ _ = @TypeOf(d);
2166 \\ _ = &d;
21172167 \\ }
21182168 \\ var d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440)));
2119 \\ _ = @TypeOf(d);
2169 \\ _ = &d;
21202170 \\}
21212171 });
21222172
......@@ -2150,7 +2200,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
21502200 , &[_][]const u8{
21512201 \\pub export fn foo() void {
21522202 \\ var a: c_int = undefined;
2203 \\ _ = &a;
21532204 \\ var b: c_int = undefined;
2205 \\ _ = &b;
21542206 \\ a = blk: {
21552207 \\ const tmp = @as(c_int, 2);
21562208 \\ b = tmp;
......@@ -2180,11 +2232,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
21802232 , &[_][]const u8{
21812233 \\pub export fn foo() c_int {
21822234 \\ var a: c_int = 5;
2235 \\ _ = &a;
21832236 \\ while (true) {
21842237 \\ a = 2;
21852238 \\ }
21862239 \\ while (true) {
21872240 \\ var a_1: c_int = 4;
2241 \\ _ = &a_1;
21882242 \\ a_1 = 9;
21892243 \\ return blk: {
21902244 \\ _ = @as(c_int, 6);
......@@ -2193,6 +2247,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
21932247 \\ }
21942248 \\ while (true) {
21952249 \\ var a_1: c_int = 2;
2250 \\ _ = &a_1;
21962251 \\ a_1 = 12;
21972252 \\ }
21982253 \\ while (true) {
......@@ -2214,10 +2269,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
22142269 \\pub export fn foo() void {
22152270 \\ {
22162271 \\ var i: c_int = 2;
2272 \\ _ = &i;
22172273 \\ var b: c_int = 4;
2218 \\ _ = @TypeOf(b);
2274 \\ _ = &b;
22192275 \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) {
22202276 \\ var a: c_int = 2;
2277 \\ _ = &a;
22212278 \\ _ = blk: {
22222279 \\ _ = blk_1: {
22232280 \\ a = 6;
......@@ -2228,7 +2285,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
22282285 \\ }
22292286 \\ }
22302287 \\ var i: u8 = 2;
2231 \\ _ = @TypeOf(i);
2288 \\ _ = &i;
22322289 \\}
22332290 });
22342291
......@@ -2309,7 +2366,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
23092366 , &[_][]const u8{
23102367 \\pub export fn switch_fn(arg_i: c_int) void {
23112368 \\ var i = arg_i;
2369 \\ _ = &i;
23122370 \\ var res: c_int = 0;
2371 \\ _ = &res;
23132372 \\ while (true) {
23142373 \\ switch (i) {
23152374 \\ @as(c_int, 0) => {
......@@ -2398,7 +2457,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
23982457 , &[_][]const u8{
23992458 \\pub export fn max(arg_a: c_int) void {
24002459 \\ var a = arg_a;
2460 \\ _ = &a;
24012461 \\ var tmp: c_int = undefined;
2462 \\ _ = &tmp;
24022463 \\ tmp = a;
24032464 \\ a = tmp;
24042465 \\}
......@@ -2412,8 +2473,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
24122473 , &[_][]const u8{
24132474 \\pub export fn max(arg_a: c_int) void {
24142475 \\ var a = arg_a;
2476 \\ _ = &a;
24152477 \\ var b: c_int = undefined;
2478 \\ _ = &b;
24162479 \\ var c: c_int = undefined;
2480 \\ _ = &c;
24172481 \\ c = blk: {
24182482 \\ const tmp = a;
24192483 \\ b = tmp;
......@@ -2442,6 +2506,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
24422506 , &[_][]const u8{
24432507 \\pub export fn int_from_float(arg_a: f32) c_int {
24442508 \\ var a = arg_a;
2509 \\ _ = &a;
24452510 \\ return @as(c_int, @intFromFloat(a));
24462511 \\}
24472512 });
......@@ -2465,27 +2530,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
24652530 , &[_][]const u8{
24662531 \\pub export fn escapes() [*c]const u8 {
24672532 \\ var a: u8 = '\'';
2468 \\ _ = @TypeOf(a);
2533 \\ _ = &a;
24692534 \\ var b: u8 = '\\';
2470 \\ _ = @TypeOf(b);
2535 \\ _ = &b;
24712536 \\ var c: u8 = '\x07';
2472 \\ _ = @TypeOf(c);
2537 \\ _ = &c;
24732538 \\ var d: u8 = '\x08';
2474 \\ _ = @TypeOf(d);
2539 \\ _ = &d;
24752540 \\ var e: u8 = '\x0c';
2476 \\ _ = @TypeOf(e);
2541 \\ _ = &e;
24772542 \\ var f: u8 = '\n';
2478 \\ _ = @TypeOf(f);
2543 \\ _ = &f;
24792544 \\ var g: u8 = '\r';
2480 \\ _ = @TypeOf(g);
2545 \\ _ = &g;
24812546 \\ var h: u8 = '\t';
2482 \\ _ = @TypeOf(h);
2547 \\ _ = &h;
24832548 \\ var i: u8 = '\x0b';
2484 \\ _ = @TypeOf(i);
2549 \\ _ = &i;
24852550 \\ var j: u8 = '\x00';
2486 \\ _ = @TypeOf(j);
2551 \\ _ = &j;
24872552 \\ var k: u8 = '"';
2488 \\ _ = @TypeOf(k);
2553 \\ _ = &k;
24892554 \\ return "'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
24902555 \\}
24912556 });
......@@ -2505,11 +2570,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
25052570 , &[_][]const u8{
25062571 \\pub export fn foo() void {
25072572 \\ var a: c_int = 2;
2573 \\ _ = &a;
25082574 \\ while (true) {
25092575 \\ a = a - @as(c_int, 1);
25102576 \\ if (!(a != 0)) break;
25112577 \\ }
25122578 \\ var b: c_int = 2;
2579 \\ _ = &b;
25132580 \\ while (true) {
25142581 \\ b = b - @as(c_int, 1);
25152582 \\ if (!(b != 0)) break;
......@@ -2550,21 +2617,37 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
25502617 \\pub const SomeTypedef = c_int;
25512618 \\pub export fn and_or_non_bool(arg_a: c_int, arg_b: f32, arg_c: ?*anyopaque) c_int {
25522619 \\ var a = arg_a;
2620 \\ _ = &a;
25532621 \\ var b = arg_b;
2622 \\ _ = &b;
25542623 \\ var c = arg_c;
2624 \\ _ = &c;
25552625 \\ var d: enum_Foo = @as(c_uint, @bitCast(FooA));
2626 \\ _ = &d;
25562627 \\ var e: c_int = @intFromBool((a != 0) and (b != 0));
2628 \\ _ = &e;
25572629 \\ var f: c_int = @intFromBool((b != 0) and (c != null));
2630 \\ _ = &f;
25582631 \\ var g: c_int = @intFromBool((a != 0) and (c != null));
2632 \\ _ = &g;
25592633 \\ var h: c_int = @intFromBool((a != 0) or (b != 0));
2634 \\ _ = &h;
25602635 \\ var i: c_int = @intFromBool((b != 0) or (c != null));
2636 \\ _ = &i;
25612637 \\ var j: c_int = @intFromBool((a != 0) or (c != null));
2638 \\ _ = &j;
25622639 \\ var k: c_int = @intFromBool((a != 0) or (@as(c_int, @bitCast(d)) != 0));
2640 \\ _ = &k;
25632641 \\ var l: c_int = @intFromBool((@as(c_int, @bitCast(d)) != 0) and (b != 0));
2642 \\ _ = &l;
25642643 \\ var m: c_int = @intFromBool((c != null) or (d != 0));
2644 \\ _ = &m;
25652645 \\ var td: SomeTypedef = 44;
2646 \\ _ = &td;
25662647 \\ var o: c_int = @intFromBool((td != 0) or (b != 0));
2648 \\ _ = &o;
25672649 \\ var p: c_int = @intFromBool((c != null) and (td != 0));
2650 \\ _ = &p;
25682651 \\ return (((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p;
25692652 \\}
25702653 ,
......@@ -2604,7 +2687,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
26042687 , &[_][]const u8{
26052688 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
26062689 \\ var a = arg_a;
2690 \\ _ = &a;
26072691 \\ var b = arg_b;
2692 \\ _ = &b;
26082693 \\ return (a & b) ^ (a | b);
26092694 \\}
26102695 });
......@@ -2623,14 +2708,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
26232708 , &[_][]const u8{
26242709 \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int {
26252710 \\ var a = arg_a;
2711 \\ _ = &a;
26262712 \\ var b = arg_b;
2713 \\ _ = &b;
26272714 \\ var c: c_int = @intFromBool(a < b);
2715 \\ _ = &c;
26282716 \\ var d: c_int = @intFromBool(a > b);
2717 \\ _ = &d;
26292718 \\ var e: c_int = @intFromBool(a <= b);
2719 \\ _ = &e;
26302720 \\ var f: c_int = @intFromBool(a >= b);
2721 \\ _ = &f;
26312722 \\ var g: c_int = @intFromBool(c < d);
2723 \\ _ = &g;
26322724 \\ var h: c_int = @intFromBool(e < f);
2725 \\ _ = &h;
26332726 \\ var i: c_int = @intFromBool(g < h);
2727 \\ _ = &i;
26342728 \\ return i;
26352729 \\}
26362730 });
......@@ -2646,7 +2740,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
26462740 , &[_][]const u8{
26472741 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
26482742 \\ var a = arg_a;
2743 \\ _ = &a;
26492744 \\ var b = arg_b;
2745 \\ _ = &b;
26502746 \\ if (a == b) return a;
26512747 \\ if (a != b) return b;
26522748 \\ return a;
......@@ -2663,6 +2759,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
26632759 \\pub const yes = [*c]u8;
26642760 \\pub export fn foo() void {
26652761 \\ var a: yes = undefined;
2762 \\ _ = &a;
26662763 \\ if (a != null) {
26672764 \\ _ = @as(c_int, 2);
26682765 \\ }
......@@ -2681,7 +2778,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
26812778 \\pub export fn foo() c_int {
26822779 \\ return blk: {
26832780 \\ var a: c_int = 1;
2684 \\ _ = @TypeOf(a);
2781 \\ _ = &a;
2782 \\ _ = &a;
26852783 \\ break :blk a;
26862784 \\ };
26872785 \\}
......@@ -2707,6 +2805,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27072805 \\pub export var b: f32 = 2.0;
27082806 \\pub export fn foo() void {
27092807 \\ var c: [*c]struct_Foo = undefined;
2808 \\ _ = &c;
27102809 \\ _ = a.b;
27112810 \\ _ = c.*.b;
27122811 \\}
......@@ -2726,6 +2825,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27262825 \\pub export var array: [100]c_int = [1]c_int{0} ** 100;
27272826 \\pub export fn foo(arg_index: c_int) c_int {
27282827 \\ var index = arg_index;
2828 \\ _ = &index;
27292829 \\ return array[@as(c_uint, @intCast(index))];
27302830 \\}
27312831 ,
......@@ -2740,7 +2840,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27402840 , &[_][]const u8{
27412841 \\pub export fn foo() void {
27422842 \\ var a: [10]c_int = undefined;
2843 \\ _ = &a;
27432844 \\ var i: c_int = 0;
2845 \\ _ = &i;
27442846 \\ a[@as(c_uint, @intCast(i))] = 0;
27452847 \\}
27462848 });
......@@ -2753,7 +2855,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27532855 , &[_][]const u8{
27542856 \\pub export fn foo() void {
27552857 \\ var a: [10]c_longlong = undefined;
2858 \\ _ = &a;
27562859 \\ var i: c_longlong = 0;
2860 \\ _ = &i;
27572861 \\ a[@as(usize, @intCast(i))] = 0;
27582862 \\}
27592863 });
......@@ -2766,7 +2870,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27662870 , &[_][]const u8{
27672871 \\pub export fn foo() void {
27682872 \\ var a: [10]c_uint = undefined;
2873 \\ _ = &a;
27692874 \\ var i: c_uint = 0;
2875 \\ _ = &i;
27702876 \\ a[i] = 0;
27712877 \\}
27722878 });
......@@ -2776,6 +2882,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27762882 \\int bar(int x) { return x; }
27772883 , &[_][]const u8{
27782884 \\pub inline fn CALL(arg: anytype) @TypeOf(bar(arg)) {
2885 \\ _ = &arg;
27792886 \\ return bar(arg);
27802887 \\}
27812888 });
......@@ -2785,7 +2892,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27852892 \\int bar(void) { return 0; }
27862893 , &[_][]const u8{
27872894 \\pub inline fn CALL(arg: anytype) @TypeOf(bar()) {
2788 \\ _ = @TypeOf(arg);
2895 \\ _ = &arg;
27892896 \\ return bar();
27902897 \\}
27912898 });
......@@ -2801,7 +2908,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
28012908 , &[_][]const u8{
28022909 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
28032910 \\ var a = arg_a;
2911 \\ _ = &a;
28042912 \\ var b = arg_b;
2913 \\ _ = &b;
28052914 \\ if ((a < b) or (a == b)) return b;
28062915 \\ if ((a >= b) and (a == b)) return a;
28072916 \\ return a;
......@@ -2823,7 +2932,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
28232932 , &[_][]const u8{
28242933 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
28252934 \\ var a = arg_a;
2935 \\ _ = &a;
28262936 \\ var b = arg_b;
2937 \\ _ = &b;
28272938 \\ if (a < b) return b;
28282939 \\ if (a < b) return b else return a;
28292940 \\ if (a < b) {} else {}
......@@ -2844,14 +2955,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
28442955 \\pub export fn foo() void {
28452956 \\ if (true) {
28462957 \\ var a: c_int = 2;
2847 \\ _ = @TypeOf(a);
2958 \\ _ = &a;
28482959 \\ }
28492960 \\ if ((blk: {
28502961 \\ _ = @as(c_int, 2);
28512962 \\ break :blk @as(c_int, 5);
28522963 \\ }) != 0) {
28532964 \\ var a: c_int = 2;
2854 \\ _ = @TypeOf(a);
2965 \\ _ = &a;
28552966 \\ }
28562967 \\}
28572968 });
......@@ -2874,9 +2985,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
28742985 \\;
28752986 \\pub export fn if_none_bool(arg_a: c_int, arg_b: f32, arg_c: ?*anyopaque, arg_d: enum_SomeEnum) c_int {
28762987 \\ var a = arg_a;
2988 \\ _ = &a;
28772989 \\ var b = arg_b;
2990 \\ _ = &b;
28782991 \\ var c = arg_c;
2992 \\ _ = &c;
28792993 \\ var d = arg_d;
2994 \\ _ = &d;
28802995 \\ if (a != 0) return 0;
28812996 \\ if (b != 0) return 1;
28822997 \\ if (c != null) return 2;
......@@ -2904,6 +3019,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
29043019 , &[_][]const u8{
29053020 \\pub export fn abs(arg_a: c_int) c_int {
29063021 \\ var a = arg_a;
3022 \\ _ = &a;
29073023 \\ return if (a < @as(c_int, 0)) -a else a;
29083024 \\}
29093025 });
......@@ -2924,16 +3040,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
29243040 , &[_][]const u8{
29253041 \\pub export fn foo1(arg_a: c_uint) c_uint {
29263042 \\ var a = arg_a;
3043 \\ _ = &a;
29273044 \\ a +%= 1;
29283045 \\ return a;
29293046 \\}
29303047 \\pub export fn foo2(arg_a: c_int) c_int {
29313048 \\ var a = arg_a;
3049 \\ _ = &a;
29323050 \\ a += 1;
29333051 \\ return a;
29343052 \\}
29353053 \\pub export fn foo3(arg_a: [*c]c_int) [*c]c_int {
29363054 \\ var a = arg_a;
3055 \\ _ = &a;
29373056 \\ a += 1;
29383057 \\ return a;
29393058 \\}
......@@ -2959,7 +3078,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
29593078 \\}
29603079 \\pub export fn bar() void {
29613080 \\ var f: ?*const fn () callconv(.C) void = &foo;
3081 \\ _ = &f;
29623082 \\ var b: ?*const fn () callconv(.C) c_int = &baz;
3083 \\ _ = &b;
29633084 \\ f.?();
29643085 \\ f.?();
29653086 \\ foo();
......@@ -2985,7 +3106,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
29853106 , &[_][]const u8{
29863107 \\pub export fn foo() void {
29873108 \\ var i: c_int = 0;
3109 \\ _ = &i;
29883110 \\ var u: c_uint = 0;
3111 \\ _ = &u;
29893112 \\ i += 1;
29903113 \\ i -= 1;
29913114 \\ u +%= 1;
......@@ -3024,7 +3147,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30243147 , &[_][]const u8{
30253148 \\pub export fn log2(arg_a: c_uint) c_int {
30263149 \\ var a = arg_a;
3150 \\ _ = &a;
30273151 \\ var i: c_int = 0;
3152 \\ _ = &i;
30283153 \\ while (a > @as(c_uint, @bitCast(@as(c_int, 0)))) {
30293154 \\ a >>= @intCast(@as(c_int, 1));
30303155 \\ }
......@@ -3044,7 +3169,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30443169 , &[_][]const u8{
30453170 \\pub export fn log2(arg_a: u32) c_int {
30463171 \\ var a = arg_a;
3172 \\ _ = &a;
30473173 \\ var i: c_int = 0;
3174 \\ _ = &i;
30483175 \\ while (a > @as(u32, @bitCast(@as(c_int, 0)))) {
30493176 \\ a >>= @intCast(@as(c_int, 1));
30503177 \\ }
......@@ -3072,7 +3199,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30723199 , &[_][]const u8{
30733200 \\pub export fn foo() void {
30743201 \\ var a: c_int = 0;
3202 \\ _ = &a;
30753203 \\ var b: c_uint = 0;
3204 \\ _ = &b;
30763205 \\ a += blk: {
30773206 \\ const ref = &a;
30783207 \\ ref.* += @as(c_int, 1);
......@@ -3151,6 +3280,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
31513280 , &[_][]const u8{
31523281 \\pub export fn foo() void {
31533282 \\ var a: c_uint = 0;
3283 \\ _ = &a;
31543284 \\ a +%= blk: {
31553285 \\ const ref = &a;
31563286 \\ ref.* +%= @as(c_uint, @bitCast(@as(c_int, 1)));
......@@ -3210,7 +3340,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
32103340 , &[_][]const u8{
32113341 \\pub export fn foo() void {
32123342 \\ var i: c_int = 0;
3343 \\ _ = &i;
32133344 \\ var u: c_uint = 0;
3345 \\ _ = &u;
32143346 \\ i += 1;
32153347 \\ i -= 1;
32163348 \\ u +%= 1;
......@@ -3305,6 +3437,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
33053437 \\pub fn bar() callconv(.C) void {}
33063438 \\pub export fn foo(arg_baz: ?*const fn () callconv(.C) [*c]c_int) void {
33073439 \\ var baz = arg_baz;
3440 \\ _ = &baz;
33083441 \\ bar();
33093442 \\ _ = baz.?();
33103443 \\}
......@@ -3331,7 +3464,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
33313464 \\#define a 2
33323465 , &[_][]const u8{
33333466 \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").zig.c_translation.cast(?*anyopaque, baz))) {
3334 \\ _ = @TypeOf(bar);
3467 \\ _ = &bar;
33353468 \\ return baz(@import("std").zig.c_translation.cast(?*anyopaque, baz));
33363469 \\}
33373470 ,
......@@ -3375,10 +3508,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
33753508 \\#define MAX(a, b) ((b) > (a) ? (b) : (a))
33763509 , &[_][]const u8{
33773510 \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) {
3511 \\ _ = &a;
3512 \\ _ = &b;
33783513 \\ return if (b < a) b else a;
33793514 \\}
33803515 ,
33813516 \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) {
3517 \\ _ = &a;
3518 \\ _ = &b;
33823519 \\ return if (b > a) b else a;
33833520 \\}
33843521 });
......@@ -3390,7 +3527,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
33903527 , &[_][]const u8{
33913528 \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int {
33923529 \\ var p = arg_p;
3530 \\ _ = &p;
33933531 \\ var x = arg_x;
3532 \\ _ = &x;
33943533 \\ return blk: {
33953534 \\ const tmp = x;
33963535 \\ (blk_1: {
......@@ -3417,6 +3556,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
34173556 \\}
34183557 \\pub export fn bar(arg_x: c_long) c_ushort {
34193558 \\ var x = arg_x;
3559 \\ _ = &x;
34203560 \\ return @as(c_ushort, @bitCast(@as(c_short, @truncate(x))));
34213561 \\}
34223562 });
......@@ -3429,6 +3569,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
34293569 , &[_][]const u8{
34303570 \\pub export fn foo(arg_bar_1: c_int) void {
34313571 \\ var bar_1 = arg_bar_1;
3572 \\ _ = &bar_1;
34323573 \\ bar_1 = 2;
34333574 \\}
34343575 \\pub export var bar: c_int = 4;
......@@ -3442,6 +3583,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
34423583 , &[_][]const u8{
34433584 \\pub export fn foo(arg_bar_1: c_int) void {
34443585 \\ var bar_1 = arg_bar_1;
3586 \\ _ = &bar_1;
34453587 \\ bar_1 = 2;
34463588 \\}
34473589 ,
......@@ -3471,14 +3613,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
34713613 , &[_][]const u8{
34723614 \\pub export fn foo(arg_a: [*c]c_int) void {
34733615 \\ var a = arg_a;
3474 \\ _ = @TypeOf(a);
3616 \\ _ = &a;
34753617 \\}
34763618 \\pub export fn bar(arg_a: [*c]const c_int) void {
34773619 \\ var a = arg_a;
3620 \\ _ = &a;
34783621 \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a)))));
34793622 \\}
34803623 \\pub export fn baz(arg_a: [*c]volatile c_int) void {
34813624 \\ var a = arg_a;
3625 \\ _ = &a;
34823626 \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a)))));
34833627 \\}
34843628 });
......@@ -3493,9 +3637,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
34933637 , &[_][]const u8{
34943638 \\pub export fn foo(arg_x: bool) bool {
34953639 \\ var x = arg_x;
3640 \\ _ = &x;
34963641 \\ var a: bool = @as(c_int, @intFromBool(x)) != @as(c_int, 1);
3642 \\ _ = &a;
34973643 \\ var b: bool = @as(c_int, @intFromBool(a)) != @as(c_int, 0);
3644 \\ _ = &b;
34983645 \\ var c: bool = @intFromPtr(&foo) != 0;
3646 \\ _ = &c;
34993647 \\ return foo(@as(c_int, @intFromBool(c)) != @as(c_int, @intFromBool(b)));
35003648 \\}
35013649 });
......@@ -3506,7 +3654,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
35063654 \\}
35073655 , &[_][]const u8{
35083656 \\pub export fn max(x: c_int, arg_y: c_int) c_int {
3657 \\ _ = &x;
35093658 \\ var y = arg_y;
3659 \\ _ = &y;
35103660 \\ return if (x > y) x else y;
35113661 \\}
35123662 });
......@@ -3567,6 +3717,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
35673717 \\
35683718 , &[_][]const u8{
35693719 \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen) {
3720 \\ _ = &dpy;
35703721 \\ return @import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen;
35713722 \\}
35723723 });
......@@ -3809,6 +3960,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
38093960 \\ const foo = struct {
38103961 \\ var static: struct_FOO = @import("std").mem.zeroes(struct_FOO);
38113962 \\ };
3963 \\ _ = &foo;
38123964 \\ return foo.static.x;
38133965 \\}
38143966 });
......@@ -3830,13 +3982,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
38303982 , &[_][]const u8{
38313983 \\pub export fn bar(arg_x: c_int, arg_y: c_int) c_int {
38323984 \\ var x = arg_x;
3985 \\ _ = &x;
38333986 \\ var y = arg_y;
3834 \\ _ = @TypeOf(y);
3987 \\ _ = &y;
38353988 \\ return x;
38363989 \\}
38373990 ,
38383991 \\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A) {
3839 \\ _ = @TypeOf(B);
3992 \\ _ = &A;
3993 \\ _ = &B;
38403994 \\ return A;
38413995 \\}
38423996 });
......@@ -3911,6 +4065,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
39114065 , &[_][]const u8{
39124066 \\pub export fn foo() void {
39134067 \\ var a: c_int = undefined;
4068 \\ _ = &a;
39144069 \\ if ((blk: {
39154070 \\ const tmp = @intFromBool(@as(c_int, 1) > @as(c_int, 0));
39164071 \\ a = tmp;
......@@ -3929,9 +4084,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
39294084 , &[_][]const u8{
39304085 \\pub export fn foo() void {
39314086 \\ var a: S = undefined;
4087 \\ _ = &a;
39324088 \\ var b: S = undefined;
4089 \\ _ = &b;
39334090 \\ var c: c_longlong = @divExact(@as(c_longlong, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8));
3934 \\ _ = @TypeOf(c);
4091 \\ _ = &c;
39354092 \\}
39364093 });
39374094 } else {
......@@ -3944,9 +4101,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
39444101 , &[_][]const u8{
39454102 \\pub export fn foo() void {
39464103 \\ var a: S = undefined;
4104 \\ _ = &a;
39474105 \\ var b: S = undefined;
4106 \\ _ = &b;
39484107 \\ var c: c_long = @divExact(@as(c_long, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8));
3949 \\ _ = @TypeOf(c);
4108 \\ _ = &c;
39504109 \\}
39514110 });
39524111 }
......@@ -3973,7 +4132,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
39734132 , &[_][]const u8{
39744133 \\pub export fn foo() void {
39754134 \\ var n: c_int = undefined;
4135 \\ _ = &n;
39764136 \\ var tmp: c_int = 1;
4137 \\ _ = &tmp;
39774138 \\ if ((blk: {
39784139 \\ const tmp_1 = tmp;
39794140 \\ n = tmp_1;
......@@ -3990,7 +4151,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
39904151 , &[_][]const u8{
39914152 \\pub export fn foo() void {
39924153 \\ var tmp: c_int = undefined;
4154 \\ _ = &tmp;
39934155 \\ var n: c_int = 1;
4156 \\ _ = &n;
39944157 \\ if ((blk: {
39954158 \\ const tmp_1 = n;
39964159 \\ tmp = tmp_1;
......@@ -4007,7 +4170,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
40074170 , &[_][]const u8{
40084171 \\pub export fn foo() void {
40094172 \\ var n: c_int = undefined;
4173 \\ _ = &n;
40104174 \\ var ref: c_int = 1;
4175 \\ _ = &ref;
40114176 \\ if ((blk: {
40124177 \\ const tmp = blk_1: {
40134178 \\ const ref_2 = &ref;
......@@ -4028,7 +4193,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
40284193 , &[_][]const u8{
40294194 \\pub export fn foo() void {
40304195 \\ var n: c_int = undefined;
4196 \\ _ = &n;
40314197 \\ var ref: c_int = 1;
4198 \\ _ = &ref;
40324199 \\ if ((blk: {
40334200 \\ const tmp = blk_1: {
40344201 \\ const ref_2 = &ref;
......@@ -4050,7 +4217,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
40504217 , &[_][]const u8{
40514218 \\pub export fn foo() void {
40524219 \\ var n: c_int = undefined;
4220 \\ _ = &n;
40534221 \\ var ref: c_int = 1;
4222 \\ _ = &ref;
40544223 \\ if ((blk: {
40554224 \\ const ref_1 = &n;
40564225 \\ ref_1.* += ref;
......@@ -4067,7 +4236,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
40674236 , &[_][]const u8{
40684237 \\pub export fn foo() void {
40694238 \\ var ref: c_int = undefined;
4239 \\ _ = &ref;
40704240 \\ var n: c_int = 1;
4241 \\ _ = &n;
40714242 \\ if ((blk: {
40724243 \\ const ref_1 = &ref;
40734244 \\ ref_1.* += n;
......@@ -4085,8 +4256,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
40854256 , &[_][]const u8{
40864257 \\pub export fn foo() void {
40874258 \\ var f: c_int = 1;
4259 \\ _ = &f;
40884260 \\ var n: c_int = undefined;
4261 \\ _ = &n;
40894262 \\ var cond_temp: c_int = 1;
4263 \\ _ = &cond_temp;
40904264 \\ if ((blk: {
40914265 \\ const tmp = blk_1: {
40924266 \\ const cond_temp_2 = cond_temp;
......@@ -4107,8 +4281,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
41074281 , &[_][]const u8{
41084282 \\pub export fn foo() void {
41094283 \\ var cond_temp: c_int = 1;
4284 \\ _ = &cond_temp;
41104285 \\ var n: c_int = undefined;
4286 \\ _ = &n;
41114287 \\ var f: c_int = 1;
4288 \\ _ = &f;
41124289 \\ if ((blk: {
41134290 \\ const tmp = blk_1: {
41144291 \\ const cond_temp_2 = f;
......@@ -4149,6 +4326,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
41494326 , &[_][]const u8{
41504327 \\pub export fn somefunc() void {
41514328 \\ var y: c_int = undefined;
4329 \\ _ = &y;
41524330 \\ _ = blk: {
41534331 \\ y = 1;
41544332 \\ };
tools/gen_spirv_spec.zig+2-2
......@@ -23,7 +23,7 @@ pub fn main() !void {
2323 var scanner = std.json.Scanner.initCompleteInput(allocator, spec);
2424 var diagnostics = std.json.Diagnostics{};
2525 scanner.enableDiagnostics(&diagnostics);
26 var parsed = std.json.parseFromTokenSource(g.CoreRegistry, allocator, &scanner, .{}) catch |err| {
26 const parsed = std.json.parseFromTokenSource(g.CoreRegistry, allocator, &scanner, .{}) catch |err| {
2727 std.debug.print("line,col: {},{}\n", .{ diagnostics.getLine(), diagnostics.getColumn() });
2828 return err;
2929 };
......@@ -466,7 +466,7 @@ fn renderBitEnum(
466466
467467 std.debug.assert(@popCount(value) == 1);
468468
469 var bitpos = std.math.log2_int(u32, value);
469 const bitpos = std.math.log2_int(u32, value);
470470 if (flags_by_bitpos[bitpos]) |*existing| {
471471 const tag_index = std.mem.indexOfDiff(u8, enumerant.enumerant, enumerants[existing.*].enumerant).?;
472472 const enum_priority = tagPriorityScore(enumerant.enumerant[tag_index..]);
tools/generate_linux_syscalls.zig+1-1
......@@ -35,7 +35,7 @@ pub fn main() !void {
3535
3636 // As of 5.17.1, the largest table is 23467 bytes.
3737 // 32k should be enough for now.
38 var buf = try allocator.alloc(u8, 1 << 15);
38 const buf = try allocator.alloc(u8, 1 << 15);
3939 const linux_dir = try std.fs.openDirAbsolute(linux_path, .{});
4040
4141 try writer.writeAll(