authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-14 08:11:37+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-19 09:57:04+00:00
logd82d327de22db3cd2ed4412f395dd5276a3b6a06
treee54151d8152b514b8a4af9524ab4e7eec533b9c8
parent9c16b2370d30e74a63a84a835d840266021424fd
signaturelock-open Commit is signed but in an unrecognized format.

test: update remaining code to fix 'var is never mutated' errors


11 files changed, 49 insertions(+), 50 deletions(-)

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/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