From baabc6013ea4f44082e69375214e76b5d803c5cb Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 10 Nov 2023 07:57:54 +0000 Subject: [PATCH 01/15] compiler: add error for unnecessary use of 'var' When a local variable is never used as an lvalue, we can determine that `const` would be sufficient for this variable, so emit an error in this case. More sophisticated checking is unfortunately not possible with Zig's current analysis model, since whether an lvalue is actually mutated depends on semantic analysis, in which some code paths may not be analyzed, so attempting to determine this would result in false positive compile errors. It's worth noting that an unfortunate consequence of this is that any field call `a.b()` will allow `a` to be `var`, even if `b` does not take a pointer as its first parameter - this is again a necessary compromise because the parameter type is not known until semantic analysis. Also update `translate-c` to not trigger these errors. This is done by replacing the `_ = @TypeOf(x)` emitted with `_ = &x` - the reference there means that the local is permitted to be `var`. A similar strategy will be used to prevent compile errors in the behavior tests, where we sometimes want to force a value to be runtime-known. Resolves: #224 --- src/AstGen.zig | 28 +++++++++++++++++++++------- src/translate_c/ast.zig | 9 +++++++-- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index 5638216ed178aa27a3ae5a196a7347320b93c713..58ba3ee11cc8f6a9f29e936558703ead3abb9947 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -1226,7 +1226,7 @@ fn awaitExpr( try astgen.errNoteNode(gz.suspend_node, "suspend block here", .{}), }); } - const operand = try expr(gz, scope, .{ .rl = .none }, rhs_node); + const operand = try expr(gz, scope, .{ .rl = .ref }, rhs_node); const result = if (gz.nosuspend_node != 0) try gz.addExtendedPayload(.await_nosuspend, Zir.Inst.UnNode{ .node = gz.nodeIndexToRelative(node), @@ -1248,7 +1248,7 @@ fn resumeExpr( const tree = astgen.tree; const node_datas = tree.nodes.items(.data); const rhs_node = node_datas[node].lhs; - const operand = try expr(gz, scope, .{ .rl = .none }, rhs_node); + const operand = try expr(gz, scope, .{ .rl = .ref }, rhs_node); const result = try gz.addUnNode(.@"resume", operand, node); return rvalue(gz, ri, result, node); } @@ -2941,11 +2941,19 @@ fn checkUsed(gz: *GenZir, outer_scope: *Scope, inner_scope: *Scope) InnerError!v const s = scope.cast(Scope.LocalPtr).?; if (s.used == 0 and s.discarded == 0) { try astgen.appendErrorTok(s.token_src, "unused {s}", .{@tagName(s.id_cat)}); - } else if (s.used != 0 and s.discarded != 0) { - try astgen.appendErrorTokNotes(s.discarded, "pointless discard of {s}", .{@tagName(s.id_cat)}, &[_]u32{ - try gz.astgen.errNoteTok(s.used, "used here", .{}), - }); + } else { + if (s.used != 0 and s.discarded != 0) { + try astgen.appendErrorTokNotes(s.discarded, "pointless discard of {s}", .{@tagName(s.id_cat)}, &[_]u32{ + try astgen.errNoteTok(s.used, "used here", .{}), + }); + } + if (s.id_cat == .@"local variable" and !s.used_as_lvalue) { + try astgen.appendErrorTokNotes(s.token_src, "local variable is never mutated", .{}, &.{ + try astgen.errNoteTok(s.token_src, "consider using 'const'", .{}), + }); + } } + scope = s.parent; }, .defer_normal, .defer_error => scope = scope.cast(Scope.Defer).?.parent, @@ -7579,7 +7587,10 @@ fn localVarRef( ); switch (ri.rl) { - .ref, .ref_coerced_ty => return ptr_inst, + .ref, .ref_coerced_ty => { + local_ptr.used_as_lvalue = true; + return ptr_inst; + }, else => { const loaded = try gz.addUnNode(.load, ptr_inst, ident); return rvalueNoCoercePreRef(gz, ri, loaded, ident); @@ -10948,6 +10959,9 @@ const Scope = struct { /// Track the identifier where it is discarded, like this `_ = foo;`. /// 0 means never discarded. discarded: Ast.TokenIndex = 0, + /// Whether this value is used as an lvalue after inititialization. + /// If not, we know it can be `const`, so will emit a compile error if it is `var`. + used_as_lvalue: bool = false, /// String table index. name: u32, id_cat: IdCat, diff --git a/src/translate_c/ast.zig b/src/translate_c/ast.zig index 0381f58cf9cf72cd03c48c52274220b948fccd93..8330e6785f105512eb92d63a6888364499cc57be 100644 --- a/src/translate_c/ast.zig +++ b/src/translate_c/ast.zig @@ -1625,13 +1625,18 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { }); const main_token = try c.addToken(.equal, "="); if (payload.value.tag() == .identifier) { - // Render as `_ = @TypeOf(foo);` to avoid tripping "pointless discard" error. + // Render as `_ = &foo;` to avoid tripping "pointless discard" and "local variable never mutated" errors. + var addr_of_pl: Payload.UnOp = .{ + .base = .{ .tag = .address_of }, + .data = payload.value, + }; + const addr_of: Node = .{ .ptr_otherwise = &addr_of_pl.base }; return c.addNode(.{ .tag = .assign, .main_token = main_token, .data = .{ .lhs = lhs, - .rhs = try renderBuiltinCall(c, "@TypeOf", &.{payload.value}), + .rhs = try renderNode(c, addr_of), }, }); } else { -- 2.54.0 From 51595d6b75d8ac2443a2c142c71f2a617c12fe96 Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 10 Nov 2023 05:27:17 +0000 Subject: [PATCH 02/15] lib: correct unnecessary uses of 'var' --- lib/build_runner.zig | 2 +- lib/compiler_rt/absvdi2_test.zig | 2 +- lib/compiler_rt/absvsi2_test.zig | 2 +- lib/compiler_rt/absvti2_test.zig | 2 +- lib/compiler_rt/addo.zig | 2 +- lib/compiler_rt/addodi4_test.zig | 4 +- lib/compiler_rt/addosi4_test.zig | 4 +- lib/compiler_rt/addoti4_test.zig | 4 +- lib/compiler_rt/bswapdi2_test.zig | 2 +- lib/compiler_rt/bswapsi2_test.zig | 2 +- lib/compiler_rt/bswapti2_test.zig | 2 +- lib/compiler_rt/ceil.zig | 2 +- lib/compiler_rt/clzdi2_test.zig | 4 +- lib/compiler_rt/clzti2_test.zig | 4 +- lib/compiler_rt/cmpdi2_test.zig | 2 +- lib/compiler_rt/cmpsi2_test.zig | 2 +- lib/compiler_rt/cmpti2_test.zig | 2 +- lib/compiler_rt/ctzdi2_test.zig | 4 +- lib/compiler_rt/ctzsi2_test.zig | 4 +- lib/compiler_rt/ctzti2_test.zig | 4 +- lib/compiler_rt/divc3_test.zig | 40 ++++----- lib/compiler_rt/divxf3.zig | 4 +- lib/compiler_rt/emutls.zig | 22 ++--- lib/compiler_rt/exp.zig | 2 +- lib/compiler_rt/exp2.zig | 2 +- lib/compiler_rt/ffsdi2_test.zig | 4 +- lib/compiler_rt/ffssi2_test.zig | 4 +- lib/compiler_rt/ffsti2_test.zig | 4 +- lib/compiler_rt/float_from_int.zig | 6 +- lib/compiler_rt/fma.zig | 32 +++---- lib/compiler_rt/fmod.zig | 16 ++-- lib/compiler_rt/mulc3.zig | 2 +- lib/compiler_rt/mulc3_test.zig | 32 +++---- lib/compiler_rt/mulo.zig | 4 +- lib/compiler_rt/negdi2_test.zig | 2 +- lib/compiler_rt/negsi2_test.zig | 2 +- lib/compiler_rt/negti2_test.zig | 2 +- lib/compiler_rt/negvdi2_test.zig | 2 +- lib/compiler_rt/negvsi2_test.zig | 2 +- lib/compiler_rt/negvti2_test.zig | 2 +- lib/compiler_rt/paritydi2_test.zig | 6 +- lib/compiler_rt/paritysi2_test.zig | 6 +- lib/compiler_rt/parityti2_test.zig | 6 +- lib/compiler_rt/popcountdi2_test.zig | 2 +- lib/compiler_rt/popcountsi2_test.zig | 2 +- lib/compiler_rt/popcountti2_test.zig | 2 +- lib/compiler_rt/powiXf2_test.zig | 10 +-- lib/compiler_rt/subo.zig | 2 +- lib/compiler_rt/subodi4_test.zig | 4 +- lib/compiler_rt/subosi4_test.zig | 4 +- lib/compiler_rt/suboti4_test.zig | 4 +- lib/compiler_rt/ucmpdi2_test.zig | 2 +- lib/compiler_rt/ucmpsi2_test.zig | 2 +- lib/compiler_rt/ucmpti2_test.zig | 2 +- lib/compiler_rt/udivmod.zig | 8 +- lib/compiler_rt/udivmodei4.zig | 4 +- lib/std/Build/Cache.zig | 2 +- lib/std/Build/Cache/DepTokenizer.zig | 6 +- lib/std/Build/Step/CheckObject.zig | 2 +- lib/std/Build/Step/ConfigHeader.zig | 4 +- lib/std/Build/Step/Run.zig | 2 +- lib/std/Progress.zig | 1 + lib/std/Thread/WaitGroup.zig | 2 +- lib/std/array_hash_map.zig | 6 +- lib/std/array_list.zig | 4 +- lib/std/atomic/Atomic.zig | 2 +- lib/std/atomic/queue.zig | 4 +- lib/std/atomic/stack.zig | 4 +- lib/std/base64.zig | 22 ++--- lib/std/buf_map.zig | 3 +- lib/std/buf_set.zig | 9 +- lib/std/builtin.zig | 7 +- lib/std/child_process.zig | 2 +- lib/std/coff.zig | 2 +- lib/std/compress/deflate/bits_utils.zig | 4 +- lib/std/compress/deflate/compressor.zig | 50 +++++------ lib/std/compress/deflate/compressor_test.zig | 32 +++---- lib/std/compress/deflate/decompressor.zig | 50 +++++------ lib/std/compress/deflate/deflate_fast.zig | 64 +++++++------- .../compress/deflate/deflate_fast_test.zig | 18 ++-- lib/std/compress/deflate/dict_decoder.zig | 14 +-- .../compress/deflate/huffman_bit_writer.zig | 86 +++++++++---------- lib/std/compress/deflate/huffman_code.zig | 16 ++-- lib/std/compress/zstandard.zig | 2 +- lib/std/compress/zstandard/decode/huffman.zig | 2 +- lib/std/compress/zstandard/decompress.zig | 4 +- lib/std/crypto/25519/curve25519.zig | 2 +- lib/std/crypto/25519/field.zig | 2 +- lib/std/crypto/Certificate.zig | 2 +- lib/std/crypto/aes.zig | 2 +- lib/std/crypto/aes_ocb.zig | 2 +- lib/std/crypto/argon2.zig | 2 +- lib/std/crypto/ascon.zig | 3 +- lib/std/crypto/bcrypt.zig | 2 +- lib/std/crypto/blake3.zig | 2 +- lib/std/crypto/ecdsa.zig | 2 +- lib/std/crypto/pbkdf2.zig | 6 +- lib/std/crypto/pcurves/common.zig | 2 +- lib/std/crypto/poly1305.zig | 6 +- lib/std/crypto/salsa20.zig | 6 +- lib/std/crypto/scrypt.zig | 14 +-- lib/std/crypto/tls/Client.zig | 6 +- lib/std/debug.zig | 8 +- lib/std/dwarf.zig | 10 +-- lib/std/dwarf/expressions.zig | 8 +- lib/std/enums.zig | 5 +- lib/std/event/group.zig | 2 +- lib/std/event/loop.zig | 2 +- lib/std/event/rwlock.zig | 8 +- lib/std/fmt.zig | 20 +++-- lib/std/fmt/errol.zig | 4 +- lib/std/fmt/parse_float/parse.zig | 4 +- lib/std/fs.zig | 4 +- lib/std/fs/get_app_data_dir.zig | 4 + lib/std/fs/test.zig | 2 +- lib/std/fs/watch.zig | 6 +- lib/std/hash/auto_hash.zig | 1 + lib/std/hash/cityhash.zig | 2 +- lib/std/hash/murmur.zig | 56 ++++++------ lib/std/hash_map.zig | 8 +- lib/std/heap.zig | 18 ++-- lib/std/heap/arena_allocator.zig | 2 +- lib/std/heap/general_purpose_allocator.zig | 6 +- lib/std/heap/memory_pool.zig | 2 +- lib/std/http/Client.zig | 2 +- lib/std/http/protocol.zig | 15 ++-- lib/std/io/Reader/test.zig | 16 ++-- lib/std/io/buffered_reader.zig | 25 +++--- lib/std/io/test.zig | 4 +- lib/std/json/dynamic_test.zig | 18 ++-- lib/std/json/static_test.zig | 18 ++-- lib/std/math.zig | 3 +- lib/std/math/atan.zig | 4 +- lib/std/math/atan2.zig | 16 ++-- lib/std/math/big/int.zig | 10 +-- lib/std/math/big/int_test.zig | 37 ++++++-- lib/std/math/cbrt.zig | 4 +- lib/std/math/complex/atan.zig | 4 +- lib/std/math/ilogb.zig | 4 +- lib/std/math/log1p.zig | 8 +- lib/std/math/sqrt.zig | 2 +- lib/std/mem.zig | 25 +++--- lib/std/meta.zig | 16 ++-- lib/std/meta/trait.zig | 7 +- lib/std/net.zig | 8 +- lib/std/net/test.zig | 10 +-- lib/std/os.zig | 12 +-- lib/std/os/linux.zig | 1 + lib/std/os/linux/io_uring.zig | 39 +++++---- lib/std/os/plan9.zig | 2 +- lib/std/os/test.zig | 30 +++---- lib/std/os/uefi.zig | 7 +- lib/std/os/uefi/device_path.zig | 4 +- lib/std/os/uefi/pool_allocator.zig | 2 +- lib/std/os/uefi/protocol/device_path.zig | 5 +- lib/std/os/windows.zig | 6 +- lib/std/pdb.zig | 2 +- lib/std/priority_dequeue.zig | 10 +-- lib/std/priority_queue.zig | 2 +- lib/std/process.zig | 24 +++--- lib/std/rand/test.zig | 4 +- lib/std/sort.zig | 2 +- lib/std/sort/block.zig | 4 +- lib/std/sort/pdq.zig | 8 +- lib/std/tar.zig | 2 +- lib/std/testing.zig | 20 ++--- lib/std/treap.zig | 2 +- lib/std/unicode.zig | 2 +- lib/std/zig/Parse.zig | 3 +- lib/std/zig/c_translation.zig | 15 ++-- lib/std/zig/perf_test.zig | 2 +- lib/std/zig/render.zig | 2 +- lib/std/zig/string_literal.zig | 2 +- lib/std/zig/system/NativeTargetInfo.zig | 2 +- 174 files changed, 738 insertions(+), 711 deletions(-) diff --git a/lib/build_runner.zig b/lib/build_runner.zig index 3eb405914ff2ea60d59e7d8d45345cce35cfd6e4..a5e537c43c4c55f3248f64e295e021dafb8fe0a5 100644 --- a/lib/build_runner.zig +++ b/lib/build_runner.zig @@ -24,7 +24,7 @@ pub fn main() !void { }; const arena = thread_safe_arena.allocator(); - var args = try process.argsAlloc(arena); + const args = try process.argsAlloc(arena); // skip my own exe name var arg_idx: usize = 1; diff --git a/lib/compiler_rt/absvdi2_test.zig b/lib/compiler_rt/absvdi2_test.zig index e861ef0ff3372c1058f99d75c9e7fa2b15f33e7d..ad6f9f63b315e17393312bbf7d776c32f14af9fe 100644 --- a/lib/compiler_rt/absvdi2_test.zig +++ b/lib/compiler_rt/absvdi2_test.zig @@ -3,7 +3,7 @@ const testing = @import("std").testing; const __absvdi2 = @import("absvdi2.zig").__absvdi2; fn test__absvdi2(a: i64, expected: i64) !void { - var result = __absvdi2(a); + const result = __absvdi2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/absvsi2_test.zig b/lib/compiler_rt/absvsi2_test.zig index 9c74ebee679f428a73dda2293501063275e8f370..d0a2cbc34198f185cff020677cbcb8ddf43686d2 100644 --- a/lib/compiler_rt/absvsi2_test.zig +++ b/lib/compiler_rt/absvsi2_test.zig @@ -3,7 +3,7 @@ const testing = @import("std").testing; const __absvsi2 = @import("absvsi2.zig").__absvsi2; fn test__absvsi2(a: i32, expected: i32) !void { - var result = __absvsi2(a); + const result = __absvsi2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/absvti2_test.zig b/lib/compiler_rt/absvti2_test.zig index fbed961775bc98ef99b5eadf4317f56068e07f54..62f5d76fa5f1480d8dd32702d4791170b8c8cbf0 100644 --- a/lib/compiler_rt/absvti2_test.zig +++ b/lib/compiler_rt/absvti2_test.zig @@ -3,7 +3,7 @@ const testing = @import("std").testing; const __absvti2 = @import("absvti2.zig").__absvti2; fn test__absvti2(a: i128, expected: i128) !void { - var result = __absvti2(a); + const result = __absvti2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/addo.zig b/lib/compiler_rt/addo.zig index 5248dfb8b86bbd05995e9fbe750ed2b96df97e10..2663dc5caedee7192674f4061e1a8c36b4c2cdda 100644 --- a/lib/compiler_rt/addo.zig +++ b/lib/compiler_rt/addo.zig @@ -18,7 +18,7 @@ comptime { inline fn addoXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { @setRuntimeSafety(builtin.is_test); overflow.* = 0; - var sum: ST = a +% b; + const sum: ST = a +% b; // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract // Let sum = a +% b == a + b + carry == wraparound addition. // Overflow in a+b+carry occurs, iff a and b have opposite signs diff --git a/lib/compiler_rt/addodi4_test.zig b/lib/compiler_rt/addodi4_test.zig index f70a80a5b2c3f13753bb09c290954b5f3fedeb4f..92f8e9c1f26f1957a656b479da81ed60208840a5 100644 --- a/lib/compiler_rt/addodi4_test.zig +++ b/lib/compiler_rt/addodi4_test.zig @@ -6,8 +6,8 @@ const math = std.math; fn test__addodi4(a: i64, b: i64) !void { var result_ov: c_int = undefined; var expected_ov: c_int = undefined; - var result = addv.__addodi4(a, b, &result_ov); - var expected: i64 = simple_addodi4(a, b, &expected_ov); + const result = addv.__addodi4(a, b, &result_ov); + const expected: i64 = simple_addodi4(a, b, &expected_ov); try testing.expectEqual(expected, result); try testing.expectEqual(expected_ov, result_ov); } diff --git a/lib/compiler_rt/addosi4_test.zig b/lib/compiler_rt/addosi4_test.zig index a8f81d70d1aa7a2fc34ba90cf734928b832d3ebc..3494909f50a6677783d3271e5d773e0858f6e7b6 100644 --- a/lib/compiler_rt/addosi4_test.zig +++ b/lib/compiler_rt/addosi4_test.zig @@ -4,8 +4,8 @@ const testing = @import("std").testing; fn test__addosi4(a: i32, b: i32) !void { var result_ov: c_int = undefined; var expected_ov: c_int = undefined; - var result = addv.__addosi4(a, b, &result_ov); - var expected: i32 = simple_addosi4(a, b, &expected_ov); + const result = addv.__addosi4(a, b, &result_ov); + const expected: i32 = simple_addosi4(a, b, &expected_ov); try testing.expectEqual(expected, result); try testing.expectEqual(expected_ov, result_ov); } diff --git a/lib/compiler_rt/addoti4_test.zig b/lib/compiler_rt/addoti4_test.zig index dd0f4e3d3cd2ced7294922710364d5296344fedc..dc85830df939a134f3f3a9f467f0d3440179f646 100644 --- a/lib/compiler_rt/addoti4_test.zig +++ b/lib/compiler_rt/addoti4_test.zig @@ -6,8 +6,8 @@ const math = std.math; fn test__addoti4(a: i128, b: i128) !void { var result_ov: c_int = undefined; var expected_ov: c_int = undefined; - var result = addv.__addoti4(a, b, &result_ov); - var expected: i128 = simple_addoti4(a, b, &expected_ov); + const result = addv.__addoti4(a, b, &result_ov); + const expected: i128 = simple_addoti4(a, b, &expected_ov); try testing.expectEqual(expected, result); try testing.expectEqual(expected_ov, result_ov); } diff --git a/lib/compiler_rt/bswapdi2_test.zig b/lib/compiler_rt/bswapdi2_test.zig index a425179920e27dc8c479f774fb66adbcc9a9bee9..78e1492b4f7406523a1d84221e42354d82ac9e71 100644 --- a/lib/compiler_rt/bswapdi2_test.zig +++ b/lib/compiler_rt/bswapdi2_test.zig @@ -2,7 +2,7 @@ const bswap = @import("bswap.zig"); const testing = @import("std").testing; fn test__bswapdi2(a: u64, expected: u64) !void { - var result = bswap.__bswapdi2(a); + const result = bswap.__bswapdi2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/bswapsi2_test.zig b/lib/compiler_rt/bswapsi2_test.zig index 912d3b281909cfcfa82f8532d2ee94ba75eed003..4a138f88c5803abb95e6eb825f5464289feb16e4 100644 --- a/lib/compiler_rt/bswapsi2_test.zig +++ b/lib/compiler_rt/bswapsi2_test.zig @@ -2,7 +2,7 @@ const bswap = @import("bswap.zig"); const testing = @import("std").testing; fn test__bswapsi2(a: u32, expected: u32) !void { - var result = bswap.__bswapsi2(a); + const result = bswap.__bswapsi2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/bswapti2_test.zig b/lib/compiler_rt/bswapti2_test.zig index 6a164a28b386619f6eec1faafa6cb544c7547804..c190961dc37d492bf0b0be6c09a4d8d37c3f00d7 100644 --- a/lib/compiler_rt/bswapti2_test.zig +++ b/lib/compiler_rt/bswapti2_test.zig @@ -2,7 +2,7 @@ const bswap = @import("bswap.zig"); const testing = @import("std").testing; fn test__bswapti2(a: u128, expected: u128) !void { - var result = bswap.__bswapti2(a); + const result = bswap.__bswapti2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/ceil.zig b/lib/compiler_rt/ceil.zig index baa9edbee46da7d7050466a7fec6fe3b52b8ae6d..41ce1c00d82d14a7688236ef35a67984b61cbbf7 100644 --- a/lib/compiler_rt/ceil.zig +++ b/lib/compiler_rt/ceil.zig @@ -32,7 +32,7 @@ pub fn __ceilh(x: f16) callconv(.C) f16 { pub fn ceilf(x: f32) callconv(.C) f32 { var u: u32 = @bitCast(x); - var e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F; + const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F; var m: u32 = undefined; // TODO: Shouldn't need this explicit check. diff --git a/lib/compiler_rt/clzdi2_test.zig b/lib/compiler_rt/clzdi2_test.zig index b4b120e75424072584ec754f7e9b2e4f263f9df5..decb28421e816226bb4896965e6f89a29e88244b 100644 --- a/lib/compiler_rt/clzdi2_test.zig +++ b/lib/compiler_rt/clzdi2_test.zig @@ -2,8 +2,8 @@ const clz = @import("count0bits.zig"); const testing = @import("std").testing; fn test__clzdi2(a: u64, expected: i64) !void { - var x: i64 = @bitCast(a); - var result = clz.__clzdi2(x); + const x: i64 = @bitCast(a); + const result = clz.__clzdi2(x); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/clzti2_test.zig b/lib/compiler_rt/clzti2_test.zig index 9477a34f70fea7f25b3c33be082076fb4f573fef..cc2bbb163fc75149db0f7084024e494900d3ee80 100644 --- a/lib/compiler_rt/clzti2_test.zig +++ b/lib/compiler_rt/clzti2_test.zig @@ -2,8 +2,8 @@ const clz = @import("count0bits.zig"); const testing = @import("std").testing; fn test__clzti2(a: u128, expected: i64) !void { - var x: i128 = @bitCast(a); - var result = clz.__clzti2(x); + const x: i128 = @bitCast(a); + const result = clz.__clzti2(x); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/cmpdi2_test.zig b/lib/compiler_rt/cmpdi2_test.zig index a6d136b87541ae798bc3ced71265d3bd46907f70..3291a6564f73ce635caf135e01e5241ca93cb00c 100644 --- a/lib/compiler_rt/cmpdi2_test.zig +++ b/lib/compiler_rt/cmpdi2_test.zig @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); const testing = @import("std").testing; fn test__cmpdi2(a: i64, b: i64, expected: i64) !void { - var result = cmp.__cmpdi2(a, b); + const result = cmp.__cmpdi2(a, b); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/cmpsi2_test.zig b/lib/compiler_rt/cmpsi2_test.zig index caf35999744d5356b96443bbfa6d961898eca2b8..c418c2e14a00e1a9a29d70d7d453c3780f93b26d 100644 --- a/lib/compiler_rt/cmpsi2_test.zig +++ b/lib/compiler_rt/cmpsi2_test.zig @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); const testing = @import("std").testing; fn test__cmpsi2(a: i32, b: i32, expected: i32) !void { - var result = cmp.__cmpsi2(a, b); + const result = cmp.__cmpsi2(a, b); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/cmpti2_test.zig b/lib/compiler_rt/cmpti2_test.zig index 50f84e9952a523bfb36870491bb2e4847d31d255..3f83f2fa9c46a4e3518a8e14eb91bbb841a87848 100644 --- a/lib/compiler_rt/cmpti2_test.zig +++ b/lib/compiler_rt/cmpti2_test.zig @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); const testing = @import("std").testing; fn test__cmpti2(a: i128, b: i128, expected: i128) !void { - var result = cmp.__cmpti2(a, b); + const result = cmp.__cmpti2(a, b); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/ctzdi2_test.zig b/lib/compiler_rt/ctzdi2_test.zig index 7850ac53c4b87d3e5115507cd7aab06916168b1c..eb7822de70b082c7243d9d595b99699e516854b5 100644 --- a/lib/compiler_rt/ctzdi2_test.zig +++ b/lib/compiler_rt/ctzdi2_test.zig @@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig"); const testing = @import("std").testing; fn test__ctzdi2(a: u64, expected: i32) !void { - var x: i64 = @bitCast(a); - var result = ctz.__ctzdi2(x); + const x: i64 = @bitCast(a); + const result = ctz.__ctzdi2(x); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/ctzsi2_test.zig b/lib/compiler_rt/ctzsi2_test.zig index c273c959fe8c3d02c9c933ea537e2d5d310ad477..e545d22c337755844c59e8bdc1f1b32aebbea35f 100644 --- a/lib/compiler_rt/ctzsi2_test.zig +++ b/lib/compiler_rt/ctzsi2_test.zig @@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig"); const testing = @import("std").testing; fn test__ctzsi2(a: u32, expected: i32) !void { - var x: i32 = @bitCast(a); - var result = ctz.__ctzsi2(x); + const x: i32 = @bitCast(a); + const result = ctz.__ctzsi2(x); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/ctzti2_test.zig b/lib/compiler_rt/ctzti2_test.zig index 2b881bbf8a035e4533ef6c6cd560d45601d27bd3..70a0cd0a77c68d37428b026d61fffd93aba3f1af 100644 --- a/lib/compiler_rt/ctzti2_test.zig +++ b/lib/compiler_rt/ctzti2_test.zig @@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig"); const testing = @import("std").testing; fn test__ctzti2(a: u128, expected: i32) !void { - var x: i128 = @bitCast(a); - var result = ctz.__ctzti2(x); + const x: i128 = @bitCast(a); + const result = ctz.__ctzti2(x); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/divc3_test.zig b/lib/compiler_rt/divc3_test.zig index 525e2f70fcd8fc747f38b444a8aa30f21b03390d..4056168e1edda87e222144998e7b87d2449cd99e 100644 --- a/lib/compiler_rt/divc3_test.zig +++ b/lib/compiler_rt/divc3_test.zig @@ -19,20 +19,20 @@ test { fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void { { - var a: T = 1.0; - var b: T = 0.0; - var c: T = -1.0; - var d: T = 0.0; + const a: T = 1.0; + const b: T = 0.0; + const c: T = -1.0; + const d: T = 0.0; const result = f(a, b, c, d); try expect(result.real == -1.0); try expect(result.imag == 0.0); } { - var a: T = 1.0; - var b: T = 0.0; - var c: T = -4.0; - var d: T = 0.0; + const a: T = 1.0; + const b: T = 0.0; + const c: T = -4.0; + const d: T = 0.0; const result = f(a, b, c, d); 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) { // if the first operand is an infinity and the second operand is a finite number, then the // result of the / operator is an infinity; - var a: T = -math.inf(T); - var b: T = 0.0; - var c: T = -4.0; - var d: T = 1.0; + const a: T = -math.inf(T); + const b: T = 0.0; + const c: T = -4.0; + const d: T = 1.0; const result = f(a, b, c, d); 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) { // if the first operand is a finite number and the second operand is an infinity, then the // result of the / operator is a zero; - var a: T = 17.2; - var b: T = 0.0; - var c: T = -math.inf(T); - var d: T = 0.0; + const a: T = 17.2; + const b: T = 0.0; + const c: T = -math.inf(T); + const d: T = 0.0; const result = f(a, b, c, d); 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) { // if the first operand is a nonzero finite number or an infinity and the second operand is // a zero, then the result of the / operator is an infinity - var a: T = 1.1; - var b: T = 0.1; - var c: T = 0.0; - var d: T = 0.0; + const a: T = 1.1; + const b: T = 0.1; + const c: T = 0.0; + const d: T = 0.0; const result = f(a, b, c, d); try expect(result.real == math.inf(T)); diff --git a/lib/compiler_rt/divxf3.zig b/lib/compiler_rt/divxf3.zig index baa39cd61cb4fb00ad7d9e7a2fec54a282d6cf0d..84a7da0fc33784a4ae0004c5dbdb35486b9b4b9e 100644 --- a/lib/compiler_rt/divxf3.zig +++ b/lib/compiler_rt/divxf3.zig @@ -162,7 +162,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0). // Right shift the quotient if it falls in the [1,2) range and adjust the // exponent accordingly. - var quotient: u64 = if (quotient128 < (integerBit << 1)) b: { + const quotient: u64 = if (quotient128 < (integerBit << 1)) b: { quotientExponent -= 1; break :b @intCast(quotient128); } else @intCast(quotient128 >> 1); @@ -177,7 +177,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 { // // If r is greater than 1/2 ulp(q)*b, then q rounds up. Otherwise, we // already have the correct result. The exact halfway case cannot occur. - var residual: u64 = -%(quotient *% q63b); + const residual: u64 = -%(quotient *% q63b); const writtenExponent = quotientExponent + exponentBias; if (writtenExponent >= maxExponent) { diff --git a/lib/compiler_rt/emutls.zig b/lib/compiler_rt/emutls.zig index 01c090deabba9f2434df657466a9f72109973305..3a04012925af9d79aeed15bc7f447871df04143a 100644 --- a/lib/compiler_rt/emutls.zig +++ b/lib/compiler_rt/emutls.zig @@ -57,8 +57,8 @@ const simple_allocator = struct { /// Resize a slice. pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T { - var c_ptr: *anyopaque = @ptrCast(slice.ptr); - var new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort())); + const c_ptr: *anyopaque = @ptrCast(slice.ptr); + const new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort())); return new_array[0..len]; } @@ -78,7 +78,7 @@ const ObjectArray = struct { /// create a new ObjectArray with n slots. must call deinit() to deallocate. pub fn init(n: usize) *ObjectArray { - var array = simple_allocator.alloc(ObjectArray); + const array = simple_allocator.alloc(ObjectArray); array.* = ObjectArray{ .slots = simple_allocator.allocSlice(?ObjectPointer, n), @@ -166,7 +166,7 @@ const current_thread_storage = struct { const size = @max(16, index); // create a new array and store it. - var array: *ObjectArray = ObjectArray.init(size); + const array: *ObjectArray = ObjectArray.init(size); current_thread_storage.setspecific(array); return array; } @@ -304,13 +304,13 @@ const emutls_control = extern struct { test "simple_allocator" { if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest; - var data1: *[64]u8 = simple_allocator.alloc([64]u8); + const data1: *[64]u8 = simple_allocator.alloc([64]u8); defer simple_allocator.free(data1); for (data1) |*c| { c.* = 0xff; } - var data2: [*]u8 = simple_allocator.advancedAlloc(@alignOf(u8), 64); + const data2: [*]u8 = simple_allocator.advancedAlloc(@alignOf(u8), 64); defer simple_allocator.free(data2); for (data2[0..63]) |*c| { c.* = 0xff; @@ -324,7 +324,7 @@ test "__emutls_get_address zeroed" { try expect(ctl.object.index == 0); // retrieve a variable from ctl - var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); + const x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); try expect(ctl.object.index != 0); // index has been allocated for this ctl try expect(x.* == 0); // storage has been zeroed @@ -332,7 +332,7 @@ test "__emutls_get_address zeroed" { x.* = 1234; // retrieve a variable from ctl (same ctl) - var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); + const y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); try expect(y.* == 1234); // same content that x.* try expect(x == y); // same pointer @@ -345,7 +345,7 @@ test "__emutls_get_address with default_value" { var ctl = emutls_control.init(usize, &value); try expect(ctl.object.index == 0); - var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); + const x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); try expect(ctl.object.index != 0); try expect(x.* == 5678); // storage initialized with default value @@ -354,7 +354,7 @@ test "__emutls_get_address with default_value" { try expect(value == 5678); // the default value didn't change - var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); + const y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl))); try expect(y.* == 9012); // the modified storage persists } @@ -364,7 +364,7 @@ test "test default_value with differents sizes" { const testType = struct { fn _testType(comptime T: type, value: T) !void { var ctl = emutls_control.init(T, &value); - var x = ctl.get_typed_pointer(T); + const x = ctl.get_typed_pointer(T); try expect(x.* == value); } }._testType; diff --git a/lib/compiler_rt/exp.zig b/lib/compiler_rt/exp.zig index 65a6adb4407f20cb1f141e9a2b63bc8869b1d320..6b8ac040764001927c33ef07ec3cde30eb05e585 100644 --- a/lib/compiler_rt/exp.zig +++ b/lib/compiler_rt/exp.zig @@ -117,7 +117,7 @@ pub fn exp(x_: f64) callconv(.C) f64 { const P5: f64 = 4.13813679705723846039e-08; var x = x_; - var ux: u64 = @bitCast(x); + const ux: u64 = @bitCast(x); var hx = ux >> 32; const sign: i32 = @intCast(hx >> 31); hx &= 0x7FFFFFFF; diff --git a/lib/compiler_rt/exp2.zig b/lib/compiler_rt/exp2.zig index 84bbe19d7304b6397ace99df915a0525e5c169ed..5ffb73c4f55d07bf9ba6c45f2f91e6e24a7ce70e 100644 --- a/lib/compiler_rt/exp2.zig +++ b/lib/compiler_rt/exp2.zig @@ -38,7 +38,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 { const P3: f32 = 0x1.c6b348p-5; const P4: f32 = 0x1.3b2c9cp-7; - var u: u32 = @bitCast(x); + const u: u32 = @bitCast(x); const ix = u & 0x7FFFFFFF; // |x| > 126 diff --git a/lib/compiler_rt/ffsdi2_test.zig b/lib/compiler_rt/ffsdi2_test.zig index 135052bf39032365152e1b5f22f446396cf6d7ce..1845990231ada9423e9c9fb01e97274f152653a8 100644 --- a/lib/compiler_rt/ffsdi2_test.zig +++ b/lib/compiler_rt/ffsdi2_test.zig @@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig"); const testing = @import("std").testing; fn test__ffsdi2(a: u64, expected: i32) !void { - var x = @as(i64, @bitCast(a)); - var result = ffs.__ffsdi2(x); + const x = @as(i64, @bitCast(a)); + const result = ffs.__ffsdi2(x); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/ffssi2_test.zig b/lib/compiler_rt/ffssi2_test.zig index 38435a9e4bb8e2cacbe43f062933dbab7e3d8d24..24cb24eb3d1238e50c872a2a84596b4a82a367e2 100644 --- a/lib/compiler_rt/ffssi2_test.zig +++ b/lib/compiler_rt/ffssi2_test.zig @@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig"); const testing = @import("std").testing; fn test__ffssi2(a: u32, expected: i32) !void { - var x = @as(i32, @bitCast(a)); - var result = ffs.__ffssi2(x); + const x = @as(i32, @bitCast(a)); + const result = ffs.__ffssi2(x); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/ffsti2_test.zig b/lib/compiler_rt/ffsti2_test.zig index a0686b33e40d79c4ea627dc3ac9042b6cb59857b..b5bc73f3b383fb9ed9d6ae41ffb158c749d54f86 100644 --- a/lib/compiler_rt/ffsti2_test.zig +++ b/lib/compiler_rt/ffsti2_test.zig @@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig"); const testing = @import("std").testing; fn test__ffsti2(a: u128, expected: i32) !void { - var x = @as(i128, @bitCast(a)); - var result = ffs.__ffsti2(x); + const x = @as(i128, @bitCast(a)); + const result = ffs.__ffsti2(x); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/float_from_int.zig b/lib/compiler_rt/float_from_int.zig index 5ef511a4bfaa005086c75ff7bd16bedbde8b6589..66f5eb0587ffaaa0131de0227a897717b1b64a44 100644 --- a/lib/compiler_rt/float_from_int.zig +++ b/lib/compiler_rt/float_from_int.zig @@ -18,12 +18,12 @@ pub fn floatFromInt(comptime T: type, x: anytype) T { const max_exp = exp_bias; // Sign - var abs_val = if (@TypeOf(x) == comptime_int or @typeInfo(@TypeOf(x)).Int.signedness == .signed) @abs(x) else x; + const abs_val = if (@TypeOf(x) == comptime_int or @typeInfo(@TypeOf(x)).Int.signedness == .signed) @abs(x) else x; const sign_bit = if (x < 0) @as(uT, 1) << (float_bits - 1) else 0; var result: uT = sign_bit; // Compute significand - var exp = int_bits - @clz(abs_val) - 1; + const exp = int_bits - @clz(abs_val) - 1; if (int_bits <= fractional_bits or exp <= fractional_bits) { const shift_amt = fractional_bits - @as(math.Log2Int(uT), @intCast(exp)); @@ -31,7 +31,7 @@ pub fn floatFromInt(comptime T: type, x: anytype) T { result = @as(uT, @intCast(abs_val)) << shift_amt; result ^= implicit_bit; // Remove implicit integer bit } else { - var shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits); + const shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits); const exact_tie: bool = @ctz(abs_val) == shift_amt - 1; // Shift down result and remove implicit integer bit diff --git a/lib/compiler_rt/fma.zig b/lib/compiler_rt/fma.zig index accc4ed36cfe243ec8179f1b44c5a2b04877439e..ad775db5dd6e18c1dc45db89d8a686247f050ae6 100644 --- a/lib/compiler_rt/fma.zig +++ b/lib/compiler_rt/fma.zig @@ -59,13 +59,13 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 { } const x1 = math.frexp(x); - var ex = x1.exponent; - var xs = x1.significand; + const ex = x1.exponent; + const xs = x1.significand; const x2 = math.frexp(y); - var ey = x2.exponent; - var ys = x2.significand; + const ey = x2.exponent; + const ys = x2.significand; const x3 = math.frexp(z); - var ez = x3.exponent; + const ez = x3.exponent; var zs = x3.significand; var spread = ex + ey - ez; @@ -118,13 +118,13 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.C) f128 { } const x1 = math.frexp(x); - var ex = x1.exponent; - var xs = x1.significand; + const ex = x1.exponent; + const xs = x1.significand; const x2 = math.frexp(y); - var ey = x2.exponent; - var ys = x2.significand; + const ey = x2.exponent; + const ys = x2.significand; const x3 = math.frexp(z); - var ez = x3.exponent; + const ez = x3.exponent; var zs = x3.significand; var spread = ex + ey - ez; @@ -181,15 +181,15 @@ fn dd_mul(a: f64, b: f64) dd { var p = a * split; var ha = a - p; ha += p; - var la = a - ha; + const la = a - ha; p = b * split; var hb = b - p; hb += p; - var lb = b - hb; + const lb = b - hb; p = ha * hb; - var q = ha * lb + la * hb; + const q = ha * lb + la * hb; ret.hi = p + q; ret.lo = p - ret.hi + q + la * lb; @@ -301,15 +301,15 @@ fn dd_mul128(a: f128, b: f128) dd128 { var p = a * split; var ha = a - p; ha += p; - var la = a - ha; + const la = a - ha; p = b * split; var hb = b - p; hb += p; - var lb = b - hb; + const lb = b - hb; p = ha * hb; - var q = ha * lb + la * hb; + const q = ha * lb + la * hb; ret.hi = p + q; ret.lo = p - ret.hi + q + la * lb; diff --git a/lib/compiler_rt/fmod.zig b/lib/compiler_rt/fmod.zig index 7c40298f320addd33e023f157943c5e4390346cc..08e1ff892cf6580370f5bf482fe38e32583e1b42 100644 --- a/lib/compiler_rt/fmod.zig +++ b/lib/compiler_rt/fmod.zig @@ -81,13 +81,13 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { if (expB == 0) expB = normalize(f80, &bRep); var highA: u64 = 0; - var highB: u64 = 0; + const highB: u64 = 0; var lowA: u64 = @truncate(aRep); - var lowB: u64 = @truncate(bRep); + const lowB: u64 = @truncate(bRep); while (expA > expB) : (expA -= 1) { var high = highA -% highB; - var low = lowA -% lowB; + const low = lowA -% lowB; if (lowA < lowB) { high -%= 1; } @@ -104,7 +104,7 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 { } var high = highA -% highB; - var low = lowA -% lowB; + const low = lowA -% lowB; if (lowA < lowB) { high -%= 1; } @@ -194,13 +194,13 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { // OR in extra non-stored mantissa digit var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48; - var highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48; + const highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48; var lowA: u64 = aPtr_u64[low_index]; - var lowB: u64 = bPtr_u64[low_index]; + const lowB: u64 = bPtr_u64[low_index]; while (expA > expB) : (expA -= 1) { var high = highA -% highB; - var low = lowA -% lowB; + const low = lowA -% lowB; if (lowA < lowB) { high -%= 1; } @@ -217,7 +217,7 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { } var high = highA -% highB; - var low = lowA -% lowB; + const low = lowA -% lowB; if (lowA < lowB) { high -= 1; } diff --git a/lib/compiler_rt/mulc3.zig b/lib/compiler_rt/mulc3.zig index 0033df70b6ed7df1b6e8821177429cf8d99392df..eea753245f7687b2e3e9b65c12bdd278f1a3c757 100644 --- a/lib/compiler_rt/mulc3.zig +++ b/lib/compiler_rt/mulc3.zig @@ -25,7 +25,7 @@ pub inline fn mulc3(comptime T: type, a_in: T, b_in: T, c_in: T, d_in: T) Comple const zero: T = 0.0; const one: T = 1.0; - var z = Complex(T){ + const z: Complex(T) = .{ .real = ac - bd, .imag = ad + bc, }; diff --git a/lib/compiler_rt/mulc3_test.zig b/lib/compiler_rt/mulc3_test.zig index b07ecd12ae4752862895e74bcee2145a42a9f868..6495f1cfe10b3a3453f0447ed9fa119295371be6 100644 --- a/lib/compiler_rt/mulc3_test.zig +++ b/lib/compiler_rt/mulc3_test.zig @@ -19,20 +19,20 @@ test { fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void { { - var a: T = 1.0; - var b: T = 0.0; - var c: T = -1.0; - var d: T = 0.0; + const a: T = 1.0; + const b: T = 0.0; + const c: T = -1.0; + const d: T = 0.0; const result = f(a, b, c, d); try expect(result.real == -1.0); try expect(result.imag == 0.0); } { - var a: T = 1.0; - var b: T = 0.0; - var c: T = -4.0; - var d: T = 0.0; + const a: T = 1.0; + const b: T = 0.0; + const c: T = -4.0; + const d: T = 0.0; const result = f(a, b, c, d); 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) { // if one operand is an infinity and the other operand is a nonzero finite number or an infinity, // then the result of the * operator is an infinity; - var a: T = math.inf(T); - var b: T = -math.inf(T); - var c: T = 1.0; - var d: T = 0.0; + const a: T = math.inf(T); + const b: T = -math.inf(T); + const c: T = 1.0; + const d: T = 0.0; const result = f(a, b, c, d); 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) { // if one operand is an infinity and the other operand is a nonzero finite number or an infinity, // then the result of the * operator is an infinity; - var a: T = math.inf(T); - var b: T = -1.0; - var c: T = 1.0; - var d: T = math.inf(T); + const a: T = math.inf(T); + const b: T = -1.0; + const c: T = 1.0; + const d: T = math.inf(T); const result = f(a, b, c, d); try expect(result.real == math.inf(T)); diff --git a/lib/compiler_rt/mulo.zig b/lib/compiler_rt/mulo.zig index d40554da1080f3fdea03904e356b4cdeed44fa5a..ec77068fc626a810931910cd6cee058e4fee8fd7 100644 --- a/lib/compiler_rt/mulo.zig +++ b/lib/compiler_rt/mulo.zig @@ -20,7 +20,7 @@ comptime { inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { overflow.* = 0; const min = math.minInt(ST); - var res: ST = a *% b; + const res: ST = a *% b; // Hacker's Delight section Overflow subsection Multiplication // case a=-2^{31}, b=-1 problem, because // 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) }; const min = math.minInt(ST); const max = math.maxInt(ST); - var res: EST = @as(EST, a) * @as(EST, b); + const res: EST = @as(EST, a) * @as(EST, b); //invariant: -2^{bitwidth(EST)} < res < 2^{bitwidth(EST)-1} if (res < min or max < res) overflow.* = 1; diff --git a/lib/compiler_rt/negdi2_test.zig b/lib/compiler_rt/negdi2_test.zig index 2bb6ad29a81d16c0ad6375e505ed7035d99abca3..a4bb0217ada987622d4269b682f369ae83864c2e 100644 --- a/lib/compiler_rt/negdi2_test.zig +++ b/lib/compiler_rt/negdi2_test.zig @@ -2,7 +2,7 @@ const neg = @import("negXi2.zig"); const testing = @import("std").testing; fn test__negdi2(a: i64, expected: i64) !void { - var result = neg.__negdi2(a); + const result = neg.__negdi2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/negsi2_test.zig b/lib/compiler_rt/negsi2_test.zig index 608a44c12fdc7427860385463e97c66d5733c13c..2584de2136e9f2ebb9691afe5323e071edeaf9f8 100644 --- a/lib/compiler_rt/negsi2_test.zig +++ b/lib/compiler_rt/negsi2_test.zig @@ -5,7 +5,7 @@ const testing = std.testing; const print = std.debug.print; fn test__negsi2(a: i32, expected: i32) !void { - var result = neg.__negsi2(a); + const result = neg.__negsi2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/negti2_test.zig b/lib/compiler_rt/negti2_test.zig index 37841573c122baa8673b45f40a14a6e08bc06752..d58f9c8f270f236b6184d75ed1278c75e72f6fe7 100644 --- a/lib/compiler_rt/negti2_test.zig +++ b/lib/compiler_rt/negti2_test.zig @@ -2,7 +2,7 @@ const neg = @import("negXi2.zig"); const testing = @import("std").testing; fn test__negti2(a: i128, expected: i128) !void { - var result = neg.__negti2(a); + const result = neg.__negti2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/negvdi2_test.zig b/lib/compiler_rt/negvdi2_test.zig index 25a7213f691e8c2108d3781cc6e3a0a0345f7338..8d791c5371deaeb38a251910abe974830827353b 100644 --- a/lib/compiler_rt/negvdi2_test.zig +++ b/lib/compiler_rt/negvdi2_test.zig @@ -2,7 +2,7 @@ const negv = @import("negv.zig"); const testing = @import("std").testing; fn test__negvdi2(a: i64, expected: i64) !void { - var result = negv.__negvdi2(a); + const result = negv.__negvdi2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/negvsi2_test.zig b/lib/compiler_rt/negvsi2_test.zig index 4e0c27c9aef82ef419d718424dfb46ad6ffa601d..f502b65d2bade140af2e5117d3550a52995b5411 100644 --- a/lib/compiler_rt/negvsi2_test.zig +++ b/lib/compiler_rt/negvsi2_test.zig @@ -2,7 +2,7 @@ const negv = @import("negv.zig"); const testing = @import("std").testing; fn test__negvsi2(a: i32, expected: i32) !void { - var result = negv.__negvsi2(a); + const result = negv.__negvsi2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/negvti2_test.zig b/lib/compiler_rt/negvti2_test.zig index aa50f2bd43c22977383cd00f5a22e0971253a6ac..dd183481e85f1d06ceec0fadaffcc7a52d5274cc 100644 --- a/lib/compiler_rt/negvti2_test.zig +++ b/lib/compiler_rt/negvti2_test.zig @@ -2,7 +2,7 @@ const negv = @import("negv.zig"); const testing = @import("std").testing; fn test__negvti2(a: i128, expected: i128) !void { - var result = negv.__negvti2(a); + const result = negv.__negvti2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/paritydi2_test.zig b/lib/compiler_rt/paritydi2_test.zig index 92f8e6a53e40b0432fd0d635c0b0ca08e8630bb7..fdcbe3ac6890866336162f6457a0358a84c4c083 100644 --- a/lib/compiler_rt/paritydi2_test.zig +++ b/lib/compiler_rt/paritydi2_test.zig @@ -13,8 +13,8 @@ fn paritydi2Naive(a: i64) i32 { } fn test__paritydi2(a: i64) !void { - var x = parity.__paritydi2(a); - var expected: i64 = paritydi2Naive(a); + const x = parity.__paritydi2(a); + const expected: i64 = paritydi2Naive(a); try testing.expectEqual(expected, x); } @@ -30,7 +30,7 @@ test "paritydi2" { var rnd = RndGen.init(42); var i: u32 = 0; while (i < 10_000) : (i += 1) { - var rand_num = rnd.random().int(i64); + const rand_num = rnd.random().int(i64); try test__paritydi2(rand_num); } } diff --git a/lib/compiler_rt/paritysi2_test.zig b/lib/compiler_rt/paritysi2_test.zig index 804dc74c33ca749a85e26362c3762fe4e67ff2ad..ec1820c4fd80811107e461b43f9b3b4a33a44d53 100644 --- a/lib/compiler_rt/paritysi2_test.zig +++ b/lib/compiler_rt/paritysi2_test.zig @@ -13,8 +13,8 @@ fn paritysi2Naive(a: i32) i32 { } fn test__paritysi2(a: i32) !void { - var x = parity.__paritysi2(a); - var expected: i32 = paritysi2Naive(a); + const x = parity.__paritysi2(a); + const expected: i32 = paritysi2Naive(a); try testing.expectEqual(expected, x); } @@ -30,7 +30,7 @@ test "paritysi2" { var rnd = RndGen.init(42); var i: u32 = 0; while (i < 10_000) : (i += 1) { - var rand_num = rnd.random().int(i32); + const rand_num = rnd.random().int(i32); try test__paritysi2(rand_num); } } diff --git a/lib/compiler_rt/parityti2_test.zig b/lib/compiler_rt/parityti2_test.zig index f934ee90215c40fe10649007e95273526ee8990d..587cc1890fcff158fa532c553c901eb8eade7776 100644 --- a/lib/compiler_rt/parityti2_test.zig +++ b/lib/compiler_rt/parityti2_test.zig @@ -13,8 +13,8 @@ fn parityti2Naive(a: i128) i32 { } fn test__parityti2(a: i128) !void { - var x = parity.__parityti2(a); - var expected: i128 = parityti2Naive(a); + const x = parity.__parityti2(a); + const expected: i128 = parityti2Naive(a); try testing.expectEqual(expected, x); } @@ -30,7 +30,7 @@ test "parityti2" { var rnd = RndGen.init(42); var i: u32 = 0; while (i < 10_000) : (i += 1) { - var rand_num = rnd.random().int(i128); + const rand_num = rnd.random().int(i128); try test__parityti2(rand_num); } } diff --git a/lib/compiler_rt/popcountdi2_test.zig b/lib/compiler_rt/popcountdi2_test.zig index daf2c1f18332680fc5a4a5eb27f1b50ffb7e6681..b3967c410b15ae8e72696a4907d93bc7fd6ade57 100644 --- a/lib/compiler_rt/popcountdi2_test.zig +++ b/lib/compiler_rt/popcountdi2_test.zig @@ -29,7 +29,7 @@ test "popcountdi2" { var rnd = RndGen.init(42); var i: u32 = 0; while (i < 10_000) : (i += 1) { - var rand_num = rnd.random().int(i64); + const rand_num = rnd.random().int(i64); try test__popcountdi2(rand_num); } } diff --git a/lib/compiler_rt/popcountsi2_test.zig b/lib/compiler_rt/popcountsi2_test.zig index 497b62516fb93b6429b71d20fcb07b8e8d6d686e..bf30e069aa14cc10267021a4bd33e1a5d993d914 100644 --- a/lib/compiler_rt/popcountsi2_test.zig +++ b/lib/compiler_rt/popcountsi2_test.zig @@ -29,7 +29,7 @@ test "popcountsi2" { var rnd = RndGen.init(42); var i: u32 = 0; while (i < 10_000) : (i += 1) { - var rand_num = rnd.random().int(i32); + const rand_num = rnd.random().int(i32); try test__popcountsi2(rand_num); } } diff --git a/lib/compiler_rt/popcountti2_test.zig b/lib/compiler_rt/popcountti2_test.zig index b873bcd449f11e2d1133f7e7e28c2fa614e6840c..4d242a8328b5e05ae5f341cdaa1947af422a72d7 100644 --- a/lib/compiler_rt/popcountti2_test.zig +++ b/lib/compiler_rt/popcountti2_test.zig @@ -29,7 +29,7 @@ test "popcountti2" { var rnd = RndGen.init(42); var i: u32 = 0; while (i < 10_000) : (i += 1) { - var rand_num = rnd.random().int(i128); + const rand_num = rnd.random().int(i128); try test__popcountti2(rand_num); } } diff --git a/lib/compiler_rt/powiXf2_test.zig b/lib/compiler_rt/powiXf2_test.zig index dfa676a5a8b49cd9113f0a7bb563a95e1f2ce646..7bd43c73c3d2d1a379a6ef66977c55dff1fc8a00 100644 --- a/lib/compiler_rt/powiXf2_test.zig +++ b/lib/compiler_rt/powiXf2_test.zig @@ -9,27 +9,27 @@ const testing = std.testing; const math = std.math; fn test__powihf2(a: f16, b: i32, expected: f16) !void { - var result = powiXf2.__powihf2(a, b); + const result = powiXf2.__powihf2(a, b); try testing.expectEqual(expected, result); } fn test__powisf2(a: f32, b: i32, expected: f32) !void { - var result = powiXf2.__powisf2(a, b); + const result = powiXf2.__powisf2(a, b); try testing.expectEqual(expected, result); } fn test__powidf2(a: f64, b: i32, expected: f64) !void { - var result = powiXf2.__powidf2(a, b); + const result = powiXf2.__powidf2(a, b); try testing.expectEqual(expected, result); } fn test__powitf2(a: f128, b: i32, expected: f128) !void { - var result = powiXf2.__powitf2(a, b); + const result = powiXf2.__powitf2(a, b); try testing.expectEqual(expected, result); } fn test__powixf2(a: f80, b: i32, expected: f80) !void { - var result = powiXf2.__powixf2(a, b); + const result = powiXf2.__powixf2(a, b); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/subo.zig b/lib/compiler_rt/subo.zig index b3542a9e9d810bf330fe554e22a19e81abc6f905..a14dd5e18e22ed31c0178a5f4d9d1cb44c16466d 100644 --- a/lib/compiler_rt/subo.zig +++ b/lib/compiler_rt/subo.zig @@ -27,7 +27,7 @@ pub fn __suboti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 { inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { overflow.* = 0; - var sum: ST = a -% b; + const sum: ST = a -% b; // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract // Let sum = a -% b == a - b - carry == wraparound subtraction. // Overflow in a-b-carry occurs, iff a and b have opposite signs diff --git a/lib/compiler_rt/subodi4_test.zig b/lib/compiler_rt/subodi4_test.zig index 687e97c71cc31fbeccb1410ddc0beb3aaca7ad51..2dd717e14b4b440f80c119fa43ff5406af6c58b7 100644 --- a/lib/compiler_rt/subodi4_test.zig +++ b/lib/compiler_rt/subodi4_test.zig @@ -6,8 +6,8 @@ const math = std.math; fn test__subodi4(a: i64, b: i64) !void { var result_ov: c_int = undefined; var expected_ov: c_int = undefined; - var result = subo.__subodi4(a, b, &result_ov); - var expected: i64 = simple_subodi4(a, b, &expected_ov); + const result = subo.__subodi4(a, b, &result_ov); + const expected: i64 = simple_subodi4(a, b, &expected_ov); try testing.expectEqual(expected, result); try testing.expectEqual(expected_ov, result_ov); } diff --git a/lib/compiler_rt/subosi4_test.zig b/lib/compiler_rt/subosi4_test.zig index 6c7ae97c253dfc5af80521cae083a1f6b9486d1e..8644e8100ef66dcd4a1ec17e03767bef38020b26 100644 --- a/lib/compiler_rt/subosi4_test.zig +++ b/lib/compiler_rt/subosi4_test.zig @@ -4,8 +4,8 @@ const testing = @import("std").testing; fn test__subosi4(a: i32, b: i32) !void { var result_ov: c_int = undefined; var expected_ov: c_int = undefined; - var result = subo.__subosi4(a, b, &result_ov); - var expected: i32 = simple_subosi4(a, b, &expected_ov); + const result = subo.__subosi4(a, b, &result_ov); + const expected: i32 = simple_subosi4(a, b, &expected_ov); try testing.expectEqual(expected, result); try testing.expectEqual(expected_ov, result_ov); } diff --git a/lib/compiler_rt/suboti4_test.zig b/lib/compiler_rt/suboti4_test.zig index f42fe3edce2a1e115519448840c9860df4dc9664..68ad0ff72fe9e6048becccc92cc8e0b63d8b7211 100644 --- a/lib/compiler_rt/suboti4_test.zig +++ b/lib/compiler_rt/suboti4_test.zig @@ -6,8 +6,8 @@ const math = std.math; fn test__suboti4(a: i128, b: i128) !void { var result_ov: c_int = undefined; var expected_ov: c_int = undefined; - var result = subo.__suboti4(a, b, &result_ov); - var expected: i128 = simple_suboti4(a, b, &expected_ov); + const result = subo.__suboti4(a, b, &result_ov); + const expected: i128 = simple_suboti4(a, b, &expected_ov); try testing.expectEqual(expected, result); try testing.expectEqual(expected_ov, result_ov); } diff --git a/lib/compiler_rt/ucmpdi2_test.zig b/lib/compiler_rt/ucmpdi2_test.zig index 00c10e52be39a3b0bc84938b191e6dee18c00855..5efc8daffeeb330ebd64b286f9a6fd3db9cd400e 100644 --- a/lib/compiler_rt/ucmpdi2_test.zig +++ b/lib/compiler_rt/ucmpdi2_test.zig @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); const testing = @import("std").testing; fn test__ucmpdi2(a: u64, b: u64, expected: i32) !void { - var result = cmp.__ucmpdi2(a, b); + const result = cmp.__ucmpdi2(a, b); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/ucmpsi2_test.zig b/lib/compiler_rt/ucmpsi2_test.zig index cbca4b33cfd74919283887865e9ec52d08d3b543..161438ab78fd8fd2994d44a8da020b22dd977aa4 100644 --- a/lib/compiler_rt/ucmpsi2_test.zig +++ b/lib/compiler_rt/ucmpsi2_test.zig @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); const testing = @import("std").testing; fn test__ucmpsi2(a: u32, b: u32, expected: i32) !void { - var result = cmp.__ucmpsi2(a, b); + const result = cmp.__ucmpsi2(a, b); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/ucmpti2_test.zig b/lib/compiler_rt/ucmpti2_test.zig index 56f2dc61fbbca1966b241d511ac4f9a6276d09a2..6b3f7fdf2159b521baf03716ac612c8fe5a24e9e 100644 --- a/lib/compiler_rt/ucmpti2_test.zig +++ b/lib/compiler_rt/ucmpti2_test.zig @@ -2,7 +2,7 @@ const cmp = @import("cmp.zig"); const testing = @import("std").testing; fn test__ucmpti2(a: u128, b: u128, expected: i32) !void { - var result = cmp.__ucmpti2(a, b); + const result = cmp.__ucmpti2(a, b); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/udivmod.zig b/lib/compiler_rt/udivmod.zig index 1075cb0f315b1411066dbb79f4b1c9c4b98f7542..a9705f317d322c056afbe7e35062f4d00e367391 100644 --- a/lib/compiler_rt/udivmod.zig +++ b/lib/compiler_rt/udivmod.zig @@ -52,7 +52,7 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T { if (rhat >= b) break; } - var un21 = un64 *% b +% un1 -% q1 *% v; + const un21 = un64 *% b +% un1 -% q1 *% v; // Compute the second quotient digit var q0 = un21 / vn1; @@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { return 0; } - var a: [2]HalfT = @bitCast(a_); - var b: [2]HalfT = @bitCast(b_); + const a: [2]HalfT = @bitCast(a_); + const b: [2]HalfT = @bitCast(b_); var q: [2]HalfT = undefined; var r: [2]HalfT = undefined; @@ -125,7 +125,7 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { } // 0 <= shift <= 63 - var shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]); + const shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]); var af: T = @bitCast(a); var bf = @as(T, @bitCast(b)) << shift; q = @bitCast(@as(T, 0)); diff --git a/lib/compiler_rt/udivmodei4.zig b/lib/compiler_rt/udivmodei4.zig index 064a3b842e356b9f42faf0afaec00bcb2595d12a..194f45a23dc43eddc7e83d7c5eff50d80e77cb4c 100644 --- a/lib/compiler_rt/udivmodei4.zig +++ b/lib/compiler_rt/udivmodei4.zig @@ -116,7 +116,7 @@ pub fn __udivei4(r_q: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) @setRuntimeSafety(builtin.is_test); const u = u_p[0 .. bits / 32]; const v = v_p[0 .. bits / 32]; - var q = r_q[0 .. bits / 32]; + const q = r_q[0 .. bits / 32]; @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable; } @@ -124,7 +124,7 @@ pub fn __umodei4(r_p: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize) @setRuntimeSafety(builtin.is_test); const u = u_p[0 .. bits / 32]; const v = v_p[0 .. bits / 32]; - var r = r_p[0 .. bits / 32]; + const r = r_p[0 .. bits / 32]; @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable; } diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig index a5943be6bb05a305672ebecec93ab73bd91a3da8..283a3d1f5f7235be7015051773e17d745b40dac1 100644 --- a/lib/std/Build/Cache.zig +++ b/lib/std/Build/Cache.zig @@ -141,7 +141,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath { var i: u8 = 1; // Start at 1 to skip over checking the null prefix. while (i < prefixes_slice.len) : (i += 1) { const p = prefixes_slice[i].path.?; - var sub_path = getPrefixSubpath(gpa, p, resolved_path) catch |err| switch (err) { + const sub_path = getPrefixSubpath(gpa, p, resolved_path) catch |err| switch (err) { error.NotASubPath => continue, else => |e| return e, }; diff --git a/lib/std/Build/Cache/DepTokenizer.zig b/lib/std/Build/Cache/DepTokenizer.zig index 0e5224edc043c785d7e8a664159d896d0cdc71ff..9edc53cbb2e3f4c0144dd0cf5916e938ab169069 100644 --- a/lib/std/Build/Cache/DepTokenizer.zig +++ b/lib/std/Build/Cache/DepTokenizer.zig @@ -950,7 +950,7 @@ fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void { fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void { var buf: [80]u8 = undefined; - var text = try std.fmt.bufPrint(buf[0..], "{s} {d} bytes ", .{ label, bytes.len }); + const text = try std.fmt.bufPrint(buf[0..], "{s} {d} bytes ", .{ label, bytes.len }); try out.writeAll(text); var i: usize = text.len; const end = 79; @@ -983,12 +983,12 @@ fn hexDump(out: anytype, bytes: []const u8) !void { try printDecValue(out, offset, 8); try out.writeAll(":"); try out.writeAll(" "); - var end1 = @min(offset + n, offset + 8); + const end1 = @min(offset + n, offset + 8); for (bytes[offset..end1]) |b| { try out.writeAll(" "); try printHexValue(out, b, 2); } - var end2 = offset + n; + const end2 = offset + n; if (end2 > end1) { try out.writeAll(" "); for (bytes[end1..end2]) |b| { diff --git a/lib/std/Build/Step/CheckObject.zig b/lib/std/Build/Step/CheckObject.zig index d27c8d6d270c6fc0d6bbeb6406db7d5d3faad2d4..d82691672747c1f1c8672e144f6d12b3eb1fb252 100644 --- a/lib/std/Build/Step/CheckObject.zig +++ b/lib/std/Build/Step/CheckObject.zig @@ -293,7 +293,7 @@ const Check = struct { /// Creates a new empty sequence of actions. pub fn checkStart(self: *CheckObject) void { - var new_check = Check.create(self.step.owner.allocator); + const new_check = Check.create(self.step.owner.allocator); self.checks.append(new_check) catch @panic("OOM"); } diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index 87d02e2f9393672d5fcec7f01855f9fd99d18895..9f040349c67782b2716979ef960ae82e21868b26 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -307,8 +307,8 @@ fn render_cmake( values: std.StringArrayHashMap(Value), src_path: []const u8, ) !void { - var build = step.owner; - var allocator = build.allocator; + const build = step.owner; + const allocator = build.allocator; var values_copy = try values.clone(); defer values_copy.deinit(); diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index 3d26d25070f4106c4bdb6b4ed257b5323121bf0c..5555b03e94efe8f33188f78c4cfbc9e08394715b 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -301,7 +301,7 @@ pub fn addPathDir(self: *Run, search_path: []const u8) void { const env_map = getEnvMapInternal(self); const key = "PATH"; - var prev_path = env_map.get(key); + const prev_path = env_map.get(key); if (prev_path) |pp| { const new_path = b.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path }); diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig index 7d3b8b8b1c43b3bf5fc7f8e0860c054f2e80b89b..fef89a228fdeee1933abebe31ffe11700c7e1fa5 100644 --- a/lib/std/Progress.zig +++ b/lib/std/Progress.zig @@ -397,6 +397,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any test "basic functionality" { var disable = true; + _ = &disable; if (disable) { // This test is disabled because it uses time.sleep() and is therefore slow. It also // prints bogus progress data to stderr. diff --git a/lib/std/Thread/WaitGroup.zig b/lib/std/Thread/WaitGroup.zig index c8be6658db76bc530f35bda4785274a3882bb319..f2274db86a27ea6a3f1e82e4ad7c132f2207e29a 100644 --- a/lib/std/Thread/WaitGroup.zig +++ b/lib/std/Thread/WaitGroup.zig @@ -25,7 +25,7 @@ pub fn finish(self: *WaitGroup) void { } pub fn wait(self: *WaitGroup) void { - var state = self.state.fetchAdd(is_waiting, .Acquire); + const state = self.state.fetchAdd(is_waiting, .Acquire); assert(state & is_waiting == 0); if ((state / one_pending) > 0) { diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig index bf5f6581ac1b57bb886f9e12f2200bdf56702e82..b82a037e144769e0432cbb1b921e07b4b9c93d88 100644 --- a/lib/std/array_hash_map.zig +++ b/lib/std/array_hash_map.zig @@ -2076,11 +2076,11 @@ test "iterator hash map" { try reset_map.putNoClobber(1, 22); try reset_map.putNoClobber(2, 33); - var keys = [_]i32{ + const keys = [_]i32{ 0, 2, 1, }; - var values = [_]i32{ + const values = [_]i32{ 11, 33, 22, }; @@ -2116,7 +2116,7 @@ test "iterator hash map" { } it.reset(); - var entry = it.next().?; + const entry = it.next().?; try testing.expect(entry.key_ptr.* == first_entry.key_ptr.*); try testing.expect(entry.value_ptr.* == first_entry.value_ptr.*); } diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index e50eb920412e16045a13542a7bf22f7366a96d98..24655046a9d9b725657fd45500243f83191f5df1 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -979,7 +979,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void { if (self.capacity >= new_capacity) return; - var better_capacity = growCapacity(self.capacity, new_capacity); + const better_capacity = growCapacity(self.capacity, new_capacity); return self.ensureTotalCapacityPrecise(allocator, better_capacity); } @@ -1159,7 +1159,7 @@ test "std.ArrayList/ArrayListUnmanaged.init" { } { - var list = ArrayListUnmanaged(i32){}; + const list = ArrayListUnmanaged(i32){}; try testing.expect(list.items.len == 0); try testing.expect(list.capacity == 0); diff --git a/lib/std/atomic/Atomic.zig b/lib/std/atomic/Atomic.zig index e38ada0c20bdd54bef5afe1bb386c243562fa309..892e9633d5073b48b74aa7cfc5bdf6ab8dc8e0d2 100644 --- a/lib/std/atomic/Atomic.zig +++ b/lib/std/atomic/Atomic.zig @@ -125,7 +125,7 @@ pub fn Atomic(comptime T: type) type { @compileError(@tagName(Ordering.Unordered) ++ " is only allowed on atomic loads and stores"); } - comptime var success_is_stronger = switch (failure) { + const success_is_stronger = switch (failure) { .SeqCst => success == .SeqCst, .AcqRel => @compileError(@tagName(failure) ++ " implies " ++ @tagName(Ordering.Release) ++ " which is only allowed on success"), .Acquire => success == .SeqCst or success == .AcqRel or success == .Acquire, diff --git a/lib/std/atomic/queue.zig b/lib/std/atomic/queue.zig index e8d37507d3751c4a6f1f410c13b02d7a07d264a6..552f2f95101671264e368a40689b1e3f51e9467b 100644 --- a/lib/std/atomic/queue.zig +++ b/lib/std/atomic/queue.zig @@ -175,11 +175,11 @@ const puts_per_thread = 500; const put_thread_count = 3; test "std.atomic.Queue" { - var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); + const plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); defer std.heap.page_allocator.free(plenty_of_memory); var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory); - var a = fixed_buffer_allocator.threadSafeAllocator(); + const a = fixed_buffer_allocator.threadSafeAllocator(); var queue = Queue(i32).init(); var context = Context{ diff --git a/lib/std/atomic/stack.zig b/lib/std/atomic/stack.zig index 1f19869fd610162d10dc683935e3f2bd68efc939..0fc622cf63efac1fb16239b1964d6d900af78c02 100644 --- a/lib/std/atomic/stack.zig +++ b/lib/std/atomic/stack.zig @@ -85,11 +85,11 @@ const puts_per_thread = 500; const put_thread_count = 3; test "std.atomic.stack" { - var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); + const plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); defer std.heap.page_allocator.free(plenty_of_memory); var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory); - var a = fixed_buffer_allocator.threadSafeAllocator(); + const a = fixed_buffer_allocator.threadSafeAllocator(); var stack = Stack(i32).init(); var context = Context{ diff --git a/lib/std/base64.zig b/lib/std/base64.zig index 8d0effd05b10536e2bb7f1a1fc624237db16b1dc..ce84e640d1e21a3b9aea048385d81a03ed3b850b 100644 --- a/lib/std/base64.zig +++ b/lib/std/base64.zig @@ -239,7 +239,7 @@ pub const Base64Decoder = struct { if ((bits & invalid_char_tst) != 0) return error.InvalidCharacter; std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .little); } - var remaining = source[fast_src_idx..]; + const remaining = source[fast_src_idx..]; for (remaining, fast_src_idx..) |c, src_idx| { const d = decoder.char_to_index[c]; if (d == invalid_char) { @@ -259,7 +259,7 @@ pub const Base64Decoder = struct { return error.InvalidPadding; } if (leftover_idx == null) return; - var leftover = source[leftover_idx.?..]; + const leftover = source[leftover_idx.?..]; if (decoder.pad_char) |pad_char| { const padding_len = acc_len / 2; var padding_chars: usize = 0; @@ -338,7 +338,7 @@ pub const Base64DecoderWithIgnore = struct { if (decoder.pad_char != null and padding_len != 0) return error.InvalidPadding; return dest_idx; } - var leftover = source[leftover_idx.?..]; + const leftover = source[leftover_idx.?..]; if (decoder.pad_char) |pad_char| { var padding_chars: usize = 0; for (leftover) |c| { @@ -483,7 +483,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ // Base64Decoder { var buffer: [0x100]u8 = undefined; - var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)]; + const decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)]; try codecs.Decoder.decode(decoded, expected_encoded); try testing.expectEqualSlices(u8, expected_decoded, decoded); } @@ -492,8 +492,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ { const decoder_ignore_nothing = codecs.decoderWithIgnore(""); var buffer: [0x100]u8 = undefined; - var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)]; - var written = try decoder_ignore_nothing.decode(decoded, expected_encoded); + const decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)]; + const written = try decoder_ignore_nothing.decode(decoded, expected_encoded); try testing.expect(written <= decoded.len); try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); } @@ -502,8 +502,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void { const decoder_ignore_space = codecs.decoderWithIgnore(" "); var buffer: [0x100]u8 = undefined; - var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)]; - var written = try decoder_ignore_space.decode(decoded, encoded); + const decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)]; + const written = try decoder_ignore_space.decode(decoded, encoded); try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); } @@ -511,7 +511,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void const decoder_ignore_space = codecs.decoderWithIgnore(" "); var buffer: [0x100]u8 = undefined; if (codecs.Decoder.calcSizeForSlice(encoded)) |decoded_size| { - var decoded = buffer[0..decoded_size]; + const decoded = buffer[0..decoded_size]; if (codecs.Decoder.decode(decoded, encoded)) |_| { return error.ExpectedError; } else |err| if (err != expected_err) return err; @@ -525,7 +525,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void { const decoder_ignore_space = codecs.decoderWithIgnore(" "); var buffer: [0x100]u8 = undefined; - var decoded = buffer[0 .. (try codecs.Decoder.calcSizeForSlice(encoded)) - 1]; + const decoded = buffer[0 .. (try codecs.Decoder.calcSizeForSlice(encoded)) - 1]; if (decoder_ignore_space.decode(decoded, encoded)) |_| { return error.ExpectedError; } else |err| if (err != error.NoSpaceLeft) return err; @@ -534,7 +534,7 @@ fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void { fn testFourBytesDestNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void { const decoder_ignore_space = codecs.decoderWithIgnore(" "); var buffer: [0x100]u8 = undefined; - var decoded = buffer[0..4]; + const decoded = buffer[0..4]; if (decoder_ignore_space.decode(decoded, encoded)) |_| { return error.ExpectedError; } else |err| if (err != error.NoSpaceLeft) return err; diff --git a/lib/std/buf_map.zig b/lib/std/buf_map.zig index f20a581972dc36e031adeb5607214d99f6efd3a2..4de5e01e0fedc8e96ce0033544f2ab4803e0551b 100644 --- a/lib/std/buf_map.zig +++ b/lib/std/buf_map.zig @@ -15,8 +15,7 @@ pub const BufMap = struct { /// That allocator will be used for both backing allocations /// and string deduplication. pub fn init(allocator: Allocator) BufMap { - var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) }; - return self; + return .{ .hash_map = BufMapHashMap.init(allocator) }; } /// Free the backing storage of the map, as well as all diff --git a/lib/std/buf_set.zig b/lib/std/buf_set.zig index 90ee86e12d58a1811ffdf0deca81e4736d619d9c..46c10f82f856db8578db5479c40ea1e8fadfe27b 100644 --- a/lib/std/buf_set.zig +++ b/lib/std/buf_set.zig @@ -17,8 +17,7 @@ pub const BufSet = struct { /// be used internally for both backing allocations and /// string duplication. pub fn init(a: Allocator) BufSet { - var self = BufSet{ .hash_map = BufSetHashMap.init(a) }; - return self; + return .{ .hash_map = BufSetHashMap.init(a) }; } /// Free a BufSet along with all stored keys. @@ -76,8 +75,8 @@ pub const BufSet = struct { self: *const BufSet, new_allocator: Allocator, ) Allocator.Error!BufSet { - var cloned_hashmap = try self.hash_map.cloneWithAllocator(new_allocator); - var cloned = BufSet{ .hash_map = cloned_hashmap }; + const cloned_hashmap = try self.hash_map.cloneWithAllocator(new_allocator); + const cloned = BufSet{ .hash_map = cloned_hashmap }; var it = cloned.hash_map.keyIterator(); while (it.next()) |key_ptr| { key_ptr.* = try cloned.copy(key_ptr.*); @@ -134,7 +133,7 @@ test "BufSet clone" { } test "BufSet.clone with arena" { - var allocator = std.testing.allocator; + const allocator = std.testing.allocator; var arena = std.heap.ArenaAllocator.init(allocator); defer arena.deinit(); diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 4042bc274304b19a3db353782cda99f8635d947f..19c704c9a56c11abc4f1c591cc4c587d1d1c1e7a 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -777,9 +777,8 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr } var fmt: [256]u8 = undefined; - var slice = try std.fmt.bufPrint(&fmt, "\r\nerr: {s}\r\n", .{exit_msg}); - - var len = try std.unicode.utf8ToUtf16Le(utf16, slice); + const slice = try std.fmt.bufPrint(&fmt, "\r\nerr: {s}\r\n", .{exit_msg}); + const len = try std.unicode.utf8ToUtf16Le(utf16, slice); utf16[len] = 0; @@ -790,7 +789,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr }; var exit_size: usize = 0; - var exit_data = ExitData.create_exit_data(msg, &exit_size) catch null; + const exit_data = ExitData.create_exit_data(msg, &exit_size) catch null; if (exit_data) |data| { if (uefi.system_table.std_err) |out| { diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index b3edbcd76ac17936ad17a1af403d2d8cb2292825..1d793028602faf06c8c9bb4b2a6b9749287926ae 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -847,7 +847,7 @@ pub const ChildProcess = struct { } windowsCreateProcessPathExt(self.allocator, &dir_buf, &app_buf, PATHEXT, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| { - var original_err = switch (no_path_err) { + const original_err = switch (no_path_err) { error.FileNotFound, error.InvalidExe, error.AccessDenied => |e| e, error.UnrecoverableInvalidExe => return error.InvalidExe, else => |e| return e, diff --git a/lib/std/coff.zig b/lib/std/coff.zig index b2bf09ef2a65e0f45179c1dd75fabcd35d43810e..e9214cbd79d59e48fc4dc9830179cf841cd393a8 100644 --- a/lib/std/coff.zig +++ b/lib/std/coff.zig @@ -1075,7 +1075,7 @@ pub const Coff = struct { var stream = std.io.fixedBufferStream(data); const reader = stream.reader(); try stream.seekTo(pe_pointer_offset); - var coff_header_offset = try reader.readInt(u32, .little); + const coff_header_offset = try reader.readInt(u32, .little); try stream.seekTo(coff_header_offset); var buf: [4]u8 = undefined; try reader.readNoEof(&buf); diff --git a/lib/std/compress/deflate/bits_utils.zig b/lib/std/compress/deflate/bits_utils.zig index 4b440dc44e567b48d04a8581eec5d2232bf964ee..97a557d0da42ecb94205d492b868b150764f4a05 100644 --- a/lib/std/compress/deflate/bits_utils.zig +++ b/lib/std/compress/deflate/bits_utils.zig @@ -15,7 +15,7 @@ test "bitReverse" { out: u16, }; - var reverse_bits_tests = [_]ReverseBitsTest{ + const reverse_bits_tests = [_]ReverseBitsTest{ .{ .in = 1, .bit_count = 1, .out = 1 }, .{ .in = 1, .bit_count = 2, .out = 2 }, .{ .in = 1, .bit_count = 3, .out = 4 }, @@ -27,7 +27,7 @@ test "bitReverse" { }; for (reverse_bits_tests) |h| { - var v = bitReverse(u16, h.in, h.bit_count); + const v = bitReverse(u16, h.in, h.bit_count); try std.testing.expectEqual(h.out, v); } } diff --git a/lib/std/compress/deflate/compressor.zig b/lib/std/compress/deflate/compressor.zig index 72de63f162db0e5f7365f7839d4fbec585c202fe..e41b0976364417740f0564113c0930f6924b7fc2 100644 --- a/lib/std/compress/deflate/compressor.zig +++ b/lib/std/compress/deflate/compressor.zig @@ -156,8 +156,8 @@ fn levels(compression: Compression) CompressionLevel { // up to length 'max'. Both slices must be at least 'max' // bytes in size. fn matchLen(a: []u8, b: []u8, max: u32) u32 { - var bounded_a = a[0..max]; - var bounded_b = b[0..max]; + const bounded_a = a[0..max]; + const bounded_b = b[0..max]; for (bounded_a, 0..) |av, i| { if (bounded_b[i] != av) { return @as(u32, @intCast(i)); @@ -191,7 +191,7 @@ fn bulkHash4(b: []u8, dst: []u32) u32 { @as(u32, b[0]) << 24; dst[0] = (hb *% hash_mul) >> (32 - hash_bits); - var end = b.len - min_match_length + 1; + const end = b.len - min_match_length + 1; var i: u32 = 1; while (i < end) : (i += 1) { hb = (hb << 8) | @as(u32, b[i + 3]); @@ -305,7 +305,7 @@ pub fn Compressor(comptime WriterType: anytype) type { } self.hash_offset += window_size; if (self.hash_offset > max_hash_offset) { - var delta = self.hash_offset - 1; + const delta = self.hash_offset - 1; self.hash_offset -= delta; self.chain_head -|= delta; @@ -369,31 +369,31 @@ pub fn Compressor(comptime WriterType: anytype) type { } // Add all to window. @memcpy(self.window[0..b.len], b); - var n = b.len; + const n = b.len; // Calculate 256 hashes at the time (more L1 cache hits) - var loops = (n + 256 - min_match_length) / 256; + const loops = (n + 256 - min_match_length) / 256; var j: usize = 0; while (j < loops) : (j += 1) { - var index = j * 256; + const index = j * 256; var end = index + 256 + min_match_length - 1; if (end > n) { end = n; } - var to_check = self.window[index..end]; - var dst_size = to_check.len - min_match_length + 1; + const to_check = self.window[index..end]; + const dst_size = to_check.len - min_match_length + 1; if (dst_size <= 0) { continue; } - var dst = self.hash_match[0..dst_size]; + const dst = self.hash_match[0..dst_size]; _ = self.bulk_hasher(to_check, dst); var new_h: u32 = 0; for (dst, 0..) |val, i| { - var di = i + index; + const di = i + index; new_h = val; - var hh = &self.hash_head[new_h & hash_mask]; + const hh = &self.hash_head[new_h & hash_mask]; // Get previous value with the same hash. // Our chain should point to the previous value. self.hash_prev[di & window_mask] = hh.*; @@ -447,13 +447,13 @@ pub fn Compressor(comptime WriterType: anytype) type { } var w_end = win[pos + length]; - var w_pos = win[pos..]; - var min_index = pos -| window_size; + const w_pos = win[pos..]; + const min_index = pos -| window_size; var i = prev_head; while (tries > 0) : (tries -= 1) { if (w_end == win[i + length]) { - var n = matchLen(win[i..], w_pos, min_match_look); + const n = matchLen(win[i..], w_pos, min_match_look); if (n > length and (n > min_match_length or pos - i <= 4096)) { length = n; @@ -565,7 +565,7 @@ pub fn Compressor(comptime WriterType: anytype) type { while (true) { assert(self.index <= self.window_end); - var lookahead = self.window_end -| self.index; + const lookahead = self.window_end -| self.index; if (lookahead < min_match_length + max_match_length) { if (!self.sync) { break; @@ -590,16 +590,16 @@ pub fn Compressor(comptime WriterType: anytype) type { if (self.index < self.max_insert_index) { // Update the hash self.hash = hash4(self.window[self.index .. self.index + min_match_length]); - var hh = &self.hash_head[self.hash & hash_mask]; + const hh = &self.hash_head[self.hash & hash_mask]; self.chain_head = @as(u32, @intCast(hh.*)); self.hash_prev[self.index & window_mask] = @as(u32, @intCast(self.chain_head)); hh.* = @as(u32, @intCast(self.index + self.hash_offset)); } - var prev_length = self.length; - var prev_offset = self.offset; + const prev_length = self.length; + const prev_offset = self.offset; self.length = min_match_length - 1; self.offset = 0; - var min_index = self.index -| window_size; + const min_index = self.index -| window_size; if (self.hash_offset <= self.chain_head and self.chain_head - self.hash_offset >= min_index and @@ -610,7 +610,7 @@ pub fn Compressor(comptime WriterType: anytype) type { prev_length < self.compression_level.lazy)) { { - var fmatch = self.findMatch( + const fmatch = self.findMatch( self.index, self.chain_head -| self.hash_offset, min_match_length - 1, @@ -658,7 +658,7 @@ pub fn Compressor(comptime WriterType: anytype) type { self.hash = hash4(self.window[index .. index + min_match_length]); // Get previous value with the same hash. // Our chain should point to the previous value. - var hh = &self.hash_head[self.hash & hash_mask]; + const hh = &self.hash_head[self.hash & hash_mask]; self.hash_prev[index & window_mask] = hh.*; // Set the head of the hash chain to us. hh.* = @as(u32, @intCast(index + self.hash_offset)); @@ -740,7 +740,7 @@ pub fn Compressor(comptime WriterType: anytype) type { // compressed form of data to its underlying writer. while (buf.len > 0) { try self.step(); - var filled = self.fill(buf); + const filled = self.fill(buf); buf = buf[filled..]; } @@ -1097,12 +1097,12 @@ test "bulkHash4" { while (j < out.len) : (j += 1) { var y = out[0..j]; - var dst = try testing.allocator.alloc(u32, y.len - min_match_length + 1); + const dst = try testing.allocator.alloc(u32, y.len - min_match_length + 1); defer testing.allocator.free(dst); _ = bulkHash4(y, dst); for (dst, 0..) |got, i| { - var want = hash4(y[i..]); + const want = hash4(y[i..]); try testing.expectEqual(want, got); } } diff --git a/lib/std/compress/deflate/compressor_test.zig b/lib/std/compress/deflate/compressor_test.zig index 140284ea5e4fee0f727aa98ce04308b04342d4dc..1f765e3fdc66f7d6fe3f0be7a215cdc55b604aa5 100644 --- a/lib/std/compress/deflate/compressor_test.zig +++ b/lib/std/compress/deflate/compressor_test.zig @@ -27,7 +27,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { var whole_buf = std.ArrayList(u8).init(testing.allocator); defer whole_buf.deinit(); - var multi_writer = io.multiWriter(.{ + const multi_writer = io.multiWriter(.{ divided_buf.writer(), whole_buf.writer(), }).writer(); @@ -48,7 +48,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { defer decomp.deinit(); // Write first half of the input and flush() - var half: usize = (input.len + 1) / 2; + const half: usize = (input.len + 1) / 2; var half_len: usize = half - 0; { _ = try comp.writer().writeAll(input[0..half]); @@ -57,10 +57,10 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { try comp.flush(); // Read back - var decompressed = try testing.allocator.alloc(u8, half_len); + const decompressed = try testing.allocator.alloc(u8, half_len); defer testing.allocator.free(decompressed); - var read = try decomp.reader().readAll(decompressed); // read at least half + const read = try decomp.reader().readAll(decompressed); // read at least half try testing.expectEqual(half_len, read); try testing.expectEqualSlices(u8, input[0..half], decompressed); } @@ -74,7 +74,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { try comp.close(); // Read back - var decompressed = try testing.allocator.alloc(u8, half_len); + const decompressed = try testing.allocator.alloc(u8, half_len); defer testing.allocator.free(decompressed); var read = try decomp.reader().readAll(decompressed); @@ -94,11 +94,11 @@ fn testSync(level: deflate.Compression, input: []const u8) !void { try comp.close(); // stream should work for ordinary reader too (reading whole_buf in one go) - var whole_buf_reader = io.fixedBufferStream(whole_buf.items).reader(); + const whole_buf_reader = io.fixedBufferStream(whole_buf.items).reader(); var decomp = try decompressor(testing.allocator, whole_buf_reader, null); defer decomp.deinit(); - var decompressed = try testing.allocator.alloc(u8, input.len); + const decompressed = try testing.allocator.alloc(u8, input.len); defer testing.allocator.free(decompressed); _ = try decomp.reader().readAll(decompressed); @@ -125,10 +125,10 @@ fn testToFromWithLevelAndLimit(level: deflate.Compression, input: []const u8, li var decomp = try decompressor(testing.allocator, fib.reader(), null); defer decomp.deinit(); - var decompressed = try testing.allocator.alloc(u8, input.len); + const decompressed = try testing.allocator.alloc(u8, input.len); defer testing.allocator.free(decompressed); - var read: usize = try decomp.reader().readAll(decompressed); + const read: usize = try decomp.reader().readAll(decompressed); try testing.expectEqual(input.len, read); try testing.expectEqualSlices(u8, input, decompressed); @@ -153,7 +153,7 @@ fn testToFromWithLimit(input: []const u8, limit: [11]u32) !void { } test "deflate/inflate" { - var limits = [_]u32{0} ** 11; + const limits = [_]u32{0} ** 11; var test0 = [_]u8{}; var test1 = [_]u8{0x11}; @@ -313,7 +313,7 @@ test "decompressor dictionary" { try comp.writer().writeAll(text); try comp.close(); - var decompressed = try testing.allocator.alloc(u8, text.len); + const decompressed = try testing.allocator.alloc(u8, text.len); defer testing.allocator.free(decompressed); var decomp = try decompressor( @@ -432,7 +432,7 @@ test "deflate/inflate string" { }; inline for (deflate_inflate_string_tests) |t| { - var golden = @embedFile("testdata/" ++ t.filename); + const golden = @embedFile("testdata/" ++ t.filename); try testToFromWithLimit(golden, t.limit); } } @@ -466,14 +466,14 @@ test "inflate reset" { var decomp = try decompressor(testing.allocator, fib.reader(), null); defer decomp.deinit(); - var decompressed_0: []u8 = try decomp.reader() + const decompressed_0: []u8 = try decomp.reader() .readAllAlloc(testing.allocator, math.maxInt(usize)); defer testing.allocator.free(decompressed_0); fib = io.fixedBufferStream(compressed_strings[1].items); try decomp.reset(fib.reader(), null); - var decompressed_1: []u8 = try decomp.reader() + const decompressed_1: []u8 = try decomp.reader() .readAllAlloc(testing.allocator, math.maxInt(usize)); defer testing.allocator.free(decompressed_1); @@ -513,14 +513,14 @@ test "inflate reset dictionary" { var decomp = try decompressor(testing.allocator, fib.reader(), dict); defer decomp.deinit(); - var decompressed_0: []u8 = try decomp.reader() + const decompressed_0: []u8 = try decomp.reader() .readAllAlloc(testing.allocator, math.maxInt(usize)); defer testing.allocator.free(decompressed_0); fib = io.fixedBufferStream(compressed_strings[1].items); try decomp.reset(fib.reader(), dict); - var decompressed_1: []u8 = try decomp.reader() + const decompressed_1: []u8 = try decomp.reader() .readAllAlloc(testing.allocator, math.maxInt(usize)); defer testing.allocator.free(decompressed_1); diff --git a/lib/std/compress/deflate/decompressor.zig b/lib/std/compress/deflate/decompressor.zig index 4e7f46db422cd95c95f5df9a0a7951229d70f001..8e86bc09f3cab6e3a375cf76317796f70eada8c4 100644 --- a/lib/std/compress/deflate/decompressor.zig +++ b/lib/std/compress/deflate/decompressor.zig @@ -136,11 +136,11 @@ const HuffmanDecoder = struct { self.min = min; if (max > huffman_chunk_bits) { - var num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits)); + const num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits)); self.link_mask = @as(u32, @intCast(num_links - 1)); // create link tables - var link = next_code[huffman_chunk_bits + 1] >> 1; + const link = next_code[huffman_chunk_bits + 1] >> 1; self.links = try self.allocator.alloc([]u16, huffman_num_chunks - link); self.sub_chunks = ArrayList(u32).init(self.allocator); self.initialized = true; @@ -148,7 +148,7 @@ const HuffmanDecoder = struct { while (j < huffman_num_chunks) : (j += 1) { var reverse = @as(u32, @intCast(bu.bitReverse(u16, @as(u16, @intCast(j)), 16))); reverse >>= @as(u32, @intCast(16 - huffman_chunk_bits)); - var off = j - @as(u32, @intCast(link)); + const off = j - @as(u32, @intCast(link)); if (sanity) { // check we are not overwriting an existing chunk assert(self.chunks[reverse] == 0); @@ -168,9 +168,9 @@ const HuffmanDecoder = struct { if (n == 0) { continue; } - var ncode = next_code[n]; + const ncode = next_code[n]; next_code[n] += 1; - var chunk = @as(u16, @intCast((li << huffman_value_shift) | n)); + const chunk = @as(u16, @intCast((li << huffman_value_shift) | n)); var reverse = @as(u16, @intCast(bu.bitReverse(u16, @as(u16, @intCast(ncode)), 16))); reverse >>= @as(u4, @intCast(16 - n)); if (n <= huffman_chunk_bits) { @@ -187,14 +187,14 @@ const HuffmanDecoder = struct { self.chunks[off] = chunk; } } else { - var j = reverse & (huffman_num_chunks - 1); + const j = reverse & (huffman_num_chunks - 1); if (sanity) { // Expect an indirect chunk assert(self.chunks[j] & huffman_count_mask == huffman_chunk_bits + 1); // Longer codes should have been // associated with a link table above. } - var value = self.chunks[j] >> huffman_value_shift; + const value = self.chunks[j] >> huffman_value_shift; var link_tab = self.links[value]; reverse >>= huffman_chunk_bits; var off = reverse; @@ -354,8 +354,8 @@ pub fn Decompressor(comptime ReaderType: type) type { fn init(allocator: Allocator, in_reader: ReaderType, dict: ?[]const u8) !Self { fixed_huffman_decoder = try fixedHuffmanDecoderInit(allocator); - var bits = try allocator.create([max_num_lit + max_num_dist]u32); - var codebits = try allocator.create([num_codes]u32); + const bits = try allocator.create([max_num_lit + max_num_dist]u32); + const codebits = try allocator.create([num_codes]u32); var dd = ddec.DictDecoder{}; try dd.init(allocator, max_match_offset, dict); @@ -416,7 +416,7 @@ pub fn Decompressor(comptime ReaderType: type) type { } self.final = self.b & 1 == 1; self.b >>= 1; - var typ = self.b & 3; + const typ = self.b & 3; self.b >>= 2; self.nb -= 1 + 2; switch (typ) { @@ -494,21 +494,21 @@ pub fn Decompressor(comptime ReaderType: type) type { while (self.nb < 5 + 5 + 4) { try self.moreBits(); } - var nlit = @as(u32, @intCast(self.b & 0x1F)) + 257; + const nlit = @as(u32, @intCast(self.b & 0x1F)) + 257; if (nlit > max_num_lit) { corrupt_input_error_offset = self.roffset; self.err = InflateError.CorruptInput; return InflateError.CorruptInput; } self.b >>= 5; - var ndist = @as(u32, @intCast(self.b & 0x1F)) + 1; + const ndist = @as(u32, @intCast(self.b & 0x1F)) + 1; if (ndist > max_num_dist) { corrupt_input_error_offset = self.roffset; self.err = InflateError.CorruptInput; return InflateError.CorruptInput; } self.b >>= 5; - var nclen = @as(u32, @intCast(self.b & 0xF)) + 4; + const nclen = @as(u32, @intCast(self.b & 0xF)) + 4; // num_codes is 19, so nclen is always valid. self.b >>= 4; self.nb -= 5 + 5 + 4; @@ -536,9 +536,9 @@ pub fn Decompressor(comptime ReaderType: type) type { // HLIT + 257 code lengths, HDIST + 1 code lengths, // using the code length Huffman code. i = 0; - var n = nlit + ndist; + const n = nlit + ndist; while (i < n) { - var x = try self.huffSym(&self.hd1); + const x = try self.huffSym(&self.hd1); if (x < 16) { // Actual length. self.bits[i] = x; @@ -618,7 +618,7 @@ pub fn Decompressor(comptime ReaderType: type) type { switch (self.step_state) { .init => { // Read literal and/or (length, distance) according to RFC section 3.2.3. - var v = try self.huffSym(self.hl.?); + const v = try self.huffSym(self.hl.?); var n: u32 = 0; // number of bits extra var length: u32 = 0; switch (v) { @@ -699,7 +699,7 @@ pub fn Decompressor(comptime ReaderType: type) type { switch (dist) { 0...3 => dist += 1, 4...max_num_dist - 1 => { // 4...29 - var nb = @as(u32, @intCast(dist - 2)) >> 1; + const nb = @as(u32, @intCast(dist - 2)) >> 1; // have 1 bit in bottom of dist, need nb more. var extra = (dist & 1) << @as(u5, @intCast(nb)); while (self.nb < nb) { @@ -757,14 +757,14 @@ pub fn Decompressor(comptime ReaderType: type) type { self.b = 0; // Length then ones-complement of length. - var nr: u32 = 4; + const nr: u32 = 4; self.inner_reader.readNoEof(self.buf[0..nr]) catch { self.err = InflateError.UnexpectedEndOfStream; return InflateError.UnexpectedEndOfStream; }; self.roffset += @as(u64, @intCast(nr)); - var n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8; - var nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8; + const n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8; + const nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8; if (@as(u16, @intCast(nn)) != @as(u16, @truncate(~n))) { corrupt_input_error_offset = self.roffset; self.err = InflateError.CorruptInput; @@ -789,7 +789,7 @@ pub fn Decompressor(comptime ReaderType: type) type { buf = buf[0..self.copy_len]; } - var cnt = try self.inner_reader.read(buf); + const cnt = try self.inner_reader.read(buf); if (cnt < buf.len) { self.err = InflateError.UnexpectedEndOfStream; } @@ -819,7 +819,7 @@ pub fn Decompressor(comptime ReaderType: type) type { } fn moreBits(self: *Self) InflateError!void { - var c = self.inner_reader.readByte() catch |e| { + const c = self.inner_reader.readByte() catch |e| { if (e == error.EndOfStream) { return InflateError.UnexpectedEndOfStream; } @@ -845,7 +845,7 @@ pub fn Decompressor(comptime ReaderType: type) type { var b = self.b; while (true) { while (nb < n) { - var c = self.inner_reader.readByte() catch |e| { + const c = self.inner_reader.readByte() catch |e| { self.b = b; self.nb = nb; if (e == error.EndOfStream) { @@ -1053,7 +1053,7 @@ test "inflate A Tale of Two Cities (1859) intro" { defer decomp.deinit(); var got: [700]u8 = undefined; - var got_len = try decomp.reader().read(&got); + const got_len = try decomp.reader().read(&got); try testing.expectEqual(@as(usize, 616), got_len); try testing.expectEqualSlices(u8, expected, got[0..expected.len]); } @@ -1117,6 +1117,6 @@ fn decompress(input: []const u8) !void { const reader = fib.reader(); var decomp = try decompressor(allocator, reader, null); defer decomp.deinit(); - var output = try decomp.reader().readAllAlloc(allocator, math.maxInt(usize)); + const output = try decomp.reader().readAllAlloc(allocator, math.maxInt(usize)); defer std.testing.allocator.free(output); } diff --git a/lib/std/compress/deflate/deflate_fast.zig b/lib/std/compress/deflate/deflate_fast.zig index a11548fa1fa10675f6fd28e40d754fbb656c3c21..3a2668762ecc3196da45579024758b2a15f557ae 100644 --- a/lib/std/compress/deflate/deflate_fast.zig +++ b/lib/std/compress/deflate/deflate_fast.zig @@ -30,7 +30,7 @@ const table_size = 1 << table_bits; // Size of the table. const buffer_reset = math.maxInt(i32) - max_store_block_size * 2; fn load32(b: []u8, i: i32) u32 { - var s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4]; + const s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4]; return @as(u32, @intCast(s[0])) | @as(u32, @intCast(s[1])) << 8 | @as(u32, @intCast(s[2])) << 16 | @@ -38,7 +38,7 @@ fn load32(b: []u8, i: i32) u32 { } fn load64(b: []u8, i: i32) u64 { - var s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))]; + const s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))]; return @as(u64, @intCast(s[0])) | @as(u64, @intCast(s[1])) << 8 | @as(u64, @intCast(s[2])) << 16 | @@ -117,7 +117,7 @@ pub const DeflateFast = struct { // s_limit is when to stop looking for offset/length copies. The input_margin // lets us use a fast path for emitLiteral in the main loop, while we are // looking for copies. - var s_limit = @as(i32, @intCast(src.len - input_margin)); + const s_limit = @as(i32, @intCast(src.len - input_margin)); // next_emit is where in src the next emitLiteral should start from. var next_emit: i32 = 0; @@ -147,18 +147,18 @@ pub const DeflateFast = struct { var candidate: TableEntry = undefined; while (true) { s = next_s; - var bytes_between_hash_lookups = skip >> 5; + const bytes_between_hash_lookups = skip >> 5; next_s = s + bytes_between_hash_lookups; skip += bytes_between_hash_lookups; if (next_s > s_limit) { break :outer; } candidate = self.table[next_hash & table_mask]; - var now = load32(src, next_s); + const now = load32(src, next_s); self.table[next_hash & table_mask] = .{ .offset = s + self.cur, .val = cv }; next_hash = hash(now); - var offset = s - (candidate.offset - self.cur); + const offset = s - (candidate.offset - self.cur); if (offset > max_match_offset or cv != candidate.val) { // Out of range or not matched. cv = now; @@ -187,8 +187,8 @@ pub const DeflateFast = struct { // Extend the 4-byte match as long as possible. // s += 4; - var t = candidate.offset - self.cur + 4; - var l = self.matchLen(s, t, src); + const t = candidate.offset - self.cur + 4; + const l = self.matchLen(s, t, src); // matchToken is flate's equivalent of Snappy's emitCopy. (length,offset) dst[tokens_count.*] = token.matchToken( @@ -209,20 +209,20 @@ pub const DeflateFast = struct { // are faster as one load64 call (with some shifts) instead of // three load32 calls. var x = load64(src, s - 1); - var prev_hash = hash(@as(u32, @truncate(x))); + const prev_hash = hash(@as(u32, @truncate(x))); self.table[prev_hash & table_mask] = TableEntry{ .offset = self.cur + s - 1, .val = @as(u32, @truncate(x)), }; x >>= 8; - var curr_hash = hash(@as(u32, @truncate(x))); + const curr_hash = hash(@as(u32, @truncate(x))); candidate = self.table[curr_hash & table_mask]; self.table[curr_hash & table_mask] = TableEntry{ .offset = self.cur + s, .val = @as(u32, @truncate(x)), }; - var offset = s - (candidate.offset - self.cur); + const offset = s - (candidate.offset - self.cur); if (offset > max_match_offset or @as(u32, @truncate(x)) != candidate.val) { cv = @as(u32, @truncate(x >> 8)); next_hash = hash(cv); @@ -261,7 +261,7 @@ pub const DeflateFast = struct { // If we are inside the current block if (t >= 0) { var b = src[@as(usize, @intCast(t))..]; - var a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))]; + const a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))]; b = b[0..a.len]; // Extend the match to be as long as possible. for (a, 0..) |_, i| { @@ -273,7 +273,7 @@ pub const DeflateFast = struct { } // We found a match in the previous block. - var tp = @as(i32, @intCast(self.prev_len)) + t; + const tp = @as(i32, @intCast(self.prev_len)) + t; if (tp < 0) { return 0; } @@ -293,7 +293,7 @@ pub const DeflateFast = struct { // If we reached our limit, we matched everything we are // allowed to in the previous block and we return. - var n = @as(i32, @intCast(b.len)); + const n = @as(i32, @intCast(b.len)); if (@as(u32, @intCast(s + n)) == s1) { return n; } @@ -366,7 +366,7 @@ test "best speed match 1/3" { .cur = 0, }; var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 }; - var got: i32 = e.matchLen(3, -3, ¤t); + const got: i32 = e.matchLen(3, -3, ¤t); try expectEqual(@as(i32, 6), got); } { @@ -379,7 +379,7 @@ test "best speed match 1/3" { .cur = 0, }; var current = [_]u8{ 2, 4, 5, 0, 1, 2, 3, 4, 5 }; - var got: i32 = e.matchLen(3, -3, ¤t); + const got: i32 = e.matchLen(3, -3, ¤t); try expectEqual(@as(i32, 3), got); } { @@ -392,7 +392,7 @@ test "best speed match 1/3" { .cur = 0, }; var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 }; - var got: i32 = e.matchLen(3, -3, ¤t); + const got: i32 = e.matchLen(3, -3, ¤t); try expectEqual(@as(i32, 2), got); } { @@ -405,7 +405,7 @@ test "best speed match 1/3" { .cur = 0, }; var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; - var got: i32 = e.matchLen(0, -1, ¤t); + const got: i32 = e.matchLen(0, -1, ¤t); try expectEqual(@as(i32, 4), got); } { @@ -418,7 +418,7 @@ test "best speed match 1/3" { .cur = 0, }; var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; - var got: i32 = e.matchLen(4, -7, ¤t); + const got: i32 = e.matchLen(4, -7, ¤t); try expectEqual(@as(i32, 5), got); } { @@ -431,7 +431,7 @@ test "best speed match 1/3" { .cur = 0, }; var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; - var got: i32 = e.matchLen(0, -1, ¤t); + const got: i32 = e.matchLen(0, -1, ¤t); try expectEqual(@as(i32, 0), got); } { @@ -444,7 +444,7 @@ test "best speed match 1/3" { .cur = 0, }; var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 }; - var got: i32 = e.matchLen(1, 0, ¤t); + const got: i32 = e.matchLen(1, 0, ¤t); try expectEqual(@as(i32, 0), got); } } @@ -462,7 +462,7 @@ test "best speed match 2/3" { .cur = 0, }; var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 }; - var got: i32 = e.matchLen(1, -5, ¤t); + const got: i32 = e.matchLen(1, -5, ¤t); try expectEqual(@as(i32, 0), got); } { @@ -475,7 +475,7 @@ test "best speed match 2/3" { .cur = 0, }; var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 }; - var got: i32 = e.matchLen(1, -1, ¤t); + const got: i32 = e.matchLen(1, -1, ¤t); try expectEqual(@as(i32, 0), got); } { @@ -488,7 +488,7 @@ test "best speed match 2/3" { .cur = 0, }; var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 }; - var got: i32 = e.matchLen(1, 0, ¤t); + const got: i32 = e.matchLen(1, 0, ¤t); try expectEqual(@as(i32, 3), got); } { @@ -501,7 +501,7 @@ test "best speed match 2/3" { .cur = 0, }; var current = [_]u8{ 3, 4, 5 }; - var got: i32 = e.matchLen(0, -3, ¤t); + const got: i32 = e.matchLen(0, -3, ¤t); try expectEqual(@as(i32, 3), got); } } @@ -564,11 +564,11 @@ test "best speed match 2/2" { }; for (cases) |c| { - var previous = try testing.allocator.alloc(u8, c.previous); + const previous = try testing.allocator.alloc(u8, c.previous); defer testing.allocator.free(previous); @memset(previous, 0); - var current = try testing.allocator.alloc(u8, c.current); + const current = try testing.allocator.alloc(u8, c.current); defer testing.allocator.free(current); @memset(current, 0); @@ -579,7 +579,7 @@ test "best speed match 2/2" { .allocator = undefined, .cur = 0, }; - var got: i32 = e.matchLen(c.s, c.t, current); + const got: i32 = e.matchLen(c.s, c.t, current); try expectEqual(@as(i32, c.expected), got); } } @@ -609,10 +609,10 @@ test "best speed shift offsets" { // Second part should pick up matches from the first block. tokens_count = 0; enc.encode(&tokens, &tokens_count, &test_data); - var want_first_tokens = tokens_count; + const want_first_tokens = tokens_count; tokens_count = 0; enc.encode(&tokens, &tokens_count, &test_data); - var want_second_tokens = tokens_count; + const want_second_tokens = tokens_count; try expect(want_first_tokens > want_second_tokens); @@ -657,7 +657,7 @@ test "best speed reset" { const ArrayList = std.ArrayList; const input_size = 65536; - var input = try testing.allocator.alloc(u8, input_size); + const input = try testing.allocator.alloc(u8, input_size); defer testing.allocator.free(input); var i: usize = 0; @@ -699,7 +699,7 @@ test "best speed reset" { // Reset until we are right before the wraparound. // Each reset adds max_match_offset to the offset. i = 0; - var limit = (buffer_reset - input.len - o - max_match_offset) / max_match_offset; + const limit = (buffer_reset - input.len - o - max_match_offset) / max_match_offset; while (i < limit) : (i += 1) { // skip ahead to where we are close to wrap around... comp.reset(discard.writer()); diff --git a/lib/std/compress/deflate/deflate_fast_test.zig b/lib/std/compress/deflate/deflate_fast_test.zig index 08f6079aa5f681732267b6b8c8283fb32330f636..ca9a978ad108b7e9553adf707bc75dce3952993a 100644 --- a/lib/std/compress/deflate/deflate_fast_test.zig +++ b/lib/std/compress/deflate/deflate_fast_test.zig @@ -39,18 +39,18 @@ test "best speed" { var tc_15 = [_]u32{ 65536, 129 }; var tc_16 = [_]u32{ 65536, 65536, 256 }; var tc_17 = [_]u32{ 65536, 65536, 65536 }; - var test_cases = [_][]u32{ + const test_cases = [_][]u32{ &tc_01, &tc_02, &tc_03, &tc_04, &tc_05, &tc_06, &tc_07, &tc_08, &tc_09, &tc_10, &tc_11, &tc_12, &tc_13, &tc_14, &tc_15, &tc_16, &tc_17, }; for (test_cases) |tc| { - var firsts = [_]u32{ 1, 65534, 65535, 65536, 65537, 131072 }; + const firsts = [_]u32{ 1, 65534, 65535, 65536, 65537, 131072 }; for (firsts) |first_n| { tc[0] = first_n; - var to_flush = [_]bool{ false, true }; + const to_flush = [_]bool{ false, true }; for (to_flush) |flush| { var compressed = ArrayList(u8).init(testing.allocator); defer compressed.deinit(); @@ -75,14 +75,14 @@ test "best speed" { try comp.close(); - var decompressed = try testing.allocator.alloc(u8, want.items.len); + const decompressed = try testing.allocator.alloc(u8, want.items.len); defer testing.allocator.free(decompressed); var fib = io.fixedBufferStream(compressed.items); var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null); defer decomp.deinit(); - var read = try decomp.reader().readAll(decompressed); + const read = try decomp.reader().readAll(decompressed); _ = decomp.close(); try testing.expectEqual(want.items.len, read); @@ -109,7 +109,7 @@ test "best speed max match offset" { for (extras) |extra| { var offset_adj: i32 = -5; while (offset_adj <= 5) : (offset_adj += 1) { - var offset = deflate_const.max_match_offset + offset_adj; + const offset = deflate_const.max_match_offset + offset_adj; // Make src to be a []u8 of the form // fmt("{s}{s}{s}{s}{s}", .{abc, zeros0, xyzMaybe, abc, zeros1}) @@ -119,7 +119,7 @@ test "best speed max match offset" { // zeros1 is between 0 and 30 zeros. // The difference between the two abc's will be offset, which // is max_match_offset plus or minus a small adjustment. - var src_len: usize = @as(usize, @intCast(offset + @as(i32, abc.len) + @as(i32, @intCast(extra)))); + const src_len: usize = @as(usize, @intCast(offset + @as(i32, abc.len) + @as(i32, @intCast(extra)))); var src = try testing.allocator.alloc(u8, src_len); defer testing.allocator.free(src); @@ -143,13 +143,13 @@ test "best speed max match offset" { try comp.writer().writeAll(src); _ = try comp.close(); - var decompressed = try testing.allocator.alloc(u8, src.len); + const decompressed = try testing.allocator.alloc(u8, src.len); defer testing.allocator.free(decompressed); var fib = io.fixedBufferStream(compressed.items); var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null); defer decomp.deinit(); - var read = try decomp.reader().readAll(decompressed); + const read = try decomp.reader().readAll(decompressed); _ = decomp.close(); try testing.expectEqual(src.len, read); diff --git a/lib/std/compress/deflate/dict_decoder.zig b/lib/std/compress/deflate/dict_decoder.zig index 75fdd359dd9f7ae42a71d99a6ce145095c2d3c4c..72a3f6310b60edc682b3e7ed7700fd3484470c8e 100644 --- a/lib/std/compress/deflate/dict_decoder.zig +++ b/lib/std/compress/deflate/dict_decoder.zig @@ -123,7 +123,7 @@ pub const DictDecoder = struct { // This invariant must be kept: 0 < dist <= histSize() pub fn writeCopy(self: *Self, dist: u32, length: u32) u32 { assert(0 < dist and dist <= self.histSize()); - var dst_base = self.wr_pos; + const dst_base = self.wr_pos; var dst_pos = dst_base; var src_pos: i32 = @as(i32, @intCast(dst_pos)) - @as(i32, @intCast(dist)); var end_pos = dst_pos + length; @@ -175,12 +175,12 @@ pub const DictDecoder = struct { // This invariant must be kept: 0 < dist <= histSize() pub fn tryWriteCopy(self: *Self, dist: u32, length: u32) u32 { var dst_pos = self.wr_pos; - var end_pos = dst_pos + length; + const end_pos = dst_pos + length; if (dst_pos < dist or end_pos > self.hist.len) { return 0; } - var dst_base = dst_pos; - var src_pos = dst_pos - dist; + const dst_base = dst_pos; + const src_pos = dst_pos - dist; // Copy possibly overlapping section before destination position. while (dst_pos < end_pos) { @@ -195,7 +195,7 @@ pub const DictDecoder = struct { // emitted to the user. The data returned by readFlush must be fully consumed // before calling any other DictDecoder methods. pub fn readFlush(self: *Self) []u8 { - var to_read = self.hist[self.rd_pos..self.wr_pos]; + const to_read = self.hist[self.rd_pos..self.wr_pos]; self.rd_pos = self.wr_pos; if (self.wr_pos == self.hist.len) { self.wr_pos = 0; @@ -279,7 +279,7 @@ test "dictionary decoder" { length: u32, // Length of copy or insertion }; - var poem_refs = [_]PoemRefs{ + const poem_refs = [_]PoemRefs{ .{ .dist = 0, .length = 38 }, .{ .dist = 33, .length = 3 }, .{ .dist = 0, .length = 48 }, .{ .dist = 79, .length = 3 }, .{ .dist = 0, .length = 11 }, .{ .dist = 34, .length = 5 }, .{ .dist = 0, .length = 6 }, .{ .dist = 23, .length = 7 }, .{ .dist = 0, .length = 8 }, @@ -368,7 +368,7 @@ test "dictionary decoder" { fn writeString(dst_dd: *DictDecoder, dst: anytype, str: []const u8) !void { var string = str; while (string.len > 0) { - var cnt = DictDecoder.copy(dst_dd.writeSlice(), string); + const cnt = DictDecoder.copy(dst_dd.writeSlice(), string); dst_dd.writeMark(cnt); string = string[cnt..]; if (dst_dd.availWrite() == 0) { diff --git a/lib/std/compress/deflate/huffman_bit_writer.zig b/lib/std/compress/deflate/huffman_bit_writer.zig index 18813b0b284ea4ffab74ada021b98fec5cbc500f..27c8b0a7af5a6cb95650f6268de8a28885480866 100644 --- a/lib/std/compress/deflate/huffman_bit_writer.zig +++ b/lib/std/compress/deflate/huffman_bit_writer.zig @@ -134,7 +134,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { self.bits |= @as(u64, @intCast(b)) << @as(u6, @intCast(self.nbits)); self.nbits += nb; if (self.nbits >= 48) { - var bits = self.bits; + const bits = self.bits; self.bits >>= 48; self.nbits -= 48; var n = self.nbytes; @@ -224,7 +224,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { while (size != bad_code) : (in_index += 1) { // INVARIANT: We have seen "count" copies of size that have not yet // had output generated for them. - var next_size = codegen[in_index]; + const next_size = codegen[in_index]; if (next_size == size) { count += 1; continue; @@ -295,12 +295,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { while (num_codegens > 4 and self.codegen_freq[codegen_order[num_codegens - 1]] == 0) { num_codegens -= 1; } - var header = 3 + 5 + 5 + 4 + (3 * num_codegens) + + const header = 3 + 5 + 5 + 4 + (3 * num_codegens) + self.codegen_encoding.bitLength(self.codegen_freq[0..]) + self.codegen_freq[16] * 2 + self.codegen_freq[17] * 3 + self.codegen_freq[18] * 7; - var size = header + + const size = header + lit_enc.bitLength(self.literal_freq) + off_enc.bitLength(self.offset_freq) + extra_bits; @@ -339,7 +339,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits)); self.nbits += @as(u32, @intCast(c.len)); if (self.nbits >= 48) { - var bits = self.bits; + const bits = self.bits; self.bits >>= 48; self.nbits -= 48; var n = self.nbytes; @@ -386,13 +386,13 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { var i: u32 = 0; while (i < num_codegens) : (i += 1) { - var value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len)); + const value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len)); try self.writeBits(@as(u32, @intCast(value)), 3); } i = 0; while (true) { - var code_word: u32 = @as(u32, @intCast(self.codegen[i])); + const code_word: u32 = @as(u32, @intCast(self.codegen[i])); i += 1; if (code_word == bad_code) { break; @@ -458,14 +458,14 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { return; } - var lit_and_off = self.indexTokens(tokens); - var num_literals = lit_and_off.num_literals; - var num_offsets = lit_and_off.num_offsets; + const lit_and_off = self.indexTokens(tokens); + const num_literals = lit_and_off.num_literals; + const num_offsets = lit_and_off.num_offsets; var extra_bits: u32 = 0; - var ret = storedSizeFits(input); - var stored_size = ret.size; - var storable = ret.storable; + const ret = storedSizeFits(input); + const stored_size = ret.size; + const storable = ret.storable; if (storable) { // We only bother calculating the costs of the extra bits required by @@ -504,12 +504,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { &self.offset_encoding, ); self.codegen_encoding.generate(self.codegen_freq[0..], 7); - var dynamic_size = self.dynamicSize( + const dynamic_size = self.dynamicSize( &self.literal_encoding, &self.offset_encoding, extra_bits, ); - var dyn_size = dynamic_size.size; + const dyn_size = dynamic_size.size; num_codegens = dynamic_size.num_codegens; if (dyn_size < size) { @@ -551,9 +551,9 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { return; } - var total_tokens = self.indexTokens(tokens); - var num_literals = total_tokens.num_literals; - var num_offsets = total_tokens.num_offsets; + const total_tokens = self.indexTokens(tokens); + const num_literals = total_tokens.num_literals; + const num_offsets = total_tokens.num_offsets; // Generate codegen and codegenFrequencies, which indicates how to encode // the literal_encoding and the offset_encoding. @@ -564,15 +564,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { &self.offset_encoding, ); self.codegen_encoding.generate(self.codegen_freq[0..], 7); - var dynamic_size = self.dynamicSize(&self.literal_encoding, &self.offset_encoding, 0); - var size = dynamic_size.size; - var num_codegens = dynamic_size.num_codegens; + const dynamic_size = self.dynamicSize(&self.literal_encoding, &self.offset_encoding, 0); + const size = dynamic_size.size; + const num_codegens = dynamic_size.num_codegens; // Store bytes, if we don't get a reasonable improvement. - var stored_size = storedSizeFits(input); - var ssize = stored_size.size; - var storable = stored_size.storable; + const stored_size = storedSizeFits(input); + const ssize = stored_size.size; + const storable = stored_size.storable; if (storable and ssize < (size + (size >> 4))) { try self.writeStoredHeader(input.?.len, eof); try self.writeBytes(input.?); @@ -611,8 +611,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { self.literal_freq[token.literal(t)] += 1; continue; } - var length = token.length(t); - var offset = token.offset(t); + const length = token.length(t); + const offset = token.offset(t); self.literal_freq[length_codes_start + token.lengthCode(length)] += 1; self.offset_freq[token.offsetCode(offset)] += 1; } @@ -660,21 +660,21 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { continue; } // Write the length - var length = token.length(t); - var length_code = token.lengthCode(length); + const length = token.length(t); + const length_code = token.lengthCode(length); try self.writeCode(le_codes[length_code + length_codes_start]); - var extra_length_bits = @as(u32, @intCast(length_extra_bits[length_code])); + const extra_length_bits = @as(u32, @intCast(length_extra_bits[length_code])); if (extra_length_bits > 0) { - var extra_length = @as(u32, @intCast(length - length_base[length_code])); + const extra_length = @as(u32, @intCast(length - length_base[length_code])); try self.writeBits(extra_length, extra_length_bits); } // Write the offset - var offset = token.offset(t); - var offset_code = token.offsetCode(offset); + const offset = token.offset(t); + const offset_code = token.offsetCode(offset); try self.writeCode(oe_codes[offset_code]); - var extra_offset_bits = @as(u32, @intCast(offset_extra_bits[offset_code])); + const extra_offset_bits = @as(u32, @intCast(offset_extra_bits[offset_code])); if (extra_offset_bits > 0) { - var extra_offset = @as(u32, @intCast(offset - offset_base[offset_code])); + const extra_offset = @as(u32, @intCast(offset - offset_base[offset_code])); try self.writeBits(extra_offset, extra_offset_bits); } } @@ -718,15 +718,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { &self.huff_offset, ); self.codegen_encoding.generate(self.codegen_freq[0..], 7); - var dynamic_size = self.dynamicSize(&self.literal_encoding, &self.huff_offset, 0); - var size = dynamic_size.size; + const dynamic_size = self.dynamicSize(&self.literal_encoding, &self.huff_offset, 0); + const size = dynamic_size.size; num_codegens = dynamic_size.num_codegens; // Store bytes, if we don't get a reasonable improvement. - var stored_size_ret = storedSizeFits(input); - var ssize = stored_size_ret.size; - var storable = stored_size_ret.storable; + const stored_size_ret = storedSizeFits(input); + const ssize = stored_size_ret.size; + const storable = stored_size_ret.storable; if (storable and ssize < (size + (size >> 4))) { try self.writeStoredHeader(input.len, eof); @@ -736,18 +736,18 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { // Huffman. try self.writeDynamicHeader(num_literals, num_offsets, num_codegens, eof); - var encoding = self.literal_encoding.codes[0..257]; + const encoding = self.literal_encoding.codes[0..257]; var n = self.nbytes; for (input) |t| { // Bitwriting inlined, ~30% speedup - var c = encoding[t]; + const c = encoding[t]; self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits)); self.nbits += @as(u32, @intCast(c.len)); if (self.nbits < 48) { continue; } // Store 6 bytes - var bits = self.bits; + const bits = self.bits; self.bits >>= 48; self.nbits -= 48; var bytes = self.bytes[n..][0..6]; @@ -1679,7 +1679,7 @@ fn testWriterEOF(ttype: TestType, ht_tokens: []const token.Token, input: []const try bw.flush(); - var b = buf.items; + const b = buf.items; try expect(b.len > 0); try expect(b[0] & 1 == 1); } diff --git a/lib/std/compress/deflate/huffman_code.zig b/lib/std/compress/deflate/huffman_code.zig index 4fea45f86313226f44d83388d73934b6b4a592e6..c484d71fad3f7d5d3e637b91f5260ae616bfa40d 100644 --- a/lib/std/compress/deflate/huffman_code.zig +++ b/lib/std/compress/deflate/huffman_code.zig @@ -96,7 +96,7 @@ pub const HuffmanEncoder = struct { mem.sort(LiteralNode, self.lfs, {}, byFreq); // Get the number of literals for each bit count - var bit_count = self.bitCounts(list, max_bits); + const bit_count = self.bitCounts(list, max_bits); // And do the assignment self.assignEncodingAndSize(bit_count, list); } @@ -128,7 +128,7 @@ pub const HuffmanEncoder = struct { // that should be encoded in i bits. fn bitCounts(self: *HuffmanEncoder, list: []LiteralNode, max_bits_to_use: usize) []u32 { var max_bits = max_bits_to_use; - var n = list.len; + const n = list.len; assert(max_bits < max_bits_limit); @@ -184,10 +184,10 @@ pub const HuffmanEncoder = struct { continue; } - var prev_freq = l.last_freq; + const prev_freq = l.last_freq; if (l.next_char_freq < l.next_pair_freq) { // The next item on this row is a leaf node. - var next = leaf_counts[level][level] + 1; + const next = leaf_counts[level][level] + 1; l.last_freq = l.next_char_freq; // Lower leaf_counts are the same of the previous node. leaf_counts[level][level] = next; @@ -236,7 +236,7 @@ pub const HuffmanEncoder = struct { var bit_count = self.bit_count[0 .. max_bits + 1]; var bits: u32 = 1; - var counts = &leaf_counts[max_bits]; + const counts = &leaf_counts[max_bits]; { var level = max_bits; while (level > 0) : (level -= 1) { @@ -267,7 +267,7 @@ pub const HuffmanEncoder = struct { // are encoded using "bits" bits, and get the values // code, code + 1, .... The code values are // assigned in literal order (not frequency order). - var chunk = list[list.len - @as(u32, @intCast(bits)) ..]; + const chunk = list[list.len - @as(u32, @intCast(bits)) ..]; self.lns = chunk; mem.sort(LiteralNode, self.lns, {}, byLiteral); @@ -303,7 +303,7 @@ pub fn newHuffmanEncoder(allocator: Allocator, size: u32) !HuffmanEncoder { // Generates a HuffmanCode corresponding to the fixed literal table pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder { - var h = try newHuffmanEncoder(allocator, deflate_const.max_num_frequencies); + const h = try newHuffmanEncoder(allocator, deflate_const.max_num_frequencies); var codes = h.codes; var ch: u16 = 0; @@ -338,7 +338,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder { } pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder { - var h = try newHuffmanEncoder(allocator, 30); + const h = try newHuffmanEncoder(allocator, 30); var codes = h.codes; for (codes, 0..) |_, ch| { codes[ch] = HuffCode{ .code = bu.bitReverse(u16, @as(u16, @intCast(ch)), 5), .len = 5 }; diff --git a/lib/std/compress/zstandard.zig b/lib/std/compress/zstandard.zig index 225d6a9c691bcabb7962bf3c932f00c9b666a807..4d9421acac6dc2ebb152a8962b656f80c84d2d28 100644 --- a/lib/std/compress/zstandard.zig +++ b/lib/std/compress/zstandard.zig @@ -268,7 +268,7 @@ test "zstandard decompression" { const compressed3 = @embedFile("testdata/rfc8478.txt.zst.3"); const compressed19 = @embedFile("testdata/rfc8478.txt.zst.19"); - var buffer = try std.testing.allocator.alloc(u8, uncompressed.len); + const buffer = try std.testing.allocator.alloc(u8, uncompressed.len); defer std.testing.allocator.free(buffer); const res3 = try decompress.decode(buffer, compressed3, true); diff --git a/lib/std/compress/zstandard/decode/huffman.zig b/lib/std/compress/zstandard/decode/huffman.zig index 13fb1ac5f256775ac7ae52584a6e485428a64e83..9fc5cac7e5ce2108e52441585826444116d04961 100644 --- a/lib/std/compress/zstandard/decode/huffman.zig +++ b/lib/std/compress/zstandard/decode/huffman.zig @@ -54,7 +54,7 @@ fn decodeFseHuffmanTreeSlice(src: []const u8, compressed_size: usize, weights: * const start_index = std.math.cast(usize, counting_reader.bytes_read) orelse return error.MalformedHuffmanTree; - var huff_data = src[start_index..compressed_size]; + const huff_data = src[start_index..compressed_size]; var huff_bits: readers.ReverseBitReader = undefined; huff_bits.init(huff_data) catch return error.MalformedHuffmanTree; diff --git a/lib/std/compress/zstandard/decompress.zig b/lib/std/compress/zstandard/decompress.zig index c33d87379afb3842bcf29500ed8662a8eab7d2b7..a012312ab1a8cebbd7dcd995a12e6641d541c6a4 100644 --- a/lib/std/compress/zstandard/decompress.zig +++ b/lib/std/compress/zstandard/decompress.zig @@ -304,7 +304,7 @@ pub fn decodeZstandardFrame( var frame_context = context: { var fbs = std.io.fixedBufferStream(src[consumed_count..]); - var source = fbs.reader(); + const source = fbs.reader(); const frame_header = try decodeZstandardHeader(source); consumed_count += fbs.pos; break :context FrameContext.init( @@ -447,7 +447,7 @@ pub fn decodeZstandardFrameArrayList( var frame_context = context: { var fbs = std.io.fixedBufferStream(src[consumed_count..]); - var source = fbs.reader(); + const source = fbs.reader(); const frame_header = try decodeZstandardHeader(source); consumed_count += fbs.pos; break :context try FrameContext.init(frame_header, window_size_max, verify_checksum); diff --git a/lib/std/crypto/25519/curve25519.zig b/lib/std/crypto/25519/curve25519.zig index d5d70d00e455e0f9b0d40c9e764a80c107fcd2c6..48f167922e4e44d321f6d7dbadd36ce282ed29df 100644 --- a/lib/std/crypto/25519/curve25519.zig +++ b/lib/std/crypto/25519/curve25519.zig @@ -129,7 +129,7 @@ test "non-affine edwards25519 to curve25519 projection" { const skh = "90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e"; var sk: [32]u8 = undefined; _ = std.fmt.hexToBytes(&sk, skh) catch unreachable; - var edp = try crypto.ecc.Edwards25519.basePoint.mul(sk); + const edp = try crypto.ecc.Edwards25519.basePoint.mul(sk); const xp = try Curve25519.fromEdwards25519(edp); const expected_hex = "cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378"; var expected: [32]u8 = undefined; diff --git a/lib/std/crypto/25519/field.zig b/lib/std/crypto/25519/field.zig index 401616f1b8c2bfc7c179390cf6390374913e7f62..e18093f4c2f5dd17a010db3df28538b23495dd96 100644 --- a/lib/std/crypto/25519/field.zig +++ b/lib/std/crypto/25519/field.zig @@ -416,7 +416,7 @@ pub const Fe = struct { /// Compute the square root of `x2`, returning `error.NotSquare` if `x2` was not a square pub fn sqrt(x2: Fe) NotSquareError!Fe { - var x2_copy = x2; + const x2_copy = x2; const x = x2.uncheckedSqrt(); const check = x.sq().sub(x2_copy); if (check.isZero()) { diff --git a/lib/std/crypto/Certificate.zig b/lib/std/crypto/Certificate.zig index 9303e3c522f3c091d991838a5fc7ecb2e204f6d5..8318269d872bc2b9195976a289031e9badc5c921 100644 --- a/lib/std/crypto/Certificate.zig +++ b/lib/std/crypto/Certificate.zig @@ -982,7 +982,7 @@ pub const rsa = struct { if (mgf_len > mgf_out_buf.len) { // Modulus > 4096 bits return error.InvalidSignature; } - var mgf_out = mgf_out_buf[0 .. ((mgf_len - 1) / Hash.digest_length + 1) * Hash.digest_length]; + const mgf_out = mgf_out_buf[0 .. ((mgf_len - 1) / Hash.digest_length + 1) * Hash.digest_length]; var dbMask = try MGF1(Hash, mgf_out, h, mgf_len); // 8. Let DB = maskedDB \xor dbMask. diff --git a/lib/std/crypto/aes.zig b/lib/std/crypto/aes.zig index d043099f50ba7e5b12e2153c316d9579f933c931..f5752888fca018ce39af901e68082464ceeb7d27 100644 --- a/lib/std/crypto/aes.zig +++ b/lib/std/crypto/aes.zig @@ -47,7 +47,7 @@ test "ctr" { }; var out: [exp_out.len]u8 = undefined; - var ctx = Aes128.initEnc(key); + const ctx = Aes128.initEnc(key); ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.big); try testing.expectEqualSlices(u8, exp_out[0..], out[0..]); } diff --git a/lib/std/crypto/aes_ocb.zig b/lib/std/crypto/aes_ocb.zig index 05353a3c822c6369caccfe5f631e3c6ef9c23e07..879710d8481b2b44dad2c5b1f9bdb20dfde9c303 100644 --- a/lib/std/crypto/aes_ocb.zig +++ b/lib/std/crypto/aes_ocb.zig @@ -95,7 +95,7 @@ fn AesOcb(comptime Aes: anytype) type { var ktop_: Block = undefined; aes_enc_ctx.encrypt(&ktop_, &nx); const ktop = mem.readInt(u128, &ktop_, .big); - var stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56))); + const stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56))); var offset: Block = undefined; mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .big); return offset; diff --git a/lib/std/crypto/argon2.zig b/lib/std/crypto/argon2.zig index 4e6d391799d69f43263f1ce325d4ea4d3cad7191..8440590a98436b890ed88a01df1f1be1f7499519 100644 --- a/lib/std/crypto/argon2.zig +++ b/lib/std/crypto/argon2.zig @@ -565,7 +565,7 @@ const PhcFormatHasher = struct { const expected_hash = hash_result.hash.constSlice(); var hash_buf: [max_hash_len]u8 = undefined; if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding; - var hash = hash_buf[0..expected_hash.len]; + const hash = hash_buf[0..expected_hash.len]; try kdf(allocator, hash, password, hash_result.salt.constSlice(), params, mode); if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed; diff --git a/lib/std/crypto/ascon.zig b/lib/std/crypto/ascon.zig index 521f9c922e5862a4ea0ccb81ba12f374be591471..7691f14590b4a4ab11564e637af3b413e645136a 100644 --- a/lib/std/crypto/ascon.zig +++ b/lib/std/crypto/ascon.zig @@ -42,8 +42,7 @@ pub fn State(comptime endian: std.builtin.Endian) type { /// Initialize the state from u64 words in native endianness. pub fn initFromWords(initial_state: [5]u64) Self { - var state = Self{ .st = initial_state }; - return state; + return .{ .st = initial_state }; } /// Initialize the state for Ascon XOF diff --git a/lib/std/crypto/bcrypt.zig b/lib/std/crypto/bcrypt.zig index 720f264d163fa45b25a80f1da76f101487a91b8a..7c505f542fd511ac590b9ea339f1c21f2b38607a 100644 --- a/lib/std/crypto/bcrypt.zig +++ b/lib/std/crypto/bcrypt.zig @@ -431,7 +431,7 @@ pub fn bcrypt( const trimmed_len = @min(password.len, password_buf.len - 1); @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]); password_buf[trimmed_len] = 0; - var passwordZ = password_buf[0 .. trimmed_len + 1]; + const passwordZ = password_buf[0 .. trimmed_len + 1]; state.expand(salt[0..], passwordZ); const rounds: u64 = @as(u64, 1) << params.rounds_log; diff --git a/lib/std/crypto/blake3.zig b/lib/std/crypto/blake3.zig index 04becf678959ad9581f3f9a9ab61fde1a54700dc..d87211fb1ea9e981bb05138e85b79ed6f224de13 100644 --- a/lib/std/crypto/blake3.zig +++ b/lib/std/crypto/blake3.zig @@ -241,7 +241,7 @@ const Output = struct { var out_block_it = ChunkIterator.init(output, 2 * OUT_LEN); var output_block_counter: usize = 0; while (out_block_it.next()) |out_block| { - var words = compress( + const words = compress( self.input_chaining_value, self.block_words, self.block_len, diff --git a/lib/std/crypto/ecdsa.zig b/lib/std/crypto/ecdsa.zig index 6f8a32ea21e73ca1f8f182d962977b723802fe9b..321923525b4955e2556d6c73f02d90e3c1dab408 100644 --- a/lib/std/crypto/ecdsa.zig +++ b/lib/std/crypto/ecdsa.zig @@ -201,7 +201,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { const scalar_encoded_length = Curve.scalar.encoded_length; const h_len = @max(Hash.digest_length, scalar_encoded_length); var h: [h_len]u8 = [_]u8{0} ** h_len; - var h_slice = h[h_len - Hash.digest_length .. h_len]; + const h_slice = h[h_len - Hash.digest_length .. h_len]; self.h.final(h_slice); std.debug.assert(h.len >= scalar_encoded_length); diff --git a/lib/std/crypto/pbkdf2.zig b/lib/std/crypto/pbkdf2.zig index 2e0318369b836cbe6c01d21d9225ec8e22c9e63c..cb11950228a33b94df78d871310cce5dbcac58b6 100644 --- a/lib/std/crypto/pbkdf2.zig +++ b/lib/std/crypto/pbkdf2.zig @@ -255,10 +255,8 @@ test "Very large dk_len" { const c = 1; const dk_len = 1 << 33; - var dk = try std.testing.allocator.alloc(u8, dk_len); - defer { - std.testing.allocator.free(dk); - } + const dk = try std.testing.allocator.alloc(u8, dk_len); + defer std.testing.allocator.free(dk); // Just verify this doesn't crash with an overflow try pbkdf2(dk, p, s, c, HmacSha1); diff --git a/lib/std/crypto/pcurves/common.zig b/lib/std/crypto/pcurves/common.zig index 4a6815ae052c0a0d2751eb61a2a67f5adecbae3b..ccf40f59ce670afbfa7c3cef9fc9c171fd8612e5 100644 --- a/lib/std/crypto/pcurves/common.zig +++ b/lib/std/crypto/pcurves/common.zig @@ -71,7 +71,7 @@ pub fn Field(comptime params: FieldParams) type { /// Unpack a field element. pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe { - var s = if (endian == .little) s_ else orderSwap(s_); + const s = if (endian == .little) s_ else orderSwap(s_); try rejectNonCanonical(s, .little); var limbs_z: NonMontgomeryDomainFieldElement = undefined; fiat.fromBytes(&limbs_z, s); diff --git a/lib/std/crypto/poly1305.zig b/lib/std/crypto/poly1305.zig index 67e1b630c1cba0ba673adbd2fe8020d8f4cf8841..d9fd344c19e7d624bccce406a76ca5ce4028b3f7 100644 --- a/lib/std/crypto/poly1305.zig +++ b/lib/std/crypto/poly1305.zig @@ -90,8 +90,8 @@ pub const Poly1305 = struct { h2 = t2 & 3; // Add c*(4+1) - var cclo = t2 & ~@as(u64, 3); - var cchi = t3; + const cclo = t2 & ~@as(u64, 3); + const cchi = t3; v = @addWithOverflow(h0, cclo); h0 = v[0]; v = add(h1, cchi, v[1]); @@ -163,7 +163,7 @@ pub const Poly1305 = struct { var h0 = st.h[0]; var h1 = st.h[1]; - var h2 = st.h[2]; + const h2 = st.h[2]; // H - (2^130 - 5) var v = @subWithOverflow(h0, 0xfffffffffffffffb); diff --git a/lib/std/crypto/salsa20.zig b/lib/std/crypto/salsa20.zig index b83db0a317857e2f7dc1c0d9e474e7e30dd21e26..7f4c1b0157a09aac380c9dad82d84940bb030a19 100644 --- a/lib/std/crypto/salsa20.zig +++ b/lib/std/crypto/salsa20.zig @@ -605,8 +605,8 @@ test "xsalsa20poly1305 box" { crypto.random.bytes(&msg); crypto.random.bytes(&nonce); - var kp1 = try Box.KeyPair.create(null); - var kp2 = try Box.KeyPair.create(null); + const kp1 = try Box.KeyPair.create(null); + const kp2 = try Box.KeyPair.create(null); try Box.seal(boxed[0..], msg[0..], nonce, kp1.public_key, kp2.secret_key); try Box.open(msg2[0..], boxed[0..], nonce, kp2.public_key, kp1.secret_key); } @@ -617,7 +617,7 @@ test "xsalsa20poly1305 sealedbox" { var boxed: [msg.len + SealedBox.seal_length]u8 = undefined; crypto.random.bytes(&msg); - var kp = try Box.KeyPair.create(null); + const kp = try Box.KeyPair.create(null); try SealedBox.seal(boxed[0..], msg[0..], kp.public_key); try SealedBox.open(msg2[0..], boxed[0..], kp); } diff --git a/lib/std/crypto/scrypt.zig b/lib/std/crypto/scrypt.zig index cf16476d925a1dd0fefe6df1a7d7bc02ff4e27af..96943b06f12d028dc12ea9110f819f260b519371 100644 --- a/lib/std/crypto/scrypt.zig +++ b/lib/std/crypto/scrypt.zig @@ -87,8 +87,8 @@ fn integerify(b: []align(16) const u32, r: u30) u64 { } fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void { - var x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]); - var y: []align(16) u32 = @alignCast(xy[32 * r ..]); + const x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]); + const y: []align(16) u32 = @alignCast(xy[32 * r ..]); for (x, 0..) |*v1, j| { v1.* = mem.readInt(u32, b[4 * j ..][0..4], .little); @@ -191,9 +191,9 @@ pub fn kdf( params.r > max_int / 256 or n > max_int / 128 / @as(u64, params.r)) return KdfError.WeakParameters; - var xy = try allocator.alignedAlloc(u32, 16, 64 * params.r); + const xy = try allocator.alignedAlloc(u32, 16, 64 * params.r); defer allocator.free(xy); - var v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r); + const v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r); defer allocator.free(v); var dk = try allocator.alignedAlloc(u8, 16, params.p * 128 * params.r); defer allocator.free(dk); @@ -263,7 +263,7 @@ const crypt_format = struct { const value = self.constSlice(); const len = Codec.encodedLen(value.len); if (len > buf.len) return EncodingError.NoSpaceLeft; - var encoded = buf[0..len]; + const encoded = buf[0..len]; Codec.encode(encoded, value); return encoded; } @@ -439,7 +439,7 @@ const PhcFormatHasher = struct { const expected_hash = hash_result.hash.constSlice(); var hash_buf: [max_hash_len]u8 = undefined; if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding; - var hash = hash_buf[0..expected_hash.len]; + const hash = hash_buf[0..expected_hash.len]; try kdf(allocator, hash, password, hash_result.salt.constSlice(), params); if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed; } @@ -487,7 +487,7 @@ const CryptFormatHasher = struct { const expected_hash = hash_result.hash.constSlice(); var hash_buf: [max_hash_len]u8 = undefined; if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding; - var hash = hash_buf[0..expected_hash.len]; + const hash = hash_buf[0..expected_hash.len]; try kdf(allocator, hash, password, hash_result.salt, params); if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed; } diff --git a/lib/std/crypto/tls/Client.zig b/lib/std/crypto/tls/Client.zig index 5f6b1e4c141cfce8996ba81ea9d86ba428d96103..af564a1e525f23e937f8b8ce3de0eb069e1458f2 100644 --- a/lib/std/crypto/tls/Client.zig +++ b/lib/std/crypto/tls/Client.zig @@ -491,7 +491,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In try all_extd.ensure(4); const et = all_extd.decode(tls.ExtensionType); const ext_size = all_extd.decode(u16); - var extd = try all_extd.sub(ext_size); + const extd = try all_extd.sub(ext_size); _ = extd; switch (et) { .server_name => {}, @@ -516,7 +516,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In while (!certs_decoder.eof()) { try certs_decoder.ensure(3); const cert_size = certs_decoder.decode(u24); - var certd = try certs_decoder.sub(cert_size); + const certd = try certs_decoder.sub(cert_size); const subject_cert: Certificate = .{ .buffer = certd.buf, @@ -552,7 +552,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In try certs_decoder.ensure(2); const total_ext_size = certs_decoder.decode(u16); - var all_extd = try certs_decoder.sub(total_ext_size); + const all_extd = try certs_decoder.sub(total_ext_size); _ = all_extd; } }, diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 9247ab4047271190f9691287306eea6753723926..0ce9f7b13203548657c3e8e3d016086af3213a9e 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -812,7 +812,7 @@ pub fn writeStackTraceWindows( var addr_buf: [1024]usize = undefined; const n = walkStackWindows(addr_buf[0..], context); const addrs = addr_buf[0..n]; - var start_i: usize = if (start_addr) |saddr| blk: { + const start_i: usize = if (start_addr) |saddr| blk: { for (addrs, 0..) |addr, i| { if (addr == saddr) break :blk i; } @@ -1158,7 +1158,7 @@ pub fn readElfDebugInfo( var zlib_stream = std.compress.zlib.decompressStream(allocator, section_stream.reader()) catch continue; defer zlib_stream.deinit(); - var decompressed_section = try allocator.alloc(u8, chdr.ch_size); + const decompressed_section = try allocator.alloc(u8, chdr.ch_size); errdefer allocator.free(decompressed_section); const read = zlib_stream.reader().readAll(decompressed_section) catch continue; @@ -2046,7 +2046,7 @@ pub const ModuleDebugInfo = switch (native_os) { }; try DW.openDwarfDebugInfo(&di, allocator); - var info = OFileInfo{ + const info = OFileInfo{ .di = di, .addr_table = addr_table, }; @@ -2122,7 +2122,7 @@ pub const ModuleDebugInfo = switch (native_os) { // Check if its debug infos are already in the cache const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0); - var o_file_info = self.ofiles.getPtr(o_file_path) orelse + const o_file_info = self.ofiles.getPtr(o_file_path) orelse (self.loadOFile(allocator, o_file_path) catch |err| switch (err) { error.FileNotFound, error.MissingDebugInfo, diff --git a/lib/std/dwarf.zig b/lib/std/dwarf.zig index 7b4aa0fdec9a7f1ad71dabe78dfc1e36754af67f..97864c03ff36aa01158db6712ffbb3a4bd1de7e9 100644 --- a/lib/std/dwarf.zig +++ b/lib/std/dwarf.zig @@ -622,7 +622,7 @@ fn parseFormValue(allocator: mem.Allocator, in_stream: anytype, form_id: u64, en return parseFormValue(allocator, in_stream, child_form_id, endian, is_64); } const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64)); - var frame = try allocator.create(F); + const frame = try allocator.create(F); defer allocator.destroy(frame); return await @asyncCall(frame, {}, parseFormValue, .{ allocator, in_stream, child_form_id, endian, is_64 }); }, @@ -1034,7 +1034,7 @@ pub const DwarfInfo = struct { // specified by DW_AT.low_pc or to some other value encoded // in the list itself. // If no starting value is specified use zero. - var base_address = compile_unit.die.getAttrAddr(di, AT.low_pc, compile_unit.*) catch |err| switch (err) { + const base_address = compile_unit.die.getAttrAddr(di, AT.low_pc, compile_unit.*) catch |err| switch (err) { error.MissingDebugInfo => @as(u64, 0), // TODO https://github.com/ziglang/zig/issues/11135 else => return err, }; @@ -1438,7 +1438,7 @@ pub const DwarfInfo = struct { if (opcode == LNS.extended_op) { const op_size = try leb.readULEB128(u64, in); if (op_size < 1) return badDwarf(); - var sub_op = try in.readByte(); + const sub_op = try in.readByte(); switch (sub_op) { LNE.end_sequence => { prog.end_sequence = true; @@ -2308,7 +2308,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo else => return badDwarf(), }; - var base = switch (enc & EH.PE.rel_mask) { + const base = switch (enc & EH.PE.rel_mask) { EH.PE.pcrel => ctx.pc_rel_base, EH.PE.textrel => ctx.text_rel_base orelse return error.PointerBaseNotSpecified, EH.PE.datarel => ctx.data_rel_base orelse return error.PointerBaseNotSpecified, @@ -2624,7 +2624,7 @@ pub const CommonInformationEntry = struct { var has_aug_data = false; var aug_str_len: usize = 0; - var aug_str_start = stream.pos; + const aug_str_start = stream.pos; var aug_byte = try reader.readByte(); while (aug_byte != 0) : (aug_byte = try reader.readByte()) { switch (aug_byte) { diff --git a/lib/std/dwarf/expressions.zig b/lib/std/dwarf/expressions.zig index 729ff0de9ba53b2f3285f8c7bd50ea87ebd8ecad..61acab7793e6ed4ec9b2f1376da6edb31dff7184 100644 --- a/lib/std/dwarf/expressions.zig +++ b/lib/std/dwarf/expressions.zig @@ -443,7 +443,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { OP.xderef_type, => { if (self.stack.items.len == 0) return error.InvalidExpression; - var addr = try self.stack.items[self.stack.items.len - 1].asIntegral(); + const addr = try self.stack.items[self.stack.items.len - 1].asIntegral(); const addr_space_identifier: ?usize = switch (opcode) { OP.xderef, OP.xderef_size, @@ -1350,7 +1350,7 @@ test "DWARF expressions" { // Arithmetic and Logical Operations { - var context = ExpressionContext{}; + const context = ExpressionContext{}; stack_machine.reset(); program.clearRetainingCapacity(); @@ -1474,7 +1474,7 @@ test "DWARF expressions" { // Control Flow Operations { - var context = ExpressionContext{}; + const context = ExpressionContext{}; const expected = .{ .{ OP.le, 1, 1, 0 }, .{ OP.ge, 1, 0, 1 }, @@ -1531,7 +1531,7 @@ test "DWARF expressions" { // Type conversions { - var context = ExpressionContext{}; + const context = ExpressionContext{}; stack_machine.reset(); program.clearRetainingCapacity(); diff --git a/lib/std/enums.zig b/lib/std/enums.zig index b3b546c4d0768c31e03b5001be9d6937d134cb85..0ee090dae1ee5630134f47a1a5bf0dcbafaf5764 100644 --- a/lib/std/enums.zig +++ b/lib/std/enums.zig @@ -123,6 +123,7 @@ pub fn directEnumArray( test "std.enums.directEnumArray" { const E = enum(i4) { a = 4, b = 6, c = 2 }; var runtime_false: bool = false; + _ = &runtime_false; const array = directEnumArray(E, bool, 4, .{ .a = true, .b = runtime_false, @@ -165,6 +166,7 @@ pub fn directEnumArrayDefault( test "std.enums.directEnumArrayDefault" { const E = enum(i4) { a = 4, b = 6, c = 2 }; var runtime_false: bool = false; + _ = &runtime_false; const array = directEnumArrayDefault(E, bool, false, 4, .{ .a = true, .b = runtime_false, @@ -179,6 +181,7 @@ test "std.enums.directEnumArrayDefault" { test "std.enums.directEnumArrayDefault slice" { const E = enum(i4) { a = 4, b = 6, c = 2 }; var runtime_b = "b"; + _ = &runtime_b; const array = directEnumArrayDefault(E, []const u8, "default", 4, .{ .a = "a", .b = runtime_b, @@ -196,7 +199,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E { return comptime blk: { const V = @TypeOf(value); if (V == E) break :blk value; - var name: ?[]const u8 = switch (@typeInfo(V)) { + const name: ?[]const u8 = switch (@typeInfo(V)) { .EnumLiteral, .Enum => @tagName(value), .Pointer => if (std.meta.trait.isZigString(V)) value else null, else => null, diff --git a/lib/std/event/group.zig b/lib/std/event/group.zig index 639d90b12ae0077918fb58112548e179b66b7b79..6d513000f474637807ff29c7b41500651034ec24 100644 --- a/lib/std/event/group.zig +++ b/lib/std/event/group.zig @@ -66,7 +66,7 @@ pub fn Group(comptime ReturnType: type) type { /// `func` must be async and have return type `ReturnType`. /// Thread-safe. pub fn call(self: *Self, comptime func: anytype, args: anytype) error{OutOfMemory}!void { - var frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args))); + const frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args))); errdefer self.allocator.destroy(frame); const node = try self.allocator.create(AllocStack.Node); errdefer self.allocator.destroy(node); diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index 883312d176d84a6343fb0f39550003523634849c..58cf09fbf54b511556b848a57d12b489573e9f0a 100644 --- a/lib/std/event/loop.zig +++ b/lib/std/event/loop.zig @@ -753,7 +753,7 @@ pub const Loop = struct { } }; - var run_frame = try alloc.create(@Frame(Wrapper.run)); + const run_frame = try alloc.create(@Frame(Wrapper.run)); run_frame.* = async Wrapper.run(args, self, alloc); } diff --git a/lib/std/event/rwlock.zig b/lib/std/event/rwlock.zig index 47ddf74fd5dcc0c19e4acaea44ce39cf9bf10eb0..0f017a0ca0c88786872be4b04046fec9106b3126 100644 --- a/lib/std/event/rwlock.zig +++ b/lib/std/event/rwlock.zig @@ -228,7 +228,7 @@ test "std.event.RwLock" { } fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void { var read_nodes: [100]Loop.NextTickNode = undefined; - for (read_nodes) |*read_node| { + for (&read_nodes) |*read_node| { const frame = allocator.create(@Frame(readRunner)) catch @panic("memory"); read_node.data = frame; frame.* = async readRunner(lock); @@ -236,19 +236,19 @@ fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void { } var write_nodes: [shared_it_count]Loop.NextTickNode = undefined; - for (write_nodes) |*write_node| { + for (&write_nodes) |*write_node| { const frame = allocator.create(@Frame(writeRunner)) catch @panic("memory"); write_node.data = frame; frame.* = async writeRunner(lock); Loop.instance.?.onNextTick(write_node); } - for (write_nodes) |*write_node| { + for (&write_nodes) |*write_node| { const casted = @as(*const @Frame(writeRunner), @ptrCast(write_node.data)); await casted; allocator.destroy(casted); } - for (read_nodes) |*read_node| { + for (&read_nodes) |*read_node| { const casted = @as(*const @Frame(readRunner), @ptrCast(read_node.data)); await casted; allocator.destroy(casted); diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index ed049079b6467197b1804ab50700274c9d14fde9..e21b1b9af1601904512b3bbf21bf7aa92a67931e 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -1296,10 +1296,10 @@ pub fn formatFloatDecimal( errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal); // exp < 0 means the leading is always 0 as errol result is normalized. - var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0; + const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0; // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this. - var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len); + const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len); if (num_digits_whole > 0) { // We may have to zero pad, for instance 1e4 requires zero padding. @@ -1354,10 +1354,10 @@ pub fn formatFloatDecimal( } } else { // exp < 0 means the leading is always 0 as errol result is normalized. - var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0; + const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0; // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this. - var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len); + const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len); if (num_digits_whole > 0) { // We may have to zero pad, for instance 1e4 requires zero padding. @@ -2218,6 +2218,7 @@ test "slice" { } { var runtime_zero: usize = 0; + _ = &runtime_zero; const value = @as([*]align(1) const []const u8, @ptrFromInt(0xdeadbeef))[runtime_zero..runtime_zero]; try expectFmt("slice: []const u8@deadbeef\n", "slice: {*}\n", .{value}); } @@ -2232,6 +2233,7 @@ test "slice" { { var int_slice = [_]u32{ 1, 4096, 391891, 1111111111 }; var runtime_zero: usize = 0; + _ = &runtime_zero; try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {any}", .{int_slice[runtime_zero..]}); try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {d}", .{int_slice[runtime_zero..]}); try expectFmt("int: { 1, 1000, 5fad3, 423a35c7 }", "int: {x}", .{int_slice[runtime_zero..]}); @@ -2794,14 +2796,14 @@ test "padding" { } test "decimal float padding" { - var number: f32 = 3.1415; + const number: f32 = 3.1415; try expectFmt("left-pad: **3.141\n", "left-pad: {d:*>7.3}\n", .{number}); try expectFmt("center-pad: *3.141*\n", "center-pad: {d:*^7.3}\n", .{number}); try expectFmt("right-pad: 3.141**\n", "right-pad: {d:*<7.3}\n", .{number}); } test "sci float padding" { - var number: f32 = 3.1415; + const number: f32 = 3.1415; try expectFmt("left-pad: **3.141e+00\n", "left-pad: {e:*>11.3}\n", .{number}); try expectFmt("center-pad: *3.141e+00*\n", "center-pad: {e:*^11.3}\n", .{number}); try expectFmt("right-pad: 3.141e+00**\n", "right-pad: {e:*<11.3}\n", .{number}); @@ -2825,7 +2827,7 @@ test "named arguments" { } test "runtime width specifier" { - var width: usize = 9; + const width: usize = 9; try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width }); try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width }); try expectFmt(" hello", "{s:[1]}", .{ "hello", width }); @@ -2833,8 +2835,8 @@ test "runtime width specifier" { } test "runtime precision specifier" { - var number: f32 = 3.1415; - var precision: usize = 2; + const number: f32 = 3.1415; + const precision: usize = 2; try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision }); try expectFmt("3.14e+00", "{:1.[precision]}", .{ .number = number, .precision = precision }); } diff --git a/lib/std/fmt/errol.zig b/lib/std/fmt/errol.zig index af686d6448d739be7ee863ff860dca7bc40b7a13..760ebca786e2120e0b182d241584a953d7c270fe 100644 --- a/lib/std/fmt/errol.zig +++ b/lib/std/fmt/errol.zig @@ -367,8 +367,8 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal { var lo = ((fpprev(val) - n) + mid) / 2.0; var hi = ((fpnext(val) - n) + mid) / 2.0; - var buf_index = u64toa(u, buffer); - var exp = @as(i32, @intCast(buf_index)); + const buf_index = u64toa(u, buffer); + const exp: i32 = @intCast(buf_index); var j = buf_index; buffer[j] = 0; diff --git a/lib/std/fmt/parse_float/parse.zig b/lib/std/fmt/parse_float/parse.zig index a31df31312eb8a51702dc6a65587881e5e730343..841119aa0207f931aeb65a1fc465b1a3b4d81fa5 100644 --- a/lib/std/fmt/parse_float/parse.zig +++ b/lib/std/fmt/parse_float/parse.zig @@ -105,7 +105,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool // parse initial digits before dot var mantissa: MantissaT = 0; tryParseDigits(MantissaT, stream, &mantissa, info.base); - var int_end = stream.offsetTrue(); + const int_end = stream.offsetTrue(); var n_digits = @as(isize, @intCast(stream.offsetTrue())); // the base being 16 implies a 0x prefix, which shouldn't be included in the digit count if (info.base == 16) n_digits -= 2; @@ -188,7 +188,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool // than 19 digits. That means we must have a decimal // point, and at least 1 fractional digit. stream.advance(1); - var marker = stream.offsetTrue(); + const marker = stream.offsetTrue(); tryParseNDigits(MantissaT, stream, &mantissa, info.base, info.max_mantissa_digits); break :blk @as(i64, @intCast(marker)) - @as(i64, @intCast(stream.offsetTrue())); } diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 6cda6716b7652f0a46d237810224fe212135f973..fd8116edaa21322430a66f668edde93223367dbc 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -1689,7 +1689,7 @@ pub const Dir = struct { } if (builtin.os.tag == .windows) { var dir_path_buffer: [os.windows.PATH_MAX_WIDE]u16 = undefined; - var dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer); + const dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer); if (builtin.link_libc) { return os.chdirW(dir_path); } @@ -1810,7 +1810,7 @@ pub const Dir = struct { const base_flags = w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA | w.SYNCHRONIZE | w.FILE_TRAVERSE; const flags: u32 = if (iterable) base_flags | w.FILE_LIST_DIRECTORY else base_flags; - var dir = try self.makeOpenDirAccessMaskW(sub_path_w, flags, .{ + const dir = try self.makeOpenDirAccessMaskW(sub_path_w, flags, .{ .no_follow = args.no_follow, .create_disposition = w.FILE_OPEN, }); diff --git a/lib/std/fs/get_app_data_dir.zig b/lib/std/fs/get_app_data_dir.zig index ae203e52602056ad49f78c689c60a282b847fcc8..904cea5e7fe4c7e0ce065e5b3e630efb57edc5b0 100644 --- a/lib/std/fs/get_app_data_dir.zig +++ b/lib/std/fs/get_app_data_dir.zig @@ -57,6 +57,10 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi }, .haiku => { var dir_path_ptr: [*:0]u8 = undefined; + if (true) { + _ = &dir_path_ptr; + @compileError("TODO: init dir_path_ptr"); + } // TODO look into directory_which const be_user_settings = 0xbbe; const rc = os.system.find_directory(be_user_settings, -1, true, dir_path_ptr, 1); diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index 9a11c7cb29090c61ef18c0bdfa1fd94674ba23b9..6786aec4b0234d75cce339fb5b67ad564fa52119 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -80,7 +80,7 @@ const TestContext = struct { transform_fn: *const PathType.TransformFn, pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext { - var tmp = tmpIterableDir(.{}); + const tmp = tmpIterableDir(.{}); return .{ .path_type = path_type, .arena = ArenaAllocator.init(allocator), diff --git a/lib/std/fs/watch.zig b/lib/std/fs/watch.zig index 280c8888e6ea39a8e78209ab272e04bb5e270dad..e6485093cac37f52b2f4ced98977ee4df9ed4b96 100644 --- a/lib/std/fs/watch.zig +++ b/lib/std/fs/watch.zig @@ -116,7 +116,7 @@ pub fn Watch(comptime V: type) type { }, }; - var buf = try allocator.alloc(Event.Error!Event, event_buf_count); + const buf = try allocator.alloc(Event.Error!Event, event_buf_count); self.channel.init(buf); self.os_data.putter_frame = async self.linuxEventPutter(); return self; @@ -132,7 +132,7 @@ pub fn Watch(comptime V: type) type { }, }; - var buf = try allocator.alloc(Event.Error!Event, event_buf_count); + const buf = try allocator.alloc(Event.Error!Event, event_buf_count); self.channel.init(buf); return self; }, @@ -147,7 +147,7 @@ pub fn Watch(comptime V: type) type { }, }; - var buf = try allocator.alloc(Event.Error!Event, event_buf_count); + const buf = try allocator.alloc(Event.Error!Event, event_buf_count); self.channel.init(buf); return self; }, diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig index c5c6c585ebadd68f4f09e22e32371d2b80465e3b..78e2cab1040e5d46331184212869d912e5887b15 100644 --- a/lib/std/hash/auto_hash.zig +++ b/lib/std/hash/auto_hash.zig @@ -280,6 +280,7 @@ test "hash slice shallow" { const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 }; // TODO audit deep/shallow - maybe it has the wrong behavior with respect to array pointers and slices var runtime_zero: usize = 0; + _ = &runtime_zero; const a = array1[runtime_zero..]; const b = array2[runtime_zero..]; const c = array1[runtime_zero..3]; diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig index cd240da964ad75474056b4971da619be22fb7b42..781949321d0c37d624b29f8f5599fff5f0873f39 100644 --- a/lib/std/hash/cityhash.zig +++ b/lib/std/hash/cityhash.zig @@ -271,7 +271,7 @@ pub const CityHash64 = struct { var b1: u64 = b; a1 +%= w; b1 = rotr64(b1 +% a1 +% z, 21); - var c: u64 = a1; + const c: u64 = a1; a1 +%= x; a1 +%= y; b1 +%= rotr64(a1, 44); diff --git a/lib/std/hash/murmur.zig b/lib/std/hash/murmur.zig index a9299f245d36b8305db7d9c293f56b041b2f8525..65a52f6b564fbf3316de8982b413f872c7627ded 100644 --- a/lib/std/hash/murmur.zig +++ b/lib/std/hash/murmur.zig @@ -134,7 +134,7 @@ pub const Murmur2_64 = struct { const m: u64 = 0xc6a4a7935bd1e995; const len: u64 = 4; var h1: u64 = seed ^ (len *% m); - var k1: u64 = v; + const k1: u64 = v; h1 ^= k1; h1 *%= m; h1 ^= h1 >> 47; @@ -282,16 +282,14 @@ pub const Murmur3_32 = struct { const verify = @import("verify.zig"); test "murmur2_32" { - var v0: u32 = 0x12345678; - var v1: u64 = 0x1234567812345678; - var v0le: u32 = v0; - var v1le: u64 = v1; - if (native_endian == .big) { - v0le = @byteSwap(v0le); - v1le = @byteSwap(v1le); - } - try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0)); - try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1)); + const v0: u32 = 0x12345678; + const v1: u64 = 0x1234567812345678; + const v0le: u32, const v1le: u64 = switch (native_endian) { + .little => .{ v0, v1 }, + .big => .{ @byteSwap(v0), @byteSwap(v1) }, + }; + try testing.expectEqual(Murmur2_32.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0)); + try testing.expectEqual(Murmur2_32.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1)); } test "murmur2_32 smhasher" { @@ -306,16 +304,14 @@ test "murmur2_32 smhasher" { } test "murmur2_64" { - var v0: u32 = 0x12345678; - var v1: u64 = 0x1234567812345678; - var v0le: u32 = v0; - var v1le: u64 = v1; - if (native_endian == .big) { - v0le = @byteSwap(v0le); - v1le = @byteSwap(v1le); - } - try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0)); - try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1)); + const v0: u32 = 0x12345678; + const v1: u64 = 0x1234567812345678; + const v0le: u32, const v1le: u64 = switch (native_endian) { + .little => .{ v0, v1 }, + .big => .{ @byteSwap(v0), @byteSwap(v1) }, + }; + try testing.expectEqual(Murmur2_64.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0)); + try testing.expectEqual(Murmur2_64.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1)); } test "mumur2_64 smhasher" { @@ -330,16 +326,14 @@ test "mumur2_64 smhasher" { } test "murmur3_32" { - var v0: u32 = 0x12345678; - var v1: u64 = 0x1234567812345678; - var v0le: u32 = v0; - var v1le: u64 = v1; - if (native_endian == .big) { - v0le = @byteSwap(v0le); - v1le = @byteSwap(v1le); - } - try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0)); - try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1)); + const v0: u32 = 0x12345678; + const v1: u64 = 0x1234567812345678; + const v0le: u32, const v1le: u64 = switch (native_endian) { + .little => .{ v0, v1 }, + .big => .{ @byteSwap(v0), @byteSwap(v1) }, + }; + try testing.expectEqual(Murmur3_32.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0)); + try testing.expectEqual(Murmur3_32.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1)); } test "mumur3_32 smhasher" { diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig index 40a412bf3c4b6441b954e8c4d4bc8312f6cdf0fe..2353c8962ee3ea4b1f3c78335dcfa647a7c8b687 100644 --- a/lib/std/hash_map.zig +++ b/lib/std/hash_map.zig @@ -1484,8 +1484,8 @@ pub fn HashMapUnmanaged( var i: Size = 0; var metadata = self.metadata.?; - var keys_ptr = self.keys(); - var values_ptr = self.values(); + const keys_ptr = self.keys(); + const values_ptr = self.values(); while (i < self.capacity()) : (i += 1) { if (metadata[i].isUsed()) { other.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], new_ctx); @@ -1521,8 +1521,8 @@ pub fn HashMapUnmanaged( const old_capacity = self.capacity(); var i: Size = 0; var metadata = self.metadata.?; - var keys_ptr = self.keys(); - var values_ptr = self.values(); + const keys_ptr = self.keys(); + const values_ptr = self.values(); while (i < old_capacity) : (i += 1) { if (metadata[i].isUsed()) { map.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], ctx); diff --git a/lib/std/heap.zig b/lib/std/heap.zig index 0c61242e5619d1635276f436b93a07352af1145e..ec8679f6b2e072a7ee3785abb690dfe30255cf53 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -81,10 +81,10 @@ const CAllocator = struct { // Thin wrapper around regular malloc, overallocate to account for // alignment padding and store the original malloc()'ed pointer before // the aligned address. - var unaligned_ptr = @as([*]u8, @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null)); + const unaligned_ptr = @as([*]u8, @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null)); const unaligned_addr = @intFromPtr(unaligned_ptr); const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment); - var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); + const aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); getHeader(aligned_ptr).* = unaligned_ptr; return aligned_ptr; @@ -661,12 +661,12 @@ test "FixedBufferAllocator.reset" { const X = 0xeeeeeeeeeeeeeeee; const Y = 0xffffffffffffffff; - var x = try allocator.create(u64); + const x = try allocator.create(u64); x.* = X; try testing.expectError(error.OutOfMemory, allocator.create(u64)); fba.reset(); - var y = try allocator.create(u64); + const y = try allocator.create(u64); y.* = Y; // we expect Y to have overwritten X. @@ -691,9 +691,9 @@ test "FixedBufferAllocator Reuse memory on realloc" { var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]); const allocator = fixed_buffer_allocator.allocator(); - var slice0 = try allocator.alloc(u8, 5); + const slice0 = try allocator.alloc(u8, 5); try testing.expect(slice0.len == 5); - var slice1 = try allocator.realloc(slice0, 10); + const slice1 = try allocator.realloc(slice0, 10); try testing.expect(slice1.ptr == slice0.ptr); try testing.expect(slice1.len == 10); try testing.expectError(error.OutOfMemory, allocator.realloc(slice1, 11)); @@ -706,8 +706,8 @@ test "FixedBufferAllocator Reuse memory on realloc" { var slice0 = try allocator.alloc(u8, 2); slice0[0] = 1; slice0[1] = 2; - var slice1 = try allocator.alloc(u8, 2); - var slice2 = try allocator.realloc(slice0, 4); + const slice1 = try allocator.alloc(u8, 2); + const slice2 = try allocator.realloc(slice0, 4); try testing.expect(slice0.ptr != slice2.ptr); try testing.expect(slice1.ptr != slice2.ptr); try testing.expect(slice2[0] == 1); @@ -757,7 +757,7 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void { allocator.free(slice); // Zero-length allocation - var empty = try allocator.alloc(u8, 0); + const empty = try allocator.alloc(u8, 0); allocator.free(empty); // Allocation with zero-sized types const zero_bit_ptr = try allocator.create(u0); diff --git a/lib/std/heap/arena_allocator.zig b/lib/std/heap/arena_allocator.zig index 69a99eccd3169de5da9475500e4ec1d1bd7da5ac..09f2e609f484820bd625f3c1ccde0cc1c64a02cc 100644 --- a/lib/std/heap/arena_allocator.zig +++ b/lib/std/heap/arena_allocator.zig @@ -257,7 +257,7 @@ test "ArenaAllocator (reset with preheating)" { rounds -= 1; _ = arena_allocator.reset(.retain_capacity); var alloced_bytes: usize = 0; - var total_size: usize = random.intRangeAtMost(usize, 256, 16384); + const total_size: usize = random.intRangeAtMost(usize, 256, 16384); while (alloced_bytes < total_size) { const size = random.intRangeAtMost(usize, 16, 256); const alignment = 32; diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig index 6dc6df399811c98c782a6b2cd1013e24f194be53..b79d73f0e966b408f7699d450cae1f6051701ad0 100644 --- a/lib/std/heap/general_purpose_allocator.zig +++ b/lib/std/heap/general_purpose_allocator.zig @@ -512,7 +512,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { var buckets = &self.buckets[bucket_index]; const slot_count = @divExact(page_size, size_class); if (self.cur_buckets[bucket_index] == null or self.cur_buckets[bucket_index].?.alloc_cursor == slot_count) { - var new_bucket = try self.createBucket(size_class); + const new_bucket = try self.createBucket(size_class); errdefer self.freeBucket(new_bucket, size_class); const node = try self.bucket_node_pool.create(); node.key = new_bucket; @@ -526,7 +526,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { const slot_index = bucket.alloc_cursor; bucket.alloc_cursor += 1; - var used_bits_byte = bucket.usedBits(slot_index / 8); + const used_bits_byte = bucket.usedBits(slot_index / 8); const used_bit_index: u3 = @as(u3, @intCast(slot_index % 8)); // TODO cast should be unnecessary used_bits_byte.* |= (@as(u8, 1) << used_bit_index); bucket.used_count += 1; @@ -915,7 +915,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { if (bucket.used_count == 0) { var entry = self.buckets[bucket_index].getEntryFor(bucket); // save the node for destruction/insertion into in empty_buckets - var node = entry.node.?; + const node = entry.node.?; entry.set(null); if (self.cur_buckets[bucket_index] == bucket) { self.cur_buckets[bucket_index] = null; diff --git a/lib/std/heap/memory_pool.zig b/lib/std/heap/memory_pool.zig index 722bdd8f3ee44b949f8d1b44d6cd7d0057ed70b3..af86adacc1b6cc9ffa4d75e24fb5951a22b8f3c1 100644 --- a/lib/std/heap/memory_pool.zig +++ b/lib/std/heap/memory_pool.zig @@ -172,7 +172,7 @@ test "memory pool: preheating (success)" { } test "memory pool: preheating (failure)" { - var failer = std.testing.failing_allocator; + const failer = std.testing.failing_allocator; try std.testing.expectError(error.OutOfMemory, MemoryPool(u32).initPreheated(failer, 5)); } diff --git a/lib/std/http/Client.zig b/lib/std/http/Client.zig index eb9896d40abd4407484da24c9b5f470ea16649b2..9b66975a09b9ea3111a965a0cad57f9ce8b625b6 100644 --- a/lib/std/http/Client.zig +++ b/lib/std/http/Client.zig @@ -144,7 +144,7 @@ pub const ConnectionPool = struct { pool.mutex.lock(); defer pool.mutex.unlock(); - var next = pool.free.first; + const next = pool.free.first; _ = next; while (pool.free_len > new_size) { const popped = pool.free.popFirst() orelse unreachable; diff --git a/lib/std/http/protocol.zig b/lib/std/http/protocol.zig index 4fe9c80380b20de35f3faa6ac8664863b366f252..e7570958039cb629d5a271a037bd00df4e1826ea 100644 --- a/lib/std/http/protocol.zig +++ b/lib/std/http/protocol.zig @@ -765,10 +765,9 @@ test "HeadersParser.read length" { var r = HeadersParser.initDynamic(256); defer r.header_bytes.deinit(std.testing.allocator); const data = "GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 5\r\n\r\nHello"; - var fbs = std.io.fixedBufferStream(data); - var conn = MockBufferedConnection{ - .conn = fbs, + var conn: MockBufferedConnection = .{ + .conn = std.io.fixedBufferStream(data), }; while (true) { // read headers @@ -796,10 +795,9 @@ test "HeadersParser.read chunked" { var r = HeadersParser.initDynamic(256); defer r.header_bytes.deinit(std.testing.allocator); 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"; - var fbs = std.io.fixedBufferStream(data); - var conn = MockBufferedConnection{ - .conn = fbs, + var conn: MockBufferedConnection = .{ + .conn = std.io.fixedBufferStream(data), }; while (true) { // read headers @@ -826,10 +824,9 @@ test "HeadersParser.read chunked trailer" { var r = HeadersParser.initDynamic(256); defer r.header_bytes.deinit(std.testing.allocator); 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"; - var fbs = std.io.fixedBufferStream(data); - var conn = MockBufferedConnection{ - .conn = fbs, + var conn: MockBufferedConnection = .{ + .conn = std.io.fixedBufferStream(data), }; while (true) { // read headers diff --git a/lib/std/io/Reader/test.zig b/lib/std/io/Reader/test.zig index 42fce984570537ba1dac8d8c42ffa3ed5989bfcc..166a94fbcf7dcdf789c37662859a9173f27592f5 100644 --- a/lib/std/io/Reader/test.zig +++ b/lib/std/io/Reader/test.zig @@ -91,13 +91,13 @@ test "Reader.readUntilDelimiterAlloc returns ArrayLists with bytes read until th const reader = fis.reader(); { - var result = try reader.readUntilDelimiterAlloc(a, '\n', 5); + const result = try reader.readUntilDelimiterAlloc(a, '\n', 5); defer a.free(result); try std.testing.expectEqualStrings("0000", result); } { - var result = try reader.readUntilDelimiterAlloc(a, '\n', 5); + const result = try reader.readUntilDelimiterAlloc(a, '\n', 5); defer a.free(result); try std.testing.expectEqualStrings("1234", result); } @@ -112,7 +112,7 @@ test "Reader.readUntilDelimiterAlloc returns an empty ArrayList" { const reader = fis.reader(); { - var result = try reader.readUntilDelimiterAlloc(a, '\n', 5); + const result = try reader.readUntilDelimiterAlloc(a, '\n', 5); defer a.free(result); try std.testing.expectEqualStrings("", result); } @@ -126,7 +126,7 @@ test "Reader.readUntilDelimiterAlloc returns StreamTooLong, then an ArrayList wi try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterAlloc(a, '\n', 5)); - var result = try reader.readUntilDelimiterAlloc(a, '\n', 5); + const result = try reader.readUntilDelimiterAlloc(a, '\n', 5); defer a.free(result); try std.testing.expectEqualStrings("67", result); } @@ -219,13 +219,13 @@ test "Reader.readUntilDelimiterOrEofAlloc returns ArrayLists with bytes read unt const reader = fis.reader(); { - var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; + const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; defer a.free(result); try std.testing.expectEqualStrings("0000", result); } { - var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; + const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; defer a.free(result); try std.testing.expectEqualStrings("1234", result); } @@ -240,7 +240,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns an empty ArrayList" { const reader = fis.reader(); { - var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; + const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; defer a.free(result); try std.testing.expectEqualStrings("", result); } @@ -254,7 +254,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns StreamTooLong, then an ArrayLi try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)); - var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; + const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?; defer a.free(result); try std.testing.expectEqualStrings("67", result); } diff --git a/lib/std/io/buffered_reader.zig b/lib/std/io/buffered_reader.zig index efc1d78cc4cfc26208f2455ea1ff5f19da01f3ef..40a81e3956300b0539791ed0a62923678378632a 100644 --- a/lib/std/io/buffered_reader.zig +++ b/lib/std/io/buffered_reader.zig @@ -131,8 +131,9 @@ test "io.BufferedReader Block" { // len out == block { - var block_reader = BlockReader.init(block, 2); - var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader }; + var test_buf_reader: BufferedReader(4, BlockReader) = .{ + .unbuffered_reader = BlockReader.init(block, 2), + }; var out_buf: [4]u8 = undefined; _ = try test_buf_reader.read(&out_buf); try testing.expectEqualSlices(u8, &out_buf, block); @@ -143,8 +144,9 @@ test "io.BufferedReader Block" { // len out < block { - var block_reader = BlockReader.init(block, 2); - var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader }; + var test_buf_reader: BufferedReader(4, BlockReader) = .{ + .unbuffered_reader = BlockReader.init(block, 2), + }; var out_buf: [3]u8 = undefined; _ = try test_buf_reader.read(&out_buf); try testing.expectEqualSlices(u8, &out_buf, "012"); @@ -157,8 +159,9 @@ test "io.BufferedReader Block" { // len out > block { - var block_reader = BlockReader.init(block, 2); - var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader }; + var test_buf_reader: BufferedReader(4, BlockReader) = .{ + .unbuffered_reader = BlockReader.init(block, 2), + }; var out_buf: [5]u8 = undefined; _ = try test_buf_reader.read(&out_buf); try testing.expectEqualSlices(u8, &out_buf, "01230"); @@ -169,8 +172,9 @@ test "io.BufferedReader Block" { // len out == 0 { - var block_reader = BlockReader.init(block, 2); - var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader }; + var test_buf_reader: BufferedReader(4, BlockReader) = .{ + .unbuffered_reader = BlockReader.init(block, 2), + }; var out_buf: [0]u8 = undefined; _ = try test_buf_reader.read(&out_buf); try testing.expectEqualSlices(u8, &out_buf, ""); @@ -178,8 +182,9 @@ test "io.BufferedReader Block" { // len bufreader buf > block { - var block_reader = BlockReader.init(block, 2); - var test_buf_reader = BufferedReader(5, BlockReader){ .unbuffered_reader = block_reader }; + var test_buf_reader: BufferedReader(5, BlockReader) = .{ + .unbuffered_reader = BlockReader.init(block, 2), + }; var out_buf: [4]u8 = undefined; _ = try test_buf_reader.read(&out_buf); try testing.expectEqualSlices(u8, &out_buf, block); diff --git a/lib/std/io/test.zig b/lib/std/io/test.zig index 6de0fe1e5387751ec7154a8fddcea9375e9afe39..c02446e53f84f58da6c330bcb19b3cd60d686042 100644 --- a/lib/std/io/test.zig +++ b/lib/std/io/test.zig @@ -167,13 +167,13 @@ test "updateTimes" { file.close(); tmp.dir.deleteFile(tmp_file_name) catch {}; } - var stat_old = try file.stat(); + const stat_old = try file.stat(); // Set atime and mtime to 5s before try file.updateTimes( stat_old.atime - 5 * std.time.ns_per_s, stat_old.mtime - 5 * std.time.ns_per_s, ); - var stat_new = try file.stat(); + const stat_new = try file.stat(); try expect(stat_new.atime < stat_old.atime); try expect(stat_new.mtime < stat_old.mtime); } diff --git a/lib/std/json/dynamic_test.zig b/lib/std/json/dynamic_test.zig index 326c00e9b68cad728ebc492c90eecf667829fadb..1e9f35eaf995a2433917e3e946412267a26b8618 100644 --- a/lib/std/json/dynamic_test.zig +++ b/lib/std/json/dynamic_test.zig @@ -190,15 +190,15 @@ test "Value.jsonStringify" { var obj = ObjectMap.init(testing.allocator); defer obj.deinit(); try obj.putNoClobber("a", .{ .string = "b" }); - var array = [_]Value{ - Value.null, - Value{ .bool = true }, - Value{ .integer = 42 }, - Value{ .number_string = "43" }, - Value{ .float = 42 }, - Value{ .string = "weeee" }, - Value{ .array = Array.fromOwnedSlice(undefined, &vals) }, - Value{ .object = obj }, + const array = [_]Value{ + .null, + .{ .bool = true }, + .{ .integer = 42 }, + .{ .number_string = "43" }, + .{ .float = 42 }, + .{ .string = "weeee" }, + .{ .array = Array.fromOwnedSlice(undefined, &vals) }, + .{ .object = obj }, }; var buffer: [0x1000]u8 = undefined; var fbs = std.io.fixedBufferStream(&buffer); diff --git a/lib/std/json/static_test.zig b/lib/std/json/static_test.zig index 82b0d89044939e69cb05ec52c62c7cc1f1689434..e3d296584c4c5d343a4576511df34b0f7489bc94 100644 --- a/lib/std/json/static_test.zig +++ b/lib/std/json/static_test.zig @@ -533,7 +533,7 @@ test "parse into struct with misc fields" { string: []const u8, }; }; - var document_str = + const document_str = \\{ \\ "int": 420, \\ "float": 3.14, @@ -588,7 +588,7 @@ test "parse into struct with strings and arrays with sentinels" { data: [:99]const i32, simple_data: []const i32, }; - var document_str = + const document_str = \\{ \\ "language": "zig", \\ "language_without_sentinel": "zig again!", @@ -634,7 +634,7 @@ test "parse into struct ignoring unknown fields" { language: []const u8, }; - var str = + const str = \\{ \\ "int": 420, \\ "float": 3.14, @@ -685,7 +685,7 @@ test "parse into tuple" { std.meta.Tuple(&.{ u8, []const u8, u8 }), Union, }); - var str = + const str = \\[ \\ 420, \\ 3.14, @@ -789,7 +789,7 @@ test "parse into vector" { vec_i32: @Vector(4, i32), vec_f32: @Vector(2, f32), }; - var s = + const s = \\{ \\ "vec_f32": [1.5, 2.5], \\ "vec_i32": [4, 5, 6, 7] @@ -821,7 +821,7 @@ test "json parse partial" { num: u32, yes: bool, }; - var str = + const str = \\{ \\ "outer": { \\ "key1": { @@ -835,7 +835,7 @@ test "json parse partial" { \\ } \\} ; - var allocator = testing.allocator; + const allocator = testing.allocator; var scanner = JsonScanner.initCompleteInput(allocator, str); defer scanner.deinit(); @@ -876,13 +876,13 @@ test "json parse allocate when streaming" { not_const: []u8, is_const: []const u8, }; - var str = + const str = \\{ \\ "not_const": "non const string", \\ "is_const": "const string" \\} ; - var allocator = testing.allocator; + const allocator = testing.allocator; var arena = ArenaAllocator.init(allocator); defer arena.deinit(); diff --git a/lib/std/math.zig b/lib/std/math.zig index 57471e2b03a105715bf12af06bc95fc39b3a8db4..1710cdc9480eb0182ac5036408ccabb51e8f9efe 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -427,6 +427,7 @@ test "clamp" { // Mix of comptime and non-comptime var i: i32 = 1; + _ = &i; try testing.expect(std.math.clamp(i, 0, 1) == 1); } @@ -1113,7 +1114,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) { comptime assert(info.signedness == .unsigned); const PromotedType = std.meta.Int(info.signedness, info.bits + 1); const overflowBit = @as(PromotedType, 1) << info.bits; - var x = ceilPowerOfTwoPromote(T, value); + const x = ceilPowerOfTwoPromote(T, value); if (overflowBit & x != 0) { return error.Overflow; } diff --git a/lib/std/math/atan.zig b/lib/std/math/atan.zig index bf85bdab7e9c41055ece441dc812e20d8071920c..0e7a86df60b7cb6678f13b073dcce953419c9655 100644 --- a/lib/std/math/atan.zig +++ b/lib/std/math/atan.zig @@ -143,8 +143,8 @@ fn atan64(x_: f64) f64 { }; var x = x_; - var ux = @as(u64, @bitCast(x)); - var ix = @as(u32, @intCast(ux >> 32)); + const ux: u64 = @bitCast(x); + var ix: u32 = @intCast(ux >> 32); const sign = ix >> 31; ix &= 0x7FFFFFFF; diff --git a/lib/std/math/atan2.zig b/lib/std/math/atan2.zig index b3ed7b7bcafdbd1077113300652f20b3b792f80e..93b1b88f32d5ebf968ddaeb63608464472837eb1 100644 --- a/lib/std/math/atan2.zig +++ b/lib/std/math/atan2.zig @@ -104,7 +104,7 @@ fn atan2_32(y: f32, x: f32) f32 { } // z = atan(|y / x|) with correct underflow - var z = z: { + const z = z: { if ((m & 2) != 0 and iy + (26 << 23) < ix) { break :z 0.0; } else { @@ -129,13 +129,13 @@ fn atan2_64(y: f64, x: f64) f64 { return x + y; } - var ux = @as(u64, @bitCast(x)); - var ix = @as(u32, @intCast(ux >> 32)); - var lx = @as(u32, @intCast(ux & 0xFFFFFFFF)); + const ux: u64 = @bitCast(x); + var ix: u32 = @intCast(ux >> 32); + const lx: u32 = @intCast(ux & 0xFFFFFFFF); - var uy = @as(u64, @bitCast(y)); - var iy = @as(u32, @intCast(uy >> 32)); - var ly = @as(u32, @intCast(uy & 0xFFFFFFFF)); + const uy: u64 = @bitCast(y); + var iy: u32 = @intCast(uy >> 32); + const ly: u32 = @intCast(uy & 0xFFFFFFFF); // x = 1.0 if ((ix -% 0x3FF00000) | lx == 0) { @@ -194,7 +194,7 @@ fn atan2_64(y: f64, x: f64) f64 { } // z = atan(|y / x|) with correct underflow - var z = z: { + const z = z: { if ((m & 2) != 0 and iy +% (64 << 20) < ix) { break :z 0.0; } else { diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index 346da746d04b7122d8ee630676f6de668c2a3451..f02ef18246518c39cba768a4b7d355add816cb3e 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -797,7 +797,7 @@ pub const Mutable = struct { // 0b0..01..1000 with @log2(@sizeOf(Limb)) consecutive ones const endian_mask: usize = (@sizeOf(Limb) - 1) << 3; - var bytes = std.mem.sliceAsBytes(r.limbs); + const bytes = std.mem.sliceAsBytes(r.limbs); var bits = std.packed_int_array.PackedIntSliceEndian(u1, .little).init(bytes, limbs_required * @bitSizeOf(Limb)); var k: usize = 0; @@ -1407,7 +1407,7 @@ pub const Mutable = struct { } // Avoid copying u to s by swapping u and s - var tmp_s = s; + const tmp_s = s; s = u; u = tmp_s; } @@ -1911,7 +1911,7 @@ pub const Mutable = struct { var positive = true; if (signedness == .signed) { const total_bits = bit_offset + bit_count; - var last_byte = switch (endian) { + const last_byte = switch (endian) { .little => ((total_bits + 7) / 8) - 1, .big => buffer.len - ((total_bits + 7) / 8), }; @@ -3161,7 +3161,7 @@ pub const Managed = struct { /// r = a ^ b pub fn bitXor(r: *Managed, a: *const Managed, b: *const Managed) !void { - var cap = @max(a.len(), b.len()) + @intFromBool(a.isPositive() != b.isPositive()); + const cap = @max(a.len(), b.len()) + @intFromBool(a.isPositive() != b.isPositive()); try r.ensureCapacity(cap); var m = r.toMutable(); @@ -4178,7 +4178,7 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void { // most significant bit set. // Square the result if the current bit is zero, square and multiply by a if // it is one. - var exp_bits = 32 - 1 - b_leading_zeros; + const exp_bits = 32 - 1 - b_leading_zeros; var exp = b << @as(u5, @intCast(1 + b_leading_zeros)); var i: usize = 0; diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig index a925f2c4b22e469c5756ffa7c7a5c769c1beb611..e1f423e3c15dfd258fa7e012cfd8b489416147a0 100644 --- a/lib/std/math/big/int_test.zig +++ b/lib/std/math/big/int_test.zig @@ -300,20 +300,18 @@ test "big.int twos complement limit set" { }; inline for (test_types) |T| { - // To work around 'control flow attempts to use compile-time variable at runtime' - const U = T; - const int_info = @typeInfo(U).Int; + const int_info = @typeInfo(T).Int; var a = try Managed.init(testing.allocator); defer a.deinit(); try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits); - var max: U = maxInt(U); - try testing.expect(max == try a.to(U)); + const max: T = maxInt(T); + try testing.expect(max == try a.to(T)); try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits); - var min: U = minInt(U); - try testing.expect(min == try a.to(U)); + const min: T = minInt(T); + try testing.expect(min == try a.to(T)); } } @@ -519,6 +517,9 @@ test "big.int add multi-single" { test "big.int add multi-multi" { var op1: u128 = 0xefefefef7f7f7f7f; var op2: u128 = 0xfefefefe9f9f9f9f; + // These must be runtime-known to prevent this comparison being tautological, as the + // compiler uses `std.math.big.int` internally to add these values at comptime. + _ = .{ &op1, &op2 }; var a = try Managed.initSet(testing.allocator, op1); defer a.deinit(); var b = try Managed.initSet(testing.allocator, op2); @@ -833,6 +834,7 @@ test "big.int sub multi-single" { test "big.int sub multi-multi" { var op1: u128 = 0xefefefefefefefefefefefef; var op2: u128 = 0xabababababababababababab; + _ = .{ &op1, &op2 }; var a = try Managed.initSet(testing.allocator, op1); defer a.deinit(); @@ -920,6 +922,8 @@ test "big.int mul multi-multi" { var op1: u256 = 0x998888efefefefefefefef; var op2: u256 = 0x333000abababababababab; + _ = .{ &op1, &op2 }; + var a = try Managed.initSet(testing.allocator, op1); defer a.deinit(); var b = try Managed.initSet(testing.allocator, op2); @@ -1042,6 +1046,8 @@ test "big.int mulWrap multi-multi unsigned" { var op1: u256 = 0x998888efefefefefefefef; var op2: u256 = 0x333000abababababababab; + _ = .{ &op1, &op2 }; + var a = try Managed.initSet(testing.allocator, op1); defer a.deinit(); var b = try Managed.initSet(testing.allocator, op2); @@ -1164,6 +1170,7 @@ test "big.int div single-single with rem" { test "big.int div multi-single no rem" { var op1: u128 = 0xffffeeeeddddcccc; var op2: u128 = 34; + _ = .{ &op1, &op2 }; var a = try Managed.initSet(testing.allocator, op1); defer a.deinit(); @@ -1183,6 +1190,7 @@ test "big.int div multi-single no rem" { test "big.int div multi-single with rem" { var op1: u128 = 0xffffeeeeddddcccf; var op2: u128 = 34; + _ = .{ &op1, &op2 }; var a = try Managed.initSet(testing.allocator, op1); defer a.deinit(); @@ -1202,6 +1210,7 @@ test "big.int div multi-single with rem" { test "big.int div multi>2-single" { var op1: u128 = 0xfefefefefefefefefefefefefefefefe; var op2: u128 = 0xefab8; + _ = .{ &op1, &op2 }; var a = try Managed.initSet(testing.allocator, op1); defer a.deinit(); @@ -2106,6 +2115,8 @@ test "big.int sat shift-left signed multi positive" { if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; var x: SignedDoubleLimb = 1; + _ = &x; + const shift = @bitSizeOf(SignedDoubleLimb) - 1; var a = try Managed.initSet(testing.allocator, x); @@ -2119,6 +2130,8 @@ test "big.int sat shift-left signed multi negative" { if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; var x: SignedDoubleLimb = -1; + _ = &x; + const shift = @bitSizeOf(SignedDoubleLimb) - 1; var a = try Managed.initSet(testing.allocator, x); @@ -2130,6 +2143,8 @@ test "big.int sat shift-left signed multi negative" { test "big.int bitNotWrap unsigned simple" { var x: u10 = 123; + _ = &x; + var a = try Managed.initSet(testing.allocator, x); defer a.deinit(); @@ -2149,6 +2164,8 @@ test "big.int bitNotWrap unsigned multi" { test "big.int bitNotWrap signed simple" { var x: i11 = -456; + _ = &x; + var a = try Managed.initSet(testing.allocator, -456); defer a.deinit(); @@ -2306,6 +2323,8 @@ test "big.int bitwise xor simple" { test "big.int bitwise xor multi-limb" { var x: DoubleLimb = maxInt(Limb) + 1; var y: DoubleLimb = maxInt(Limb); + _ = .{ &x, &y }; + var a = try Managed.initSet(testing.allocator, x); defer a.deinit(); var b = try Managed.initSet(testing.allocator, y); @@ -2548,7 +2567,7 @@ test "big.int gcd one large" { test "big.int mutable to managed" { const allocator = testing.allocator; - var limbs_buf = try allocator.alloc(Limb, 8); + const limbs_buf = try allocator.alloc(Limb, 8); defer allocator.free(limbs_buf); var a = Mutable.init(limbs_buf, 0xdeadbeef); @@ -2965,7 +2984,7 @@ test "big int conversion write twos complement zero" { // (2) should correctly interpret bytes based on the provided endianness // (3) should ignore any bits from bit_count to 8 * abi_size - var bit_count: usize = 12 * 8 + 1; + const bit_count: usize = 12 * 8 + 1; var buffer: []const u8 = undefined; buffer = &([_]u8{0} ** 13); diff --git a/lib/std/math/cbrt.zig b/lib/std/math/cbrt.zig index 22745ee4d57d6b38e4a6873bd91c9f8bd127d0ea..db0273eda8601ffc1e7faac69113452f02e853d4 100644 --- a/lib/std/math/cbrt.zig +++ b/lib/std/math/cbrt.zig @@ -102,7 +102,7 @@ fn cbrt64(x: f64) f64 { // cbrt to 23 bits // cbrt(x) = t * cbrt(x / t^3) ~= t * P(t^3 / x) - var r = (t * t) * (t / x); + const r = (t * t) * (t / x); t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4)); // Round t away from 0 to 23 bits @@ -113,7 +113,7 @@ fn cbrt64(x: f64) f64 { // one step newton to 53 bits const s = t * t; var q = x / s; - var w = t + t; + const w = t + t; q = (q - t) / (w + q); return t + t * q; diff --git a/lib/std/math/complex/atan.zig b/lib/std/math/complex/atan.zig index 381fc43f7d42b1d964a59db92edfb5a8bef58c41..b932b6d6247061801137de4386b3549752376f3f 100644 --- a/lib/std/math/complex/atan.zig +++ b/lib/std/math/complex/atan.zig @@ -55,7 +55,7 @@ fn atan32(z: Complex(f32)) Complex(f32) { } var t = 0.5 * math.atan2(f32, 2.0 * x, a); - var w = redupif32(t); + const w = redupif32(t); t = y - 1.0; a = x2 + t * t; @@ -104,7 +104,7 @@ fn atan64(z: Complex(f64)) Complex(f64) { } var t = 0.5 * math.atan2(f64, 2.0 * x, a); - var w = redupif64(t); + const w = redupif64(t); t = y - 1.0; a = x2 + t * t; diff --git a/lib/std/math/ilogb.zig b/lib/std/math/ilogb.zig index 735a2250c9fdbc38a198b23ba1493c0440766513..6f4bb131892e3c60262371cee7c0b14e02e20ddb 100644 --- a/lib/std/math/ilogb.zig +++ b/lib/std/math/ilogb.zig @@ -38,8 +38,8 @@ fn ilogbX(comptime T: type, x: T) i32 { const absMask = signBit - 1; - var u = @as(Z, @bitCast(x)) & absMask; - var e = @as(i32, @intCast(u >> significandBits)); + const u = @as(Z, @bitCast(x)) & absMask; + const e: i32 = @intCast(u >> significandBits); if (e == 0) { if (u == 0) { diff --git a/lib/std/math/log1p.zig b/lib/std/math/log1p.zig index 4cfdcecec935b0fc4cded9697db32fef91a53cd3..4545823ece6189994328b5266589878376db11d7 100644 --- a/lib/std/math/log1p.zig +++ b/lib/std/math/log1p.zig @@ -33,8 +33,8 @@ fn log1p_32(x: f32) f32 { const Lg3: f32 = 0x91e9ee.0p-25; const Lg4: f32 = 0xf89e26.0p-26; - const u = @as(u32, @bitCast(x)); - var ix = u; + const u: u32 = @bitCast(x); + const ix = u; var k: i32 = 1; var f: f32 = undefined; var c: f32 = undefined; @@ -112,8 +112,8 @@ fn log1p_64(x: f64) f64 { const Lg6: f64 = 1.531383769920937332e-01; const Lg7: f64 = 1.479819860511658591e-01; - var ix = @as(u64, @bitCast(x)); - var hx = @as(u32, @intCast(ix >> 32)); + const ix: u64 = @bitCast(x); + const hx: u32 = @intCast(ix >> 32); var k: i32 = 1; var c: f64 = undefined; var f: f64 = undefined; diff --git a/lib/std/math/sqrt.zig b/lib/std/math/sqrt.zig index 0dd5381cd9469183392423d47a222f9813ea78d6..b4a9ee3838bcd46d85332df00b69a734ce22b33a 100644 --- a/lib/std/math/sqrt.zig +++ b/lib/std/math/sqrt.zig @@ -50,7 +50,7 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) { } while (one != 0) { - var c = op >= res + one; + const c = op >= res + one; if (c) op -= res + one; res >>= 1; if (c) res += one; diff --git a/lib/std/mem.zig b/lib/std/mem.zig index 73fe2e77577caeeae38fe634defa95bda58d0fcd..bd0f8ca75454416764f48e7cef1c16058202779b 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -403,11 +403,11 @@ test "zeroes" { b: u32, }; - var c = zeroes(C_union); + const c = zeroes(C_union); try testing.expectEqual(@as(u8, 0), c.a); try testing.expectEqual(@as(u32, 0), c.b); - comptime var comptime_union = zeroes(C_union); + const comptime_union = comptime zeroes(C_union); try testing.expectEqual(@as(u8, 0), comptime_union.a); try testing.expectEqual(@as(u32, 0), comptime_union.b); @@ -3399,7 +3399,7 @@ test "reverseIterator" { try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*); try testing.expectEqual(@as(?*const i32, null), it.nextPtr()); - var mut_slice: []i32 = &array; + const mut_slice: []i32 = &array; var mut_it = reverseIterator(mut_slice); mut_it.nextPtr().?.* += 1; mut_it.nextPtr().?.* += 2; @@ -3419,7 +3419,7 @@ test "reverseIterator" { try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*); try testing.expectEqual(@as(?*const i32, null), it.nextPtr()); - var mut_ptr_to_array: *[2]i32 = &array; + const mut_ptr_to_array: *[2]i32 = &array; var mut_it = reverseIterator(mut_ptr_to_array); mut_it.nextPtr().?.* += 1; mut_it.nextPtr().?.* += 2; @@ -3581,7 +3581,7 @@ test "replacementSize" { /// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory. pub fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, needle: []const T, replacement: []const T) Allocator.Error![]T { - var output = try allocator.alloc(T, replacementSize(T, input, needle, replacement)); + const output = try allocator.alloc(T, replacementSize(T, input, needle, replacement)); _ = replace(T, input, needle, replacement, output); return output; } @@ -3693,8 +3693,8 @@ pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) { test "alignPointer" { const S = struct { fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void { - var ptr = @as(T, @ptrFromInt(base)); - var aligned = alignPointer(ptr, align_to); + const ptr: T = @ptrFromInt(base); + const aligned = alignPointer(ptr, align_to); try testing.expectEqual(expected, @intFromPtr(aligned)); } }; @@ -3848,7 +3848,7 @@ test "bytesAsValue" { .big => "\xC0\xDE\xFA\xCE", .little => "\xCE\xFA\xDE\xC0", }.*; - var codeface = bytesAsValue(u32, &codeface_bytes); + const codeface = bytesAsValue(u32, &codeface_bytes); try testing.expect(codeface.* == 0xC0DEFACE); codeface.* = 0; for (codeface_bytes) |b| @@ -3941,6 +3941,7 @@ test "bytesAsSlice" { { const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF }; var runtime_zero: usize = 0; + _ = &runtime_zero; const slice = bytesAsSlice(u16, bytes[runtime_zero..]); try testing.expect(slice.len == 2); try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD); @@ -3957,6 +3958,7 @@ test "bytesAsSlice keeps pointer alignment" { { var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 }; var runtime_zero: usize = 0; + _ = &runtime_zero; const numbers = bytesAsSlice(u32, bytes[runtime_zero..]); try comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32); } @@ -3967,8 +3969,8 @@ test "bytesAsSlice on a packed struct" { a: u8, }; - var b = [1]u8{9}; - var f = bytesAsSlice(F, &b); + const b: [1]u8 = .{9}; + const f = bytesAsSlice(F, &b); try testing.expect(f[0].a == 9); } @@ -4120,8 +4122,7 @@ pub const alignForwardGeneric = @compileError("renamed to alignForward"); /// result eventually gets discarded. // TODO: use @declareSideEffect() when it is available - https://github.com/ziglang/zig/issues/6168 pub fn doNotOptimizeAway(val: anytype) void { - var a: u8 = 0; - if (@typeInfo(@TypeOf(.{a})).Struct.fields[0].is_comptime) return; + if (@inComptime()) return; const max_gp_register_bits = @bitSizeOf(c_long); const t = @typeInfo(@TypeOf(val)); diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 75dee47fa7c6f36c1e3908058978267d40e1f860..827b8f847cb11de3962e65212520418b7daedffa 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -738,7 +738,7 @@ test "std.meta.TagPayload" { }, }; const MovedEvent = TagPayload(Event, Event.Moved); - var e: Event = undefined; + const e: Event = .{ .Moved = undefined }; try testing.expect(MovedEvent == @TypeOf(e.Moved)); } @@ -839,9 +839,9 @@ test "std.meta.eql" { try testing.expect(eql(u_1, u_3)); try testing.expect(!eql(u_1, u_2)); - var a1 = "abcdef".*; - var a2 = "abcdef".*; - var a3 = "ghijkl".*; + const a1 = "abcdef".*; + const a2 = "abcdef".*; + const a3 = "ghijkl".*; try testing.expect(eql(a1, a2)); try testing.expect(!eql(a1, a3)); @@ -859,9 +859,9 @@ test "std.meta.eql" { try testing.expect(!eql(EU.tst(false), EU.tst(true))); const V = @Vector(4, u32); - var v1: V = @splat(1); - var v2: V = @splat(1); - var v3: V = @splat(2); + const v1: V = @splat(1); + const v2: V = @splat(1); + const v3: V = @splat(2); try testing.expect(eql(v1, v2)); try testing.expect(!eql(v1, v3)); @@ -879,6 +879,8 @@ test "intToEnum with error return" { var zero: u8 = 0; var one: u16 = 1; + _ = &zero; + _ = &one; try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A); try testing.expect(intToEnum(E2, one) catch unreachable == E2.B); try testing.expect(intToEnum(E3, zero) catch unreachable == E3.A); diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig index e00fac261cbfedda87be8831d5e3c33166ef9a52..3d3a1099faa429d6dd3a238f09187c2ba0d711db 100644 --- a/lib/std/meta/trait.zig +++ b/lib/std/meta/trait.zig @@ -225,6 +225,7 @@ test "isSingleItemPtr" { try comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0]))); try comptime testing.expect(!isSingleItemPtr(@TypeOf(array))); var runtime_zero: usize = 0; + _ = &runtime_zero; try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1]))); } @@ -253,6 +254,7 @@ pub fn isSlice(comptime T: type) bool { test "isSlice" { const array = [_]u8{0} ** 10; var runtime_zero: usize = 0; + _ = &runtime_zero; try testing.expect(isSlice(@TypeOf(array[runtime_zero..]))); try testing.expect(!isSlice(@TypeOf(array))); try testing.expect(!isSlice(@TypeOf(&array[0]))); @@ -341,8 +343,9 @@ pub fn isConstPtr(comptime T: type) bool { } test "isConstPtr" { - var t = @as(u8, 0); - const c = @as(u8, 0); + var t: u8 = 0; + t = t; + const c: u8 = 0; try testing.expect(isConstPtr(*const @TypeOf(t))); try testing.expect(isConstPtr(@TypeOf(&c))); try testing.expect(!isConstPtr(*@TypeOf(t))); diff --git a/lib/std/net.zig b/lib/std/net.zig index 9e32fe613fdd9dce105cec9665f669c4f6963b82..7e15effe54f00513c85342b9166c7fa0d9423173 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -662,7 +662,7 @@ pub fn connectUnixSocket(path: []const u8) !Stream { fn if_nametoindex(name: []const u8) !u32 { if (builtin.target.os.tag == .linux) { var ifr: os.ifreq = undefined; - var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0); + const sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0); defer os.closeSocket(sockfd); @memcpy(ifr.ifrn.name[0..name.len], name); @@ -1375,7 +1375,7 @@ fn linuxLookupNameFromDns( rc: ResolvConf, port: u16, ) !void { - var ctx = dpc_ctx{ + const ctx = dpc_ctx{ .addrs = addrs, .canon = canon, .port = port, @@ -1591,8 +1591,8 @@ fn resMSendRc( }}; const retry_interval = timeout / attempts; var next: u32 = 0; - var t2: u64 = @as(u64, @bitCast(std.time.milliTimestamp())); - var t0 = t2; + var t2: u64 = @bitCast(std.time.milliTimestamp()); + const t0 = t2; var t1 = t2 - retry_interval; var servfail_retry: usize = undefined; diff --git a/lib/std/net/test.zig b/lib/std/net/test.zig index 0fe53a7b9f70d9b475b753ccd01be881f3ff03f0..5e98ee2a4dae115c6bcde7dc6d8bf0a5162fcad7 100644 --- a/lib/std/net/test.zig +++ b/lib/std/net/test.zig @@ -33,12 +33,12 @@ test "parse and render IPv6 addresses" { "::ffff:123.5.123.5", }; for (ips, 0..) |ip, i| { - var addr = net.Address.parseIp6(ip, 0) catch unreachable; + const addr = net.Address.parseIp6(ip, 0) catch unreachable; var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3])); if (builtin.os.tag == .linux) { - var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable; + const addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable; var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable; try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3])); } @@ -80,7 +80,7 @@ test "parse and render IPv4 addresses" { "123.255.0.91", "127.0.0.1", }) |ip| { - var addr = net.Address.parseIp4(ip, 0) catch unreachable; + const addr = net.Address.parseIp4(ip, 0) catch unreachable; var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; try std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2])); } @@ -303,10 +303,10 @@ test "listen on a unix socket, send bytes, receive bytes" { var server = net.StreamServer.init(.{}); defer server.deinit(); - var socket_path = try generateFileName("socket.unix"); + const socket_path = try generateFileName("socket.unix"); defer testing.allocator.free(socket_path); - var socket_addr = try net.Address.initUnix(socket_path); + const socket_addr = try net.Address.initUnix(socket_path); defer std.fs.cwd().deleteFile(socket_path) catch {}; try server.listen(socket_addr); diff --git a/lib/std/os.zig b/lib/std/os.zig index 1ae5157d8ba30f40b657bcf7c014e446c2e52144..cf388f76e95557bc57cdd7e7a015fd9474496b74 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -4642,7 +4642,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr const path_w = try windows.sliceToPrefixedFileW(dirfd, path); return faccessatW(dirfd, path_w.span().ptr, mode, flags); } else if (builtin.os.tag == .wasi and !builtin.link_libc) { - var resolved = RelativePathWasi{ .dir_fd = dirfd, .relative_path = path }; + const resolved = RelativePathWasi{ .dir_fd = dirfd, .relative_path = path }; const file = blk: { break :blk fstatat(dirfd, path, flags); @@ -4775,7 +4775,7 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t { } } - var fds: [2]fd_t = try pipe(); + const fds: [2]fd_t = try pipe(); errdefer { close(fds[0]); close(fds[1]); @@ -6709,7 +6709,7 @@ pub fn dn_expand( // loop invariants: p= msg.len) return error.InvalidDnsPacket; p = msg.ptr + j; @@ -7285,7 +7285,7 @@ pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError; pub const TimerFdSetError = TimerFdGetError || error{Canceled}; pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t { - var rc = linux.timerfd_create(clokid, flags); + const rc = linux.timerfd_create(clokid, flags); return switch (errno(rc)) { .SUCCESS => @as(fd_t, @intCast(rc)), .INVAL => unreachable, @@ -7299,7 +7299,7 @@ pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t { } pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec, old_value: ?*linux.itimerspec) TimerFdSetError!void { - var rc = linux.timerfd_settime(fd, flags, new_value, old_value); + const rc = linux.timerfd_settime(fd, flags, new_value, old_value); return switch (errno(rc)) { .SUCCESS => {}, .BADF => error.InvalidHandle, @@ -7312,7 +7312,7 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec, pub fn timerfd_gettime(fd: i32) TimerFdGetError!linux.itimerspec { var curr_value: linux.itimerspec = undefined; - var rc = linux.timerfd_gettime(fd, &curr_value); + const rc = linux.timerfd_gettime(fd, &curr_value); return switch (errno(rc)) { .SUCCESS => return curr_value, .BADF => error.InvalidHandle, diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 9163eb98a9d06dd4880a3634e398b40b5027ecdc..97ad9525620d88756eb9c7cd23c5176ffcfe794d 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -1326,6 +1326,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize next_unsent = i + 1; break; } + size += iov.iov_len; } } if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR) diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index 3b282422aebb676b617864a8220e9a2c97be9404..2219d9583293317b33fb5647dd8c18d379675f4d 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -137,7 +137,7 @@ pub const IO_Uring = struct { // We must therefore use wrapping addition and subtraction to avoid a runtime crash. const next = self.sq.sqe_tail +% 1; if (next -% head > self.sq.sqes.len) return error.SubmissionQueueFull; - var sqe = &self.sq.sqes[self.sq.sqe_tail & self.sq.mask]; + const sqe = &self.sq.sqes[self.sq.sqe_tail & self.sq.mask]; self.sq.sqe_tail = next; return sqe; } @@ -279,7 +279,7 @@ pub const IO_Uring = struct { const ready = self.cq_ready(); const count = @min(cqes.len, ready); var head = self.cq.head.*; - var tail = head +% count; + const tail = head +% count; // TODO Optimize this by using 1 or 2 memcpy's (if the tail wraps) rather than a loop. var i: usize = 0; // Do not use "less-than" operator since head and tail may wrap: @@ -1916,7 +1916,7 @@ test "splice/read" { var buffer_read = [_]u8{98} ** 20; _ = try file_src.write(&buffer_write); - var fds = try os.pipe(); + const fds = try os.pipe(); const pipe_offset: u64 = std.math.maxInt(u64); 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" { // Workaround for LLVM bug: https://github.com/ziglang/zig/issues/12014 const path_addr = if (builtin.zig_backend == .stage2_llvm) p: { var workaround = path; + _ = &workaround; break :p @intFromPtr(workaround); } else @intFromPtr(path); @@ -2199,7 +2200,7 @@ test "sendmsg/recvmsg" { var iovecs_recv = [_]os.iovec{ os.iovec{ .iov_base = &buffer_recv, .iov_len = buffer_recv.len }, }; - var addr = [_]u8{0} ** 4; + const addr = [_]u8{0} ** 4; var address_recv = net.Address.initIp4(addr, 0); var msg_recv: os.msghdr = os.msghdr{ .name = &address_recv.any, @@ -2676,7 +2677,7 @@ test "shutdown" { var slen: os.socklen_t = address.getOsSockLen(); try os.getsockname(server, &address.any, &slen); - var shutdown_sqe = try ring.shutdown(0x445445445, server, os.linux.SHUT.RD); + const shutdown_sqe = try ring.shutdown(0x445445445, server, os.linux.SHUT.RD); try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode); try testing.expectEqual(@as(i32, server), shutdown_sqe.fd); @@ -2702,7 +2703,7 @@ test "shutdown" { const server = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); defer os.close(server); - var shutdown_sqe = ring.shutdown(0x445445445, server, os.linux.SHUT.RD) catch |err| switch (err) { + const shutdown_sqe = ring.shutdown(0x445445445, server, os.linux.SHUT.RD) catch |err| switch (err) { else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), }; try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode); @@ -2740,7 +2741,7 @@ test "renameat" { // Submit renameat - var sqe = try ring.renameat( + const sqe = try ring.renameat( 0x12121212, tmp.dir.fd, old_path, @@ -2807,7 +2808,7 @@ test "unlinkat" { // Submit unlinkat - var sqe = try ring.unlinkat( + const sqe = try ring.unlinkat( 0x12121212, tmp.dir.fd, path, @@ -2854,7 +2855,7 @@ test "mkdirat" { // Submit mkdirat - var sqe = try ring.mkdirat( + const sqe = try ring.mkdirat( 0x12121212, tmp.dir.fd, path, @@ -2902,7 +2903,7 @@ test "symlinkat" { // Submit symlinkat - var sqe = try ring.symlinkat( + const sqe = try ring.symlinkat( 0x12121212, path, tmp.dir.fd, @@ -2953,7 +2954,7 @@ test "linkat" { // Submit linkat - var sqe = try ring.linkat( + const sqe = try ring.linkat( 0x12121212, tmp.dir.fd, first_path, @@ -3032,7 +3033,7 @@ test "provide_buffers: read" { var i: usize = 0; while (i < buffers.len) : (i += 1) { - var sqe = try ring.read(0xdededede, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); + const sqe = try ring.read(0xdededede, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); try testing.expectEqual(@as(i32, fd), sqe.fd); try testing.expectEqual(@as(u64, 0), sqe.addr); @@ -3058,7 +3059,7 @@ test "provide_buffers: read" { // This read should fail { - var sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); + const sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); try testing.expectEqual(@as(i32, fd), sqe.fd); try testing.expectEqual(@as(u64, 0), sqe.addr); @@ -3097,7 +3098,7 @@ test "provide_buffers: read" { // Final read which should work { - var sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); + const sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); try testing.expectEqual(@as(i32, fd), sqe.fd); try testing.expectEqual(@as(u64, 0), sqe.addr); @@ -3158,7 +3159,7 @@ test "remove_buffers" { // Remove 3 buffers { - var sqe = try ring.remove_buffers(0xbababababa, 3, group_id); + const sqe = try ring.remove_buffers(0xbababababa, 3, group_id); try testing.expectEqual(linux.IORING_OP.REMOVE_BUFFERS, sqe.opcode); try testing.expectEqual(@as(i32, 3), sqe.fd); try testing.expectEqual(@as(u64, 0), sqe.addr); @@ -3270,7 +3271,7 @@ test "provide_buffers: accept/connect/send/recv" { var i: usize = 0; while (i < buffers.len) : (i += 1) { - var sqe = try ring.recv(0xdededede, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); + const sqe = try ring.recv(0xdededede, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode); try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd); try testing.expectEqual(@as(u64, 0), sqe.addr); @@ -3299,7 +3300,7 @@ test "provide_buffers: accept/connect/send/recv" { // This recv should fail { - var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); + const sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode); try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd); try testing.expectEqual(@as(u64, 0), sqe.addr); @@ -3349,7 +3350,7 @@ test "provide_buffers: accept/connect/send/recv" { @memset(mem.sliceAsBytes(&buffers), 1); { - var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); + const sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0); try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode); try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd); try testing.expectEqual(@as(u64, 0), sqe.addr); @@ -3477,7 +3478,7 @@ test "accept multishot" { var nr: usize = 4; // number of clients to connect while (nr > 0) : (nr -= 1) { // connect client - var client = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); + const client = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); errdefer os.closeSocket(client); try os.connect(client, &address.any, address.getOsSockLen()); diff --git a/lib/std/os/plan9.zig b/lib/std/os/plan9.zig index 93341712213a36dd734e96f84b8d47413f9e0aba..b42fd52245879122e615e09ce997f01c5a33d07f 100644 --- a/lib/std/os/plan9.zig +++ b/lib/std/os/plan9.zig @@ -278,7 +278,7 @@ pub fn sbrk(n: usize) usize { bloc = @intFromPtr(&ExecData.end); bloc_max = @intFromPtr(&ExecData.end); } - var bl = std.mem.alignForward(usize, bloc, std.mem.page_size); + const bl = std.mem.alignForward(usize, bloc, std.mem.page_size); const n_aligned = std.mem.alignForward(usize, n, std.mem.page_size); if (bl + n_aligned > bloc_max) { // we need to allocate diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index f4a67f1035279b573aa0e770295734db9b7ec61e..40e0991e5fc884245e02c788e699e2b2d8a64519 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -58,7 +58,7 @@ test "chdir smoke test" { { // Create a tmp directory var tmp_dir_buf: [fs.MAX_PATH_BYTES]u8 = undefined; - var tmp_dir_path = path: { + const tmp_dir_path = path: { var allocator = std.heap.FixedBufferAllocator.init(&tmp_dir_buf); break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{ old_cwd, "zig-test-tmp" }); }; @@ -72,7 +72,7 @@ test "chdir smoke test" { // On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase var resolved_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined; - var resolved_cwd = path: { + const resolved_cwd = path: { var allocator = std.heap.FixedBufferAllocator.init(&resolved_cwd_buf); break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{new_cwd}); }; @@ -523,7 +523,7 @@ test "pipe" { if (native_os == .windows or native_os == .wasi) return error.SkipZigTest; - var fds = try os.pipe(); + const fds = try os.pipe(); try expect((try os.write(fds[1], "hello")) == 5); var buf: [16]u8 = undefined; try expect((try os.read(fds[0], buf[0..])) == 5); @@ -533,7 +533,7 @@ test "pipe" { } test "argsAlloc" { - var args = try std.process.argsAlloc(std.testing.allocator); + const args = try std.process.argsAlloc(std.testing.allocator); std.process.argsFree(std.testing.allocator, args); } @@ -1087,7 +1087,7 @@ test "timerfd" { return error.SkipZigTest; const linux = os.linux; - var tfd = try os.timerfd_create(linux.CLOCK.MONOTONIC, linux.TFD.CLOEXEC); + const tfd = try os.timerfd_create(linux.CLOCK.MONOTONIC, linux.TFD.CLOEXEC); defer os.close(tfd); // Fire event 10_000_000ns = 10ms after the os.timerfd_settime call. @@ -1097,8 +1097,8 @@ test "timerfd" { var fds: [1]os.pollfd = .{.{ .fd = tfd, .events = os.linux.POLL.IN, .revents = 0 }}; try expectEqual(@as(usize, 1), try os.poll(&fds, -1)); // -1 => infinite waiting - var git = try os.timerfd_gettime(tfd); - var expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } }; + const git = try os.timerfd_gettime(tfd); + const expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } }; try expectEqual(expect_disarmed_timer, git); } @@ -1128,11 +1128,11 @@ test "read with empty buffer" { break :blk try fs.realpathAlloc(allocator, relative_path); }; - var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); + const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); var file = try fs.cwd().createFile(file_path, .{ .read = true }); defer file.close(); - var bytes = try allocator.alloc(u8, 0); + const bytes = try allocator.alloc(u8, 0); _ = try os.read(file.handle, bytes); } @@ -1153,11 +1153,11 @@ test "pread with empty buffer" { break :blk try fs.realpathAlloc(allocator, relative_path); }; - var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); + const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); var file = try fs.cwd().createFile(file_path, .{ .read = true }); defer file.close(); - var bytes = try allocator.alloc(u8, 0); + const bytes = try allocator.alloc(u8, 0); _ = try os.pread(file.handle, bytes, 0); } @@ -1178,11 +1178,11 @@ test "write with empty buffer" { break :blk try fs.realpathAlloc(allocator, relative_path); }; - var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); + const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); var file = try fs.cwd().createFile(file_path, .{}); defer file.close(); - var bytes = try allocator.alloc(u8, 0); + const bytes = try allocator.alloc(u8, 0); _ = try os.write(file.handle, bytes); } @@ -1203,11 +1203,11 @@ test "pwrite with empty buffer" { break :blk try fs.realpathAlloc(allocator, relative_path); }; - var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); + const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); var file = try fs.cwd().createFile(file_path, .{}); defer file.close(); - var bytes = try allocator.alloc(u8, 0); + const bytes = try allocator.alloc(u8, 0); _ = try os.pwrite(file.handle, bytes, 0); } diff --git a/lib/std/os/uefi.zig b/lib/std/os/uefi.zig index 535b88a2620419b7f98e871d7b6622bb6edbf0ad..7ad01e58e79bd2ec9a9971af1653224014f4361f 100644 --- a/lib/std/os/uefi.zig +++ b/lib/std/os/uefi.zig @@ -149,11 +149,10 @@ pub const TimeCapabilities = extern struct { pub const FileHandle = *opaque {}; test "GUID formatting" { - var bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 }; + const bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 }; + const guid: Guid = @bitCast(bytes); - var guid = @as(Guid, @bitCast(bytes)); - - var str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid}); + const str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid}); defer std.testing.allocator.free(str); try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287")); diff --git a/lib/std/os/uefi/device_path.zig b/lib/std/os/uefi/device_path.zig index b15654e8a7aee4920ae73de25b73fa30108d5162..55a3763d66c138b1d404e84b2aba7cce626fe500 100644 --- a/lib/std/os/uefi/device_path.zig +++ b/lib/std/os/uefi/device_path.zig @@ -213,7 +213,7 @@ pub const DevicePath = union(Type) { // multiple adr entries can optionally follow pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 { // self.length is a minimum of 8 with one adr which is size 4. - var entries = (self.length - 4) / @sizeOf(u32); + const entries = (self.length - 4) / @sizeOf(u32); return @as([*]align(1) const u32, @ptrCast(&self.adr))[0..entries]; } }; @@ -431,7 +431,7 @@ pub const DevicePath = union(Type) { device_product_id: u16 align(1), pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 { - var serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16); + const serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16); return @as([*]align(1) const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(UsbWwidDevicePath)))[0..serial_len]; } }; diff --git a/lib/std/os/uefi/pool_allocator.zig b/lib/std/os/uefi/pool_allocator.zig index 3f64a2f3f64b6c79d3af6a273fa18721e02fa891..aa9798c6e5fb93bcd1542e475a0047a1142098aa 100644 --- a/lib/std/os/uefi/pool_allocator.zig +++ b/lib/std/os/uefi/pool_allocator.zig @@ -34,7 +34,7 @@ const UefiPoolAllocator = struct { const unaligned_addr = @intFromPtr(unaligned_ptr); const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), ptr_align); - var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); + const aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); getHeader(aligned_ptr).* = unaligned_ptr; return aligned_ptr; diff --git a/lib/std/os/uefi/protocol/device_path.zig b/lib/std/os/uefi/protocol/device_path.zig index 396398252dce61ee5b9fec9cc508416e464a131d..a08eee193cb6334ecdc477dbcf724c9be5f8f66b 100644 --- a/lib/std/os/uefi/protocol/device_path.zig +++ b/lib/std/os/uefi/protocol/device_path.zig @@ -43,7 +43,7 @@ pub const DevicePath = extern struct { /// Creates a file device path from the existing device path and a file path. pub fn create_file_device_path(self: *DevicePath, allocator: Allocator, path: [:0]align(1) const u16) !*DevicePath { - var path_size = self.size(); + const path_size = self.size(); // 2 * (path.len + 1) for the path and its null terminator, which are u16s // DevicePath for the extra node before the end @@ -82,8 +82,7 @@ pub const DevicePath = extern struct { // Got the associated union type for self.type, now // we need to initialize it and its subtype if (self.type == enum_value) { - var subtype = self.initSubtype(ufield.type); - + const subtype = self.initSubtype(ufield.type); if (subtype) |sb| { // e.g. return .{ .Hardware = .{ .Pci = @ptrCast(...) } } return @unionInit(uefi.DevicePath, ufield.name, sb); diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index b0c0ce5be0d693088cf3caf0982492e05df1232f..efc3f5574db27fa76792688df96e5fc7448dbe73 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -1166,7 +1166,7 @@ test "QueryObjectName" { const handle = tmp.dir.fd; var out_buffer: [PATH_MAX_WIDE]u16 = undefined; - var result_path = try QueryObjectName(handle, &out_buffer); + const result_path = try QueryObjectName(handle, &out_buffer); const required_len_in_u16 = result_path.len + @divExact(@intFromPtr(result_path.ptr) - @intFromPtr(&out_buffer), 2) + 1; //insufficient size 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 { }; while (true) { - var a_cp = a_utf8_it.nextCodepoint() orelse break; - var b_cp = b_utf8_it.nextCodepoint() orelse return false; + const a_cp = a_utf8_it.nextCodepoint() orelse break; + const b_cp = b_utf8_it.nextCodepoint() orelse return false; if (a_cp <= std.math.maxInt(u16) and b_cp <= std.math.maxInt(u16)) { if (a_cp != b_cp and upcaseImpl(@intCast(a_cp)) != upcaseImpl(@intCast(b_cp))) { diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig index acc8aa1ec7bf88746d512cc6b9e6e3a2368bc225..d0623145a06e3089d569b745bce7f41dab6e7b08 100644 --- a/lib/std/pdb.zig +++ b/lib/std/pdb.zig @@ -897,7 +897,7 @@ const Msf = struct { return error.UnhandledBigDirectoryStream; // cf. BlockMapAddr comment. try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr); - var dir_blocks = try allocator.alloc(u32, dir_block_count); + const dir_blocks = try allocator.alloc(u32, dir_block_count); for (dir_blocks) |*b| { b.* = try in.readInt(u32, .little); } diff --git a/lib/std/priority_dequeue.zig b/lib/std/priority_dequeue.zig index 31ae965286c7687b38b66341bc76d478c8b65cad..dc3981b65e3a82e367abf97c4c76322af627e528 100644 --- a/lib/std/priority_dequeue.zig +++ b/lib/std/priority_dequeue.zig @@ -82,8 +82,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar }; fn getStartForSiftUp(self: Self, child: T, index: usize) StartIndexAndLayer { - var child_index = index; - var parent_index = parentIndex(child_index); + const child_index = index; + const parent_index = parentIndex(child_index); const parent = self.items[parent_index]; const min_layer = self.nextIsMinLayer(); @@ -115,7 +115,7 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar fn doSiftUp(self: *Self, start_index: usize, target_order: Order) void { var child_index = start_index; while (child_index > 2) { - var grandparent_index = grandparentIndex(child_index); + const grandparent_index = grandparentIndex(child_index); const child = self.items[child_index]; const grandparent = self.items[grandparent_index]; @@ -286,8 +286,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar } fn bestItemAtIndices(self: Self, index1: usize, index2: usize, target_order: Order) ItemAndIndex { - var item1 = self.getItem(index1); - var item2 = self.getItem(index2); + const item1 = self.getItem(index1); + const item2 = self.getItem(index2); return self.bestItem(item1, item2, target_order); } diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig index a568eeadcf08b543b5a151d5fb021d1ed8799557..74f7cb68854dc2c08a01e9ec1002eeab083166ce 100644 --- a/lib/std/priority_queue.zig +++ b/lib/std/priority_queue.zig @@ -470,7 +470,7 @@ test "std.PriorityQueue: remove at index" { break idx; idx += 1; } else unreachable; - var sorted_items = [_]u32{ 1, 3, 4, 5, 8, 9 }; + const sorted_items = [_]u32{ 1, 3, 4, 5, 8, 9 }; try expectEqual(queue.removeIndex(two_idx), 2); var i: usize = 0; diff --git a/lib/std/process.zig b/lib/std/process.zig index 518def42159494068d0ac52b9394b2dfcf3179b3..d736fbe8df01fbe438db5d58c3e124159bc3264d 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -298,9 +298,9 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap { return result; } - var environ = try allocator.alloc([*:0]u8, environ_count); + const environ = try allocator.alloc([*:0]u8, environ_count); defer allocator.free(environ); - var environ_buf = try allocator.alloc(u8, environ_buf_size); + const environ_buf = try allocator.alloc(u8, environ_buf_size); defer allocator.free(environ_buf); 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 } test "os.getEnvVarOwned" { - var ga = std.testing.allocator; + const ga = std.testing.allocator; try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV")); } @@ -477,10 +477,10 @@ pub const ArgIteratorWasi = struct { return &[_][:0]u8{}; } - var argv = try allocator.alloc([*:0]u8, count); + const argv = try allocator.alloc([*:0]u8, count); defer allocator.free(argv); - var argv_buf = try allocator.alloc(u8, buf_size); + const argv_buf = try allocator.alloc(u8, buf_size); switch (w.args_get(argv.ptr, argv_buf.ptr)) { .SUCCESS => {}, @@ -551,7 +551,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { /// cmd_line_utf8 MUST remain valid and constant while using this instance pub fn init(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self { - var buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1); + const buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1); errdefer allocator.free(buffer); return Self{ @@ -564,7 +564,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { /// cmd_line_utf8 will be free'd (with the allocator) on deinit() pub fn initTakeOwnership(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self { - var buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1); + const buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1); errdefer allocator.free(buffer); return Self{ @@ -577,8 +577,8 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { /// cmd_line_utf16le MUST be encoded UTF16-LE, and is converted to UTF-8 in an internal buffer pub fn initUtf16le(allocator: Allocator, cmd_line_utf16le: [*:0]const u16) InitUtf16leError!Self { - var utf16le_slice = mem.sliceTo(cmd_line_utf16le, 0); - var cmd_line = std.unicode.utf16leToUtf8Alloc(allocator, utf16le_slice) catch |err| switch (err) { + const utf16le_slice = mem.sliceTo(cmd_line_utf16le, 0); + const cmd_line = std.unicode.utf16leToUtf8Alloc(allocator, utf16le_slice) catch |err| switch (err) { error.ExpectedSecondSurrogateHalf, error.DanglingSurrogateHalf, error.UnexpectedSecondSurrogateHalf, @@ -588,7 +588,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { }; errdefer allocator.free(cmd_line); - var buffer = try allocator.alloc(u8, cmd_line.len + 1); + const buffer = try allocator.alloc(u8, cmd_line.len + 1); errdefer allocator.free(buffer); return Self{ @@ -681,7 +681,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { 0 => { self.emitBackslashes(backslash_count); self.buffer[self.end] = 0; - var token = self.buffer[self.start..self.end :0]; + const token = self.buffer[self.start..self.end :0]; self.end += 1; self.start = self.end; return token; @@ -713,7 +713,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type { self.emitCharacter(character); } else { self.buffer[self.end] = 0; - var token = self.buffer[self.start..self.end :0]; + const token = self.buffer[self.start..self.end :0]; self.end += 1; self.start = self.end; return token; diff --git a/lib/std/rand/test.zig b/lib/std/rand/test.zig index d02c0163577e94c0a6a1517547ef0f10f02c4748..d498985097c4bec741e20cf803c4980dd37772a5 100644 --- a/lib/std/rand/test.zig +++ b/lib/std/rand/test.zig @@ -332,13 +332,13 @@ test "Random float chi-square goodness of fit" { while (i < num_numbers) : (i += 1) { const rand_f32 = random.float(f32); const rand_f64 = random.float(f64); - var f32_put = try f32_hist.getOrPut(@as(u32, @intFromFloat(rand_f32 * @as(f32, @floatFromInt(num_buckets))))); + const f32_put = try f32_hist.getOrPut(@as(u32, @intFromFloat(rand_f32 * @as(f32, @floatFromInt(num_buckets))))); if (f32_put.found_existing) { f32_put.value_ptr.* += 1; } else { f32_put.value_ptr.* = 1; } - var f64_put = try f64_hist.getOrPut(@as(u32, @intFromFloat(rand_f64 * @as(f64, @floatFromInt(num_buckets))))); + const f64_put = try f64_hist.getOrPut(@as(u32, @intFromFloat(rand_f64 * @as(f64, @floatFromInt(num_buckets))))); if (f64_put.found_existing) { f64_put.value_ptr.* += 1; } else { diff --git a/lib/std/sort.zig b/lib/std/sort.zig index e110a8beb8a08b78d7002b64bd5f4d227272c132..f354e80df61ba284a2efb2f892b90cc95723727b 100644 --- a/lib/std/sort.zig +++ b/lib/std/sort.zig @@ -387,7 +387,7 @@ test "sort fuzz testing" { var i: usize = 0; while (i < test_case_count) : (i += 1) { const array_size = random.intRangeLessThan(usize, 0, 1000); - var array = try testing.allocator.alloc(i32, array_size); + const array = try testing.allocator.alloc(i32, array_size); defer testing.allocator.free(array); // populate with random data for (array) |*item| { diff --git a/lib/std/sort/block.zig b/lib/std/sort/block.zig index fe6e62865327253714b52003f15d45e5dc3c73f8..4c94fb78adb6fde1582e0e806f84cfdfe88ec7a6 100644 --- a/lib/std/sort/block.zig +++ b/lib/std/sort/block.zig @@ -302,8 +302,8 @@ pub fn block( } else { iterator.begin(); while (!iterator.finished()) { - var A = iterator.nextRange(); - var B = iterator.nextRange(); + const A = iterator.nextRange(); + const B = iterator.nextRange(); if (lessThan(context, items[B.end - 1], items[A.start])) { // the two ranges are in reverse order, so a simple rotation should fix it diff --git a/lib/std/sort/pdq.zig b/lib/std/sort/pdq.zig index 0e1595b82c664ead542fb4bb252f4b96e404129e..d74c7788a4c14a31007f94e8e66dd22fff84eeb3 100644 --- a/lib/std/sort/pdq.zig +++ b/lib/std/sort/pdq.zig @@ -276,10 +276,10 @@ fn chosePivot(a: usize, b: usize, pivot: *usize, context: anytype) Hint { // max_swaps is the maximum number of swaps allowed in this function const max_swaps = 4 * 3; - var len = b - a; - var i = a + len / 4 * 1; - var j = a + len / 4 * 2; - var k = a + len / 4 * 3; + const len = b - a; + const i = a + len / 4 * 1; + const j = a + len / 4 * 2; + const k = a + len / 4 * 3; var swaps: usize = 0; if (len >= 8) { diff --git a/lib/std/tar.zig b/lib/std/tar.zig index bdbec87e39becb00eb47c28bd1b1897aaf169e38..15727fdebf379e1ec776747bc71641fd14fe8eab 100644 --- a/lib/std/tar.zig +++ b/lib/std/tar.zig @@ -218,7 +218,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi if (file_size == 0 and unstripped_file_name.len == 0) return; const file_name = try stripComponents(unstripped_file_name, options.strip_components); - var file = dir.createFile(file_name, .{}) catch |err| switch (err) { + const file = dir.createFile(file_name, .{}) catch |err| switch (err) { error.FileNotFound => again: { const code = code: { if (std.fs.path.dirname(file_name)) |dir_name| { diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 95f1b156c1376ae28543e7d453641ad58206dfa6..09507a2392da7930384383fe2344441f8995cb09 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -399,7 +399,7 @@ fn SliceDiffer(comptime T: type) type { pub fn write(self: Self, writer: anytype) !void { for (self.expected, 0..) |value, i| { - var full_index = self.start_index + i; + const full_index = self.start_index + i; const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true; if (diff) try self.ttyconf.setColor(writer, .red); if (@typeInfo(T) == .Pointer) { @@ -424,7 +424,7 @@ const BytesDiffer = struct { // to avoid having to calculate diffs twice per chunk var diffs: std.bit_set.IntegerBitSet(16) = .{ .mask = 0 }; for (chunk, 0..) |byte, i| { - var absolute_byte_index = (expected_iterator.index - chunk.len) + i; + const absolute_byte_index = (expected_iterator.index - chunk.len) + i; const diff = if (absolute_byte_index < self.actual.len) self.actual[absolute_byte_index] != byte else true; if (diff) diffs.set(i); try self.writeByteDiff(writer, "{X:0>2} ", byte, diff); @@ -565,13 +565,13 @@ pub fn tmpDir(opts: std.fs.Dir.OpenDirOptions) TmpDir { var sub_path: [TmpDir.sub_path_len]u8 = undefined; _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes); - var cwd = std.fs.cwd(); + const cwd = std.fs.cwd(); var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir"); defer cache_dir.close(); - var parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch + const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir"); - var dir = parent_dir.makeOpenPath(&sub_path, opts) catch + const dir = parent_dir.makeOpenPath(&sub_path, opts) catch @panic("unable to make tmp dir for testing: unable to make and open the tmp dir"); return .{ @@ -587,13 +587,13 @@ pub fn tmpIterableDir(opts: std.fs.Dir.OpenDirOptions) TmpIterableDir { var sub_path: [TmpIterableDir.sub_path_len]u8 = undefined; _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes); - var cwd = std.fs.cwd(); + const cwd = std.fs.cwd(); var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir"); defer cache_dir.close(); - var parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch + const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir"); - var dir = parent_dir.makeOpenPathIterable(&sub_path, opts) catch + const dir = parent_dir.makeOpenPathIterable(&sub_path, opts) catch @panic("unable to make tmp dir for testing: unable to make and open the tmp dir"); return .{ @@ -618,8 +618,8 @@ test "expectEqual nested array" { } test "expectEqual vector" { - var a: @Vector(4, u32) = @splat(4); - var b: @Vector(4, u32) = @splat(4); + const a: @Vector(4, u32) = @splat(4); + const b: @Vector(4, u32) = @splat(4); try expectEqual(a, b); } diff --git a/lib/std/treap.zig b/lib/std/treap.zig index 383dc1802a6a7a7124194050d3169c090d7e9d21..a555b494950cd3c0eb20cbc0d1fe8dfde20ea53b 100644 --- a/lib/std/treap.zig +++ b/lib/std/treap.zig @@ -379,7 +379,7 @@ test "std.Treap: insert, find, replace, remove" { const key = node.key; // find the entry by-key and by-node after having been inserted. - var entry = treap.getEntryFor(node.key); + const entry = treap.getEntryFor(node.key); try testing.expectEqual(entry.key, key); try testing.expectEqual(entry.node, node); try testing.expectEqual(entry.node, treap.getEntryForExisting(node).node); diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig index bd73a3bea397cb331f2bb5a729ae7852dc717eca..2eadccda9e190b5bc82f43ec158e51beaad41ed5 100644 --- a/lib/std/unicode.zig +++ b/lib/std/unicode.zig @@ -242,7 +242,7 @@ pub fn utf8ValidateSlice(input: []const u8) bool { s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, }; - var n = remaining.len; + const n = remaining.len; var i: usize = 0; while (i < n) { const first_byte = remaining[i]; diff --git a/lib/std/zig/Parse.zig b/lib/std/zig/Parse.zig index 0187c09108069bb8d7e8b8d257d2f0a6add2a282..cc4f2962295323385147da1fc9c7a6149fd60b67 100644 --- a/lib/std/zig/Parse.zig +++ b/lib/std/zig/Parse.zig @@ -3516,7 +3516,6 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers { var saw_const = false; var saw_volatile = false; var saw_allowzero = false; - var saw_addrspace = false; while (true) { switch (p.token_tags[p.tok_i]) { .keyword_align => { @@ -3557,7 +3556,7 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers { saw_allowzero = true; }, .keyword_addrspace => { - if (saw_addrspace) { + if (result.addrspace_node != 0) { try p.warn(.extra_addrspace_qualifier); } result.addrspace_node = try p.parseAddrSpace(); diff --git a/lib/std/zig/c_translation.zig b/lib/std/zig/c_translation.zig index 9a700a7a971b6d4f8cdd2cf1fd48d0e14cceacec..e9581b9e412113c3ceaf28ec67eeced646c2c6bf 100644 --- a/lib/std/zig/c_translation.zig +++ b/lib/std/zig/c_translation.zig @@ -129,6 +129,7 @@ test "cast" { try testing.expectEqual(@as(?*anyopaque, @ptrFromInt(2)), cast(?*anyopaque, @as(*u8, @ptrFromInt(2)))); var foo: c_int = -1; + _ = &foo; try testing.expect(cast(*anyopaque, -1) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))))); try testing.expect(cast(*anyopaque, foo) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))))); try testing.expect(cast(?*anyopaque, -1) == @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))))); @@ -601,22 +602,22 @@ test "WL_CONTAINER_OF" { a: u32 = 0, b: u32 = 0, }; - var x = S{}; - var y = S{}; - var ptr = Macros.WL_CONTAINER_OF(&x.b, &y, "b"); + const x = S{}; + const y = S{}; + const ptr = Macros.WL_CONTAINER_OF(&x.b, &y, "b"); try testing.expectEqual(&x, ptr); } test "CAST_OR_CALL casting" { - var arg = @as(c_int, 1000); - var casted = Macros.CAST_OR_CALL(u8, arg); + const arg: c_int = 1000; + const casted = Macros.CAST_OR_CALL(u8, arg); try testing.expectEqual(cast(u8, arg), casted); const S = struct { x: u32 = 0, }; - var s = S{}; - var casted_ptr = Macros.CAST_OR_CALL(*u8, &s); + var s: S = .{}; + const casted_ptr = Macros.CAST_OR_CALL(*u8, &s); try testing.expectEqual(cast(*u8, &s), casted_ptr); } diff --git a/lib/std/zig/perf_test.zig b/lib/std/zig/perf_test.zig index a53dee7fa8ae0578fdf9094f46a2bac1739668bb..2a893013d90bdf0e6f8ddbed758edf2b37e35d34 100644 --- a/lib/std/zig/perf_test.zig +++ b/lib/std/zig/perf_test.zig @@ -32,7 +32,7 @@ pub fn main() !void { fn testOnce() usize { var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); - var allocator = fixed_buf_alloc.allocator(); + const allocator = fixed_buf_alloc.allocator(); _ = std.zig.Ast.parse(allocator, source, .zig) catch @panic("parse failure"); return fixed_buf_alloc.end_index; } diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index d6e862a9225cc5873d4e9162b5996d1b9da7b9f3..23e5ee83b482749989c8b4c4d1fa852a3b017de9 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -3495,7 +3495,7 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type { /// Turns all one-shot indents into regular indents /// Returns number of indents that must now be manually popped pub fn lockOneShotIndent(self: *Self) usize { - var locked_count = self.indent_one_shot_count; + const locked_count = self.indent_one_shot_count; self.indent_one_shot_count = 0; return locked_count; } diff --git a/lib/std/zig/string_literal.zig b/lib/std/zig/string_literal.zig index 53b1ab7ca83bfe676c3fc40875d5725ef91b6866..8ba2fc2f65149c308b278a99f760e5610694698e 100644 --- a/lib/std/zig/string_literal.zig +++ b/lib/std/zig/string_literal.zig @@ -288,7 +288,7 @@ test "parse" { var fixed_buf_mem: [64]u8 = undefined; var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(&fixed_buf_mem); - var alloc = fixed_buf_alloc.allocator(); + const alloc = fixed_buf_alloc.allocator(); try expectError(error.InvalidLiteral, parseAlloc(alloc, "\"\\x6\"")); try expect(eql(u8, "foo\nbar", try parseAlloc(alloc, "\"foo\\nbar\""))); diff --git a/lib/std/zig/system/NativeTargetInfo.zig b/lib/std/zig/system/NativeTargetInfo.zig index ba0d699f915ab274a46e902759b51ebd6894ab3b..88a8a3742ef9bc1c0b76a2d35c7fb9537a8b95c9 100644 --- a/lib/std/zig/system/NativeTargetInfo.zig +++ b/lib/std/zig/system/NativeTargetInfo.zig @@ -189,7 +189,7 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo { // native CPU architecture as being different than the current target), we use this: const cpu_arch = cross_target.getCpuArch(); - var cpu = switch (cross_target.cpu_model) { + const cpu = switch (cross_target.cpu_model) { .native => detectNativeCpuAndFeatures(cpu_arch, os, cross_target), .baseline => Target.Cpu.baseline(cpu_arch), .determined_by_cpu_arch => if (cross_target.cpu_arch == null) -- 2.54.0 From 2c1acb618027939c0812bc87a432b51632127717 Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 10 Nov 2023 08:04:39 +0000 Subject: [PATCH 03/15] test: update translate-c tests to match new discard format --- test/translate_c.zig | 118 +++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/test/translate_c.zig b/test/translate_c.zig index 37bf7a487806cd582149067ce051e3f9afaf1fff..2df0f8c6cf1354422ed75520d0605c188a2b8fae 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -123,10 +123,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() void { \\ while (true) if (true) { \\ var a: c_int = 1; - \\ _ = @TypeOf(a); + \\ _ = &a; \\ } else { \\ var b: c_int = 2; - \\ _ = @TypeOf(b); + \\ _ = &b; \\ }; \\ if (true) if (true) {}; \\} @@ -199,7 +199,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ .B = 0, \\ .C = 0, \\ }; - \\ _ = @TypeOf(a); + \\ _ = &a; \\ { \\ const struct_Foo_1 = extern struct { \\ A: c_int = @import("std").mem.zeroes(c_int), @@ -211,7 +211,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ .B = 0, \\ .C = 0, \\ }; - \\ _ = @TypeOf(a_2); + \\ _ = &a_2; \\ } \\} }); @@ -240,24 +240,24 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ B: c_int, \\ C: c_int, \\ }; - \\ _ = @TypeOf(union_unnamed_1); + \\ _ = &union_unnamed_1; \\ const Foo = union_unnamed_1; \\ var a: Foo = Foo{ \\ .A = @as(c_int, 0), \\ }; - \\ _ = @TypeOf(a); + \\ _ = &a; \\ { \\ const union_unnamed_2 = extern union { \\ A: c_int, \\ B: c_int, \\ C: c_int, \\ }; - \\ _ = @TypeOf(union_unnamed_2); + \\ _ = &union_unnamed_2; \\ const Foo_1 = union_unnamed_2; \\ var a_2: Foo_1 = Foo_1{ \\ .A = @as(c_int, 0), \\ }; - \\ _ = @TypeOf(a_2); + \\ _ = &a_2; \\ } \\} }); @@ -325,7 +325,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ const bar_1 = struct { \\ threadlocal var static: c_int = 2; \\ }; - \\ _ = @TypeOf(bar_1); + \\ _ = &bar_1; \\ return 0; \\} }); @@ -344,7 +344,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} \\pub export fn bar() c_int { \\ var a: c_int = 2; - \\ _ = @TypeOf(a); + \\ _ = &a; \\ return 0; \\} \\pub export fn baz() c_int { @@ -359,7 +359,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn main() void { \\ var a: c_int = @as(c_int, @bitCast(@as(c_uint, @truncate(@alignOf(c_int))))); - \\ _ = @TypeOf(a); + \\ _ = &a; \\} }); @@ -507,7 +507,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\#define bar(x) (&x, +3, 4 == 4, 5 * 6, baz(1, 2), 2 % 2, baz(1,2)) , &[_][]const u8{ \\pub const foo = blk_1: { - \\ _ = @TypeOf(foo); + \\ _ = &foo; \\ break :blk_1 bar; \\}; , @@ -729,7 +729,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn function(arg_opaque_1: ?*struct_opaque) void { \\ var opaque_1 = arg_opaque_1; \\ var cast: ?*struct_opaque_2 = @as(?*struct_opaque_2, @ptrCast(opaque_1)); - \\ _ = @TypeOf(cast); + \\ _ = &cast; \\} }); @@ -764,7 +764,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn my_fn() align(128) void {} \\pub export fn other_fn() void { \\ var ARR: [16]u8 align(16) = undefined; - \\ _ = @TypeOf(ARR); + \\ _ = &ARR; \\} }); } @@ -801,17 +801,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_int = undefined; - \\ _ = @TypeOf(a); + \\ _ = &a; \\ var b: u8 = 123; - \\ _ = @TypeOf(b); + \\ _ = &b; \\ const c: c_int = undefined; - \\ _ = @TypeOf(c); + \\ _ = &c; \\ const d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440))); - \\ _ = @TypeOf(d); + \\ _ = &d; \\ var e: c_int = 10; - \\ _ = @TypeOf(e); + \\ _ = &e; \\ var f: c_uint = 10; - \\ _ = @TypeOf(f); + \\ _ = &f; \\} }); @@ -870,7 +870,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ const v2 = struct { \\ const static: [5:0]u8 = "2.2.2".*; \\ }; - \\ _ = @TypeOf(v2); + \\ _ = &v2; \\} }); @@ -913,7 +913,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn bar() void { \\ var func_ptr: ?*anyopaque = @as(?*anyopaque, @ptrCast(&foo)); \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @as(?*const fn () callconv(.C) void, @ptrFromInt(@as(c_ulong, @intCast(@intFromPtr(func_ptr))))); - \\ _ = @TypeOf(typed_func_ptr); + \\ _ = &typed_func_ptr; \\} }); @@ -1360,7 +1360,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_int = undefined; - \\ _ = @TypeOf(a); + \\ _ = &a; \\} }); @@ -1599,23 +1599,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ var p: ?*anyopaque = undefined; \\ { \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p))); - \\ _ = @TypeOf(to_char); + \\ _ = &to_char; \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p))); - \\ _ = @TypeOf(to_short); + \\ _ = &to_short; \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p))); - \\ _ = @TypeOf(to_int); + \\ _ = &to_int; \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p))); - \\ _ = @TypeOf(to_longlong); + \\ _ = &to_longlong; \\ } \\ { \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p))); - \\ _ = @TypeOf(to_char); + \\ _ = &to_char; \\ var to_short: [*c]c_short = @as([*c]c_short, @ptrCast(@alignCast(p))); - \\ _ = @TypeOf(to_short); + \\ _ = &to_short; \\ var to_int: [*c]c_int = @as([*c]c_int, @ptrCast(@alignCast(p))); - \\ _ = @TypeOf(to_int); + \\ _ = &to_int; \\ var to_longlong: [*c]c_longlong = @as([*c]c_longlong, @ptrCast(@alignCast(p))); - \\ _ = @TypeOf(to_longlong); + \\ _ = &to_longlong; \\ } \\} }); @@ -1859,11 +1859,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ var arr: [10]u8 = [1]u8{ \\ 1, \\ } ++ [1]u8{0} ** 9; - \\ _ = @TypeOf(arr); + \\ _ = &arr; \\ var arr1: [10][*c]u8 = [1][*c]u8{ \\ null, \\ } ++ [1][*c]u8{null} ** 9; - \\ _ = @TypeOf(arr1); + \\ _ = &arr1; \\} }); @@ -2107,16 +2107,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub var c: c_int = 4; \\pub export fn foo(arg_c_1: u8) void { \\ var c_1 = arg_c_1; - \\ _ = @TypeOf(c_1); + \\ _ = &c_1; \\ var a_2: c_int = undefined; \\ var b_3: u8 = 123; \\ b_3 = @as(u8, @bitCast(@as(i8, @truncate(a_2)))); \\ { \\ var d: c_int = 5; - \\ _ = @TypeOf(d); + \\ _ = &d; \\ } \\ var d: c_uint = @as(c_uint, @bitCast(@as(c_int, 440))); - \\ _ = @TypeOf(d); + \\ _ = &d; \\} }); @@ -2215,7 +2215,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ { \\ var i: c_int = 2; \\ var b: c_int = 4; - \\ _ = @TypeOf(b); + \\ _ = &b; \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) { \\ var a: c_int = 2; \\ _ = blk: { @@ -2228,7 +2228,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ } \\ } \\ var i: u8 = 2; - \\ _ = @TypeOf(i); + \\ _ = &i; \\} }); @@ -2465,27 +2465,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn escapes() [*c]const u8 { \\ var a: u8 = '\''; - \\ _ = @TypeOf(a); + \\ _ = &a; \\ var b: u8 = '\\'; - \\ _ = @TypeOf(b); + \\ _ = &b; \\ var c: u8 = '\x07'; - \\ _ = @TypeOf(c); + \\ _ = &c; \\ var d: u8 = '\x08'; - \\ _ = @TypeOf(d); + \\ _ = &d; \\ var e: u8 = '\x0c'; - \\ _ = @TypeOf(e); + \\ _ = &e; \\ var f: u8 = '\n'; - \\ _ = @TypeOf(f); + \\ _ = &f; \\ var g: u8 = '\r'; - \\ _ = @TypeOf(g); + \\ _ = &g; \\ var h: u8 = '\t'; - \\ _ = @TypeOf(h); + \\ _ = &h; \\ var i: u8 = '\x0b'; - \\ _ = @TypeOf(i); + \\ _ = &i; \\ var j: u8 = '\x00'; - \\ _ = @TypeOf(j); + \\ _ = &j; \\ var k: u8 = '"'; - \\ _ = @TypeOf(k); + \\ _ = &k; \\ return "'\\\x07\x08\x0c\n\r\t\x0b\x00\""; \\} }); @@ -2681,7 +2681,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() c_int { \\ return blk: { \\ var a: c_int = 1; - \\ _ = @TypeOf(a); + \\ _ = &a; \\ break :blk a; \\ }; \\} @@ -2785,7 +2785,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\int bar(void) { return 0; } , &[_][]const u8{ \\pub inline fn CALL(arg: anytype) @TypeOf(bar()) { - \\ _ = @TypeOf(arg); + \\ _ = &arg; \\ return bar(); \\} }); @@ -2844,14 +2844,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() void { \\ if (true) { \\ var a: c_int = 2; - \\ _ = @TypeOf(a); + \\ _ = &a; \\ } \\ if ((blk: { \\ _ = @as(c_int, 2); \\ break :blk @as(c_int, 5); \\ }) != 0) { \\ var a: c_int = 2; - \\ _ = @TypeOf(a); + \\ _ = &a; \\ } \\} }); @@ -3331,7 +3331,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\#define a 2 , &[_][]const u8{ \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").zig.c_translation.cast(?*anyopaque, baz))) { - \\ _ = @TypeOf(bar); + \\ _ = &bar; \\ return baz(@import("std").zig.c_translation.cast(?*anyopaque, baz)); \\} , @@ -3471,7 +3471,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo(arg_a: [*c]c_int) void { \\ var a = arg_a; - \\ _ = @TypeOf(a); + \\ _ = &a; \\} \\pub export fn bar(arg_a: [*c]const c_int) void { \\ var a = arg_a; @@ -3831,12 +3831,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn bar(arg_x: c_int, arg_y: c_int) c_int { \\ var x = arg_x; \\ var y = arg_y; - \\ _ = @TypeOf(y); + \\ _ = &y; \\ return x; \\} , \\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A) { - \\ _ = @TypeOf(B); + \\ _ = &B; \\ return A; \\} }); @@ -3931,7 +3931,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ var a: S = undefined; \\ var b: S = undefined; \\ var c: c_longlong = @divExact(@as(c_longlong, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8)); - \\ _ = @TypeOf(c); + \\ _ = &c; \\} }); } else { @@ -3946,7 +3946,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ var a: S = undefined; \\ var b: S = undefined; \\ var c: c_long = @divExact(@as(c_long, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8)); - \\ _ = @TypeOf(c); + \\ _ = &c; \\} }); } -- 2.54.0 From 21fa187abc2a06c9bd5cfe4355c5edbfb3177f6b Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 11 Nov 2023 07:27:31 +0000 Subject: [PATCH 04/15] test: update cases to silence 'var is never mutated' errors --- ...ding_numbers_at_runtime_and_comptime.2.zig | 1 + test/cases/array_in_anon_struct.zig | 1 + test/cases/assert_function.17.zig | 1 + test/cases/bad_inferred_variable_type.zig | 2 +- test/cases/binary_operands.1.zig | 1 + test/cases/binary_operands.10.zig | 1 + test/cases/binary_operands.11.zig | 1 + test/cases/binary_operands.12.zig | 1 + test/cases/binary_operands.13.zig | 1 + test/cases/binary_operands.14.zig | 2 +- test/cases/binary_operands.2.zig | 1 + test/cases/binary_operands.3.zig | 1 + test/cases/binary_operands.4.zig | 2 +- test/cases/binary_operands.6.zig | 1 + test/cases/binary_operands.7.zig | 1 + test/cases/binary_operands.8.zig | 1 + test/cases/binary_operands.9.zig | 1 + ...n_of_non-tagged_union_and_enum_literal.zig | 3 +- ..._known_struct_is_resolved_before_error.zig | 2 +- ..._ABI_compatible_type_or_has_align_attr.zig | 2 +- .../compile_errors/C_pointer_to_anyopaque.zig | 2 +- ..._runtime_parameter_from_outer_function.zig | 4 +- .../compile_errors/add_on_undefined_value.zig | 2 +- .../alignment_of_enum_field_specified.zig | 2 +- ...mbiguous_coercion_of_division_operands.zig | 12 +++--- .../compile_errors/and_on_undefined_value.zig | 3 +- .../array_access_of_non_array.zig | 2 +- .../compile_errors/array_access_of_type.zig | 2 +- .../array_access_with_non_integer_index.zig | 4 +- .../array_init_invalid_elem_count.zig | 12 +++--- .../assign_inline_fn_to_non-comptime_var.zig | 2 +- .../assign_local_bad_coercion.zig | 2 +- .../assign_too_big_number_to_u16.zig | 4 +- ...th_a_function_that_returns_an_optional.zig | 4 +- .../async/Frame_of_generic_function.zig | 4 +- ...sync_function_depends_on_its_own_frame.zig | 2 +- ...on_indirectly_depends_on_its_own_frame.zig | 2 +- .../async/bad_alignment_in_asynccall.zig | 1 + .../async/const_frame_cast_to_anyframe.zig | 2 +- ..._recursion_of_async_functions_detected.zig | 8 ++-- .../invalid_suspend_in_exported_function.zig | 2 +- ...c_function_pointer_passed_to_asyncCall.zig | 1 + ...bad_implicit_casting_of_anyframe_types.zig | 6 +-- .../runtime-known_async_function_called.zig | 1 + ...own_function_called_with_async_keyword.zig | 1 + ...cit_cast_from_const_T_to_array_len_1_T.zig | 4 +- ...licit_cast_from_array_pointer_to_slice.zig | 6 +-- .../compile_errors/bad_alignment_type.zig | 8 ++-- .../compile_errors/bad_usage_of_call.zig | 5 ++- .../binary_OR_operator_on_error_sets.zig | 2 +- ...tCast_same_size_but_bit_count_mismatch.zig | 4 +- ...h_different_sizes_inside_an_expression.zig | 5 ++- ...comptime_only_scope_uses_condbr_inline.zig | 8 ++-- .../break_void_result_location.zig | 5 ++- .../compile_errors/c_pointer_to_void.zig | 6 +-- ...tcall_thiscall_on_unsupported_platform.zig | 6 +-- ...en_optional_T_where_T_is_not_a_pointer.zig | 8 ++-- ...et_to_error_union_of_smaller_error_set.zig | 6 +-- .../cast_global_error_set_to_error_set.zig | 6 +-- .../catch_on_undefined_value.zig | 2 +- ...to_non_optional_with_incomparable_type.zig | 4 +- ...parison_operators_with_undefined_value.zig | 12 +++--- ...ompile_error_in_struct_init_expression.zig | 2 +- .../compile_time_null_ptr_cast.zig | 2 +- .../compile_time_undef_ptr_cast.zig | 1 + ...st_enum_to_union_but_field_has_payload.zig | 2 +- ...mptime_continue_inside_runtime_if_bool.zig | 5 ++- ...ptime_continue_inside_runtime_if_error.zig | 5 ++- ...me_continue_inside_runtime_if_optional.zig | 5 ++- ...omptime_continue_inside_runtime_switch.zig | 5 ++- ...ime_continue_inside_runtime_while_bool.zig | 5 ++- ...me_continue_inside_runtime_while_error.zig | 5 ++- ...continue_inside_runtime_while_optional.zig | 5 ++- ...comptime_continue_to_outer_inline_loop.zig | 5 ++- .../comptime_if_inside_runtime_for.zig | 7 ++-- .../comptime_slice_of_an_undefined_slice.zig | 2 +- .../comptime_struct_field_no_init_value.zig | 2 +- ...mptime_vector_overflow_shows_the_index.zig | 2 +- ...de_comptime_function_has_compile_error.zig | 6 +-- .../deref_on_undefined_value.zig | 2 +- .../deref_slice_and_get_len_field.zig | 1 + .../compile_errors/dereference_an_array.zig | 3 +- ...encing_invalid_payload_ptr_at_comptime.zig | 2 +- ...edding_opaque_type_in_struct_and_union.zig | 4 +- .../compile_errors/div_on_undefined_value.zig | 1 + .../double_pointer_to_anyopaque_pointer.zig | 7 ++-- .../empty_switch_on_an_integer.zig | 2 +- ...acked_by_comptime_int_must_be_comptime.zig | 2 +- .../enum_field_value_references_enum.zig | 2 +- ...field_count_range_but_not_matching_tag.zig | 4 +- .../enum_value_already_taken.zig | 2 +- ..._initializer_doesnt_crash_the_compiler.zig | 2 +- ..._union_operator_with_non_error_set_LHS.zig | 2 +- .../error_when_evaluating_return_type.zig | 2 +- ...n_why_generic_fn_is_called_at_comptime.zig | 5 ++- ..._known_at_comptime_violates_error_sets.zig | 6 +-- ...xplicitly_casting_non_tag_type_to_enum.zig | 4 +- .../extern_union_field_missing_type.zig | 2 +- .../extern_union_given_enum_tag_type.zig | 2 +- .../compile_errors/field_access_of_slices.zig | 5 ++- test/cases/compile_errors/for.zig | 7 ++-- .../for_loop_body_expression_ignored.zig | 2 +- .../compile_errors/function_ptr_alignment.zig | 10 ++--- ...ailure_in_generic_function_return_type.zig | 3 +- ...generic_method_call_with_invalid_param.zig | 9 ++-- ...nored_expression_in_while_continuation.zig | 10 +++-- ..._and_Zig_pointer-bad_const-align-child.zig | 12 +++--- .../implicit_cast_from_f64_to_f32.zig | 2 +- ...mplicit_cast_of_error_set_not_a_subset.zig | 6 +-- ...ers_which_would_mess_up_null_semantics.zig | 13 ++++-- ..._casting_null_c_pointer_to_zig_pointer.zig | 5 ++- .../implicitly_casting_enum_to_tag_type.zig | 2 +- .../incompatible sub-byte fields.zig | 7 ++-- .../compile_errors/incompatible_sentinels.zig | 4 +- .../incorrect_pointer_dereference_syntax.zig | 1 + .../incorrect_type_to_memset_memcpy.zig | 8 ++-- ..._array_of_size_zero_with_runtime_index.zig | 3 +- ...e_call_runtime_value_to_comptime_param.zig | 2 +- ...float_conversion_to_comptime_int-float.zig | 10 +++-- .../intFromPtr_0_to_non_optional_pointer.zig | 4 +- .../int_to_err_global_invalid_number.zig | 2 +- .../int_to_err_non_global_invalid_number.zig | 6 +-- .../integer_cast_truncates_bits.zig | 4 +- .../compile_errors/invalid_compare_string.zig | 8 ++-- .../invalid_deref_on_switch_target.zig | 2 +- .../compile_errors/invalid_float_casts.zig | 12 ++++-- .../invalid_inline_else_type.zig | 9 ++-- .../compile_errors/invalid_int_casts.zig | 12 ++++-- .../invalid_multiple_dereferences.zig | 9 ++-- .../invalid_non-exhaustive_enum_to_union.zig | 4 +- .../invalid_peer_type_resolution.zig | 38 +++++++++-------- .../invalid_store_to_comptime_field.zig | 24 ++++++----- .../compile_errors/invalid_struct_field.zig | 5 ++- ...gnostic_string_for_top_level_decl_type.zig | 4 +- ..._3818_bitcast_from_parray-slice_to_u16.zig | 2 +- ...ional_anyopaque_to_anyopaque_must_fail.zig | 10 ++--- ...zy_pointer_with_undefined_element_type.zig | 3 +- ...tor_pointer_with_unknown_runtime_index.zig | 2 +- .../cases/compile_errors/memset_no_length.zig | 10 +++-- ..._const_in_slice_with_nested_array_type.zig | 2 +- .../compile_errors/missing_else_clause.zig | 4 +- ...ing_parameter_name_of_generic_function.zig | 2 +- ...elled_type_with_pointer_only_reference.zig | 2 +- .../compile_errors/mod_on_undefined_value.zig | 1 + .../mult_on_undefined_value.zig | 2 +- .../negate_on_undefined_value.zig | 2 +- test/cases/compile_errors/nested_vectors.zig | 2 +- ...of_things_that_require_const_variables.zig | 14 +++---- .../non-integer_tag_type_to_enum.zig | 2 +- .../non_void_error_union_payload_ignored.zig | 6 ++- .../cases/compile_errors/not_an_enum_type.zig | 2 +- .../compile_errors/or_on_undefined_value.zig | 3 +- .../orelse_on_undefined_value.zig | 2 +- .../compile_errors/out_of_bounds_index.zig | 16 ++++---- .../overflow_in_enum_value_allocation.zig | 2 +- .../packed_union_given_enum_tag_type.zig | 2 +- ...cked_union_with_automatic_layout_field.zig | 2 +- ...pointer_arithmetic_on_pointer-to-array.zig | 10 ++--- .../pointer_to_anyopaque_slice.zig | 1 + .../ptrFromInt_with_misaligned_address.zig | 2 +- .../compile_errors/recursive_inline_fn.zig | 3 +- .../reference_to_const_data.zig | 9 ++-- ...ify_typeOf_with_incompatible_arguments.zig | 1 + ...ompatibility_mismatching_handle_is_ptr.zig | 2 +- ...mismatching_handle_is_ptr_generic_call.zig | 2 +- ...ime_assignment_to_comptime_struct_type.zig | 1 + ...time_assignment_to_comptime_union_type.zig | 5 ++- ...ast_to_union_which_has_non-void_fields.zig | 4 +- .../runtime_indexing_comptime_array.zig | 6 ++- .../runtime_to_comptime_num.zig | 20 +++++---- .../runtime_value_in_switch_prong.zig | 2 +- ...f_referential_struct_requires_comptime.zig | 2 +- ...lf_referential_union_requires_comptime.zig | 2 +- .../shift_by_negative_comptime_integer.zig | 4 +- ...ift_on_type_with_non-power-of-two_size.zig | 12 ++++-- ...ing_without_int_type_or_comptime_known.zig | 6 ++- ...elected_index_past_first_vector_length.zig | 8 ++-- ...ce_cannot_have_its_bytes_reinterpreted.zig | 5 +-- .../compile_errors/slice_of_null_pointer.zig | 6 +-- .../slice_sentinel_mismatch-2.zig | 2 +- ...pecify_enum_tag_type_that_is_too_small.zig | 3 +- .../specify_non-integer_enum_tag_type.zig | 2 +- ...line_assembly_template_cannot_be_found.zig | 2 +- ...tor_pointer_with_unknown_runtime_index.zig | 3 +- .../compile_errors/sub_on_undefined_value.zig | 2 +- .../switch_capture_incompatible_types.zig | 4 +- ...ch_on_enum_with_1_field_with_no_prongs.zig | 2 +- test/cases/compile_errors/switch_on_slice.zig | 3 +- .../switch_ranges_endpoints_are_validated.zig | 4 +- .../switch_with_overlapping_case_ranges.zig | 2 +- ...hing_with_exhaustive_enum_has___prong_.zig | 2 +- .../switching_with_non-exhaustive_enums.zig | 6 +-- ...d_on_union_with_no_associated_enum_tag.zig | 7 ++-- .../compile_errors/truncate_sign_mismatch.zig | 16 ++++---- .../compile_errors/tuple_init_edge_cases.zig | 41 +++++++++++-------- .../union_access_of_inactive_field.zig | 1 + .../union_auto-enum_value_already_taken.zig | 2 +- .../union_duplicate_enum_field.zig | 2 +- .../union_enum_field_does_not_match_enum.zig | 2 +- .../union_noreturn_field_initialized.zig | 6 +-- .../union_runtime_coercion_from_enum.zig | 2 +- ...zig => unreachable_else_prong_err_set.zig} | 4 +- ...to_assign_null_to_non-nullable_pointer.zig | 11 +++-- ..._invalid_number_literal_as_array_index.zig | 2 +- .../variable_with_type_noreturn.zig | 2 +- .../variadic_arg_validation.zig | 9 ++-- .../while_loop_body_expression_ignored.zig | 28 +++++++------ .../while_loop_break_value_ignored.zig | 6 ++- .../wrong_type_passed_to_panic.zig | 2 +- test/cases/compile_log.0.zig | 2 +- test/cases/compile_log.1.zig | 1 + test/cases/comptime_var.0.zig | 5 ++- test/cases/comptime_var.1.zig | 1 + test/cases/comptime_var.5.zig | 1 + test/cases/conditions.5.zig | 1 + test/cases/decl_value_arena.zig | 2 +- test/cases/enum_values.0.zig | 4 +- test/cases/enum_values.1.zig | 3 ++ test/cases/error_in_nested_declaration.zig | 2 +- test/cases/error_unions.0.zig | 1 + test/cases/error_unions.1.zig | 1 + test/cases/error_unions.2.zig | 1 + test/cases/error_unions.3.zig | 1 + test/cases/error_unions.4.zig | 1 + test/cases/error_unions.5.zig | 1 + test/cases/f32_passed_to_variadic_fn.zig | 4 +- test/cases/inner_func_accessing_outer_var.zig | 5 ++- test/cases/llvm/blocks.zig | 1 + ...ment_address_space_reading_and_writing.zig | 1 + test/cases/llvm/nested_blocks.zig | 2 +- test/cases/llvm/optionals.zig | 4 ++ .../llvm/simple_addition_and_subtraction.zig | 1 + test/cases/locals.0.zig | 4 +- test/cases/locals.1.zig | 3 +- ...ying_numbers_at_runtime_and_comptime.2.zig | 1 + .../only_1_function_and_it_gets_updated.1.zig | 2 +- test/cases/optionals.0.zig | 1 + test/cases/optionals.1.zig | 1 + test/cases/optionals.2.zig | 1 + test/cases/optionals.3.zig | 1 + test/cases/runtime_bitwise_and.zig | 1 + test/cases/runtime_bitwise_or.zig | 1 + .../@asyncCall with too small a frame.zig | 3 +- test/cases/safety/@intCast to u0.zig | 2 +- ...o to non-optional byte-aligned pointer.zig | 3 +- ...t address zero to non-optional pointer.zig | 3 +- .../@ptrFromInt with misaligned address.zig | 3 +- .../@tagName on corrupted enum value.zig | 2 +- .../@tagName on corrupted union value.zig | 4 +- ...ray slice sentinel mismatch non-scalar.zig | 2 +- .../exact division failure - vectors.zig | 4 +- test/cases/safety/for_len_mismatch.zig | 1 + test/cases/safety/for_len_mismatch_three.zig | 1 + .../integer division by zero - vectors.zig | 4 +- test/cases/safety/memcpy_alias.zig | 1 + test/cases/safety/memcpy_len_mismatch.zig | 1 + .../safety/memset_slice_undefined_bytes.zig | 1 + .../safety/memset_slice_undefined_large.zig | 1 + .../optional unwrap operator on C pointer.zig | 3 +- ...tional unwrap operator on null pointer.zig | 3 +- ...r casting null to non-optional pointer.zig | 3 +- ...n which has been suspended and resumed.zig | 2 +- ...ed function which never been suspended.zig | 2 +- .../safety/shift left by huge amount.zig | 3 +- .../safety/shift right by huge amount.zig | 3 +- ...ed integer division overflow - vectors.zig | 4 +- ...in cast to unsigned integer - widening.zig | 3 +- .../safety/signed-unsigned vector cast.zig | 3 +- ...ice start index greater than end index.zig | 1 + ...h sentinel out of bounds - runtime len.zig | 1 + .../slicing null C pointer - runtime len.zig | 3 +- test/cases/safety/slicing null C pointer.zig | 3 +- test/cases/safety/truncating vector cast.zig | 3 +- ...ast to signed integer - same bit count.zig | 3 +- .../safety/unsigned-signed vector cast.zig | 3 +- .../vector integer addition overflow.zig | 4 +- ...vector integer multiplication overflow.zig | 4 +- .../vector integer negation overflow.zig | 1 + .../vector integer subtraction overflow.zig | 4 +- test/cases/structs.0.zig | 1 + test/cases/structs.2.zig | 1 + test/cases/structs.3.zig | 1 + test/cases/switch.0.zig | 3 +- test/cases/switch.1.zig | 2 + test/cases/switch.2.zig | 3 +- test/cases/switch.3.zig | 3 +- test/cases/type_of.0.zig | 1 + test/cases/while_loops.1.zig | 1 + test/cases/while_loops.2.zig | 1 + 289 files changed, 671 insertions(+), 489 deletions(-) rename test/cases/compile_errors/{uncreachable_else_prong_err_set.zig => unreachable_else_prong_err_set.zig} (84%) diff --git a/test/cases/adding_numbers_at_runtime_and_comptime.2.zig b/test/cases/adding_numbers_at_runtime_and_comptime.2.zig index 6643d811fc7edd946d27adac4302439093fb2603..d6d8755dc3ca614d588dc9ad460e4fb806845941 100644 --- a/test/cases/adding_numbers_at_runtime_and_comptime.2.zig +++ b/test/cases/adding_numbers_at_runtime_and_comptime.2.zig @@ -1,5 +1,6 @@ pub fn main() void { var x: usize = 3; + _ = &x; const y = add(1, 2, x); if (y - 6 != 0) unreachable; } diff --git a/test/cases/array_in_anon_struct.zig b/test/cases/array_in_anon_struct.zig index 43e815d621e7f6e4dbdea464f127db853e42608f..6164e7056918ea077be4d3c56c4ad277053e7918 100644 --- a/test/cases/array_in_anon_struct.zig +++ b/test/cases/array_in_anon_struct.zig @@ -2,6 +2,7 @@ const std = @import("std"); noinline fn outer() u32 { var a: u32 = 42; + _ = &a; return inner(.{ .unused = a, .value = [1]u32{0}, diff --git a/test/cases/assert_function.17.zig b/test/cases/assert_function.17.zig index ac9dce3079f6444476afd65757675726390946cf..01c4a5ca3cbe016f2fcf75688b7d7dc1cbd95d1f 100644 --- a/test/cases/assert_function.17.zig +++ b/test/cases/assert_function.17.zig @@ -1,5 +1,6 @@ pub fn main() void { var i: u64 = 0xFFEEDDCCBBAA9988; + _ = &i; assert(i == 0xFFEEDDCCBBAA9988); } diff --git a/test/cases/bad_inferred_variable_type.zig b/test/cases/bad_inferred_variable_type.zig index 7c464f48c91211e650eff61d70013a64757b1253..e84129960616fbdbde5b5a49f69d1c9ca7b22ecd 100644 --- a/test/cases/bad_inferred_variable_type.zig +++ b/test/cases/bad_inferred_variable_type.zig @@ -1,6 +1,6 @@ pub fn main() void { var x = null; - _ = x; + _ = &x; } // error diff --git a/test/cases/binary_operands.1.zig b/test/cases/binary_operands.1.zig index fdee492d227abb71eca039c996d32c6a24568d43..2b244b194a8b695934c4917d14e137414d4b0b15 100644 --- a/test/cases/binary_operands.1.zig +++ b/test/cases/binary_operands.1.zig @@ -1,5 +1,6 @@ pub fn main() void { var i: i32 = 2147483647; + _ = &i; if (i +% 1 != -2147483648) unreachable; return; } diff --git a/test/cases/binary_operands.10.zig b/test/cases/binary_operands.10.zig index 63e045c258199ca9127804d16969e7ba2d4c9a64..721a9217437bcf92dfb9d5f859d3ac53f91def9e 100644 --- a/test/cases/binary_operands.10.zig +++ b/test/cases/binary_operands.10.zig @@ -2,6 +2,7 @@ pub fn main() void { var i: u32 = 5; i *= 7; var result: u32 = foo(i, 10); + _ = &result; if (result != 350) unreachable; return; } diff --git a/test/cases/binary_operands.11.zig b/test/cases/binary_operands.11.zig index f461bcc0af9ba6cb1cae194c078fb53bcd6b24bd..f6a87551781872317d72c17a6b74bbd8b1f258b5 100644 --- a/test/cases/binary_operands.11.zig +++ b/test/cases/binary_operands.11.zig @@ -1,5 +1,6 @@ pub fn main() void { var i: i32 = 2147483647; + _ = &i; const result = i *% 2; if (result != -2) unreachable; return; diff --git a/test/cases/binary_operands.12.zig b/test/cases/binary_operands.12.zig index 0ffb5e22309d4642af7b59c80999f2ce465d7c45..d8b369764fb38b5e12a7379cdbdae1979b1386f7 100644 --- a/test/cases/binary_operands.12.zig +++ b/test/cases/binary_operands.12.zig @@ -1,5 +1,6 @@ pub fn main() void { var i: u3 = 3; + _ = &i; if (i *% 3 != 1) unreachable; return; } diff --git a/test/cases/binary_operands.13.zig b/test/cases/binary_operands.13.zig index d626059e1034a9b09eeae9ae69509c8f6c44cd2c..680d82a91985140dfdb4c071e0d3b3504b7b0bee 100644 --- a/test/cases/binary_operands.13.zig +++ b/test/cases/binary_operands.13.zig @@ -1,5 +1,6 @@ pub fn main() void { var i: i4 = 3; + _ = &i; if (i *% 3 != -7) unreachable; return; } diff --git a/test/cases/binary_operands.14.zig b/test/cases/binary_operands.14.zig index fcc7245ad97d3606a1d364981bbae5c1339cc8d7..aa1d62bcde45beffdd81be488d2773e378e766d8 100644 --- a/test/cases/binary_operands.14.zig +++ b/test/cases/binary_operands.14.zig @@ -1,7 +1,7 @@ pub fn main() void { var i: u32 = 352; i /= 7; // i = 50 - var result: u32 = foo(i, 7); + const result: u32 = foo(i, 7); if (result != 7) unreachable; return; } diff --git a/test/cases/binary_operands.2.zig b/test/cases/binary_operands.2.zig index 78c10f56b76f4bce803dea768d77530c16479cb1..5b08fecc04482d097242cb0b3736396baaafecbe 100644 --- a/test/cases/binary_operands.2.zig +++ b/test/cases/binary_operands.2.zig @@ -1,5 +1,6 @@ pub fn main() void { var i: i4 = 7; + _ = &i; if (i +% 1 != -8) unreachable; return; } diff --git a/test/cases/binary_operands.3.zig b/test/cases/binary_operands.3.zig index 0297f1e7a48a877295b059a36e0fc958e2033f61..75d78d522a6de9d6bb550de5e99ed4dfb10c40dc 100644 --- a/test/cases/binary_operands.3.zig +++ b/test/cases/binary_operands.3.zig @@ -1,5 +1,6 @@ pub fn main() u8 { var i: u8 = 255; + _ = &i; return i +% 1; } diff --git a/test/cases/binary_operands.4.zig b/test/cases/binary_operands.4.zig index f0f8910e1463b4127d7da741907491cbbee4394a..b3fd9fc289aeb8084d239fe4bef28fb832975cc3 100644 --- a/test/cases/binary_operands.4.zig +++ b/test/cases/binary_operands.4.zig @@ -1,7 +1,7 @@ pub fn main() u8 { var i: u8 = 5; i += 20; - var result: u8 = foo(i, 10); + const result: u8 = foo(i, 10); return result - 35; } fn foo(x: u8, y: u8) u8 { diff --git a/test/cases/binary_operands.6.zig b/test/cases/binary_operands.6.zig index 5c9c5be68aa1364a8f782aaab099532cd6dde297..b6e04e609e57ce5c1e4dead30ee174c0af87a427 100644 --- a/test/cases/binary_operands.6.zig +++ b/test/cases/binary_operands.6.zig @@ -1,5 +1,6 @@ pub fn main() void { var i: i32 = -2147483648; + _ = &i; if (i -% 1 != 2147483647) unreachable; return; } diff --git a/test/cases/binary_operands.7.zig b/test/cases/binary_operands.7.zig index 634a47fb0ce4042bd71d386044a2077109f39356..ae69df2c550908835e281571e0d9bd89690c87e9 100644 --- a/test/cases/binary_operands.7.zig +++ b/test/cases/binary_operands.7.zig @@ -1,5 +1,6 @@ pub fn main() void { var i: i7 = -64; + _ = &i; if (i -% 1 != 63) unreachable; return; } diff --git a/test/cases/binary_operands.8.zig b/test/cases/binary_operands.8.zig index a20f6646944d35e89980743212ce060d9b3e5930..fb2741cab6d9161c01aabc18e0f5c41a40dee315 100644 --- a/test/cases/binary_operands.8.zig +++ b/test/cases/binary_operands.8.zig @@ -1,5 +1,6 @@ pub fn main() void { var i: u4 = 0; + _ = &i; if (i -% 1 != 15) unreachable; } diff --git a/test/cases/binary_operands.9.zig b/test/cases/binary_operands.9.zig index e6c4f5d52b491158f629ec74f7b0f16f624f94ac..a9d62b96e340506748f0e320e6063d81f2378686 100644 --- a/test/cases/binary_operands.9.zig +++ b/test/cases/binary_operands.9.zig @@ -2,6 +2,7 @@ pub fn main() u8 { var i: u8 = 5; i -= 3; var result: u8 = foo(i, 10); + _ = &result; return result - 8; } fn foo(x: u8, y: u8) u8 { diff --git a/test/cases/comparison_of_non-tagged_union_and_enum_literal.zig b/test/cases/comparison_of_non-tagged_union_and_enum_literal.zig index 621b8ead259868e26f9532a831e2b014d685ce35..3e529d5e302898d9b5717a4bf039efab8526b6b1 100644 --- a/test/cases/comparison_of_non-tagged_union_and_enum_literal.zig +++ b/test/cases/comparison_of_non-tagged_union_and_enum_literal.zig @@ -2,7 +2,8 @@ export fn entry() void { const U = union { A: u32, B: u64 }; var u = U{ .A = 42 }; var ok = u == .A; - _ = ok; + _ = &u; + _ = &ok; } // error diff --git a/test/cases/compile_errors/AstGen_comptime_known_struct_is_resolved_before_error.zig b/test/cases/compile_errors/AstGen_comptime_known_struct_is_resolved_before_error.zig index 3ec79c7c53637119f4747d36beca692030562514..0764dc9472be9884f94abc187ecdc52086fd5257 100644 --- a/test/cases/compile_errors/AstGen_comptime_known_struct_is_resolved_before_error.zig +++ b/test/cases/compile_errors/AstGen_comptime_known_struct_is_resolved_before_error.zig @@ -6,7 +6,7 @@ const S2 = struct { }; pub export fn entry() void { var s: S1 = undefined; - _ = s; + _ = &s; } // error diff --git a/test/cases/compile_errors/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig b/test/cases/compile_errors/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig index c10a146cf08f70fae0bc502e379371b57297d2e5..c0188477b85c45ffb98233af27d6ef72647d23d9 100644 --- a/test/cases/compile_errors/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig +++ b/test/cases/compile_errors/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig @@ -1,7 +1,7 @@ const Foo = struct { a: u32 }; export fn a() void { const T = [*c]Foo; - var t: T = undefined; + const t: T = undefined; _ = t; } diff --git a/test/cases/compile_errors/C_pointer_to_anyopaque.zig b/test/cases/compile_errors/C_pointer_to_anyopaque.zig index c2a0ad088dea41d979bccefa6235441766aa0fb6..21c67e151cff436e7a5fefa0521818bd0951cc1d 100644 --- a/test/cases/compile_errors/C_pointer_to_anyopaque.zig +++ b/test/cases/compile_errors/C_pointer_to_anyopaque.zig @@ -1,7 +1,7 @@ export fn a() void { var x: *anyopaque = undefined; var y: [*c]anyopaque = x; - _ = y; + _ = .{ &x, &y }; } // error diff --git a/test/cases/compile_errors/accessing_runtime_parameter_from_outer_function.zig b/test/cases/compile_errors/accessing_runtime_parameter_from_outer_function.zig index 49ef3b4d4d9f026943c2b40cd7a1b3743422d21c..176ace28db9143e47fce79e1e88fae4e9c6a4adc 100644 --- a/test/cases/compile_errors/accessing_runtime_parameter_from_outer_function.zig +++ b/test/cases/compile_errors/accessing_runtime_parameter_from_outer_function.zig @@ -7,8 +7,8 @@ fn outer(y: u32) *const fn (u32) u32 { return st.get; } export fn entry() void { - var func = outer(10); - var x = func(3); + const func = outer(10); + const x = func(3); _ = x; } diff --git a/test/cases/compile_errors/add_on_undefined_value.zig b/test/cases/compile_errors/add_on_undefined_value.zig index 404f5019be58e43978e93d509e33c466e78231b3..b59de233c57cd3ab1e0affccf188bbee978f43c4 100644 --- a/test/cases/compile_errors/add_on_undefined_value.zig +++ b/test/cases/compile_errors/add_on_undefined_value.zig @@ -1,5 +1,5 @@ comptime { - var a: i64 = undefined; + const a: i64 = undefined; _ = a + a; } diff --git a/test/cases/compile_errors/alignment_of_enum_field_specified.zig b/test/cases/compile_errors/alignment_of_enum_field_specified.zig index ecb06aa2543bdaf116bb244e2c08a4d0f5363e77..409a8e0f934bce1429e4de31a12d72910fa716ad 100644 --- a/test/cases/compile_errors/alignment_of_enum_field_specified.zig +++ b/test/cases/compile_errors/alignment_of_enum_field_specified.zig @@ -6,7 +6,7 @@ const Number = enum { // zig fmt: on export fn entry1() void { - var x: Number = undefined; + const x: Number = undefined; _ = x; } diff --git a/test/cases/compile_errors/ambiguous_coercion_of_division_operands.zig b/test/cases/compile_errors/ambiguous_coercion_of_division_operands.zig index f3e51a1bed2459b067e42f966e0b6ba4b4afe328..5defb463c2f860f6f6770df56b0c7db1cdb872d3 100644 --- a/test/cases/compile_errors/ambiguous_coercion_of_division_operands.zig +++ b/test/cases/compile_errors/ambiguous_coercion_of_division_operands.zig @@ -1,17 +1,17 @@ export fn entry1() void { - var f: f32 = 54.0 / 5; + const f: f32 = 54.0 / 5; _ = f; } export fn entry2() void { - var f: f32 = 54 / 5.0; + const f: f32 = 54 / 5.0; _ = f; } export fn entry3() void { - var f: f32 = 55.0 / 5; + const f: f32 = 55.0 / 5; _ = f; } export fn entry4() void { - var f: f32 = 55 / 5.0; + const f: f32 = 55 / 5.0; _ = f; } @@ -19,5 +19,5 @@ export fn entry4() void { // backend=stage2 // target=native // -// :2:23: error: ambiguous coercion of division operands 'comptime_float' and 'comptime_int'; non-zero remainder '4' -// :6:21: error: ambiguous coercion of division operands 'comptime_int' and 'comptime_float'; non-zero remainder '4' +// :2:25: error: ambiguous coercion of division operands 'comptime_float' and 'comptime_int'; non-zero remainder '4' +// :6:23: error: ambiguous coercion of division operands 'comptime_int' and 'comptime_float'; non-zero remainder '4' diff --git a/test/cases/compile_errors/and_on_undefined_value.zig b/test/cases/compile_errors/and_on_undefined_value.zig index cee23d054061351e516fb85a7081f2596804183c..416ba800976a63cdd7d9f30811fbdc0bec04a8a6 100644 --- a/test/cases/compile_errors/and_on_undefined_value.zig +++ b/test/cases/compile_errors/and_on_undefined_value.zig @@ -1,5 +1,6 @@ comptime { var a: bool = undefined; + _ = &a; _ = a and a; } @@ -7,4 +8,4 @@ comptime { // backend=stage2 // target=native // -// :3:9: error: use of undefined value here causes undefined behavior +// :4:9: error: use of undefined value here causes undefined behavior diff --git a/test/cases/compile_errors/array_access_of_non_array.zig b/test/cases/compile_errors/array_access_of_non_array.zig index 0f06bae1dd011a84551c8a0cbf2454014dd810f0..4bcb9bd237974c6998c84739a7d24f6d8019f42d 100644 --- a/test/cases/compile_errors/array_access_of_non_array.zig +++ b/test/cases/compile_errors/array_access_of_non_array.zig @@ -3,7 +3,7 @@ export fn f() void { bad[0] = bad[0]; } export fn g() void { - var bad: bool = undefined; + const bad: bool = undefined; _ = bad[0]; } diff --git a/test/cases/compile_errors/array_access_of_type.zig b/test/cases/compile_errors/array_access_of_type.zig index 1e66ca3776d24467c74a4d3f73f0a51427de6594..b9e6f24a5547c71a7a00e0758ddfc37c19638188 100644 --- a/test/cases/compile_errors/array_access_of_type.zig +++ b/test/cases/compile_errors/array_access_of_type.zig @@ -1,6 +1,6 @@ export fn foo() void { var b: u8[40] = undefined; - _ = b; + _ = &b; } // error diff --git a/test/cases/compile_errors/array_access_with_non_integer_index.zig b/test/cases/compile_errors/array_access_with_non_integer_index.zig index 3d7bde7364df1c727af3bb7d47841335a31131fc..0189d0f09ca6936ad4e29c515064adc675af55be 100644 --- a/test/cases/compile_errors/array_access_with_non_integer_index.zig +++ b/test/cases/compile_errors/array_access_with_non_integer_index.zig @@ -2,11 +2,13 @@ export fn f() void { var array = "aoeu"; var bad = false; array[bad] = array[bad]; + _ = &bad; } export fn g() void { var array = "aoeu"; var bad = false; _ = array[bad]; + _ = .{ &array, &bad }; } // error @@ -14,4 +16,4 @@ export fn g() void { // target=native // // :4:11: error: expected type 'usize', found 'bool' -// :9:15: error: expected type 'usize', found 'bool' +// :10:15: error: expected type 'usize', found 'bool' diff --git a/test/cases/compile_errors/array_init_invalid_elem_count.zig b/test/cases/compile_errors/array_init_invalid_elem_count.zig index 23e00cd057464735f9049e0c3370ff8c09840a74..ce281452698940aef17b36fb456d2f6c07b6f110 100644 --- a/test/cases/compile_errors/array_init_invalid_elem_count.zig +++ b/test/cases/compile_errors/array_init_invalid_elem_count.zig @@ -2,27 +2,27 @@ const V = @Vector(8, u8); const A = [8]u8; comptime { var v: V = V{1}; - _ = v; + _ = &v; } comptime { var v: V = V{}; - _ = v; + _ = &v; } comptime { var a: A = A{1}; - _ = a; + _ = &a; } comptime { var a: A = A{}; - _ = a; + _ = &a; } pub export fn entry1() void { var bla: V = .{ 1, 2, 3, 4 }; - _ = bla; + _ = &bla; } pub export fn entry2() void { var bla: A = .{ 1, 2, 3, 4 }; - _ = bla; + _ = &bla; } const S = struct { list: [2]u8 = .{0}, diff --git a/test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig b/test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig index b2da9f32d9857107ab212c6f0499c34941153094..155df733fbbf8c3ed28c627601416d1c0ea6eea8 100644 --- a/test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig +++ b/test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig @@ -1,6 +1,6 @@ export fn entry() void { var a = &b; - _ = a; + _ = &a; } inline fn b() void {} diff --git a/test/cases/compile_errors/assign_local_bad_coercion.zig b/test/cases/compile_errors/assign_local_bad_coercion.zig index 0aa93f48bdcd33e8785d966ad61ad2c9c1573839..405af4f23534c93627cb78343c9d6019ef0a59c4 100644 --- a/test/cases/compile_errors/assign_local_bad_coercion.zig +++ b/test/cases/compile_errors/assign_local_bad_coercion.zig @@ -9,7 +9,7 @@ export fn constEntry() u32 { export fn varEntry() u32 { var x: u32 = g(); - return x; + return (&x).*; } // error diff --git a/test/cases/compile_errors/assign_too_big_number_to_u16.zig b/test/cases/compile_errors/assign_too_big_number_to_u16.zig index 1f8b097ae2329e49e24e17bee22b7546546206fc..4f595a95da5f956f1dc6cba28c2c5aabc26e6460 100644 --- a/test/cases/compile_errors/assign_too_big_number_to_u16.zig +++ b/test/cases/compile_errors/assign_too_big_number_to_u16.zig @@ -1,5 +1,5 @@ export fn foo() void { - var vga_mem: u16 = 0xB8000; + const vga_mem: u16 = 0xB8000; _ = vga_mem; } @@ -7,4 +7,4 @@ export fn foo() void { // backend=stage2 // target=native // -// :2:24: error: type 'u16' cannot represent integer value '753664' +// :2:26: error: type 'u16' cannot represent integer value '753664' diff --git a/test/cases/compile_errors/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig b/test/cases/compile_errors/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig index 6a7de57352b624d57866f13c7a03ef2e4e6e9308..f91b6a4ef22b81a6350e2b528dc025e3c90f5eb9 100644 --- a/test/cases/compile_errors/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig +++ b/test/cases/compile_errors/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig @@ -10,8 +10,8 @@ const S = struct { export fn entry() void { var u = U{ .Ye = maybe(false) }; var s = S{ .num = maybe(false) }; - _ = u; - _ = s; + _ = &u; + _ = &s; } // error diff --git a/test/cases/compile_errors/async/Frame_of_generic_function.zig b/test/cases/compile_errors/async/Frame_of_generic_function.zig index d90e53eb4683dba5f55a8e99388d04f47aa91390..af0fb5c72edeaf840439695f1530312357cf4d55 100644 --- a/test/cases/compile_errors/async/Frame_of_generic_function.zig +++ b/test/cases/compile_errors/async/Frame_of_generic_function.zig @@ -1,10 +1,10 @@ export fn entry() void { var frame: @Frame(func) = undefined; - _ = frame; + _ = &frame; } fn func(comptime T: type) void { var x: T = undefined; - _ = x; + _ = &x; } // error diff --git a/test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig b/test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig index 4dde5860bafc4709d376e1703df95b14ce58420f..b266d86ed807f16487194bac04bac6ac5b980bf1 100644 --- a/test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig +++ b/test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig @@ -3,7 +3,7 @@ export fn entry() void { } fn amain() callconv(.Async) void { var x: [@sizeOf(@Frame(amain))]u8 = undefined; - _ = x; + _ = &x; } // error diff --git a/test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig b/test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig index 4dac0d4fa33fbc45db20184af0c0734552b9df81..4e7341bff59841643916c573dde47ad7f55c0f23 100644 --- a/test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig +++ b/test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig @@ -6,7 +6,7 @@ fn amain() callconv(.Async) void { } fn other() void { var x: [@sizeOf(@Frame(amain))]u8 = undefined; - _ = x; + _ = &x; } // error diff --git a/test/cases/compile_errors/async/bad_alignment_in_asynccall.zig b/test/cases/compile_errors/async/bad_alignment_in_asynccall.zig index 399914000994b76b44c91e8200b74dafcd7aa1be..da00a0eeb7e305fb058cc540033509b5ffab86c6 100644 --- a/test/cases/compile_errors/async/bad_alignment_in_asynccall.zig +++ b/test/cases/compile_errors/async/bad_alignment_in_asynccall.zig @@ -2,6 +2,7 @@ export fn entry() void { var ptr: fn () callconv(.Async) void = func; var bytes: [64]u8 = undefined; _ = @asyncCall(&bytes, {}, ptr, .{}); + _ = &ptr; } fn func() callconv(.Async) void {} diff --git a/test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig b/test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig index affdb953d72f317ea094a806b6c08aa05c135256..52b866afcffe2a820fd23bacf90c4c916e6c6864 100644 --- a/test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig +++ b/test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig @@ -5,7 +5,7 @@ export fn a() void { export fn b() void { const f = async func(); var x: anyframe = &f; - _ = x; + _ = &x; } fn func() void { suspend {} diff --git a/test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig b/test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig index d845dc7930a73e4c85f24b57f9c6432a64bae4d3..804baed45fbdc72cbdae4df649a7d29401868296 100644 --- a/test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig +++ b/test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig @@ -12,7 +12,7 @@ fn rangeSum(x: i32) i32 { frame = null; if (x == 0) return 0; - var child = rangeSumIndirect(x - 1); + const child = rangeSumIndirect(x - 1); return child + 1; } @@ -23,7 +23,7 @@ fn rangeSumIndirect(x: i32) i32 { frame = null; if (x == 0) return 0; - var child = rangeSum(x - 1); + const child = rangeSum(x - 1); return child + 1; } @@ -32,5 +32,5 @@ fn rangeSumIndirect(x: i32) i32 { // target=native // // tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself -// tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here -// tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here +// tmp.zig:15:35: note: when analyzing type '@Frame(rangeSum)' here +// tmp.zig:28:25: note: when analyzing type '@Frame(rangeSumIndirect)' here diff --git a/test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig b/test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig index cfcbfba889dfd57b1260ee14df08d354f4973de4..fb3488ce9500d7df4fde80712f53a7587d7e98e0 100644 --- a/test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig +++ b/test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig @@ -1,7 +1,7 @@ export fn entry() void { var frame = async func(); var result = await frame; - _ = result; + _ = &result; } fn func() void { suspend {} diff --git a/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig b/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig index 97bc6a09bddb71cc196d7261ff474769cb61cb03..b62524f6de11afb5be59ceb2a5d1ba75c6edf277 100644 --- a/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig +++ b/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig @@ -2,6 +2,7 @@ export fn entry() void { var ptr = afunc; var bytes: [100]u8 align(16) = undefined; _ = @asyncCall(&bytes, {}, ptr, .{}); + _ = &ptr; } fn afunc() void {} diff --git a/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig b/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig index bdf7bec45816cff736f401e4c05ecfbaf9c50bbc..6ab99bf00dc0f52d613a8d7a399cc1c5c38f55de 100644 --- a/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig +++ b/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig @@ -1,17 +1,17 @@ export fn a() void { var x: anyframe = undefined; var y: anyframe->i32 = x; - _ = y; + _ = .{ &x, &y }; } export fn b() void { var x: i32 = undefined; var y: anyframe->i32 = x; - _ = y; + _ = .{ &x, &y }; } export fn c() void { var x: @Frame(func) = undefined; var y: anyframe->i32 = &x; - _ = y; + _ = .{ &x, &y }; } fn func() void {} diff --git a/test/cases/compile_errors/async/runtime-known_async_function_called.zig b/test/cases/compile_errors/async/runtime-known_async_function_called.zig index 90685ce566297391b6924ec1a56cddc2db28aa9a..8a5ef27d62dbd9190e2eaa3b888f9460066a9637 100644 --- a/test/cases/compile_errors/async/runtime-known_async_function_called.zig +++ b/test/cases/compile_errors/async/runtime-known_async_function_called.zig @@ -4,6 +4,7 @@ export fn entry() void { fn amain() void { var ptr = afunc; _ = ptr(); + _ = &ptr; } fn afunc() callconv(.Async) void {} diff --git a/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig b/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig index bfc22cca255d0aadfc0e6645ffcba7429a53ac72..9933c95435c9fd3d64abbd45ae73c9b8379654e1 100644 --- a/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig +++ b/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig @@ -1,6 +1,7 @@ export fn entry() void { var ptr = afunc; _ = async ptr(); + _ = &ptr; } fn afunc() callconv(.Async) void {} diff --git a/test/cases/compile_errors/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig b/test/cases/compile_errors/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig index b553d492aeb42fffacaa401a4f6b14dfd95dbeba..912bf6ba3c40df16b35d229381069ee9954b99d4 100644 --- a/test/cases/compile_errors/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig +++ b/test/cases/compile_errors/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig @@ -1,9 +1,9 @@ -export fn entry(byte: u8) void { +export fn entry() void { const w: i32 = 1234; var x: *const i32 = &w; var y: *[1]i32 = x; y[0] += 1; - _ = byte; + _ = &x; } // error diff --git a/test/cases/compile_errors/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig b/test/cases/compile_errors/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig index 0641d8e3f9605a9a0a60efdfa8f33ad74dc732a5..cbc380c8fec74122bc580614fc5321c34db7d85a 100644 --- a/test/cases/compile_errors/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig +++ b/test/cases/compile_errors/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig @@ -1,6 +1,6 @@ export fn a() void { var x: [10]u8 = undefined; - var y: []align(16) u8 = &x; + const y: []align(16) u8 = &x; _ = y; } @@ -8,5 +8,5 @@ export fn a() void { // backend=stage2 // target=native // -// :3:29: error: expected type '[]align(16) u8', found '*[10]u8' -// :3:29: note: pointer alignment '1' cannot cast into pointer alignment '16' +// :3:31: error: expected type '[]align(16) u8', found '*[10]u8' +// :3:31: note: pointer alignment '1' cannot cast into pointer alignment '16' diff --git a/test/cases/compile_errors/bad_alignment_type.zig b/test/cases/compile_errors/bad_alignment_type.zig index 523ee2491ae0ca2ea388c2998b2673a1701d5302..c85eb8427d76d7c30ceee947a96468109c665148 100644 --- a/test/cases/compile_errors/bad_alignment_type.zig +++ b/test/cases/compile_errors/bad_alignment_type.zig @@ -1,9 +1,9 @@ export fn entry1() void { - var x: []align(true) i32 = undefined; + const x: []align(true) i32 = undefined; _ = x; } export fn entry2() void { - var x: *align(@as(f64, 12.34)) i32 = undefined; + const x: *align(@as(f64, 12.34)) i32 = undefined; _ = x; } @@ -11,5 +11,5 @@ export fn entry2() void { // backend=stage2 // target=native // -// :2:20: error: expected type 'u32', found 'bool' -// :6:19: error: fractional component prevents float value '12.34' from coercion to type 'u32' +// :2:22: error: expected type 'u32', found 'bool' +// :6:21: error: fractional component prevents float value '12.34' from coercion to type 'u32' diff --git a/test/cases/compile_errors/bad_usage_of_call.zig b/test/cases/compile_errors/bad_usage_of_call.zig index 3669cda3bf2935f2f697072e5bfd6814fe16a148..3b7abe53f69fbde6d908c98d106926af595b6c52 100644 --- a/test/cases/compile_errors/bad_usage_of_call.zig +++ b/test/cases/compile_errors/bad_usage_of_call.zig @@ -11,7 +11,7 @@ export fn entry4() void { @call(.never_inline, bar, .{}); } export fn entry5(c: bool) void { - var baz = if (c) &baz1 else &baz2; + const baz = if (c) &baz1 else &baz2; @call(.compile_time, baz, .{}); } export fn entry6() void { @@ -22,6 +22,7 @@ export fn entry7() void { } pub export fn entry() void { var call_me: *const fn () void = undefined; + _ = &call_me; @call(.always_inline, call_me, .{}); } @@ -45,4 +46,4 @@ noinline fn dummy2() void {} // :15:26: error: modifier 'compile_time' requires a comptime-known function // :18:9: error: 'always_inline' call of noinline function // :21:9: error: 'always_inline' call of noinline function -// :25:27: error: modifier 'always_inline' requires a comptime-known function +// :26:27: error: modifier 'always_inline' requires a comptime-known function diff --git a/test/cases/compile_errors/binary_OR_operator_on_error_sets.zig b/test/cases/compile_errors/binary_OR_operator_on_error_sets.zig index 9955194f95a3f63567becc471e5b1f119347dfe9..ae239d300e85c4695d5a7a28e84988808541d4e8 100644 --- a/test/cases/compile_errors/binary_OR_operator_on_error_sets.zig +++ b/test/cases/compile_errors/binary_OR_operator_on_error_sets.zig @@ -1,7 +1,7 @@ pub const A = error.A; pub const AB = A | error.B; export fn entry() void { - var x: AB = undefined; + const x: AB = undefined; _ = x; } diff --git a/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig b/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig index e366e0cb03f548b76c8f9b99e81615fc5e87b145..1a7305904b2e5e304bc63af343ba9d7c70ad13d8 100644 --- a/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig +++ b/test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig @@ -1,5 +1,5 @@ export fn entry(byte: u8) void { - var oops: u7 = @bitCast(byte); + const oops: u7 = @bitCast(byte); _ = oops; } @@ -7,4 +7,4 @@ export fn entry(byte: u8) void { // backend=stage2 // target=native // -// :2:20: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits +// :2:22: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits diff --git a/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig b/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig index f73dfeb38a46c7d1efb993211c6816f93e4a0b2e..e1a16be60a1a38a534b2aa8a11597dc5dc0398b7 100644 --- a/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig +++ b/test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig @@ -1,5 +1,6 @@ export fn entry() void { - var foo = (@as(u8, @bitCast(@as(f32, 1.0))) == 0xf); + const f: f32 = 1.0; + const foo = (@as(u8, @bitCast(f)) == 0xf); _ = foo; } @@ -7,4 +8,4 @@ export fn entry() void { // backend=stage2 // target=native // -// :2:24: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits +// :3:26: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits diff --git a/test/cases/compile_errors/branch_in_comptime_only_scope_uses_condbr_inline.zig b/test/cases/compile_errors/branch_in_comptime_only_scope_uses_condbr_inline.zig index 8c0166ad2dccb6fac8f8e11eefb851129efc28fe..c072c7ef9d977c4ae5efb84f2021d247b68cdd24 100644 --- a/test/cases/compile_errors/branch_in_comptime_only_scope_uses_condbr_inline.zig +++ b/test/cases/compile_errors/branch_in_comptime_only_scope_uses_condbr_inline.zig @@ -1,5 +1,6 @@ pub export fn entry1() void { var x: u32 = 3; + _ = &x; _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{ if (x > 1) 1 else -1, }); @@ -7,6 +8,7 @@ pub export fn entry1() void { pub export fn entry2() void { var y: ?i8 = -1; + _ = &y; _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{ y orelse 1, }); @@ -16,6 +18,6 @@ pub export fn entry2() void { // backend=stage2 // target=native // -// :4:15: error: unable to evaluate comptime expression -// :4:13: note: operation is runtime due to this operand -// :11:11: error: unable to evaluate comptime expression +// :5:15: error: unable to evaluate comptime expression +// :5:13: note: operation is runtime due to this operand +// :13:11: error: unable to evaluate comptime expression diff --git a/test/cases/compile_errors/break_void_result_location.zig b/test/cases/compile_errors/break_void_result_location.zig index 140ddb6ed13eaa2235c8f3fdab317291bcad992b..24a7644ce10029354dfa88b52fbf579ce27a1be5 100644 --- a/test/cases/compile_errors/break_void_result_location.zig +++ b/test/cases/compile_errors/break_void_result_location.zig @@ -10,6 +10,7 @@ export fn f2() void { } export fn f3() void { var t: bool = true; + _ = &t; const x: usize = while (t) { break; }; @@ -28,5 +29,5 @@ export fn f4() void { // // :2:22: error: expected type 'usize', found 'void' // :7:9: error: expected type 'usize', found 'void' -// :14:9: error: expected type 'usize', found 'void' -// :20:9: error: expected type 'usize', found 'void' +// :15:9: error: expected type 'usize', found 'void' +// :21:9: error: expected type 'usize', found 'void' diff --git a/test/cases/compile_errors/c_pointer_to_void.zig b/test/cases/compile_errors/c_pointer_to_void.zig index 116f5a89486f9f1a93ff73ac961270d83d45b4d0..502feb4326b2a06e585ba1b7dff0bd725c061528 100644 --- a/test/cases/compile_errors/c_pointer_to_void.zig +++ b/test/cases/compile_errors/c_pointer_to_void.zig @@ -1,5 +1,5 @@ export fn entry() void { - var a: [*c]void = undefined; + const a: [*c]void = undefined; _ = a; } @@ -7,5 +7,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :2:16: error: C pointers cannot point to non-C-ABI-compatible type 'void' -// :2:16: note: 'void' is a zero bit type; for C 'void' use 'anyopaque' +// :2:18: error: C pointers cannot point to non-C-ABI-compatible type 'void' +// :2:18: note: 'void' is a zero bit type; for C 'void' use 'anyopaque' diff --git a/test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig b/test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig index 9813df24db7cfa32d1c509cc3800a3bc9846affd..3480dc8aa7d32b6bc56f1a55bf09b8a68fe91b34 100644 --- a/test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig +++ b/test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig @@ -2,15 +2,15 @@ const F1 = fn () callconv(.Stdcall) void; const F2 = fn () callconv(.Fastcall) void; const F3 = fn () callconv(.Thiscall) void; export fn entry1() void { - var a: F1 = undefined; + const a: F1 = undefined; _ = a; } export fn entry2() void { - var a: F2 = undefined; + const a: F2 = undefined; _ = a; } export fn entry3() void { - var a: F3 = undefined; + const a: F3 = undefined; _ = a; } diff --git a/test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig b/test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig index fa1fc21568cfebd2651baddaf4e88fd06e4c9e59..1698fdeaedf9fe3df8b2e0d401d0e5fbb6205e66 100644 --- a/test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig +++ b/test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig @@ -4,6 +4,7 @@ export fn entry1() void { var a: fnty1 = undefined; var b: fnty2 = undefined; a = b; + _ = &b; } pub const fnty3 = ?*const fn (u63) void; @@ -11,6 +12,7 @@ export fn entry2() void { var a: fnty3 = undefined; var b: fnty2 = undefined; a = b; + _ = &b; } // error @@ -21,6 +23,6 @@ export fn entry2() void { // :6:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (i8) void' // :6:9: note: parameter 0 'u64' cannot cast into 'i8' // :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values -// :13:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void' -// :13:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void' -// :13:9: note: parameter 0 'u64' cannot cast into 'u63' +// :14:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void' +// :14:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void' +// :14:9: note: parameter 0 'u64' cannot cast into 'u63' diff --git a/test/cases/compile_errors/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig b/test/cases/compile_errors/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig index 36a17d734b20575642811277b2ddfd9a97c9eb82..792fd9fb0d05edc3e70012e3bcc0c3c45946c3d4 100644 --- a/test/cases/compile_errors/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig +++ b/test/cases/compile_errors/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig @@ -1,6 +1,6 @@ const SmallErrorSet = error{A}; export fn entry() void { - var x: SmallErrorSet!i32 = foo(); + const x: SmallErrorSet!i32 = foo(); _ = x; } fn foo() anyerror!i32 { @@ -11,5 +11,5 @@ fn foo() anyerror!i32 { // backend=stage2 // target=native // -// :3:35: error: expected type 'error{A}!i32', found 'anyerror!i32' -// :3:35: note: global error set cannot cast into a smaller set +// :3:37: error: expected type 'error{A}!i32', found 'anyerror!i32' +// :3:37: note: global error set cannot cast into a smaller set diff --git a/test/cases/compile_errors/cast_global_error_set_to_error_set.zig b/test/cases/compile_errors/cast_global_error_set_to_error_set.zig index 39d94740161d37db7d49909f41a72de3c168649c..3d6628b7995b742d8853252700b00b3c4662686c 100644 --- a/test/cases/compile_errors/cast_global_error_set_to_error_set.zig +++ b/test/cases/compile_errors/cast_global_error_set_to_error_set.zig @@ -1,6 +1,6 @@ const SmallErrorSet = error{A}; export fn entry() void { - var x: SmallErrorSet = foo(); + const x: SmallErrorSet = foo(); _ = x; } fn foo() anyerror { @@ -11,5 +11,5 @@ fn foo() anyerror { // backend=stage2 // target=native // -// :3:31: error: expected type 'error{A}', found 'anyerror' -// :3:31: note: global error set cannot cast into a smaller set +// :3:33: error: expected type 'error{A}', found 'anyerror' +// :3:33: note: global error set cannot cast into a smaller set diff --git a/test/cases/compile_errors/catch_on_undefined_value.zig b/test/cases/compile_errors/catch_on_undefined_value.zig index ef041c95391dab4bad402e41bba2d8e64d5e0b71..0fb11fc05f942565c294ba0587fe125faeb840c6 100644 --- a/test/cases/compile_errors/catch_on_undefined_value.zig +++ b/test/cases/compile_errors/catch_on_undefined_value.zig @@ -1,5 +1,5 @@ comptime { - var a: anyerror!bool = undefined; + const a: anyerror!bool = undefined; if (a catch false) {} } diff --git a/test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig b/test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig index 653b7ffcfbbc855ef71047eb07def1add048b7f3..e9746f7e166878836a8fc0becd0d604400e670c9 100644 --- a/test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig +++ b/test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig @@ -1,6 +1,6 @@ export fn entry() void { - var x: ?[3]i32 = undefined; - var y: [3]i32 = undefined; + const x: ?[3]i32 = undefined; + const y: [3]i32 = undefined; _ = (x == y); } diff --git a/test/cases/compile_errors/comparison_operators_with_undefined_value.zig b/test/cases/compile_errors/comparison_operators_with_undefined_value.zig index b7b40d3178bcbfbc71a03954ac9a1bfe6a22c0ca..d4dda81788c240dbf2ed624d1c957b3ec52433d2 100644 --- a/test/cases/compile_errors/comparison_operators_with_undefined_value.zig +++ b/test/cases/compile_errors/comparison_operators_with_undefined_value.zig @@ -1,36 +1,36 @@ // operator == comptime { - var a: i64 = undefined; + const a: i64 = undefined; var x: i32 = 0; if (a == a) x += 1; } // operator != comptime { - var a: i64 = undefined; + const a: i64 = undefined; var x: i32 = 0; if (a != a) x += 1; } // operator > comptime { - var a: i64 = undefined; + const a: i64 = undefined; var x: i32 = 0; if (a > a) x += 1; } // operator < comptime { - var a: i64 = undefined; + const a: i64 = undefined; var x: i32 = 0; if (a < a) x += 1; } // operator >= comptime { - var a: i64 = undefined; + const a: i64 = undefined; var x: i32 = 0; if (a >= a) x += 1; } // operator <= comptime { - var a: i64 = undefined; + const a: i64 = undefined; var x: i32 = 0; if (a <= a) x += 1; } diff --git a/test/cases/compile_errors/compile_error_in_struct_init_expression.zig b/test/cases/compile_errors/compile_error_in_struct_init_expression.zig index 64a97a7a5b0c6d2c29f2cf46066a6ca8d09c9158..9813951a8ba83f5fec4f3dc37517bc345ce38210 100644 --- a/test/cases/compile_errors/compile_error_in_struct_init_expression.zig +++ b/test/cases/compile_errors/compile_error_in_struct_init_expression.zig @@ -3,7 +3,7 @@ const Foo = struct { b: i32, }; export fn entry() void { - var x = Foo{ + const x: Foo = .{ .b = 5, }; _ = x; diff --git a/test/cases/compile_errors/compile_time_null_ptr_cast.zig b/test/cases/compile_errors/compile_time_null_ptr_cast.zig index 7d25931aaaad8ea176407d8c95bb037e6b874360..2142521fd172f61c277036d7013e1d5ff352ded0 100644 --- a/test/cases/compile_errors/compile_time_null_ptr_cast.zig +++ b/test/cases/compile_errors/compile_time_null_ptr_cast.zig @@ -1,5 +1,5 @@ comptime { - var opt_ptr: ?*i32 = null; + const opt_ptr: ?*i32 = null; const ptr: *i32 = @ptrCast(opt_ptr); _ = ptr; } diff --git a/test/cases/compile_errors/compile_time_undef_ptr_cast.zig b/test/cases/compile_errors/compile_time_undef_ptr_cast.zig index d93e8bc73d1beb3417fe87e7031d910b6a4a33a6..9e6bfd8003412d59edf1385e998c7c71629cf541 100644 --- a/test/cases/compile_errors/compile_time_undef_ptr_cast.zig +++ b/test/cases/compile_errors/compile_time_undef_ptr_cast.zig @@ -1,6 +1,7 @@ comptime { var undef_ptr: *i32 = undefined; const ptr: *i32 = @ptrCast(undef_ptr); + _ = &undef_ptr; _ = ptr; } diff --git a/test/cases/compile_errors/comptime_cast_enum_to_union_but_field_has_payload.zig b/test/cases/compile_errors/comptime_cast_enum_to_union_but_field_has_payload.zig index d38738dae727d50d17be0012d115cad073c10aeb..465a0f466e7b5012d06b90d5203a4681a71e829f 100644 --- a/test/cases/compile_errors/comptime_cast_enum_to_union_but_field_has_payload.zig +++ b/test/cases/compile_errors/comptime_cast_enum_to_union_but_field_has_payload.zig @@ -6,7 +6,7 @@ const Value = union(Letter) { }; export fn entry() void { var x: Value = Letter.A; - _ = x; + _ = &x; } // error diff --git a/test/cases/compile_errors/comptime_continue_inside_runtime_if_bool.zig b/test/cases/compile_errors/comptime_continue_inside_runtime_if_bool.zig index b2a7312c529301e7f6371d8350f8b9683defecbb..d3462ed8984310a44042bbd277eda439bb9ab139 100644 --- a/test/cases/compile_errors/comptime_continue_inside_runtime_if_bool.zig +++ b/test/cases/compile_errors/comptime_continue_inside_runtime_if_bool.zig @@ -1,5 +1,6 @@ export fn entry() void { var p: usize = undefined; + _ = &p; comptime var q = true; inline while (q) { if (p == 11) continue; @@ -11,5 +12,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :5:22: error: comptime control flow inside runtime block -// :5:15: note: runtime control flow here +// :6:22: error: comptime control flow inside runtime block +// :6:15: note: runtime control flow here diff --git a/test/cases/compile_errors/comptime_continue_inside_runtime_if_error.zig b/test/cases/compile_errors/comptime_continue_inside_runtime_if_error.zig index 194274a1edf82f3a7a8edea31e242f2a1437a6ba..fb1e60cb3db1ffccf6b08b0db285282fe1cca777 100644 --- a/test/cases/compile_errors/comptime_continue_inside_runtime_if_error.zig +++ b/test/cases/compile_errors/comptime_continue_inside_runtime_if_error.zig @@ -1,5 +1,6 @@ export fn entry() void { var p: anyerror!i32 = undefined; + _ = &p; comptime var q = true; inline while (q) { if (p) |_| continue else |_| {} @@ -11,5 +12,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :5:20: error: comptime control flow inside runtime block -// :5:13: note: runtime control flow here +// :6:20: error: comptime control flow inside runtime block +// :6:13: note: runtime control flow here diff --git a/test/cases/compile_errors/comptime_continue_inside_runtime_if_optional.zig b/test/cases/compile_errors/comptime_continue_inside_runtime_if_optional.zig index 965454ef03f0bf51b2e5cc8dea46486675aa612b..f4837c812e975f9e6a453a90c2f956d745fe2c7a 100644 --- a/test/cases/compile_errors/comptime_continue_inside_runtime_if_optional.zig +++ b/test/cases/compile_errors/comptime_continue_inside_runtime_if_optional.zig @@ -1,5 +1,6 @@ export fn entry() void { var p: ?i32 = undefined; + _ = &p; comptime var q = true; inline while (q) { if (p) |_| continue; @@ -11,5 +12,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :5:20: error: comptime control flow inside runtime block -// :5:13: note: runtime control flow here +// :6:20: error: comptime control flow inside runtime block +// :6:13: note: runtime control flow here diff --git a/test/cases/compile_errors/comptime_continue_inside_runtime_switch.zig b/test/cases/compile_errors/comptime_continue_inside_runtime_switch.zig index 391ecbdf1a2bc48d09427ec4ca905180a8c07cc8..6a23da4cb641f8cae8e83b85fc3ec2a52d115e36 100644 --- a/test/cases/compile_errors/comptime_continue_inside_runtime_switch.zig +++ b/test/cases/compile_errors/comptime_continue_inside_runtime_switch.zig @@ -1,5 +1,6 @@ export fn entry() void { var p: i32 = undefined; + _ = &p; comptime var q = true; inline while (q) { switch (p) { @@ -14,5 +15,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :6:19: error: comptime control flow inside runtime block -// :5:17: note: runtime control flow here +// :7:19: error: comptime control flow inside runtime block +// :6:17: note: runtime control flow here diff --git a/test/cases/compile_errors/comptime_continue_inside_runtime_while_bool.zig b/test/cases/compile_errors/comptime_continue_inside_runtime_while_bool.zig index 54d62e6d371cf1ff3602b6d9e4f3a4e6d61fe28c..55b8b1bde7149ebca3132d335c67282bb80b442a 100644 --- a/test/cases/compile_errors/comptime_continue_inside_runtime_while_bool.zig +++ b/test/cases/compile_errors/comptime_continue_inside_runtime_while_bool.zig @@ -1,5 +1,6 @@ export fn entry() void { var p: usize = undefined; + _ = &p; comptime var q = true; outer: inline while (q) { while (p == 11) continue :outer; @@ -11,5 +12,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :5:25: error: comptime control flow inside runtime block -// :5:18: note: runtime control flow here +// :6:25: error: comptime control flow inside runtime block +// :6:18: note: runtime control flow here diff --git a/test/cases/compile_errors/comptime_continue_inside_runtime_while_error.zig b/test/cases/compile_errors/comptime_continue_inside_runtime_while_error.zig index 0eef1c33745ec04619b57f79ecb0f15bd42c70f1..fe6f3c202e93752ab94b0c11a956da86fce15059 100644 --- a/test/cases/compile_errors/comptime_continue_inside_runtime_while_error.zig +++ b/test/cases/compile_errors/comptime_continue_inside_runtime_while_error.zig @@ -1,5 +1,6 @@ export fn entry() void { var p: anyerror!usize = undefined; + _ = &p; comptime var q = true; outer: inline while (q) { while (p) |_| { @@ -13,5 +14,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :6:13: error: comptime control flow inside runtime block -// :5:16: note: runtime control flow here +// :7:13: error: comptime control flow inside runtime block +// :6:16: note: runtime control flow here diff --git a/test/cases/compile_errors/comptime_continue_inside_runtime_while_optional.zig b/test/cases/compile_errors/comptime_continue_inside_runtime_while_optional.zig index e6753a5911e34415c90f42589bfcc9c19ae355eb..2724af30596cf5bcc44b58d3571df814b490ded3 100644 --- a/test/cases/compile_errors/comptime_continue_inside_runtime_while_optional.zig +++ b/test/cases/compile_errors/comptime_continue_inside_runtime_while_optional.zig @@ -1,5 +1,6 @@ export fn entry() void { var p: ?usize = undefined; + _ = &p; comptime var q = true; outer: inline while (q) { while (p) |_| continue :outer; @@ -11,5 +12,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :5:23: error: comptime control flow inside runtime block -// :5:16: note: runtime control flow here +// :6:23: error: comptime control flow inside runtime block +// :6:16: note: runtime control flow here diff --git a/test/cases/compile_errors/comptime_continue_to_outer_inline_loop.zig b/test/cases/compile_errors/comptime_continue_to_outer_inline_loop.zig index 5e6a321db26c77ef23c42c0bf33ec715970893b9..e9fb8c0066de0d6feacd95244a35be2be774eaa9 100644 --- a/test/cases/compile_errors/comptime_continue_to_outer_inline_loop.zig +++ b/test/cases/compile_errors/comptime_continue_to_outer_inline_loop.zig @@ -1,5 +1,6 @@ pub export fn entry() void { var a = false; + _ = &a; const arr1 = .{ 1, 2, 3 }; loop: inline for (arr1) |val1| { _ = val1; @@ -17,5 +18,5 @@ pub export fn entry() void { // backend=stage2 // target=native // -// :9:30: error: comptime control flow inside runtime block -// :6:13: note: runtime control flow here +// :10:30: error: comptime control flow inside runtime block +// :7:13: note: runtime control flow here diff --git a/test/cases/compile_errors/comptime_if_inside_runtime_for.zig b/test/cases/compile_errors/comptime_if_inside_runtime_for.zig index 40055a70b9b86d7142359cc4c133bd7fa19b3482..425eb99e9c9faad90d5a2f022c5cb135c9f8e411 100644 --- a/test/cases/compile_errors/comptime_if_inside_runtime_for.zig +++ b/test/cases/compile_errors/comptime_if_inside_runtime_for.zig @@ -1,8 +1,9 @@ export fn entry() void { var x: u32 = 0; + _ = &x; for (0..1, 1..2) |_, _| { var y = x + if (x == 0) 1 else 0; - _ = y; + _ = &y; } } @@ -10,5 +11,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :4:21: error: value with comptime-only type 'comptime_int' depends on runtime control flow -// :3:10: note: runtime control flow here +// :5:21: error: value with comptime-only type 'comptime_int' depends on runtime control flow +// :4:10: note: runtime control flow here diff --git a/test/cases/compile_errors/comptime_slice_of_an_undefined_slice.zig b/test/cases/compile_errors/comptime_slice_of_an_undefined_slice.zig index d1b22d86b7f1f08db6257c4d98138e518bd2b389..aa3719816c692d88f96fdeb66d51b6557ebaef1e 100644 --- a/test/cases/compile_errors/comptime_slice_of_an_undefined_slice.zig +++ b/test/cases/compile_errors/comptime_slice_of_an_undefined_slice.zig @@ -1,7 +1,7 @@ comptime { var a: []u8 = undefined; var b = a[0..10]; - _ = b; + _ = &b; } // error diff --git a/test/cases/compile_errors/comptime_struct_field_no_init_value.zig b/test/cases/compile_errors/comptime_struct_field_no_init_value.zig index c0cb470eeeb3ba05e618362e532204ded04f1d3f..95ace475305870ed16cb5435d385f537926a14c5 100644 --- a/test/cases/compile_errors/comptime_struct_field_no_init_value.zig +++ b/test/cases/compile_errors/comptime_struct_field_no_init_value.zig @@ -3,7 +3,7 @@ const Foo = struct { }; export fn entry() void { var f: Foo = undefined; - _ = f; + _ = &f; } // error diff --git a/test/cases/compile_errors/comptime_vector_overflow_shows_the_index.zig b/test/cases/compile_errors/comptime_vector_overflow_shows_the_index.zig index fda8ffe4537402c0e723ba985303dbd444a22723..ace946453ecf1c11c522342fb6f0c5ac7b68686c 100644 --- a/test/cases/compile_errors/comptime_vector_overflow_shows_the_index.zig +++ b/test/cases/compile_errors/comptime_vector_overflow_shows_the_index.zig @@ -2,7 +2,7 @@ comptime { var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; var x = a + b; - _ = x; + _ = .{ &a, &b, &x }; } // error diff --git a/test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig b/test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig index 1ce744d6d7e09ff89b667510cbd477b7d72d37da..6efed3eb8131fd4c85b1b9e105d523efd47bbf94 100644 --- a/test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig +++ b/test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig @@ -1,9 +1,7 @@ const ContextAllocator = MemoryPool(usize); pub fn MemoryPool(comptime T: type) type { - const free_list_t = @compileError( - "aoeu", - ); + const free_list_t = @compileError("aoeu"); _ = T; return struct { @@ -12,7 +10,7 @@ pub fn MemoryPool(comptime T: type) type { } export fn entry() void { - var allocator: ContextAllocator = undefined; + const allocator: ContextAllocator = undefined; _ = allocator; } diff --git a/test/cases/compile_errors/deref_on_undefined_value.zig b/test/cases/compile_errors/deref_on_undefined_value.zig index fa12e2824cad3e1794a6d1bad893d4d8f8198af6..81d0fbda1b503038ee97a09b88da6c291af30651 100644 --- a/test/cases/compile_errors/deref_on_undefined_value.zig +++ b/test/cases/compile_errors/deref_on_undefined_value.zig @@ -1,5 +1,5 @@ comptime { - var a: *u8 = undefined; + const a: *u8 = undefined; _ = a.*; } diff --git a/test/cases/compile_errors/deref_slice_and_get_len_field.zig b/test/cases/compile_errors/deref_slice_and_get_len_field.zig index 1ba03c6d50cf90ad0c647ec3552f24fb0d5bcc5e..2550c88d27404bc015257b4e61a2b5ab6caccf9a 100644 --- a/test/cases/compile_errors/deref_slice_and_get_len_field.zig +++ b/test/cases/compile_errors/deref_slice_and_get_len_field.zig @@ -1,6 +1,7 @@ export fn entry() void { var a: []u8 = undefined; _ = a.*.len; + _ = &a; } // error diff --git a/test/cases/compile_errors/dereference_an_array.zig b/test/cases/compile_errors/dereference_an_array.zig index 27e4d81e5550148c4c21eedb28a01d34d300ba99..7c71da914def49b7127c04df865a178b4c9cf48c 100644 --- a/test/cases/compile_errors/dereference_an_array.zig +++ b/test/cases/compile_errors/dereference_an_array.zig @@ -1,6 +1,7 @@ var s_buffer: [10]u8 = undefined; pub fn pass(in: []u8) []u8 { var out = &s_buffer; + _ = &out; out.*.* = in[0]; return out.*[0..1]; } @@ -13,4 +14,4 @@ export fn entry() usize { // backend=stage2 // target=native // -// :4:10: error: cannot dereference non-pointer type '[10]u8' +// :5:10: error: cannot dereference non-pointer type '[10]u8' diff --git a/test/cases/compile_errors/dereferencing_invalid_payload_ptr_at_comptime.zig b/test/cases/compile_errors/dereferencing_invalid_payload_ptr_at_comptime.zig index 69457965bb28a5f2d910ef2c30ab3ec337c9f8fc..17117713ed60f41f29e78556242d0fa848ee8126 100644 --- a/test/cases/compile_errors/dereferencing_invalid_payload_ptr_at_comptime.zig +++ b/test/cases/compile_errors/dereferencing_invalid_payload_ptr_at_comptime.zig @@ -16,7 +16,7 @@ comptime { _ = payload_ptr.*; } comptime { - var val: u8 = 15; + const val: u8 = 15; var err_union: anyerror!u8 = val; const payload_ptr = &(err_union catch unreachable); diff --git a/test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig b/test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig index d9f27da4aa66d647893922243b834c69358a90b1..7fc562fd69240a6a32353edcfa299e6026074407 100644 --- a/test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig +++ b/test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig @@ -8,11 +8,11 @@ const Bar = union { }; export fn a() void { var foo: Foo = undefined; - _ = foo; + _ = &foo; } export fn b() void { var bar: Bar = undefined; - _ = bar; + _ = &bar; } export fn c() void { const baz = &@as(O, undefined); diff --git a/test/cases/compile_errors/div_on_undefined_value.zig b/test/cases/compile_errors/div_on_undefined_value.zig index 8365cdfa73d1a7cbc18a2a1aeee49c419a347919..bc2cfa158d1137a03429a5a36ed296d3d5fef315 100644 --- a/test/cases/compile_errors/div_on_undefined_value.zig +++ b/test/cases/compile_errors/div_on_undefined_value.zig @@ -1,6 +1,7 @@ comptime { var a: i64 = undefined; _ = a / a; + _ = &a; } // error diff --git a/test/cases/compile_errors/double_pointer_to_anyopaque_pointer.zig b/test/cases/compile_errors/double_pointer_to_anyopaque_pointer.zig index c695b7393dcbb94f1528673288a7386e28fbc4ad..dbebf07e0b01c2e2ab51b6f96b19bfb079dae51d 100644 --- a/test/cases/compile_errors/double_pointer_to_anyopaque_pointer.zig +++ b/test/cases/compile_errors/double_pointer_to_anyopaque_pointer.zig @@ -11,12 +11,13 @@ pub export fn entry2() void { fn func(_: ?*anyopaque) void {} pub export fn entry3() void { var x: *?*usize = undefined; - + _ = &x; const ptr: *const anyopaque = x; _ = ptr; } export fn entry4() void { var a: []*u32 = undefined; + _ = &a; var b: []anyopaque = undefined; b = a; } @@ -32,5 +33,5 @@ export fn entry4() void { // :11:12: note: parameter type declared here // :15:35: error: expected type '*const anyopaque', found '*?*usize' // :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque' -// :21:9: error: expected type '[]anyopaque', found '[]*u32' -// :21:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque' +// :22:9: error: expected type '[]anyopaque', found '[]*u32' +// :22:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque' diff --git a/test/cases/compile_errors/empty_switch_on_an_integer.zig b/test/cases/compile_errors/empty_switch_on_an_integer.zig index 6ba69f8d3e8762797e11aaf50648117a69db96a0..5ac9ed454fa38471155086c51d05aa96345d07ce 100644 --- a/test/cases/compile_errors/empty_switch_on_an_integer.zig +++ b/test/cases/compile_errors/empty_switch_on_an_integer.zig @@ -1,5 +1,5 @@ export fn entry() void { - var x: u32 = 0; + const x: u32 = 0; switch (x) {} } diff --git a/test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig b/test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig index 7dab294d4a109e7d27f7d68ce659c2adbedd9280..498a0c80b7ab271d5a2e68e8a0bdc907cb5c0978 100644 --- a/test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig +++ b/test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig @@ -1,7 +1,7 @@ pub export fn entry() void { const E = enum(comptime_int) { a, b, c, _ }; var e: E = .a; - _ = e; + _ = &e; } // error diff --git a/test/cases/compile_errors/enum_field_value_references_enum.zig b/test/cases/compile_errors/enum_field_value_references_enum.zig index b2b73b15247f740cc0d634a40f647899f334468f..7c258adce71f4296c9c2dc30a83f64f576015d1c 100644 --- a/test/cases/compile_errors/enum_field_value_references_enum.zig +++ b/test/cases/compile_errors/enum_field_value_references_enum.zig @@ -3,7 +3,7 @@ pub const Foo = enum(c_int) { C = D, }; export fn entry() void { - var s: Foo = Foo.E; + const s: Foo = Foo.E; _ = s; } const D = 1; diff --git a/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig b/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig index 3e1190cc32d224ee4b6836f9bf1dc792aec24df5..74df2d3de948cbd93226e7633fc616f62bf95522 100644 --- a/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig +++ b/test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig @@ -3,7 +3,7 @@ const Foo = enum(u32) { B = 11, }; export fn entry() void { - var x: Foo = @enumFromInt(0); + const x: Foo = @enumFromInt(0); _ = x; } @@ -11,5 +11,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :6:18: error: enum 'tmp.Foo' has no tag with value '0' +// :6:20: error: enum 'tmp.Foo' has no tag with value '0' // :1:13: note: enum declared here diff --git a/test/cases/compile_errors/enum_value_already_taken.zig b/test/cases/compile_errors/enum_value_already_taken.zig index 733585a7488dcebb3db8556e95ba9551520219a5..e3a13785e1dd62438bbe900fa7f4b0f25e066b61 100644 --- a/test/cases/compile_errors/enum_value_already_taken.zig +++ b/test/cases/compile_errors/enum_value_already_taken.zig @@ -6,7 +6,7 @@ const MultipleChoice = enum(u32) { E = 60, }; export fn entry() void { - var x = MultipleChoice.C; + const x = MultipleChoice.C; _ = x; } diff --git a/test/cases/compile_errors/error_in_struct_initializer_doesnt_crash_the_compiler.zig b/test/cases/compile_errors/error_in_struct_initializer_doesnt_crash_the_compiler.zig index c0b1193fb1331f66f87d3c105704584d9f2814bf..515ac855ce2ca6956eacaa5759bdb3aa238d5088 100644 --- a/test/cases/compile_errors/error_in_struct_initializer_doesnt_crash_the_compiler.zig +++ b/test/cases/compile_errors/error_in_struct_initializer_doesnt_crash_the_compiler.zig @@ -4,7 +4,7 @@ pub export fn entry() void { e: u8, }; var a = .{@sizeOf(bitfield)}; - _ = a; + _ = &a; } // error diff --git a/test/cases/compile_errors/error_union_operator_with_non_error_set_LHS.zig b/test/cases/compile_errors/error_union_operator_with_non_error_set_LHS.zig index cafca1ee55bd6c15afc4d3590d5974955c3a9af2..e20b2861cc2579649dcac4bee76bf5313867c428 100644 --- a/test/cases/compile_errors/error_union_operator_with_non_error_set_LHS.zig +++ b/test/cases/compile_errors/error_union_operator_with_non_error_set_LHS.zig @@ -1,6 +1,6 @@ comptime { const z = i32!i32; - var x: z = undefined; + const x: z = undefined; _ = x; } diff --git a/test/cases/compile_errors/error_when_evaluating_return_type.zig b/test/cases/compile_errors/error_when_evaluating_return_type.zig index 647b51b475895df5652e34942dfcd26a477a34bd..08e19cd46ae0672bdf180b0809490d89ded6361e 100644 --- a/test/cases/compile_errors/error_when_evaluating_return_type.zig +++ b/test/cases/compile_errors/error_when_evaluating_return_type.zig @@ -6,7 +6,7 @@ const Foo = struct { } }; export fn entry() void { - var rule_set = try Foo.init(); + const rule_set = try Foo.init(); _ = rule_set; } diff --git a/test/cases/compile_errors/explain_why_generic_fn_is_called_at_comptime.zig b/test/cases/compile_errors/explain_why_generic_fn_is_called_at_comptime.zig index 701241a403b1eedabbcf6e59594fb433b8a9f9e0..aada601c79bf49a4183292a28b23610bedfddb59 100644 --- a/test/cases/compile_errors/explain_why_generic_fn_is_called_at_comptime.zig +++ b/test/cases/compile_errors/explain_why_generic_fn_is_called_at_comptime.zig @@ -11,12 +11,13 @@ fn foo(a: u8, comptime PtrTy: type) S(PtrTy) { } pub export fn entry() void { var a: u8 = 1; + _ = &a; _ = foo(a, fn () void); } // error // backend=stage2 // target=native // -// :14:13: error: unable to resolve comptime value -// :14:13: note: argument to function being called at comptime must be comptime-known +// :15:13: error: unable to resolve comptime value +// :15:13: note: argument to function being called at comptime must be comptime-known // :9:38: note: expression is evaluated at comptime because the generic function was instantiated with a comptime-only return type diff --git a/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig b/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig index fedfaf2d07067cf12a6218bc7c076d01481394bf..a1beac65f2f228e0593990eeec62cbd977c9d414 100644 --- a/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig +++ b/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig @@ -1,8 +1,8 @@ const Set1 = error{ A, B }; const Set2 = error{ A, C }; comptime { - var x = Set1.B; - var y: Set2 = @errorCast(x); + const x = Set1.B; + const y: Set2 = @errorCast(x); _ = y; } @@ -10,4 +10,4 @@ comptime { // backend=stage2 // target=native // -// :5:19: error: 'error.B' not a member of error set 'error{C,A}' +// :5:21: error: 'error.B' not a member of error set 'error{C,A}' diff --git a/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig b/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig index bb920138e1b3e1bb7ccc6b31e3d8da6ace77ff18..05189c7b0c6fe50f88bdf67c0cdb1e0ac8130822 100644 --- a/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig +++ b/test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig @@ -7,7 +7,7 @@ const Small = enum(u2) { export fn entry() void { var y = @as(f32, 3); - var x: Small = @enumFromInt(y); + const x: Small = @enumFromInt((&y).*); _ = x; } @@ -15,4 +15,4 @@ export fn entry() void { // backend=stage2 // target=native // -// :10:33: error: expected integer type, found 'f32' +// :10:39: error: expected integer type, found 'f32' diff --git a/test/cases/compile_errors/extern_union_field_missing_type.zig b/test/cases/compile_errors/extern_union_field_missing_type.zig index fde58f69e5e288b91cb1508f4d772e4f4bb46786..9720ff90f1074ed3fa96d31bf199ac8b7e22cb85 100644 --- a/test/cases/compile_errors/extern_union_field_missing_type.zig +++ b/test/cases/compile_errors/extern_union_field_missing_type.zig @@ -2,7 +2,7 @@ const Letter = extern union { A, }; export fn entry() void { - var a = Letter{ .A = {} }; + const a: Letter = .{ .A = {} }; _ = a; } diff --git a/test/cases/compile_errors/extern_union_given_enum_tag_type.zig b/test/cases/compile_errors/extern_union_given_enum_tag_type.zig index 4aa0e623c796428b97e6ed616c1b9dde442f531c..93eefea1447cda40c4c75739075c80d1f04b430e 100644 --- a/test/cases/compile_errors/extern_union_given_enum_tag_type.zig +++ b/test/cases/compile_errors/extern_union_given_enum_tag_type.zig @@ -9,7 +9,7 @@ const Payload = extern union(Letter) { C: bool, }; export fn entry() void { - var a = Payload{ .A = 1234 }; + const a: Payload = .{ .A = 1234 }; _ = a; } diff --git a/test/cases/compile_errors/field_access_of_slices.zig b/test/cases/compile_errors/field_access_of_slices.zig index 1fbfda9646916ac61a61afe496065ca012a3dbeb..c7fe0d8b40c3e85664cb49059cc91c0da96c5383 100644 --- a/test/cases/compile_errors/field_access_of_slices.zig +++ b/test/cases/compile_errors/field_access_of_slices.zig @@ -1,5 +1,6 @@ export fn entry() void { var slice: []i32 = undefined; + _ = &slice; const info = @TypeOf(slice).unknown; _ = info; } @@ -8,5 +9,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :3:32: error: type '[]i32' has no members -// :3:32: note: slice values have 'len' and 'ptr' members +// :4:32: error: type '[]i32' has no members +// :4:32: note: slice values have 'len' and 'ptr' members diff --git a/test/cases/compile_errors/for.zig b/test/cases/compile_errors/for.zig index 568c416062f19e4050b6f8cb48a0f5b18255ddfa..4c25f9d93f05abf597e3ebb555191882e3468b45 100644 --- a/test/cases/compile_errors/for.zig +++ b/test/cases/compile_errors/for.zig @@ -17,6 +17,7 @@ export fn c() void { for (buf) |*byte| { _ = byte; } + _ = &buf; } export fn d() void { const x: [*]const u8 = "hello"; @@ -39,6 +40,6 @@ export fn d() void { // :10:14: note: for loop operand must be a range, array, slice, tuple, or vector // :17:16: error: pointer capture of non pointer type '[10]u8' // :17:10: note: consider using '&' here -// :24:5: error: unbounded for loop -// :24:10: note: type '[*]const u8' has no upper bound -// :24:18: note: type '[*]const u8' has no upper bound +// :25:5: error: unbounded for loop +// :25:10: note: type '[*]const u8' has no upper bound +// :25:18: note: type '[*]const u8' has no upper bound diff --git a/test/cases/compile_errors/for_loop_body_expression_ignored.zig b/test/cases/compile_errors/for_loop_body_expression_ignored.zig index 3ce73a9fabaa369041270fa40c340b423e06a531..a0247139ea18361b2f37642e3559fa8bb8f32d7d 100644 --- a/test/cases/compile_errors/for_loop_body_expression_ignored.zig +++ b/test/cases/compile_errors/for_loop_body_expression_ignored.zig @@ -7,7 +7,7 @@ export fn f1() void { export fn f2() void { var x: anyerror!i32 = error.Bad; for ("hello") |_| returns() else unreachable; - _ = x; + _ = &x; } export fn f3() void { for ("hello") |_| {} else true; diff --git a/test/cases/compile_errors/function_ptr_alignment.zig b/test/cases/compile_errors/function_ptr_alignment.zig index fabee524c7c7725ba58b1595c1ea4e9f9cc89700..995ef8d9b1cbf8035e36a3745287146d5fe416f1 100644 --- a/test/cases/compile_errors/function_ptr_alignment.zig +++ b/test/cases/compile_errors/function_ptr_alignment.zig @@ -1,24 +1,24 @@ comptime { var a: *align(2) @TypeOf(foo) = undefined; - _ = a; + _ = &a; } fn foo() void {} comptime { var a: *align(1) fn () void = undefined; - _ = a; + _ = &a; } comptime { var a: *align(2) fn () align(2) void = undefined; - _ = a; + _ = &a; } comptime { var a: *align(2) fn () void = undefined; - _ = a; + _ = &a; } comptime { var a: *align(1) fn () align(2) void = undefined; - _ = a; + _ = &a; } // error diff --git a/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig b/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig index c730f80e6f4282478e344a63a82ed7f659b5b555..9a8d765c0416ec906c646fc976457ffde6834390 100644 --- a/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig +++ b/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig @@ -3,6 +3,7 @@ const std = @import("std"); pub export fn entry() void { var ohnoes: *usize = undefined; _ = sliceAsBytes(ohnoes); + _ = &ohnoes; } fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) {} @@ -10,4 +11,4 @@ fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) { // backend=llvm // target=native // -// :7:63: error: expected type 'type', found 'bool' +// :8:63: error: expected type 'type', found 'bool' diff --git a/test/cases/compile_errors/generic_method_call_with_invalid_param.zig b/test/cases/compile_errors/generic_method_call_with_invalid_param.zig index ccea6708e4e565e436dc89b054b63162c86f0de5..6ce431461b78562e0a73bc3d5a17f54611567e24 100644 --- a/test/cases/compile_errors/generic_method_call_with_invalid_param.zig +++ b/test/cases/compile_errors/generic_method_call_with_invalid_param.zig @@ -11,6 +11,7 @@ export fn callVoidMethodWithBool() void { export fn callComptimeBoolMethodWithRuntimeBool() void { const s = S{}; var arg = true; + _ = &arg; s.comptimeBoolMethod(arg); } @@ -25,8 +26,8 @@ const S = struct { // target=native // // :3:18: error: expected type 'bool', found 'void' -// :18:43: note: parameter type declared here -// :8:18: error: expected type 'void', found 'bool' // :19:43: note: parameter type declared here -// :14:26: error: runtime-known argument passed to comptime parameter -// :20:57: note: declared comptime here +// :8:18: error: expected type 'void', found 'bool' +// :20:43: note: parameter type declared here +// :15:26: error: runtime-known argument passed to comptime parameter +// :21:57: note: declared comptime here diff --git a/test/cases/compile_errors/ignored_expression_in_while_continuation.zig b/test/cases/compile_errors/ignored_expression_in_while_continuation.zig index d108903c82189767de44dc831f4bae600feb3419..4fa396190a58501cc9b65bc527113d3470e17225 100644 --- a/test/cases/compile_errors/ignored_expression_in_while_continuation.zig +++ b/test/cases/compile_errors/ignored_expression_in_while_continuation.zig @@ -3,10 +3,12 @@ export fn a() void { } export fn b() void { var x: anyerror!i32 = 1234; + _ = &x; while (x) |_| : (bad()) {} else |_| {} } export fn c() void { var x: ?i32 = 1234; + _ = &x; while (x) |_| : (bad()) {} } fn bad() anyerror!void { @@ -19,7 +21,7 @@ fn bad() anyerror!void { // // :2:24: error: error is ignored // :2:24: note: consider using 'try', 'catch', or 'if' -// :6:25: error: error is ignored -// :6:25: note: consider using 'try', 'catch', or 'if' -// :10:25: error: error is ignored -// :10:25: note: consider using 'try', 'catch', or 'if' +// :7:25: error: error is ignored +// :7:25: note: consider using 'try', 'catch', or 'if' +// :12:25: error: error is ignored +// :12:25: note: consider using 'try', 'catch', or 'if' diff --git a/test/cases/compile_errors/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig b/test/cases/compile_errors/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig index 78261f182fdd3966b0d21d95bea8f27f116425ef..d30db5733d8ee4c5a8b980022a5a48be3ea194ea 100644 --- a/test/cases/compile_errors/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig +++ b/test/cases/compile_errors/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig @@ -1,32 +1,32 @@ export fn a() void { var x: [*c]u8 = undefined; var y: *align(4) u8 = x; - _ = y; + _ = .{ &x, &y }; } export fn b() void { var x: [*c]const u8 = undefined; var y: *u8 = x; - _ = y; + _ = .{ &x, &y }; } export fn c() void { var x: [*c]u8 = undefined; var y: *u32 = x; - _ = y; + _ = .{ &x, &y }; } export fn d() void { var y: *align(1) u32 = undefined; var x: [*c]u32 = y; - _ = x; + _ = .{ &x, &y }; } export fn e() void { var y: *const u8 = undefined; var x: [*c]u8 = y; - _ = x; + _ = .{ &x, &y }; } export fn f() void { var y: *u8 = undefined; var x: [*c]u32 = y; - _ = x; + _ = .{ &x, &y }; } // error diff --git a/test/cases/compile_errors/implicit_cast_from_f64_to_f32.zig b/test/cases/compile_errors/implicit_cast_from_f64_to_f32.zig index da4503cefea742222bdb12851e27fc217a2c8d2a..a8d4675ac897c52cea2253d334c274970a8df4d6 100644 --- a/test/cases/compile_errors/implicit_cast_from_f64_to_f32.zig +++ b/test/cases/compile_errors/implicit_cast_from_f64_to_f32.zig @@ -7,7 +7,7 @@ export fn entry() void { export fn entry2() void { var x1: f64 = 1.0; var y2: f32 = x1; - _ = y2; + _ = .{ &x1, &y2 }; } // error diff --git a/test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig b/test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig index 5e5b57680c806c387d8dbde1dbfbd48df4bada6d..617e6386274df81ab05fb26b2296da442312d55c 100644 --- a/test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig +++ b/test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig @@ -4,7 +4,7 @@ export fn entry() void { foo(Set1.B); } fn foo(set1: Set1) void { - var x: Set2 = set1; + const x: Set2 = set1; _ = x; } @@ -12,5 +12,5 @@ fn foo(set1: Set1) void { // backend=stage2 // target=native // -// :7:19: error: expected type 'error{C,A}', found 'error{A,B}' -// :7:19: note: 'error.B' not a member of destination error set +// :7:21: error: expected type 'error{C,A}', found 'error{A,B}' +// :7:21: note: 'error.B' not a member of destination error set diff --git a/test/cases/compile_errors/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig b/test/cases/compile_errors/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig index ecdc6c14c9bb7f2e60a026ebbb96c9639f76d3a0..ed3c402ef9273190ea34a344b1864e87e044dc13 100644 --- a/test/cases/compile_errors/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig +++ b/test/cases/compile_errors/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig @@ -4,6 +4,9 @@ export fn entry() void { var ptr_opt_many_ptr = &opt_many_ptr; var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; ptr_opt_many_ptr = c_ptr; + _ = &slice; + _ = &ptr_opt_many_ptr; + _ = &c_ptr; } export fn entry2() void { var buf: [4]u8 = "aoeu".*; @@ -11,7 +14,9 @@ export fn entry2() void { var opt_many_ptr: [*]u8 = slice.ptr; var ptr_opt_many_ptr = &opt_many_ptr; var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; - _ = c_ptr; + _ = &slice; + _ = &ptr_opt_many_ptr; + _ = &c_ptr; } // error @@ -21,6 +26,6 @@ export fn entry2() void { // :6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8' // :6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8' // :6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8' -// :13:35: error: expected type '[*c][*c]const u8', found '*[*]u8' -// :13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8' -// :13:35: note: mutable '[*]u8' allows illegal null values stored to type '[*c]const u8' +// :16:35: error: expected type '[*c][*c]const u8', found '*[*]u8' +// :16:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8' +// :16:35: note: mutable '[*]u8' allows illegal null values stored to type '[*c]const u8' diff --git a/test/cases/compile_errors/implicit_casting_null_c_pointer_to_zig_pointer.zig b/test/cases/compile_errors/implicit_casting_null_c_pointer_to_zig_pointer.zig index b51635ad30c0329b2275b538e53490dabb5b6ee4..3738f89492c1b1b3f389a1c9c16bcbd16925da39 100644 --- a/test/cases/compile_errors/implicit_casting_null_c_pointer_to_zig_pointer.zig +++ b/test/cases/compile_errors/implicit_casting_null_c_pointer_to_zig_pointer.zig @@ -1,6 +1,7 @@ comptime { var c_ptr: [*c]u8 = 0; - var zig_ptr: *u8 = c_ptr; + const zig_ptr: *u8 = c_ptr; + _ = &c_ptr; _ = zig_ptr; } @@ -8,4 +9,4 @@ comptime { // backend=stage2 // target=native // -// :3:24: error: null pointer casted to type '*u8' +// :3:26: error: null pointer casted to type '*u8' diff --git a/test/cases/compile_errors/implicitly_casting_enum_to_tag_type.zig b/test/cases/compile_errors/implicitly_casting_enum_to_tag_type.zig index 2f7686c93d7e001fe67ae47f88576ed790df7f7c..28d3c2445ec2fa58988bb1e91077cc37376b7175 100644 --- a/test/cases/compile_errors/implicitly_casting_enum_to_tag_type.zig +++ b/test/cases/compile_errors/implicitly_casting_enum_to_tag_type.zig @@ -7,7 +7,7 @@ const Small = enum(u2) { export fn entry() void { var x: u2 = Small.Two; - _ = x; + _ = &x; } // error diff --git a/test/cases/compile_errors/incompatible sub-byte fields.zig b/test/cases/compile_errors/incompatible sub-byte fields.zig index dc6f715c2f2e976c2f2519d3bbe007ca0181b847..caadf6c5d95e76c20dbe4747c651881f221b12ac 100644 --- a/test/cases/compile_errors/incompatible sub-byte fields.zig +++ b/test/cases/compile_errors/incompatible sub-byte fields.zig @@ -11,6 +11,7 @@ export fn entry() void { var a = A{ .a = 2, .b = 2 }; var b = B{ .q = 22, .a = 3, .b = 2 }; var t: usize = 0; + _ = &t; const ptr = switch (t) { 0 => &a.a, 1 => &b.a, @@ -24,6 +25,6 @@ export fn entry() void { // backend=stage2 // target=native // -// :14:17: error: incompatible types: '*align(1:0:1) u2' and '*align(2:8:2) u2' -// :15:14: note: type '*align(1:0:1) u2' here -// :16:14: note: type '*align(2:8:2) u2' here +// :15:17: error: incompatible types: '*align(1:0:1) u2' and '*align(2:8:2) u2' +// :16:14: note: type '*align(1:0:1) u2' here +// :17:14: note: type '*align(2:8:2) u2' here diff --git a/test/cases/compile_errors/incompatible_sentinels.zig b/test/cases/compile_errors/incompatible_sentinels.zig index 821a0a8c6993a7873443f92e5df3635ae21efbfe..169a69a75a510a17e54eaf0a78873ae10dc94881 100644 --- a/test/cases/compile_errors/incompatible_sentinels.zig +++ b/test/cases/compile_errors/incompatible_sentinels.zig @@ -8,11 +8,11 @@ export fn entry2(ptr: [*]u8) [*:0]u8 { } export fn entry3() void { var array: [2:0]u8 = [_:255]u8{ 1, 2 }; - _ = array; + _ = &array; } export fn entry4() void { var array: [2:0]u8 = [_]u8{ 1, 2 }; - _ = array; + _ = &array; } // error diff --git a/test/cases/compile_errors/incorrect_pointer_dereference_syntax.zig b/test/cases/compile_errors/incorrect_pointer_dereference_syntax.zig index 33b5d1f3b633e16ed657c697af9ee726e8843613..4f80b6186507f588894d291821a3a189ca388052 100644 --- a/test/cases/compile_errors/incorrect_pointer_dereference_syntax.zig +++ b/test/cases/compile_errors/incorrect_pointer_dereference_syntax.zig @@ -1,6 +1,7 @@ pub export fn entry() void { var a: *u32 = undefined; _ = *a; + _ = &a; } // error diff --git a/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig b/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig index 55af9c1185fd9714c2f9af84bed12b08afc9a6c5..26b31dd50662807e514adf041bd07c844d10443a 100644 --- a/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig +++ b/test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig @@ -1,17 +1,17 @@ pub export fn entry() void { var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; - var slice: []u8 = &buf; + const slice: []u8 = &buf; const a: u32 = 1234; @memcpy(slice.ptr, @as([*]const u8, @ptrCast(&a))); } pub export fn entry1() void { var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; - var ptr: *u8 = &buf[0]; + const ptr: *u8 = &buf[0]; @memcpy(ptr, 0); } pub export fn entry2() void { var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; - var ptr: *u8 = &buf[0]; + const ptr: *u8 = &buf[0]; @memset(ptr, 0); } pub export fn non_matching_lengths() void { @@ -29,7 +29,7 @@ pub export fn memcpy_const_dest_ptr() void { @memcpy(&buf1, &buf2); } pub export fn memset_array() void { - var buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; + const buf: [5]u8 = .{ 1, 2, 3, 4, 5 }; @memcpy(buf, 1); } diff --git a/test/cases/compile_errors/indexing_an_array_of_size_zero_with_runtime_index.zig b/test/cases/compile_errors/indexing_an_array_of_size_zero_with_runtime_index.zig index eceb5db50e18423a4b9480e887b6d49b12af4e82..21991c66ebc7dd448d888bfd674d3dbe9569e281 100644 --- a/test/cases/compile_errors/indexing_an_array_of_size_zero_with_runtime_index.zig +++ b/test/cases/compile_errors/indexing_an_array_of_size_zero_with_runtime_index.zig @@ -1,6 +1,7 @@ const array = [_]u8{}; export fn foo() void { var index: usize = 0; + _ = &index; const pointer = &array[index]; _ = pointer; } @@ -9,4 +10,4 @@ export fn foo() void { // backend=stage2 // target=native // -// :4:27: error: indexing into empty array is not allowed +// :5:27: error: indexing into empty array is not allowed diff --git a/test/cases/compile_errors/inline_call_runtime_value_to_comptime_param.zig b/test/cases/compile_errors/inline_call_runtime_value_to_comptime_param.zig index cddd91384b2e928cb0af5c4a34dec88917feaa04..2b3738cd2f7e6f0e37f3617f4f709ed701e8e713 100644 --- a/test/cases/compile_errors/inline_call_runtime_value_to_comptime_param.zig +++ b/test/cases/compile_errors/inline_call_runtime_value_to_comptime_param.zig @@ -6,7 +6,7 @@ fn acceptRuntime(value: u64) void { } pub export fn entry() void { var value: u64 = 0; - acceptRuntime(value); + acceptRuntime((&value).*); } // error diff --git a/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig b/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig index 772463206992de543c5045ec33127658541d3bc4..d6bf372a88ce5554f3da12d2768bc132cde3555c 100644 --- a/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig +++ b/test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig @@ -1,9 +1,11 @@ export fn foo() void { var a: f32 = 2; + _ = &a; _ = @as(comptime_int, @intFromFloat(a)); } export fn bar() void { var a: u32 = 2; + _ = &a; _ = @as(comptime_float, @floatFromInt(a)); } @@ -11,7 +13,7 @@ export fn bar() void { // backend=stage2 // target=native // -// :3:41: error: unable to resolve comptime value -// :3:41: note: value being casted to 'comptime_int' must be comptime-known -// :7:43: error: unable to resolve comptime value -// :7:43: note: value being casted to 'comptime_float' must be comptime-known +// :4:41: error: unable to resolve comptime value +// :4:41: note: value being casted to 'comptime_int' must be comptime-known +// :9:43: error: unable to resolve comptime value +// :9:43: note: value being casted to 'comptime_float' must be comptime-known diff --git a/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig b/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig index e443b3daa962a34feadbdf7b6d0e5594705470ce..1c2a8215d76b13de21c8f5c714a217fee8922ec0 100644 --- a/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig +++ b/test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig @@ -1,5 +1,5 @@ export fn entry() void { - var b: *i32 = @ptrFromInt(0); + const b: *i32 = @ptrFromInt(0); _ = b; } @@ -7,4 +7,4 @@ export fn entry() void { // backend=stage2 // target=native // -// :2:31: error: pointer type '*i32' does not allow address zero +// :2:33: error: pointer type '*i32' does not allow address zero diff --git a/test/cases/compile_errors/int_to_err_global_invalid_number.zig b/test/cases/compile_errors/int_to_err_global_invalid_number.zig index 000b5d1e6abd5dd6ec4875e67a09d1db2463b117..82056640fdcba7557543e6a79dcb04488c3885af 100644 --- a/test/cases/compile_errors/int_to_err_global_invalid_number.zig +++ b/test/cases/compile_errors/int_to_err_global_invalid_number.zig @@ -5,7 +5,7 @@ const Set1 = error{ comptime { var x: u16 = 3; var y = @errorFromInt(x); - _ = y; + _ = .{ &x, &y }; } // error diff --git a/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig b/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig index 23c3917b445a4fff38b4bba04900106e1d6560f7..c9f6c1e2e4a05107aeacf5084fa2b85d133f00b5 100644 --- a/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig +++ b/test/cases/compile_errors/int_to_err_non_global_invalid_number.zig @@ -7,8 +7,8 @@ const Set2 = error{ C, }; comptime { - var x = @intFromError(Set1.B); - var y: Set2 = @errorCast(@errorFromInt(x)); + const x = @intFromError(Set1.B); + const y: Set2 = @errorCast(@errorFromInt(x)); _ = y; } @@ -16,4 +16,4 @@ comptime { // backend=llvm // target=native // -// :11:19: error: 'error.B' not a member of error set 'error{C,A}' +// :11:21: error: 'error.B' not a member of error set 'error{C,A}' diff --git a/test/cases/compile_errors/integer_cast_truncates_bits.zig b/test/cases/compile_errors/integer_cast_truncates_bits.zig index a230dd3e5bae3a03522335537bc1c0b3fa20d995..afe3484a418f7871bbf6c636f0285f7dfeea8c6e 100644 --- a/test/cases/compile_errors/integer_cast_truncates_bits.zig +++ b/test/cases/compile_errors/integer_cast_truncates_bits.zig @@ -11,12 +11,12 @@ export fn entry2() void { export fn entry3() void { var spartan_count: u16 = 300; var byte: u8 = spartan_count; - _ = byte; + _ = .{ &spartan_count, &byte }; } export fn entry4() void { var signed: i8 = -1; var unsigned: u64 = signed; - _ = unsigned; + _ = .{ &signed, &unsigned }; } // error diff --git a/test/cases/compile_errors/invalid_compare_string.zig b/test/cases/compile_errors/invalid_compare_string.zig index a5c7f041a5649d9608ce6d65ec2b1f43c0864799..95f6fa4122d3faedbc8e5446c7c47c040f55cbec 100644 --- a/test/cases/compile_errors/invalid_compare_string.zig +++ b/test/cases/compile_errors/invalid_compare_string.zig @@ -1,20 +1,20 @@ comptime { - var a = "foo"; + const a = "foo"; if (a == "foo") unreachable; } comptime { - var a = "foo"; + const a = "foo"; if (a == ("foo")) unreachable; // intentionally allow } comptime { - var a = "foo"; + const a = "foo"; switch (a) { "foo" => unreachable, else => {}, } } comptime { - var a = "foo"; + const a = "foo"; switch (a) { ("foo") => unreachable, // intentionally allow else => {}, diff --git a/test/cases/compile_errors/invalid_deref_on_switch_target.zig b/test/cases/compile_errors/invalid_deref_on_switch_target.zig index a880b16fca8579d4cf982582834aa3c349a31857..70fab8e8c16259535e88f9334a508d9ae5ad9526 100644 --- a/test/cases/compile_errors/invalid_deref_on_switch_target.zig +++ b/test/cases/compile_errors/invalid_deref_on_switch_target.zig @@ -1,5 +1,5 @@ comptime { - var tile = Tile.Empty; + const tile = Tile.Empty; switch (tile.*) { Tile.Empty => {}, Tile.Filled => {}, diff --git a/test/cases/compile_errors/invalid_float_casts.zig b/test/cases/compile_errors/invalid_float_casts.zig index 2b09c722be87114d4c54c7f8db9a805e9e4fe988..332fc0d895cef8ee3a2c0a44ca3b446c69b91780 100644 --- a/test/cases/compile_errors/invalid_float_casts.zig +++ b/test/cases/compile_errors/invalid_float_casts.zig @@ -1,17 +1,21 @@ export fn foo() void { var a: f32 = 2; + _ = &a; _ = @as(comptime_float, @floatCast(a)); } export fn bar() void { var a: f32 = 2; + _ = &a; _ = @as(f32, @intFromFloat(a)); } export fn baz() void { var a: f32 = 2; + _ = &a; _ = @as(f32, @floatFromInt(a)); } export fn qux() void { var a: u32 = 2; + _ = &a; _ = @as(f32, @floatCast(a)); } @@ -19,7 +23,7 @@ export fn qux() void { // backend=stage2 // target=native // -// :3:40: error: unable to cast runtime value to 'comptime_float' -// :7:18: error: expected integer type, found 'f32' -// :11:32: error: expected integer type, found 'f32' -// :15:29: error: expected float or vector type, found 'u32' +// :4:40: error: unable to cast runtime value to 'comptime_float' +// :9:18: error: expected integer type, found 'f32' +// :14:32: error: expected integer type, found 'f32' +// :19:29: error: expected float or vector type, found 'u32' diff --git a/test/cases/compile_errors/invalid_inline_else_type.zig b/test/cases/compile_errors/invalid_inline_else_type.zig index 2d52fca43ebbfe0144c66cd54f2f245b9ed35f1b..5d3205e3f72046534027c385656226b8641d3399 100644 --- a/test/cases/compile_errors/invalid_inline_else_type.zig +++ b/test/cases/compile_errors/invalid_inline_else_type.zig @@ -1,5 +1,6 @@ pub export fn entry1() void { var a: anyerror = undefined; + _ = &a; switch (a) { inline else => {}, } @@ -7,12 +8,14 @@ pub export fn entry1() void { const E = enum(u8) { a, _ }; pub export fn entry2() void { var a: E = undefined; + _ = &a; switch (a) { inline else => {}, } } pub export fn entry3() void { var a: *u32 = undefined; + _ = &a; switch (a) { inline else => {}, } @@ -22,6 +25,6 @@ pub export fn entry3() void { // backend=stage2 // target=native // -// :4:21: error: cannot enumerate values of type 'anyerror' for 'inline else' -// :11:21: error: cannot enumerate values of type 'tmp.E' for 'inline else' -// :17:21: error: cannot enumerate values of type '*u32' for 'inline else' +// :5:21: error: cannot enumerate values of type 'anyerror' for 'inline else' +// :13:21: error: cannot enumerate values of type 'tmp.E' for 'inline else' +// :20:21: error: cannot enumerate values of type '*u32' for 'inline else' diff --git a/test/cases/compile_errors/invalid_int_casts.zig b/test/cases/compile_errors/invalid_int_casts.zig index 1e52c52609560209fe561d545135a48014253ca5..71fcbb18924470774a22c78c0148d023ca8512e9 100644 --- a/test/cases/compile_errors/invalid_int_casts.zig +++ b/test/cases/compile_errors/invalid_int_casts.zig @@ -1,17 +1,21 @@ export fn foo() void { var a: u32 = 2; + _ = &a; _ = @as(comptime_int, @intCast(a)); } export fn bar() void { var a: u32 = 2; + _ = &a; _ = @as(u32, @floatFromInt(a)); } export fn baz() void { var a: u32 = 2; + _ = &a; _ = @as(u32, @intFromFloat(a)); } export fn qux() void { var a: f32 = 2; + _ = &a; _ = @as(u32, @intCast(a)); } @@ -19,7 +23,7 @@ export fn qux() void { // backend=stage2 // target=native // -// :3:36: error: unable to cast runtime value to 'comptime_int' -// :7:18: error: expected float type, found 'u32' -// :11:32: error: expected float type, found 'u32' -// :15:27: error: expected integer or vector, found 'f32' +// :4:36: error: unable to cast runtime value to 'comptime_int' +// :9:18: error: expected float type, found 'u32' +// :14:32: error: expected float type, found 'u32' +// :19:27: error: expected integer or vector, found 'f32' diff --git a/test/cases/compile_errors/invalid_multiple_dereferences.zig b/test/cases/compile_errors/invalid_multiple_dereferences.zig index 3edebf7b1f79383e73e669bae0f1f82ccc13a00c..0c94bdf11e24c88fd67d1c9b2c714b82c9faf4fe 100644 --- a/test/cases/compile_errors/invalid_multiple_dereferences.zig +++ b/test/cases/compile_errors/invalid_multiple_dereferences.zig @@ -1,11 +1,12 @@ export fn a() void { var box = Box{ .field = 0 }; + _ = &box; box.*.field = 1; } export fn b() void { var box = Box{ .field = 0 }; - var boxPtr = &box; - boxPtr.*.*.field = 1; + const box_ptr = &box; + box_ptr.*.*.field = 1; } pub const Box = struct { field: i32, @@ -15,5 +16,5 @@ pub const Box = struct { // backend=stage2 // target=native // -// :3:8: error: cannot dereference non-pointer type 'tmp.Box' -// :8:13: error: cannot dereference non-pointer type 'tmp.Box' +// :4:8: error: cannot dereference non-pointer type 'tmp.Box' +// :9:14: error: cannot dereference non-pointer type 'tmp.Box' diff --git a/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig b/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig index d7a93edfcda4c52152ade45472d505b0885f789e..05b685558206d9bab8e2f1399d8494c644896856 100644 --- a/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig +++ b/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig @@ -10,12 +10,12 @@ const U = union(E) { export fn foo() void { var e: E = @enumFromInt(15); var u: U = e; - _ = u; + _ = .{ &e, &u }; } export fn bar() void { const e: E = @enumFromInt(15); var u: U = e; - _ = u; + _ = &u; } // error diff --git a/test/cases/compile_errors/invalid_peer_type_resolution.zig b/test/cases/compile_errors/invalid_peer_type_resolution.zig index d82986a60a27439451cd81c2dc3e7c11922d9572..e96caecfb65ba7bf247b3675622c23345c59ae88 100644 --- a/test/cases/compile_errors/invalid_peer_type_resolution.zig +++ b/test/cases/compile_errors/invalid_peer_type_resolution.zig @@ -1,11 +1,13 @@ export fn optionalVector() void { var x: ?@Vector(10, i32) = undefined; var y: @Vector(11, i32) = undefined; + _ = .{ &x, &y }; _ = @TypeOf(x, y); } export fn badTupleField() void { var x = .{ @as(u8, 0), @as(u32, 1) }; var y = .{ @as(u8, 1), "hello" }; + _ = .{ &x, &y }; _ = @TypeOf(x, y); } export fn badNestedField() void { @@ -30,21 +32,21 @@ export fn incompatiblePointers4() void { // backend=llvm // target=native // -// :4:9: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)' -// :4:17: note: type '?@Vector(10, i32)' here -// :4:20: note: type '@Vector(11, i32)' here -// :9:9: error: struct field '1' has conflicting types -// :9:9: note: incompatible types: 'u32' and '*const [5:0]u8' -// :9:17: note: type 'u32' here -// :9:20: note: type '*const [5:0]u8' here -// :14:9: error: struct field 'bar' has conflicting types -// :14:9: note: struct field '1' has conflicting types -// :14:9: note: incompatible types: 'comptime_int' and '*const [2:0]u8' -// :14:17: note: type 'comptime_int' here -// :14:20: note: type '*const [2:0]u8' here -// :19:9: error: incompatible types: '[]const u8' and '[*:0]const u8' -// :19:17: note: type '[]const u8' here -// :19:20: note: type '[*:0]const u8' here -// :26:9: error: incompatible types: '[]const u8' and '[*]const u8' -// :26:23: note: type '[]const u8' here -// :26:26: note: type '[*]const u8' here +// :5:9: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)' +// :5:17: note: type '?@Vector(10, i32)' here +// :5:20: note: type '@Vector(11, i32)' here +// :11:9: error: struct field '1' has conflicting types +// :11:9: note: incompatible types: 'u32' and '*const [5:0]u8' +// :11:17: note: type 'u32' here +// :11:20: note: type '*const [5:0]u8' here +// :16:9: error: struct field 'bar' has conflicting types +// :16:9: note: struct field '1' has conflicting types +// :16:9: note: incompatible types: 'comptime_int' and '*const [2:0]u8' +// :16:17: note: type 'comptime_int' here +// :16:20: note: type '*const [2:0]u8' here +// :21:9: error: incompatible types: '[]const u8' and '[*:0]const u8' +// :21:17: note: type '[]const u8' here +// :21:20: note: type '[*:0]const u8' here +// :28:9: error: incompatible types: '[]const u8' and '[*]const u8' +// :28:23: note: type '[]const u8' here +// :28:26: note: type '[*]const u8' here diff --git a/test/cases/compile_errors/invalid_store_to_comptime_field.zig b/test/cases/compile_errors/invalid_store_to_comptime_field.zig index 672eea8ddc9dec208ae57c0fec79be637c47a3b4..6703ac14ca38a72130c11a82471bcd970dfe6a7d 100644 --- a/test/cases/compile_errors/invalid_store_to_comptime_field.zig +++ b/test/cases/compile_errors/invalid_store_to_comptime_field.zig @@ -17,8 +17,9 @@ pub export fn entry2() void { var list = .{ 1, 2, 3 }; var list2 = @TypeOf(list){ .@"0" = 1, .@"1" = 2, .@"2" = 3 }; var list3 = @TypeOf(list){ 1, 2, 4 }; - _ = list2; - _ = list3; + _ = &list; + _ = &list2; + _ = &list3; } pub export fn entry3() void { const U = struct { @@ -46,6 +47,7 @@ pub export fn entry5() void { } pub export fn entry6() void { var x: u32 = 15; + _ = &x; const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); const S = struct { fn foo(_: T) void {} @@ -74,12 +76,12 @@ pub export fn entry8() void { // :6:9: error: value stored in comptime field does not match the default value of the field // :14:9: error: value stored in comptime field does not match the default value of the field // :19:38: error: value stored in comptime field does not match the default value of the field -// :31:19: error: value stored in comptime field does not match the default value of the field -// :25:29: note: default value set here -// :41:19: error: value stored in comptime field does not match the default value of the field -// :35:29: note: default value set here -// :45:12: error: value stored in comptime field does not match the default value of the field -// :53:25: error: value stored in comptime field does not match the default value of the field -// :66:36: error: value stored in comptime field does not match the default value of the field -// :59:30: error: value stored in comptime field does not match the default value of the field -// :57:29: note: default value set here +// :32:19: error: value stored in comptime field does not match the default value of the field +// :26:29: note: default value set here +// :42:19: error: value stored in comptime field does not match the default value of the field +// :36:29: note: default value set here +// :46:12: error: value stored in comptime field does not match the default value of the field +// :55:25: error: value stored in comptime field does not match the default value of the field +// :68:36: error: value stored in comptime field does not match the default value of the field +// :61:30: error: value stored in comptime field does not match the default value of the field +// :59:29: note: default value set here diff --git a/test/cases/compile_errors/invalid_struct_field.zig b/test/cases/compile_errors/invalid_struct_field.zig index ff8c96a0b6ac4c19ebd50f7274a2f002c2c2b3ea..7a3922dd1fcd25e7e48b0c45aa8fb9e469dac906 100644 --- a/test/cases/compile_errors/invalid_struct_field.zig +++ b/test/cases/compile_errors/invalid_struct_field.zig @@ -8,6 +8,7 @@ export fn f() void { export fn g() void { var a: A = undefined; const y = a.bar; + _ = &a; _ = y; } export fn e() void { @@ -26,5 +27,5 @@ export fn e() void { // :1:11: note: struct declared here // :10:17: error: no field named 'bar' in struct 'tmp.A' // :1:11: note: struct declared here -// :18:45: error: no field named 'f' in struct 'tmp.e.B' -// :14:15: note: struct declared here +// :19:45: error: no field named 'f' in struct 'tmp.e.B' +// :15:15: note: struct declared here diff --git a/test/cases/compile_errors/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig b/test/cases/compile_errors/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig index d78891bb2b86763228a2802f649b23eb45011b56..886b9687d40d2de3f1b6d2823906fde429a91bd1 100644 --- a/test/cases/compile_errors/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig +++ b/test/cases/compile_errors/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig @@ -1,5 +1,5 @@ export fn entry() void { - var foo: u32 = @This(){}; + const foo: u32 = @This(){}; _ = foo; } @@ -7,5 +7,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :2:27: error: expected type 'u32', found 'tmp' +// :2:29: error: expected type 'u32', found 'tmp' // :1:1: note: struct declared here diff --git a/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig b/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig index c6566bb46a0ce06ed8b5b3214cb5aa8e96107166..6792be129a26bf65e10b8e6bf104053bd0f50e25 100644 --- a/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig +++ b/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig @@ -4,7 +4,7 @@ export fn foo1() void { _ = word; } export fn foo2() void { - var bytes: []const u8 = &[_]u8{ 1, 2 }; + const bytes: []const u8 = &[_]u8{ 1, 2 }; const word: u16 = @bitCast(bytes); _ = word; } diff --git a/test/cases/compile_errors/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig b/test/cases/compile_errors/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig index 95bba054b3afbc8b337d43e5ae630be740e6f07f..7d397c85b34e97d05ccb441fcdf554a52db94606 100644 --- a/test/cases/compile_errors/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig +++ b/test/cases/compile_errors/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig @@ -1,14 +1,14 @@ export fn foo() void { var u: ?*anyopaque = null; var v: *anyopaque = undefined; - v = u; + v = (&u).*; } // error // backend=stage2 // target=native // -// :4:9: error: expected type '*anyopaque', found '?*anyopaque' -// :4:9: note: cannot convert optional to payload type -// :4:9: note: consider using '.?', 'orelse', or 'if' -// :4:9: note: '?*anyopaque' could have null values which are illegal in type '*anyopaque' +// :4:13: error: expected type '*anyopaque', found '?*anyopaque' +// :4:13: note: cannot convert optional to payload type +// :4:13: note: consider using '.?', 'orelse', or 'if' +// :4:13: note: '?*anyopaque' could have null values which are illegal in type '*anyopaque' diff --git a/test/cases/compile_errors/lazy_pointer_with_undefined_element_type.zig b/test/cases/compile_errors/lazy_pointer_with_undefined_element_type.zig index bffaa770ec38b619f12d820d77ab41639dc95ab7..a1ae3f937b1f5779bd201f8d4873672332c97fe5 100644 --- a/test/cases/compile_errors/lazy_pointer_with_undefined_element_type.zig +++ b/test/cases/compile_errors/lazy_pointer_with_undefined_element_type.zig @@ -1,5 +1,6 @@ export fn foo() void { comptime var T: type = undefined; + _ = &T; const S = struct { x: *T }; const I = @typeInfo(S); _ = I; @@ -9,4 +10,4 @@ export fn foo() void { // backend=stage2 // target=native // -// :3:28: error: use of undefined value here causes undefined behavior +// :4:28: error: use of undefined value here causes undefined behavior diff --git a/test/cases/compile_errors/load_vector_pointer_with_unknown_runtime_index.zig b/test/cases/compile_errors/load_vector_pointer_with_unknown_runtime_index.zig index d2182d8ad03eeef7dd2f0bdc7a11712899ae483c..7cef1c75160469e4a21f45f80e079550e8026cef 100644 --- a/test/cases/compile_errors/load_vector_pointer_with_unknown_runtime_index.zig +++ b/test/cases/compile_errors/load_vector_pointer_with_unknown_runtime_index.zig @@ -3,7 +3,7 @@ export fn entry() void { var i: u32 = 0; var x = loadv(&v[i]); - _ = x; + _ = .{ &i, &x }; } fn loadv(ptr: anytype) i31 { diff --git a/test/cases/compile_errors/memset_no_length.zig b/test/cases/compile_errors/memset_no_length.zig index 0355971cf95b38ee93664d2cf6c71b1adc49555b..23e77a08c153af0b0774d4bdfd3468214f73adfe 100644 --- a/test/cases/compile_errors/memset_no_length.zig +++ b/test/cases/compile_errors/memset_no_length.zig @@ -1,9 +1,11 @@ export fn foo() void { var ptr: [*]u8 = undefined; + _ = &ptr; @memset(ptr, 123); } export fn bar() void { var ptr: [*c]bool = undefined; + _ = &ptr; @memset(ptr, true); } @@ -11,7 +13,7 @@ export fn bar() void { // backend=stage2 // target=native // -// :3:5: error: unknown @memset length -// :3:13: note: destination type '[*]u8' provides no length -// :7:5: error: unknown @memset length -// :7:13: note: destination type '[*c]bool' provides no length +// :4:5: error: unknown @memset length +// :4:13: note: destination type '[*]u8' provides no length +// :9:5: error: unknown @memset length +// :9:13: note: destination type '[*c]bool' provides no length diff --git a/test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig b/test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig index 4043f305a0579be158a097a64b171c088e949400..8285d344e211eb450465bb3809e1effbd13024a0 100644 --- a/test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig +++ b/test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig @@ -7,7 +7,7 @@ pub fn getGeo3DTex2D() Geo3DTex2D { }; } export fn entry() void { - var geo_data = getGeo3DTex2D(); + const geo_data = getGeo3DTex2D(); _ = geo_data; } diff --git a/test/cases/compile_errors/missing_else_clause.zig b/test/cases/compile_errors/missing_else_clause.zig index 965d8e21777f2f4ac0f1933163df9f07c079c62b..5ce8c76f4d22a41674b3e78c157f14f80c6e9702 100644 --- a/test/cases/compile_errors/missing_else_clause.zig +++ b/test/cases/compile_errors/missing_else_clause.zig @@ -14,7 +14,7 @@ fn h() void { // https://github.com/ziglang/zig/issues/12743 const T = struct { oh_no: *u32 }; var x: T = if (false) {}; - _ = x; + _ = &x; } fn k(b: bool) void { // block_ptr case @@ -22,7 +22,7 @@ fn k(b: bool) void { var x = if (b) blk: { break :blk if (false) T{ .oh_no = 2 }; } else T{ .oh_no = 1 }; - _ = x; + _ = &x; } export fn entry() void { f(true); diff --git a/test/cases/compile_errors/missing_parameter_name_of_generic_function.zig b/test/cases/compile_errors/missing_parameter_name_of_generic_function.zig index edd19bd7de071f1d6111bf6113f120719a1e1523..ba7b30186e77eaf48f01b10a2d55779394cb4b34 100644 --- a/test/cases/compile_errors/missing_parameter_name_of_generic_function.zig +++ b/test/cases/compile_errors/missing_parameter_name_of_generic_function.zig @@ -1,7 +1,7 @@ fn dump(anytype) void {} export fn entry() void { var a: u8 = 9; - dump(a); + dump((&a).*); } // error diff --git a/test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig b/test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig index ca8adade01983049acc45e10540e6f1f114f68de..9d22dba0373429f4f24473d65235203e144b338e 100644 --- a/test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig +++ b/test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig @@ -24,7 +24,7 @@ pub const JsonNode = struct { fn foo() void { var jll: JasonList = undefined; jll.init(1234); - var jd = JsonNode{ .kind = JsonType.JSONArray, .jobject = JsonOA.JSONArray{jll} }; + const jd = JsonNode{ .kind = JsonType.JSONArray, .jobject = JsonOA.JSONArray{jll} }; _ = jd; } diff --git a/test/cases/compile_errors/mod_on_undefined_value.zig b/test/cases/compile_errors/mod_on_undefined_value.zig index 31f6f37815537fe26e224b231a8e8512e9fb6a6a..3641b0e71c169aa2a2de170cfc2d7d704bc2233a 100644 --- a/test/cases/compile_errors/mod_on_undefined_value.zig +++ b/test/cases/compile_errors/mod_on_undefined_value.zig @@ -1,6 +1,7 @@ comptime { var a: i64 = undefined; _ = a % a; + _ = &a; } // error diff --git a/test/cases/compile_errors/mult_on_undefined_value.zig b/test/cases/compile_errors/mult_on_undefined_value.zig index 1ef459421a97e80768ff7423753b82e39af31d6e..1e65797153526d45b1acd9d0aeb71a717b89e4a2 100644 --- a/test/cases/compile_errors/mult_on_undefined_value.zig +++ b/test/cases/compile_errors/mult_on_undefined_value.zig @@ -1,5 +1,5 @@ comptime { - var a: i64 = undefined; + const a: i64 = undefined; _ = a * a; } diff --git a/test/cases/compile_errors/negate_on_undefined_value.zig b/test/cases/compile_errors/negate_on_undefined_value.zig index 2e0ee4ed3b2df3d6869489bf418a60210bc02b6e..3f54800db143e81de00787f9467a6def412c6c11 100644 --- a/test/cases/compile_errors/negate_on_undefined_value.zig +++ b/test/cases/compile_errors/negate_on_undefined_value.zig @@ -1,5 +1,5 @@ comptime { - var a: i64 = undefined; + const a: i64 = undefined; _ = -a; } diff --git a/test/cases/compile_errors/nested_vectors.zig b/test/cases/compile_errors/nested_vectors.zig index 29934668b07f0bb5d8e00eb1d75c54b976bd1ec3..500de6bcf069e4198cd7383acb20e8959530b8c5 100644 --- a/test/cases/compile_errors/nested_vectors.zig +++ b/test/cases/compile_errors/nested_vectors.zig @@ -1,7 +1,7 @@ export fn entry() void { const V1 = @Vector(4, u8); const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } }); - var v: V2 = undefined; + const v: V2 = undefined; _ = v; } diff --git a/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig b/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig index 7064ebb1b672000e823da27a91c7549fd6affb0f..0b3d02a224b1c36b935162e3cd403f25083b78d5 100644 --- a/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig +++ b/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig @@ -1,30 +1,30 @@ export fn entry1() void { var m2 = &2; - _ = m2; + _ = &m2; } export fn entry2() void { var a = undefined; - _ = a; + _ = &a; } export fn entry3() void { var b = 1; - _ = b; + _ = &b; } export fn entry4() void { var c = 1.0; - _ = c; + _ = &c; } export fn entry5() void { var d = null; - _ = d; + _ = &d; } export fn entry6(opaque_: *Opaque) void { var e = opaque_.*; - _ = e; + _ = &e; } export fn entry7() void { var f = i32; - _ = f; + _ = &f; } const Opaque = opaque {}; export fn entry8() void { diff --git a/test/cases/compile_errors/non-integer_tag_type_to_enum.zig b/test/cases/compile_errors/non-integer_tag_type_to_enum.zig index 85ffc5b4b69739179c6f57607cd5f94b12fb92ae..9f14492b57256ffdd4c216097b16a76166c186ce 100644 --- a/test/cases/compile_errors/non-integer_tag_type_to_enum.zig +++ b/test/cases/compile_errors/non-integer_tag_type_to_enum.zig @@ -3,7 +3,7 @@ const Foo = enum(f32) { }; export fn entry() void { var f: Foo = undefined; - _ = f; + _ = &f; } // error diff --git a/test/cases/compile_errors/non_void_error_union_payload_ignored.zig b/test/cases/compile_errors/non_void_error_union_payload_ignored.zig index 41b5b6803d19e2b72e91a4bccac4d216ab062ad7..63c116b7bc7d364ab2a8eecd3949325694c6b89f 100644 --- a/test/cases/compile_errors/non_void_error_union_payload_ignored.zig +++ b/test/cases/compile_errors/non_void_error_union_payload_ignored.zig @@ -5,6 +5,7 @@ pub export fn entry1() void { } else |_| { // bar } + _ = &x; } pub export fn entry2() void { var x: anyerror!usize = 5; @@ -13,6 +14,7 @@ pub export fn entry2() void { } else |_| { // bar } + _ = &x; } // error @@ -21,5 +23,5 @@ pub export fn entry2() void { // // :3:5: error: error union payload is ignored // :3:5: note: payload value can be explicitly ignored with '|_|' -// :11:5: error: error union payload is ignored -// :11:5: note: payload value can be explicitly ignored with '|_|' +// :12:5: error: error union payload is ignored +// :12:5: note: payload value can be explicitly ignored with '|_|' diff --git a/test/cases/compile_errors/not_an_enum_type.zig b/test/cases/compile_errors/not_an_enum_type.zig index bdd03c8db7fe54490e4342f4e3d64af7b4b79899..51f0e458a93a0508e4eb9221f62a2e0abd395cba 100644 --- a/test/cases/compile_errors/not_an_enum_type.zig +++ b/test/cases/compile_errors/not_an_enum_type.zig @@ -1,6 +1,6 @@ export fn entry() void { var self: Error = undefined; - switch (self) { + switch ((&self).*) { InvalidToken => |x| return x.token, ExpectedVarDeclOrFn => |x| return x.token, } diff --git a/test/cases/compile_errors/or_on_undefined_value.zig b/test/cases/compile_errors/or_on_undefined_value.zig index b40c1beddd6a9f4bf6fccbb0795db2371c702d44..ee04a43844c8fb4c41e99525d711c9d21637375e 100644 --- a/test/cases/compile_errors/or_on_undefined_value.zig +++ b/test/cases/compile_errors/or_on_undefined_value.zig @@ -1,5 +1,6 @@ comptime { var a: bool = undefined; + _ = &a; _ = a or a; } @@ -7,4 +8,4 @@ comptime { // backend=stage2 // target=native // -// :3:9: error: use of undefined value here causes undefined behavior +// :4:9: error: use of undefined value here causes undefined behavior diff --git a/test/cases/compile_errors/orelse_on_undefined_value.zig b/test/cases/compile_errors/orelse_on_undefined_value.zig index e67cd952d30cabe735aebfbf792146af86f33929..de460bf35c8e6427c9daf1602f2eeeee30ae0e84 100644 --- a/test/cases/compile_errors/orelse_on_undefined_value.zig +++ b/test/cases/compile_errors/orelse_on_undefined_value.zig @@ -1,5 +1,5 @@ comptime { - var a: ?bool = undefined; + const a: ?bool = undefined; _ = a orelse false; } diff --git a/test/cases/compile_errors/out_of_bounds_index.zig b/test/cases/compile_errors/out_of_bounds_index.zig index 3f5b71d530fdbe6f29ba8f2435a13a57f3e7b504..29b5c7d7d1247e51d979c9fb3e34c5d59b453540 100644 --- a/test/cases/compile_errors/out_of_bounds_index.zig +++ b/test/cases/compile_errors/out_of_bounds_index.zig @@ -1,29 +1,29 @@ comptime { var array = [_:0]u8{ 1, 2, 3, 4 }; var src_slice: [:0]u8 = &array; - var slice = src_slice[2..6]; + const slice = src_slice[2..6]; _ = slice; } comptime { var array = [_:0]u8{ 1, 2, 3, 4 }; - var slice = array[2..6]; + const slice = array[2..6]; _ = slice; } comptime { var array = [_]u8{ 1, 2, 3, 4 }; - var slice = array[2..5]; + const slice = array[2..5]; _ = slice; } comptime { var array = [_:0]u8{ 1, 2, 3, 4 }; - var slice = array[3..2]; + const slice = array[3..2]; _ = slice; } // error // target=native // -// :4:30: error: end index 6 out of bounds for slice of length 4 +1 (sentinel) -// :9:26: error: end index 6 out of bounds for array of length 4 +1 (sentinel) -// :14:26: error: end index 5 out of bounds for array of length 4 -// :19:23: error: start index 3 is larger than end index 2 +// :4:32: error: end index 6 out of bounds for slice of length 4 +1 (sentinel) +// :9:28: error: end index 6 out of bounds for array of length 4 +1 (sentinel) +// :14:28: error: end index 5 out of bounds for array of length 4 +// :19:25: error: start index 3 is larger than end index 2 diff --git a/test/cases/compile_errors/overflow_in_enum_value_allocation.zig b/test/cases/compile_errors/overflow_in_enum_value_allocation.zig index 821ac6c2563e8f76d189ff9ff4599f346d3e2233..d2f8fc4536e964f72f29b79e50cc31070e47d3bc 100644 --- a/test/cases/compile_errors/overflow_in_enum_value_allocation.zig +++ b/test/cases/compile_errors/overflow_in_enum_value_allocation.zig @@ -3,7 +3,7 @@ const Moo = enum(u8) { Over, }; pub export fn entry() void { - var y = Moo.Last; + const y = Moo.Last; _ = y; } diff --git a/test/cases/compile_errors/packed_union_given_enum_tag_type.zig b/test/cases/compile_errors/packed_union_given_enum_tag_type.zig index 2e69afd0a9ec46c5d15b3f4b469e93df77ec61e8..cab4c6bdfb61af88f8714ba01e7ddca359c6d6a6 100644 --- a/test/cases/compile_errors/packed_union_given_enum_tag_type.zig +++ b/test/cases/compile_errors/packed_union_given_enum_tag_type.zig @@ -9,7 +9,7 @@ const Payload = packed union(Letter) { C: bool, }; export fn entry() void { - var a = Payload{ .A = 1234 }; + const a: Payload = .{ .A = 1234 }; _ = a; } diff --git a/test/cases/compile_errors/packed_union_with_automatic_layout_field.zig b/test/cases/compile_errors/packed_union_with_automatic_layout_field.zig index 26d224de85942b2ab7dfba8f4f8300f8f69f2f88..210f30a1b395aed504c2d06a252692b689192225 100644 --- a/test/cases/compile_errors/packed_union_with_automatic_layout_field.zig +++ b/test/cases/compile_errors/packed_union_with_automatic_layout_field.zig @@ -7,7 +7,7 @@ const Payload = packed union { B: bool, }; export fn entry() void { - var a = Payload{ .B = true }; + const a: Payload = .{ .B = true }; _ = a; } diff --git a/test/cases/compile_errors/pointer_arithmetic_on_pointer-to-array.zig b/test/cases/compile_errors/pointer_arithmetic_on_pointer-to-array.zig index e97a098f40ce53338c19b61addb8dad48fa24d3e..931028dd2fb075239b40cf14e8683a5d3308d1bd 100644 --- a/test/cases/compile_errors/pointer_arithmetic_on_pointer-to-array.zig +++ b/test/cases/compile_errors/pointer_arithmetic_on_pointer-to-array.zig @@ -1,7 +1,7 @@ export fn foo() void { var x: [10]u8 = undefined; - var y = &x; - var z = y + 1; + const y = &x; + const z = y + 1; _ = z; } @@ -9,6 +9,6 @@ export fn foo() void { // backend=stage2 // target=native // -// :4:15: error: incompatible types: '*[10]u8' and 'comptime_int' -// :4:13: note: type '*[10]u8' here -// :4:17: note: type 'comptime_int' here +// :4:17: error: incompatible types: '*[10]u8' and 'comptime_int' +// :4:15: note: type '*[10]u8' here +// :4:19: note: type 'comptime_int' here diff --git a/test/cases/compile_errors/pointer_to_anyopaque_slice.zig b/test/cases/compile_errors/pointer_to_anyopaque_slice.zig index 2c7334bedb931a2971d4bb0d7a2cb41ffadc6a1a..1e37caa5563551ba7ad902528121d17909148ffe 100644 --- a/test/cases/compile_errors/pointer_to_anyopaque_slice.zig +++ b/test/cases/compile_errors/pointer_to_anyopaque_slice.zig @@ -2,6 +2,7 @@ export fn x() void { var a: *u32 = undefined; var b: []anyopaque = undefined; b = a; + _ = &a; } // error diff --git a/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig b/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig index dfcbf6849c31bee514dba58f67164090a2101246..cc008ea9ee410f103277f6dc02f6de8903f04908 100644 --- a/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig +++ b/test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig @@ -1,6 +1,6 @@ pub export fn entry() void { var y: [*]align(4) u8 = @ptrFromInt(5); - _ = y; + _ = &y; } // error diff --git a/test/cases/compile_errors/recursive_inline_fn.zig b/test/cases/compile_errors/recursive_inline_fn.zig index 67184271ebf94927f31a1711b82219b642017413..1cecfdbada3caa847e288b64c2cf0995de0b5be5 100644 --- a/test/cases/compile_errors/recursive_inline_fn.zig +++ b/test/cases/compile_errors/recursive_inline_fn.zig @@ -8,6 +8,7 @@ inline fn foo(x: i32) i32 { pub export fn entry() void { var x: i32 = 4; + _ = &x; _ = foo(x) == 20; } @@ -32,4 +33,4 @@ pub export fn entry2() void { // target=native // // :5:27: error: inline call is recursive -// :23:10: error: inline call is recursive +// :24:10: error: inline call is recursive diff --git a/test/cases/compile_errors/reference_to_const_data.zig b/test/cases/compile_errors/reference_to_const_data.zig index e773cdb4a08827daa6585c9dfb78aabdd1ee0115..ae8dc121c6e6eea4c12594acccfc64af51d3c7af 100644 --- a/test/cases/compile_errors/reference_to_const_data.zig +++ b/test/cases/compile_errors/reference_to_const_data.zig @@ -5,10 +5,12 @@ export fn foo() void { export fn bar() void { var ptr = &@as(u32, 2); ptr.* = 2; + _ = &ptr; } export fn baz() void { var ptr = &true; ptr.* = false; + _ = &ptr; } export fn qux() void { const S = struct { @@ -21,6 +23,7 @@ export fn qux() void { export fn quux() void { var x = &@returnAddress(); x.* = 6; + _ = &x; } // error @@ -29,6 +32,6 @@ export fn quux() void { // // :3:8: error: cannot assign to constant // :7:8: error: cannot assign to constant -// :11:8: error: cannot assign to constant -// :19:8: error: cannot assign to constant -// :23:6: error: cannot assign to constant +// :12:8: error: cannot assign to constant +// :21:8: error: cannot assign to constant +// :25:6: error: cannot assign to constant diff --git a/test/cases/compile_errors/reify_typeOf_with_incompatible_arguments.zig b/test/cases/compile_errors/reify_typeOf_with_incompatible_arguments.zig index ee688c362b63b99c81e7b747d13946a8e8982a6a..6b21cd275995903be00b7df647fd36315dab890c 100644 --- a/test/cases/compile_errors/reify_typeOf_with_incompatible_arguments.zig +++ b/test/cases/compile_errors/reify_typeOf_with_incompatible_arguments.zig @@ -2,6 +2,7 @@ export fn entry() void { var var_1: f32 = undefined; var var_2: u32 = undefined; _ = @TypeOf(var_1, var_2); + _ = .{ &var_1, &var_2 }; } // error diff --git a/test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr.zig b/test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr.zig index ce140b64a8cc87c4d81ae379adaacfe5c076e69c..02f9a57a2b0392428f85d77a4831cc54abf14169 100644 --- a/test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr.zig +++ b/test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr.zig @@ -1,5 +1,5 @@ export fn entry() void { - var damn = Container{ + const damn = Container{ .not_optional = getOptional(), }; _ = damn; diff --git a/test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig b/test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig index e813ea1d55abcab54cc84554cec76e9a0348c89f..4bfa1a81a26932563008bfd0924f1dae8a988f80 100644 --- a/test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig +++ b/test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig @@ -2,7 +2,7 @@ export fn entry() void { var damn = Container{ .not_optional = getOptional(i32), }; - _ = damn; + _ = &damn; } pub fn getOptional(comptime T: type) ?T { return 0; diff --git a/test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig b/test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig index e99f093c951bd06e84a480d786aa54127623308d..c2bec83afdd3c2e1733256f63c52758a82561e03 100644 --- a/test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig +++ b/test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig @@ -5,6 +5,7 @@ const Foo = struct { export fn f() void { var x: u8 = 0; const foo = Foo{ .Bar = x, .Baz = u8 }; + _ = &x; _ = foo; } diff --git a/test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig b/test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig index b0528e17bde83f22283921208c7af46dbd011f4a..21b00ac545fc743ac473266f838a753528b7acdb 100644 --- a/test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig +++ b/test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig @@ -4,6 +4,7 @@ const Foo = union { }; export fn f() void { var x: u8 = 0; + _ = &x; const foo = Foo{ .Bar = x }; _ = foo; } @@ -12,5 +13,5 @@ export fn f() void { // backend=stage2 // target=native // -// :7:23: error: unable to resolve comptime value -// :7:23: note: initializer of comptime only union must be comptime-known +// :8:23: error: unable to resolve comptime value +// :8:23: note: initializer of comptime only union must be comptime-known diff --git a/test/cases/compile_errors/runtime_cast_to_union_which_has_non-void_fields.zig b/test/cases/compile_errors/runtime_cast_to_union_which_has_non-void_fields.zig index 0142f422f475acc15df4048e77e714dbe230dd46..300e67827b6afd2f1d6103d512edb6535d6ccf0b 100644 --- a/test/cases/compile_errors/runtime_cast_to_union_which_has_non-void_fields.zig +++ b/test/cases/compile_errors/runtime_cast_to_union_which_has_non-void_fields.zig @@ -8,7 +8,7 @@ export fn entry() void { foo(Letter.A); } fn foo(l: Letter) void { - var x: Value = l; + const x: Value = l; _ = x; } @@ -16,6 +16,6 @@ fn foo(l: Letter) void { // backend=stage2 // target=native // -// :11:20: error: runtime coercion from enum 'tmp.Letter' to union 'tmp.Value' which has non-void fields +// :11:22: error: runtime coercion from enum 'tmp.Letter' to union 'tmp.Value' which has non-void fields // :3:5: note: field 'A' has type 'i32' // :2:15: note: union declared here diff --git a/test/cases/compile_errors/runtime_indexing_comptime_array.zig b/test/cases/compile_errors/runtime_indexing_comptime_array.zig index d3e747822bf5513f1353dfec3f3459cf315417ad..fb2145b3ad6c665719564902a00f8d8ae6747de8 100644 --- a/test/cases/compile_errors/runtime_indexing_comptime_array.zig +++ b/test/cases/compile_errors/runtime_indexing_comptime_array.zig @@ -13,12 +13,14 @@ pub export fn entry2() void { const test_fns = [_]TestFn{ foo, bar }; var i: usize = 0; _ = test_fns[i]; + _ = &i; } pub export fn entry3() void { const TestFn = fn () void; const test_fns = [_]TestFn{ foo, bar }; var i: usize = 0; _ = &test_fns[i]; + _ = &i; } // error // target=native @@ -28,5 +30,5 @@ pub export fn entry3() void { // :7:10: note: use '*const fn () void' for a function pointer type // :15:18: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known // :15:17: note: use '*const fn () void' for a function pointer type -// :21:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known -// :21:18: note: use '*const fn () void' for a function pointer type +// :22:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known +// :22:18: note: use '*const fn () void' for a function pointer type diff --git a/test/cases/compile_errors/runtime_to_comptime_num.zig b/test/cases/compile_errors/runtime_to_comptime_num.zig index 8d4a3fb999f5f39bd852442526f191b29a496372..eb5d5fc6309d20ac65e00816a54cf07ffaf1e153 100644 --- a/test/cases/compile_errors/runtime_to_comptime_num.zig +++ b/test/cases/compile_errors/runtime_to_comptime_num.zig @@ -1,19 +1,23 @@ pub export fn entry() void { var a: u32 = 0; + _ = &a; _ = @as(comptime_int, a); } pub export fn entry2() void { var a: u32 = 0; + _ = &a; _ = @as(comptime_float, a); } pub export fn entry3() void { comptime var aa: comptime_float = 0.0; var a: f32 = 4; + _ = &a; aa = a; } pub export fn entry4() void { comptime var aa: comptime_int = 0.0; var a: f32 = 4; + _ = &a; aa = a; } @@ -21,11 +25,11 @@ pub export fn entry4() void { // backend=stage2 // target=native // -// :3:27: error: unable to resolve comptime value -// :3:27: note: value being casted to 'comptime_int' must be comptime-known -// :7:29: error: unable to resolve comptime value -// :7:29: note: value being casted to 'comptime_float' must be comptime-known -// :12:10: error: unable to resolve comptime value -// :12:10: note: value being casted to 'comptime_float' must be comptime-known -// :17:10: error: unable to resolve comptime value -// :17:10: note: value being casted to 'comptime_int' must be comptime-known +// :4:27: error: unable to resolve comptime value +// :4:27: note: value being casted to 'comptime_int' must be comptime-known +// :9:29: error: unable to resolve comptime value +// :9:29: note: value being casted to 'comptime_float' must be comptime-known +// :15:10: error: unable to resolve comptime value +// :15:10: note: value being casted to 'comptime_float' must be comptime-known +// :21:10: error: unable to resolve comptime value +// :21:10: note: value being casted to 'comptime_int' must be comptime-known diff --git a/test/cases/compile_errors/runtime_value_in_switch_prong.zig b/test/cases/compile_errors/runtime_value_in_switch_prong.zig index 6fe7112aab77b78f8cdf1872344b25caec8a7481..a49ebb4b81f626c0d8bb6a080bf3b8dcca546a90 100644 --- a/test/cases/compile_errors/runtime_value_in_switch_prong.zig +++ b/test/cases/compile_errors/runtime_value_in_switch_prong.zig @@ -1,6 +1,6 @@ pub export fn entry() void { var byte: u8 = 1; - switch (byte) { + switch ((&byte).*) { byte => {}, else => {}, } diff --git a/test/cases/compile_errors/self_referential_struct_requires_comptime.zig b/test/cases/compile_errors/self_referential_struct_requires_comptime.zig index 5051dfbbe0a35246ed130a03cbd43a24bb57f4ec..ec3b4c1795ba81862b28098034c93d11efaaa97b 100644 --- a/test/cases/compile_errors/self_referential_struct_requires_comptime.zig +++ b/test/cases/compile_errors/self_referential_struct_requires_comptime.zig @@ -4,7 +4,7 @@ const S = struct { }; pub export fn entry() void { var s: S = undefined; - _ = s; + _ = &s; } // error diff --git a/test/cases/compile_errors/self_referential_union_requires_comptime.zig b/test/cases/compile_errors/self_referential_union_requires_comptime.zig index 0e57481d3593b853775921a8877d4fcfb9870753..5eda780431d7020cd209c699b60e58b9244d8cdc 100644 --- a/test/cases/compile_errors/self_referential_union_requires_comptime.zig +++ b/test/cases/compile_errors/self_referential_union_requires_comptime.zig @@ -4,7 +4,7 @@ const U = union { }; pub export fn entry() void { var u: U = undefined; - _ = u; + _ = &u; } // error diff --git a/test/cases/compile_errors/shift_by_negative_comptime_integer.zig b/test/cases/compile_errors/shift_by_negative_comptime_integer.zig index 7d3a740e1671c7d5d6382d0e2f80f444410ecb51..779457135311e94e5b4178e9e3f444252359249f 100644 --- a/test/cases/compile_errors/shift_by_negative_comptime_integer.zig +++ b/test/cases/compile_errors/shift_by_negative_comptime_integer.zig @@ -1,5 +1,5 @@ comptime { - var a = 1 >> -1; + const a = 1 >> -1; _ = a; } @@ -7,4 +7,4 @@ comptime { // backend=stage2 // target=native // -// :2:18: error: shift by negative amount '-1' +// :2:20: error: shift by negative amount '-1' diff --git a/test/cases/compile_errors/shift_on_type_with_non-power-of-two_size.zig b/test/cases/compile_errors/shift_on_type_with_non-power-of-two_size.zig index 9f606b042629fc91dae1476e754e1d0f4dba157c..08c8635c0e622f52412f76aeb393d82e0176a015 100644 --- a/test/cases/compile_errors/shift_on_type_with_non-power-of-two_size.zig +++ b/test/cases/compile_errors/shift_on_type_with_non-power-of-two_size.zig @@ -2,18 +2,22 @@ export fn entry() void { const S = struct { fn a() void { var x: u24 = 42; + _ = &x; _ = x >> 24; } fn b() void { var x: u24 = 42; + _ = &x; _ = x << 24; } fn c() void { var x: u24 = 42; + _ = &x; _ = @shlExact(x, 24); } fn d() void { var x: u24 = 42; + _ = &x; _ = @shrExact(x, 24); } }; @@ -27,7 +31,7 @@ export fn entry() void { // backend=stage2 // target=native // -// :5:22: error: shift amount '24' is too large for operand type 'u24' -// :9:22: error: shift amount '24' is too large for operand type 'u24' -// :13:30: error: shift amount '24' is too large for operand type 'u24' -// :17:30: error: shift amount '24' is too large for operand type 'u24' +// :6:22: error: shift amount '24' is too large for operand type 'u24' +// :11:22: error: shift amount '24' is too large for operand type 'u24' +// :16:30: error: shift amount '24' is too large for operand type 'u24' +// :21:30: error: shift amount '24' is too large for operand type 'u24' diff --git a/test/cases/compile_errors/shifting_without_int_type_or_comptime_known.zig b/test/cases/compile_errors/shifting_without_int_type_or_comptime_known.zig index 7518165e9355d66c5c54b2ebc0699e6d5225d8b8..c1595aa67faf5a8de6490fcdff7a8187b8fc5908 100644 --- a/test/cases/compile_errors/shifting_without_int_type_or_comptime_known.zig +++ b/test/cases/compile_errors/shifting_without_int_type_or_comptime_known.zig @@ -6,10 +6,12 @@ export fn entry1(x: u8) u8 { } export fn entry2() void { var x: u5 = 1; + _ = &x; _ = @shlExact(12345, x); } export fn entry3() void { var x: u5 = 1; + _ = &x; _ = @shrExact(12345, x); } @@ -19,5 +21,5 @@ export fn entry3() void { // // :2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known // :5:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known -// :9:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known -// :13:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known +// :10:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known +// :15:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known diff --git a/test/cases/compile_errors/shuffle_with_selected_index_past_first_vector_length.zig b/test/cases/compile_errors/shuffle_with_selected_index_past_first_vector_length.zig index 893d3c4e01e7f3f940fb9e77e56b2d27cf13eda6..c1594d55fb34614e67604f7b5dd4f671c1c4e9e6 100644 --- a/test/cases/compile_errors/shuffle_with_selected_index_past_first_vector_length.zig +++ b/test/cases/compile_errors/shuffle_with_selected_index_past_first_vector_length.zig @@ -1,7 +1,7 @@ export fn entry() void { const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; - var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); + const z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); _ = z; } @@ -9,6 +9,6 @@ export fn entry() void { // backend=stage2 // target=native // -// :4:39: error: mask index '4' has out-of-bounds selection -// :4:27: note: selected index '7' out of bounds of '@Vector(4, u32)' -// :4:30: note: selections from the second vector are specified with negative numbers +// :4:41: error: mask index '4' has out-of-bounds selection +// :4:29: note: selected index '7' out of bounds of '@Vector(4, u32)' +// :4:32: note: selections from the second vector are specified with negative numbers diff --git a/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig b/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig index 85fb0065d1e169414b52d0ac86441d57f96f0c4b..31fe909a4b879d2a835712979c6a0a76b9460b6e 100644 --- a/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig +++ b/test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig @@ -1,11 +1,10 @@ export fn foo() void { const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16; - var value = @as(*const []const u8, @ptrCast(&bytes)).*; - _ = value; + _ = @as(*const []const u8, @ptrCast(&bytes)).*; } // error // backend=stage2 // target=native // -// :3:57: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not. +// :3:49: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not. diff --git a/test/cases/compile_errors/slice_of_null_pointer.zig b/test/cases/compile_errors/slice_of_null_pointer.zig index 7f2c74a8a62bfc65116889043afdcd75e1d04ddd..18c4ee8a6b17aa7ede76fb5bd39c44cf8b429647 100644 --- a/test/cases/compile_errors/slice_of_null_pointer.zig +++ b/test/cases/compile_errors/slice_of_null_pointer.zig @@ -1,11 +1,11 @@ comptime { var x: [*c]u8 = null; var runtime_len: usize = 0; - var y = x[0..runtime_len]; - _ = y; + _ = &runtime_len; + _ = x[0..runtime_len]; } // error // target=native // -// :4:14: error: slice of null pointer +// :5:10: error: slice of null pointer diff --git a/test/cases/compile_errors/slice_sentinel_mismatch-2.zig b/test/cases/compile_errors/slice_sentinel_mismatch-2.zig index 42c1328bb6fca1bc3a20647e438f7c132e6dcedf..76da6949b18295135475923e29255b410dc587f7 100644 --- a/test/cases/compile_errors/slice_sentinel_mismatch-2.zig +++ b/test/cases/compile_errors/slice_sentinel_mismatch-2.zig @@ -1,5 +1,5 @@ fn foo() [:0]u8 { - var x: []u8 = undefined; + const x: []u8 = undefined; return x; } comptime { diff --git a/test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig b/test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig index 3024f1dee8413f79b0ee5db2df30bb2329b8237d..9502032a932ecf0a0775389ace56bac698f42910 100644 --- a/test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig +++ b/test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig @@ -7,8 +7,7 @@ const Small = enum(u2) { }; export fn entry() void { - var x = Small.One; - _ = x; + _ = Small.One; } // error diff --git a/test/cases/compile_errors/specify_non-integer_enum_tag_type.zig b/test/cases/compile_errors/specify_non-integer_enum_tag_type.zig index 4fa7691a11743153435032cc0518bf3de16102d7..e9d761b714d197dd1bbd3d70dca158b0cdc916ae 100644 --- a/test/cases/compile_errors/specify_non-integer_enum_tag_type.zig +++ b/test/cases/compile_errors/specify_non-integer_enum_tag_type.zig @@ -5,7 +5,7 @@ const Small = enum(f32) { }; export fn entry() void { - var x = Small.One; + const x = Small.One; _ = x; } diff --git a/test/cases/compile_errors/stage1/obj/variable_in_inline_assembly_template_cannot_be_found.zig b/test/cases/compile_errors/stage1/obj/variable_in_inline_assembly_template_cannot_be_found.zig index 7636b501fd0237702050f200014cd065a85a602c..70313fa5f5d32fbf2e27103b08b61127bfcfa392 100644 --- a/test/cases/compile_errors/stage1/obj/variable_in_inline_assembly_template_cannot_be_found.zig +++ b/test/cases/compile_errors/stage1/obj/variable_in_inline_assembly_template_cannot_be_found.zig @@ -2,7 +2,7 @@ export fn entry() void { var sp = asm volatile ("mov %[foo], sp" : [bar] "=r" (-> usize), ); - _ = sp; + _ = &sp; } // error diff --git a/test/cases/compile_errors/store_vector_pointer_with_unknown_runtime_index.zig b/test/cases/compile_errors/store_vector_pointer_with_unknown_runtime_index.zig index 0007ff13277a25b155c48894859bbb16125ee3e0..0a00ebcf14849042ed417f5b1b5133577d752082 100644 --- a/test/cases/compile_errors/store_vector_pointer_with_unknown_runtime_index.zig +++ b/test/cases/compile_errors/store_vector_pointer_with_unknown_runtime_index.zig @@ -2,6 +2,7 @@ export fn entry() void { var v: @Vector(4, i31) = [_]i31{ 1, 5, 3, undefined }; var i: u32 = 0; + _ = &i; storev(&v[i], 42); } @@ -13,4 +14,4 @@ fn storev(ptr: anytype, val: i31) void { // backend=llvm // target=native // -// :9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i31' +// :10:8: error: unable to determine vector element index of type '*align(16:0:4:?) i31' diff --git a/test/cases/compile_errors/sub_on_undefined_value.zig b/test/cases/compile_errors/sub_on_undefined_value.zig index f198a72efe669e75bf3093b6aad6a139e2b55216..de305be576c5db6dd05f37a9b65d32530ccba6aa 100644 --- a/test/cases/compile_errors/sub_on_undefined_value.zig +++ b/test/cases/compile_errors/sub_on_undefined_value.zig @@ -1,5 +1,5 @@ comptime { - var a: i64 = undefined; + const a: i64 = undefined; _ = a - a; } diff --git a/test/cases/compile_errors/switch_capture_incompatible_types.zig b/test/cases/compile_errors/switch_capture_incompatible_types.zig index b6de7d5bf5b3b125e0781d967df8d97ab9941f1c..967307441b6780cbab1e3be7128da38b821aaa31 100644 --- a/test/cases/compile_errors/switch_capture_incompatible_types.zig +++ b/test/cases/compile_errors/switch_capture_incompatible_types.zig @@ -1,7 +1,7 @@ export fn f() void { const U = union(enum) { a: u32, b: *u8 }; var u: U = undefined; - switch (u) { + switch ((&u).*) { .a, .b => |val| _ = val, } } @@ -9,7 +9,7 @@ export fn f() void { export fn g() void { const U = union(enum) { a: u64, b: u32 }; var u: U = undefined; - switch (u) { + switch ((&u).*) { .a, .b => |*ptr| _ = ptr, } } diff --git a/test/cases/compile_errors/switch_on_enum_with_1_field_with_no_prongs.zig b/test/cases/compile_errors/switch_on_enum_with_1_field_with_no_prongs.zig index cf6fc141dec1add2ab31d2111ca5e0e7d8d519ec..096cab16ad3a275c292cb7c059f79acabf158188 100644 --- a/test/cases/compile_errors/switch_on_enum_with_1_field_with_no_prongs.zig +++ b/test/cases/compile_errors/switch_on_enum_with_1_field_with_no_prongs.zig @@ -1,7 +1,7 @@ const Foo = enum { M }; export fn entry() void { - var f = Foo.M; + const f = Foo.M; switch (f) {} } diff --git a/test/cases/compile_errors/switch_on_slice.zig b/test/cases/compile_errors/switch_on_slice.zig index c2b28f67abb931404b9bb5fa41cf606a1f622820..04960635a0decda894718c573972b8fd5701161f 100644 --- a/test/cases/compile_errors/switch_on_slice.zig +++ b/test/cases/compile_errors/switch_on_slice.zig @@ -1,5 +1,6 @@ pub export fn entry() void { var a: [:0]const u8 = "foo"; + _ = &a; switch (a) { ("--version"), ("version") => unreachable, else => {}, @@ -10,4 +11,4 @@ pub export fn entry() void { // backend=stage2 // target=native // -// :3:13: error: switch on type '[:0]const u8' +// :4:13: error: switch on type '[:0]const u8' diff --git a/test/cases/compile_errors/switch_ranges_endpoints_are_validated.zig b/test/cases/compile_errors/switch_ranges_endpoints_are_validated.zig index 72c17929c080d70f744e60fb070c46879776ebe1..b32e707ebde67230f6ad10f50d6a9b2aa277d6a1 100644 --- a/test/cases/compile_errors/switch_ranges_endpoints_are_validated.zig +++ b/test/cases/compile_errors/switch_ranges_endpoints_are_validated.zig @@ -1,12 +1,12 @@ pub export fn entry1() void { - var x: i32 = 0; + const x: i32 = 0; switch (x) { 6...1 => {}, else => unreachable, } } pub export fn entr2() void { - var x: i32 = 0; + const x: i32 = 0; switch (x) { -1...-5 => {}, else => unreachable, diff --git a/test/cases/compile_errors/switch_with_overlapping_case_ranges.zig b/test/cases/compile_errors/switch_with_overlapping_case_ranges.zig index 46dc08be62da9815a2c8540a0845e33e0449092e..72f05b92a6ab7b13e6f555dd1a65cd6d637e60d7 100644 --- a/test/cases/compile_errors/switch_with_overlapping_case_ranges.zig +++ b/test/cases/compile_errors/switch_with_overlapping_case_ranges.zig @@ -1,6 +1,6 @@ export fn entry() void { var q: u8 = 0; - switch (q) { + switch ((&q).*) { 1...2 => {}, 0...255 => {}, } diff --git a/test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig b/test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig index 32aa446f9a1be97d5e847543b1cc64b3846c5110..2ca3f0be24c6f5bfc62d60ff4d3a35a800850de1 100644 --- a/test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig +++ b/test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig @@ -3,7 +3,7 @@ const E = enum { b, }; pub export fn entry() void { - var e: E = .b; + const e: E = .b; switch (e) { .a => {}, .b => {}, diff --git a/test/cases/compile_errors/switching_with_non-exhaustive_enums.zig b/test/cases/compile_errors/switching_with_non-exhaustive_enums.zig index a88393b99f013e4a35a5ce3314f4ae6442eed477..ea6f2c9fd3371f0375736fe87eca5ab848a6e804 100644 --- a/test/cases/compile_errors/switching_with_non-exhaustive_enums.zig +++ b/test/cases/compile_errors/switching_with_non-exhaustive_enums.zig @@ -8,21 +8,21 @@ const U = union(E) { b: u32, }; pub export fn entry1() void { - var e: E = .b; + const e: E = .b; switch (e) { // error: switch not handling the tag `b` .a => {}, _ => {}, } } pub export fn entry2() void { - var e: E = .b; + const e: E = .b; switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong .a => {}, .b => {}, } } pub export fn entry3() void { - var u = U{ .a = 2 }; + const u = U{ .a = 2 }; switch (u) { // error: `_` prong not allowed when switching on tagged union .a => {}, .b => {}, diff --git a/test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig b/test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig index 28eaa9bad815a428efd87409c2e69c059d3c0359..4538a8e26964d8751fb9ed33f257d1f54ff0502a 100644 --- a/test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig +++ b/test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig @@ -3,14 +3,13 @@ const FloatInt = extern union { Int: i32, }; export fn entry() void { - var fi = FloatInt{ .Float = 123.45 }; - var tagName = @tagName(fi); - _ = tagName; + const fi: FloatInt = .{ .Float = 123.45 }; + _ = @tagName(fi); } // error // backend=stage2 // target=native // -// :7:19: error: union 'tmp.FloatInt' is untagged +// :7:9: error: union 'tmp.FloatInt' is untagged // :1:25: note: union declared here diff --git a/test/cases/compile_errors/truncate_sign_mismatch.zig b/test/cases/compile_errors/truncate_sign_mismatch.zig index b34dfa8e0754c2930780cb423a09bc71c2428d20..d4d64dc8bacfb89b197eed1e5cc6f8277a89390c 100644 --- a/test/cases/compile_errors/truncate_sign_mismatch.zig +++ b/test/cases/compile_errors/truncate_sign_mismatch.zig @@ -1,25 +1,25 @@ export fn entry1() i8 { var x: u32 = 10; - return @truncate(x); + return @truncate((&x).*); } export fn entry2() u8 { var x: i32 = -10; - return @truncate(x); + return @truncate((&x).*); } export fn entry3() i8 { comptime var x: u32 = 10; - return @truncate(x); + return @truncate((&x).*); } export fn entry4() u8 { comptime var x: i32 = -10; - return @truncate(x); + return @truncate((&x).*); } // error // backend=stage2 // target=native // -// :3:22: error: expected signed integer type, found 'u32' -// :7:22: error: expected unsigned integer type, found 'i32' -// :11:22: error: expected signed integer type, found 'u32' -// :15:22: error: expected unsigned integer type, found 'i32' +// :3:26: error: expected signed integer type, found 'u32' +// :7:26: error: expected unsigned integer type, found 'i32' +// :11:26: error: expected signed integer type, found 'u32' +// :15:26: error: expected unsigned integer type, found 'i32' diff --git a/test/cases/compile_errors/tuple_init_edge_cases.zig b/test/cases/compile_errors/tuple_init_edge_cases.zig index aae7370851ec78a01e0eac870f769aaef82afd38..24f4ff9bdde06d7bf790b9d2a67fd7a4ccd9e3df 100644 --- a/test/cases/compile_errors/tuple_init_edge_cases.zig +++ b/test/cases/compile_errors/tuple_init_edge_cases.zig @@ -1,49 +1,54 @@ pub export fn entry1() void { const T = @TypeOf(.{ 123, 3 }); var b = T{ .@"1" = 3 }; - _ = b; + _ = &b; var c = T{ 123, 3 }; - _ = c; + _ = &c; var d = T{}; - _ = d; + _ = &d; } pub export fn entry2() void { var a: u32 = 2; + _ = &a; const T = @TypeOf(.{ 123, a }); var b = T{ .@"1" = 3 }; - _ = b; + _ = &b; var c = T{ 123, 3 }; - _ = c; + _ = &c; var d = T{}; - _ = d; + _ = &d; } pub export fn entry3() void { var a: u32 = 2; + _ = &a; const T = @TypeOf(.{ 123, a }); var b = T{ .@"0" = 123 }; - _ = b; + _ = &b; } comptime { var a: u32 = 2; + _ = &a; const T = @TypeOf(.{ 123, a }); var b = T{ .@"0" = 123 }; - _ = b; + _ = &b; var c = T{ 123, 2 }; - _ = c; + _ = &c; var d = T{}; - _ = d; + _ = &d; } pub export fn entry4() void { var a: u32 = 2; + _ = &a; const T = @TypeOf(.{ 123, a }); var b = T{ 123, 4, 5 }; - _ = b; + _ = &b; } pub export fn entry5() void { var a: u32 = 2; + _ = &a; const T = @TypeOf(.{ 123, a }); var b = T{ .@"0" = 123, .@"2" = 123, .@"1" = 123 }; - _ = b; + _ = &b; } pub const Consideration = struct { curve: Curve, @@ -64,9 +69,9 @@ pub export fn entry6() void { // backend=stage2 // target=native // -// :17:14: error: missing tuple field with index 1 -// :23:14: error: missing tuple field with index 1 -// :39:14: error: expected at most 2 tuple fields; found 3 -// :45:30: error: index '2' out of bounds of tuple 'struct{comptime comptime_int = 123, u32}' -// :58:37: error: missing tuple field with index 3 -// :53:32: note: struct declared here +// :18:14: error: missing tuple field with index 1 +// :25:14: error: missing tuple field with index 1 +// :43:14: error: expected at most 2 tuple fields; found 3 +// :50:30: error: index '2' out of bounds of tuple 'struct{comptime comptime_int = 123, u32}' +// :63:37: error: missing tuple field with index 3 +// :58:32: note: struct declared here diff --git a/test/cases/compile_errors/union_access_of_inactive_field.zig b/test/cases/compile_errors/union_access_of_inactive_field.zig index 4f72914216fce157fc689d84d177add5ade64fcc..a1475fafe7dcb632a80a8f7eda93421fd900116c 100644 --- a/test/cases/compile_errors/union_access_of_inactive_field.zig +++ b/test/cases/compile_errors/union_access_of_inactive_field.zig @@ -5,6 +5,7 @@ const U = union { comptime { var u: U = .{ .a = {} }; const v = u.b; + _ = &u; _ = v; } diff --git a/test/cases/compile_errors/union_auto-enum_value_already_taken.zig b/test/cases/compile_errors/union_auto-enum_value_already_taken.zig index da2fefbad5a3035bc3d1c7beb403ef4f8e71ac05..31a027b7c023d86b39541c26199f1202939eba87 100644 --- a/test/cases/compile_errors/union_auto-enum_value_already_taken.zig +++ b/test/cases/compile_errors/union_auto-enum_value_already_taken.zig @@ -6,7 +6,7 @@ const MultipleChoice = union(enum(u32)) { E = 60, }; export fn entry() void { - var x = MultipleChoice{ .C = {} }; + const x: MultipleChoice = .{ .C = {} }; _ = x; } diff --git a/test/cases/compile_errors/union_duplicate_enum_field.zig b/test/cases/compile_errors/union_duplicate_enum_field.zig index 44eb58e01449d22d53bf6382c8e61d0cc69b9cb9..6a5fafbb2580da3bce182fbe43e195489ec41768 100644 --- a/test/cases/compile_errors/union_duplicate_enum_field.zig +++ b/test/cases/compile_errors/union_duplicate_enum_field.zig @@ -5,7 +5,7 @@ const U = union(E) { }; export fn foo() void { - var u: U = .{ .a = 123 }; + const u: U = .{ .a = 123 }; _ = u; } diff --git a/test/cases/compile_errors/union_enum_field_does_not_match_enum.zig b/test/cases/compile_errors/union_enum_field_does_not_match_enum.zig index 6b70c0eaf4b4cca3be373f7ce78234ce7489bce3..ad04f9b1a77fce57430bddbfb51845b11c45d618 100644 --- a/test/cases/compile_errors/union_enum_field_does_not_match_enum.zig +++ b/test/cases/compile_errors/union_enum_field_does_not_match_enum.zig @@ -10,7 +10,7 @@ const Payload = union(Letter) { D: bool, }; export fn entry() void { - var a = Payload{ .A = 1234 }; + const a: Payload = .{ .A = 1234 }; _ = a; } diff --git a/test/cases/compile_errors/union_noreturn_field_initialized.zig b/test/cases/compile_errors/union_noreturn_field_initialized.zig index df0a2df093a0b15284b2df0ac07309c87d680540..341256afef5d5fd82e548611facaba9aefa1b023 100644 --- a/test/cases/compile_errors/union_noreturn_field_initialized.zig +++ b/test/cases/compile_errors/union_noreturn_field_initialized.zig @@ -9,7 +9,7 @@ pub export fn entry1() void { }; var a = U{ .b = undefined }; - _ = a; + _ = &a; } pub export fn entry2() void { const U = union(enum) { @@ -25,7 +25,7 @@ pub export fn entry3() void { }; var e = @typeInfo(U).Union.tag_type.?.a; var u: U = undefined; - u = e; + u = (&e).*; } // error @@ -38,6 +38,6 @@ pub export fn entry3() void { // :19:10: error: cannot initialize 'noreturn' field of union // :16:9: note: field 'a' declared here // :15:15: note: union declared here -// :28:9: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field +// :28:13: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field // :23:9: note: 'noreturn' field here // :22:15: note: union declared here diff --git a/test/cases/compile_errors/union_runtime_coercion_from_enum.zig b/test/cases/compile_errors/union_runtime_coercion_from_enum.zig index 9020e9d5d7d202ef14c9c2660bee33df59508901..206b00800e864397f5e6ed81167dfaae3731c067 100644 --- a/test/cases/compile_errors/union_runtime_coercion_from_enum.zig +++ b/test/cases/compile_errors/union_runtime_coercion_from_enum.zig @@ -11,7 +11,7 @@ fn foo() E { } export fn doTheTest() u64 { var u: U = foo(); - return u.b; + return (&u).b; } // error diff --git a/test/cases/compile_errors/uncreachable_else_prong_err_set.zig b/test/cases/compile_errors/unreachable_else_prong_err_set.zig similarity index 84% rename from test/cases/compile_errors/uncreachable_else_prong_err_set.zig rename to test/cases/compile_errors/unreachable_else_prong_err_set.zig index 4b0ae462d6041943387f8cbca37367e7670ed5a9..29ff47a5bf39e0295e562a7fea8a9ca61e5aa9cc 100644 --- a/test/cases/compile_errors/uncreachable_else_prong_err_set.zig +++ b/test/cases/compile_errors/unreachable_else_prong_err_set.zig @@ -1,5 +1,6 @@ pub export fn complex() void { var a: error{ Foo, Bar } = error.Foo; + _ = &a; switch (a) { error.Foo => unreachable, error.Bar => unreachable, @@ -11,6 +12,7 @@ pub export fn complex() void { pub export fn simple() void { var a: error{ Foo, Bar } = error.Foo; + _ = &a; switch (a) { error.Foo => unreachable, error.Bar => unreachable, @@ -22,4 +24,4 @@ pub export fn simple() void { // backend=llvm // target=native // -// :6:14: error: unreachable else prong; all cases already handled +// :7:14: error: unreachable else prong; all cases already handled diff --git a/test/cases/compile_errors/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig b/test/cases/compile_errors/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig index 0842e98895787448a8c3d0bdf84297eafeabfcf5..d3b7e45f185ad785e40b7a7216602ce5740856d0 100644 --- a/test/cases/compile_errors/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig +++ b/test/cases/compile_errors/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig @@ -1,16 +1,15 @@ export fn entry() void { var x: i32 = 1234; var p: *i32 = &x; - var pp: *?*i32 = &p; + const pp: *?*i32 = &p; pp.* = null; - var y = p.*; - _ = y; + _ = p.*; } // error // backend=stage2 // target=native // -// :4:22: error: expected type '*?*i32', found '**i32' -// :4:22: note: pointer type child '*i32' cannot cast into pointer type child '?*i32' -// :4:22: note: mutable '*i32' allows illegal null values stored to type '?*i32' +// :4:24: error: expected type '*?*i32', found '**i32' +// :4:24: note: pointer type child '*i32' cannot cast into pointer type child '?*i32' +// :4:24: note: mutable '*i32' allows illegal null values stored to type '?*i32' diff --git a/test/cases/compile_errors/use_invalid_number_literal_as_array_index.zig b/test/cases/compile_errors/use_invalid_number_literal_as_array_index.zig index c52f614657854db7a8274c0a9b402b3a64c306ed..437d100c0ef1534c10fb1c08be18c381b72f5d78 100644 --- a/test/cases/compile_errors/use_invalid_number_literal_as_array_index.zig +++ b/test/cases/compile_errors/use_invalid_number_literal_as_array_index.zig @@ -1,7 +1,7 @@ var v = 25; export fn entry() void { var arr: [v]u8 = undefined; - _ = arr; + _ = &arr; } // error diff --git a/test/cases/compile_errors/variable_with_type_noreturn.zig b/test/cases/compile_errors/variable_with_type_noreturn.zig index 837a6e696599224d038cfbc541db11d0619b0714..0b04e1eacb834b2ec7e0f6bcfdbe925b707d99bb 100644 --- a/test/cases/compile_errors/variable_with_type_noreturn.zig +++ b/test/cases/compile_errors/variable_with_type_noreturn.zig @@ -1,6 +1,6 @@ export fn entry9() void { var z: noreturn = return; - _ = z; + _ = &z; } // error diff --git a/test/cases/compile_errors/variadic_arg_validation.zig b/test/cases/compile_errors/variadic_arg_validation.zig index 2e47a4fc1ed4f6adb8209060c601953eefa9973d..0dd0e60ee80c08c45c47623f25afb9943c2742c5 100644 --- a/test/cases/compile_errors/variadic_arg_validation.zig +++ b/test/cases/compile_errors/variadic_arg_validation.zig @@ -7,6 +7,7 @@ pub export fn entry() void { pub export fn entry1() void { var arr: [2]u8 = undefined; _ = printf("%d\n", arr); + _ = &arr; } pub export fn entry2() void { @@ -23,7 +24,7 @@ pub export fn entry3() void { // // :4:33: error: integer and float literals passed to variadic function must be casted to a fixed-size number type // :9:24: error: arrays must be passed by reference to variadic function -// :13:24: error: cannot pass 'u48' to variadic function -// :13:24: note: only integers with 0 or power of two bits are extern compatible -// :17:24: error: cannot pass 'void' to variadic function -// :17:24: note: 'void' is a zero bit type; for C 'void' use 'anyopaque' +// :14:24: error: cannot pass 'u48' to variadic function +// :14:24: note: only integers with 0 or power of two bits are extern compatible +// :18:24: error: cannot pass 'void' to variadic function +// :18:24: note: 'void' is a zero bit type; for C 'void' use 'anyopaque' diff --git a/test/cases/compile_errors/while_loop_body_expression_ignored.zig b/test/cases/compile_errors/while_loop_body_expression_ignored.zig index e33f48e6a54c8cbd452cee95e6f1b5a621dcfbc1..b3e83f202ad03ccdf81e9fa5df3d8e723f072801 100644 --- a/test/cases/compile_errors/while_loop_body_expression_ignored.zig +++ b/test/cases/compile_errors/while_loop_body_expression_ignored.zig @@ -6,18 +6,22 @@ export fn f1() void { } export fn f2() void { var x: ?i32 = null; + _ = &x; while (x) |_| returns(); } export fn f3() void { var x: anyerror!i32 = error.Bad; + _ = &x; while (x) |_| returns() else |_| unreachable; } export fn f4() void { var a = true; + _ = &a; while (a) {} else true; } export fn f5() void { var a = true; + _ = &a; const foo = while (a) returns() else true; _ = foo; } @@ -29,15 +33,15 @@ export fn f5() void { // :5:25: error: value of type 'usize' ignored // :5:25: note: all non-void values must be used // :5:25: note: this error can be suppressed by assigning the value to '_' -// :9:26: error: value of type 'usize' ignored -// :9:26: note: all non-void values must be used -// :9:26: note: this error can be suppressed by assigning the value to '_' -// :13:26: error: value of type 'usize' ignored -// :13:26: note: all non-void values must be used -// :13:26: note: this error can be suppressed by assigning the value to '_' -// :17:23: error: value of type 'bool' ignored -// :17:23: note: all non-void values must be used -// :17:23: note: this error can be suppressed by assigning the value to '_' -// :21:34: error: value of type 'usize' ignored -// :21:34: note: all non-void values must be used -// :21:34: note: this error can be suppressed by assigning the value to '_' +// :10:26: error: value of type 'usize' ignored +// :10:26: note: all non-void values must be used +// :10:26: note: this error can be suppressed by assigning the value to '_' +// :15:26: error: value of type 'usize' ignored +// :15:26: note: all non-void values must be used +// :15:26: note: this error can be suppressed by assigning the value to '_' +// :20:23: error: value of type 'bool' ignored +// :20:23: note: all non-void values must be used +// :20:23: note: this error can be suppressed by assigning the value to '_' +// :25:34: error: value of type 'usize' ignored +// :25:34: note: all non-void values must be used +// :25:34: note: this error can be suppressed by assigning the value to '_' diff --git a/test/cases/compile_errors/while_loop_break_value_ignored.zig b/test/cases/compile_errors/while_loop_break_value_ignored.zig index e2f81d2b5f042066b47a64820c4e0273456faa65..37f5fcb01884f556472bd0d720b29445f8b846cd 100644 --- a/test/cases/compile_errors/while_loop_break_value_ignored.zig +++ b/test/cases/compile_errors/while_loop_break_value_ignored.zig @@ -7,6 +7,7 @@ export fn f1() void { while (a) { break returns(); } + _ = &a; } export fn f2() void { @@ -16,6 +17,7 @@ export fn f2() void { break :outer returns(); } } + _ = &x; } // error @@ -24,5 +26,5 @@ export fn f2() void { // // :7:5: error: incompatible types: 'usize' and 'void' // :8:22: note: type 'usize' here -// :14:12: error: incompatible types: 'usize' and 'void' -// :16:33: note: type 'usize' here +// :15:12: error: incompatible types: 'usize' and 'void' +// :17:33: note: type 'usize' here diff --git a/test/cases/compile_errors/wrong_type_passed_to_panic.zig b/test/cases/compile_errors/wrong_type_passed_to_panic.zig index d6f142f24a15efd190390f05e41250ef1b30c8a8..bebaffb748cc6b29ff1eaca921f6ccd224b306ae 100644 --- a/test/cases/compile_errors/wrong_type_passed_to_panic.zig +++ b/test/cases/compile_errors/wrong_type_passed_to_panic.zig @@ -1,5 +1,5 @@ export fn entry() void { - var e = error.Foo; + const e = error.Foo; @panic(e); } diff --git a/test/cases/compile_log.0.zig b/test/cases/compile_log.0.zig index 7ca643f5918374a769da711694edf8c8e020ba07..07b7c715511adbe0517922489c2246c9ea41b891 100644 --- a/test/cases/compile_log.0.zig +++ b/test/cases/compile_log.0.zig @@ -4,7 +4,7 @@ export fn _start() noreturn { @compileLog(b, 20, f, x); @compileLog(1000); var bruh: usize = true; - _ = bruh; + _ = .{ &f, &bruh }; unreachable; } export fn other() void { diff --git a/test/cases/compile_log.1.zig b/test/cases/compile_log.1.zig index 2b64d8f906aeb403222dd097ad45b08f6202da8a..fa3e93bfbf1e3200edeb853ebe0cde9d872efbf4 100644 --- a/test/cases/compile_log.1.zig +++ b/test/cases/compile_log.1.zig @@ -1,6 +1,7 @@ export fn _start() noreturn { const b = true; var f: u32 = 1; + _ = &f; @compileLog(b, 20, f, x); @compileLog(1000); unreachable; diff --git a/test/cases/comptime_var.0.zig b/test/cases/comptime_var.0.zig index 14fb074c76ab2c079565e96a6b2847640115a3fb..7044e0fb2a935f6b2c8b3cb79688a3f517974825 100644 --- a/test/cases/comptime_var.0.zig +++ b/test/cases/comptime_var.0.zig @@ -1,5 +1,6 @@ pub fn main() void { var a: u32 = 0; + _ = &a; comptime var b: u32 = 0; if (a == 0) b = 3; } @@ -9,5 +10,5 @@ pub fn main() void { // target=x86_64-macos,x86_64-linux // link_libc=true // -// :4:19: error: store to comptime variable depends on runtime condition -// :4:11: note: runtime condition here +// :5:19: error: store to comptime variable depends on runtime condition +// :5:11: note: runtime condition here diff --git a/test/cases/comptime_var.1.zig b/test/cases/comptime_var.1.zig index 054d69250c38b5c2faba39e67db1b203d7b6eec7..d914ab45b54fe4340402eee07287fb08f476fcdd 100644 --- a/test/cases/comptime_var.1.zig +++ b/test/cases/comptime_var.1.zig @@ -1,5 +1,6 @@ pub fn main() void { var a: u32 = 0; + _ = &a; comptime var b: u32 = 0; switch (a) { 0 => {}, diff --git a/test/cases/comptime_var.5.zig b/test/cases/comptime_var.5.zig index 76a06f3d4b5931e8fd23271dcc593e07ff414a7f..bd3d878fa7e6ad1993b181c259393f1f7096fb71 100644 --- a/test/cases/comptime_var.5.zig +++ b/test/cases/comptime_var.5.zig @@ -1,5 +1,6 @@ pub fn main() void { var a: u32 = 0; + _ = &a; if (a == 0) { comptime var b: u32 = 0; b = 1; diff --git a/test/cases/conditions.5.zig b/test/cases/conditions.5.zig index 2d5ba338c7aea87a6f059d6f119bd1e0f7641793..9b2dfdb58e26689fa4966cd9aaffb67320c37314 100644 --- a/test/cases/conditions.5.zig +++ b/test/cases/conditions.5.zig @@ -10,6 +10,7 @@ fn assert(ok: bool) void { fn foo(ok: bool) i32 { const val: i32 = blk: { var x: i32 = 1; + _ = &x; if (!ok) break :blk x + @as(i32, 9); break :blk x + @as(i32, 19); }; diff --git a/test/cases/decl_value_arena.zig b/test/cases/decl_value_arena.zig index 9c7c12903b292695cf6f606a28176dfc7b94dcd9..42ed310b6f9d5f121a42b2d41cac30ccc6c31649 100644 --- a/test/cases/decl_value_arena.zig +++ b/test/cases/decl_value_arena.zig @@ -14,7 +14,7 @@ pub const Connection = struct { pub fn main() void { var conn: Connection = undefined; - _ = conn; + _ = &conn; } // run diff --git a/test/cases/enum_values.0.zig b/test/cases/enum_values.0.zig index 71c3e3521abe202f44ae8e2222a54a79cacabbf0..3e4ee609251af90712ead0f7d917f3801e37f982 100644 --- a/test/cases/enum_values.0.zig +++ b/test/cases/enum_values.0.zig @@ -4,8 +4,8 @@ pub fn main() void { var number1 = Number.One; var number2: Number = .Two; if (false) { - number1; - number2; + &number1; + &number2; } const number3: Number = @enumFromInt(2); if (@intFromEnum(number3) != 2) { diff --git a/test/cases/enum_values.1.zig b/test/cases/enum_values.1.zig index 934106dd7959d66fbb00f13d93789c9204379fd6..7679a8736181df789c317d34a0872f5705f521cd 100644 --- a/test/cases/enum_values.1.zig +++ b/test/cases/enum_values.1.zig @@ -2,7 +2,9 @@ const Number = enum { One, Two, Three }; pub fn main() void { var number1 = Number.One; + _ = &number1; var number2: Number = .Two; + _ = &number2; const number3: Number = @enumFromInt(2); assert(number1 != number2); assert(number2 != number3); @@ -10,6 +12,7 @@ pub fn main() void { assert(@intFromEnum(number2) == 1); assert(@intFromEnum(number3) == 2); var x: Number = .Two; + _ = &x; assert(number2 == x); return; diff --git a/test/cases/error_in_nested_declaration.zig b/test/cases/error_in_nested_declaration.zig index 20afacfb681c266c0bf0ce2693f3bbf9b99f2e39..c2dd7b9fa888860b80e1999c2e3279366013c8a9 100644 --- a/test/cases/error_in_nested_declaration.zig +++ b/test/cases/error_in_nested_declaration.zig @@ -19,7 +19,7 @@ const S2 = struct { pub export fn entry2() void { var s: S2 = undefined; - _ = s; + _ = &s; } // error diff --git a/test/cases/error_unions.0.zig b/test/cases/error_unions.0.zig index 355698e4b66b7e43c16c1c0b4c92b9161f1c9a11..89646e468105c10f79eb56ac585a943d9e59ec56 100644 --- a/test/cases/error_unions.0.zig +++ b/test/cases/error_unions.0.zig @@ -1,6 +1,7 @@ pub fn main() void { var e1 = error.Foo; var e2 = error.Bar; + _ = .{ &e1, &e2 }; assert(e1 != e2); assert(e1 == error.Foo); assert(e2 == error.Bar); diff --git a/test/cases/error_unions.1.zig b/test/cases/error_unions.1.zig index 526e1a110d4c74415d9c3036ae99b828efd133c7..792bc88412c62132e920699501abbb7d741747ad 100644 --- a/test/cases/error_unions.1.zig +++ b/test/cases/error_unions.1.zig @@ -1,5 +1,6 @@ pub fn main() u8 { var e: anyerror!u8 = 5; + _ = &e; const i = e catch 10; return i - 5; } diff --git a/test/cases/error_unions.2.zig b/test/cases/error_unions.2.zig index b66c7d78c073bb0ef4cd4365fed5873fb66901af..cc61263aa7d6d5e8ff564c79941e33af2af67afa 100644 --- a/test/cases/error_unions.2.zig +++ b/test/cases/error_unions.2.zig @@ -1,5 +1,6 @@ pub fn main() u8 { var e: anyerror!u8 = error.Foo; + _ = &e; const i = e catch 10; return i - 10; } diff --git a/test/cases/error_unions.3.zig b/test/cases/error_unions.3.zig index d37f826272dc32f990891837ed1a1a202a81fbd4..2661e3bc1921af305a003be488636bee1c480ed4 100644 --- a/test/cases/error_unions.3.zig +++ b/test/cases/error_unions.3.zig @@ -1,5 +1,6 @@ pub fn main() u8 { var e = foo(); + _ = &e; const i = e catch 69; return i - 5; } diff --git a/test/cases/error_unions.4.zig b/test/cases/error_unions.4.zig index bbc8dd34da3b637871424a45678b5f5c5f67620c..d6d121e1d6c29491f554f79b65567e3db8b3db74 100644 --- a/test/cases/error_unions.4.zig +++ b/test/cases/error_unions.4.zig @@ -1,5 +1,6 @@ pub fn main() u8 { var e = foo(); + _ = &e; const i = e catch 69; return i - 69; } diff --git a/test/cases/error_unions.5.zig b/test/cases/error_unions.5.zig index 96d52d1de1f3a3eb31741f0bfdd8f8791f92e232..0204cef9265b752da7d52ace190c9762f2e91b3f 100644 --- a/test/cases/error_unions.5.zig +++ b/test/cases/error_unions.5.zig @@ -1,5 +1,6 @@ pub fn main() u8 { var e = foo(); + _ = &e; const i = e catch 42; return i - 42; } diff --git a/test/cases/f32_passed_to_variadic_fn.zig b/test/cases/f32_passed_to_variadic_fn.zig index 16f95fdfe88ed8343b0522bdb9b57eff6e9c102c..3b3e034ab26ce1188f00118c16f823fb1df56c14 100644 --- a/test/cases/f32_passed_to_variadic_fn.zig +++ b/test/cases/f32_passed_to_variadic_fn.zig @@ -2,8 +2,8 @@ extern fn printf(format: [*:0]const u8, ...) c_int; pub fn main() void { var a: f64 = 2.0; var b: f32 = 10.0; - _ = printf("f64: %f\n", a); - _ = printf("f32: %f\n", b); + _ = printf("f64: %f\n", (&a).*); + _ = printf("f32: %f\n", (&b).*); } // run diff --git a/test/cases/inner_func_accessing_outer_var.zig b/test/cases/inner_func_accessing_outer_var.zig index e30cf58ef84d54e38ecfac903a7e47437d971a68..6b774ea9be51f48c6f5bf808da0f988d663a15ae 100644 --- a/test/cases/inner_func_accessing_outer_var.zig +++ b/test/cases/inner_func_accessing_outer_var.zig @@ -1,5 +1,6 @@ pub fn f() void { var bar: bool = true; + _ = &bar; const S = struct { fn baz() bool { return bar; @@ -10,6 +11,6 @@ pub fn f() void { // error // -// :5:20: error: mutable 'bar' not accessible from here +// :6:20: error: mutable 'bar' not accessible from here // :2:9: note: declared mutable here -// :3:15: note: crosses namespace boundary here +// :4:15: note: crosses namespace boundary here diff --git a/test/cases/llvm/blocks.zig b/test/cases/llvm/blocks.zig index c64909c7fea640a33c5fcf793f6ed82fe3189ba6..31a86c96e3f791e814adc39aea931050e5ac3d24 100644 --- a/test/cases/llvm/blocks.zig +++ b/test/cases/llvm/blocks.zig @@ -5,6 +5,7 @@ fn assert(ok: bool) void { fn foo(ok: bool) i32 { const val: i32 = blk: { var x: i32 = 1; + _ = &x; if (!ok) break :blk x + 9; break :blk x + 19; }; diff --git a/test/cases/llvm/f_segment_address_space_reading_and_writing.zig b/test/cases/llvm/f_segment_address_space_reading_and_writing.zig index ddcd41bf162a319d4aa5a76de273e1c7ca68d7d9..adf0a4da4d0ce7435a08e08425b78dd6bd4db434 100644 --- a/test/cases/llvm/f_segment_address_space_reading_and_writing.zig +++ b/test/cases/llvm/f_segment_address_space_reading_and_writing.zig @@ -35,6 +35,7 @@ pub fn main() void { assert(getFs() == @intFromPtr(&test_value)); var test_ptr: *allowzero addrspace(.fs) u64 = @ptrFromInt(0); + _ = &test_ptr; assert(test_ptr.* == 12345); test_ptr.* = 98765; assert(test_value == 98765); diff --git a/test/cases/llvm/nested_blocks.zig b/test/cases/llvm/nested_blocks.zig index 895f7e658b61fa5c381cf6902c150fe14ee5ea75..3a951f9361916bd5a646b873c902acbb3b6aa499 100644 --- a/test/cases/llvm/nested_blocks.zig +++ b/test/cases/llvm/nested_blocks.zig @@ -10,7 +10,7 @@ fn foo(ok: bool) i32 { }; break :blk val2 + 10; }; - return val; + return (&val).*; } pub fn main() void { diff --git a/test/cases/llvm/optionals.zig b/test/cases/llvm/optionals.zig index 7d52fc0f17d73b201c3aad46adf461cfe0fe5de2..110a9c511d56037225e8ec6192292875940b3bee 100644 --- a/test/cases/llvm/optionals.zig +++ b/test/cases/llvm/optionals.zig @@ -7,8 +7,10 @@ pub fn main() void { var null_val: ?i32 = null; var val1: i32 = opt_val.?; + _ = &val1; const val1_1: i32 = opt_val.?; var ptr_val1 = &(opt_val.?); + _ = &ptr_val1; const ptr_val1_1 = &(opt_val.?); var val2: i32 = null_val orelse 20; @@ -16,9 +18,11 @@ pub fn main() void { var value: i32 = 20; var ptr_val2 = &(null_val orelse value); + _ = &ptr_val2; const val3 = opt_val orelse 30; var val3_var = opt_val orelse 30; + _ = &val3_var; assert(val1 == 10); assert(val1_1 == 10); diff --git a/test/cases/llvm/simple_addition_and_subtraction.zig b/test/cases/llvm/simple_addition_and_subtraction.zig index 8a6f419f4a5c64649aa3f7618394c0264b667304..2c768d6be9d292c6bd179033a249f8ca808e078e 100644 --- a/test/cases/llvm/simple_addition_and_subtraction.zig +++ b/test/cases/llvm/simple_addition_and_subtraction.zig @@ -4,6 +4,7 @@ fn add(a: i32, b: i32) i32 { pub fn main() void { var a: i32 = -5; + _ = &a; const x = add(a, 7); var y = add(2, 0); y -= x; diff --git a/test/cases/locals.0.zig b/test/cases/locals.0.zig index f2df242792c6249864477ac4a69614f5032d6ceb..5698a66dcf498c4df55d3fa4c71566893d6e0952 100644 --- a/test/cases/locals.0.zig +++ b/test/cases/locals.0.zig @@ -3,8 +3,8 @@ pub fn main() void { var y: f32 = 42.0; var x: u8 = 10; if (false) { - y; - x; + &y; + &x / &i; } if (i != 5) unreachable; } diff --git a/test/cases/locals.1.zig b/test/cases/locals.1.zig index f7e59e1c02e8a328b3bc84e7d0f1820c92b22d22..0d0b63f6369fbdec0e01ff96773ea22531881122 100644 --- a/test/cases/locals.1.zig +++ b/test/cases/locals.1.zig @@ -1,8 +1,9 @@ pub fn main() void { var i: u8 = 5; var y: f32 = 42.0; - _ = y; + _ = &y; var x: u8 = 10; + _ = &x; foo(i, x); i = x; if (i != 10) unreachable; diff --git a/test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig b/test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig index 31093729baa7924f2f6461d8049ad5e2f40a2ba5..8afbc51f53fe5d3a85d341ab1e93f9407f7c0267 100644 --- a/test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig +++ b/test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig @@ -1,5 +1,6 @@ pub fn main() void { var x: usize = 5; + _ = &x; const y = mul(2, 3, x); if (y - 30 != 0) unreachable; } diff --git a/test/cases/only_1_function_and_it_gets_updated.1.zig b/test/cases/only_1_function_and_it_gets_updated.1.zig index 39909f93b8221f3085df667860dd63e7995f3e98..9982ca9ab813ed96d150af9870ee2402250a6738 100644 --- a/test/cases/only_1_function_and_it_gets_updated.1.zig +++ b/test/cases/only_1_function_and_it_gets_updated.1.zig @@ -1,6 +1,6 @@ pub export fn _start() noreturn { var dummy: u32 = 10; - _ = dummy; + _ = &dummy; while (true) {} } diff --git a/test/cases/optionals.0.zig b/test/cases/optionals.0.zig index e602bf1c8047d4b39bd8bb669df837b7842c3e5d..49841ac593228a17e7be03d81c903fccbc02e6e0 100644 --- a/test/cases/optionals.0.zig +++ b/test/cases/optionals.0.zig @@ -1,5 +1,6 @@ pub fn main() u8 { var x: ?u8 = 5; + _ = &x; var y: u8 = 0; if (x) |val| { y = val; diff --git a/test/cases/optionals.1.zig b/test/cases/optionals.1.zig index 26e81b890983755980f6e5701d04faec506ff49d..4bba10fc368d7ef8c65b5c10af069663cf2ccc31 100644 --- a/test/cases/optionals.1.zig +++ b/test/cases/optionals.1.zig @@ -1,5 +1,6 @@ pub fn main() u8 { var x: ?u8 = null; + _ = &x; var y: u8 = 0; if (x) |val| { y = val; diff --git a/test/cases/optionals.2.zig b/test/cases/optionals.2.zig index b610c6d2e9669ccbbe921cce11695c0200e2ba25..0464db35422bd67ac8a70392aa16608ed7dfc2bc 100644 --- a/test/cases/optionals.2.zig +++ b/test/cases/optionals.2.zig @@ -1,5 +1,6 @@ pub fn main() u8 { var x: ?u8 = 5; + _ = &x; return x.? - 5; } diff --git a/test/cases/optionals.3.zig b/test/cases/optionals.3.zig index d513c102827858be70c41f43bda1f6698fad19ed..849914fbb5c8cdfe6517d0286198b22ed5201094 100644 --- a/test/cases/optionals.3.zig +++ b/test/cases/optionals.3.zig @@ -1,6 +1,7 @@ pub fn main() u8 { var x: u8 = 5; var y: ?u8 = x; + _ = .{ &x, &y }; return y.? - 5; } diff --git a/test/cases/runtime_bitwise_and.zig b/test/cases/runtime_bitwise_and.zig index 3ba3d3124cc400d5ccd309f392c3fd2c593732e3..3e62c5346b00c1a7f2c782d8b3739f2a997033f4 100644 --- a/test/cases/runtime_bitwise_and.zig +++ b/test/cases/runtime_bitwise_and.zig @@ -7,6 +7,7 @@ pub fn main() void { var m2: u32 = 0b0000; assert(m1 & 0b1010 == 0b1010); assert(m2 & 0b1010 == 0b0000); + _ = .{ &i, &j, &m1, &m2 }; } fn assert(b: bool) void { if (!b) unreachable; diff --git a/test/cases/runtime_bitwise_or.zig b/test/cases/runtime_bitwise_or.zig index b97c2acf0228a3314eccb4ab859eee3a7dc2d77b..0cb702923719d2d8209d31953d41c65773813ed1 100644 --- a/test/cases/runtime_bitwise_or.zig +++ b/test/cases/runtime_bitwise_or.zig @@ -7,6 +7,7 @@ pub fn main() void { var m2: u32 = 0b0000; assert(m1 | 0b1010 == 0b1111); assert(m2 | 0b1010 == 0b1010); + _ = .{ &i, &j, &m1, &m2 }; } fn assert(b: bool) void { if (!b) unreachable; diff --git a/test/cases/safety/@asyncCall with too small a frame.zig b/test/cases/safety/@asyncCall with too small a frame.zig index 1a315930584ce83570bde72d2039b168935c20e4..3d7cdb3b1d02ff5dc53c829f51acbd2db2b40d41 100644 --- a/test/cases/safety/@asyncCall with too small a frame.zig +++ b/test/cases/safety/@asyncCall with too small a frame.zig @@ -13,8 +13,9 @@ pub fn main() !void { } var bytes: [1]u8 align(16) = undefined; var ptr = other; + _ = &ptr; var frame = @asyncCall(&bytes, {}, ptr, .{}); - _ = frame; + _ = &frame; return error.TestFailed; } fn other() callconv(.Async) void { diff --git a/test/cases/safety/@intCast to u0.zig b/test/cases/safety/@intCast to u0.zig index 8c9f76e2aa00f72b0dd75c1f578a7cbe7cd64bf3..a33da87f0fa8a0891b395be27ee7ac3c12fcec70 100644 --- a/test/cases/safety/@intCast to u0.zig +++ b/test/cases/safety/@intCast to u0.zig @@ -14,7 +14,7 @@ pub fn main() !void { } fn bar(one: u1, not_zero: i32) void { - var x = one << @as(u0, @intCast(not_zero)); + const x = one << @intCast(not_zero); _ = x; } // run diff --git a/test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig b/test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig index 41cff07e329c1375c5df0fb8fa3a74be6724c938..f8c448855e3422d93fd5686c414ee928231896fa 100644 --- a/test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig +++ b/test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var zero: usize = 0; - var b: *u8 = @ptrFromInt(zero); + _ = &zero; + const b: *u8 = @ptrFromInt(zero); _ = b; return error.TestFailed; } diff --git a/test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig b/test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig index 92e98d4777d3982f1d93f2b501a7128656ec356b..c9ae253df7bafa45aea06a4f4985245d6ab5dc27 100644 --- a/test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig +++ b/test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var zero: usize = 0; - var b: *i32 = @ptrFromInt(zero); + _ = &zero; + const b: *i32 = @ptrFromInt(zero); _ = b; return error.TestFailed; } diff --git a/test/cases/safety/@ptrFromInt with misaligned address.zig b/test/cases/safety/@ptrFromInt with misaligned address.zig index afb8aa7eb85375ddbde887aa2d5095ff8b61407f..3952ab9baa2f8efbdebb037abcea2ff58c440968 100644 --- a/test/cases/safety/@ptrFromInt with misaligned address.zig +++ b/test/cases/safety/@ptrFromInt with misaligned address.zig @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var x: usize = 5; - var y: [*]align(4) u8 = @ptrFromInt(x); + _ = &x; + const y: [*]align(4) u8 = @ptrFromInt(x); _ = y; return error.TestFailed; } diff --git a/test/cases/safety/@tagName on corrupted enum value.zig b/test/cases/safety/@tagName on corrupted enum value.zig index a541771df15727135d080ab3d2457d7fc0d0cc1d..e23cd1fcf6929a4b771c1cd271f3901ca31740b6 100644 --- a/test/cases/safety/@tagName on corrupted enum value.zig +++ b/test/cases/safety/@tagName on corrupted enum value.zig @@ -16,7 +16,7 @@ const E = enum(u32) { pub fn main() !void { var e: E = undefined; @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55); - var n = @tagName(e); + const n = @tagName(e); _ = n; return error.TestFailed; } diff --git a/test/cases/safety/@tagName on corrupted union value.zig b/test/cases/safety/@tagName on corrupted union value.zig index dd3d9bd3bffd2c5ad9eebfd89208b00d01a12f2c..f742834d15209bdd658370850674e86df9a57551 100644 --- a/test/cases/safety/@tagName on corrupted union value.zig +++ b/test/cases/safety/@tagName on corrupted union value.zig @@ -16,8 +16,8 @@ const U = union(enum(u32)) { pub fn main() !void { var u: U = undefined; @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55); - var t: @typeInfo(U).Union.tag_type.? = u; - var n = @tagName(t); + const t: @typeInfo(U).Union.tag_type.? = u; + const n = @tagName(t); _ = n; return error.TestFailed; } diff --git a/test/cases/safety/array slice sentinel mismatch non-scalar.zig b/test/cases/safety/array slice sentinel mismatch non-scalar.zig index 6ea136bc0140c0e926f26feca0b61806064b385b..5523970168e4d5fb13166ecda0e0e8d5f9e85fbd 100644 --- a/test/cases/safety/array slice sentinel mismatch non-scalar.zig +++ b/test/cases/safety/array slice sentinel mismatch non-scalar.zig @@ -11,7 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { const S = struct { a: u32 }; var arr = [_]S{ .{ .a = 1 }, .{ .a = 2 } }; - var s = arr[0..1 :.{ .a = 1 }]; + const s = arr[0..1 :.{ .a = 1 }]; _ = s; return error.TestFailed; } diff --git a/test/cases/safety/exact division failure - vectors.zig b/test/cases/safety/exact division failure - vectors.zig index cc8c01db9e3b880d342894054b4468f3967ba175..c5df2b276f175ddc9f8bfa9875eb4425263d7821 100644 --- a/test/cases/safety/exact division failure - vectors.zig +++ b/test/cases/safety/exact division failure - vectors.zig @@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { - var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 }; - var b: @Vector(4, i32) = [4]i32{ 111, 222, 333, 441 }; + const a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 }; + const b: @Vector(4, i32) = [4]i32{ 111, 222, 333, 441 }; const x = divExact(a, b); _ = x; return error.TestFailed; diff --git a/test/cases/safety/for_len_mismatch.zig b/test/cases/safety/for_len_mismatch.zig index 871e203f61c5d23cb2207516a5b6a7f529403133..ee21b947d7eeb22a8072ca1360e5a9b5659a3a3e 100644 --- a/test/cases/safety/for_len_mismatch.zig +++ b/test/cases/safety/for_len_mismatch.zig @@ -12,6 +12,7 @@ pub fn main() !void { var runtime_i: usize = 1; var j: usize = 3; var slice = "too long"; + _ = .{ &runtime_i, &j, &slice }; for (runtime_i..j, slice) |a, b| { _ = a; _ = b; diff --git a/test/cases/safety/for_len_mismatch_three.zig b/test/cases/safety/for_len_mismatch_three.zig index 0cfcddbfeecc9670cc1aea1e94dabd234306ffb3..70f854def51f8152e7255dcb034b1a8a322c5e50 100644 --- a/test/cases/safety/for_len_mismatch_three.zig +++ b/test/cases/safety/for_len_mismatch_three.zig @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var slice: []const u8 = "hello"; + _ = &slice; for (10..20, slice, 20..30) |a, b, c| { _ = a; _ = b; diff --git a/test/cases/safety/integer division by zero - vectors.zig b/test/cases/safety/integer division by zero - vectors.zig index a376b66fdb85e18f387e34890bcf539d8934e34e..6e2af616b9090d73ecd6b12885ad73d48017ac80 100644 --- a/test/cases/safety/integer division by zero - vectors.zig +++ b/test/cases/safety/integer division by zero - vectors.zig @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi std.process.exit(1); } pub fn main() !void { - var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 }; - var b: @Vector(4, i32) = [4]i32{ 111, 0, 333, 444 }; + const a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 }; + const b: @Vector(4, i32) = [4]i32{ 111, 0, 333, 444 }; const x = div0(a, b); _ = x; return error.TestFailed; diff --git a/test/cases/safety/memcpy_alias.zig b/test/cases/safety/memcpy_alias.zig index cf2da08f0cd006586b18f48a382b4e6239fbb588..d87a7bf6aa4df1a6f7cb622e953d8bcf1a693c93 100644 --- a/test/cases/safety/memcpy_alias.zig +++ b/test/cases/safety/memcpy_alias.zig @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var buffer = [2]u8{ 1, 2 } ** 5; var len: usize = 5; + _ = &len; @memcpy(buffer[0..len], buffer[4 .. 4 + len]); } // run diff --git a/test/cases/safety/memcpy_len_mismatch.zig b/test/cases/safety/memcpy_len_mismatch.zig index b5cb887c31d7fb58a1f06a62b27c13b74c993b30..6ca36abccbbf5a3f7818b3483a4e156cf6a9c8ac 100644 --- a/test/cases/safety/memcpy_len_mismatch.zig +++ b/test/cases/safety/memcpy_len_mismatch.zig @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var buffer = [2]u8{ 1, 2 } ** 5; var len: usize = 5; + _ = &len; @memcpy(buffer[0..len], buffer[len .. len + 4]); } // run diff --git a/test/cases/safety/memset_slice_undefined_bytes.zig b/test/cases/safety/memset_slice_undefined_bytes.zig index 70acc5fa6522369775da8b399486b7c56d78649b..4214b5db4b761a629a34bbddbee79957123d8a9c 100644 --- a/test/cases/safety/memset_slice_undefined_bytes.zig +++ b/test/cases/safety/memset_slice_undefined_bytes.zig @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var buffer = [6]u8{ 1, 2, 3, 4, 5, 6 }; var len = buffer.len; + _ = &len; @memset(buffer[0..len], undefined); var x: u8 = buffer[1]; x += buffer[2]; diff --git a/test/cases/safety/memset_slice_undefined_large.zig b/test/cases/safety/memset_slice_undefined_large.zig index 66298993c091a0aafd5e69dae60c89b9ddb7055a..d1f4f651d33b7deec8fed32b8816d376ff723aaa 100644 --- a/test/cases/safety/memset_slice_undefined_large.zig +++ b/test/cases/safety/memset_slice_undefined_large.zig @@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var buffer = [6]i32{ 1, 2, 3, 4, 5, 6 }; var len = buffer.len; + _ = &len; @memset(buffer[0..len], undefined); var x: i32 = buffer[1]; x += buffer[2]; diff --git a/test/cases/safety/optional unwrap operator on C pointer.zig b/test/cases/safety/optional unwrap operator on C pointer.zig index a4352192337cfaef773a0320cfd163a3bdbfb471..bd3313265a5012a5d37b6e7da55bbbfa9cdaccc9 100644 --- a/test/cases/safety/optional unwrap operator on C pointer.zig +++ b/test/cases/safety/optional unwrap operator on C pointer.zig @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var ptr: [*c]i32 = null; - var b = ptr.?; + _ = &ptr; + const b = ptr.?; _ = b; return error.TestFailed; } diff --git a/test/cases/safety/optional unwrap operator on null pointer.zig b/test/cases/safety/optional unwrap operator on null pointer.zig index 5749be9e36bafde0c4188a6464dd2da7449695cf..9dda4d0a9e07f7e717e0e954f7227f4c17a67675 100644 --- a/test/cases/safety/optional unwrap operator on null pointer.zig +++ b/test/cases/safety/optional unwrap operator on null pointer.zig @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var ptr: ?*i32 = null; - var b = ptr.?; + _ = &ptr; + const b = ptr.?; _ = b; return error.TestFailed; } diff --git a/test/cases/safety/pointer casting null to non-optional pointer.zig b/test/cases/safety/pointer casting null to non-optional pointer.zig index 6ec47f52fb76032f267c254df19595c41da65d77..fdf8dc17ce27db05de31bc32e1984ffeee8e41de 100644 --- a/test/cases/safety/pointer casting null to non-optional pointer.zig +++ b/test/cases/safety/pointer casting null to non-optional pointer.zig @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var c_ptr: [*c]u8 = 0; - var zig_ptr: *u8 = c_ptr; + _ = &c_ptr; + const zig_ptr: *u8 = c_ptr; _ = zig_ptr; return error.TestFailed; } diff --git a/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig b/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig index e03974f08d25692fbe523d3780bd8af6a8bb96e4..8970e0651629d59f5d5aa20f3e10715d062a622b 100644 --- a/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig +++ b/test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig @@ -10,7 +10,7 @@ fn foo() void { global_frame = @frame(); } var f = async bar(@frame()); - _ = f; + _ = &f; std.os.exit(1); } diff --git a/test/cases/safety/resuming a non-suspended function which never been suspended.zig b/test/cases/safety/resuming a non-suspended function which never been suspended.zig index fb3f5aa307f0ca1b085ae08ff928e2c73a15e493..420da72a5c0d3b60794e56f4015073733b55bbdd 100644 --- a/test/cases/safety/resuming a non-suspended function which never been suspended.zig +++ b/test/cases/safety/resuming a non-suspended function which never been suspended.zig @@ -7,7 +7,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } fn foo() void { var f = async bar(@frame()); - _ = f; + _ = &f; std.os.exit(1); } diff --git a/test/cases/safety/shift left by huge amount.zig b/test/cases/safety/shift left by huge amount.zig index d89f7d4ebef9e0ee5f065895d3ba4f6d7d53ae7e..a038c0ee4442be2c969108f46c3030c0b48fe262 100644 --- a/test/cases/safety/shift left by huge amount.zig +++ b/test/cases/safety/shift left by huge amount.zig @@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var x: u24 = 42; var y: u5 = 24; - var z = x >> y; + _ = .{ &x, &y }; + const z = x >> y; _ = z; return error.TestFailed; } diff --git a/test/cases/safety/shift right by huge amount.zig b/test/cases/safety/shift right by huge amount.zig index 8107bc17380bb856b73e6e70d7184b4781bfd555..ced81d948d48d2b801a4306a61f83efdb579f3b8 100644 --- a/test/cases/safety/shift right by huge amount.zig +++ b/test/cases/safety/shift right by huge amount.zig @@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var x: u24 = 42; var y: u5 = 24; - var z = x << y; + _ = .{ &x, &y }; + const z = x << y; _ = z; return error.TestFailed; } diff --git a/test/cases/safety/signed integer division overflow - vectors.zig b/test/cases/safety/signed integer division overflow - vectors.zig index 53e72e90feefddf9f2f0381ff74eaa37b6aea5d8..6346d9f1a1dd363e755d1efe50fd1d80fa507eeb 100644 --- a/test/cases/safety/signed integer division overflow - vectors.zig +++ b/test/cases/safety/signed integer division overflow - vectors.zig @@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { - var a: @Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 }; - var b: @Vector(4, i16) = [_]i16{ 1, 2, -1, 4 }; + const a: @Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 }; + const b: @Vector(4, i16) = [_]i16{ 1, 2, -1, 4 }; const x = div(a, b); if (x[2] == 32767) return error.Whatever; return error.TestFailed; diff --git a/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig b/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig index 9052913691de9fe470463d75e92ead994b028ecd..87c812eddc20f28d255dd99eeeb7de2a032c5072 100644 --- a/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig +++ b/test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var value: c_short = -1; - var casted: u32 = @intCast(value); + _ = &value; + const casted: u32 = @intCast(value); _ = casted; return error.TestFailed; } diff --git a/test/cases/safety/signed-unsigned vector cast.zig b/test/cases/safety/signed-unsigned vector cast.zig index 71d0690b5d7662c58f7f9c08c55a80911fc235ea..2e3b4d25d52d3023a94093b4b755f3505d24748a 100644 --- a/test/cases/safety/signed-unsigned vector cast.zig +++ b/test/cases/safety/signed-unsigned vector cast.zig @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var x: @Vector(4, i32) = @splat(-2147483647); - var y: @Vector(4, u32) = @intCast(x); + _ = &x; + const y: @Vector(4, u32) = @intCast(x); _ = y; return error.TestFailed; } diff --git a/test/cases/safety/slice start index greater than end index.zig b/test/cases/safety/slice start index greater than end index.zig index ef0485ae6015d1c73184702aa86dbcfa419c0f5c..83d489ab5699f235dce5401e7491e25ae149a14d 100644 --- a/test/cases/safety/slice start index greater than end index.zig +++ b/test/cases/safety/slice start index greater than end index.zig @@ -11,6 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var a: usize = 1; var b: usize = 10; + _ = .{ &a, &b }; var buf: [16]u8 = undefined; const slice = buf[b..a]; diff --git a/test/cases/safety/slice with sentinel out of bounds - runtime len.zig b/test/cases/safety/slice with sentinel out of bounds - runtime len.zig index 2f27bebd55c456a75cc040a4f2bf00d4193f9ae3..abb3cc42f092900af57e654016f31918c215407e 100644 --- a/test/cases/safety/slice with sentinel out of bounds - runtime len.zig +++ b/test/cases/safety/slice with sentinel out of bounds - runtime len.zig @@ -12,6 +12,7 @@ pub fn main() !void { var buf = [4]u8{ 'a', 'b', 'c', 0 }; const input: []u8 = &buf; var len: usize = 4; + _ = &len; const slice = input[0..len :0]; _ = slice; return error.TestFailed; diff --git a/test/cases/safety/slicing null C pointer - runtime len.zig b/test/cases/safety/slicing null C pointer - runtime len.zig index eda9de20d29b4d42aa72a3093ae7ec0dc6bec92b..dd73a5011205eb927e6cab8436b503e85714c43c 100644 --- a/test/cases/safety/slicing null C pointer - runtime len.zig +++ b/test/cases/safety/slicing null C pointer - runtime len.zig @@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var ptr: [*c]const u32 = null; var len: usize = 3; - var slice = ptr[0..len]; + _ = &len; + const slice = ptr[0..len]; _ = slice; return error.TestFailed; } diff --git a/test/cases/safety/slicing null C pointer.zig b/test/cases/safety/slicing null C pointer.zig index 6ef049c6a1cc7cd3fd91b2466fe11c07a295743e..862f2dcfdba6c8a2c0a867c4192d5d5e88974839 100644 --- a/test/cases/safety/slicing null C pointer.zig +++ b/test/cases/safety/slicing null C pointer.zig @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var ptr: [*c]const u32 = null; - var slice = ptr[0..3]; + _ = &ptr; + const slice = ptr[0..3]; _ = slice; return error.TestFailed; } diff --git a/test/cases/safety/truncating vector cast.zig b/test/cases/safety/truncating vector cast.zig index ec56953730a666c95419168331ff44931452c8b3..ae76d4dec125d709752551a5013f1aaeecefb233 100644 --- a/test/cases/safety/truncating vector cast.zig +++ b/test/cases/safety/truncating vector cast.zig @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var x: @Vector(4, u32) = @splat(0xdeadbeef); - var y: @Vector(4, u16) = @intCast(x); + _ = &x; + const y: @Vector(4, u16) = @intCast(x); _ = y; return error.TestFailed; } diff --git a/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig b/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig index bd35f354226c199a5396aeb830925050cca05d69..9bd4c4200702247aaaae4e5998ed6bb5ef626f79 100644 --- a/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig +++ b/test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig @@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var value: u8 = 245; - var casted: i8 = @intCast(value); + _ = &value; + const casted: i8 = @intCast(value); _ = casted; return error.TestFailed; } diff --git a/test/cases/safety/unsigned-signed vector cast.zig b/test/cases/safety/unsigned-signed vector cast.zig index 6f42ad5aa44e37cb3ebfc595061cd03508daa828..32676f7c1cb61f5a1de619e337160ff8f345bcaa 100644 --- a/test/cases/safety/unsigned-signed vector cast.zig +++ b/test/cases/safety/unsigned-signed vector cast.zig @@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi pub fn main() !void { var x: @Vector(4, u32) = @splat(0x80000000); - var y: @Vector(4, i32) = @intCast(x); + _ = &x; + const y: @Vector(4, i32) = @intCast(x); _ = y; return error.TestFailed; } diff --git a/test/cases/safety/vector integer addition overflow.zig b/test/cases/safety/vector integer addition overflow.zig index c553b4618937a083c83c3f1008481f039e4bb7c1..21c26eeb4e477673c751cce3bb477e22ac57ef12 100644 --- a/test/cases/safety/vector integer addition overflow.zig +++ b/test/cases/safety/vector integer addition overflow.zig @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi std.process.exit(1); } pub fn main() !void { - var a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 }; - var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; + const a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 }; + const b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; const x = add(a, b); _ = x; return error.TestFailed; diff --git a/test/cases/safety/vector integer multiplication overflow.zig b/test/cases/safety/vector integer multiplication overflow.zig index 4549f7c3e3578243d89bb9bb77b841afbe004933..8678eccec6fecb65087e062dc04b3d64c997b209 100644 --- a/test/cases/safety/vector integer multiplication overflow.zig +++ b/test/cases/safety/vector integer multiplication overflow.zig @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi std.process.exit(1); } pub fn main() !void { - var a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 }; - var b: @Vector(4, u8) = [_]u8{ 5, 6, 2, 8 }; + const a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 }; + const b: @Vector(4, u8) = [_]u8{ 5, 6, 2, 8 }; const x = mul(b, a); _ = x; return error.TestFailed; diff --git a/test/cases/safety/vector integer negation overflow.zig b/test/cases/safety/vector integer negation overflow.zig index 8c2c160c680f96537a5097fdf8637c29e75b02c1..5f8becad177ce4cb58b0a7ec818f603a0b1c1cfd 100644 --- a/test/cases/safety/vector integer negation overflow.zig +++ b/test/cases/safety/vector integer negation overflow.zig @@ -9,6 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { var a: @Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 }; + _ = &a; const x = neg(a); _ = x; return error.TestFailed; diff --git a/test/cases/safety/vector integer subtraction overflow.zig b/test/cases/safety/vector integer subtraction overflow.zig index bc475d9800dcced84a54e703f20d67604539e311..82c03421210496a4ef6861f3b73790680419f64a 100644 --- a/test/cases/safety/vector integer subtraction overflow.zig +++ b/test/cases/safety/vector integer subtraction overflow.zig @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi std.process.exit(1); } pub fn main() !void { - var a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 }; - var b: @Vector(4, u32) = [_]u32{ 5, 6, 7, 8 }; + const a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 }; + const b: @Vector(4, u32) = [_]u32{ 5, 6, 7, 8 }; const x = sub(b, a); _ = x; return error.TestFailed; diff --git a/test/cases/structs.0.zig b/test/cases/structs.0.zig index 03a8938d9ebcf80db462bb7f98d093b97a28003d..306cf73ebfa5a5b0becfb9c082d3d0b8915b2e5f 100644 --- a/test/cases/structs.0.zig +++ b/test/cases/structs.0.zig @@ -2,6 +2,7 @@ const Example = struct { x: u8 }; pub fn main() u8 { var example: Example = .{ .x = 5 }; + _ = &example; return example.x - 5; } diff --git a/test/cases/structs.2.zig b/test/cases/structs.2.zig index b1d3cbf080accc76edd40158f4f7c5946f9c7c79..7593284301b2508deab2e23aa6927e9b93c9c182 100644 --- a/test/cases/structs.2.zig +++ b/test/cases/structs.2.zig @@ -2,6 +2,7 @@ const Example = struct { x: u8, y: u8 }; pub fn main() u8 { var example: Example = .{ .x = 5, .y = 10 }; + _ = &example; return example.y + example.x - 15; } diff --git a/test/cases/structs.3.zig b/test/cases/structs.3.zig index 558b5a1e2d7109fdf53d0c9b862718588178440e..cfc064d67103a3009b128590ec98faf924647377 100644 --- a/test/cases/structs.3.zig +++ b/test/cases/structs.3.zig @@ -3,6 +3,7 @@ const Example = struct { x: u8, y: u8 }; pub fn main() u8 { var example: Example = .{ .x = 5, .y = 10 }; var example2: Example = .{ .x = 10, .y = 20 }; + _ = &example2; example = example2; return example.y + example.x - 30; diff --git a/test/cases/switch.0.zig b/test/cases/switch.0.zig index d0c0e43f8fb8d9a5cc41e1636c41ec24e9ffce71..f4a79fa772b36dcafeda9950f36a4caf7220e471 100644 --- a/test/cases/switch.0.zig +++ b/test/cases/switch.0.zig @@ -1,6 +1,7 @@ pub fn main() u8 { var val: u8 = 1; - var a: u8 = switch (val) { + _ = &val; + const a: u8 = switch (val) { 0, 1 => 2, 2 => 3, 3 => 4, diff --git a/test/cases/switch.1.zig b/test/cases/switch.1.zig index fe503bf212e45fb1c74940b227b33221868e146e..d93e1ccb4740b74081d7470597bb3957ba09446e 100644 --- a/test/cases/switch.1.zig +++ b/test/cases/switch.1.zig @@ -1,11 +1,13 @@ pub fn main() u8 { var val: u8 = 2; + _ = &val; var a: u8 = switch (val) { 0, 1 => 2, 2 => 3, 3 => 4, else => 5, }; + _ = &a; return a - 3; } diff --git a/test/cases/switch.2.zig b/test/cases/switch.2.zig index 24f40d8402ca658e294b45e1d771b9f5697efb90..1506d822d1c1552d085fa2edf4557f5ae7e328e2 100644 --- a/test/cases/switch.2.zig +++ b/test/cases/switch.2.zig @@ -1,6 +1,7 @@ pub fn main() u8 { var val: u8 = 10; - var a: u8 = switch (val) { + _ = &val; + const a: u8 = switch (val) { 0, 1 => 2, 2 => 3, 3 => 4, diff --git a/test/cases/switch.3.zig b/test/cases/switch.3.zig index e0b55db3bff6a6809e7ce5285ccce49f40b8c82b..6225dda3ff8792677e18b4877f51407a93efade1 100644 --- a/test/cases/switch.3.zig +++ b/test/cases/switch.3.zig @@ -2,7 +2,8 @@ const MyEnum = enum { One, Two, Three }; pub fn main() u8 { var val: MyEnum = .Two; - var a: u8 = switch (val) { + _ = &val; + const a: u8 = switch (val) { .One => 1, .Two => 2, .Three => 3, diff --git a/test/cases/type_of.0.zig b/test/cases/type_of.0.zig index 5f7702ef2cbd1a788b50973ca23b662772549896..823572c8636435afcf445143c4bf8b74c75cbbb9 100644 --- a/test/cases/type_of.0.zig +++ b/test/cases/type_of.0.zig @@ -1,5 +1,6 @@ pub fn main() void { var x: usize = 0; + _ = &x; const z = @TypeOf(x, @as(u128, 5)); assert(z == u128); } diff --git a/test/cases/while_loops.1.zig b/test/cases/while_loops.1.zig index 715a813b65e66c4b1f42e4b00b397b5933b0de35..283398adbce8469da74d8a2946539c0901a26ea1 100644 --- a/test/cases/while_loops.1.zig +++ b/test/cases/while_loops.1.zig @@ -2,6 +2,7 @@ pub fn main() u8 { var i: u8 = 0; while (i < @as(u8, 10)) { var x: u8 = 1; + _ = &x; i += x; } return i - 10; diff --git a/test/cases/while_loops.2.zig b/test/cases/while_loops.2.zig index 7ad8101c3777d2a94289fedd8406693f4b7c0861..fa4f9ed26c232656f38d6125095cb54a0805da68 100644 --- a/test/cases/while_loops.2.zig +++ b/test/cases/while_loops.2.zig @@ -2,6 +2,7 @@ pub fn main() u8 { var i: u8 = 0; while (i < @as(u8, 10)) { var x: u8 = 1; + _ = &x; i += x; if (i == @as(u8, 5)) break; } -- 2.54.0 From 9c16b2370d30e74a63a84a835d840266021424fd Mon Sep 17 00:00:00 2001 From: mlugg Date: Thu, 16 Nov 2023 13:21:18 +0000 Subject: [PATCH 05/15] test: update behavior to silence 'var is never mutated' errors --- test/behavior/abs.zig | 33 ++++ test/behavior/align.zig | 10 +- test/behavior/alignof.zig | 1 + test/behavior/array.zig | 33 +++- test/behavior/asm.zig | 1 + test/behavior/async_fn.zig | 32 ++-- test/behavior/await_struct.zig | 2 +- test/behavior/basic.zig | 19 +- test/behavior/bit_shifting.zig | 4 +- test/behavior/bitcast.zig | 26 ++- test/behavior/bitreverse.zig | 30 +++- test/behavior/bugs/10147.zig | 6 +- test/behavior/bugs/10970.zig | 1 + test/behavior/bugs/11046.zig | 1 + test/behavior/bugs/11139.zig | 1 + test/behavior/bugs/11159.zig | 6 +- test/behavior/bugs/11162.zig | 3 +- test/behavior/bugs/11165.zig | 4 +- test/behavior/bugs/11181.zig | 2 +- test/behavior/bugs/12000.zig | 1 + test/behavior/bugs/12025.zig | 1 + test/behavior/bugs/12092.zig | 1 + test/behavior/bugs/12498.zig | 1 + test/behavior/bugs/12776.zig | 1 + test/behavior/bugs/12891.zig | 5 + test/behavior/bugs/12972.zig | 1 + test/behavior/bugs/12984.zig | 2 +- test/behavior/bugs/13128.zig | 1 + test/behavior/bugs/13159.zig | 1 + test/behavior/bugs/13285.zig | 2 +- test/behavior/bugs/13366.zig | 2 + test/behavior/bugs/13714.zig | 1 + test/behavior/bugs/13785.zig | 1 + test/behavior/bugs/1381.zig | 1 + test/behavior/bugs/1442.zig | 1 + test/behavior/bugs/1500.zig | 1 + test/behavior/bugs/1735.zig | 2 +- test/behavior/bugs/2557.zig | 2 +- test/behavior/bugs/3468.zig | 1 + test/behavior/bugs/3586.zig | 2 +- test/behavior/bugs/4560.zig | 1 + test/behavior/bugs/6047.zig | 1 + test/behavior/bugs/624.zig | 1 + test/behavior/bugs/656.zig | 1 + test/behavior/bugs/6781.zig | 3 +- test/behavior/bugs/679.zig | 1 + test/behavior/bugs/6905.zig | 8 +- test/behavior/bugs/7187.zig | 2 +- test/behavior/bugs/726.zig | 6 +- test/behavior/bugs/7325.zig | 2 + test/behavior/bugs/9584.zig | 1 + test/behavior/byteswap.zig | 12 +- test/behavior/call.zig | 5 + test/behavior/cast.zig | 160 ++++++++++++----- test/behavior/cast_int.zig | 19 +- test/behavior/comptime_memory.zig | 2 +- test/behavior/destructure.zig | 4 + test/behavior/empty_union.zig | 4 + test/behavior/enum.zig | 15 +- test/behavior/error.zig | 22 ++- test/behavior/eval.zig | 59 ++++--- .../extern_struct_zero_size_fields.zig | 2 +- test/behavior/floatop.zig | 164 ++++++++++++++++-- test/behavior/fn.zig | 13 +- test/behavior/fn_in_struct_in_comptime.zig | 3 +- test/behavior/for.zig | 19 +- test/behavior/generics.zig | 2 + test/behavior/if.zig | 17 +- test/behavior/inline_switch.zig | 8 + test/behavior/int128.zig | 3 + test/behavior/int_comparison_elision.zig | 1 + test/behavior/int_div.zig | 2 + test/behavior/math.zig | 58 ++++++- test/behavior/maximum_minimum.zig | 29 +++- test/behavior/memcpy.zig | 1 + test/behavior/memset.zig | 7 +- test/behavior/muladd.zig | 20 ++- test/behavior/null.zig | 1 + test/behavior/optional.zig | 19 +- test/behavior/packed-struct.zig | 15 +- test/behavior/pointers.zig | 60 ++++--- test/behavior/popcount.zig | 10 ++ test/behavior/prefetch.zig | 1 + test/behavior/ptrcast.zig | 28 +-- test/behavior/ptrfromint.zig | 1 + test/behavior/saturating_arithmetic.zig | 2 + test/behavior/select.zig | 12 +- test/behavior/shuffle.zig | 12 +- test/behavior/sizeof_and_typeof.zig | 6 + test/behavior/slice.zig | 76 ++++---- test/behavior/struct.zig | 65 ++++--- .../struct_contains_null_ptr_itself.zig | 1 + test/behavior/switch.zig | 26 ++- test/behavior/truncate.zig | 29 ++-- test/behavior/tuple.zig | 33 +++- test/behavior/tuple_declarations.zig | 6 +- test/behavior/type.zig | 5 +- test/behavior/type_info.zig | 2 +- test/behavior/union.zig | 51 +++++- test/behavior/var_args.zig | 1 + test/behavior/vector.zig | 154 ++++++++++------ test/behavior/void.zig | 4 +- test/behavior/wasm.zig | 1 + test/behavior/widening.zig | 5 + 104 files changed, 1160 insertions(+), 390 deletions(-) diff --git a/test/behavior/abs.zig b/test/behavior/abs.zig index 51ade3dbcfc2ddd0f665341cf533fe6c75e3ef9c..fad29a1a586888bce0163f4e846ea0b2092e6ad3 100644 --- a/test/behavior/abs.zig +++ b/test/behavior/abs.zig @@ -16,26 +16,32 @@ test "@abs integers" { fn testAbsIntegers() !void { { var x: i32 = -1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: i32 = 0; + _ = &x; try expect(@abs(x) == 0); } { var x: i32 = 1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: i64 = std.math.minInt(i64); + _ = &x; try expect(@abs(x) == @as(u64, -std.math.minInt(i64))); } { var x: i5 = -1; + _ = &x; try expect(@abs(x) == 1); } { var x: i5 = -5; + _ = &x; try expect(@abs(x) == 5); } comptime { @@ -56,22 +62,27 @@ test "@abs unsigned integers" { fn testAbsUnsignedIntegers() !void { { var x: u32 = 1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: u32 = 0; + _ = &x; try expect(@abs(x) == 0); } { var x: u32 = 1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: u5 = 1; + _ = &x; try expect(@abs(x) == 1); } { var x: u5 = 5; + _ = &x; try expect(@abs(x) == 5); } comptime { @@ -102,27 +113,33 @@ test "@abs floats" { fn testAbsFloats(comptime T: type) !void { { var x: T = -2.62; + _ = &x; try expect(@abs(x) == 2.62); } { var x: T = 2.62; + _ = &x; try expect(@abs(x) == 2.62); } { var x: T = 0.0; + _ = &x; try expect(@abs(x) == 0.0); } { var x: T = -std.math.pi; + _ = &x; try expect(@abs(x) == std.math.pi); } { var x: T = -std.math.inf(T); + _ = &x; try expect(@abs(x) == std.math.inf(T)); } { var x: T = std.math.inf(T); + _ = &x; try expect(@abs(x) == std.math.inf(T)); } comptime { @@ -164,31 +181,37 @@ fn testAbsIntVectors(comptime len: comptime_int) !void { { var x: I32 = @splat(-10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: I32 = @splat(10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: I32 = @splat(0); var y: U32 = @splat(0); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: I64 = @splat(-10); var y: U64 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); } { var x: I64 = @splat(std.math.minInt(i64)); var y: U64 = @splat(-std.math.minInt(i64)); + _ = .{ &x, &y }; try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); } { var x = std.simd.repeat(len, @Vector(4, i32){ -2, 5, std.math.minInt(i32), -7 }); var y = std.simd.repeat(len, @Vector(4, u32){ 2, 5, -std.math.minInt(i32), 7 }); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } } @@ -225,26 +248,31 @@ fn testAbsUnsignedIntVectors(comptime len: comptime_int) !void { { var x: U32 = @splat(10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: U32 = @splat(10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: U32 = @splat(0); var y: U32 = @splat(0); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: U64 = @splat(10); var y: U64 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); } { var x = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); var y = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } } @@ -346,26 +374,31 @@ fn testAbsFloatVectors(comptime T: type, comptime len: comptime_int) !void { { var x: V = @splat(-7.5); var y: V = @splat(7.5); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(7.5); var y: V = @splat(7.5); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(0.0); var y: V = @splat(0.0); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(-std.math.pi); var y: V = @splat(std.math.pi); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(std.math.pi); var y: V = @splat(std.math.pi); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } } diff --git a/test/behavior/align.zig b/test/behavior/align.zig index 7b95cf8a56d6d6d3d771b7b2efa5bb49f5b93cea..4458bc49e9d69a09c302b8513082b9092d8598a8 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -29,6 +29,7 @@ test "slicing array of length 1 can not assume runtime index is always zero" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var runtime_index: usize = 1; + _ = &runtime_index; const slice = @as(*align(4) [1]u8, &foo)[runtime_index..]; try expect(@TypeOf(slice) == []u8); try expect(slice.len == 0); @@ -438,6 +439,7 @@ test "runtime-known array index has best alignment possible" { // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2 var smaller align(2) = [_]u32{ 1, 2, 3, 4 }; var runtime_zero: usize = 0; + _ = &runtime_zero; comptime assert(@TypeOf(smaller[runtime_zero..]) == []align(2) u32); comptime assert(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32); try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32); @@ -464,6 +466,7 @@ test "alignment of function with c calling convention" { const a = @alignOf(@TypeOf(nothing)); var runtime_nothing = ¬hing; + _ = &runtime_nothing; const casted1: *align(a) const u8 = @ptrCast(runtime_nothing); const casted2: *const fn () callconv(.C) void = @ptrCast(casted1); casted2(); @@ -486,6 +489,7 @@ test "read 128-bit field from default aligned struct in stack memory" { .nevermind = 1, .badguy = 12, }; + _ = &default_aligned; try expect(12 == default_aligned.badguy); } @@ -579,10 +583,10 @@ test "comptime alloc alignment" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; comptime var bytes1 = [_]u8{0}; - _ = bytes1; + _ = &bytes1; comptime var bytes2 align(256) = [_]u8{0}; - var bytes2_addr = @intFromPtr(&bytes2); + const bytes2_addr = @intFromPtr(&bytes2); try expect(bytes2_addr & 0xff == 0); } @@ -591,6 +595,7 @@ test "@alignCast null" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var ptr: ?*anyopaque = null; + _ = &ptr; const aligned: ?*anyopaque = @alignCast(ptr); try expect(aligned == null); } @@ -637,6 +642,7 @@ test "alignment of zero-bit types is respected" { var s32: S align(32) = .{}; var zero: usize = 0; + _ = &zero; try expect(@intFromPtr(&s) % @alignOf(usize) == 0); try expect(@intFromPtr(&s.arr) % @alignOf(usize) == 0); diff --git a/test/behavior/alignof.zig b/test/behavior/alignof.zig index 0443b2d6b3168f3495fbfa52c78e2ced937c8466..81d1e49fdfc7885a732f378ede578ec8e561aadd 100644 --- a/test/behavior/alignof.zig +++ b/test/behavior/alignof.zig @@ -31,6 +31,7 @@ test "correct alignment for elements and slices of aligned array" { var buf: [1024]u8 align(64) = undefined; var start: usize = 1; var end: usize = undefined; + _ = .{ &start, &end }; try expect(@alignOf(@TypeOf(buf[start..end])) == @alignOf(*u8)); try expect(@alignOf(@TypeOf(&buf[start..end])) == @alignOf(*u8)); try expect(@alignOf(@TypeOf(&buf[start])) == @alignOf(*u8)); diff --git a/test/behavior/array.zig b/test/behavior/array.zig index 2586770c6fa4a84052e1371af7dfa41a7610b9a0..e9a7f4b9c088ba1927ff97752c1502cdae6ab489 100644 --- a/test/behavior/array.zig +++ b/test/behavior/array.zig @@ -138,6 +138,7 @@ test "array literal with specified size" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var array = [2]u8{ 1, 2 }; + _ = &array; try expect(array[0] == 1); try expect(array[1] == 2); } @@ -146,7 +147,7 @@ test "array len field" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var arr = [4]u8{ 0, 0, 0, 0 }; - var ptr = &arr; + const ptr = &arr; try expect(arr.len == 4); try comptime expect(arr.len == 4); try expect(ptr.len == 4); @@ -163,7 +164,8 @@ test "array with sentinels" { { var zero_sized: [0:0xde]u8 = [_:0xde]u8{}; try expect(zero_sized[0] == 0xde); - var reinterpreted = @as(*[1]u8, @ptrCast(&zero_sized)); + var reinterpreted: *[1]u8 = @ptrCast(&zero_sized); + _ = &reinterpreted; try expect(reinterpreted[0] == 0xde); } var arr: [3:0x55]u8 = undefined; @@ -225,6 +227,7 @@ test "implicit comptime in array type size" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var arr: [plusOne(10)]bool = undefined; + _ = &arr; try expect(arr.len == 11); } @@ -281,6 +284,7 @@ test "anonymous list literal syntax" { const S = struct { fn doTheTest() !void { var array: [4]u8 = .{ 1, 2, 3, 4 }; + _ = &array; try expect(array[0] == 1); try expect(array[1] == 2); try expect(array[2] == 3); @@ -365,6 +369,7 @@ test "runtime initialize array elem and then implicit cast to slice" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var two: i32 = 2; + _ = &two; const x: []const i32 = &[_]i32{two}; try expect(x[0] == 2); } @@ -472,6 +477,7 @@ test "anonymous literal in array" { .{ .a = 3 }, .{ .b = 3 }, }; + _ = &array; try expect(array[0].a == 3); try expect(array[0].b == 4); try expect(array[1].a == 2); @@ -489,8 +495,10 @@ test "access the null element of a null terminated array" { const S = struct { fn doTheTest() !void { var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' }; + _ = &array; try expect(array[4] == 0); var len: usize = 4; + _ = &len; try expect(array[len] == 0); } }; @@ -510,6 +518,7 @@ test "type deduction for array subscript expression" { try expect(@as(u8, 0xAA) == array[if (v0) 1 else 0]); var v1 = false; try expect(@as(u8, 0x55) == array[if (v1) 1 else 0]); + _ = .{ &array, &v0, &v1 }; } }; try S.doTheTest(); @@ -529,7 +538,7 @@ test "sentinel element count towards the ABI size calculation" { fill_post: u8 = 0xAA, }; var x = T{}; - var as_slice = mem.asBytes(&x); + const as_slice = mem.asBytes(&x); try expect(@as(usize, 3) == as_slice.len); try expect(@as(u8, 0x55) == as_slice[0]); try expect(@as(u8, 0xAA) == as_slice[2]); @@ -559,6 +568,7 @@ test "zero-sized array with recursive type definition" { }; var t: S = .{ .list = .{ .s = undefined } }; + _ = &t; try expect(@as(usize, 0) == t.list.x); } @@ -576,15 +586,17 @@ test "type coercion of anon struct literal to array" { fn doTheTest() !void { var x1: u8 = 42; + _ = &x1; const t1 = .{ x1, 56, 54 }; - var arr1: [3]u8 = t1; + const arr1: [3]u8 = t1; try expect(arr1[0] == 42); try expect(arr1[1] == 56); try expect(arr1[2] == 54); var x2: U = .{ .a = 42 }; + _ = &x2; const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } }; - var arr2: [3]U = t2; + const arr2: [3]U = t2; try expect(arr2[0].a == 42); try expect(arr2[1].b == true); try expect(mem.eql(u8, arr2[2].c, "hello")); @@ -608,15 +620,17 @@ test "type coercion of pointer to anon struct literal to pointer to array" { fn doTheTest() !void { var x1: u8 = 42; + _ = &x1; const t1 = &.{ x1, 56, 54 }; - var arr1: *const [3]u8 = t1; + const arr1: *const [3]u8 = t1; try expect(arr1[0] == 42); try expect(arr1[1] == 56); try expect(arr1[2] == 54); var x2: U = .{ .a = 42 }; + _ = &x2; const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } }; - var arr2: *const [3]U = t2; + const arr2: *const [3]U = t2; try expect(arr2[0].a == 42); try expect(arr2[1].b == true); try expect(mem.eql(u8, arr2[2].c, "hello")); @@ -656,6 +670,7 @@ test "array init of container level array variable" { } noinline fn bar(x: usize, y: usize) void { var tmp: [2]usize = .{ x, y }; + _ = &tmp; pair = tmp; } }; @@ -668,6 +683,7 @@ test "array init of container level array variable" { test "runtime initialized sentinel-terminated array literal" { var c: u16 = 300; + _ = &c; const f = &[_:0x9999]u16{c}; const g = @as(*const [4]u8, @ptrCast(f)); try std.testing.expect(g[2] == 0x99); @@ -681,6 +697,7 @@ test "array of array agregate init" { var a = [1]u32{11} ** 10; var b = [1][10]u32{a} ** 2; + _ = .{ &a, &b }; try std.testing.expect(b[1][1] == 11); } @@ -778,6 +795,7 @@ test "runtime side-effects in comptime-known array init" { test "slice initialized through reference to anonymous array init provides result types" { var my_u32: u32 = 123; var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; const foo: []const u16 = &.{ @intCast(my_u32), @intCast(my_u64), @@ -790,6 +808,7 @@ test "slice initialized through reference to anonymous array init provides resul test "pointer to array initialized through reference to anonymous array init provides result types" { var my_u32: u32 = 123; var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; const foo: *const [4]u16 = &.{ @intCast(my_u32), @intCast(my_u64), diff --git a/test/behavior/asm.zig b/test/behavior/asm.zig index ca7497225e66c5869b5bdc403f2972643b83e639..acb17ea004f48f72a62374a5970d4b680f80d453 100644 --- a/test/behavior/asm.zig +++ b/test/behavior/asm.zig @@ -180,6 +180,7 @@ test "asm modifiers (AArch64)" { if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly var x: u32 = 15; + _ = &x; const double = asm ("add %[ret:w], %[in:w], %[in:w]" : [ret] "=r" (-> u32), : [in] "r" (x), diff --git a/test/behavior/async_fn.zig b/test/behavior/async_fn.zig index 7eaa5c78d02d7134a4faf5a9f69135b652dab88e..a8efbcfa8cf75fbe818f9ef5110696b5d7819888 100644 --- a/test/behavior/async_fn.zig +++ b/test/behavior/async_fn.zig @@ -137,11 +137,13 @@ test "@frameSize" { fn doTheTest() !void { { var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other)); + _ = &ptr; const size = @frameSize(ptr); try expect(size == @sizeOf(@Frame(other))); } { var ptr = @as(fn () callconv(.Async) void, @ptrCast(first)); + _ = &ptr; const size = @frameSize(ptr); try expect(size == @sizeOf(@Frame(first))); } @@ -153,7 +155,7 @@ test "@frameSize" { fn other(param: i32) void { _ = param; var local: i32 = undefined; - _ = local; + _ = &local; suspend {} } }; @@ -239,7 +241,7 @@ test "coroutine await" { await_seq('a'); var p = async await_amain(); - _ = p; + _ = &p; await_seq('f'); resume await_a_promise; await_seq('i'); @@ -279,7 +281,7 @@ test "coroutine await early return" { early_seq('a'); var p = async early_amain(); - _ = p; + _ = &p; early_seq('f'); try expect(early_final_result == 1234); try expect(std.mem.eql(u8, &early_points, "abcdef")); @@ -329,6 +331,7 @@ test "async fn pointer in a struct field" { bar: fn (*i32) callconv(.Async) void, }; var foo = Foo{ .bar = simpleAsyncFn2 }; + _ = &foo; var bytes: [64]u8 align(16) = undefined; const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); try comptime expect(@TypeOf(f) == anyframe->void); @@ -367,6 +370,7 @@ test "@asyncCall with return type" { } }; var foo = Foo{ .bar = Foo.middle }; + _ = &foo; var bytes: [150]u8 align(16) = undefined; var aresult: i32 = 0; _ = @asyncCall(&bytes, &aresult, foo.bar, .{}); @@ -385,6 +389,7 @@ test "async fn with inferred error set" { fn doTheTest() !void { var frame: [1]@Frame(middle) = undefined; var fn_ptr = middle; + _ = &fn_ptr; var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined; _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{}); resume global_frame; @@ -827,7 +832,7 @@ test "alignment of local variables in async functions" { const S = struct { fn doTheTest() !void { var y: u8 = 123; - _ = y; + _ = &y; var x: u8 align(128) = 1; try expect(@intFromPtr(&x) % 128 == 0); } @@ -843,7 +848,7 @@ test "no reason to resolve frame still works" { } fn simpleNothing() void { var x: i32 = 1234; - _ = x; + _ = &x; } test "async call a generic function" { @@ -913,13 +918,14 @@ test "struct parameter to async function is copied to the frame" { if (x == 0) return; clobberStack(x - 1); var y: i32 = x; - _ = y; + _ = &y; } fn bar(f: *@Frame(foo)) void { var pt = Point{ .x = 1, .y = 2 }; + _ = &pt; f.* = async foo(pt); - var result = await f; + const result = await f; expect(result == 1) catch @panic("test failure"); } @@ -1141,6 +1147,7 @@ test "@asyncCall using the result location inside the frame" { bar: fn (*i32) callconv(.Async) i32, }; var foo = Foo{ .bar = S.simple2 }; + _ = &foo; var bytes: [64]u8 align(16) = undefined; const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); try comptime expect(@TypeOf(f) == anyframe->i32); @@ -1465,7 +1472,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" { // the for loop spills still happen even though there is a VarDecl in scope // before the suspend. var anything = true; - _ = anything; + _ = &anything; suspend { global_frame = @frame(); } @@ -1538,6 +1545,7 @@ test "async function passed align(16) arg after align(8) arg" { fn foo() void { var a: u128 = 99; + _ = &a; bar(10, .{a}) catch unreachable; } @@ -1590,6 +1598,7 @@ test "async function call resolves target fn frame, runtime func" { const stack_size = 1000; var stack_frame: [stack_size]u8 align(std.Target.stack_align) = undefined; var func: fn () callconv(.Async) anyerror!void = bar; + _ = &func; return await @asyncCall(&stack_frame, {}, func, .{}); } @@ -1614,6 +1623,7 @@ test "properly spill optional payload capture value" { fn foo() void { var opt: ?usize = 1234; + _ = &opt; if (opt) |x| { bar(); global_int += x; @@ -1863,6 +1873,7 @@ test "@asyncCall with pass-by-value arguments" { var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; // The function pointer must not be comptime-known. var t = S.f; + _ = &t; var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, .{ .f0 = 1, .f1 = 2 }, @@ -1870,7 +1881,7 @@ test "@asyncCall with pass-by-value arguments" { [_]u8{ 1, 2, 3, 4, 5 }, F2, }); - _ = frame_ptr; + _ = &frame_ptr; } test "@asyncCall with arguments having non-standard alignment" { @@ -1893,6 +1904,7 @@ test "@asyncCall with arguments having non-standard alignment" { var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; // The function pointer must not be comptime-known. var t = S.f; + _ = &t; var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 }); - _ = frame_ptr; + _ = &frame_ptr; } diff --git a/test/behavior/await_struct.zig b/test/behavior/await_struct.zig index bc1420f96a75cd543c32fa3688f1e11aad19ff24..4175a90cd9dc201f8c27bc387a7859e78da61b57 100644 --- a/test/behavior/await_struct.zig +++ b/test/behavior/await_struct.zig @@ -14,7 +14,7 @@ test "coroutine await struct" { await_seq('a'); var p = async await_amain(); - _ = p; + _ = &p; await_seq('f'); resume await_a_promise; await_seq('i'); diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index 30b62866581b6bfbc64d2ebafaee476dc39104d4..c2ec18d0fe5470592d8e7762ac0796c460fafb1b 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -118,6 +118,7 @@ fn thisIsAColdFn() void { test "unicode escape in character literal" { var a: u24 = '\u{01f4a9}'; + _ = &a; try expect(a == 128169); } @@ -362,6 +363,7 @@ test "variable is allowed to be a pointer to an opaque type" { } fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA { var a = ptr; + _ = &a; return a; } @@ -441,6 +443,7 @@ test "double implicit cast in same expression" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x = @as(i32, @as(u16, nine())); + _ = &x; try expect(x == 9); } fn nine() u8 { @@ -570,6 +573,7 @@ test "comptime cast fn to ptr" { test "equality compare fn ptrs" { var a = &emptyFn; + _ = &a; try expect(a == a); } @@ -611,6 +615,7 @@ test "global constant is loaded with a runtime-known index" { const S = struct { fn doTheTest() !void { var index: usize = 1; + _ = &index; const ptr = &pieces[index].field; try expect(ptr.* == 2); } @@ -785,6 +790,7 @@ test "variable name containing underscores does not shadow int primitive" { test "if expression type coercion" { var cond: bool = true; + _ = &cond; const x: u16 = if (cond) 1 else 0; try expect(@as(u16, x) == 1); } @@ -825,6 +831,7 @@ test "discarding the result of various expressions" { test "labeled block implicitly ends in a break" { var a = false; + _ = &a; blk: { if (a) break :blk; } @@ -852,6 +859,7 @@ test "catch in block has correct result location" { test "labeled block with runtime branch forwards its result location type to break statements" { const E = enum { a, b }; var a = false; + _ = &a; const e: E = blk: { if (a) { break :blk .a; @@ -872,8 +880,7 @@ test "try in labeled block doesn't cast to wrong type" { }; const s: ?*S = blk: { var a = try S.foo(); - - _ = a; + _ = &a; break :blk null; }; _ = s; @@ -894,6 +901,7 @@ test "weird array and tuple initializations" { const E = enum { a, b }; const S = struct { e: E }; var a = false; + _ = &a; const b = S{ .e = .a }; _ = &[_]S{ @@ -1009,6 +1017,7 @@ test "switch inside @as gets correct type" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: u32 = 0; + _ = &a; var b: [2]u32 = undefined; b[0] = @as(u32, switch (a) { 1 => 1, @@ -1110,7 +1119,8 @@ test "orelse coercion as function argument" { } }; var optional: ?Loc = .{}; - var foo = Container.init(optional orelse .{}); + _ = &optional; + const foo = Container.init(optional orelse .{}); try expect(foo.a.?.start == -1); } @@ -1153,6 +1163,7 @@ test "arrays and vectors with big integers" { test "pointer to struct literal with runtime field is constant" { const S = struct { data: usize }; var runtime_zero: usize = 0; + _ = &runtime_zero; const ptr = &S{ .data = runtime_zero }; try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_const); } @@ -1163,6 +1174,7 @@ test "integer compare" { var z: T = 0; var p: T = 123; var n: T = -123; + _ = .{ &z, &p, &n }; try expect(z == z and z != p and z != n); try expect(p == p and p != n and n == n); try expect(z > n and z < p and z >= n and z <= p); @@ -1180,6 +1192,7 @@ test "integer compare" { fn doTheTestUnsigned(comptime T: type) !void { var z: T = 0; var p: T = 123; + _ = .{ &z, &p }; try expect(z == z and z != p); try expect(p == p); try expect(z < p and z <= p); diff --git a/test/behavior/bit_shifting.zig b/test/behavior/bit_shifting.zig index 8b605385d2cf96b97a08cb54303dde17ddbeb088..b47dfa23c17020b42841b241402c324329c7335c 100644 --- a/test/behavior/bit_shifting.zig +++ b/test/behavior/bit_shifting.zig @@ -99,9 +99,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c // #2225 test "comptime shr of BigInt" { comptime { - var n0 = 0xdeadbeef0000000000000000; + const n0 = 0xdeadbeef0000000000000000; try expect(n0 >> 64 == 0xdeadbeef); - var n1 = 17908056155735594659; + const n1 = 17908056155735594659; try expect(n1 >> 64 == 0); } } diff --git a/test/behavior/bitcast.zig b/test/behavior/bitcast.zig index 846a1c33afe389f1e594509463c6ab61f8720069..131a8ee0acf11b5fe736db407db65107b8f546c2 100644 --- a/test/behavior/bitcast.zig +++ b/test/behavior/bitcast.zig @@ -149,8 +149,9 @@ test "bitcast literal [4]u8 param to u32" { } test "bitcast generates a temporary value" { - var y = @as(u16, 0x55AA); - const x = @as(u16, @bitCast(@as([2]u8, @bitCast(y)))); + var y: u16 = 0x55AA; + _ = &y; + const x: u16 = @bitCast(@as([2]u8, @bitCast(y))); try expect(y == x); } @@ -171,7 +172,8 @@ test "@bitCast packed structs at runtime and comptime" { const S = struct { fn doTheTest() !void { var full = Full{ .number = 0x1234 }; - var two_halves = @as(Divided, @bitCast(full)); + _ = &full; + const two_halves: Divided = @bitCast(full); try expect(two_halves.half1 == 0x34); try expect(two_halves.quarter3 == 0x2); try expect(two_halves.quarter4 == 0x1); @@ -195,7 +197,8 @@ test "@bitCast extern structs at runtime and comptime" { const S = struct { fn doTheTest() !void { var full = Full{ .number = 0x1234 }; - var two_halves = @as(TwoHalves, @bitCast(full)); + _ = &full; + const two_halves: TwoHalves = @bitCast(full); switch (native_endian) { .big => { try expect(two_halves.half1 == 0x12); @@ -225,8 +228,9 @@ test "bitcast packed struct to integer and back" { const S = struct { fn doTheTest() !void { var move = LevelUpMove{ .move_id = 1, .level = 2 }; - var v = @as(u16, @bitCast(move)); - var back_to_a_move = @as(LevelUpMove, @bitCast(v)); + _ = &move; + const v: u16 = @bitCast(move); + const back_to_a_move: LevelUpMove = @bitCast(v); try expect(back_to_a_move.move_id == 1); try expect(back_to_a_move.level == 2); } @@ -312,7 +316,8 @@ test "@bitCast packed struct of floats" { const S = struct { fn doTheTest() !void { var foo = Foo{}; - var v = @as(Foo2, @bitCast(foo)); + _ = &foo; + const v: Foo2 = @bitCast(foo); try expect(v.a == foo.a); try expect(v.b == foo.b); try expect(v.c == foo.c); @@ -354,10 +359,12 @@ test "comptime @bitCast packed struct to int and back" { // S -> Int var s: S = .{}; + _ = &s; try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{}))); // Int -> S var i: Int = 0; + _ = &i; const rt_cast = @as(S, @bitCast(i)); const ct_cast = comptime @as(S, @bitCast(@as(Int, 0))); inline for (@typeInfo(S).Struct.fields) |field| { @@ -376,6 +383,7 @@ test "comptime bitcast with fields following f80" { const FloatT = extern struct { f: f80, x: u128 align(16) }; const x: FloatT = .{ .f = 0.5, .x = 123 }; var x_as_uint: u256 = comptime @as(u256, @bitCast(x)); + _ = &x_as_uint; try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f); try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x); @@ -428,6 +436,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u16, bitCastWrapper16(snan_f16_const)); var snan_f16_var = math.snan(f16); + _ = &snan_f16_var; try expectEqual(snan_u16, @as(u16, @bitCast(snan_f16_var))); try expectEqual(snan_u16, bitCastWrapper16(snan_f16_var)); @@ -437,6 +446,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u32, bitCastWrapper32(snan_f32_const)); var snan_f32_var = math.snan(f32); + _ = &snan_f32_var; try expectEqual(snan_u32, @as(u32, @bitCast(snan_f32_var))); try expectEqual(snan_u32, bitCastWrapper32(snan_f32_var)); @@ -446,6 +456,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u64, bitCastWrapper64(snan_f64_const)); var snan_f64_var = math.snan(f64); + _ = &snan_f64_var; try expectEqual(snan_u64, @as(u64, @bitCast(snan_f64_var))); try expectEqual(snan_u64, bitCastWrapper64(snan_f64_var)); @@ -455,6 +466,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u128, bitCastWrapper128(snan_f128_const)); var snan_f128_var = math.snan(f128); + _ = &snan_f128_var; try expectEqual(snan_u128, @as(u128, @bitCast(snan_f128_var))); try expectEqual(snan_u128, bitCastWrapper128(snan_f128_var)); } diff --git a/test/behavior/bitreverse.zig b/test/behavior/bitreverse.zig index b254910e461528b4bd813c4bd1f267b8c47bfb9b..a179e120e80fd4b82095b68facf2f7d48eeee147 100644 --- a/test/behavior/bitreverse.zig +++ b/test/behavior/bitreverse.zig @@ -86,11 +86,30 @@ fn testBitReverse() !void { try expect(@bitReverse(@as(i24, -6773785)) == @bitReverse(neg24)); var neg32: i32 = -16773785; try expect(@bitReverse(@as(i32, -16773785)) == @bitReverse(neg32)); + + _ = .{ + &num0, + &num5, + &num8, + &num16, + &num24, + &num32, + &num40, + &num48, + &num56, + &num64, + &num128, + &neg8, + &neg16, + &neg24, + &neg32, + }; } fn vector8() !void { var v = @Vector(2, u8){ 0x12, 0x23 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0x48); try expect(result[1] == 0xc4); } @@ -109,7 +128,8 @@ test "bitReverse vectors u8" { fn vector16() !void { var v = @Vector(2, u16){ 0x1234, 0x2345 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0x2c48); try expect(result[1] == 0xa2c4); } @@ -128,7 +148,8 @@ test "bitReverse vectors u16" { fn vector24() !void { var v = @Vector(2, u24){ 0x123456, 0x234567 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0x6a2c48); try expect(result[1] == 0xe6a2c4); } @@ -147,7 +168,8 @@ test "bitReverse vectors u24" { fn vector0() !void { var v = @Vector(2, u0){ 0, 0 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0); try expect(result[1] == 0); } diff --git a/test/behavior/bugs/10147.zig b/test/behavior/bugs/10147.zig index a1fe9bff6830f429dd8df237fbd0965196e5e2bf..b8d60904797693dde2711a879ee37fc6bd41ae6b 100644 --- a/test/behavior/bugs/10147.zig +++ b/test/behavior/bugs/10147.zig @@ -10,9 +10,11 @@ test "test calling @clz on both vector and scalar inputs" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u32 = 0x1; + _ = &x; var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 }; - var a = @clz(x); - var b = @clz(y); + _ = &y; + const a = @clz(x); + const b = @clz(y); try std.testing.expectEqual(@as(u6, 31), a); try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b); } diff --git a/test/behavior/bugs/10970.zig b/test/behavior/bugs/10970.zig index 539dfaff719a7dbeabd78f92301370bb0e143ad9..cd1c78ad98d143b49c7b2d074b68964b155bb6b2 100644 --- a/test/behavior/bugs/10970.zig +++ b/test/behavior/bugs/10970.zig @@ -9,6 +9,7 @@ test "breaking from a loop in an if statement" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var cond = true; + _ = &cond; const opt = while (cond) { if (retOpt()) |opt| { break opt; diff --git a/test/behavior/bugs/11046.zig b/test/behavior/bugs/11046.zig index a13e02e45c2455dd9cd72dd9e7021ed92cf4abfe..3c08dc649ecfbfa288dd5a8520e6d9ce82e9ccfc 100644 --- a/test/behavior/bugs/11046.zig +++ b/test/behavior/bugs/11046.zig @@ -2,6 +2,7 @@ const builtin = @import("builtin"); fn foo() !void { var a = true; + _ = &a; if (a) return error.Foo; return error.Bar; } diff --git a/test/behavior/bugs/11139.zig b/test/behavior/bugs/11139.zig index 7af8b59101192a629030d4a76a93f9bf6e27f5c3..93b25f39217f8cc9e401f5c6f584522a4fdf9bc3 100644 --- a/test/behavior/bugs/11139.zig +++ b/test/behavior/bugs/11139.zig @@ -21,5 +21,6 @@ fn storeArrayOfArrayOfStructs() u8 { S{ .x = 15 }, }, }; + _ = &cases; return cases[0][0].x; } diff --git a/test/behavior/bugs/11159.zig b/test/behavior/bugs/11159.zig index 352491fefc0404065debfa9c16b5c3fa0cbf50ae..56ffb45b82f57229d94e63bc69aad8403b939a7e 100644 --- a/test/behavior/bugs/11159.zig +++ b/test/behavior/bugs/11159.zig @@ -4,7 +4,7 @@ const builtin = @import("builtin"); test { const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); var a: T = .{ 0, 0 }; - _ = a; + _ = &a; } test { @@ -13,7 +13,7 @@ test { comptime y: u32 = 0, }; var a: S = .{}; - _ = a; + _ = &a; var b = S{}; - _ = b; + _ = &b; } diff --git a/test/behavior/bugs/11162.zig b/test/behavior/bugs/11162.zig index 6b4cef78e7be685e98f93fff58eae223c483acab..918cf1c7936b24f0485a114de936bdc18605a7fe 100644 --- a/test/behavior/bugs/11162.zig +++ b/test/behavior/bugs/11162.zig @@ -6,8 +6,9 @@ test "aggregate initializers should allow initializing comptime fields, verifyin if (true) return error.SkipZigTest; // TODO var x: u32 = 15; + _ = &x; const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); - var a: T = .{ -1234, 5678, x + 1 }; + const a: T = .{ -1234, 5678, x + 1 }; try expect(a[0] == -1234); try expect(a[1] == 5678); diff --git a/test/behavior/bugs/11165.zig b/test/behavior/bugs/11165.zig index e23861ddc1007f077540e70702e14a012af0e86c..ff4695f647b146020bc81b1642954ed0f403266f 100644 --- a/test/behavior/bugs/11165.zig +++ b/test/behavior/bugs/11165.zig @@ -18,7 +18,7 @@ test "bytes" { }; var u_2 = U{ .s = s_1 }; - _ = u_2; + _ = &u_2; } test "aggregate" { @@ -40,5 +40,5 @@ test "aggregate" { }; var u_2 = U{ .s = s_1 }; - _ = u_2; + _ = &u_2; } diff --git a/test/behavior/bugs/11181.zig b/test/behavior/bugs/11181.zig index 8abccc40c3a6130c315cd3442d3b01cfacd334c7..7819fe0ad83b55a332c815c89bb2944b55553d67 100644 --- a/test/behavior/bugs/11181.zig +++ b/test/behavior/bugs/11181.zig @@ -21,5 +21,5 @@ test "var inferred array of slices" { .{ .v = false }, }, }; - _ = decls; + _ = &decls; } diff --git a/test/behavior/bugs/12000.zig b/test/behavior/bugs/12000.zig index d7b856d2f5cd0147b41cfc39ad1beb7b33e38b52..d13e402d87ae5a575a38b29c75d5c3ec34b420ab 100644 --- a/test/behavior/bugs/12000.zig +++ b/test/behavior/bugs/12000.zig @@ -11,5 +11,6 @@ test { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO var t: T = .{ .next = null }; + _ = &t; try std.testing.expect(t.next == null); } diff --git a/test/behavior/bugs/12025.zig b/test/behavior/bugs/12025.zig index 92f8aff0aa1c03c23a4083d44fb0c841796e2059..73eca7c99b2046de11dffaeddf0ec7992626ba6b 100644 --- a/test/behavior/bugs/12025.zig +++ b/test/behavior/bugs/12025.zig @@ -5,6 +5,7 @@ test { .foo = &1, .bar = &2, }; + _ = &st; inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| { _ = field; diff --git a/test/behavior/bugs/12092.zig b/test/behavior/bugs/12092.zig index e5e89a9c5819d495ca6f5953047bbe320fc7d8dc..673a0f1f47cad67150c451a4b2a187e9feabd1ab 100644 --- a/test/behavior/bugs/12092.zig +++ b/test/behavior/bugs/12092.zig @@ -19,6 +19,7 @@ test { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO var baz: u32 = 24; + _ = &baz; try takeFoo(&.{ .a = .{ .b = baz, diff --git a/test/behavior/bugs/12498.zig b/test/behavior/bugs/12498.zig index 3e4bafc2db1ea994be232987a8de38719e9be283..fd9ee98d295b47a633499240411f6a03e5b79080 100644 --- a/test/behavior/bugs/12498.zig +++ b/test/behavior/bugs/12498.zig @@ -4,5 +4,6 @@ const expect = std.testing.expect; const S = struct { a: usize }; test "lazy abi size used in comparison" { var rhs: i32 = 100; + _ = &rhs; try expect(@sizeOf(S) < rhs); } diff --git a/test/behavior/bugs/12776.zig b/test/behavior/bugs/12776.zig index 91df319decabc45890688b2af83f8c3c3fae2764..8195a9df6fd6fd75417920822235972cd0450d84 100644 --- a/test/behavior/bugs/12776.zig +++ b/test/behavior/bugs/12776.zig @@ -22,6 +22,7 @@ const CPU = packed struct { } fn tick(self: *CPU) !void { var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F); + _ = &queued_interrupts; if (self.interrupts and queued_interrupts != 0) { self.interrupts = false; } diff --git a/test/behavior/bugs/12891.zig b/test/behavior/bugs/12891.zig index 354d9e856e2b2b347236fc2ff3ffb3a1a01dc06b..20caab294c40dfc3a4ef5565c43d2bfc32151512 100644 --- a/test/behavior/bugs/12891.zig +++ b/test/behavior/bugs/12891.zig @@ -4,26 +4,31 @@ const builtin = @import("builtin"); test "issue12891" { const f = 10.0; var i: usize = 0; + _ = &i; try std.testing.expect(i < f); } test "nan" { const f = comptime std.math.nan(f64); var i: usize = 0; + _ = &i; try std.testing.expect(!(f < i)); } test "inf" { const f = comptime std.math.inf(f64); var i: usize = 0; + _ = &i; try std.testing.expect(f > i); } test "-inf < 0" { const f = comptime -std.math.inf(f64); var i: usize = 0; + _ = &i; try std.testing.expect(f < i); } test "inf >= 1" { const f = comptime std.math.inf(f64); var i: usize = 1; + _ = &i; try std.testing.expect(f >= i); } test "isNan(nan * 1)" { diff --git a/test/behavior/bugs/12972.zig b/test/behavior/bugs/12972.zig index 3c256a19f81f5f1afe1a2f7d6c1c3e9243921c49..f27a6bac8d4327bd0dda9c72245bcbbc6a5bb2d9 100644 --- a/test/behavior/bugs/12972.zig +++ b/test/behavior/bugs/12972.zig @@ -12,6 +12,7 @@ test { f(&.{c}); var v: u8 = 42; + _ = &v; f(&[_:null]?u8{v}); f(&.{v}); } diff --git a/test/behavior/bugs/12984.zig b/test/behavior/bugs/12984.zig index 75f2747eda3dd9b54af050319046891b9863396b..5cbb021ba973c86c35335256d50b7b32f2b44ade 100644 --- a/test/behavior/bugs/12984.zig +++ b/test/behavior/bugs/12984.zig @@ -16,5 +16,5 @@ test "simple test" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO var c: CustomDraw = undefined; - _ = c; + _ = &c; } diff --git a/test/behavior/bugs/13128.zig b/test/behavior/bugs/13128.zig index b87513d51003d02757628522d752a634af8b813a..fff5be8e7e5bfc48532e7798ecf2c01d3b9e48cb 100644 --- a/test/behavior/bugs/13128.zig +++ b/test/behavior/bugs/13128.zig @@ -18,6 +18,7 @@ test "runtime union init, most-aligned field != largest" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u8 = 1; + _ = &x; try foo(.{ .x = x }); const val: U = @unionInit(U, "x", x); diff --git a/test/behavior/bugs/13159.zig b/test/behavior/bugs/13159.zig index eec01658e6e2e694b7349052ae24b4f8502ac95e..db28f9e5be93dce83fab37d67986ae8039e36fb3 100644 --- a/test/behavior/bugs/13159.zig +++ b/test/behavior/bugs/13159.zig @@ -13,5 +13,6 @@ test { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var foo = Bar.Baz.fizz; + _ = &foo; try expect(foo == .fizz); } diff --git a/test/behavior/bugs/13285.zig b/test/behavior/bugs/13285.zig index 15ebfa580431e56a47e4abbc45740f7a8ce99171..a50cf71e5594f912c6dd5d9a2336aa1d482cca83 100644 --- a/test/behavior/bugs/13285.zig +++ b/test/behavior/bugs/13285.zig @@ -8,7 +8,7 @@ test { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: Crasher = undefined; - var crasher_ptr = &a; + const crasher_ptr = &a; var crasher_local = crasher_ptr.*; const crasher_local_ptr = &crasher_local; crasher_local_ptr.lets_crash = 1; diff --git a/test/behavior/bugs/13366.zig b/test/behavior/bugs/13366.zig index 9b08bcd3fc46fba2b9c07d8c944408a9583c0e52..c87f122929f20c590fa72637206f39169f175597 100644 --- a/test/behavior/bugs/13366.zig +++ b/test/behavior/bugs/13366.zig @@ -18,9 +18,11 @@ test { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO var a: u32 = 16; + _ = &a; var reason = .{ .c_import = .{ .a = a } }; var block = Block{ .reason = &reason, }; + _ = █ try expect(block.reason.?.c_import.a == 16); } diff --git a/test/behavior/bugs/13714.zig b/test/behavior/bugs/13714.zig index f11dac36764a4f2599f16123fab8bd5e04fbd219..b1902720c52b5ba5f9942ec04b7ef300122dbbbc 100644 --- a/test/behavior/bugs/13714.zig +++ b/test/behavior/bugs/13714.zig @@ -1,4 +1,5 @@ comptime { var image: [1]u8 = undefined; + _ = ℑ _ = @shlExact(@as(u16, image[0]), 8); } diff --git a/test/behavior/bugs/13785.zig b/test/behavior/bugs/13785.zig index 53d03f541361c0b5b063b06f690f45c5dfce92d1..e3c71d954c41eb371bcbbd5307efd8071d448b02 100644 --- a/test/behavior/bugs/13785.zig +++ b/test/behavior/bugs/13785.zig @@ -9,5 +9,6 @@ test { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var a: u8 = 0; + _ = &a; try std.io.null_writer.print("\n{} {}\n", .{ a, S{} }); } diff --git a/test/behavior/bugs/1381.zig b/test/behavior/bugs/1381.zig index c9ea2102f59fa0f4259b7ee4f03a2543ad21563e..090883e875f97dce27771f73df5f3c47d303b718 100644 --- a/test/behavior/bugs/1381.zig +++ b/test/behavior/bugs/1381.zig @@ -20,6 +20,7 @@ test "union that needs padding bytes inside an array" { A{ .B = B{ .D = 1 } }, A{ .B = B{ .D = 1 } }, }; + _ = &as; const a = as[0].B; try std.testing.expect(a.D == 1); diff --git a/test/behavior/bugs/1442.zig b/test/behavior/bugs/1442.zig index 02170ccabe3d55e024f2571d50f44086e8693410..3d02686c4863e102ad76080a6b30e0e7a8c1b420 100644 --- a/test/behavior/bugs/1442.zig +++ b/test/behavior/bugs/1442.zig @@ -12,5 +12,6 @@ test "const error union field alignment" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var union_or_err: anyerror!Union = Union{ .Color = 1234 }; + _ = &union_or_err; try std.testing.expect((union_or_err catch unreachable).Color == 1234); } diff --git a/test/behavior/bugs/1500.zig b/test/behavior/bugs/1500.zig index cc12c5d0be9aedd06911a4b86c98c2733c2e740a..ac0d76f879b2687694e8e8326dd08b9c79122897 100644 --- a/test/behavior/bugs/1500.zig +++ b/test/behavior/bugs/1500.zig @@ -8,6 +8,7 @@ const B = *const fn (A) void; test "allow these dependencies" { var a: A = undefined; var b: B = undefined; + _ = .{ &a, &b }; if (false) { a; b; diff --git a/test/behavior/bugs/1735.zig b/test/behavior/bugs/1735.zig index 68f851e57875be49346961ba6c08c6485d0391dc..0115143b94ea6566878ded4955924767d44a6de9 100644 --- a/test/behavior/bugs/1735.zig +++ b/test/behavior/bugs/1735.zig @@ -45,6 +45,6 @@ test "initialization" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - var t = a.init(); + const t = a.init(); try std.testing.expect(t.foo.len == 0); } diff --git a/test/behavior/bugs/2557.zig b/test/behavior/bugs/2557.zig index 05cf8156c03d72520108f44afd59402d8a2fe339..3f05b628abfac6ed8ba828b213b9326d781d6671 100644 --- a/test/behavior/bugs/2557.zig +++ b/test/behavior/bugs/2557.zig @@ -2,5 +2,5 @@ test { var a = if (true) { return; } else true; - _ = a; + _ = &a; } diff --git a/test/behavior/bugs/3468.zig b/test/behavior/bugs/3468.zig index adf3db330681c74f6696bc9948c6b8b1b7aff2f9..293e608aec2981e344af18b5950de87ca1fdb97f 100644 --- a/test/behavior/bugs/3468.zig +++ b/test/behavior/bugs/3468.zig @@ -3,4 +3,5 @@ test "pointer deref next to assignment" { var a:i32=2; var b=&a; b.*=3; + _=&b; } diff --git a/test/behavior/bugs/3586.zig b/test/behavior/bugs/3586.zig index 19527147280af2cd850f993ebcc86d07c039d26d..5bc682b14919273851dd0bb1cf10b57afd90f573 100644 --- a/test/behavior/bugs/3586.zig +++ b/test/behavior/bugs/3586.zig @@ -12,5 +12,5 @@ test "fixed" { var ctr = Container{ .params = NoteParams{}, }; - _ = ctr; + _ = &ctr; } diff --git a/test/behavior/bugs/4560.zig b/test/behavior/bugs/4560.zig index ca9a34ea8975f20ab4c1f6268c5db51e5f05ca90..4f6e456755fa44c3afe4380f0acb14f54c9ea216 100644 --- a/test/behavior/bugs/4560.zig +++ b/test/behavior/bugs/4560.zig @@ -11,6 +11,7 @@ test "fixed" { .max_distance_from_start_index = 456, }, }; + _ = &s; try std.testing.expect(s.a == 1); try std.testing.expect(s.b.size == 123); try std.testing.expect(s.b.max_distance_from_start_index == 456); diff --git a/test/behavior/bugs/6047.zig b/test/behavior/bugs/6047.zig index 9e6547a116f1d1c774d4d99fcb9999e0c6b6dc96..0288a5262742347b70888fa88f8ce6bc9c281f97 100644 --- a/test/behavior/bugs/6047.zig +++ b/test/behavior/bugs/6047.zig @@ -6,6 +6,7 @@ fn getError() !void { fn getError2() !void { var a: u8 = 'c'; + _ = &a; try if (a == 'a') getError() else if (a == 'b') getError() else getError(); } diff --git a/test/behavior/bugs/624.zig b/test/behavior/bugs/624.zig index a0a93c0104f941888193d3de27360cdee76440ce..14d6bbdfb185199ad84b936f2f947e281dfbfe30 100644 --- a/test/behavior/bugs/624.zig +++ b/test/behavior/bugs/624.zig @@ -25,5 +25,6 @@ test "foo" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var allocator = ContextAllocator{ .n = 10 }; + _ = &allocator; try expect(allocator.n == 10); } diff --git a/test/behavior/bugs/656.zig b/test/behavior/bugs/656.zig index 004f442165a82630c2aa56e09d5061173aff78b0..a44ccb3647066fe74bf8728815f702e20d382258 100644 --- a/test/behavior/bugs/656.zig +++ b/test/behavior/bugs/656.zig @@ -22,6 +22,7 @@ fn foo(a: bool, b: bool) !void { var prefix_op = PrefixOp{ .AddrOf = Value{ .align_expr = 1234 }, }; + _ = &prefix_op; if (a) {} else { switch (prefix_op) { PrefixOp.AddrOf => |addr_of_info| { diff --git a/test/behavior/bugs/6781.zig b/test/behavior/bugs/6781.zig index eb1f9766d1a9e41eb5eef77ef5e162134dd869f8..fdbb1dd917537091da34502766230fe93ed42871 100644 --- a/test/behavior/bugs/6781.zig +++ b/test/behavior/bugs/6781.zig @@ -51,7 +51,8 @@ pub const JournalHeader = packed struct { return @as(u128, @bitCast(target[0..hash_chain_root_size].*)); } else { var array = target[0..hash_chain_root_size].*; - return @as(u128, @bitCast(array)); + _ = &array; + return @bitCast(array); } } diff --git a/test/behavior/bugs/679.zig b/test/behavior/bugs/679.zig index 6420e7f99f056751c8a8910b06feffb510f7e701..81de1bb038cfc55a00c95af2dacdab5896b02e75 100644 --- a/test/behavior/bugs/679.zig +++ b/test/behavior/bugs/679.zig @@ -14,5 +14,6 @@ const Element = struct { test "false dependency loop in struct definition" { const listType = ElementList; var x: listType = 42; + _ = &x; try expect(x == 42); } diff --git a/test/behavior/bugs/6905.zig b/test/behavior/bugs/6905.zig index be96efaacefd28cdb9193136c7d34336a842ddd2..2d473e108c2acc6ed22411b3c3c2b8fed1160382 100644 --- a/test/behavior/bugs/6905.zig +++ b/test/behavior/bugs/6905.zig @@ -6,13 +6,15 @@ test "sentinel-terminated 0-length slices" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO - var u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; + const u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; var index: u8 = 2; - var slice = u32s[index..index :2]; - var array_ptr = u32s[2..2 :2]; + _ = &index; + const slice = u32s[index..index :2]; + const array_ptr = u32s[2..2 :2]; const comptime_known_array_value = u32s[2..2 :2].*; var runtime_array_value = u32s[2..2 :2].*; + _ = &runtime_array_value; try expect(slice[0] == 2); try expect(array_ptr[0] == 2); diff --git a/test/behavior/bugs/7187.zig b/test/behavior/bugs/7187.zig index bb2e82af890f26e5bc1ec4b69b38fe9db98f4376..0af95129633a9da888022f9e1d75f1966e78d163 100644 --- a/test/behavior/bugs/7187.zig +++ b/test/behavior/bugs/7187.zig @@ -5,7 +5,7 @@ const expect = std.testing.expect; test "miscompilation with bool return type" { var x: usize = 1; var y: bool = getFalse(); - _ = y; + _ = .{ &x, &y }; try expect(x == 1); } diff --git a/test/behavior/bugs/726.zig b/test/behavior/bugs/726.zig index c544e422a442bc2be1f0a15416325c049fc3939a..e6fd6a92b3b91684cf8b8faf1177fd3e62d2031b 100644 --- a/test/behavior/bugs/726.zig +++ b/test/behavior/bugs/726.zig @@ -7,7 +7,8 @@ test "@ptrCast from const to nullable" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO const c: u8 = 4; - var x: ?*const u8 = @as(?*const u8, @ptrCast(&c)); + var x: ?*const u8 = @ptrCast(&c); + _ = &x; try expect(x.?.* == 4); } @@ -19,6 +20,7 @@ test "@ptrCast from var in empty struct to nullable" { const container = struct { var c: u8 = 4; }; - var x: ?*const u8 = @as(?*const u8, @ptrCast(&container.c)); + var x: ?*const u8 = @ptrCast(&container.c); + _ = &x; try expect(x.?.* == 4); } diff --git a/test/behavior/bugs/7325.zig b/test/behavior/bugs/7325.zig index 3652553b515797d80b697687468ba5f162742e53..85c3b385f00df79f244d81596ca1523f21be6f2c 100644 --- a/test/behavior/bugs/7325.zig +++ b/test/behavior/bugs/7325.zig @@ -85,6 +85,7 @@ test { var param: ParamType = .{ .one_of = .{ .name = "name" }, }; + _ = ¶m; var arg: CallArg = .{ .value = .{ .literal_enum_value = .{ @@ -92,6 +93,7 @@ test { }, }, }; + _ = &arg; const result = try genExpression(arg.value); switch (result) { diff --git a/test/behavior/bugs/9584.zig b/test/behavior/bugs/9584.zig index 6f3223c362256a9a1a32f1cf6964eafd9a49759a..0e41307bf4e3cc0beb248b7ed5cfd46b7913f478 100644 --- a/test/behavior/bugs/9584.zig +++ b/test/behavior/bugs/9584.zig @@ -60,6 +60,7 @@ test { .g = false, .h = false, }; + _ = &flags; var x = X{ .x = flags, }; diff --git a/test/behavior/byteswap.zig b/test/behavior/byteswap.zig index 88c5372364ab1608bf334c863dab812f8996b2e1..3cbf35a40ce22b7208128c478fc595e88759c1db 100644 --- a/test/behavior/byteswap.zig +++ b/test/behavior/byteswap.zig @@ -56,7 +56,8 @@ test "@byteSwap integers" { fn vector8() !void { var v = @Vector(2, u8){ 0x12, 0x13 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0x12); try expect(result[1] == 0x13); } @@ -75,7 +76,8 @@ test "@byteSwap vectors u8" { fn vector16() !void { var v = @Vector(2, u16){ 0x1234, 0x2345 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0x3412); try expect(result[1] == 0x4523); } @@ -94,7 +96,8 @@ test "@byteSwap vectors u16" { fn vector24() !void { var v = @Vector(2, u24){ 0x123456, 0x234567 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0x563412); try expect(result[1] == 0x674523); } @@ -113,7 +116,8 @@ test "@byteSwap vectors u24" { fn vector0() !void { var v = @Vector(2, u0){ 0, 0 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0); try expect(result[1] == 0); } diff --git a/test/behavior/call.zig b/test/behavior/call.zig index 61aa48803b10a9102259a6b54cd4ef00eebfe8b6..a476ba1788baddc36f8f50c59996e59a552e9e25 100644 --- a/test/behavior/call.zig +++ b/test/behavior/call.zig @@ -47,6 +47,7 @@ test "basic invocations" { { // call of non comptime-known function var alias_foo = &foo; + _ = &alias_foo; try expect(@call(.no_async, alias_foo, .{}) == 1234); try expect(@call(.never_tail, alias_foo, .{}) == 1234); try expect(@call(.never_inline, alias_foo, .{}) == 1234); @@ -66,6 +67,7 @@ test "tuple parameters" { }.add; var a: i32 = 12; var b: i32 = 34; + _ = .{ &a, &b }; try expect(@call(.auto, add, .{ a, 34 }) == 46); try expect(@call(.auto, add, .{ 12, b }) == 46); try expect(@call(.auto, add, .{ a, b }) == 46); @@ -101,6 +103,7 @@ test "result location of function call argument through runtime condition and st } }; var runtime = true; + _ = &runtime; try namespace.foo(.{ .e = if (!runtime) .a else .b, }); @@ -445,6 +448,7 @@ test "non-anytype generic parameters provide result type" { var rt_u16: u16 = 123; var rt_u32: u32 = 0x10000222; + _ = .{ &rt_u16, &rt_u32 }; try S.f(u8, @intCast(rt_u16)); try S.f(u8, @intCast(123)); @@ -470,6 +474,7 @@ test "argument to generic function has correct result type" { fn doTheTest() !void { var t = true; + _ = &t; // Since the enum literal passes through a runtime conditional here, these can only // compile if RLS provides the correct result type to the argument diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index aeb7a8f1faab84d693f1110f9d1ace6cec97aabd..486014074dbd2ada59edcfee08608590f841a055 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -58,6 +58,7 @@ test "@intCast to comptime_int" { test "implicit cast comptime numbers to any type when the value fits" { const a: u64 = 255; var b: u8 = a; + _ = &b; try expect(b == 255); } @@ -273,7 +274,7 @@ test "implicit cast from *[N]T to [*c]T" { test "*usize to *void" { var i = @as(usize, 0); - var v = @as(*void, @ptrCast(&i)); + const v: *void = @ptrCast(&i); v.* = {}; } @@ -391,7 +392,8 @@ test "peer type unsigned int to signed" { var w: u31 = 5; var x: u8 = 7; var y: i32 = -5; - var a = w + y + x; + _ = .{ &w, &x, &y }; + const a = w + y + x; try comptime expect(@TypeOf(a) == i32); try expect(a == 7); } @@ -401,8 +403,9 @@ test "expected [*c]const u8, found [*:0]const u8" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: [*:0]const u8 = "hello"; - var b: [*c]const u8 = a; - var c: [*:0]const u8 = b; + _ = &a; + const b: [*c]const u8 = a; + const c: [*:0]const u8 = b; try expect(std.mem.eql(u8, c[0..5], "hello")); } @@ -609,14 +612,16 @@ test "@intCast on vector" { fn doTheTest() !void { // Upcast (implicit, equivalent to @intCast) var up0: @Vector(2, u8) = [_]u8{ 0x55, 0xaa }; - var up1 = @as(@Vector(2, u16), up0); - var up2 = @as(@Vector(2, u32), up0); - var up3 = @as(@Vector(2, u64), up0); + _ = &up0; + const up1 = @as(@Vector(2, u16), up0); + const up2 = @as(@Vector(2, u32), up0); + const up3 = @as(@Vector(2, u64), up0); // Downcast (safety-checked) var down0 = up3; - var down1 = @as(@Vector(2, u32), @intCast(down0)); - var down2 = @as(@Vector(2, u16), @intCast(down0)); - var down3 = @as(@Vector(2, u8), @intCast(down0)); + _ = &down0; + const down1 = @as(@Vector(2, u32), @intCast(down0)); + const down2 = @as(@Vector(2, u16), @intCast(down0)); + const down3 = @as(@Vector(2, u8), @intCast(down0)); try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa })); try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa })); @@ -629,7 +634,8 @@ test "@intCast on vector" { fn doTheTestFloat() !void { var vec: @Vector(2, f32) = @splat(1234.0); - var wider: @Vector(2, f64) = vec; + _ = &vec; + const wider: @Vector(2, f64) = vec; try expect(wider[0] == 1234.0); try expect(wider[1] == 1234.0); } @@ -648,7 +654,8 @@ test "@floatCast cast down" { { var double: f64 = 0.001534; - var single = @as(f32, @floatCast(double)); + _ = &double; + const single = @as(f32, @floatCast(double)); try expect(single == 0.001534); } { @@ -672,6 +679,7 @@ test "peer type resolution: unreachable, error set, unreachable" { Unexpected, }; var err = Error.SystemResources; + _ = &err; const transformed_err = switch (err) { error.FileDescriptorAlreadyPresentInSet => unreachable, error.OperationCausesCircularLoop => unreachable, @@ -821,10 +829,11 @@ test "peer cast *[0]T to E![]const T" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var buffer: [5]u8 = "abcde".*; - var buf: anyerror![]const u8 = buffer[0..]; + const buf: anyerror![]const u8 = buffer[0..]; var b = false; - var y = if (b) &[0]u8{} else buf; - var z = if (!b) buf else &[0]u8{}; + _ = &b; + const y = if (b) &[0]u8{} else buf; + const z = if (!b) buf else &[0]u8{}; try expect(mem.eql(u8, "abcde", y catch unreachable)); try expect(mem.eql(u8, "abcde", z catch unreachable)); } @@ -835,9 +844,10 @@ test "peer cast *[0]T to []const T" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var buffer: [5]u8 = "abcde".*; - var buf: []const u8 = buffer[0..]; + const buf: []const u8 = buffer[0..]; var b = false; - var y = if (b) &[0]u8{} else buf; + _ = &b; + const y = if (b) &[0]u8{} else buf; try expect(mem.eql(u8, "abcde", y)); } @@ -846,6 +856,7 @@ test "peer cast *[N]T to [*]T" { var array = [4:99]i32{ 1, 2, 3, 4 }; var dest: [*]i32 = undefined; + _ = &dest; try expect(@TypeOf(&array, dest) == [*]i32); try expect(@TypeOf(dest, &array) == [*]i32); } @@ -879,8 +890,8 @@ test "peer cast [:x]T to []T" { const S = struct { fn doTheTest() !void { var array = [4:0]i32{ 1, 2, 3, 4 }; - var slice: [:0]i32 = &array; - var dest: []i32 = slice; + const slice: [:0]i32 = &array; + const dest: []i32 = slice; try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); } }; @@ -895,7 +906,8 @@ test "peer cast [N:x]T to [N]T" { const S = struct { fn doTheTest() !void { var array = [4:0]i32{ 1, 2, 3, 4 }; - var dest: [4]i32 = array; + _ = &array; + const dest: [4]i32 = array; try expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 })); } }; @@ -910,7 +922,7 @@ test "peer cast *[N:x]T to *[N]T" { const S = struct { fn doTheTest() !void { var array = [4:0]i32{ 1, 2, 3, 4 }; - var dest: *[4]i32 = &array; + const dest: *[4]i32 = &array; try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); } }; @@ -925,7 +937,7 @@ test "peer cast [*:x]T to [*]T" { const S = struct { fn doTheTest() !void { var array = [4:99]i32{ 1, 2, 3, 4 }; - var dest: [*]i32 = &array; + const dest: [*]i32 = &array; try expect(dest[0] == 1); try expect(dest[1] == 2); try expect(dest[2] == 3); @@ -945,8 +957,8 @@ test "peer cast [:x]T to [*:x]T" { const S = struct { fn doTheTest() !void { var array = [4:0]i32{ 1, 2, 3, 4 }; - var slice: [:0]i32 = &array; - var dest: [*:0]i32 = slice; + const slice: [:0]i32 = &array; + const dest: [*:0]i32 = slice; try expect(dest[0] == 1); try expect(dest[1] == 2); try expect(dest[2] == 3); @@ -998,6 +1010,7 @@ test "peer type resolution implicit cast to variable type" { test "variable initialization uses result locations properly with regards to the type" { var b = true; + _ = &b; const x: i32 = if (b) 1 else 2; try expect(x == 1); } @@ -1025,7 +1038,7 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" { var array: [4:0]u8 = undefined; array[4] = 0; // TODO remove this when #4372 is solved - var slice: [:0]u8 = array[0..4 :0]; + const slice: [:0]u8 = array[0..4 :0]; try comptime expect(@TypeOf(slice, "hi") == [:0]const u8); try comptime expect(@TypeOf("hi", slice) == [:0]const u8); } @@ -1042,6 +1055,7 @@ test "peer type resolve array pointer and unknown pointer" { var array: [4]u8 = undefined; var const_ptr: [*]const u8 = undefined; var ptr: [*]u8 = undefined; + _ = .{ &const_ptr, &ptr }; try comptime expect(@TypeOf(&array, ptr) == [*]u8); try comptime expect(@TypeOf(ptr, &array) == [*]u8); @@ -1090,6 +1104,7 @@ test "implicit cast from [*]T to ?*anyopaque" { var a = [_]u8{ 3, 2, 1 }; var runtime_zero: usize = 0; + _ = &runtime_zero; incrementVoidPtrArray(a[runtime_zero..].ptr, 3); try expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 })); } @@ -1151,11 +1166,11 @@ test "implicit ptr to *anyopaque" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: u32 = 1; - var ptr: *align(@alignOf(u32)) anyopaque = &a; - var b: *u32 = @as(*u32, @ptrCast(ptr)); + const ptr: *align(@alignOf(u32)) anyopaque = &a; + const b: *u32 = @as(*u32, @ptrCast(ptr)); try expect(b.* == 1); - var ptr2: ?*align(@alignOf(u32)) anyopaque = &a; - var c: *u32 = @as(*u32, @ptrCast(ptr2.?)); + const ptr2: ?*align(@alignOf(u32)) anyopaque = &a; + const c: *u32 = @as(*u32, @ptrCast(ptr2.?)); try expect(c.* == 1); } @@ -1264,6 +1279,7 @@ test "implicit cast *[0]T to E![]const u8" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x = @as(anyerror![]const u8, &[0]u8{}); + _ = &x; try expect((x catch unreachable).len == 0); } @@ -1274,6 +1290,7 @@ test "cast from array reference to fn: comptime fn ptr" { } test "cast from array reference to fn: runtime fn ptr" { var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array)); + _ = &f; try expect(@intFromPtr(f) == @intFromPtr(&global_array)); } @@ -1285,7 +1302,8 @@ test "*const [N]null u8 to ?[]const u8" { const S = struct { fn doTheTest() !void { var a = "Hello"; - var b: ?[]const u8 = a; + _ = &a; + const b: ?[]const u8 = a; try expect(mem.eql(u8, b.?, "Hello")); } }; @@ -1318,12 +1336,13 @@ test "assignment to optional pointer result loc" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var foo: struct { ptr: ?*anyopaque } = .{ .ptr = &global_struct }; + _ = &foo; try expect(foo.ptr.? == @as(*anyopaque, @ptrCast(&global_struct))); } test "cast between *[N]void and []void" { var a: [4]void = undefined; - var b: []void = &a; + const b: []void = &a; try expect(b.len == 4); } @@ -1351,6 +1370,7 @@ test "cast f16 to wider types" { const S = struct { fn doTheTest() !void { var x: f16 = 1234.0; + _ = &x; try expect(@as(f32, 1234.0) == x); try expect(@as(f64, 1234.0) == x); try expect(@as(f128, 1234.0) == x); @@ -1370,6 +1390,7 @@ test "cast f128 to narrower types" { const S = struct { fn doTheTest() !void { var x: f128 = 1234.0; + _ = &x; try expect(@as(f16, 1234.0) == @as(f16, @floatCast(x))); try expect(@as(f32, 1234.0) == @as(f32, @floatCast(x))); try expect(@as(f64, 1234.0) == @as(f64, @floatCast(x))); @@ -1404,6 +1425,7 @@ test "cast i8 fn call peers to i32 result" { const S = struct { fn doTheTest() !void { var cond = true; + _ = &cond; const value: i32 = if (cond) smallBoi() else bigBoi(); try expect(value == 123); } @@ -1424,7 +1446,8 @@ test "cast compatible optional types" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: ?[:0]const u8 = null; - var b: ?[]const u8 = a; + _ = &a; + const b: ?[]const u8 = a; try expect(b == null); } @@ -1434,6 +1457,7 @@ test "coerce undefined single-item pointer of array to error union of slice" { const a = @as([*]u8, undefined)[0..0]; var b: error{a}![]const u8 = a; + _ = &b; const s = try b; try expect(s.len == 0); } @@ -1442,6 +1466,7 @@ test "pointer to empty struct literal to mutable slice" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: []i32 = &.{}; + _ = &x; try expect(x.len == 0); } @@ -1466,7 +1491,7 @@ test "coerce between pointers of compatible differently-named floats" { else => @compileError("unreachable"), }; var f1: F = 12.34; - var f2: *c_longdouble = &f1; + const f2: *c_longdouble = &f1; f2.* += 1; try expect(f1 == @as(F, 12.34) + 1); } @@ -1507,8 +1532,9 @@ test "implicit cast from [:0]T to [*c]T" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO var a: [:0]const u8 = "foo"; - var b: [*c]const u8 = a; - var c = std.mem.span(b); + _ = &a; + const b: [*c]const u8 = a; + const c = std.mem.span(b); try expect(c.len == a.len); try expect(c.ptr == a.ptr); } @@ -1544,6 +1570,7 @@ test "single item pointer to pointer to array to slice" { test "peer type resolution forms error union" { var foo: i32 = 123; + _ = &foo; const result = if (foo < 0) switch (-foo) { 0 => unreachable, 42 => error.AccessDenied, @@ -1561,7 +1588,7 @@ test "@constCast without a result location" { test "@volatileCast without a result location" { var x: i32 = 1234; - var y: *volatile i32 = &x; + const y: *volatile i32 = &x; const z = @volatileCast(y); try expect(@TypeOf(z) == *i32); try expect(z.* == 1234); @@ -1585,10 +1612,12 @@ test "peer type resolution: const sentinel slice and mutable non-sentinel slice" fn doTheTest(comptime T: type, comptime s: T) !void { var a: [:s]const T = @as(*const [2:s]T, @ptrFromInt(0x1000)); var b: []T = @as(*[3]T, @ptrFromInt(0x2000)); + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == []const T); comptime assert(@TypeOf(b, a) == []const T); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1611,10 +1640,12 @@ test "peer type resolution: float and comptime-known fixed-width integer" { const i: u8 = 100; var f: f32 = 1.234; + _ = &f; comptime assert(@TypeOf(i, f) == f32); comptime assert(@TypeOf(f, i) == f32); var t = true; + _ = &t; const r1 = if (t) i else f; const r2 = if (t) f else i; @@ -1631,10 +1662,12 @@ test "peer type resolution: same array type with sentinel" { var a: [2:0]u32 = .{ 0, 1 }; var b: [2:0]u32 = .{ 2, 3 }; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == [2:0]u32); comptime assert(@TypeOf(b, a) == [2:0]u32); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1651,10 +1684,12 @@ test "peer type resolution: array with sentinel and array without sentinel" { var a: [2:0]u32 = .{ 0, 1 }; var b: [2]u32 = .{ 2, 3 }; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == [2]u32); comptime assert(@TypeOf(b, a) == [2]u32); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1671,10 +1706,12 @@ test "peer type resolution: array and vector with same child type" { var arr: [2]u32 = .{ 0, 1 }; var vec: @Vector(2, u32) = .{ 2, 3 }; + _ = .{ &arr, &vec }; comptime assert(@TypeOf(arr, vec) == @Vector(2, u32)); comptime assert(@TypeOf(vec, arr) == @Vector(2, u32)); var t = true; + _ = &t; const r1 = if (t) arr else vec; const r2 = if (t) vec else arr; @@ -1694,10 +1731,12 @@ test "peer type resolution: array with smaller child type and vector with larger var arr: [2]u8 = .{ 0, 1 }; var vec: @Vector(2, u64) = .{ 2, 3 }; + _ = .{ &arr, &vec }; comptime assert(@TypeOf(arr, vec) == @Vector(2, u64)); comptime assert(@TypeOf(vec, arr) == @Vector(2, u64)); var t = true; + _ = &t; const r1 = if (t) arr else vec; const r2 = if (t) vec else arr; @@ -1715,10 +1754,12 @@ test "peer type resolution: error union and optional of same type" { const E = error{Foo}; var a: E!*u8 = error.Foo; var b: ?*u8 = null; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == E!?*u8); comptime assert(@TypeOf(b, a) == E!?*u8); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1734,11 +1775,13 @@ test "peer type resolution: C pointer and @TypeOf(null)" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: [*c]c_int = 0x1000; + _ = &a; const b = null; comptime assert(@TypeOf(a, b) == [*c]c_int); comptime assert(@TypeOf(b, a) == [*c]c_int); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1755,8 +1798,9 @@ test "peer type resolution: three-way resolution combines error set and optional const E = error{Foo}; var a: E = error.Foo; - var b: *const [5:0]u8 = @as(*const [5:0]u8, @ptrFromInt(0x1000)); + var b: *const [5:0]u8 = @ptrFromInt(0x1000); var c: ?[*:0]u8 = null; + _ = .{ &a, &b, &c }; comptime assert(@TypeOf(a, b, c) == E!?[*:0]const u8); comptime assert(@TypeOf(a, c, b) == E!?[*:0]const u8); comptime assert(@TypeOf(b, a, c) == E!?[*:0]const u8); @@ -1765,6 +1809,7 @@ test "peer type resolution: three-way resolution combines error set and optional comptime assert(@TypeOf(c, b, a) == E!?[*:0]const u8); var x: u8 = 0; + _ = &x; const r1 = switch (x) { 0 => a, 1 => b, @@ -1797,10 +1842,12 @@ test "peer type resolution: vector and optional vector" { var a: ?@Vector(3, u32) = .{ 0, 1, 2 }; var b: @Vector(3, u32) = .{ 3, 4, 5 }; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == ?@Vector(3, u32)); comptime assert(@TypeOf(b, a) == ?@Vector(3, u32)); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1816,11 +1863,13 @@ test "peer type resolution: optional fixed-width int and comptime_int" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: ?i32 = 42; + _ = &a; const b: comptime_int = 50; comptime assert(@TypeOf(a, b) == ?i32); comptime assert(@TypeOf(b, a) == ?i32); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1836,12 +1885,14 @@ test "peer type resolution: array and tuple" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var arr: [3]i32 = .{ 1, 2, 3 }; + _ = &arr; const tup = .{ 4, 5, 6 }; comptime assert(@TypeOf(arr, tup) == [3]i32); comptime assert(@TypeOf(tup, arr) == [3]i32); var t = true; + _ = &t; const r1 = if (t) arr else tup; const r2 = if (t) tup else arr; @@ -1858,12 +1909,14 @@ test "peer type resolution: vector and tuple" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var vec: @Vector(3, i32) = .{ 1, 2, 3 }; + _ = &vec; const tup = .{ 4, 5, 6 }; comptime assert(@TypeOf(vec, tup) == @Vector(3, i32)); comptime assert(@TypeOf(tup, vec) == @Vector(3, i32)); var t = true; + _ = &t; const r1 = if (t) vec else tup; const r2 = if (t) tup else vec; @@ -1881,6 +1934,7 @@ test "peer type resolution: vector and array and tuple" { var vec: @Vector(2, i8) = .{ 10, 20 }; var arr: [2]i8 = .{ 30, 40 }; + _ = .{ &vec, &arr }; const tup = .{ 50, 60 }; comptime assert(@TypeOf(vec, arr, tup) == @Vector(2, i8)); @@ -1891,6 +1945,7 @@ test "peer type resolution: vector and array and tuple" { comptime assert(@TypeOf(tup, arr, vec) == @Vector(2, i8)); var x: u8 = 0; + _ = &x; const r1 = switch (x) { 0 => vec, 1 => arr, @@ -1921,11 +1976,13 @@ test "peer type resolution: empty tuple pointer and slice" { var a: [:0]const u8 = "Hello"; var b = &.{}; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == []const u8); comptime assert(@TypeOf(b, a) == []const u8); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1940,11 +1997,13 @@ test "peer type resolution: tuple pointer and slice" { var a: [:0]const u8 = "Hello"; var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') }; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == []const u8); comptime assert(@TypeOf(b, a) == []const u8); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1959,11 +2018,13 @@ test "peer type resolution: tuple pointer and optional slice" { var a: ?[:0]const u8 = null; var b = &.{ @as(u8, 'x'), @as(u8, 'y'), @as(u8, 'z') }; + _ = .{ &a, &b }; comptime assert(@TypeOf(a, b) == ?[]const u8); comptime assert(@TypeOf(b, a) == ?[]const u8); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -1986,6 +2047,7 @@ test "peer type resolution: many compatible pointers" { @as([*]u8, &buf), @as(*const [5]u8, "foo-4"), }; + _ = &vals; // Check every possible permutation of types in @TypeOf @setEvalBranchQuota(5000); @@ -2015,6 +2077,7 @@ test "peer type resolution: many compatible pointers" { comptime assert(perms == 5 * 4 * 3 * 2 * 1); var x: u8 = 0; + _ = &x; inline for (0..5) |i| { const r = switch (x) { 0 => vals[i], @@ -2057,6 +2120,7 @@ test "peer type resolution: tuples with comptime fields" { } var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -2074,13 +2138,15 @@ test "peer type resolution: C pointer and many pointer" { var buf = "hello".*; - var a: [*c]u8 = &buf; + const a: [*c]u8 = &buf; var b: [*:0]const u8 = "world"; + _ = &b; comptime assert(@TypeOf(a, b) == [*c]const u8); comptime assert(@TypeOf(b, a) == [*c]const u8); var t = true; + _ = &t; const r1 = if (t) a else b; const r2 = if (t) b else a; @@ -2097,9 +2163,9 @@ test "peer type resolution: pointer attributes are combined correctly" { var buf_b align(4) = "bar".*; var buf_c align(4) = "baz".*; - var a: [*:0]align(4) const u8 = &buf_a; - var b: *align(2) volatile [3:0]u8 = &buf_b; - var c: [*:0]align(4) u8 = &buf_c; + const a: [*:0]align(4) const u8 = &buf_a; + const b: *align(2) volatile [3:0]u8 = &buf_b; + const c: [*:0]align(4) u8 = &buf_c; comptime assert(@TypeOf(a, b, c) == [*:0]align(2) const volatile u8); comptime assert(@TypeOf(a, c, b) == [*:0]align(2) const volatile u8); @@ -2109,6 +2175,7 @@ test "peer type resolution: pointer attributes are combined correctly" { comptime assert(@TypeOf(c, b, a) == [*:0]align(2) const volatile u8); var x: u8 = 0; + _ = &x; const r1 = switch (x) { 0 => a, 1 => b, @@ -2254,6 +2321,7 @@ test "@floatCast on vector" { const S = struct { fn doTheTest() !void { var a: @Vector(3, f64) = .{ 1.5, 2.5, 3.5 }; + _ = &a; const b: @Vector(3, f32) = @floatCast(a); try expectEqual(@Vector(3, f32){ 1.5, 2.5, 3.5 }, b); } @@ -2274,6 +2342,7 @@ test "@ptrFromInt on vector" { const S = struct { fn doTheTest() !void { var a: @Vector(3, usize) = .{ 0x1000, 0x2000, 0x3000 }; + _ = &a; const b: @Vector(3, *anyopaque) = @ptrFromInt(a); try expectEqual(@Vector(3, *anyopaque){ @ptrFromInt(0x1000), @@ -2302,6 +2371,7 @@ test "@intFromPtr on vector" { @ptrFromInt(0x2000), @ptrFromInt(0x3000), }; + _ = &a; const b: @Vector(3, usize) = @intFromPtr(a); try expectEqual(@Vector(3, usize){ 0x1000, 0x2000, 0x3000 }, b); } @@ -2322,6 +2392,7 @@ test "@floatFromInt on vector" { const S = struct { fn doTheTest() !void { var a: @Vector(3, u32) = .{ 10, 20, 30 }; + _ = &a; const b: @Vector(3, f32) = @floatFromInt(a); try expectEqual(@Vector(3, f32){ 10.0, 20.0, 30.0 }, b); } @@ -2342,6 +2413,7 @@ test "@intFromFloat on vector" { const S = struct { fn doTheTest() !void { var a: @Vector(3, f32) = .{ 10.3, 20.5, 30.7 }; + _ = &a; const b: @Vector(3, u32) = @intFromFloat(a); try expectEqual(@Vector(3, u32){ 10, 20, 30 }, b); } @@ -2362,6 +2434,7 @@ test "@intFromBool on vector" { const S = struct { fn doTheTest() !void { var a: @Vector(3, bool) = .{ false, true, false }; + _ = &a; const b: @Vector(3, u1) = @intFromBool(a); try expectEqual(@Vector(3, u1){ 0, 1, 0 }, b); } @@ -2385,7 +2458,8 @@ test "15-bit int to float" { if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; var a: u15 = 42; - var b: f32 = @floatFromInt(a); + _ = &a; + const b: f32 = @floatFromInt(a); try expect(b == 42.0); } @@ -2417,6 +2491,7 @@ test "result information is preserved through many nested structures" { const T = *const ?E!struct { x: ?*const E!?u8 }; var val: T = &.{ .x = &@truncate(0x1234) }; + _ = &val; const struct_val = val.*.? catch unreachable; const int_val = (struct_val.x.?.* catch unreachable).?; @@ -2439,6 +2514,7 @@ test "@intCast vector of signed integer" { if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO var x: @Vector(4, i32) = .{ 1, 2, 3, 4 }; + _ = &x; const y: @Vector(4, i8) = @intCast(x); try expect(y[0] == 1); diff --git a/test/behavior/cast_int.zig b/test/behavior/cast_int.zig index 23e5a614f8957fcc6354ab26557669c320fc96f3..8a832f7820616b99876719359c63fd988c0c200d 100644 --- a/test/behavior/cast_int.zig +++ b/test/behavior/cast_int.zig @@ -12,7 +12,8 @@ test "@intCast i32 to u7" { var x: u128 = maxInt(u128); var y: i32 = 120; - var z = x >> @as(u7, @intCast(y)); + _ = .{ &x, &y }; + const z = x >> @as(u7, @intCast(y)); try expect(z == 0xff); } @@ -23,20 +24,24 @@ test "coerce i8 to i32 and @intCast back" { var x: i8 = -5; var y: i32 = -5; + _ = .{ &x, &y }; try expect(y == x); var x2: i32 = -5; var y2: i8 = -5; + _ = .{ &x2, &y2 }; try expect(y2 == @as(i8, @intCast(x2))); } test "coerce non byte-sized integers accross 32bits boundary" { { var v: u21 = 6417; + _ = &v; const a: u32 = v; const b: u64 = v; const c: u64 = a; var w: u64 = 0x1234567812345678; + _ = &w; const d: u21 = @truncate(w); const e: u60 = d; try expectEqual(@as(u32, 6417), a); @@ -48,10 +53,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { { var v: u10 = 234; + _ = &v; const a: u32 = v; const b: u64 = v; const c: u64 = a; var w: u64 = 0x1234567812345678; + _ = &w; const d: u10 = @truncate(w); const e: u60 = d; try expectEqual(@as(u32, 234), a); @@ -62,10 +69,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { } { var v: u7 = 11; + _ = &v; const a: u32 = v; const b: u64 = v; const c: u64 = a; var w: u64 = 0x1234567812345678; + _ = &w; const d: u7 = @truncate(w); const e: u60 = d; try expectEqual(@as(u32, 11), a); @@ -77,10 +86,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { { var v: i21 = -6417; + _ = &v; const a: i32 = v; const b: i64 = v; const c: i64 = a; var w: i64 = -12345; + _ = &w; const d: i21 = @intCast(w); const e: i60 = d; try expectEqual(@as(i32, -6417), a); @@ -92,10 +103,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { { var v: i10 = -234; + _ = &v; const a: i32 = v; const b: i64 = v; const c: i64 = a; var w: i64 = -456; + _ = &w; const d: i10 = @intCast(w); const e: i60 = d; try expectEqual(@as(i32, -234), a); @@ -106,10 +119,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { } { var v: i7 = -11; + _ = &v; const a: i32 = v; const b: i64 = v; const c: i64 = a; var w: i64 = -42; + _ = &w; const d: i7 = @intCast(w); const e: i60 = d; try expectEqual(@as(i32, -11), a); @@ -152,7 +167,7 @@ test "load non byte-sized optional value" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // note: this bug is triggered by the == operator, expectEqual will hide it - var opt: ?Piece = try Piece.charToPiece('p'); + const opt: ?Piece = try Piece.charToPiece('p'); try expect(opt.?.type == .PAWN); try expect(opt.?.color == .BLACK); diff --git a/test/behavior/comptime_memory.zig b/test/behavior/comptime_memory.zig index 4245f332d6d5901bec5242a77024fca131937465..bfeaa339b246d203026f4886aace87ee3cc9b183 100644 --- a/test/behavior/comptime_memory.zig +++ b/test/behavior/comptime_memory.zig @@ -280,7 +280,7 @@ test "dance on linker values" { if (ptr_size > @sizeOf(Bits)) try doTypePunBitsTest(&weird_ptr[1]); - var arr_bytes = @as(*[2][ptr_size]u8, @ptrCast(&arr)); + const arr_bytes: *[2][ptr_size]u8 = @ptrCast(&arr); var rebuilt_bytes: [ptr_size]u8 = undefined; var i: usize = 0; diff --git a/test/behavior/destructure.zig b/test/behavior/destructure.zig index 4d7c336daa512d9318220604b4185d34179d0737..c2a5ca329a5513145e294ad5194a4fedded39524 100644 --- a/test/behavior/destructure.zig +++ b/test/behavior/destructure.zig @@ -7,6 +7,7 @@ test "simple destructure" { fn doTheTest() !void { var x: u32 = undefined; x, const y, var z: u64 = .{ 1, @as(u16, 2), 3 }; + _ = &z; comptime assert(@TypeOf(y) == u16); @@ -25,6 +26,7 @@ test "destructure with comptime syntax" { fn doTheTest() void { comptime var x: f32 = undefined; comptime x, const y, var z = .{ 0.5, 123, 456 }; // z is a comptime var + _ = &z; comptime assert(@TypeOf(y) == comptime_int); comptime assert(@TypeOf(z) == comptime_int); @@ -112,6 +114,7 @@ test "destructure of comptime-known tuple is comptime-known" { test "destructure of comptime-known tuple where some destinations are runtime-known is comptime-known" { var z: u32 = undefined; var x: u8, const y, z = .{ 1, 2, 3 }; + _ = &x; comptime assert(@TypeOf(y) == comptime_int); comptime assert(y == 2); @@ -122,6 +125,7 @@ test "destructure of comptime-known tuple where some destinations are runtime-kn test "destructure of tuple with comptime fields results in some comptime-known values" { var runtime: u32 = 42; + _ = &runtime; const a, const b, const c, const d = .{ 123, runtime, 456, runtime }; // a, c are comptime-known diff --git a/test/behavior/empty_union.zig b/test/behavior/empty_union.zig index 40bdd627f34e6c85c51a6adc1600cb571f7cd458..f05feacfafd7e429ff01aa3c65e376acaba63441 100644 --- a/test/behavior/empty_union.zig +++ b/test/behavior/empty_union.zig @@ -5,12 +5,14 @@ const expect = std.testing.expect; test "switch on empty enum" { const E = enum {}; var e: E = undefined; + _ = &e; switch (e) {} } test "switch on empty enum with a specified tag type" { const E = enum(u8) {}; var e: E = undefined; + _ = &e; switch (e) {} } @@ -19,6 +21,7 @@ test "switch on empty auto numbered tagged union" { const U = union(enum(u8)) {}; var u: U = undefined; + _ = &u; switch (u) {} } @@ -28,6 +31,7 @@ test "switch on empty tagged union" { const E = enum {}; const U = union(E) {}; var u: U = undefined; + _ = &u; switch (u) {} } diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig index efd0295a9797856eedb66b90e06fdb84aad7095b..d203476afcc4fb9137cd1fd67e1fb94d4f7508af 100644 --- a/test/behavior/enum.zig +++ b/test/behavior/enum.zig @@ -579,6 +579,7 @@ test "enum literal cast to enum" { var color1: Color = .Auto; var color2 = Color.Auto; + _ = .{ &color1, &color2 }; try expect(color1 == color2); } @@ -663,7 +664,8 @@ test "empty non-exhaustive enum" { const E = enum(u8) { _ }; fn doTheTest(y: u8) !void { - var e = @as(E, @enumFromInt(y)); + var e: E = @enumFromInt(y); + _ = &e; try expect(switch (e) { _ => true, }); @@ -858,6 +860,7 @@ test "comparison operator on enum with one member is comptime-known" { const State = enum { Start }; test "switch on enum with one member is comptime-known" { var state = State.Start; + _ = &state; switch (state) { State.Start => return, } @@ -917,7 +920,8 @@ test "enum literal casting to tagged union" { var t = true; var x: Arch = .x86_64; - var y = if (t) x else .x86_64; + _ = .{ &t, &x }; + const y = if (t) x else .x86_64; switch (y) { .x86_64 => {}, else => @panic("fail"), @@ -1031,6 +1035,7 @@ test "tag name with assigned enum values" { B = 0, }; var b = LocalFoo.B; + _ = &b; try expect(mem.eql(u8, @tagName(b), "B")); } @@ -1055,6 +1060,7 @@ test "tag name with signed enum values" { delta = 65, }; var b = LocalFoo.bravo; + _ = &b; try expect(mem.eql(u8, @tagName(b), "bravo")); } @@ -1135,13 +1141,13 @@ test "tag name functions are unique" { const E = enum { a, b }; var b = E.a; var a = @tagName(b); - _ = a; + _ = .{ &a, &b }; } { const E = enum { a, b, c, d, e, f }; var b = E.a; var a = @tagName(b); - _ = a; + _ = .{ &a, &b }; } } @@ -1189,6 +1195,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" { test "runtime int to enum with one possible value" { const E = enum { one }; var runtime: usize = 0; + _ = &runtime; if (@as(E, @enumFromInt(runtime)) != .one) { @compileError("test failed"); } diff --git a/test/behavior/error.zig b/test/behavior/error.zig index dfd511af2e7d936ae1ec9ac3a5c29fe5263eef5d..715cd6e4458837e129785a77b6c254548ce84dae 100644 --- a/test/behavior/error.zig +++ b/test/behavior/error.zig @@ -102,8 +102,7 @@ test "widen cast integer payload of error union function call" { const S = struct { fn errorable() !u64 { - var x = @as(u64, try number()); - return x; + return @as(u64, try number()); } fn number() anyerror!u32 { @@ -119,7 +118,7 @@ test "debug info for optional error set" { const SomeError = error{ Hello, Hello2 }; var a_local_variable: ?SomeError = null; - _ = a_local_variable; + _ = &a_local_variable; } test "implicit cast to optional to error union to return result loc" { @@ -160,6 +159,7 @@ fn entry() void { fn entryPtr() void { var ptr = &bar2; + _ = &ptr; fooPtr(ptr); } @@ -226,9 +226,9 @@ const Set1 = error{ A, B }; const Set2 = error{ A, C }; fn testExplicitErrorSetCast(set1: Set1) !void { - var x = @as(Set2, @errorCast(set1)); + const x: Set2 = @errorCast(set1); try expect(@TypeOf(x) == Set2); - var y = @as(Set1, @errorCast(x)); + const y: Set1 = @errorCast(x); try expect(@TypeOf(y) == Set1); try expect(y == error.A); } @@ -408,17 +408,17 @@ test "nested error union function call in optional unwrap" { }; fn errorable() !i32 { - var x: Foo = (try getFoo()) orelse return error.Other; + const x: Foo = (try getFoo()) orelse return error.Other; return x.a; } fn errorable2() !i32 { - var x: Foo = (try getFoo2()) orelse return error.Other; + const x: Foo = (try getFoo2()) orelse return error.Other; return x.a; } fn errorable3() !i32 { - var x: Foo = (try getFoo3()) orelse return error.Other; + const x: Foo = (try getFoo3()) orelse return error.Other; return x.a; } @@ -673,6 +673,7 @@ test "peer type resolution of two different error unions" { const a: error{B}!void = {}; const b: error{A}!void = {}; var cond = true; + _ = &cond; const err = if (cond) a else b; try err; } @@ -681,6 +682,7 @@ test "coerce error set to the current inferred error set" { const S = struct { fn foo() !void { var a = false; + _ = &a; if (a) { const b: error{A}!void = error.A; return b; @@ -831,6 +833,7 @@ test "alignment of wrapping an error union payload" { fn foo() anyerror!I { var i: I = .{ .x = 1234 }; + _ = &i; return i; } }; @@ -842,6 +845,7 @@ test "compare error union and error set" { var a: anyerror = error.Foo; var b: anyerror!u32 = error.Bar; + _ = &a; try expect(a != b); try expect(b != a); @@ -863,6 +867,7 @@ fn non_errorable() void { // This test is needed because stage 2's fix for #1923 means that catch blocks interact // with the error return trace index. var x: error{Foo}!void = {}; + _ = &x; return x catch {}; } @@ -902,6 +907,7 @@ test "optional error union return type" { const S = struct { fn foo() ?anyerror!u32 { var x: u32 = 1234; + _ = &x; return @as(anyerror!u32, x); } }; diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig index 39e9e32484516fb3f628fc9d3a26b70f61f5ffc0..ac09066552f5514ca5b41bd85bac9e7b4703d187 100644 --- a/test/behavior/eval.zig +++ b/test/behavior/eval.zig @@ -37,6 +37,7 @@ fn gimme1or2(comptime a: bool) i32 { const x: i32 = 1; const y: i32 = 2; comptime var z: i32 = if (a) x else y; + _ = &z; return z; } test "inline variable gets result of const if" { @@ -74,6 +75,7 @@ test "constant expressions" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var array: [array_size]u8 = undefined; + _ = &array; try expect(@sizeOf(@TypeOf(array)) == 20); } const array_size: u8 = 20; @@ -129,7 +131,7 @@ test "pointer to type" { comptime { var T: type = i32; try expect(T == i32); - var ptr = &T; + const ptr = &T; try expect(@TypeOf(ptr) == *type); ptr.* = f32; try expect(T == f32); @@ -372,6 +374,7 @@ fn doNothingWithType(comptime T: type) void { test "zero extend from u0 to u1" { var zero_u0: u0 = 0; var zero_u1: u1 = zero_u0; + _ = .{ &zero_u0, &zero_u1 }; try expect(zero_u1 == 0); } @@ -408,6 +411,7 @@ test "inline for with same type but different values" { var res: usize = 0; inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| { var a: T = undefined; + _ = &a; res += a.len; } try expect(res == 5); @@ -460,9 +464,9 @@ test "comptime shl" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - var a: u128 = 3; - var b: u7 = 63; - var c: u128 = 3 << 63; + const a: u128 = 3; + const b: u7 = 63; + const c: u128 = 3 << 63; try expect((a << b) == c); } @@ -489,6 +493,7 @@ test "comptime shlWithOverflow" { const ct_shifted = @shlWithOverflow(~@as(u64, 0), 16)[0]; var a = ~@as(u64, 0); + _ = &a; const rt_shifted = @shlWithOverflow(a, 16)[0]; try expect(ct_shifted == rt_shifted); @@ -521,7 +526,8 @@ test "runtime 128 bit integer division" { var a: u128 = 152313999999999991610955792383; var b: u128 = 10000000000000000000; - var c = a / b; + _ = .{ &a, &b }; + const c = a / b; try expect(c == 15231399999); } @@ -555,6 +561,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var runtime = [1]i32{3}; + _ = &runtime; comptime var i: usize = 0; inline while (i < 2) : (i += 1) { const result = if (i == 0) [1]i32{2} else runtime; @@ -692,7 +699,7 @@ test "call method with comptime pass-by-non-copying-value self parameter" { }; const s = S{ .a = 2 }; - var b = s.b(); + const b = s.b(); try expect(b == 2); } @@ -759,7 +766,8 @@ test "array concatenation peer resolves element types - value" { var a = [2]u3{ 1, 7 }; var b = [3]u8{ 200, 225, 255 }; - var c = a ++ b; + _ = .{ &a, &b }; + const c = a ++ b; comptime assert(@TypeOf(c) == [5]u8); try expect(c[0] == 1); try expect(c[1] == 7); @@ -775,7 +783,7 @@ test "array concatenation peer resolves element types - pointer" { var a = [2]u3{ 1, 7 }; var b = [3]u8{ 200, 225, 255 }; - var c = &a ++ &b; + const c = &a ++ &b; comptime assert(@TypeOf(c) == *[5]u8); try expect(c[0] == 1); try expect(c[1] == 7); @@ -791,14 +799,15 @@ test "array concatenation sets the sentinel - value" { var a = [2]u3{ 1, 7 }; var b = [3:69]u8{ 200, 225, 255 }; - var c = a ++ b; + _ = .{ &a, &b }; + const c = a ++ b; comptime assert(@TypeOf(c) == [5:69]u8); try expect(c[0] == 1); try expect(c[1] == 7); try expect(c[2] == 200); try expect(c[3] == 225); try expect(c[4] == 255); - var ptr: [*]const u8 = &c; + const ptr: [*]const u8 = &c; try expect(ptr[5] == 69); } @@ -808,14 +817,14 @@ test "array concatenation sets the sentinel - pointer" { var a = [2]u3{ 1, 7 }; var b = [3:69]u8{ 200, 225, 255 }; - var c = &a ++ &b; + const c = &a ++ &b; comptime assert(@TypeOf(c) == *[5:69]u8); try expect(c[0] == 1); try expect(c[1] == 7); try expect(c[2] == 200); try expect(c[3] == 225); try expect(c[4] == 255); - var ptr: [*]const u8 = c; + const ptr: [*]const u8 = c; try expect(ptr[5] == 69); } @@ -825,13 +834,14 @@ test "array multiplication sets the sentinel - value" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a = [2:7]u3{ 1, 6 }; - var b = a ** 2; + _ = &a; + const b = a ** 2; comptime assert(@TypeOf(b) == [4:7]u3); try expect(b[0] == 1); try expect(b[1] == 6); try expect(b[2] == 1); try expect(b[3] == 6); - var ptr: [*]const u3 = &b; + const ptr: [*]const u3 = &b; try expect(ptr[4] == 7); } @@ -841,13 +851,13 @@ test "array multiplication sets the sentinel - pointer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a = [2:7]u3{ 1, 6 }; - var b = &a ** 2; + const b = &a ** 2; comptime assert(@TypeOf(b) == *[4:7]u3); try expect(b[0] == 1); try expect(b[1] == 6); try expect(b[2] == 1); try expect(b[3] == 6); - var ptr: [*]const u3 = b; + const ptr: [*]const u3 = b; try expect(ptr[4] == 7); } @@ -913,8 +923,8 @@ test "comptime pointer load through elem_ptr" { .x = i, }; } - var ptr = @as([*]S, @ptrCast(&array)); - var x = ptr[0].x; + var ptr: [*]S = @ptrCast(&array); + const x = ptr[0].x; assert(x == 0); ptr += 1; assert(ptr[1].x == 2); @@ -953,11 +963,12 @@ test "closure capture type of runtime-known parameter" { const S = struct { fn b(c: anytype) !void { const D = struct { c: @TypeOf(c) }; - var d = D{ .c = c }; + const d: D = .{ .c = c }; try expect(d.c == 1234); } }; var c: i32 = 1234; + _ = &c; try S.b(c); } @@ -966,6 +977,7 @@ test "closure capture type of runtime-known var" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 1234; + _ = &x; const S = struct { val: @TypeOf(x + 100) }; const s: S = .{ .val = x }; try expect(s.val == 1234); @@ -977,6 +989,7 @@ test "comptime break passing through runtime condition converted to runtime brea const S = struct { fn doTheTest() !void { var runtime: u8 = 'b'; + _ = &runtime; inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { bar(); if (byte == runtime) { @@ -1010,6 +1023,7 @@ test "comptime break to outer loop passing through runtime condition converted t const S = struct { fn doTheTest() !void { var runtime: u8 = 'b'; + _ = &runtime; outer: inline for ([3]u8{ 'A', 'B', 'C' }) |outer_byte| { inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { bar(outer_byte); @@ -1387,6 +1401,7 @@ test "break from inline loop depends on runtime condition" { test "inline for inside a runtime condition" { var a = false; + _ = &a; if (a) { const arr = .{ 1, 2, 3 }; inline for (arr) |val| { @@ -1522,6 +1537,7 @@ test "non-optional and optional array elements concatenated" { const array = [1]u8{'A'} ++ [1]?u8{null}; var index: usize = 0; + _ = &index; try expect(array[index].? == 'A'); } @@ -1556,6 +1572,7 @@ test "container level const and var have unique addresses" { var v: @This() = c; }; var p = &S.c; + _ = &p; try std.testing.expect(p.x == S.c.x); S.v.x = 2; try std.testing.expect(p.x == S.c.x); @@ -1625,7 +1642,8 @@ test "inline for loop of functions returning error unions" { test "if inside a switch" { var condition = true; var wave_type: u32 = 0; - var sample: i32 = switch (wave_type) { + _ = .{ &condition, &wave_type }; + const sample: i32 = switch (wave_type) { 0 => if (condition) 2 else 3, 1 => 100, 2 => 200, @@ -1673,6 +1691,7 @@ test "@inComptime" { comptime { var foo = [3]u8{ 0x55, 0x55, 0x55 }; var bar = [2]u8{ 1, 2 }; + _ = .{ &foo, &bar }; foo[0..2].* = bar; assert(foo[0] == 1); assert(foo[1] == 2); diff --git a/test/behavior/extern_struct_zero_size_fields.zig b/test/behavior/extern_struct_zero_size_fields.zig index 1b13532f11e72a6b847538338679a876e9cba4ab..592ec85f5011f4fca84506c864b7221f907637d9 100644 --- a/test/behavior/extern_struct_zero_size_fields.zig +++ b/test/behavior/extern_struct_zero_size_fields.zig @@ -17,5 +17,5 @@ const T = extern struct { test { var t: T = .{}; - _ = t; + _ = &t; } diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig index f114f30fa9b979dd2012663586be82e2dad6a976..e1c870bce65a971209b25d3327cf8c69648a9e77 100644 --- a/test/behavior/floatop.zig +++ b/test/behavior/floatop.zig @@ -42,6 +42,8 @@ test "add f80/f128/c_longdouble" { fn testAdd(comptime T: type) !void { var one_point_two_five: T = 1.25; var two_point_seven_five: T = 2.75; + _ = &one_point_two_five; + _ = &two_point_seven_five; try expect(one_point_two_five + two_point_seven_five == 4); } @@ -74,6 +76,8 @@ test "sub f80/f128/c_longdouble" { fn testSub(comptime T: type) !void { var one_point_two_five: T = 1.25; var two_point_seven_five: T = 2.75; + _ = &one_point_two_five; + _ = &two_point_seven_five; try expect(one_point_two_five - two_point_seven_five == -1.5); } @@ -106,6 +110,8 @@ test "mul f80/f128/c_longdouble" { fn testMul(comptime T: type) !void { var one_point_two_five: T = 1.25; var two_point_seven_five: T = 2.75; + _ = &one_point_two_five; + _ = &two_point_seven_five; try expect(one_point_two_five * two_point_seven_five == 3.4375); } @@ -152,6 +158,7 @@ fn testCmp(comptime T: type) !void { { // No decimal part var x: T = 1.0; + _ = &x; try expect(x == 1.0); try expect(x != 0.0); try expect(x > 0.0); @@ -162,6 +169,7 @@ fn testCmp(comptime T: type) !void { { // Non-zero decimal part var x: T = 1.5; + _ = &x; try expect(x != 1.0); try expect(x != 2.0); try expect(x > 1.0); @@ -184,6 +192,7 @@ fn testCmp(comptime T: type) !void { math.floatMax(T), math.inf(T), }; + _ = &edges; for (edges, 0..) |rhs, rhs_i| { for (edges, 0..) |lhs, lhs_i| { const no_nan = lhs_i != 5 and rhs_i != 5; @@ -212,6 +221,7 @@ test "different sized float comparisons" { fn testDifferentSizedFloatComparisons() !void { var a: f16 = 1; var b: f64 = 2; + _ = .{ &a, &b }; try expect(a < b); } @@ -240,7 +250,8 @@ test "negative f128 intFromFloat at compile-time" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; const a: f128 = -2; - var b = @as(i64, @intFromFloat(a)); + var b: i64 = @intFromFloat(a); + _ = &b; try expect(@as(i64, -2) == b); } @@ -331,6 +342,28 @@ fn testSqrt(comptime T: type) !void { try expect(math.isNan(@sqrt(neg_one))); var nan: T = math.nan(T); try expect(math.isNan(@sqrt(nan))); + + _ = .{ + &four, + &nine, + &twenty_five, + &sixty_four, + &one_point_one, + &two, + &three_point_six, + &sixty_four_point_one, + &twelve, + &thirteen, + &fourteen, + &a, + &b, + &c, + &inf, + &zero, + &neg_zero, + &neg_one, + &nan, + }; } test "@sqrt with vectors" { @@ -345,7 +378,8 @@ test "@sqrt with vectors" { fn testSqrtWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @sqrt(v); + _ = &v; + const result = @sqrt(v); try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon)); @@ -394,8 +428,10 @@ test "@sin f80/f128/c_longdouble" { fn testSin(comptime T: type) !void { const eps = epsForType(T); var zero: T = 0; + _ = &zero; try expect(@sin(zero) == 0); var pi: T = math.pi; + _ = π try expect(math.approxEqAbs(T, @sin(pi), 0, eps)); try expect(math.approxEqAbs(T, @sin(pi / 2.0), 1, eps)); try expect(math.approxEqAbs(T, @sin(pi / 4.0), 0.7071067811865475, eps)); @@ -414,7 +450,8 @@ test "@sin with vectors" { fn testSinWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @sin(v); + _ = &v; + const result = @sin(v); try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon)); @@ -463,8 +500,10 @@ test "@cos f80/f128/c_longdouble" { fn testCos(comptime T: type) !void { const eps = epsForType(T); var zero: T = 0; + _ = &zero; try expect(@cos(zero) == 1); var pi: T = math.pi; + _ = π try expect(math.approxEqAbs(T, @cos(pi), -1, eps)); try expect(math.approxEqAbs(T, @cos(pi / 2.0), 0, eps)); try expect(math.approxEqAbs(T, @cos(pi / 4.0), 0.7071067811865475, eps)); @@ -483,7 +522,8 @@ test "@cos with vectors" { fn testCosWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @cos(v); + _ = &v; + const result = @cos(v); try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon)); @@ -532,8 +572,10 @@ test "@tan f80/f128/c_longdouble" { fn testTan(comptime T: type) !void { const eps = epsForType(T); var zero: T = 0; + _ = &zero; try expect(@tan(zero) == 0); var pi: T = math.pi; + _ = π try expect(math.approxEqAbs(T, @tan(pi), 0, eps)); try expect(math.approxEqAbs(T, @tan(pi / 3.0), 1.732050807568878, eps)); try expect(math.approxEqAbs(T, @tan(pi / 4.0), 1, eps)); @@ -552,7 +594,8 @@ test "@tan with vectors" { fn testTanWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @tan(v); + _ = &v; + const result = @tan(v); try expect(math.approxEqAbs(f32, @tan(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @tan(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @tan(@as(f32, 3.3)), result[2], epsilon)); @@ -600,11 +643,17 @@ test "@exp f80/f128/c_longdouble" { fn testExp(comptime T: type) !void { const eps = epsForType(T); + var zero: T = 0; + _ = &zero; try expect(@exp(zero) == 1); + var two: T = 2; + _ = &two; try expect(math.approxEqAbs(T, @exp(two), 7.389056098930650, eps)); + var five: T = 5; + _ = &five; try expect(math.approxEqAbs(T, @exp(five), 148.4131591025766, eps)); } @@ -621,7 +670,8 @@ test "@exp with vectors" { fn testExpWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @exp(v); + _ = &v; + const result = @exp(v); try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon)); @@ -675,6 +725,7 @@ fn testExp2(comptime T: type) !void { try expect(math.approxEqAbs(T, @exp2(one_point_five), 2.8284271247462, eps)); var four_point_five: T = 4.5; try expect(math.approxEqAbs(T, @exp2(four_point_five), 22.627416997969, eps)); + _ = .{ &two, &one_point_five, &four_point_five }; } test "@exp2 with @vectors" { @@ -690,7 +741,8 @@ test "@exp2 with @vectors" { fn testExp2WithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @exp2(v); + _ = &v; + const result = @exp2(v); try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon)); @@ -744,6 +796,7 @@ fn testLog(comptime T: type) !void { try expect(math.approxEqAbs(T, @log(two), 0.6931471805599, eps)); var five: T = 5; try expect(math.approxEqAbs(T, @log(five), 1.6094379124341, eps)); + _ = .{ &e, &two, &five }; } test "@log with @vectors" { @@ -756,7 +809,8 @@ test "@log with @vectors" { { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @log(v); + _ = &v; + const result = @log(v); try expect(@log(@as(f32, 1.1)) == result[0]); try expect(@log(@as(f32, 2.2)) == result[1]); try expect(@log(@as(f32, 0.3)) == result[2]); @@ -811,6 +865,7 @@ fn testLog2(comptime T: type) !void { try expect(math.approxEqAbs(T, @log2(six), 2.5849625007212, eps)); var ten: T = 10; try expect(math.approxEqAbs(T, @log2(ten), 3.3219280948874, eps)); + _ = .{ &four, &six, &ten }; } test "@log2 with vectors" { @@ -830,7 +885,8 @@ test "@log2 with vectors" { fn testLog2WithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @log2(v); + _ = &v; + const result = @log2(v); try expect(@log2(@as(f32, 1.1)) == result[0]); try expect(@log2(@as(f32, 2.2)) == result[1]); try expect(@log2(@as(f32, 0.3)) == result[2]); @@ -884,6 +940,7 @@ fn testLog10(comptime T: type) !void { try expect(math.approxEqAbs(T, @log10(fifteen), 1.176091259056, eps)); var fifty: T = 50; try expect(math.approxEqAbs(T, @log10(fifty), 1.698970004336, eps)); + _ = .{ &hundred, &fifteen, &fifty }; } test "@log10 with vectors" { @@ -899,7 +956,8 @@ test "@log10 with vectors" { fn testLog10WithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @log10(v); + _ = &v; + const result = @log10(v); try expect(@log10(@as(f32, 1.1)) == result[0]); try expect(@log10(@as(f32, 2.2)) == result[1]); try expect(@log10(@as(f32, 0.3)) == result[2]); @@ -987,6 +1045,26 @@ fn testFabs(comptime T: type) !void { try expect(math.isPositiveInf(@abs(neg_inf))); var nan: T = math.nan(T); try expect(math.isNan(@abs(nan))); + + _ = .{ + &two_point_five, + &neg_two_point_five, + &twelve, + &neg_fourteen, + &one, + &neg_one, + &min, + &neg_min, + &max, + &neg_max, + &zero, + &neg_zero, + &true_min, + &neg_true_min, + &inf, + &neg_inf, + &nan, + }; } test "@abs with vectors" { @@ -1001,7 +1079,8 @@ test "@abs with vectors" { fn testFabsWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @abs(v); + _ = &v; + const result = @abs(v); try expect(math.approxEqAbs(f32, @abs(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @abs(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @abs(@as(f32, 0.3)), result[2], epsilon)); @@ -1070,6 +1149,17 @@ fn testFloor(comptime T: type) !void { try expect(@floor(fourteen_point_seven) == 14.0); var neg_fourteen_point_seven: T = -14.7; try expect(@floor(neg_fourteen_point_seven) == -15.0); + + _ = .{ + &two_point_one, + &neg_two_point_one, + &three_point_five, + &neg_three_point_five, + &twelve, + &neg_twelve, + &fourteen_point_seven, + &neg_fourteen_point_seven, + }; } test "@floor with vectors" { @@ -1086,7 +1176,8 @@ test "@floor with vectors" { fn testFloorWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @floor(v); + _ = &v; + const result = @floor(v); try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon)); @@ -1155,6 +1246,17 @@ fn testCeil(comptime T: type) !void { try expect(@ceil(fourteen_point_seven) == 15.0); var neg_fourteen_point_seven: T = -14.7; try expect(@ceil(neg_fourteen_point_seven) == -14.0); + + _ = .{ + &two_point_one, + &neg_two_point_one, + &three_point_five, + &neg_three_point_five, + &twelve, + &neg_twelve, + &fourteen_point_seven, + &neg_fourteen_point_seven, + }; } test "@ceil with vectors" { @@ -1171,7 +1273,8 @@ test "@ceil with vectors" { fn testCeilWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @ceil(v); + _ = &v; + const result = @ceil(v); try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon)); @@ -1250,6 +1353,17 @@ fn testTrunc(comptime T: type) !void { try expect(@trunc(fourteen_point_seven) == 14.0); var neg_fourteen_point_seven: T = -14.7; try expect(@trunc(neg_fourteen_point_seven) == -14.0); + + _ = .{ + &two_point_one, + &neg_two_point_one, + &three_point_five, + &neg_three_point_five, + &twelve, + &neg_twelve, + &fourteen_point_seven, + &neg_fourteen_point_seven, + }; } test "@trunc with vectors" { @@ -1266,7 +1380,8 @@ test "@trunc with vectors" { fn testTruncWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @trunc(v); + _ = &v; + const result = @trunc(v); try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon)); @@ -1365,6 +1480,27 @@ fn testNeg(comptime T: type) !void { var neg_nan: T = -math.nan(T); try expect(math.isNan(-neg_nan)); try expect(!math.signbit(-neg_nan)); + + _ = .{ + &two_point_five, + &neg_two_point_five, + &twelve, + &neg_fourteen, + &one, + &neg_one, + &min, + &neg_min, + &max, + &neg_max, + &zero, + &neg_zero, + &true_min, + &neg_true_min, + &inf, + &neg_inf, + &nan, + &neg_nan, + }; } test "eval @setFloatMode at compile-time" { diff --git a/test/behavior/fn.zig b/test/behavior/fn.zig index ddfc9648c2568f880c1e3a8823a7b15309158ad1..4f8dd35490590cab284389d76f89f24f6da70f97 100644 --- a/test/behavior/fn.zig +++ b/test/behavior/fn.zig @@ -21,6 +21,7 @@ fn testLocVars(b: i32) void { test "mutable local variables" { var zero: i32 = 0; + _ = &zero; try expect(zero == 0); var i = @as(i32, 0); @@ -70,7 +71,7 @@ fn outer(y: u32) *const fn (u32) u32 { test "return inner function which references comptime variable of outer function" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - var func = outer(10); + const func = outer(10); try expect(func(3) == 7); } @@ -259,7 +260,7 @@ test "implicit cast fn call result to optional in field result" { const S = struct { fn entry() !void { - var x = Foo{ + const x = Foo{ .field = optionalPtr(), }; try expect(x.field.?.* == 999); @@ -386,6 +387,7 @@ test "ability to give comptime types and non comptime types to same parameter" { const S = struct { fn doTheTest() !void { var x: i32 = 1; + _ = &x; try expect(foo(x) == 10); try expect(foo(i32) == 20); } @@ -413,11 +415,11 @@ test "import passed byref to function in return type" { const S = struct { fn get() @import("std").ArrayListUnmanaged(i32) { - var x: @import("std").ArrayListUnmanaged(i32) = .{}; + const x: @import("std").ArrayListUnmanaged(i32) = .{}; return x; } }; - var list = S.get(); + const list = S.get(); try expect(list.items.len == 0); } @@ -434,11 +436,13 @@ test "implicit cast function to function ptr" { } }; var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue; + _ = &fnPtr1; try expect(fnPtr1() == 123); const S2 = struct { extern fn someFunctionThatReturnsAValue() c_int; }; var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue; + _ = &fnPtr2; try expect(fnPtr2() == 123); } @@ -588,5 +592,6 @@ test "pointer to alias behaves same as pointer to function" { const bar = foo; }; var a = &S.bar; + _ = &a; try std.testing.expect(S.foo() == a()); } diff --git a/test/behavior/fn_in_struct_in_comptime.zig b/test/behavior/fn_in_struct_in_comptime.zig index 0acadbc5ea9c95d494f436b49634e00f43c80086..40410d4aea5c87ccecc1c097238d61e88d763480 100644 --- a/test/behavior/fn_in_struct_in_comptime.zig +++ b/test/behavior/fn_in_struct_in_comptime.zig @@ -5,8 +5,7 @@ fn get_foo() fn (*u8) usize { comptime { return struct { fn func(ptr: *u8) usize { - var u = @intFromPtr(ptr); - return u; + return @intFromPtr(ptr); } }.func; } diff --git a/test/behavior/for.zig b/test/behavior/for.zig index 5a41f75077e58bad06fc4291c51910815b357514..a43fc2305bf561038a3f5b0025b633f398272d54 100644 --- a/test/behavior/for.zig +++ b/test/behavior/for.zig @@ -26,7 +26,7 @@ test "break from outer for loop" { } fn testBreakOuter() !void { - var array = "aoeu"; + const array = "aoeu"; var count: usize = 0; outer: for (array) |_| { for (array) |_| { @@ -43,7 +43,7 @@ test "continue outer for loop" { } fn testContinueOuter() !void { - var array = "aoeu"; + const array = "aoeu"; var counter: usize = 0; outer: for (array) |_| { for (array) |_| { @@ -137,7 +137,7 @@ test "2 break statements and an else" { fn entry(t: bool, f: bool) !void { var buf: [10]u8 = undefined; var ok = false; - ok = for (buf) |item| { + ok = for (&buf) |*item| { _ = item; if (f) break false; if (t) break true; @@ -201,7 +201,7 @@ test "for on slice with allowzero ptr" { const S = struct { fn doTheTest(slice: []const u8) !void { - var ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len]; + const ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len]; for (ptr, 0..) |x, i| try expect(x == i + 1); for (ptr, 0..) |*x, i| try expect(x.* == i + 1); } @@ -230,6 +230,7 @@ test "for loop with else branch" { { var x = [_]u32{ 1, 2 }; + _ = &x; const q = for (x) |y| { if ((y & 1) != 0) continue; break y * 2; @@ -238,6 +239,7 @@ test "for loop with else branch" { } { var x = [_]u32{ 1, 2 }; + _ = &x; const q = for (x) |y| { if ((y & 1) != 0) continue; break y * 2; @@ -310,6 +312,7 @@ test "slice and two counters, one is offset and one is runtime" { const slice: []const u8 = "blah"; var start: usize = 0; + _ = &start; for (slice, start..4, 1..5) |a, b, c| { if (a == 'b') { @@ -394,6 +397,7 @@ test "inline for with slice as the comptime-known" { const comptime_slice = "hello"; var runtime_i: usize = 3; + _ = &runtime_i; const S = struct { var ok: usize = 0; @@ -424,6 +428,7 @@ test "inline for with counter as the comptime-known" { var runtime_slice = "hello"; var runtime_i: usize = 3; + _ = &runtime_i; const S = struct { var ok: usize = 0; @@ -484,14 +489,16 @@ test "inferred alloc ptr of for loop" { { var cond = false; - var opt = for (0..1) |_| { + _ = &cond; + const opt = for (0..1) |_| { if (cond) break cond; } else null; try expectEqual(@as(?bool, null), opt); } { var cond = true; - var opt = for (0..1) |_| { + _ = &cond; + const opt = for (0..1) |_| { if (cond) break cond; } else null; try expectEqual(@as(?bool, true), opt); diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index d52ad206778b6131955f0ea6c19cf80a0f333688..d0c97bdbf3ab2bcea6e8b714f0fdc9ddc589d673 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -102,6 +102,7 @@ test "type constructed by comptime function call" { fn SimpleList(comptime L: usize) type { var mutable_T = u8; + _ = &mutable_T; const T = mutable_T; return struct { array: [L]T, @@ -238,6 +239,7 @@ test "function parameter is generic" { } }; var rng: u32 = 2; + _ = &rng; S.init(rng, S.fill); } diff --git a/test/behavior/if.zig b/test/behavior/if.zig index 68ea986c05b8fda10e21f7f823ebb0ac28499da7..c4dfd04f71c3ce55ce709911d2d5c2412a012fe2 100644 --- a/test/behavior/if.zig +++ b/test/behavior/if.zig @@ -61,6 +61,7 @@ test "unwrap mutable global var" { test "labeled break inside comptime if inside runtime if" { var answer: i32 = 0; var c = true; + _ = &c; if (c) { answer = if (true) blk: { break :blk @as(i32, 42); @@ -73,6 +74,7 @@ test "const result loc, runtime if cond, else unreachable" { const Num = enum { One, Two }; var t = true; + _ = &t; const x = if (t) Num.Two else unreachable; try expect(x == .Two); } @@ -103,6 +105,7 @@ test "if prongs cast to expected type instead of peer type resolution" { try expect(x == 2); var b = true; + _ = &b; const y: i32 = if (b) 1 else 2; try expect(y == 1); } @@ -118,10 +121,11 @@ test "if peer expressions inferred optional type" { var self: []const u8 = "abcdef"; var index: usize = 0; - var left_index = (index << 1) + 1; - var right_index = left_index + 1; - var left = if (left_index < self.len) self[left_index] else null; - var right = if (right_index < self.len) self[right_index] else null; + _ = .{ &self, &index }; + const left_index = (index << 1) + 1; + const right_index = left_index + 1; + const left = if (left_index < self.len) self[left_index] else null; + const right = if (right_index < self.len) self[right_index] else null; try expect(left_index < self.len); try expect(right_index < self.len); try expect(left.? == 98); @@ -135,6 +139,7 @@ test "if-else expression with runtime condition result location is inferred opti const A = struct { b: u64, c: u64 }; var d: bool = true; + _ = &d; const e = if (d) A{ .b = 15, .c = 30 } else null; try expect(e != null); } @@ -142,7 +147,8 @@ test "if-else expression with runtime condition result location is inferred opti test "result location with inferred type ends up being pointer to comptime_int" { var a: ?u32 = 1234; var b: u32 = 2000; - var c = if (a) |d| blk: { + _ = .{ &a, &b }; + const c = if (a) |d| blk: { if (d < b) break :blk @as(u32, 1); break :blk 0; } else @as(u32, 0); @@ -152,6 +158,7 @@ test "result location with inferred type ends up being pointer to comptime_int" test "if-@as-if chain" { var fast = true; var very_fast = false; + _ = .{ &fast, &very_fast }; const num_frames = if (fast) @as(u32, if (very_fast) 16 else 4) diff --git a/test/behavior/inline_switch.zig b/test/behavior/inline_switch.zig index deb4518820cfca5ecc733f5d328e0d8f8bd0d405..59dc7096b9d5007670e8d9927fa401aa1eea63e1 100644 --- a/test/behavior/inline_switch.zig +++ b/test/behavior/inline_switch.zig @@ -22,6 +22,7 @@ test "inline prong ranges" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: usize = 0; + _ = &x; switch (x) { inline 0...20, 24 => |item| { if (item > 25) @compileError("bad"); @@ -36,6 +37,7 @@ test "inline switch enums" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: E = .a; + _ = &x; switch (x) { inline .a, .b => |aorb| if (aorb != .a and aorb != .b) @compileError("bad"), inline .c, .d => |cord| if (cord != .c and cord != .d) @compileError("bad"), @@ -49,6 +51,7 @@ test "inline switch unions" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: U = .a; + _ = &x; switch (x) { inline .a, .b => |aorb, tag| { if (tag == .a) { @@ -74,6 +77,7 @@ test "inline else bool" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a = true; + _ = &a; switch (a) { true => {}, inline else => |val| if (val != false) @compileError("bad"), @@ -86,6 +90,7 @@ test "inline else error" { const Err = error{ a, b, c }; var a = Err.a; + _ = &a; switch (a) { error.a => {}, inline else => |val| comptime if (val == error.a) @compileError("bad"), @@ -98,6 +103,7 @@ test "inline else enum" { const E2 = enum(u8) { a = 2, b = 3, c = 4, d = 5 }; var a: E2 = .a; + _ = &a; switch (a) { .a, .b => {}, inline else => |val| comptime if (@intFromEnum(val) < 4) @compileError("bad"), @@ -109,6 +115,7 @@ test "inline else int with gaps" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: u8 = 0; + _ = &a; switch (a) { 1...125, 128...254 => {}, inline else => |val| { @@ -126,6 +133,7 @@ test "inline else int all values" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: u2 = 0; + _ = &a; switch (a) { inline else => |val| { if (val != 0 and diff --git a/test/behavior/int128.zig b/test/behavior/int128.zig index 01e6bc42acb388dd2198aa16e6b3ee4b9339fe5a..7287cd1ab267ce82e0674de1ef0e775fe0ea5f89 100644 --- a/test/behavior/int128.zig +++ b/test/behavior/int128.zig @@ -39,6 +39,7 @@ test "undefined 128 bit int" { var undef: u128 = undefined; var undef_signed: i128 = undefined; + _ = .{ &undef, &undef_signed }; try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @as(u128, @bitCast(undef_signed)) == undef); } @@ -73,6 +74,7 @@ test "truncate int128" { { var buff: u128 = maxInt(u128); + _ = &buff; try expect(@as(u64, @truncate(buff)) == maxInt(u64)); try expect(@as(u90, @truncate(buff)) == maxInt(u90)); try expect(@as(u128, @truncate(buff)) == maxInt(u128)); @@ -80,6 +82,7 @@ test "truncate int128" { { var buff: i128 = maxInt(i128); + _ = &buff; try expect(@as(i64, @truncate(buff)) == -1); try expect(@as(i90, @truncate(buff)) == -1); try expect(@as(i128, @truncate(buff)) == maxInt(i128)); diff --git a/test/behavior/int_comparison_elision.zig b/test/behavior/int_comparison_elision.zig index c384f6208677a167821f4aced86e2abd6df32982..9ac9e1fca1561d6155e297a2a9b8c7dbee269806 100644 --- a/test/behavior/int_comparison_elision.zig +++ b/test/behavior/int_comparison_elision.zig @@ -30,6 +30,7 @@ fn testIntEdges(comptime T: type) void { const max = maxInt(T); var runtime_val: T = undefined; + _ = &runtime_val; if (min > runtime_val) @compileError("analyzed impossible branch"); if (min <= runtime_val) {} else @compileError("analyzed impossible branch"); diff --git a/test/behavior/int_div.zig b/test/behavior/int_div.zig index 12368f0fba9bce12e40c8774400c9d3e80684ab7..bc570434cec90a9488359aa8231cb4472d3dc505 100644 --- a/test/behavior/int_div.zig +++ b/test/behavior/int_div.zig @@ -100,11 +100,13 @@ test "large integer division" { { var numerator: u256 = 99999999999999999997315645440; var divisor: u256 = 10000000000000000000000000000; + _ = .{ &numerator, &divisor }; try expect(numerator / divisor == 9); } { var numerator: u256 = 99999999999999999999000000000000000000000; var divisor: u256 = 10000000000000000000000000000000000000000; + _ = .{ &numerator, &divisor }; try expect(numerator / divisor == 9); } } diff --git a/test/behavior/math.zig b/test/behavior/math.zig index 3a5f753dd8ecef083db586b6458e1f31d6ff307f..ab54c9e4a9f0c2dadc800b88fbef7e18ed8f74b1 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -624,7 +624,8 @@ const DivResult = struct { test "bit shift a u1" { var x: u1 = 1; - var y = x << 0; + _ = &x; + const y = x << 0; try expect(y == 1); } @@ -692,7 +693,8 @@ test "128-bit multiplication" { { var a: u128 = 0xffffffffffffffff; var b: u128 = 100; - var c = a * b; + _ = .{ &a, &b }; + const c = a * b; try expect(c == 0x63ffffffffffffff9c); } } @@ -704,18 +706,21 @@ test "@addWithOverflow" { { var a: u8 = 250; + _ = &a; const ov = @addWithOverflow(a, 100); try expect(ov[0] == 94); try expect(ov[1] == 1); } { var a: u8 = 100; + _ = &a; const ov = @addWithOverflow(a, 150); try expect(ov[0] == 250); try expect(ov[1] == 0); } { var a: u8 = 200; + _ = &a; var b: u8 = 99; var ov = @addWithOverflow(a, b); try expect(ov[0] == 43); @@ -729,6 +734,7 @@ test "@addWithOverflow" { { var a: usize = 6; var b: usize = 6; + _ = .{ &a, &b }; const ov = @addWithOverflow(a, b); try expect(ov[0] == 12); try expect(ov[1] == 0); @@ -737,6 +743,7 @@ test "@addWithOverflow" { { var a: isize = -6; var b: isize = -6; + _ = .{ &a, &b }; const ov = @addWithOverflow(a, b); try expect(ov[0] == -12); try expect(ov[1] == 0); @@ -772,18 +779,21 @@ test "basic @mulWithOverflow" { { var a: u8 = 86; + _ = &a; const ov = @mulWithOverflow(a, 3); try expect(ov[0] == 2); try expect(ov[1] == 1); } { var a: u8 = 85; + _ = &a; const ov = @mulWithOverflow(a, 3); try expect(ov[0] == 255); try expect(ov[1] == 0); } var a: u8 = 123; + _ = &a; var b: u8 = 2; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 246); @@ -802,6 +812,7 @@ test "extensive @mulWithOverflow" { { var a: u5 = 3; + _ = &a; var b: u5 = 10; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 30); @@ -815,6 +826,7 @@ test "extensive @mulWithOverflow" { { var a: i5 = 3; + _ = &a; var b: i5 = -5; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -15); @@ -828,6 +840,7 @@ test "extensive @mulWithOverflow" { { var a: u8 = 3; + _ = &a; var b: u8 = 85; var ov = @mulWithOverflow(a, b); @@ -842,6 +855,7 @@ test "extensive @mulWithOverflow" { { var a: i8 = 3; + _ = &a; var b: i8 = -42; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -126); @@ -855,6 +869,7 @@ test "extensive @mulWithOverflow" { { var a: u14 = 3; + _ = &a; var b: u14 = 0x1555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0x3fff); @@ -868,6 +883,7 @@ test "extensive @mulWithOverflow" { { var a: i14 = 3; + _ = &a; var b: i14 = -0xaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x1ffe); @@ -880,6 +896,7 @@ test "extensive @mulWithOverflow" { { var a: u16 = 3; + _ = &a; var b: u16 = 0x5555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0xffff); @@ -893,6 +910,7 @@ test "extensive @mulWithOverflow" { { var a: i16 = 3; + _ = &a; var b: i16 = -0x2aaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x7ffe); @@ -906,6 +924,7 @@ test "extensive @mulWithOverflow" { { var a: u30 = 3; + _ = &a; var b: u30 = 0x15555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0x3fffffff); @@ -919,6 +938,7 @@ test "extensive @mulWithOverflow" { { var a: i30 = 3; + _ = &a; var b: i30 = -0xaaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x1ffffffe); @@ -932,6 +952,7 @@ test "extensive @mulWithOverflow" { { var a: u32 = 3; + _ = &a; var b: u32 = 0x55555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0xffffffff); @@ -945,6 +966,7 @@ test "extensive @mulWithOverflow" { { var a: i32 = 3; + _ = &a; var b: i32 = -0x2aaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x7ffffffe); @@ -967,6 +989,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: u62 = 3; + _ = &a; var b: u62 = 0x1555555555555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0x3fffffffffffffff); @@ -980,6 +1003,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: i62 = 3; + _ = &a; var b: i62 = -0xaaaaaaaaaaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x1ffffffffffffffe); @@ -993,6 +1017,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: u64 = 3; + _ = &a; var b: u64 = 0x5555555555555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0xffffffffffffffff); @@ -1006,6 +1031,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: i64 = 3; + _ = &a; var b: i64 = -0x2aaaaaaaaaaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x7ffffffffffffffe); @@ -1025,12 +1051,14 @@ test "@subWithOverflow" { { var a: u8 = 1; + _ = &a; const ov = @subWithOverflow(a, 2); try expect(ov[0] == 255); try expect(ov[1] == 1); } { var a: u8 = 1; + _ = &a; const ov = @subWithOverflow(a, 1); try expect(ov[0] == 0); try expect(ov[1] == 0); @@ -1038,6 +1066,7 @@ test "@subWithOverflow" { { var a: u8 = 1; + _ = &a; var b: u8 = 2; var ov = @subWithOverflow(a, b); try expect(ov[0] == 255); @@ -1051,6 +1080,7 @@ test "@subWithOverflow" { { var a: usize = 6; var b: usize = 6; + _ = .{ &a, &b }; const ov = @subWithOverflow(a, b); try expect(ov[0] == 0); try expect(ov[1] == 0); @@ -1059,6 +1089,7 @@ test "@subWithOverflow" { { var a: isize = -6; var b: isize = -6; + _ = .{ &a, &b }; const ov = @subWithOverflow(a, b); try expect(ov[0] == 0); try expect(ov[1] == 0); @@ -1072,6 +1103,7 @@ test "@shlWithOverflow" { { var a: u4 = 2; + _ = &a; var b: u2 = 1; var ov = @shlWithOverflow(a, b); try expect(ov[0] == 4); @@ -1085,6 +1117,7 @@ test "@shlWithOverflow" { { var a: i9 = 127; + _ = &a; var b: u4 = 1; var ov = @shlWithOverflow(a, b); try expect(ov[0] == 254); @@ -1108,6 +1141,7 @@ test "@shlWithOverflow" { } { var a: u16 = 0b0000_0000_0000_0011; + _ = &a; var b: u4 = 15; var ov = @shlWithOverflow(a, b); try expect(ov[0] == 0b1000_0000_0000_0000); @@ -1124,24 +1158,28 @@ test "overflow arithmetic with u0 values" { { var a: u0 = 0; + _ = &a; const ov = @addWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); } { var a: u0 = 0; + _ = &a; const ov = @subWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); } { var a: u0 = 0; + _ = &a; const ov = @mulWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); } { var a: u0 = 0; + _ = &a; const ov = @shlWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); @@ -1157,6 +1195,7 @@ test "allow signed integer division/remainder when values are comptime-known and try expect(-6 % 3 == 0); var undef: i32 = undefined; + _ = &undef; if (0 % undef != 0) { @compileError("0 as numerator should return comptime zero independent of denominator"); } @@ -1183,18 +1222,22 @@ test "quad hex float literal parsing accurate" { fn doTheTest() !void { { var f: f128 = 0x1.2eab345678439abcdefea56782346p+5; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234); } { var f: f128 = 0x1.edcb34a235253948765432134674fp-1; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even } { var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50); } { var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568); } const exp2ft = [_]f64{ @@ -1294,6 +1337,7 @@ test "shift left/right on u0 operand" { fn doTheTest() !void { var x: u0 = 0; var y: u0 = 0; + _ = .{ &x, &y }; try expectEqual(@as(u0, 0), x << 0); try expectEqual(@as(u0, 0), x >> 0); try expectEqual(@as(u0, 0), x << y); @@ -1310,7 +1354,7 @@ test "shift left/right on u0 operand" { test "comptime float rem int" { comptime { - var x = @as(f32, 1) % 2; + const x = @as(f32, 1) % 2; try expect(x == 1.0); } } @@ -1511,7 +1555,8 @@ test "vector integer addition" { fn doTheTest() !void { var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; - var result = a + b; + _ = .{ &a, &b }; + const result = a + b; var result_array: [4]i32 = result; const expected = [_]i32{ 6, 8, 10, 12 }; try expectEqualSlices(i32, &expected, &result_array); @@ -1552,6 +1597,7 @@ test "NaN comparison f80" { fn testNanEqNan(comptime F: type) !void { var nan1 = math.nan(F); var nan2 = math.nan(F); + _ = .{ &nan1, &nan2 }; try expect(nan1 != nan2); try expect(!(nan1 == nan2)); try expect(!(nan1 > nan2)); @@ -1571,6 +1617,7 @@ test "vector comparison" { fn doTheTest() !void { var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 }; var b: @Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 }; + _ = .{ &a, &b }; try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false })); try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false })); try expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false })); @@ -1609,7 +1656,8 @@ test "signed zeros are represented properly" { fn testOne(comptime T: type) !void { const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); var as_fp_val = -@as(T, 0.0); - var as_uint_val = @as(ST, @bitCast(as_fp_val)); + _ = &as_fp_val; + const as_uint_val: ST = @bitCast(as_fp_val); // Ensure the sign bit is set. try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1); } diff --git a/test/behavior/maximum_minimum.zig b/test/behavior/maximum_minimum.zig index 7d19f1dcdc797c17cbe01fe943089de849624159..f7cb1ee51319898f6dc6d9bdb51ac3e5bfb04d2f 100644 --- a/test/behavior/maximum_minimum.zig +++ b/test/behavior/maximum_minimum.zig @@ -15,6 +15,7 @@ test "@max" { var x: i32 = 10; var y: f32 = 0.68; var nan: f32 = std.math.nan(f32); + _ = .{ &x, &y, &nan }; try expect(@as(i32, 10) == @max(@as(i32, -3), x)); try expect(@as(f32, 3.2) == @max(@as(f32, 3.2), y)); try expect(y == @max(nan, y)); @@ -38,17 +39,20 @@ test "@max on vectors" { fn doTheTest() !void { var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; - var x = @max(a, b); + const x = @max(a, b); + _ = .{ &a, &b }; try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 2147483647, 2147483647, 30, 40 })); var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 }; - var y = @max(c, d); + const y = @max(c, d); + _ = .{ &c, &d }; try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ 0, 0.42, -0.64, 7.8 })); var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 }; - var z = @max(e, f); + const z = @max(e, f); + _ = .{ &e, &f }; try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 })); } }; @@ -66,6 +70,7 @@ test "@min" { var x: i32 = 10; var y: f32 = 0.68; var nan: f32 = std.math.nan(f32); + _ = .{ &x, &y, &nan }; try expect(@as(i32, -3) == @min(@as(i32, -3), x)); try expect(@as(f32, 0.68) == @min(@as(f32, 3.2), y)); try expect(y == @min(nan, y)); @@ -89,17 +94,20 @@ test "@min for vectors" { fn doTheTest() !void { var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; - var x = @min(a, b); + _ = .{ &a, &b }; + const x = @min(a, b); try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 1, -2, 3, 4 })); var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 }; - var y = @min(c, d); + _ = .{ &c, &d }; + const y = @min(c, d); try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ -0.23, 0.4, -2.4, 0.9 })); var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 }; - var z = @max(e, f); + _ = .{ &e, &f }; + const z = @max(e, f); try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 })); } }; @@ -119,6 +127,7 @@ test "@min/max for floats" { fn doTheTest(comptime T: type) !void { var x: T = -3.14; var y: T = 5.27; + _ = .{ &x, &y }; try expectEqual(x, @min(x, y)); try expectEqual(x, @min(y, x)); try expectEqual(y, @max(x, y)); @@ -126,6 +135,7 @@ test "@min/max for floats" { if (T != comptime_float) { var nan: T = std.math.nan(T); + _ = &nan; try expectEqual(y, @max(nan, y)); try expectEqual(y, @max(y, nan)); } @@ -175,6 +185,7 @@ test "@min/@max notices bounds" { var x: u16 = 20; const y = 30; var z: u32 = 100; + _ = .{ &x, &z }; const min = @min(x, y, z); const max = @max(x, y, z); try expectEqual(x, min); @@ -194,6 +205,7 @@ test "@min/@max notices vector bounds" { var x: @Vector(2, u16) = .{ 140, 40 }; const y: @Vector(2, u64) = .{ 5, 100 }; var z: @Vector(2, u32) = .{ 10, 300 }; + _ = .{ &x, &z }; const min = @min(x, y, z); const max = @max(x, y, z); try expectEqual(@Vector(2, u32){ 5, 40 }, min); @@ -224,6 +236,7 @@ test "@min/@max notices bounds from types" { var x: u16 = 123; var y: u32 = 456; var z: u8 = 10; + _ = .{ &x, &y, &z }; const min = @min(x, y, z); const max = @max(x, y, z); @@ -246,6 +259,7 @@ test "@min/@max notices bounds from vector types" { var x: @Vector(2, u16) = .{ 30, 67 }; var y: @Vector(2, u32) = .{ 20, 500 }; var z: @Vector(2, u8) = .{ 60, 15 }; + _ = .{ &x, &y, &z }; const min = @min(x, y, z); const max = @max(x, y, z); @@ -263,6 +277,7 @@ test "@min/@max notices bounds from types when comptime-known value is undef" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 1_000_000; + _ = &x; const y: u16 = undefined; // y is comptime-known, but is undef, so bounds cannot be refined using its value @@ -285,6 +300,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx)) return error.SkipZigTest; var x: @Vector(2, u32) = .{ 1_000_000, 12345 }; + _ = &x; const y: @Vector(2, u16) = .{ 10, undefined }; // y is comptime-known, but an element is undef, so bounds cannot be refined using its value @@ -302,6 +318,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known test "@min/@max of signed and unsigned runtime integers" { var x: i32 = -1; var y: u31 = 1; + _ = .{ &x, &y }; const min = @min(x, y); const max = @max(x, y); diff --git a/test/behavior/memcpy.zig b/test/behavior/memcpy.zig index 8d9880ccb06be82ad34177d617992715373e7e00..33f6c0f34c84bb78b87f14ceb9db012a31a88dad 100644 --- a/test/behavior/memcpy.zig +++ b/test/behavior/memcpy.zig @@ -57,6 +57,7 @@ fn testMemcpyDestManyPtr() !void { var str = "hello".*; var buf: [5]u8 = undefined; var len: usize = 5; + _ = &len; @memcpy(@as([*]u8, @ptrCast(&buf)), @as([*]const u8, @ptrCast(&str))[0..len]); try expect(buf[0] == 'h'); try expect(buf[1] == 'e'); diff --git a/test/behavior/memset.zig b/test/behavior/memset.zig index e3cf646f87106808837244e79e1ad8017d201745..966443f9cca19b87bb45359b3b799091f63d8484 100644 --- a/test/behavior/memset.zig +++ b/test/behavior/memset.zig @@ -46,7 +46,8 @@ fn testMemsetSlice() !void { // memset slice to non-undefined, ABI size == 1 var array: [20]u8 = undefined; var len = array.len; - var slice = array[0..len]; + _ = &len; + const slice = array[0..len]; @memset(slice, 'A'); try expect(slice[0] == 'A'); try expect(slice[11] == 'A'); @@ -56,7 +57,8 @@ fn testMemsetSlice() !void { // memset slice to non-undefined, ABI size > 1 var array: [20]u32 = undefined; var len = array.len; - var slice = array[0..len]; + _ = &len; + const slice = array[0..len]; @memset(slice, 1234); try expect(slice[0] == 1234); try expect(slice[11] == 1234); @@ -111,6 +113,7 @@ test "memset with large array element, runtime known" { const A = [128]u64; var buf: [5]A = undefined; var runtime_known_element = [_]u64{0} ** 128; + _ = &runtime_known_element; @memset(&buf, runtime_known_element); for (buf[0]) |elem| try expect(elem == 0); for (buf[1]) |elem| try expect(elem == 0); diff --git a/test/behavior/muladd.zig b/test/behavior/muladd.zig index b17c95a24e5b2ea6d7c45b9de9deee1fa578b276..3bdba835f96cd72313b3bffbd261bb3b90dcde45 100644 --- a/test/behavior/muladd.zig +++ b/test/behavior/muladd.zig @@ -21,12 +21,14 @@ fn testMulAdd() !void { var a: f32 = 5.5; var b: f32 = 2.5; var c: f32 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f32, a, b, c) == 20); } { var a: f64 = 5.5; var b: f64 = 2.5; var c: f64 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f64, a, b, c) == 20); } } @@ -46,6 +48,7 @@ fn testMulAdd16() !void { var a: f16 = 5.5; var b: f16 = 2.5; var c: f16 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f16, a, b, c) == 20); } @@ -65,6 +68,7 @@ fn testMulAdd80() !void { var a: f16 = 5.5; var b: f80 = 2.5; var c: f80 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f80, a, b, c) == 20); } @@ -84,6 +88,7 @@ fn testMulAdd128() !void { var a: f16 = 5.5; var b: f128 = 2.5; var c: f128 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f128, a, b, c) == 20); } @@ -91,7 +96,8 @@ fn vector16() !void { var a = @Vector(4, f16){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f16){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f16){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f16), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f16), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); @@ -115,7 +121,8 @@ fn vector32() !void { var a = @Vector(4, f32){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f32){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f32){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f32), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f32), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); @@ -139,7 +146,8 @@ fn vector64() !void { var a = @Vector(4, f64){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f64){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f64){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f64), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f64), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); @@ -163,7 +171,8 @@ fn vector80() !void { var a = @Vector(4, f80){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f80){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f80){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f80), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f80), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); try expect(x[2] == 20); @@ -187,7 +196,8 @@ fn vector128() !void { var a = @Vector(4, f128){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f128){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f128){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f128), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f128), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); diff --git a/test/behavior/null.zig b/test/behavior/null.zig index 3fe6e663e1c0954b3a2eea81f535de869357bde5..20afa21cb894d35327d1b1ea1e814ba2f685ca42 100644 --- a/test/behavior/null.zig +++ b/test/behavior/null.zig @@ -134,6 +134,7 @@ test "optional pointer to 0 bit type null value at runtime" { const EmptyStruct = struct {}; var x: ?*EmptyStruct = null; + _ = &x; try expect(x == null); } diff --git a/test/behavior/optional.zig b/test/behavior/optional.zig index 648b6988422670aa5d0478c0a4d15cf2013d48cb..d6dd27db3ba6dc63a6dbd2450c6358f58711ae82 100644 --- a/test/behavior/optional.zig +++ b/test/behavior/optional.zig @@ -11,7 +11,7 @@ test "passing an optional integer as a parameter" { const S = struct { fn entry() bool { - var x: i32 = 1234; + const x: i32 = 1234; return foo(x); } @@ -29,7 +29,7 @@ test "optional pointer to size zero struct" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var e = EmptyStruct{}; - var o: ?*EmptyStruct = &e; + const o: ?*EmptyStruct = &e; try expect(o != null); } @@ -63,6 +63,7 @@ test "optional with void type" { x: ?void, }; var x = Foo{ .x = null }; + _ = &x; try expect(x.x == null); } @@ -102,6 +103,7 @@ test "nested optional field in struct" { var s = S1{ .x = S2{ .y = 127 }, }; + _ = &s; try expect(s.x.?.y == 127); } @@ -120,6 +122,8 @@ fn test_cmp_optional_non_optional() !void { var five: i32 = 5; var int_n: ?i32 = null; + _ = .{ &ten, &opt_ten, &five, &int_n }; + try expect(int_n != ten); try expect(opt_ten == ten); try expect(opt_ten != five); @@ -208,7 +212,7 @@ test "self-referential struct through a slice of optional" { }; }; - var n = S.Node.new(); + const n = S.Node.new(); try expect(n.data == null); } @@ -252,7 +256,7 @@ test "0-bit child type coerced to optional return ptr result location" { const S = struct { fn doTheTest() !void { var y = Foo{}; - var z = y.thing(); + const z = y.thing(); try expect(z != null); } @@ -425,6 +429,7 @@ test "alignment of wrapping an optional payload" { fn foo() ?I { var i: I = .{ .x = 1234 }; + _ = &i; return i; } }; @@ -450,15 +455,16 @@ test "peer type resolution in nested if expressions" { const Thing = struct { n: i32 }; var a = false; var b = false; + _ = .{ &a, &b }; - var result1 = if (a) + const result1 = if (a) Thing{ .n = 1 } else null; try expect(result1 == null); try expect(@TypeOf(result1) == ?Thing); - var result2 = if (a) + const result2 = if (a) Thing{ .n = 0 } else if (b) Thing{ .n = 1 } @@ -486,5 +492,6 @@ test "cast slice to const slice nested in error union and optional" { test "variable of optional of noreturn" { var null_opv: ?noreturn = null; + _ = &null_opv; try std.testing.expectEqual(@as(?noreturn, null), null_opv); } diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig index a8665a02ea47edca27df68f65a55350ec3c75c65..60e8d6d93a18607506b3781dc60bffc92fe71359 100644 --- a/test/behavior/packed-struct.zig +++ b/test/behavior/packed-struct.zig @@ -479,10 +479,9 @@ test "load pointer from packed struct" { y: u32, }; var a: A = .{ .index = 123 }; - var b_list: []const B = &.{.{ .x = &a, .y = 99 }}; + const b_list: []const B = &.{.{ .x = &a, .y = 99 }}; for (b_list) |b| { - var i = b.x.index; - try expect(i == 123); + try expect(b.x.index == 123); } } @@ -770,6 +769,7 @@ test "nested packed struct field access test" { }; var arg = a{ .b = hld{ .c = 1, .d = 2 }, .g = mld{ .h = 6, .i = 8 } }; + _ = &arg; try std.testing.expect(arg.b.c == 1); try std.testing.expect(arg.b.d == 2); try std.testing.expect(arg.g.h == 6); @@ -790,6 +790,7 @@ test "nested packed struct at non-zero offset" { }; var k: u8 = 123; + _ = &k; var v: A = .{ .p1 = .{ .a = k + 1, .b = k }, .p2 = .{ .a = k + 1, .b = k }, @@ -833,6 +834,7 @@ test "nested packed struct at non-zero offset 2" { fn doTheTest() !void { var k: u8 = 123; + _ = &k; var v: A = .{ .p1 = .{ .a = k + 1, .b = k }, .p2 = .{ .a = k + 1, .b = k }, @@ -877,6 +879,7 @@ test "runtime init of unnamed packed struct type" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var z: u8 = 123; + _ = &z; try (packed struct { x: u8, pub fn m(s: @This()) !void { @@ -941,6 +944,7 @@ test "packed struct initialized in bitcast" { const T = packed struct { val: u8 }; var val: u8 = 123; + _ = &val; const t = @as(u8, @bitCast(T{ .val = val })); try expect(t == val); } @@ -976,7 +980,8 @@ test "store undefined to packed result location" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u4 = 0; - var s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined }; + _ = &x; + const s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined }; try expectEqual(x, s.x); } @@ -1004,7 +1009,7 @@ test "field access of packed struct smaller than its abi size inside struct init } }; - var s = S.init(true); + const s = S.init(true); // note: this bug is triggered by the == operator, expectEqual will hide it try expect(@as(i2, 0) == s.ps.x); try expect(@as(i2, 1) == s.ps.y); diff --git a/test/behavior/pointers.zig b/test/behavior/pointers.zig index 52e3e68c3fcb09c86d6576de2bccfb0569c3c32c..3e3e67cc4e5f78255c002943f69544674f35fedb 100644 --- a/test/behavior/pointers.zig +++ b/test/behavior/pointers.zig @@ -11,7 +11,7 @@ test "dereference pointer" { fn testDerefPtr() !void { var x: i32 = 1234; - var y = &x; + const y = &x; y.* += 1; try expect(x == 1235); } @@ -53,8 +53,8 @@ test "implicit cast single item pointer to C pointer and back" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var y: u8 = 11; - var x: [*c]u8 = &y; - var z: *u8 = x; + const x: [*c]u8 = &y; + const z: *u8 = x; z.* += 1; try expect(y == 12); } @@ -74,6 +74,7 @@ test "assigning integer to C pointer" { var ptr2: [*c]u8 = x; var ptr3: [*c]u8 = 1; var ptr4: [*c]u8 = y; + _ = .{ &x, &y, &ptr, &ptr2, &ptr3, &ptr4 }; try expect(ptr == ptr2); try expect(ptr3 == ptr4); @@ -88,6 +89,7 @@ test "C pointer comparison and arithmetic" { fn doTheTest() !void { var ptr1: [*c]u32 = 0; var ptr2 = ptr1 + 10; + _ = &ptr1; try expect(ptr1 == 0); try expect(ptr1 >= 0); try expect(ptr1 <= 0); @@ -125,14 +127,15 @@ fn testDerefPtrOneVal() !void { } test "peer type resolution with C pointers" { - var ptr_one: *u8 = undefined; - var ptr_many: [*]u8 = undefined; - var ptr_c: [*c]u8 = undefined; + const ptr_one: *u8 = undefined; + const ptr_many: [*]u8 = undefined; + const ptr_c: [*c]u8 = undefined; var t = true; - var x1 = if (t) ptr_one else ptr_c; - var x2 = if (t) ptr_many else ptr_c; - var x3 = if (t) ptr_c else ptr_one; - var x4 = if (t) ptr_c else ptr_many; + _ = &t; + const x1 = if (t) ptr_one else ptr_c; + const x2 = if (t) ptr_many else ptr_c; + const x3 = if (t) ptr_c else ptr_one; + const x4 = if (t) ptr_c else ptr_many; try expect(@TypeOf(x1) == [*c]u8); try expect(@TypeOf(x2) == [*c]u8); try expect(@TypeOf(x3) == [*c]u8); @@ -141,8 +144,9 @@ test "peer type resolution with C pointers" { test "peer type resolution with C pointer and const pointer" { var ptr_c: [*c]u8 = undefined; - const ptr_const: u8 = undefined; - try expect(@TypeOf(ptr_c, &ptr_const) == [*c]const u8); + var ptr_const: *const u8 = &undefined; + _ = .{ &ptr_c, &ptr_const }; + try expect(@TypeOf(ptr_c, ptr_const) == [*c]const u8); } test "implicit casting between C pointer and optional non-C pointer" { @@ -151,9 +155,10 @@ test "implicit casting between C pointer and optional non-C pointer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var slice: []const u8 = "aoeu"; + _ = &slice; const opt_many_ptr: ?[*]const u8 = slice.ptr; var ptr_opt_many_ptr = &opt_many_ptr; - var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; + const c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; try expect(c_ptr.*.* == 'a'); ptr_opt_many_ptr = c_ptr; try expect(ptr_opt_many_ptr.*.?[1] == 'o'); @@ -192,11 +197,12 @@ test "allowzero pointer and slice" { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - var ptr = @as([*]allowzero i32, @ptrFromInt(0)); - var opt_ptr: ?[*]allowzero i32 = ptr; + var ptr: [*]allowzero i32 = @ptrFromInt(0); + const opt_ptr: ?[*]allowzero i32 = ptr; try expect(opt_ptr != null); try expect(@intFromPtr(ptr) == 0); var runtime_zero: usize = 0; + _ = &runtime_zero; var slice = ptr[runtime_zero..10]; try comptime expect(@TypeOf(slice) == []allowzero i32); try expect(@intFromPtr(&slice[5]) == 20); @@ -211,6 +217,7 @@ test "assign null directly to C pointer and test null equality" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: [*c]i32 = null; + _ = &x; try expect(x == null); try expect(null == x); try expect(!(x != null)); @@ -236,7 +243,7 @@ test "assign null directly to C pointer and test null equality" { try comptime expect((y orelse ptr_othery) == ptr_othery); var n: i32 = 1234; - var x1: [*c]i32 = &n; + const x1: [*c]i32 = &n; try expect(!(x1 == null)); try expect(!(null == x1)); try expect(x1 != null); @@ -279,9 +286,9 @@ test "null terminated pointer" { const S = struct { fn doTheTest() !void { var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' }; - var zero_ptr: [*:0]const u8 = @as([*:0]const u8, @ptrCast(&array_with_zero)); - var no_zero_ptr: [*]const u8 = zero_ptr; - var zero_ptr_again = @as([*:0]const u8, @ptrCast(no_zero_ptr)); + const zero_ptr: [*:0]const u8 = @ptrCast(&array_with_zero); + const no_zero_ptr: [*]const u8 = zero_ptr; + const zero_ptr_again: [*:0]const u8 = @ptrCast(no_zero_ptr); try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello")); } }; @@ -296,7 +303,7 @@ test "allow any sentinel" { const S = struct { fn doTheTest() !void { var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 }; - var ptr: [*:std.math.minInt(i32)]i32 = &array; + const ptr: [*:std.math.minInt(i32)]i32 = &array; try expect(ptr[4] == std.math.minInt(i32)); } }; @@ -317,6 +324,7 @@ test "pointer sentinel with enums" { fn doTheTest() !void { var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; + _ = &ptr; try expect(ptr[4] == .sentinel); // TODO this should be try comptime expect, see #3731 } }; @@ -332,6 +340,7 @@ test "pointer sentinel with optional element" { const S = struct { fn doTheTest() !void { var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; + _ = &ptr; try expect(ptr[4] == null); // TODO this should be try comptime expect, see #3731 } }; @@ -348,6 +357,7 @@ test "pointer sentinel with +inf" { fn doTheTest() !void { const inf_f32 = comptime std.math.inf(f32); var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 }; + _ = &ptr; try expect(ptr[4] == inf_f32); // TODO this should be try comptime expect, see #3731 } }; @@ -366,6 +376,7 @@ test "pointer arithmetic affects the alignment" { { var ptr: [*]align(8) u32 = undefined; var x: usize = 1; + _ = .{ &ptr, &x }; try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8); const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4 @@ -380,6 +391,7 @@ test "pointer arithmetic affects the alignment" { { var ptr: [*]align(8) [3]u8 = undefined; var x: usize = 1; + _ = .{ &ptr, &x }; const ptr1 = ptr + 17; // 3 * 17 = 51 try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1); @@ -467,8 +479,8 @@ test "array slicing to slice" { const S = struct { fn doTheTest() !void { var str: [5]i32 = [_]i32{ 1, 2, 3, 4, 5 }; - var sub: *[2]i32 = str[1..3]; - var slice: []i32 = sub; // used to cause failures + const sub: *[2]i32 = str[1..3]; + const slice: []i32 = sub; // used to cause failures try testing.expect(slice.len == 2); try testing.expect(slice[0] == 2); } @@ -495,7 +507,8 @@ test "ptrCast comptime known slice to C pointer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO const s: [:0]const u8 = "foo"; - var p = @as([*c]const u8, @ptrCast(s)); + var p: [*c]const u8 = @ptrCast(s); + _ = &p; try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0)); } @@ -527,6 +540,7 @@ test "pointer to array has explicit alignment" { test "result type preserved through multiple references" { const S = struct { x: u32 }; var my_u64: u64 = 12345; + _ = &my_u64; const foo: *const *const *const S = &&&.{ .x = @intCast(my_u64), }; diff --git a/test/behavior/popcount.zig b/test/behavior/popcount.zig index eda7346a2dbbf5ebe1904017542639fdd2ed2422..261019c65faa77f2edb960f498b171b339039421 100644 --- a/test/behavior/popcount.zig +++ b/test/behavior/popcount.zig @@ -26,6 +26,7 @@ test "@popCount 128bit integer" { { var x: u128 = 0b11111111000110001100010000100001000011000011100101010001; + _ = &x; try expect(@popCount(x) == 24); } @@ -35,30 +36,37 @@ test "@popCount 128bit integer" { fn testPopCountIntegers() !void { { var x: u32 = 0xffffffff; + _ = &x; try expect(@popCount(x) == 32); } { var x: u5 = 0x1f; + _ = &x; try expect(@popCount(x) == 5); } { var x: u32 = 0xaa; + _ = &x; try expect(@popCount(x) == 4); } { var x: u32 = 0xaaaaaaaa; + _ = &x; try expect(@popCount(x) == 16); } { var x: u32 = 0xaaaaaaaa; + _ = &x; try expect(@popCount(x) == 16); } { var x: i16 = -1; + _ = &x; try expect(@popCount(x) == 16); } { var x: i8 = -120; + _ = &x; try expect(@popCount(x) == 2); } comptime { @@ -81,12 +89,14 @@ test "@popCount vectors" { fn testPopCountVectors() !void { { var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8; + _ = &x; const expected = [1]u6{32} ** 8; const result: [8]u6 = @popCount(x); try expect(std.mem.eql(u6, &expected, &result)); } { var x: @Vector(8, i16) = [1]i16{-1} ** 8; + _ = &x; const expected = [1]u5{16} ** 8; const result: [8]u5 = @popCount(x); try expect(std.mem.eql(u5, &expected, &result)); diff --git a/test/behavior/prefetch.zig b/test/behavior/prefetch.zig index d4baa649d003f2d8151863bdb9d038363d828a27..e98e848393aaa79803c2e70625140f247eb89482 100644 --- a/test/behavior/prefetch.zig +++ b/test/behavior/prefetch.zig @@ -6,6 +6,7 @@ test "@prefetch()" { var a: [2]u32 = .{ 42, 42 }; var a_len = a.len; + _ = &a_len; @prefetch(&a, .{}); diff --git a/test/behavior/ptrcast.zig b/test/behavior/ptrcast.zig index 635a4df84385edabb70fd0a0fe3e60deb11f7b36..4e9283b3a474b9f89a190feb69239503af397cf2 100644 --- a/test/behavior/ptrcast.zig +++ b/test/behavior/ptrcast.zig @@ -71,8 +71,8 @@ fn testReinterpretBytesAsExternStruct() !void { c: u8, }; - var ptr = @as(*const S, @ptrCast(&bytes)); - var val = ptr.c; + const ptr: *const S = @ptrCast(&bytes); + const val = ptr.c; try expect(val == 5); } @@ -95,8 +95,8 @@ fn testReinterpretExternStructAsExternStruct() !void { a: u32 align(2), c: u8, }; - var ptr = @as(*const S2, @ptrCast(&bytes)); - var val = ptr.c; + const ptr: *const S2 = @ptrCast(&bytes); + const val = ptr.c; try expect(val == 5); } @@ -121,8 +121,8 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void { a2: u16, c: u8, }; - var ptr = @as(*const S2, @ptrCast(&bytes)); - var val = ptr.c; + const ptr: *const S2 = @ptrCast(&bytes); + const val = ptr.c; try expect(val == 5); } @@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" { c: u8, }; comptime var ptr = @as(*const S, @ptrCast(&bytes)); - var val = &ptr.c; + const val = &ptr.c; try expect(val.* == 5); // Test lowering an elem ptr comptime var src_value = S{ .a = 15, .c = 5 }; comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); - var val2 = &ptr2[4]; + const val2 = &ptr2[4]; try expect(val2.* == 5); } @@ -160,13 +160,13 @@ test "lower reinterpreted comptime field ptr" { c: u8, }; comptime var ptr = @as(*const S, @ptrCast(&bytes)); - var val = &ptr.c; + const val = &ptr.c; try expect(val.* == 5); // Test lowering an elem ptr comptime var src_value = S{ .a = 15, .c = 5 }; comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); - var val2 = &ptr2[4]; + const val2 = &ptr2[4]; try expect(val2.* == 5); } @@ -233,9 +233,9 @@ test "implicit optional pointer to optional anyopaque pointer" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO var buf: [4]u8 = "aoeu".*; - var x: ?[*]u8 = &buf; - var y: ?*anyopaque = x; - var z = @as(*[4]u8, @ptrCast(y)); + const x: ?[*]u8 = &buf; + const y: ?*anyopaque = x; + const z: *[4]u8 = @ptrCast(y); try expect(std.mem.eql(u8, z, "aoeu")); } @@ -276,7 +276,7 @@ test "@ptrCast undefined value at comptime" { } }; comptime { - var x = S.transmute([]u8, i32, undefined); + const x = S.transmute([]u8, i32, undefined); _ = x; } } diff --git a/test/behavior/ptrfromint.zig b/test/behavior/ptrfromint.zig index 72244aa7d122178eabb8624a52bc6f0176565d64..89706be891f5648c6288896e2cbbf012776601f3 100644 --- a/test/behavior/ptrfromint.zig +++ b/test/behavior/ptrfromint.zig @@ -9,6 +9,7 @@ test "casting integer address to function pointer" { fn addressToFunction() void { var addr: usize = 0xdeadbee0; + _ = &addr; _ = @as(*const fn () void, @ptrFromInt(addr)); } diff --git a/test/behavior/saturating_arithmetic.zig b/test/behavior/saturating_arithmetic.zig index 30d1aa712e347dbf31e1d3b128ba4907c6a4d7db..82d10d95402a0cf57db429ab5b74101679d7bbcb 100644 --- a/test/behavior/saturating_arithmetic.zig +++ b/test/behavior/saturating_arithmetic.zig @@ -246,9 +246,11 @@ test "saturating shl uses the LHS type" { const lhs_const: u8 = 1; var lhs_var: u8 = 1; + _ = &lhs_var; const rhs_const: usize = 8; var rhs_var: usize = 8; + _ = &rhs_var; try expect((lhs_const <<| 8) == 255); try expect((lhs_const <<| rhs_const) == 255); diff --git a/test/behavior/select.zig b/test/behavior/select.zig index 66cc0a49b019238b500333a340b307711af1b46d..de717e5e5bd5840565abee3e975137b224d3a7b9 100644 --- a/test/behavior/select.zig +++ b/test/behavior/select.zig @@ -19,7 +19,8 @@ fn selectVectors() !void { var a = @Vector(4, bool){ true, false, true, false }; var b = @Vector(4, i32){ -1, 4, 999, -31 }; var c = @Vector(4, i32){ -5, 1, 0, 1234 }; - var abc = @select(i32, a, b, c); + _ = .{ &a, &b, &c }; + const abc = @select(i32, a, b, c); try expect(abc[0] == -1); try expect(abc[1] == 1); try expect(abc[2] == 999); @@ -28,7 +29,8 @@ fn selectVectors() !void { var x = @Vector(4, bool){ false, false, false, true }; var y = @Vector(4, f32){ 0.001, 33.4, 836, -3381.233 }; var z = @Vector(4, f32){ 0.0, 312.1, -145.9, 9993.55 }; - var xyz = @select(f32, x, y, z); + _ = .{ &x, &y, &z }; + const xyz = @select(f32, x, y, z); try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); } @@ -48,7 +50,8 @@ fn selectArrays() !void { var a = [4]bool{ false, true, false, true }; var b = [4]usize{ 0, 1, 2, 3 }; var c = [4]usize{ 4, 5, 6, 7 }; - var abc = @select(usize, a, b, c); + _ = .{ &a, &b, &c }; + const abc = @select(usize, a, b, c); try expect(abc[0] == 4); try expect(abc[1] == 1); try expect(abc[2] == 6); @@ -57,6 +60,7 @@ fn selectArrays() !void { var x = [4]bool{ false, false, false, true }; var y = [4]f32{ 0.001, 33.4, 836, -3381.233 }; var z = [4]f32{ 0.0, 312.1, -145.9, 9993.55 }; - var xyz = @select(f32, x, y, z); + _ = .{ &x, &y, &z }; + const xyz = @select(f32, x, y, z); try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); } diff --git a/test/behavior/shuffle.zig b/test/behavior/shuffle.zig index 6137c66f1f9300da56f183086fbe2031557fe657..e9d7706ff4a9090d84783e2fbf286857b7401f0e 100644 --- a/test/behavior/shuffle.zig +++ b/test/behavior/shuffle.zig @@ -13,7 +13,9 @@ test "@shuffle int" { const S = struct { fn doTheTest() !void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; + _ = &v; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; + _ = &x; const mask = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; var res = @shuffle(i32, v, x, mask); try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 })); @@ -29,12 +31,14 @@ test "@shuffle int" { // Upcasting of b var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; + _ = &v2; const mask3 = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; res = @shuffle(i32, x, v2, mask3); try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 })); // Upcasting of a var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; + _ = &v3; const mask4 = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; res = @shuffle(i32, v3, x, mask4); try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 })); @@ -55,9 +59,11 @@ test "@shuffle bool 1" { const S = struct { fn doTheTest() !void { var x: @Vector(4, bool) = [4]bool{ false, true, false, true }; + _ = &x; var v: @Vector(2, bool) = [2]bool{ true, false }; + _ = &v; const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; - var res = @shuffle(bool, x, v, mask); + const res = @shuffle(bool, x, v, mask); try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false })); } }; @@ -81,9 +87,11 @@ test "@shuffle bool 2" { const S = struct { fn doTheTest() !void { var x: @Vector(3, bool) = [3]bool{ false, true, false }; + _ = &x; var v: @Vector(2, bool) = [2]bool{ true, false }; + _ = &v; const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; - var res = @shuffle(bool, x, v, mask); + const res = @shuffle(bool, x, v, mask); try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false })); } }; diff --git a/test/behavior/sizeof_and_typeof.zig b/test/behavior/sizeof_and_typeof.zig index 74b02d7fdba4150c911e549f8af25bc6e051fd1c..00f891a70f9805094f29242369e8fb3b95272072 100644 --- a/test/behavior/sizeof_and_typeof.zig +++ b/test/behavior/sizeof_and_typeof.zig @@ -22,20 +22,24 @@ test "@TypeOf() with multiple arguments" { var var_1: u32 = undefined; var var_2: u8 = undefined; var var_3: u64 = undefined; + _ = .{ &var_1, &var_2, &var_3 }; try comptime expect(@TypeOf(var_1, var_2, var_3) == u64); } { var var_1: f16 = undefined; var var_2: f32 = undefined; var var_3: f64 = undefined; + _ = .{ &var_1, &var_2, &var_3 }; try comptime expect(@TypeOf(var_1, var_2, var_3) == f64); } { var var_1: u16 = undefined; + _ = &var_1; try comptime expect(@TypeOf(var_1, 0xffff) == u16); } { var var_1: f32 = undefined; + _ = &var_1; try comptime expect(@TypeOf(var_1, 3.1415) == f32); } } @@ -269,6 +273,7 @@ test "runtime instructions inside typeof in comptime only scope" { { var y: i8 = 2; + _ = &y; const i: [2]i8 = [_]i8{ 1, y }; const T = struct { a: @TypeOf(i) = undefined, // causes crash @@ -279,6 +284,7 @@ test "runtime instructions inside typeof in comptime only scope" { } { var y: i8 = 2; + _ = &y; const i = .{ 1, y }; const T = struct { b: @TypeOf(i[1]) = undefined, diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig index c95bc293ef9934465ec5c83fb45affbb8b6d4cd7..7ceabf05cf48c4dafa9a35cc373c185553e0363a 100644 --- a/test/behavior/slice.zig +++ b/test/behavior/slice.zig @@ -23,7 +23,7 @@ comptime { }; const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong }; const list: []const type = &unsigned; - var pos = S.indexOfScalar(type, list, c_ulong).?; + const pos = S.indexOfScalar(type, list, c_ulong).?; if (pos != 1) @compileError("bad pos"); } @@ -36,13 +36,14 @@ test "slicing" { var slice = array[5..10]; - if (slice.len != 5) unreachable; + try expect(slice.len == 5); const ptr = &slice[0]; - if (ptr.* != 1234) unreachable; + try expect(ptr.* == 1234); var slice_rest = array[10..]; - if (slice_rest.len != 10) unreachable; + _ = &slice_rest; + try expect(slice_rest.len == 10); } test "const slice" { @@ -79,7 +80,7 @@ test "access len index of sentinel-terminated slice" { const S = struct { fn doTheTest() !void { var slice: [:0]const u8 = "hello"; - + _ = &slice; try expect(slice.len == 5); try expect(slice[5] == 0); } @@ -208,6 +209,7 @@ test "slice string literal has correct type" { try expect(@TypeOf(array[0..]) == *const [4]i32); } var runtime_zero: usize = 0; + _ = &runtime_zero; try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8); const array = [_]i32{ 1, 2, 3, 4 }; try comptime expect(@TypeOf(array[runtime_zero..]) == []const i32); @@ -219,7 +221,8 @@ test "result location zero sized array inside struct field implicit cast to slic const E = struct { entries: []u32, }; - var foo = E{ .entries = &[_]u32{} }; + var foo: E = .{ .entries = &[_]u32{} }; + _ = &foo; try expect(foo.entries.len == 0); } @@ -242,7 +245,8 @@ test "C pointer" { var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf"; var len: u32 = 10; - var slice = buf[0..len]; + _ = &len; + const slice = buf[0..len]; try expect(mem.eql(u8, "kjdhfkjdhf", slice)); } @@ -255,6 +259,7 @@ test "C pointer slice access" { const c_ptr = @as([*c]const u32, @ptrCast(&buf)); var runtime_zero: usize = 0; + _ = &runtime_zero; try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1])); try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1])); @@ -306,11 +311,13 @@ test "obtaining a null terminated slice" { _ = ptr; var runtime_len: usize = 3; + _ = &runtime_len; const ptr2 = buf[0..runtime_len :0]; // ptr2 is a null-terminated slice try comptime expect(@TypeOf(ptr2) == [:0]u8); try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8); var runtime_zero: usize = 0; + _ = &runtime_zero; try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8); } @@ -338,8 +345,8 @@ test "@ptrCast slice to pointer" { const S = struct { fn doTheTest() !void { var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff }; - var slice: []align(@alignOf(u16)) u8 = &array; - var ptr = @as(*u16, @ptrCast(slice)); + const slice: []align(@alignOf(u16)) u8 = &array; + const ptr: *u16 = @ptrCast(slice); try expect(ptr.* == 65535); } }; @@ -357,8 +364,8 @@ test "slice multi-pointer without end" { fn testPointer() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; - var pointer: [*]u8 = &array; - var slice = pointer[1..]; + const pointer: [*]u8 = &array; + const slice = pointer[1..]; try comptime expect(@TypeOf(slice) == [*]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -366,13 +373,13 @@ test "slice multi-pointer without end" { fn testPointerZ() !void { var array = [5:0]u8{ 1, 2, 3, 4, 5 }; - var pointer: [*:0]u8 = &array; + const pointer: [*:0]u8 = &array; try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8); try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8); - var slice = pointer[1..]; + const slice = pointer[1..]; try comptime expect(@TypeOf(slice) == [*:0]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -413,7 +420,7 @@ test "slice syntax resulting in pointer-to-array" { fn testArray() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; - var slice = array[1..3]; + const slice = array[1..3]; try comptime expect(@TypeOf(slice) == *[2]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -430,12 +437,12 @@ test "slice syntax resulting in pointer-to-array" { fn testArray0() !void { { var array = [0]u8{}; - var slice = array[0..0]; + const slice = array[0..0]; try comptime expect(@TypeOf(slice) == *[0]u8); } { var array = [0:0]u8{}; - var slice = array[0..0]; + const slice = array[0..0]; try comptime expect(@TypeOf(slice) == *[0:0]u8); try expect(slice[0] == 0); } @@ -443,7 +450,7 @@ test "slice syntax resulting in pointer-to-array" { fn testArrayAlign() !void { var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; - var slice = array[4..5]; + const slice = array[4..5]; try comptime expect(@TypeOf(slice) == *align(4) [1]u8); try expect(slice[0] == 5); try comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8); @@ -452,7 +459,7 @@ test "slice syntax resulting in pointer-to-array" { fn testPointer() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; var pointer: [*]u8 = &array; - var slice = pointer[1..3]; + const slice = pointer[1..3]; try comptime expect(@TypeOf(slice) == *[2]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -467,7 +474,7 @@ test "slice syntax resulting in pointer-to-array" { fn testPointer0() !void { var pointer: [*]const u0 = &[1]u0{0}; - var slice = pointer[0..1]; + const slice = pointer[0..1]; try comptime expect(@TypeOf(slice) == *const [1]u0); try expect(slice[0] == 0); } @@ -475,7 +482,7 @@ test "slice syntax resulting in pointer-to-array" { fn testPointerAlign() !void { var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; var pointer: [*]align(4) u8 = &array; - var slice = pointer[4..5]; + const slice = pointer[4..5]; try comptime expect(@TypeOf(slice) == *align(4) [1]u8); try expect(slice[0] == 5); try comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8); @@ -484,7 +491,7 @@ test "slice syntax resulting in pointer-to-array" { fn testSlice() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; var src_slice: []u8 = &array; - var slice = src_slice[1..3]; + const slice = src_slice[1..3]; try comptime expect(@TypeOf(slice) == *[2]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -513,7 +520,7 @@ test "slice syntax resulting in pointer-to-array" { fn testSliceAlign() !void { var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; var src_slice: []align(4) u8 = &array; - var slice = src_slice[4..5]; + const slice = src_slice[4..5]; try comptime expect(@TypeOf(slice) == *align(4) [1]u8); try expect(slice[0] == 5); try comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8); @@ -616,13 +623,13 @@ test "slice pointer-to-array zero length" { { var array = [0]u8{}; var src_slice: []u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try expect(@TypeOf(slice) == *[0]u8); } { var array = [0:0]u8{}; var src_slice: [:0]u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try expect(@TypeOf(slice) == *[0:0]u8); } } @@ -630,13 +637,13 @@ test "slice pointer-to-array zero length" { { var array = [0]u8{}; var src_slice: []u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try comptime expect(@TypeOf(slice) == *[0]u8); } { var array = [0:0]u8{}; var src_slice: [:0]u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try comptime expect(@TypeOf(slice) == *[0]u8); } } @@ -655,17 +662,19 @@ test "type coercion of pointer to anon struct literal to pointer to slice" { fn doTheTest() !void { var x1: u8 = 42; + _ = &x1; const t1 = &.{ x1, 56, 54 }; - var slice1: []const u8 = t1; + const slice1: []const u8 = t1; try expect(slice1.len == 3); try expect(slice1[0] == 42); try expect(slice1[1] == 56); try expect(slice1[2] == 54); var x2: []const u8 = "hello"; + _ = &x2; const t2 = &.{ x2, ", ", "world!" }; // @compileLog(@TypeOf(t2)); - var slice2: []const []const u8 = t2; + const slice2: []const []const u8 = t2; try expect(slice2.len == 3); try expect(mem.eql(u8, slice2[0], "hello")); try expect(mem.eql(u8, slice2[1], ", ")); @@ -680,6 +689,7 @@ test "array concat of slices gives ptr to array" { comptime { var a: []const u8 = "aoeu"; var b: []const u8 = "asdf"; + _ = .{ &a, &b }; const c = a ++ b; try expect(std.mem.eql(u8, c, "aoeuasdf")); try expect(@TypeOf(c) == *const [8]u8); @@ -689,6 +699,7 @@ test "array concat of slices gives ptr to array" { test "array mult of slice gives ptr to array" { comptime { var a: []const u8 = "aoeu"; + _ = &a; const c = a ** 2; try expect(std.mem.eql(u8, c, "aoeuaoeu")); try expect(@TypeOf(c) == *const [8]u8); @@ -736,7 +747,7 @@ test "slicing array with sentinel as end index" { const S = struct { fn do() !void { var array = [_:0]u8{ 1, 2, 3, 4 }; - var slice = array[4..5]; + const slice = array[4..5]; try expect(slice.len == 1); try expect(slice[0] == 0); try expect(@TypeOf(slice) == *[1]u8); @@ -754,8 +765,8 @@ test "slicing slice with sentinel as end index" { const S = struct { fn do() !void { var array = [_:0]u8{ 1, 2, 3, 4 }; - var src_slice: [:0]u8 = &array; - var slice = src_slice[4..5]; + const src_slice: [:0]u8 = &array; + const slice = src_slice[4..5]; try expect(slice.len == 1); try expect(slice[0] == 0); try expect(@TypeOf(slice) == *[1]u8); @@ -820,6 +831,7 @@ test "global slice field access" { test "slice of void" { var n: usize = 10; + _ = &n; var arr: [12]void = undefined; const slice = @as([]void, &arr)[0..n]; try expect(slice.len == n); @@ -827,7 +839,7 @@ test "slice of void" { test "slice with dereferenced value" { var a: usize = 0; - var idx: *usize = &a; + const idx: *usize = &a; _ = blk: { var array = [_]u8{}; break :blk array[idx.*..]; diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 08954dfd68c6a9e68a5f650b2fc42ba0fbaab758..97ccb3212f3ec4c1e2b46e4b589bc737d0a33dd9 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -254,7 +254,8 @@ test "struct field init with catch" { const S = struct { fn doTheTest() !void { var x: anyerror!isize = 1; - var req = Foo{ + _ = &x; + const req = Foo{ .field = x catch undefined, }; try expect(req.field == 1); @@ -505,7 +506,7 @@ test "packed struct fields are ordered from LSB to MSB" { var all: u64 = 0x7765443322221111; var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined; @memcpy(bytes[0..8], @as([*]u8, @ptrCast(&all))); - var bitfields = @as(*Bitfields, @ptrCast(&bytes)).*; + const bitfields = @as(*Bitfields, @ptrCast(&bytes)).*; try expect(bitfields.f1 == 0x1111); try expect(bitfields.f2 == 0x2222); @@ -545,7 +546,7 @@ test "zero-bit field in packed struct" { y: void, }; var x: S = undefined; - _ = x; + _ = &x; } test "packed struct with non-ABI-aligned field" { @@ -624,6 +625,7 @@ test "default struct initialization fields" { .b = 5, }; var five: i32 = 5; + _ = &five; const y = S{ .b = five, }; @@ -714,7 +716,7 @@ test "pointer to packed struct member in a stack variable" { }; var s = S{ .a = 2, .b = 0 }; - var b_ptr = &s.b; + const b_ptr = &s.b; try expect(s.b == 0); b_ptr.* = 2; try expect(s.b == 2); @@ -727,6 +729,7 @@ test "packed struct with u0 field access" { f0: u0, }; var s = S{ .f0 = 0 }; + _ = &s; try comptime expect(s.f0 == 0); } @@ -788,7 +791,7 @@ test "fn with C calling convention returns struct by value" { const S = struct { fn entry() !void { - var x = makeBar(10); + const x = makeBar(10); try expect(@as(i32, 10) == x.handle); } @@ -827,6 +830,7 @@ test "non-packed struct with u128 entry in union" { var s = &sx; try expect(@intFromPtr(&s.f2) - @intFromPtr(&s.f1) == @offsetOf(S, "f2")); var v2 = U{ .Num = 123 }; + _ = &v2; s.f2 = v2; try expect(s.f2.Num == 123); } @@ -852,7 +856,7 @@ test "packed struct field passed to generic function" { var p: S.P = undefined; p.b = 29; - var loaded = S.genericReadPackedField(&p.b); + const loaded = S.genericReadPackedField(&p.b); try expect(loaded == 29); } @@ -871,6 +875,7 @@ test "anonymous struct literal syntax" { .x = 1, .y = 2, }; + _ = &p; try expect(p.x == 1); try expect(p.y == 2); } @@ -920,6 +925,7 @@ test "fully anonymous list literal" { test "tuple assigned to variable" { var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) }; + _ = &vec; try expect(vec.@"0" == 22); try expect(vec.@"1" == 55); try expect(vec.@"2" == 99); @@ -940,6 +946,7 @@ test "comptime struct field" { comptime std.debug.assert(@sizeOf(T) == 4); var foo: T = undefined; + _ = &foo; try comptime expect(foo.b == 1234); } @@ -950,7 +957,7 @@ test "tuple element initialized with fn call" { const S = struct { fn doTheTest() !void { - var x = .{foo()}; + const x = .{foo()}; try expectEqualSlices(u8, x[0], "hi"); } fn foo() []const u8 { @@ -977,6 +984,7 @@ test "struct with union field" { var True = Value{ .kind = .{ .Bool = true }, }; + _ = &True; try expect(@as(u32, 2) == True.ref); try expect(True.kind.Bool); } @@ -996,6 +1004,7 @@ test "struct with 0-length union array field" { }; var s: S = undefined; + _ = &s; try expectEqual(@as(usize, 0), s.zero_length.len); } @@ -1019,10 +1028,11 @@ test "type coercion of anon struct literal to struct" { fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = .{ .A = 123, .B = "foo", .C = {} }; const t1 = .{ .A = y, .B = "foo", .C = {} }; const y0: S2 = t0; - var y1: S2 = t1; + const y1: S2 = t1; try expect(y0.A == 123); try expect(std.mem.eql(u8, y0.B, "foo")); try expect(y0.C == {}); @@ -1057,10 +1067,11 @@ test "type coercion of pointer to anon struct literal to pointer to struct" { fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = &.{ .A = 123, .B = "foo", .C = {} }; const t1 = &.{ .A = y, .B = "foo", .C = {} }; const y0: *const S2 = t0; - var y1: *const S2 = t1; + const y1: *const S2 = t1; try expect(y0.A == 123); try expect(std.mem.eql(u8, y0.B, "foo")); try expect(y0.C == {}); @@ -1161,8 +1172,8 @@ test "anon init through error unions and optionals" { } fn doTheTest() !void { - var a = try (try foo()).?; - var b = try bar().?; + const a = try (try foo()).?; + const b = try bar().?; try expect(a.a + b[1] == 3); } }; @@ -1227,8 +1238,8 @@ test "typed init through error unions and optionals" { } fn doTheTest() !void { - var a = try (try foo()).?; - var b = try bar().?; + const a = try (try foo()).?; + const b = try bar().?; try expect(a.a + b[1] == 3); } }; @@ -1243,6 +1254,7 @@ test "initialize struct with empty literal" { const S = struct { x: i32 = 1234 }; var s: S = .{}; + _ = &s; try expect(s.x == 1234); } @@ -1301,10 +1313,10 @@ test "packed struct field access via pointer" { fn doTheTest() !void { const S = packed struct { a: u30 }; var s1: S = .{ .a = 1 }; - var s2 = &s1; + const s2 = &s1; try expect(s2.a == 1); var s3: S = undefined; - var s4 = &s3; + const s4 = &s3; _ = s4; } }; @@ -1343,6 +1355,7 @@ test "struct field init value is size of the struct" { }; }; var s: namespace.S = .{ .blah = 1234 }; + _ = &s; try expect(s.size == 4); } @@ -1362,6 +1375,7 @@ test "under-aligned struct field" { data: U align(4), }; var runtime: usize = 1234; + _ = &runtime; const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } }; const array = @as(*const [12]u8, @ptrCast(ptr)); const result = std.mem.readInt(u64, array[4..12], native_endian); @@ -1509,6 +1523,7 @@ test "function pointer in struct returns the struct" { } }; var a = A.f(); + _ = &a; try expect(a.f == A.f); } @@ -1538,7 +1553,8 @@ test "optional field init with tuple" { a: ?struct { b: u32 }, }; var a: u32 = 0; - var b = S{ + _ = &a; + const b = S{ .a = .{ .b = a }, }; try expect(b.a.?.b == a); @@ -1550,7 +1566,8 @@ test "if inside struct init inside if" { const MyStruct = struct { x: u32 }; const b: u32 = 5; var i: u32 = 1; - var my_var = if (i < 5) + _ = &i; + const my_var = if (i < 5) MyStruct{ .x = 1 + if (i > 0) b else 0, } @@ -1599,7 +1616,7 @@ test "instantiate struct with comptime field" { var things = struct { comptime foo: i8 = 1, }{}; - + _ = &things; comptime std.debug.assert(things.foo == 1); } @@ -1608,7 +1625,7 @@ test "instantiate struct with comptime field" { comptime foo: i8 = 1, }; var things = T{}; - + _ = &things; comptime std.debug.assert(things.foo == 1); } @@ -1616,7 +1633,7 @@ test "instantiate struct with comptime field" { var things: struct { comptime foo: i8 = 1, } = .{}; - + _ = &things; comptime std.debug.assert(things.foo == 1); } @@ -1624,7 +1641,7 @@ test "instantiate struct with comptime field" { var things: struct { comptime foo: i8 = 1, } = undefined; // Segmentation fault at address 0x0 - + _ = &things; comptime std.debug.assert(things.foo == 1); } } @@ -1755,6 +1772,7 @@ test "runtime side-effects in comptime-known struct init" { test "pointer to struct initialized through reference to anonymous initializer provides result types" { const S = struct { a: u8, b: u16, c: *const anyopaque }; var my_u16: u16 = 0xABCD; + _ = &my_u16; const s: *const S = &.{ // intentionally out of order .c = @ptrCast("hello"), @@ -1792,6 +1810,7 @@ test "initializer uses own alignment" { }; var s: S = .{}; + _ = &s; try expectEqual(4, @alignOf(S)); try expectEqual(@as(usize, 5), s.x); } @@ -1802,6 +1821,7 @@ test "initializer uses own size" { }; var s: S = .{}; + _ = &s; try expectEqual(4, @sizeOf(S)); try expectEqual(@as(usize, 5), s.x); } @@ -1815,6 +1835,7 @@ test "initializer takes a pointer to a variable inside its struct" { fn doTheTest() !void { var foo: S = .{}; + _ = &foo; try expectEqual(&S.instance, foo.s); } }; @@ -1839,6 +1860,7 @@ test "circular dependency through pointer field of a struct" { }; }; var outer: S.StructOuter = .{}; + _ = &outer; try expect(outer.middle.outer == null); try expect(outer.middle.inner == null); } @@ -1855,5 +1877,6 @@ test "field calls do not force struct field init resolution" { } }; var s: S = .{}; + _ = &s; try expect(s.x == 123); } diff --git a/test/behavior/struct_contains_null_ptr_itself.zig b/test/behavior/struct_contains_null_ptr_itself.zig index 7f0182af223a01c7a172bfc374e8a99dba2bf99b..d0cb3ef443049747edd66ea9c3282e60d8887f7c 100644 --- a/test/behavior/struct_contains_null_ptr_itself.zig +++ b/test/behavior/struct_contains_null_ptr_itself.zig @@ -7,6 +7,7 @@ test "struct contains null pointer which contains original struct" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: ?*NodeLineComment = null; + _ = &x; try expect(x == null); } diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig index 37cf8b7c6f01ed532edc7fdf70dc85d5998396a4..ae4923609fb4dcf2e12ab7856673f838f2f52973 100644 --- a/test/behavior/switch.zig +++ b/test/behavior/switch.zig @@ -157,6 +157,7 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool { test "u0" { var val: u0 = 0; + _ = &val; switch (val) { 0 => try expect(val == 0), } @@ -164,6 +165,7 @@ test "u0" { test "undefined.u0" { var val: u0 = undefined; + _ = &val; switch (val) { 0 => try expect(val == 0), } @@ -173,6 +175,7 @@ test "switch with disjoint range" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var q: u8 = 0; + _ = &q; switch (q) { 0...125 => {}, 127...255 => {}, @@ -183,12 +186,8 @@ test "switch with disjoint range" { test "switch variable for range and multiple prongs" { const S = struct { fn doTheTest() !void { - var u: u8 = 16; - try doTheSwitch(u); - try comptime doTheSwitch(u); - var v: u8 = 42; - try doTheSwitch(v); - try comptime doTheSwitch(v); + try doTheSwitch(16); + try doTheSwitch(42); } fn doTheSwitch(q: u8) !void { switch (q) { @@ -198,7 +197,8 @@ test "switch variable for range and multiple prongs" { } } }; - _ = S; + try S.doTheTest(); + try comptime S.doTheTest(); } var state: u32 = 0; @@ -322,7 +322,8 @@ test "switch on union with some prongs capturing" { }; var x: X = X{ .b = 10 }; - var y: i32 = switch (x) { + _ = &x; + const y: i32 = switch (x) { .a => unreachable, .b => |b| b + 1, }; @@ -357,6 +358,7 @@ test "anon enum literal used in switch on union enum" { }; var foo = Foo{ .a = 1234 }; + _ = &foo; switch (foo) { .a => |x| { try expect(x == 1234); @@ -406,6 +408,7 @@ test "switch on integer with else capturing expr" { const S = struct { fn doTheTest() !void { var x: i32 = 5; + _ = &x; switch (x + 10) { 14 => @panic("fail"), 16 => @panic("fail"), @@ -606,6 +609,7 @@ test "switch on error set with single else" { const S = struct { fn doTheTest() !void { var some: error{Foo} = error.Foo; + _ = &some; try expect(switch (some) { else => blk: { break :blk true; @@ -672,7 +676,8 @@ test "enum value without tag name used as switch item" { b = 2, _, }; - var e: E = @as(E, @enumFromInt(0)); + var e: E = @enumFromInt(0); + _ = &e; switch (e) { @as(E, @enumFromInt(0)) => {}, .a => return error.TestFailed, @@ -685,6 +690,7 @@ test "switch item sizeof" { const S = struct { fn doTheTest() !void { var a: usize = 0; + _ = &a; switch (a) { @sizeOf(struct {}) => {}, else => return error.TestFailed, @@ -699,6 +705,7 @@ test "comptime inline switch" { const U = union(enum) { a: type, b: type }; const value = comptime blk: { var u: U = .{ .a = u32 }; + _ = &u; break :blk switch (u) { inline .a, .b => |v| v, }; @@ -814,6 +821,7 @@ test "peer type resolution on switch captures ignores unused payload bits" { // This is runtime-known so the following store isn't comptime-known. var rt: u32 = 123; + _ = &rt; val = .{ .a = rt }; // will not necessarily zero remaning payload memory // Fields intentionally backwards here diff --git a/test/behavior/truncate.zig b/test/behavior/truncate.zig index 4fc095b66c427cd20492ec5d21b43e1f1468554f..3d128b76561a782a6c26a892d5453c9958bbba70 100644 --- a/test/behavior/truncate.zig +++ b/test/behavior/truncate.zig @@ -4,58 +4,62 @@ const expect = std.testing.expect; test "truncate u0 to larger integer allowed and has comptime-known result" { var x: u0 = 0; + _ = &x; const y = @as(u8, @truncate(x)); try comptime expect(y == 0); } test "truncate.u0.literal" { - var z = @as(u0, @truncate(0)); + const z: u0 = @truncate(0); try expect(z == 0); } test "truncate.u0.const" { const c0: usize = 0; - var z = @as(u0, @truncate(c0)); + const z: u0 = @truncate(c0); try expect(z == 0); } test "truncate.u0.var" { var d: u8 = 2; - var z = @as(u0, @truncate(d)); + _ = &d; + const z: u0 = @truncate(d); try expect(z == 0); } test "truncate i0 to larger integer allowed and has comptime-known result" { var x: i0 = 0; - const y = @as(i8, @truncate(x)); + _ = &x; + const y: i8 = @truncate(x); try comptime expect(y == 0); } test "truncate.i0.literal" { - var z = @as(i0, @truncate(0)); + const z: i0 = @truncate(0); try expect(z == 0); } test "truncate.i0.const" { const c0: isize = 0; - var z = @as(i0, @truncate(c0)); + const z: i0 = @truncate(c0); try expect(z == 0); } test "truncate.i0.var" { var d: i8 = 2; - var z = @as(i0, @truncate(d)); + _ = &d; + const z: i0 = @truncate(d); try expect(z == 0); } test "truncate on comptime integer" { - var x = @as(u16, @truncate(9999)); + const x: u16 = @truncate(9999); try expect(x == 9999); - var y = @as(u16, @truncate(-21555)); + const y: u16 = @truncate(-21555); try expect(y == 0xabcd); - var z = @as(i16, @truncate(-65537)); + const z: i16 = @truncate(-65537); try expect(z == -1); - var w = @as(u1, @truncate(1 << 100)); + const w: u1 = @truncate(1 << 100); try expect(w == 0); } @@ -69,7 +73,8 @@ test "truncate on vectors" { const S = struct { fn doTheTest() !void { var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 }; - var v2: @Vector(4, u8) = @truncate(v1); + _ = &v1; + const v2: @Vector(4, u8) = @truncate(v1); try expect(std.mem.eql(u8, &@as([4]u8, v2), &[4]u8{ 0xbb, 0xdd, 0xff, 0x22 })); } }; diff --git a/test/behavior/tuple.zig b/test/behavior/tuple.zig index 63e2cde46edb12b172f4dadc49682aea3854a9be..039a96d29fe57ce0f61bf8decbac37dd982b8115 100644 --- a/test/behavior/tuple.zig +++ b/test/behavior/tuple.zig @@ -15,9 +15,10 @@ test "tuple concatenation" { fn doTheTest() !void { var a: i32 = 1; var b: i32 = 2; - var x = .{a}; - var y = .{b}; - var c = x ++ y; + _ = .{ &a, &b }; + const x = .{a}; + const y = .{b}; + const c = x ++ y; try expect(@as(i32, 1) == c[0]); try expect(@as(i32, 2) == c[1]); } @@ -119,7 +120,7 @@ test "tuple initializer for var" { .id = @as(usize, 2), .name = Bytes{ .id = 20 }, }; - _ = tmp; + _ = &tmp; } }; @@ -157,6 +158,7 @@ test "array-like initializer for tuple types" { const S = struct { fn doTheTest() !void { var obj: T = .{ -1234, 128 }; + _ = &obj; try expect(@as(i32, -1234) == obj[0]); try expect(@as(u8, 128) == obj[1]); } @@ -171,6 +173,7 @@ test "anon struct as the result from a labeled block" { fn doTheTest() !void { const precomputed = comptime blk: { var x: i32 = 1234; + _ = &x; break :blk .{ .x = x, }; @@ -188,6 +191,7 @@ test "tuple as the result from a labeled block" { fn doTheTest() !void { const precomputed = comptime blk: { var x: i32 = 1234; + _ = &x; break :blk .{x}; }; try expect(precomputed[0] == 1234); @@ -201,13 +205,13 @@ test "tuple as the result from a labeled block" { test "initializing tuple with explicit type" { const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); var a = T{ 0, 0 }; - _ = a; + _ = &a; } test "initializing anon struct with explicit type" { const T = @TypeOf(.{ .foo = @as(i32, 1), .bar = @as(i32, 2) }); var a = T{ .foo = 1, .bar = 2 }; - _ = a; + _ = &a; } test "fieldParentPtr of tuple" { @@ -216,6 +220,7 @@ test "fieldParentPtr of tuple" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 0; + _ = &x; const tuple = .{ x, x }; try testing.expect(&tuple == @fieldParentPtr(@TypeOf(tuple), "1", &tuple[1])); } @@ -226,18 +231,21 @@ test "fieldParentPtr of anon struct" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 0; + _ = &x; const anon_st = .{ .foo = x, .bar = x }; try testing.expect(&anon_st == @fieldParentPtr(@TypeOf(anon_st), "bar", &anon_st.bar)); } test "offsetOf tuple" { var x: u32 = 0; + _ = &x; const T = @TypeOf(.{ x, x }); try expect(@offsetOf(T, "1") == @sizeOf(u32)); } test "offsetOf anon struct" { var x: u32 = 0; + _ = &x; const T = @TypeOf(.{ .foo = x, .bar = x }); try expect(@offsetOf(T, "bar") == @sizeOf(u32)); } @@ -247,8 +255,10 @@ test "initializing tuple with mixed comptime-runtime fields" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u32 = 15; + _ = &x; const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); var a: T = .{ -1234, 5678, x + 1 }; + _ = &a; try expect(a[2] == 16); } @@ -257,8 +267,10 @@ test "initializing anon struct with mixed comptime-runtime fields" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u32 = 15; + _ = &x; const T = @TypeOf(.{ .foo = @as(i32, -1234), .bar = x }); var a: T = .{ .foo = -1234, .bar = x + 1 }; + _ = &a; try expect(a.bar == 16); } @@ -338,6 +350,7 @@ test "tuple type with void field and a runtime field" { const T = std.meta.Tuple(&[_]type{ usize, void }); var t: T = .{ 5, {} }; + _ = &t; try expect(t[0] == 5); } @@ -352,6 +365,7 @@ test "branching inside tuple literal" { } }; var a = false; + _ = &a; try S.foo(.{if (a) @as(u32, 5678) else @as(u32, 1234)}); } @@ -363,6 +377,7 @@ test "tuple initialized with a runtime known value" { const E = union(enum) { e: []const u8 }; const W = union(enum) { w: E }; var e = E{ .e = "test" }; + _ = &e; const w = .{W{ .w = e }}; try expectEqualStrings(w[0].w.e, "test"); } @@ -388,6 +403,7 @@ test "nested runtime conditionals in tuple initializer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var data: u8 = 0; + _ = &data; const x = .{ if (data != 0) "" else switch (@as(u1, @truncate(data))) { 0 => "up", @@ -446,8 +462,9 @@ test "coerce anon tuple to tuple" { var x: u8 = 1; var y: u16 = 2; - var t = .{ x, y }; - var s: struct { u8, u16 } = t; + _ = .{ &x, &y }; + const t = .{ x, y }; + const s: struct { u8, u16 } = t; try expectEqual(x, s[0]); try expectEqual(y, s[1]); } diff --git a/test/behavior/tuple_declarations.zig b/test/behavior/tuple_declarations.zig index 8ffc25613d28a7c1fd31d78d25fdd9d8a1f7ffee..e3730b39953b98fcfe173be6ad23a3c18cf1eec8 100644 --- a/test/behavior/tuple_declarations.zig +++ b/test/behavior/tuple_declarations.zig @@ -38,17 +38,19 @@ test "Tuple declaration usage" { const T = struct { u32, []const u8 }; var t: T = .{ 1, "foo" }; + _ = &t; try expect(t[0] == 1); try expectEqualStrings(t[1], "foo"); - var mul = t ** 3; + const mul = t ** 3; try expect(@TypeOf(mul) != T); try expect(mul.len == 6); try expect(mul[2] == 1); try expectEqualStrings(mul[3], "foo"); var t2: T = .{ 2, "bar" }; - var cat = t ++ t2; + _ = &t2; + const cat = t ++ t2; try expect(@TypeOf(cat) != T); try expect(cat.len == 4); try expect(cat[2] == 2); diff --git a/test/behavior/type.zig b/test/behavior/type.zig index 7d0147c508090f8918d7d803d178840667f418aa..64c4c856693c4be7132dab7d228aa2d13abccfb0 100644 --- a/test/behavior/type.zig +++ b/test/behavior/type.zig @@ -410,7 +410,8 @@ test "Type.Union" { .decls = &.{}, }, }); - var packed_untagged = PackedUntagged{ .signed = -1 }; + var packed_untagged: PackedUntagged = .{ .signed = -1 }; + _ = &packed_untagged; try testing.expectEqual(@as(i32, -1), packed_untagged.signed); try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned); @@ -529,7 +530,7 @@ test "reified struct field name from optional payload" { .decls = &.{}, .is_tuple = false, } }); - var t: T = .{ .a = 123 }; + const t: T = .{ .a = 123 }; try std.testing.expect(t.a == 123); } } diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig index bc4737a5524b4fc0a6beffb5382d4b129fba4f5d..63f2ecb30f77886a9016257924bc8b5f53b07b82 100644 --- a/test/behavior/type_info.zig +++ b/test/behavior/type_info.zig @@ -417,7 +417,7 @@ test "typeInfo with comptime parameter in struct fn def" { } }; comptime var info = @typeInfo(S); - _ = info; + _ = &info; } test "type info: vectors" { diff --git a/test/behavior/union.zig b/test/behavior/union.zig index 338db4703632da9d84fba35b950c1eb74ddeeda6..804cea47f8142434bbbc120720344c2b4c203346 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -171,6 +171,7 @@ test "constant tagged union with payload" { var empty = TaggedUnionWithPayload{ .Empty = {} }; var full = TaggedUnionWithPayload{ .Full = 13 }; + _ = .{ &empty, &full }; shouldBeEmpty(empty); shouldBeNotEmpty(full); } @@ -254,6 +255,7 @@ fn bar(value: Payload) error{TestUnexpectedResult}!i32 { fn testComparison() !void { var x = Payload{ .A = 42 }; + _ = &x; try expect(x == .A); try expect(x != .B); try expect(x != .C); @@ -288,6 +290,7 @@ test "cast union to tag type of union" { fn testCastUnionToTag() !void { var u = TheUnion{ .B = 1234 }; + _ = &u; try expect(@as(TheTag, u) == TheTag.B); } @@ -303,6 +306,7 @@ test "cast tag type of union to union" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: Value2 = Letter2.B; + _ = &x; try expect(@as(Letter2, x) == Letter2.B); } const Letter2 = enum { A, B, C }; @@ -318,6 +322,7 @@ test "implicit cast union to its tag type" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: Value2 = Letter2.B; + _ = &x; try expect(x == Letter2.B); try giveMeLetterB(x); } @@ -356,6 +361,7 @@ test "simple union(enum(u32))" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x = MultipleChoice.C; + _ = &x; try expect(x == MultipleChoice.C); try expect(@intFromEnum(@as(Tag(MultipleChoice), x)) == 60); } @@ -420,9 +426,11 @@ test "union with only 1 field casted to its enum type" { }; var e = Expr{ .Literal = Literal{ .Bool = true } }; + _ = &e; const ExprTag = Tag(Expr); try comptime expect(Tag(ExprTag) == u0); var t = @as(ExprTag, e); + _ = &t; try expect(t == Expr.Literal); } @@ -494,6 +502,7 @@ test "union initializer generates padding only if needed" { }; var v = U{ .A = 532 }; + _ = &v; try expect(v.A == 532); } @@ -506,6 +515,7 @@ test "runtime tag name with single field" { }; var v = U{ .A = 42 }; + _ = &v; try expect(std.mem.eql(u8, @tagName(v), "A")); } @@ -698,8 +708,9 @@ test "union with only 1 field casted to its enum type which has enum value speci }; var e = Expr{ .Literal = Literal{ .Bool = true } }; + _ = &e; try comptime expect(Tag(ExprTag) == comptime_int); - comptime var t = @as(ExprTag, e); + const t = comptime @as(ExprTag, e); try expect(t == Expr.Literal); try expect(@intFromEnum(t) == 33); try comptime expect(@intFromEnum(t) == 33); @@ -719,6 +730,7 @@ test "@intFromEnum works on unions" { const a = Bar{ .A = true }; var b = Bar{ .B = undefined }; var c = Bar.C; + _ = .{ &b, &c }; try expect(@intFromEnum(a) == 0); try expect(@intFromEnum(b) == 1); try expect(@intFromEnum(c) == 2); @@ -800,11 +812,13 @@ test "@unionInit stored to a const" { fn doTheTest() !void { { var t = true; + _ = &t; const u = @unionInit(U, "boolean", t); try expect(u.boolean); } { var byte: u8 = 69; + _ = &byte; const u = @unionInit(U, "byte", byte); try expect(u.byte == 69); } @@ -849,7 +863,7 @@ test "@unionInit can modify a pointer value" { }; var value: UnionInitEnum = undefined; - var value_ptr = &value; + const value_ptr = &value; value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true); try expect(value.Boolean == true); @@ -906,7 +920,8 @@ test "anonymous union literal syntax" { fn doTheTest() !void { var i: Number = .{ .int = 42 }; - var f = makeNumber(); + _ = &i; + const f = makeNumber(); try expect(i.int == 42); try expect(f.float == 12.34); } @@ -934,9 +949,11 @@ test "function call result coerces from tagged union to the tag" { fn doTheTest() !void { var x: ArchTag = getArch1(); + _ = &x; try expect(x == .One); var y: ArchTag = getArch2(); + _ = &y; try expect(y == .Two); } @@ -965,14 +982,17 @@ test "cast from anonymous struct to union" { }; fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = .{ .A = 123 }; const t1 = .{ .B = "foo" }; const t2 = .{ .C = {} }; const t3 = .{ .A = y }; const x0: U = t0; var x1: U = t1; + _ = &x1; const x2: U = t2; var x3: U = t3; + _ = &x3; try expect(x0.A == 123); try expect(std.mem.eql(u8, x1.B, "foo")); try expect(x2 == .C); @@ -996,14 +1016,17 @@ test "cast from pointer to anonymous struct to pointer to union" { }; fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = &.{ .A = 123 }; const t1 = &.{ .B = "foo" }; const t2 = &.{ .C = {} }; const t3 = &.{ .A = y }; const x0: *const U = t0; var x1: *const U = t1; + _ = &x1; const x2: *const U = t2; var x3: *const U = t3; + _ = &x3; try expect(x0.A == 123); try expect(std.mem.eql(u8, x1.B, "foo")); try expect(x2.* == .C); @@ -1031,6 +1054,7 @@ test "switching on non exhaustive union" { }; fn doTheTest() !void { var a = U{ .a = 2 }; + _ = &a; switch (a) { .a => |val| try expect(val == 2), .b => return error.Fail, @@ -1055,11 +1079,13 @@ test "containers with single-field enums" { fn doTheTest() !void { var array1 = [1]A{A{ .f1 = {} }}; var array2 = [1]B{B{ .f1 = {} }}; + _ = .{ &array1, &array2 }; try expect(array1[0] == .f1); try expect(array2[0] == .f1); var struct1 = C{ .a = A{ .f1 = {} } }; var struct2 = D{ .a = B{ .f1 = {} } }; + _ = .{ &struct1, &struct2 }; try expect(struct1.a == .f1); try expect(struct2.a == .f1); } @@ -1092,8 +1118,9 @@ test "@unionInit on union with tag but no fields" { fn doTheTest() !void { var data: Data = .{ .no_op = {} }; - _ = data; + _ = &data; var o = Data.decode(&[_]u8{}); + _ = &o; try expectEqual(Type.no_op, o); } }; @@ -1156,6 +1183,7 @@ test "union with no result loc initiated with a runtime value" { } }; var a: u32 = 1; + _ = &a; U.foo(U{ .a = a }); } @@ -1174,6 +1202,7 @@ test "union with a large struct field" { fn foo(_: @This()) void {} }; var s: S = undefined; + _ = &s; U.foo(U{ .s = s }); } @@ -1207,6 +1236,7 @@ test "union tag is set when initiated as a temporary value at runtime" { } }; var b: u32 = 1; + _ = &b; try (U{ .b = b }).doTheTest(); } @@ -1226,6 +1256,7 @@ test "extern union most-aligned field is smaller" { un: [110]u8, }; var a: ?U = .{ .un = [_]u8{0} ** 110 }; + _ = &a; try expect(a != null); } @@ -1246,6 +1277,7 @@ test "return an extern union from C calling convention" { fn bar(arg_u: U) callconv(.C) U { var u = arg_u; + _ = &u; return u; } }; @@ -1324,13 +1356,16 @@ test "@unionInit uses tag value instead of field index" { a: usize, }; var i: isize = -1; + _ = &i; var u = @unionInit(U, "b", i); { var a = u.b; + _ = &a; try expect(a == i); } { var a = &u.b; + _ = &a; try expect(a.* == i); } try expect(@intFromEnum(u) == 255); @@ -1508,7 +1543,7 @@ test "coerce enum literal to union in result loc" { b: u8, fn doTest(c: bool) !void { - var u = if (c) .a else @This(){ .b = 0 }; + const u = if (c) .a else @This(){ .b = 0 }; try expect(u == .a); } }; @@ -1947,6 +1982,7 @@ test "packed union initialized via reintepreted struct field initializer" { }; var s: S = .{}; + _ = &s; try expect(s.u.a == littleToNativeEndian(u32, 0xddccbbaa)); try expect(s.u.b == if (endian == .little) 0xaa else 0xdd); } @@ -1966,6 +2002,7 @@ test "store of comptime reinterpreted memory to extern union" { }; var u: U = reinterpreted; + _ = &u; try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); try expect(u.b == 0xaa); } @@ -1985,6 +2022,7 @@ test "store of comptime reinterpreted memory to packed union" { }; var u: U = reinterpreted; + _ = &u; try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); try expect(u.b == if (endian == .little) 0xaa else 0xdd); } @@ -2018,6 +2056,7 @@ test "pass register-sized field as non-register-sized union" { }; var x: usize = 42; + _ = &x; try S.taggedUnion(.{ .x = x }); try S.untaggedUnion(.{ .x = x }); try S.externUnion(.{ .x = x }); @@ -2039,6 +2078,7 @@ test "circular dependency through pointer field of a union" { }; }; var outer: S.UnionOuter = .{}; + _ = &outer; try expect(outer.u.outer == null); try expect(outer.u.inner == null); } @@ -2057,5 +2097,6 @@ test "pass nested union with rls" { }; var c: u7 = 32; + _ = &c; try expectEqual(@as(u7, 32), Union.getC(.{ .b = .{ .c = c } })); } diff --git a/test/behavior/var_args.zig b/test/behavior/var_args.zig index 7fda8b208aabee787140bbd8a381830cbdb0b4a7..b0dccc1383be5cd607f29765b93537c0b4e9eb4a 100644 --- a/test/behavior/var_args.zig +++ b/test/behavior/var_args.zig @@ -147,6 +147,7 @@ test "simple variadic function" { var runtime: bool = true; var a: i32 = 1; var b: i32 = 2; + _ = .{ &runtime, &a, &b }; try expect(1 == S.add(1, if (runtime) a else b)); } } diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig index a1b9a4f66e56be1d4c3dfb354a07dca48a1003fb..a9569d1b1b8d2ffa9c97bbbb443fc5fa45f201d0 100644 --- a/test/behavior/vector.zig +++ b/test/behavior/vector.zig @@ -40,6 +40,7 @@ test "vector wrap operators" { try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 })); var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; try expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 })); + _ = .{ &v, &x, &z }; } }; try S.doTheTest(); @@ -57,6 +58,7 @@ test "vector bin compares with mem.eql" { fn doTheTest() !void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; + _ = .{ &v, &x }; try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false })); try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true })); try expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false })); @@ -81,6 +83,7 @@ test "vector int operators" { fn doTheTest() !void { var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; + _ = .{ &v, &x }; try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 })); try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 })); try expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 })); @@ -105,6 +108,7 @@ test "vector float operators" { fn doTheTest() !void { var v: @Vector(4, T) = [4]T{ 10, 20, 30, 40 }; var x: @Vector(4, T) = [4]T{ 1, 2, 3, 4 }; + _ = .{ &v, &x }; try expect(mem.eql(T, &@as([4]T, v + x), &[4]T{ 11, 22, 33, 44 })); try expect(mem.eql(T, &@as([4]T, v - x), &[4]T{ 9, 18, 27, 36 })); try expect(mem.eql(T, &@as([4]T, v * x), &[4]T{ 10, 40, 90, 160 })); @@ -126,6 +130,7 @@ test "vector bit operators" { fn doTheTest() !void { var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; + _ = .{ &v, &x }; try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); try expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); @@ -143,6 +148,7 @@ test "implicit cast vector to array" { const S = struct { fn doTheTest() !void { var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; + _ = &a; var result_array: [4]i32 = a; result_array = a; try expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 })); @@ -160,8 +166,9 @@ test "array to vector" { const S = struct { fn doTheTest() !void { var foo: f32 = 3.14; - var arr = [4]f32{ foo, 1.5, 0.0, 0.0 }; - var vec: @Vector(4, f32) = arr; + _ = &foo; + const arr = [4]f32{ foo, 1.5, 0.0, 0.0 }; + const vec: @Vector(4, f32) = arr; try expect(mem.eql(f32, &@as([4]f32, vec), &arr)); } }; @@ -180,25 +187,28 @@ test "array vector coercion - odd sizes" { const S = struct { fn doTheTest() !void { var foo1: i48 = 124578; - var vec1: @Vector(2, i48) = [2]i48{ foo1, 1 }; - var arr1: [2]i48 = vec1; + _ = &foo1; + const vec1: @Vector(2, i48) = [2]i48{ foo1, 1 }; + const arr1: [2]i48 = vec1; try expect(vec1[0] == foo1 and vec1[1] == 1); try expect(arr1[0] == foo1 and arr1[1] == 1); var foo2: u4 = 5; - var vec2: @Vector(2, u4) = [2]u4{ foo2, 1 }; - var arr2: [2]u4 = vec2; + _ = &foo2; + const vec2: @Vector(2, u4) = [2]u4{ foo2, 1 }; + const arr2: [2]u4 = vec2; try expect(vec2[0] == foo2 and vec2[1] == 1); try expect(arr2[0] == foo2 and arr2[1] == 1); var foo3: u13 = 13; - var vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 }; - var arr3: [3]u13 = vec3; + _ = &foo3; + const vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 }; + const arr3: [3]u13 = vec3; try expect(vec3[0] == foo3 and vec3[1] == 0 and vec3[2] == 1); try expect(arr3[0] == foo3 and arr3[1] == 0 and arr3[2] == 1); - var arr4 = [4:0]u24{ foo3, foo2, 0, 1 }; - var vec4: @Vector(4, u24) = arr4; + const arr4 = [4:0]u24{ foo3, foo2, 0, 1 }; + const vec4: @Vector(4, u24) = arr4; try expect(vec4[0] == foo3 and vec4[1] == foo2 and vec4[2] == 0 and vec4[3] == 1); } }; @@ -217,8 +227,9 @@ test "array to vector with element type coercion" { const S = struct { fn doTheTest() !void { var foo: f16 = 3.14; - var arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 }; - var vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 }; + _ = &foo; + const arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 }; + const vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 }; try std.testing.expect(std.mem.eql(f32, &@as([4]f32, vec), &arr32)); } }; @@ -237,7 +248,8 @@ test "peer type resolution with coercible element types" { var b: @Vector(2, u8) = .{ 1, 2 }; var a: @Vector(2, u16) = .{ 2, 1 }; var t: bool = true; - var c = if (t) a else b; + _ = .{ &a, &b, &t }; + const c = if (t) a else b; try std.testing.expect(@TypeOf(c) == @Vector(2, u16)); } }; @@ -285,22 +297,26 @@ test "vector casts of sizes not divisible by 8" { fn doTheTest() !void { { var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; - var x: [4]u3 = v; + _ = &v; + const x: [4]u3 = v; try expect(mem.eql(u3, &x, &@as([4]u3, v))); } { var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; - var x: [4]u2 = v; + _ = &v; + const x: [4]u2 = v; try expect(mem.eql(u2, &x, &@as([4]u2, v))); } { var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; - var x: [4]u1 = v; + _ = &v; + const x: [4]u1 = v; try expect(mem.eql(u1, &x, &@as([4]u1, v))); } { var v: @Vector(4, bool) = [4]bool{ false, false, true, false }; - var x: [4]bool = v; + _ = &v; + const x: [4]bool = v; try expect(mem.eql(bool, &x, &@as([4]bool, v))); } } @@ -327,7 +343,8 @@ test "vector @splat" { fn testForT(comptime N: comptime_int, v: anytype) !void { const T = @TypeOf(v); var vec: @Vector(N, T) = @splat(v); - var as_array = @as([N]T, vec); + _ = &vec; + const as_array = @as([N]T, vec); for (as_array) |elem| try expect(v == elem); } fn doTheTest() !void { @@ -412,6 +429,7 @@ test "load vector elements via runtime index" { const S = struct { fn doTheTest() !void { var v: @Vector(4, i32) = [_]i32{ 1, 2, 3, undefined }; + _ = &v; var i: u32 = 0; try expect(v[i] == 1); i += 1; @@ -461,7 +479,7 @@ test "initialize vector which is a struct field" { var foo = Vec4Obj{ .data = [_]f32{ 1, 2, 3, 4 }, }; - _ = foo; + _ = &foo; } }; try S.doTheTest(); @@ -481,6 +499,7 @@ test "vector comparison operators" { const V = @Vector(4, bool); var v1: V = [_]bool{ true, false, true, false }; var v2: V = [_]bool{ false, true, false, true }; + _ = .{ &v1, &v2 }; try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v1))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v2))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v2))); @@ -491,6 +510,7 @@ test "vector comparison operators" { var v1: @Vector(4, u32) = @splat(0xc0ffeeee); var v2: @Vector(4, c_uint) = v1; var v3: @Vector(4, u32) = @splat(0xdeadbeef); + _ = .{ &v1, &v2, &v3 }; try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v2))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v3))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v3))); @@ -499,6 +519,7 @@ test "vector comparison operators" { { // Comptime-known LHS/RHS var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 }; + _ = &v1; const v2: @Vector(4, u32) = @splat(2); const v3: @Vector(4, bool) = [_]bool{ true, false, true, false }; try expect(mem.eql(bool, &@as([4]bool, v3), &@as([4]bool, v1 == v2))); @@ -604,7 +625,7 @@ test "vector bitwise not operator" { const S = struct { fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void { - var y = ~x; + const y = ~x; for (@as([4]T, y), 0..) |v, i| { try expect(~x[i] == v); } @@ -640,14 +661,14 @@ test "vector shift operators" { const TX = @typeInfo(@TypeOf(x)).Array.child; const TY = @typeInfo(@TypeOf(y)).Array.child; - var xv = @as(@Vector(N, TX), x); - var yv = @as(@Vector(N, TY), y); + const xv = @as(@Vector(N, TX), x); + const yv = @as(@Vector(N, TY), y); - var z0 = xv >> yv; + const z0 = xv >> yv; for (@as([N]TX, z0), 0..) |v, i| { try expect(x[i] >> y[i] == v); } - var z1 = xv << yv; + const z1 = xv << yv; for (@as([N]TX, z1), 0..) |v, i| { try expect(x[i] << y[i] == v); } @@ -657,10 +678,10 @@ test "vector shift operators" { const TX = @typeInfo(@TypeOf(x)).Array.child; const TY = @typeInfo(@TypeOf(y)).Array.child; - var xv = @as(@Vector(N, TX), x); - var yv = @as(@Vector(N, TY), y); + const xv = @as(@Vector(N, TX), x); + const yv = @as(@Vector(N, TY), y); - var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv); + const z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv); for (@as([N]TX, z), 0..) |v, i| { const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i]; try expect(check == v); @@ -734,7 +755,7 @@ test "vector reduce operation" { const N = @typeInfo(@TypeOf(x)).Array.len; const TX = @typeInfo(@TypeOf(x)).Array.child; - var r = @reduce(op, @as(@Vector(N, TX), x)); + const r = @reduce(op, @as(@Vector(N, TX), x)); switch (@typeInfo(TX)) { .Int, .Bool => try expect(expected == r), .Float => { @@ -892,7 +913,8 @@ test "mask parameter of @shuffle is comptime scope" { const __v4hi = @Vector(4, i16); var v4_a = __v4hi{ 0, 0, 0, 0 }; var v4_b = __v4hi{ 0, 0, 0, 0 }; - var shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){ + _ = .{ &v4_a, &v4_b }; + const shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){ std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), @@ -915,7 +937,8 @@ test "saturating add" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 255, 254, 1 }; var rhs = u8x3{ 1, 2, 255 }; - var result = lhs +| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs +| rhs; const expected = u8x3{ 255, 255, 255 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -923,7 +946,8 @@ test "saturating add" { const i8x3 = @Vector(3, i8); var lhs = i8x3{ 127, 126, 1 }; var rhs = i8x3{ 1, 2, 127 }; - var result = lhs +| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs +| rhs; const expected = i8x3{ 127, 127, 127 }; try expect(mem.eql(i8, &@as([3]i8, expected), &@as([3]i8, result))); } @@ -947,7 +971,8 @@ test "saturating subtraction" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 0, 0, 0 }; var rhs = u8x3{ 255, 255, 255 }; - var result = lhs -| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs -| rhs; const expected = u8x3{ 0, 0, 0 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -973,7 +998,8 @@ test "saturating multiplication" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 2, 2, 2 }; var rhs = u8x3{ 255, 255, 255 }; - var result = lhs *| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs *| rhs; const expected = u8x3{ 255, 255, 255 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -997,7 +1023,8 @@ test "saturating shift-left" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 1, 1, 1 }; var rhs = u8x3{ 255, 255, 255 }; - var result = lhs <<| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs <<| rhs; const expected = u8x3{ 255, 255, 255 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -1040,29 +1067,33 @@ test "@addWithOverflow" { { var lhs = @Vector(4, u8){ 250, 250, 250, 250 }; var rhs = @Vector(4, u8){ 0, 5, 6, 10 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, i8){ -125, -125, 125, 125 }; var rhs = @Vector(4, i8){ -3, -4, 2, 3 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, u1){ 0, 0, 1, 1 }; var rhs = @Vector(4, u1){ 0, 1, 0, 1 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 0, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, u0){ 0, 0, 0, 0 }; var rhs = @Vector(4, u0){ 0, 0, 0, 0 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 0, 0 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 0, 0 }; try expectEqual(expected, overflow); } } @@ -1084,15 +1115,17 @@ test "@subWithOverflow" { { var lhs = @Vector(2, u8){ 5, 5 }; var rhs = @Vector(2, u8){ 5, 6 }; - var overflow = @subWithOverflow(lhs, rhs)[1]; - var expected: @Vector(2, u1) = .{ 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @subWithOverflow(lhs, rhs)[1]; + const expected: @Vector(2, u1) = .{ 0, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, i8){ -120, -120, 120, 120 }; var rhs = @Vector(4, i8){ 8, 9, -7, -8 }; - var overflow = @subWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @subWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; try expectEqual(expected, overflow); } } @@ -1113,8 +1146,9 @@ test "@mulWithOverflow" { fn doTheTest() !void { var lhs = @Vector(4, u8){ 10, 10, 10, 10 }; var rhs = @Vector(4, u8){ 25, 26, 0, 30 }; - var overflow = @mulWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @mulWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; try expectEqual(expected, overflow); } }; @@ -1134,8 +1168,9 @@ test "@shlWithOverflow" { fn doTheTest() !void { var lhs = @Vector(4, u8){ 0, 1, 8, 255 }; var rhs = @Vector(4, u3){ 7, 7, 7, 7 }; - var overflow = @shlWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @shlWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; try expectEqual(expected, overflow); } }; @@ -1161,8 +1196,8 @@ test "loading the second vector from a slice of vectors" { @Vector(2, u8){ 0, 1 }, @Vector(2, u8){ 2, 3 }, }; - var a: []const @Vector(2, u8) = &small_bases; - var a4 = a[1][1]; + const a: []const @Vector(2, u8) = &small_bases; + const a4 = a[1][1]; try expect(a4 == 3); } @@ -1183,6 +1218,7 @@ test "array of vectors is copied" { Vec3{ -345, -311, 381 }, Vec3{ -661, -816, -575 }, }; + _ = &points; var points2: [20]Vec3 = undefined; points2[0..points.len].* = points; try std.testing.expectEqual(points2[6], Vec3{ -345, -311, 381 }); @@ -1244,6 +1280,7 @@ test "zero multiplicand" { const zeros = @Vector(2, u32){ 0.0, 0.0 }; var ones = @Vector(2, u32){ 1.0, 1.0 }; + _ = &ones; _ = (ones * zeros)[0]; _ = (zeros * zeros)[0]; @@ -1266,6 +1303,7 @@ test "@intCast to u0" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var zeros = @Vector(2, u32){ 0, 0 }; + _ = &zeros; const casted = @as(@Vector(2, u0), @intCast(zeros)); _ = casted[0]; @@ -1292,7 +1330,8 @@ test "array operands to shuffle are coerced to vectors" { const mask = [5]i32{ -1, 0, 1, 2, 3 }; var a = [5]u32{ 3, 5, 7, 9, 0 }; - var b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask); + _ = &a; + const b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask); try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b); } @@ -1320,6 +1359,7 @@ test "store packed vector element" { var v = @Vector(4, u1){ 1, 1, 1, 1 }; try expectEqual(@Vector(4, u1){ 1, 1, 1, 1 }, v); var index: usize = 0; + _ = &index; v[index] = 0; try expectEqual(@Vector(4, u1){ 0, 1, 1, 1 }, v); } @@ -1337,6 +1377,7 @@ test "store to vector in slice" { }; var s: []@Vector(3, f32) = &v; var i: usize = 1; + _ = &i; s[i] = s[0]; try expectEqual(v[1], v[0]); } @@ -1378,6 +1419,7 @@ test "store vector with memset" { var kc = @Vector(2, i4){ 2, 3 }; var kd = @Vector(2, u8){ 4, 5 }; var ke = @Vector(2, i9){ 6, 7 }; + _ = .{ &ka, &kb, &kc, &kd, &ke }; @memset(&a, ka); @memset(&b, kb); @memset(&c, kc); @@ -1410,6 +1452,7 @@ test "compare vectors with different element types" { var a: @Vector(2, u8) = .{ 1, 2 }; var b: @Vector(2, u9) = .{ 3, 0 }; + _ = .{ &a, &b }; try expectEqual(@Vector(2, bool){ true, false }, a < b); } @@ -1465,8 +1508,9 @@ test "bitcast to vector with different child type" { const VecB = @Vector(4, u32); var vec_a = VecA{ 1, 1, 1, 1, 1, 1, 1, 1 }; - var vec_b: VecB = @bitCast(vec_a); - var vec_c: VecA = @bitCast(vec_b); + _ = &vec_a; + const vec_b: VecB = @bitCast(vec_a); + const vec_c: VecA = @bitCast(vec_b); try expectEqual(vec_a, vec_c); } }; diff --git a/test/behavior/void.zig b/test/behavior/void.zig index 8c6269123d9ade29c05984eaaf2768b32d6d74ba..42c57ca3a6e5efb9646be6db3e2d64c6735906f2 100644 --- a/test/behavior/void.zig +++ b/test/behavior/void.zig @@ -38,16 +38,18 @@ test "void optional" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: ?void = {}; + _ = &x; try expect(x != null); } test "void array as a local variable initializer" { var x = [_]void{{}} ** 1004; + _ = &x[0]; _ = x[0]; } const void_constant = {}; test "reference to void constants" { var a = void_constant; - _ = a; + _ = &a; } diff --git a/test/behavior/wasm.zig b/test/behavior/wasm.zig index 11bf6cff054515a1f865a6b188136ef176e80a90..c7d12be29d2afc82861f38be9e5478c5c9863b22 100644 --- a/test/behavior/wasm.zig +++ b/test/behavior/wasm.zig @@ -4,6 +4,7 @@ const builtin = @import("builtin"); test "memory size and grow" { var prev = @wasmMemorySize(0); + _ = &prev; try expect(prev == @wasmMemoryGrow(0, 1)); try expect(prev + 1 == @wasmMemorySize(0)); } diff --git a/test/behavior/widening.zig b/test/behavior/widening.zig index f44f577dcb21114ba69b6eb903c24141a8447e91..3badb40169b184cff9a730078e6cef78a563ac8c 100644 --- a/test/behavior/widening.zig +++ b/test/behavior/widening.zig @@ -15,6 +15,7 @@ test "integer widening" { var d: u64 = c; var e: u64 = d; var f: u128 = e; + _ = .{ &a, &b, &c, &d, &e, &f }; try expect(f == a); } @@ -33,6 +34,7 @@ test "implicit unsigned integer to signed integer" { var a: u8 = 250; var b: i16 = a; + _ = .{ &a, &b }; try expect(b == 250); } @@ -47,10 +49,12 @@ test "float widening" { var b: f32 = a; var c: f64 = b; var d: f128 = c; + _ = .{ &a, &b, &c, &d }; try expect(a == b); try expect(b == c); try expect(c == d); var e: f80 = c; + _ = &e; try expect(c == e); } @@ -63,6 +67,7 @@ test "float widening f16 to f128" { var x: f16 = 12.34; var y: f128 = x; + _ = .{ &x, &y }; try expect(x == y); } -- 2.54.0 From d82d327de22db3cd2ed4412f395dd5276a3b6a06 Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 14 Nov 2023 08:11:37 +0000 Subject: [PATCH 06/15] test: update remaining code to fix 'var is never mutated' errors --- test/c_abi/main.zig | 63 ++++++++++--------- test/compare_output.zig | 4 +- test/link/wasm/archive/main.zig | 3 +- test/src/Cases.zig | 7 +-- test/standalone/extern/main.zig | 4 +- .../main_return_error/error_u8_non_zero.zig | 3 +- .../stack_iterator/shared_lib_unwind.zig | 2 +- test/standalone/stack_iterator/unwind.zig | 4 +- test/standalone/use_alias/main.zig | 1 + test/standalone/windows_spawn/main.zig | 2 +- test/standalone/zerolength_check/src/main.zig | 6 +- 11 files changed, 49 insertions(+), 50 deletions(-) diff --git a/test/c_abi/main.zig b/test/c_abi/main.zig index f8aac77eb523dbace112d9feb9d7ff62916276a2..d845f89eee394555411bc1342b4736ddd4953e7b 100644 --- a/test/c_abi/main.zig +++ b/test/c_abi/main.zig @@ -278,7 +278,7 @@ test "C ABI big struct" { if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; - var s = BigStruct{ + const s = BigStruct{ .a = 1, .b = 2, .c = 3, @@ -304,7 +304,7 @@ extern fn c_big_union(BigUnion) void; test "C ABI big union" { if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; - var x = BigUnion{ + const x = BigUnion{ .a = BigStruct{ .a = 1, .b = 2, @@ -339,13 +339,13 @@ test "C ABI medium struct of ints and floats" { if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; - var s = MedStructMixed{ + const s = MedStructMixed{ .a = 1234, .b = 100.0, .c = 1337.0, }; c_med_struct_mixed(s); - var s2 = c_ret_med_struct_mixed(); + const s2 = c_ret_med_struct_mixed(); try expect(s2.a == 1234); try expect(s2.b == 100.0); try expect(s2.c == 1337.0); @@ -372,14 +372,14 @@ test "C ABI small struct of ints" { if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; - var s = SmallStructInts{ + const s = SmallStructInts{ .a = 1, .b = 2, .c = 3, .d = 4, }; c_small_struct_ints(s); - var s2 = c_ret_small_struct_ints(); + const s2 = c_ret_small_struct_ints(); try expect(s2.a == 1); try expect(s2.b == 2); try expect(s2.c == 3); @@ -407,13 +407,13 @@ test "C ABI medium struct of ints" { if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; - var s = MedStructInts{ + const s = MedStructInts{ .x = 1, .y = 2, .z = 3, }; c_med_struct_ints(s); - var s2 = c_ret_med_struct_ints(); + const s2 = c_ret_med_struct_ints(); try expect(s2.x == 1); try expect(s2.y == 2); try expect(s2.z == 3); @@ -442,9 +442,9 @@ export fn zig_small_packed_struct(x: SmallPackedStruct) void { } test "C ABI small packed struct" { - var s = SmallPackedStruct{ .a = 0, .b = 1, .c = 2, .d = 3 }; + const s = SmallPackedStruct{ .a = 0, .b = 1, .c = 2, .d = 3 }; c_small_packed_struct(s); - var s2 = c_ret_small_packed_struct(); + const s2 = c_ret_small_packed_struct(); try expect(s2.a == 0); try expect(s2.b == 1); try expect(s2.c == 2); @@ -466,9 +466,9 @@ export fn zig_big_packed_struct(x: BigPackedStruct) void { test "C ABI big packed struct" { if (!has_i128) return error.SkipZigTest; - var s = BigPackedStruct{ .a = 1, .b = 2 }; + const s = BigPackedStruct{ .a = 1, .b = 2 }; c_big_packed_struct(s); - var s2 = c_ret_big_packed_struct(); + const s2 = c_ret_big_packed_struct(); try expect(s2.a == 1); try expect(s2.b == 2); } @@ -486,7 +486,7 @@ test "C ABI split struct of ints" { if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; - var s = SplitStructInt{ + const s = SplitStructInt{ .a = 1234, .b = 100, .c = 1337, @@ -514,13 +514,13 @@ test "C ABI split struct of ints and floats" { if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; - var s = SplitStructMixed{ + const s = SplitStructMixed{ .a = 1234, .b = 100, .c = 1337.0, }; c_split_struct_mixed(s); - var s2 = c_ret_split_struct_mixed(); + const s2 = c_ret_split_struct_mixed(); try expect(s2.a == 1234); try expect(s2.b == 100); try expect(s2.c == 1337.0); @@ -541,14 +541,14 @@ test "C ABI sret and byval together" { if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; - var s = BigStruct{ + const s = BigStruct{ .a = 1, .b = 2, .c = 3, .d = 4, .e = 5, }; - var y = c_big_struct_both(s); + const y = c_big_struct_both(s); try expect(y.a == 10); try expect(y.b == 11); try expect(y.c == 12); @@ -562,7 +562,7 @@ export fn zig_big_struct_both(x: BigStruct) BigStruct { expect(x.c == 32) catch @panic("test failure"); expect(x.d == 33) catch @panic("test failure"); expect(x.e == 34) catch @panic("test failure"); - var s = BigStruct{ + const s = BigStruct{ .a = 20, .b = 21, .c = 22, @@ -594,7 +594,7 @@ test "C ABI structs of floats as parameter" { if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; - var v3 = Vector3{ + const v3 = Vector3{ .x = 3.0, .y = 6.0, .z = 12.0, @@ -602,7 +602,7 @@ test "C ABI structs of floats as parameter" { c_small_struct_floats(v3); c_small_struct_floats_extra(v3, "hello"); - var v5 = Vector5{ + const v5 = Vector5{ .x = 76.0, .y = -1.0, .z = -12.0, @@ -634,13 +634,13 @@ test "C ABI structs of ints as multiple parameters" { if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; - var r1 = Rect{ + const r1 = Rect{ .left = 1, .right = 21, .top = 16, .bottom = 4, }; - var r2 = Rect{ + const r2 = Rect{ .left = 178, .right = 189, .top = 21, @@ -671,13 +671,13 @@ test "C ABI structs of floats as multiple parameters" { if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; - var r1 = FloatRect{ + const r1 = FloatRect{ .left = 1, .right = 21, .top = 16, .bottom = 4, }; - var r2 = FloatRect{ + const r2 = FloatRect{ .left = 178, .right = 189, .top = 21, @@ -787,7 +787,7 @@ test "Struct with array as padding." { c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 }); - var x = c_ret_struct_with_array(); + const x = c_ret_struct_with_array(); try expect(x.a == 4); try expect(x.b == 155); } @@ -822,7 +822,7 @@ test "Float array like struct" { }, }); - var x = c_ret_float_array_struct(); + const x = c_ret_float_array_struct(); try expect(x.origin.x == 1); try expect(x.origin.y == 2); try expect(x.size.width == 3); @@ -840,7 +840,7 @@ test "small simd vector" { c_small_vec(.{ 1, 2 }); - var x = c_ret_small_vec(); + const x = c_ret_small_vec(); try expect(x[0] == 3); try expect(x[1] == 4); } @@ -858,7 +858,7 @@ test "medium simd vector" { c_medium_vec(.{ 1, 2, 3, 4 }); - var x = c_ret_medium_vec(); + const x = c_ret_medium_vec(); try expect(x[0] == 5); try expect(x[1] == 6); try expect(x[2] == 7); @@ -879,7 +879,7 @@ test "big simd vector" { c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 }); - var x = c_ret_big_vec(); + const x = c_ret_big_vec(); try expect(x[0] == 9); try expect(x[1] == 10); try expect(x[2] == 11); @@ -903,7 +903,7 @@ test "C ABI pointer sized float struct" { c_ptr_size_float_struct(.{ .x = 1, .y = 2 }); - var x = c_ret_ptr_size_float_struct(); + const x = c_ret_ptr_size_float_struct(); try expect(x.x == 3); try expect(x.y == 4); } @@ -1102,6 +1102,7 @@ test "C function that takes byval struct called via function pointer" { if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; var fn_ptr = &c_func_ptr_byval; + _ = &fn_ptr; fn_ptr( @as(*anyopaque, @ptrFromInt(1)), @as(*anyopaque, @ptrFromInt(2)), @@ -1224,7 +1225,7 @@ extern fn stdcall_big_union(BigUnion) callconv(stdcall_callconv) void; test "Stdcall ABI big union" { if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; - var x = BigUnion{ + const x = BigUnion{ .a = BigStruct{ .a = 1, .b = 2, diff --git a/test/compare_output.zig b/test/compare_output.zig index bcdc642a1e3451f785bdd058b0b2e16a7e052d2b..d30b6714c9af34ec9bfebc276332b964f5ddba4b 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -165,7 +165,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\const y : u16 = 5678; \\pub fn main() void { \\ var x_local : i32 = print_ok(x); - \\ _ = x_local; + \\ _ = &x_local; \\} \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) { \\ _ = val; @@ -504,7 +504,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ \\pub fn main() !void { \\ var allocator_buf: [10]u8 = undefined; - \\ var fba = std.heap.FixedBufferAllocator.init(&allocator_buf); + \\ const fba = std.heap.FixedBufferAllocator.init(&allocator_buf); \\ var fba_wrapped = std.mem.validationWrap(fba); \\ var logging_allocator = std.heap.loggingAllocator(fba_wrapped.allocator()); \\ const allocator = logging_allocator.allocator(); diff --git a/test/link/wasm/archive/main.zig b/test/link/wasm/archive/main.zig index 29be3af0ac1cb83426ad948dcec2b3090265fa4d..465f85f9f6699690f5e6d9c9d4983a7f5371667f 100644 --- a/test/link/wasm/archive/main.zig +++ b/test/link/wasm/archive/main.zig @@ -1,6 +1,7 @@ export fn foo() void { var a: f16 = 2.2; + _ = &a; // this will pull-in compiler-rt - var b = @trunc(a); + const b = @trunc(a); _ = b; } diff --git a/test/src/Cases.zig b/test/src/Cases.zig index c8265a4165a7e82d1b5ba545c7d1c3a568495b77..f533af37d7d4faf00993cb8a57870214c560c1bd 100644 --- a/test/src/Cases.zig +++ b/test/src/Cases.zig @@ -1161,10 +1161,7 @@ const TestManifest = struct { fn getDefaultParser(comptime T: type) ParseFn(T) { if (T == CrossTarget) return struct { fn parse(str: []const u8) anyerror!T { - var opts = CrossTarget.ParseOptions{ - .arch_os_abi = str, - }; - return try CrossTarget.parse(opts); + return CrossTarget.parse(.{ .arch_os_abi = str }); } }.parse; @@ -1691,7 +1688,7 @@ fn runOneCase( var argv = std.ArrayList([]const u8).init(allocator); defer argv.deinit(); - var exec_result = x: { + const exec_result = x: { var exec_node = update_node.start("execute", 0); exec_node.activate(); defer exec_node.end(); diff --git a/test/standalone/extern/main.zig b/test/standalone/extern/main.zig index 4cbed184c3fb2a95b47bba423f19cd416b0a57b2..3f5168f84195034fdd6980bfabefcc1f68d2dc95 100644 --- a/test/standalone/extern/main.zig +++ b/test/standalone/extern/main.zig @@ -6,8 +6,8 @@ const getHidden = @extern(*const fn () callconv(.C) u32, .{ .name = "getHidden" const T = extern struct { x: u32 }; test { - var mut_val_ptr = @extern(*f64, .{ .name = "mut_val" }); - var const_val_ptr = @extern(*const T, .{ .name = "const_val" }); + const mut_val_ptr = @extern(*f64, .{ .name = "mut_val" }); + const const_val_ptr = @extern(*const T, .{ .name = "const_val" }); assert(getHidden() == 0); updateHidden(123); diff --git a/test/standalone/main_return_error/error_u8_non_zero.zig b/test/standalone/main_return_error/error_u8_non_zero.zig index c45458fb2168b7918be538769eb3f5a5a7c3b228..47fe7946ec1e4ce6fdd33a749fc11d313eb3f3ab 100644 --- a/test/standalone/main_return_error/error_u8_non_zero.zig +++ b/test/standalone/main_return_error/error_u8_non_zero.zig @@ -1,8 +1,7 @@ const Err = error{Foo}; fn foo() u8 { - var x = @as(u8, @intCast(9)); - return x; + return @intCast(9); } pub fn main() !u8 { diff --git a/test/standalone/stack_iterator/shared_lib_unwind.zig b/test/standalone/stack_iterator/shared_lib_unwind.zig index 50e0421e2ac6f26b5c957da19c693461b2644ec0..57513a49c6eb9d8903152aa5a37027291b30a0c0 100644 --- a/test/standalone/stack_iterator/shared_lib_unwind.zig +++ b/test/standalone/stack_iterator/shared_lib_unwind.zig @@ -9,7 +9,7 @@ noinline fn frame4(expected: *[5]usize, unwound: *[5]usize) void { var context: debug.ThreadContext = undefined; testing.expect(debug.getContext(&context)) catch @panic("failed to getContext"); - var debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo"); + const debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo"); var it = debug.StackIterator.initWithContext(expected[0], debug_info, &context) catch @panic("failed to initWithContext"); defer it.deinit(); diff --git a/test/standalone/stack_iterator/unwind.zig b/test/standalone/stack_iterator/unwind.zig index 1280118173e24d73f6a064f5ef88bc409d0bccd6..4bb459bdacd353ea8237dce6d184c9c9b731ecc3 100644 --- a/test/standalone/stack_iterator/unwind.zig +++ b/test/standalone/stack_iterator/unwind.zig @@ -9,7 +9,7 @@ noinline fn frame3(expected: *[4]usize, unwound: *[4]usize) void { var context: debug.ThreadContext = undefined; testing.expect(debug.getContext(&context)) catch @panic("failed to getContext"); - var debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo"); + const debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo"); var it = debug.StackIterator.initWithContext(expected[0], debug_info, &context) catch @panic("failed to initWithContext"); defer it.deinit(); @@ -76,7 +76,7 @@ noinline fn frame1(expected: *[4]usize, unwound: *[4]usize) void { // Use a stack frame that is too big to encode in __unwind_info's stack-immediate encoding // to exercise the stack-indirect encoding path var pad: [std.math.maxInt(u8) * @sizeOf(usize) + 1]u8 = undefined; - _ = pad; + _ = std.mem.doNotOptimizeAway(&pad); frame2(expected, unwound); } diff --git a/test/standalone/use_alias/main.zig b/test/standalone/use_alias/main.zig index be9d6da6c323bdef920809795349e25732e65ff3..68ef6f6588497413b0f7d539fa03f7dd9ea09779 100644 --- a/test/standalone/use_alias/main.zig +++ b/test/standalone/use_alias/main.zig @@ -6,5 +6,6 @@ test "symbol exists" { .a = 1, .b = 1, }; + _ = &foo; try expect(foo.a + foo.b == 2); } diff --git a/test/standalone/windows_spawn/main.zig b/test/standalone/windows_spawn/main.zig index a57b44c7572d2d217ff6bea0dbd8082f01ab8427..82e1b5b171f56c0bbca7f890a86d512dd496dd7f 100644 --- a/test/standalone/windows_spawn/main.zig +++ b/test/standalone/windows_spawn/main.zig @@ -158,7 +158,7 @@ fn testExec(allocator: std.mem.Allocator, command: []const u8, expected_stdout: } fn testExecWithCwd(allocator: std.mem.Allocator, command: []const u8, cwd: ?[]const u8, expected_stdout: []const u8) !void { - var result = try std.ChildProcess.run(.{ + const result = try std.ChildProcess.run(.{ .allocator = allocator, .argv = &[_][]const u8{command}, .cwd = cwd, diff --git a/test/standalone/zerolength_check/src/main.zig b/test/standalone/zerolength_check/src/main.zig index e1e2c5d3763de8d9a94ecbfaf06ff38f12f5f5e0..1cb8358c9de7f0abf9d09110844fb3937d7469f0 100644 --- a/test/standalone/zerolength_check/src/main.zig +++ b/test/standalone/zerolength_check/src/main.zig @@ -1,14 +1,14 @@ const std = @import("std"); test { - var dest = foo(); - var source = foo(); + const dest = foo(); + const source = foo(); @memcpy(dest, source); @memset(dest, 4); @memset(dest, undefined); - var dest2 = foo2(); + const dest2 = foo2(); @memset(dest2, 0); } -- 2.54.0 From 026a8278f829670b434fddce34030290b6910898 Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 14 Nov 2023 09:15:15 +0000 Subject: [PATCH 07/15] tools: correct unnecessary uses of 'var' --- tools/gen_spirv_spec.zig | 4 ++-- tools/generate_linux_syscalls.zig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/gen_spirv_spec.zig b/tools/gen_spirv_spec.zig index 9427451a28d80044d68e37055a716bec79c5bfed..18fbd5cd81fc82347e3d5329e1ee916f26ceeeab 100644 --- a/tools/gen_spirv_spec.zig +++ b/tools/gen_spirv_spec.zig @@ -23,7 +23,7 @@ pub fn main() !void { var scanner = std.json.Scanner.initCompleteInput(allocator, spec); var diagnostics = std.json.Diagnostics{}; scanner.enableDiagnostics(&diagnostics); - var parsed = std.json.parseFromTokenSource(g.CoreRegistry, allocator, &scanner, .{}) catch |err| { + const parsed = std.json.parseFromTokenSource(g.CoreRegistry, allocator, &scanner, .{}) catch |err| { std.debug.print("line,col: {},{}\n", .{ diagnostics.getLine(), diagnostics.getColumn() }); return err; }; @@ -466,7 +466,7 @@ fn renderBitEnum( std.debug.assert(@popCount(value) == 1); - var bitpos = std.math.log2_int(u32, value); + const bitpos = std.math.log2_int(u32, value); if (flags_by_bitpos[bitpos]) |*existing| { const tag_index = std.mem.indexOfDiff(u8, enumerant.enumerant, enumerants[existing.*].enumerant).?; const enum_priority = tagPriorityScore(enumerant.enumerant[tag_index..]); diff --git a/tools/generate_linux_syscalls.zig b/tools/generate_linux_syscalls.zig index 3bd0647b33332f834fd254016b18904c15eee645..410c971a60501ea56786c0e6157416a5bd3a21f5 100644 --- a/tools/generate_linux_syscalls.zig +++ b/tools/generate_linux_syscalls.zig @@ -35,7 +35,7 @@ pub fn main() !void { // As of 5.17.1, the largest table is 23467 bytes. // 32k should be enough for now. - var buf = try allocator.alloc(u8, 1 << 15); + const buf = try allocator.alloc(u8, 1 << 15); const linux_dir = try std.fs.openDirAbsolute(linux_path, .{}); try writer.writeAll( -- 2.54.0 From ed4bab66d8a0c518245a6ca1ff401f0b30befe64 Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 17 Nov 2023 13:16:07 +0000 Subject: [PATCH 08/15] langref: correct unnecessary uses of 'var' --- doc/langref.html.in | 215 +++++++++++++++++++++++++------------------- 1 file changed, 121 insertions(+), 94 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 72e23a1011dddc12808ebb2a9403af83953b00be..41cd06a4a63ce955de41fcf50a5e88c0f07ac590 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -2609,16 +2609,17 @@ test "Basic vector usage" { test "Conversion between vectors, arrays, and slices" { // Vectors and fixed-length arrays can be automatically assigned back and forth - var arr1: [4]f32 = [_]f32{ 1.1, 3.2, 4.5, 5.6 }; - var vec: @Vector(4, f32) = arr1; - var arr2: [4]f32 = vec; + const arr1: [4]f32 = [_]f32{ 1.1, 3.2, 4.5, 5.6 }; + const vec: @Vector(4, f32) = arr1; + const arr2: [4]f32 = vec; try expectEqual(arr1, arr2); // You can also assign from a slice with comptime-known length to a vector using .* const vec2: @Vector(2, f32) = arr1[1..3].*; - var slice: []const f32 = &arr1; - var offset: u32 = 1; + const slice: []const f32 = &arr1; + var offset: u32 = 1; // var to make it runtime-known + _ = &offset; // suppress 'var is never mutated' error // To extract a comptime-known length from a runtime-known offset, // first extract a new slice from the starting offset, then an array of // comptime-known length @@ -2732,7 +2733,8 @@ test "pointer arithmetic with many-item pointer" { test "pointer arithmetic with slices" { var array = [_]i32{ 1, 2, 3, 4 }; - var length: usize = 0; + var length: usize = 0; // var to make it runtime-known + _ = &length; // suppress 'var is never mutated' error var slice = array[length..array.len]; try expect(slice[0] == 1); @@ -2759,7 +2761,8 @@ const expect = @import("std").testing.expect; test "pointer slicing" { var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - var start: usize = 2; + var start: usize = 2; // var to make it runtime-known + _ = &start; // suppress 'var is never mutated' error const slice = array[start..4]; try expect(slice.len == 2); @@ -2961,8 +2964,9 @@ const std = @import("std"); const expect = std.testing.expect; test "allowzero" { - var zero: usize = 0; - var ptr: *allowzero i32 = @ptrFromInt(zero); + var zero: usize = 0; // var to make to runtime-known + _ = &zero; // suppress 'var is never mutated' error + const ptr: *allowzero i32 = @ptrFromInt(zero); try expect(@intFromPtr(ptr) == 0); } {#code_end#} @@ -3006,6 +3010,7 @@ const expect = @import("std").testing.expect; test "basic slices" { var array = [_]i32{ 1, 2, 3, 4 }; var known_at_runtime_zero: usize = 0; + _ = &known_at_runtime_zero; const slice = array[known_at_runtime_zero..array.len]; try expect(@TypeOf(slice) == []i32); try expect(&slice[0] == &array[0]); @@ -3020,6 +3025,7 @@ test "basic slices" { // to perform some optimisations like recognising a comptime-known length when // the start position is only known at runtime. var runtime_start: usize = 1; + _ = &runtime_start; const length = 2; const array_ptr_len = array[runtime_start..][0..length]; try expect(@TypeOf(array_ptr_len) == *[length]i32); @@ -3056,7 +3062,8 @@ test "using slices for strings" { var all_together: [100]u8 = undefined; // You can use slice syntax with at least one runtime-known index on an // array to convert an array into a slice. - var start : usize = 0; + var start: usize = 0; + _ = &start; const all_together_slice = all_together[start..]; // String concatenation example. const hello_world = try fmt.bufPrint(all_together_slice, "{s} {s}", .{ hello, world }); @@ -3075,6 +3082,7 @@ test "slice pointer" { // A pointer to an array can be sliced just like an array: var start: usize = 0; var end: usize = 5; + _ = .{ &start, &end }; const slice = ptr[start..end]; // The slice is mutable because we sliced a mutable pointer. try expect(@TypeOf(slice) == []u8); @@ -3121,6 +3129,7 @@ const expect = std.testing.expect; test "0-terminated slicing" { var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 }; var runtime_length: usize = 3; + _ = &runtime_length; const slice = array[0..runtime_length :0]; try expect(@TypeOf(slice) == [:0]u8); @@ -3143,6 +3152,7 @@ test "sentinel mismatch" { // This does not match the indicated sentinel value of `0` and will lead // to a runtime panic. var runtime_length: usize = 2; + _ = &runtime_length; const slice = array[0..runtime_length :0]; _ = slice; @@ -3266,7 +3276,7 @@ test "linked list" { // do this: try expect(LinkedList(i32) == LinkedList(i32)); - var list = LinkedList(i32) { + const list = LinkedList(i32){ .first = null, .last = null, .len = 0, @@ -3278,12 +3288,12 @@ test "linked list" { const ListOfInts = LinkedList(i32); try expect(ListOfInts == LinkedList(i32)); - var node = ListOfInts.Node { + var node = ListOfInts.Node{ .prev = null, .next = null, .data = 1234, }; - var list2 = LinkedList(i32) { + const list2 = LinkedList(i32){ .first = &node, .last = &node, .len = 1, @@ -3372,13 +3382,13 @@ test "@bitCast between packed structs" { fn doTheTest() !void { try expect(@sizeOf(Full) == 2); try expect(@sizeOf(Divided) == 2); - var full = Full{ .number = 0x1234 }; - var divided: Divided = @bitCast(full); + const full = Full{ .number = 0x1234 }; + const divided: Divided = @bitCast(full); try expect(divided.half1 == 0x34); try expect(divided.quarter3 == 0x2); try expect(divided.quarter4 == 0x1); - var ordered: [2]u8 = @bitCast(full); + const ordered: [2]u8 = @bitCast(full); switch (native_endian) { .big => { try expect(ordered[0] == 0x12); @@ -3586,7 +3596,7 @@ const expect = std.testing.expect; const Point = struct {x: i32, y: i32}; test "anonymous struct literal" { - var pt: Point = .{ + const pt: Point = .{ .x = 13, .y = 67, }; @@ -4051,14 +4061,14 @@ const Number = union { }; test "anonymous union literal syntax" { - var i: Number = .{.int = 42}; - var f = makeNumber(); + const i: Number = .{ .int = 42 }; + const f = makeNumber(); try expect(i.int == 42); try expect(f.float == 12.34); } fn makeNumber() Number { - return .{.float = 12.34}; + return .{ .float = 12.34 }; } {#code_end#} {#header_close#} @@ -4098,7 +4108,7 @@ test "call foo" { test "access variable after block scope" { { var x: i32 = 1; - _ = x; + _ = &x; } x += 1; } @@ -4149,7 +4159,7 @@ test "separate scopes" { } { var pi: bool = true; - _ = pi; + _ = π } } {#code_end#} @@ -4423,7 +4433,7 @@ fn withSwitch(any: AnySlice) usize { } test "inline for and inline else similarity" { - var any = AnySlice{ .c = "hello" }; + const any = AnySlice{ .c = "hello" }; try expect(withFor(any) == 5); try expect(withSwitch(any) == 5); } @@ -4455,7 +4465,7 @@ fn getNum(u: U) u32 { } test "test" { - var u = U{ .b = 42 }; + const u = U{ .b = 42 }; try expect(getNum(u) == 42); } {#code_end#} @@ -4762,7 +4772,7 @@ test "multi object for" { } test "for reference" { - var items = [_]i32 { 3, 4, 2 }; + var items = [_]i32{ 3, 4, 2 }; // Iterate over the slice by reference by // specifying that the capture value is a pointer. @@ -4777,7 +4787,7 @@ test "for reference" { test "for else" { // For allows an else attached to it, the same as a while loop. - var items = [_]?i32 { 3, 4, null, 5 }; + const items = [_]?i32{ 3, 4, null, 5 }; // For loops can also be used as expressions. // 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) { test "fn type inference" { try expect(addFortyTwo(1) == 43); try expect(@TypeOf(addFortyTwo(1)) == comptime_int); - var y: i64 = 2; + const y: i64 = 2; try expect(addFortyTwo(y) == 44); try expect(@TypeOf(addFortyTwo(y)) == i64); } @@ -5795,7 +5805,7 @@ fn getData() !u32 { } fn genFoos(allocator: Allocator, num: usize) ![]Foo { - var foos = try allocator.alloc(Foo, num); + const foos = try allocator.alloc(Foo, num); errdefer allocator.free(foos); for (foos, 0..) |*foo, i| { @@ -5833,7 +5843,7 @@ fn getData() !u32 { } fn genFoos(allocator: Allocator, num: usize) ![]Foo { - var foos = try allocator.alloc(Foo, num); + const foos = try allocator.alloc(Foo, num); errdefer allocator.free(foos); // Used to track how many foos have been initialized @@ -6325,13 +6335,13 @@ test "optional pointers" {

{#code_begin|test|test_type_coercion#} test "type coercion - variable declaration" { - var a: u8 = 1; - var b: u16 = a; + const a: u8 = 1; + const b: u16 = a; _ = b; } test "type coercion - function call" { - var a: u8 = 1; + const a: u8 = 1; foo(a); } @@ -6340,8 +6350,8 @@ fn foo(b: u16) void { } test "type coercion - @as builtin" { - var a: u8 = 1; - var b = @as(u16, a); + const a: u8 = 1; + const b = @as(u16, a); _ = b; } {#code_end#} @@ -6366,7 +6376,7 @@ test "type coercion - @as builtin" { {#code_begin|test|test_no_op_casts#} test "type coercion - const qualification" { var a: i32 = 1; - var b: *i32 = &a; + const b: *i32 = &a; foo(b); } @@ -6399,26 +6409,26 @@ const expect = std.testing.expect; const mem = std.mem; test "integer widening" { - var a: u8 = 250; - var b: u16 = a; - var c: u32 = b; - var d: u64 = c; - var e: u64 = d; - var f: u128 = e; + const a: u8 = 250; + const b: u16 = a; + const c: u32 = b; + const d: u64 = c; + const e: u64 = d; + const f: u128 = e; try expect(f == a); } test "implicit unsigned integer to signed integer" { - var a: u8 = 250; - var b: i16 = a; + const a: u8 = 250; + const b: i16 = a; try expect(b == 250); } test "float widening" { - var a: f16 = 12.34; - var b: f32 = a; - var c: f64 = b; - var d: f128 = c; + const a: f16 = 12.34; + const b: f32 = a; + const c: f64 = b; + const d: f128 = c; try expect(d == a); } {#code_end#} @@ -6435,7 +6445,7 @@ test "float widening" { {#code_begin|test_err|test_ambiguous_coercion#} // Compile time coercion of float to int test "implicit cast to comptime_int" { - var f: f32 = 54.0 / 5; + const f: f32 = 54.0 / 5; _ = f; } {#code_end#} @@ -6449,31 +6459,31 @@ const expect = std.testing.expect; // const modifier on the element type. Useful in particular for // String literals. test "*const [N]T to []const T" { - var x1: []const u8 = "hello"; - var x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; + const x1: []const u8 = "hello"; + const x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; try expect(std.mem.eql(u8, x1, x2)); - var y: []const f32 = &[2]f32{ 1.2, 3.4 }; + const y: []const f32 = &[2]f32{ 1.2, 3.4 }; try expect(y[0] == 1.2); } // Likewise, it works when the destination type is an error union. test "*const [N]T to E![]const T" { - var x1: anyerror![]const u8 = "hello"; - var x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; + const x1: anyerror![]const u8 = "hello"; + const x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; try expect(std.mem.eql(u8, try x1, try x2)); - var y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 }; + const y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 }; try expect((try y)[0] == 1.2); } // Likewise, it works when the destination type is an optional. test "*const [N]T to ?[]const T" { - var x1: ?[]const u8 = "hello"; - var x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; + const x1: ?[]const u8 = "hello"; + const x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; try expect(std.mem.eql(u8, x1.?, x2.?)); - var y: ?[]const f32 = &[2]f32{ 1.2, 3.4 }; + const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 }; try expect(y.?[0] == 1.2); } @@ -6609,18 +6619,18 @@ const U2 = union(enum) { }; test "coercion between unions and enums" { - var u = U{ .two = 12.34 }; - var e: E = u; // coerce union to enum + const u = U{ .two = 12.34 }; + const e: E = u; // coerce union to enum try expect(e == E.two); const three = E.three; - var u_2: U = three; // coerce enum to union + const u_2: U = three; // coerce enum to union try expect(u_2 == E.three); - var u_3: U = .three; // coerce enum literal to union + const u_3: U = .three; // coerce enum literal to union try expect(u_3 == E.three); - var u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type. + const u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type. try expect(u_4.tag() == 1); // The following example is invalid. @@ -6698,9 +6708,9 @@ const expect = std.testing.expect; const mem = std.mem; test "peer resolve int widening" { - var a: i8 = 12; - var b: i16 = 34; - var c = a + b; + const a: i8 = 12; + const b: i16 = 34; + const c = a + b; try expect(c == 46); try expect(@TypeOf(c) == i16); } @@ -6809,6 +6819,7 @@ export fn entry() void { var x: void = {}; var y: void = {}; x = y; + y = x; } {#code_end#}

When this turns into machine code, there is no code generated in the @@ -7121,6 +7132,7 @@ fn performFn(start_value: i32) i32 { // expect(performFn('w', 99) == 99); fn performFn(start_value: i32) i32 { var result: i32 = start_value; + _ = &result; return result; } {#end_syntax_block#} @@ -8664,8 +8676,9 @@ test "@hasDecl" {

{#code_begin|test_err|test_intCast_builtin|cast truncated bits#} test "integer cast panic" { - var a: u16 = 0xabcd; - var b: u8 = @intCast(a); + var a: u16 = 0xabcd; // runtime-known + _ = &a; + const b: u8 = @intCast(a); _ = b; } {#code_end#} @@ -8825,7 +8838,7 @@ const expect = std.testing.expect; test "@wasmMemoryGrow" { if (native_arch != .wasm32) return error.SkipZigTest; - var prev = @wasmMemorySize(0); + const prev = @wasmMemorySize(0); try expect(prev == @wasmMemoryGrow(0, 1)); try expect(prev + 1 == @wasmMemorySize(0)); } @@ -9560,8 +9573,8 @@ const std = @import("std"); const expect = std.testing.expect; test "integer truncation" { - var a: u16 = 0xabcd; - var b: u8 = @truncate(a); + const a: u16 = 0xabcd; + const b: u8 = @truncate(a); try expect(b == 0xcd); } {#code_end#} @@ -9845,7 +9858,7 @@ comptime {

At runtime:

{#code_begin|exe_err|runtime_index_out_of_bounds#} pub fn main() void { - var x = foo("hello"); + const x = foo("hello"); _ = x; } @@ -9858,7 +9871,7 @@ fn foo(x: []const u8) u8 {

At compile-time:

{#code_begin|test_err|test_comptime_invalid_cast|type 'u32' cannot represent integer value '-1'#} comptime { - var value: i32 = -1; + const value: i32 = -1; const unsigned: u32 = @intCast(value); _ = unsigned; } @@ -9868,8 +9881,9 @@ comptime { const std = @import("std"); pub fn main() void { - var value: i32 = -1; - var unsigned: u32 = @intCast(value); + var value: i32 = -1; // runtime-known + _ = &value; + const unsigned: u32 = @intCast(value); std.debug.print("value: {}\n", .{unsigned}); } {#code_end#} @@ -9891,7 +9905,8 @@ comptime { const std = @import("std"); pub fn main() void { - var spartan_count: u16 = 300; + var spartan_count: u16 = 300; // runtime-known + _ = &spartan_count; const byte: u8 = @intCast(spartan_count); std.debug.print("value: {}\n", .{byte}); } @@ -9975,7 +9990,7 @@ pub fn main() !void { {#code_begin|exe|addWithOverflow_builtin#} const print = @import("std").debug.print; pub fn main() void { - var byte: u8 = 255; + const byte: u8 = 255; const ov = @addWithOverflow(byte, 10); if (ov[1] != 0) { @@ -10025,8 +10040,9 @@ comptime { const std = @import("std"); pub fn main() void { - var x: u8 = 0b01010101; - var y = @shlExact(x, 2); + var x: u8 = 0b01010101; // runtime-known + _ = &x; + const y = @shlExact(x, 2); std.debug.print("value: {}\n", .{y}); } {#code_end#} @@ -10044,8 +10060,9 @@ comptime { const std = @import("std"); pub fn main() void { - var x: u8 = 0b10101010; - var y = @shrExact(x, 2); + var x: u8 = 0b10101010; // runtime-known + _ = &x; + const y = @shrExact(x, 2); std.debug.print("value: {}\n", .{y}); } {#code_end#} @@ -10067,7 +10084,8 @@ const std = @import("std"); pub fn main() void { var a: u32 = 1; var b: u32 = 0; - var c = a / b; + _ = .{ &a, &b }; + const c = a / b; std.debug.print("value: {}\n", .{c}); } {#code_end#} @@ -10089,7 +10107,8 @@ const std = @import("std"); pub fn main() void { var a: u32 = 10; var b: u32 = 0; - var c = a % b; + _ = .{ &a, &b }; + const c = a % b; std.debug.print("value: {}\n", .{c}); } {#code_end#} @@ -10111,7 +10130,8 @@ const std = @import("std"); pub fn main() void { var a: u32 = 10; var b: u32 = 3; - var c = @divExact(a, b); + _ = .{ &a, &b }; + const c = @divExact(a, b); std.debug.print("value: {}\n", .{c}); } {#code_end#} @@ -10131,7 +10151,8 @@ const std = @import("std"); pub fn main() void { var optional_number: ?i32 = null; - var number = optional_number.?; + _ = &optional_number; + const number = optional_number.?; std.debug.print("value: {}\n", .{number}); } {#code_end#} @@ -10212,9 +10233,10 @@ comptime { const std = @import("std"); pub fn main() void { - var err = error.AnError; + const err = error.AnError; var number = @intFromError(err) + 500; - var invalid_err = @errorFromInt(number); + _ = &number; + const invalid_err = @errorFromInt(number); std.debug.print("value: {}\n", .{invalid_err}); } {#code_end#} @@ -10245,7 +10267,8 @@ const Foo = enum { pub fn main() void { var a: u2 = 3; - var b: Foo = @enumFromInt(a); + _ = &a; + const b: Foo = @enumFromInt(a); std.debug.print("value: {s}\n", .{@tagName(b)}); } {#code_end#} @@ -10402,17 +10425,18 @@ fn bar(f: *Foo) void {

At compile-time:

{#code_begin|test_err|test_comptime_out_of_bounds_float_to_integer_cast|float value '4294967296' cannot be stored in integer type 'i32'#} comptime { - const float: f32 = 4294967296; - const int: i32 = @intFromFloat(float); - _ = int; + const float: f32 = 4294967296; + const int: i32 = @intFromFloat(float); + _ = int; } {#code_end#}

At runtime:

{#code_begin|exe_err|runtime_out_of_bounds_float_to_integer_cast#} pub fn main() void { - var float: f32 = 4294967296; - var int: i32 = @intFromFloat(float); - _ = int; + var float: f32 = 4294967296; // runtime-known + _ = &float; + const int: i32 = @intFromFloat(float); + _ = int; } {#code_end#} {#header_close#} @@ -10435,7 +10459,8 @@ comptime { {#code_begin|exe_err|runtime_invalid_null_pointer_cast#} pub fn main() void { var opt_ptr: ?*i32 = null; - var ptr: *i32 = @ptrCast(opt_ptr); + _ = &opt_ptr; + const ptr: *i32 = @ptrCast(opt_ptr); _ = ptr; } {#code_end#} @@ -11120,7 +11145,9 @@ int foo(void) { {#code_begin|syntax|macro#} pub export fn foo() c_int { var a: c_int = 1; + _ = &a; var b: c_int = 2; + _ = &b; return a + b; } pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected token .Equal"); // macro.c:1:9 -- 2.54.0 From 172c2797bdd5f939e53acc26ea6820896e62733a Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 14 Nov 2023 18:40:07 +0000 Subject: [PATCH 09/15] link: fix MachO boundary symbol resolution --- src/link/MachO.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/link/MachO.zig b/src/link/MachO.zig index ee09137759fb1f9dbaad1bac8d8c5f8aaae0f48a..f0938a3c1962ce0cbea1537cd865661be3c03cc0 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -1923,6 +1923,8 @@ fn resolveBoundarySymbols(self: *MachO) !void { _ = self.unresolved.swapRemove(global_index); continue; } + + next_sym += 1; } } -- 2.54.0 From b35589343894791a48b1423aa6d4a59b4858dfdb Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 14 Nov 2023 09:10:53 +0000 Subject: [PATCH 10/15] compiler: correct unnecessary uses of 'var' --- src/Air.zig | 2 +- src/AstGen.zig | 4 +- src/Autodoc.zig | 100 ++++++++++++++--------------- src/Compilation.zig | 12 ++-- src/Package/Fetch/git.zig | 18 +++--- src/Sema.zig | 18 +++--- src/arch/riscv64/CodeGen.zig | 5 ++ src/arch/sparc64/CodeGen.zig | 4 ++ src/arch/wasm/CodeGen.zig | 8 +-- src/arch/x86_64/CodeGen.zig | 2 +- src/arch/x86_64/Disassembler.zig | 3 +- src/arch/x86_64/Lower.zig | 2 +- src/arch/x86_64/encoder.zig | 4 +- src/aro_translate_c.zig | 4 +- src/codegen.zig | 2 +- src/codegen/llvm/BitcodeReader.zig | 2 +- src/codegen/spirv.zig | 8 +-- src/link/C.zig | 2 +- src/link/Coff.zig | 10 +-- src/link/Dwarf.zig | 6 +- src/link/Elf.zig | 10 +-- src/link/Elf/eh_frame.zig | 2 +- src/link/MachO.zig | 14 ++-- src/link/MachO/Archive.zig | 6 +- src/link/MachO/Dylib.zig | 6 +- src/link/MachO/Trie.zig | 16 ++--- src/link/MachO/UnwindInfo.zig | 2 +- src/link/MachO/eh_frame.zig | 2 +- src/link/MachO/load_commands.zig | 2 +- src/link/MachO/zld.zig | 2 +- src/link/Plan9.zig | 12 ++-- src/link/Wasm.zig | 10 +-- src/link/Wasm/Object.zig | 6 +- src/link/tapi/yaml.zig | 2 +- src/main.zig | 14 ++-- src/resinator/bmp.zig | 2 +- src/resinator/cli.zig | 10 +-- src/resinator/code_pages.zig | 6 +- src/resinator/comments.zig | 8 +-- src/resinator/compile.zig | 8 +-- src/resinator/lang.zig | 2 +- src/resinator/parse.zig | 12 ++-- src/resinator/res.zig | 4 +- src/resinator/source_mapping.zig | 4 +- src/translate_c.zig | 10 +-- src/value.zig | 6 +- src/windows_sdk.zig | 18 +++--- 47 files changed, 210 insertions(+), 202 deletions(-) diff --git a/src/Air.zig b/src/Air.zig index 8bcc4dbf92d6398903791c3abeb5ef16b8ea8416..9bf0bd5ecaf2cf7754a332933cb1004e629831b3 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -1787,7 +1787,7 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool { => false, .assembly => { - var extra = air.extraData(Air.Asm, data.ty_pl.payload); + const extra = air.extraData(Air.Asm, data.ty_pl.payload); const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0; return is_volatile or if (extra.data.outputs_len == 1) @as(Air.Inst.Ref, @enumFromInt(air.extra[extra.end])) != .none diff --git a/src/AstGen.zig b/src/AstGen.zig index 58ba3ee11cc8f6a9f29e936558703ead3abb9947..be6e88af0ac4b7939519853bb559a6788fb4d0ef 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -6707,7 +6707,7 @@ fn forExpr( }; } - var then_node = for_full.ast.then_expr; + const then_node = for_full.ast.then_expr; var then_scope = parent_gz.makeSubBlock(&cond_scope.base); defer then_scope.unstack(); @@ -8160,7 +8160,7 @@ fn typeOf( } const payload_size: u32 = std.meta.fields(Zir.Inst.TypeOfPeer).len; const payload_index = try reserveExtra(astgen, payload_size + args.len); - var args_index = payload_index + payload_size; + const args_index = payload_index + payload_size; const typeof_inst = try gz.addExtendedMultiOpPayloadIndex(.typeof_peer, payload_index, args.len); diff --git a/src/Autodoc.zig b/src/Autodoc.zig index cd64b5e2cfbee2658e224bf0bb7bdb74e897dbf1..754c29cec37fdfec6798c1e82346283362f02713 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -985,7 +985,7 @@ fn walkInstruction( }, .import => { const str_tok = data[@intFromEnum(inst)].str_tok; - var path = str_tok.get(file.zir); + const path = str_tok.get(file.zir); // importFile cannot error out since all files // are already loaded at this point @@ -1210,7 +1210,7 @@ fn walkInstruction( .compile_error => { const un_node = data[@intFromEnum(inst)].un_node; - var operand: DocData.WalkResult = try self.walkRef( + const operand: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1252,7 +1252,7 @@ fn walkInstruction( const byte_count = str.len * @sizeOf(std.math.big.Limb); const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count]; - var limbs = try self.arena.alloc(std.math.big.Limb, str.len); + const limbs = try self.arena.alloc(std.math.big.Limb, str.len); @memcpy(std.mem.sliceAsBytes(limbs)[0..limb_bytes.len], limb_bytes); const big_int = std.math.big.int.Const{ @@ -1281,7 +1281,7 @@ fn walkInstruction( const slice_index = self.exprs.items.len; try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); - var lhs: DocData.WalkResult = try self.walkRef( + const lhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1289,7 +1289,7 @@ fn walkInstruction( false, call_ctx, ); - var start: DocData.WalkResult = try self.walkRef( + const start: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1321,7 +1321,7 @@ fn walkInstruction( const slice_index = self.exprs.items.len; try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); - var lhs: DocData.WalkResult = try self.walkRef( + const lhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1329,7 +1329,7 @@ fn walkInstruction( false, call_ctx, ); - var start: DocData.WalkResult = try self.walkRef( + const start: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1337,7 +1337,7 @@ fn walkInstruction( false, call_ctx, ); - var end: DocData.WalkResult = try self.walkRef( + const end: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1371,7 +1371,7 @@ fn walkInstruction( const slice_index = self.exprs.items.len; try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); - var lhs: DocData.WalkResult = try self.walkRef( + const lhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1379,7 +1379,7 @@ fn walkInstruction( false, call_ctx, ); - var start: DocData.WalkResult = try self.walkRef( + const start: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1387,7 +1387,7 @@ fn walkInstruction( false, call_ctx, ); - var end: DocData.WalkResult = try self.walkRef( + const end: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1395,7 +1395,7 @@ fn walkInstruction( false, call_ctx, ); - var sentinel: DocData.WalkResult = try self.walkRef( + const sentinel: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1436,7 +1436,7 @@ fn walkInstruction( const slice_index = self.exprs.items.len; try self.exprs.append(self.arena, .{ .slice = .{ .lhs = 0, .start = 0 } }); - var lhs: DocData.WalkResult = try self.walkRef( + const lhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1444,7 +1444,7 @@ fn walkInstruction( false, call_ctx, ); - var start: DocData.WalkResult = try self.walkRef( + const start: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1452,7 +1452,7 @@ fn walkInstruction( false, call_ctx, ); - var len: DocData.WalkResult = try self.walkRef( + const len: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1460,7 +1460,7 @@ fn walkInstruction( false, call_ctx, ); - var sentinel_opt: ?DocData.WalkResult = if (extra.data.sentinel != .none) + const sentinel_opt: ?DocData.WalkResult = if (extra.data.sentinel != .none) try self.walkRef( file, parent_scope, @@ -1574,7 +1574,7 @@ fn walkInstruction( const binop_index = self.exprs.items.len; try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } }); - var lhs: DocData.WalkResult = try self.walkRef( + const lhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1582,7 +1582,7 @@ fn walkInstruction( false, call_ctx, ); - var rhs: DocData.WalkResult = try self.walkRef( + const rhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1620,7 +1620,7 @@ fn walkInstruction( const binop_index = self.exprs.items.len; try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } }); - var lhs: DocData.WalkResult = try self.walkRef( + const lhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1628,7 +1628,7 @@ fn walkInstruction( false, call_ctx, ); - var rhs: DocData.WalkResult = try self.walkRef( + const rhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1786,7 +1786,7 @@ fn walkInstruction( const pl_node = data[@intFromEnum(inst)].pl_node; const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); - var rhs: DocData.WalkResult = try self.walkRef( + const rhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1801,7 +1801,7 @@ fn walkInstruction( const rhs_index = self.exprs.items.len; try self.exprs.append(self.arena, rhs.expr); - var lhs: DocData.WalkResult = try self.walkRef( + const lhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1850,7 +1850,7 @@ fn walkInstruction( const binop_index = self.exprs.items.len; try self.exprs.append(self.arena, .{ .builtinBin = .{ .lhs = 0, .rhs = 0 } }); - var lhs: DocData.WalkResult = try self.walkRef( + const lhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1858,7 +1858,7 @@ fn walkInstruction( false, call_ctx, ); - var rhs: DocData.WalkResult = try self.walkRef( + const rhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1882,7 +1882,7 @@ fn walkInstruction( const pl_node = data[@intFromEnum(inst)].pl_node; const extra = file.zir.extraData(Zir.Inst.MulAdd, pl_node.payload_index); - var mul1: DocData.WalkResult = try self.walkRef( + const mul1: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1890,7 +1890,7 @@ fn walkInstruction( false, call_ctx, ); - var mul2: DocData.WalkResult = try self.walkRef( + const mul2: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1898,7 +1898,7 @@ fn walkInstruction( false, call_ctx, ); - var add: DocData.WalkResult = try self.walkRef( + const add: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1914,7 +1914,7 @@ fn walkInstruction( const add_index = self.exprs.items.len; try self.exprs.append(self.arena, add.expr); - var type_index: usize = self.exprs.items.len; + const type_index: usize = self.exprs.items.len; try self.exprs.append(self.arena, add.typeRef orelse .{ .type = @intFromEnum(Ref.type_type) }); return DocData.WalkResult{ @@ -1933,7 +1933,7 @@ fn walkInstruction( const pl_node = data[@intFromEnum(inst)].pl_node; const extra = file.zir.extraData(Zir.Inst.UnionInit, pl_node.payload_index); - var union_type: DocData.WalkResult = try self.walkRef( + const union_type: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1941,7 +1941,7 @@ fn walkInstruction( false, call_ctx, ); - var field_name: DocData.WalkResult = try self.walkRef( + const field_name: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1949,7 +1949,7 @@ fn walkInstruction( false, call_ctx, ); - var init: DocData.WalkResult = try self.walkRef( + const init: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1980,7 +1980,7 @@ fn walkInstruction( const pl_node = data[@intFromEnum(inst)].pl_node; const extra = file.zir.extraData(Zir.Inst.BuiltinCall, pl_node.payload_index); - var modifier: DocData.WalkResult = try self.walkRef( + const modifier: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1989,7 +1989,7 @@ fn walkInstruction( call_ctx, ); - var callee: DocData.WalkResult = try self.walkRef( + const callee: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -1998,7 +1998,7 @@ fn walkInstruction( call_ctx, ); - var args: DocData.WalkResult = try self.walkRef( + const args: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -2028,7 +2028,7 @@ fn walkInstruction( const pl_node = data[@intFromEnum(inst)].pl_node; const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); - var lhs: DocData.WalkResult = try self.walkRef( + const lhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -2036,7 +2036,7 @@ fn walkInstruction( false, call_ctx, ); - var rhs: DocData.WalkResult = try self.walkRef( + const rhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -2060,7 +2060,7 @@ fn walkInstruction( const pl_node = data[@intFromEnum(inst)].pl_node; const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); - var lhs: DocData.WalkResult = try self.walkRef( + const lhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -2068,7 +2068,7 @@ fn walkInstruction( false, call_ctx, ); - var rhs: DocData.WalkResult = try self.walkRef( + const rhs: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -2090,7 +2090,7 @@ fn walkInstruction( // .elem_type => { // const un_node = data[@intFromEnum(inst)].un_node; - // var operand: DocData.WalkResult = try self.walkRef( + // const operand: DocData.WalkResult = try self.walkRef( // file, // parent_scope, parent_src, // un_node.operand, @@ -2158,7 +2158,7 @@ fn walkInstruction( address_space = ref_result.expr; extra_index += 1; } - var bit_start: ?DocData.Expr = null; + const bit_start: ?DocData.Expr = null; if (ptr.flags.has_bit_range) { const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index])); const ref_result = try self.walkRef( @@ -2292,7 +2292,7 @@ fn walkInstruction( const array_data = try self.arena.alloc(usize, operands.len - 1); std.debug.assert(operands.len > 0); - var array_type = try self.walkRef( + const array_type = try self.walkRef( file, parent_scope, parent_src, @@ -2352,7 +2352,7 @@ fn walkInstruction( const array_data = try self.arena.alloc(usize, operands.len - 1); std.debug.assert(operands.len > 0); - var array_type = try self.walkRef( + const array_type = try self.walkRef( file, parent_scope, parent_src, @@ -2578,7 +2578,7 @@ fn walkInstruction( const pl_node = data[@intFromEnum(inst)].pl_node; const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); const body = file.zir.extra[extra.end..][extra.data.body_len - 1]; - var operand: DocData.WalkResult = try self.walkRef( + const operand: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -2903,7 +2903,7 @@ fn walkInstruction( => { const un_node = data[@intFromEnum(inst)].un_node; - var operand: DocData.WalkResult = try self.walkRef( + const operand: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -2920,7 +2920,7 @@ fn walkInstruction( .struct_init_empty_ref_result => { const un_node = data[@intFromEnum(inst)].un_node; - var operand: DocData.WalkResult = try self.walkRef( + const operand: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -3937,7 +3937,7 @@ fn walkInstruction( try self.exprs.append(self.arena, last_type); const ptr_index = self.exprs.items.len; - var ptr: DocData.WalkResult = try self.walkRef( + const ptr: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -3948,7 +3948,7 @@ fn walkInstruction( try self.exprs.append(self.arena, ptr.expr); const expected_value_index = self.exprs.items.len; - var expected_value: DocData.WalkResult = try self.walkRef( + const expected_value: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -3959,7 +3959,7 @@ fn walkInstruction( try self.exprs.append(self.arena, expected_value.expr); const new_value_index = self.exprs.items.len; - var new_value: DocData.WalkResult = try self.walkRef( + const new_value: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -3970,7 +3970,7 @@ fn walkInstruction( try self.exprs.append(self.arena, new_value.expr); const success_order_index = self.exprs.items.len; - var success_order: DocData.WalkResult = try self.walkRef( + const success_order: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, @@ -3981,7 +3981,7 @@ fn walkInstruction( try self.exprs.append(self.arena, success_order.expr); const failure_order_index = self.exprs.items.len; - var failure_order: DocData.WalkResult = try self.walkRef( + const failure_order: DocData.WalkResult = try self.walkRef( file, parent_scope, parent_src, diff --git a/src/Compilation.zig b/src/Compilation.zig index 529ba9d33b1907414fce37778811688297899e3a..4917f40b29ce3e59c0432264d177eb454803de86 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1759,7 +1759,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { const digest = hash.final(); const artifact_sub_dir = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest }); - var artifact_dir = try options.local_cache_directory.handle.makeOpenPath(artifact_sub_dir, .{}); + const artifact_dir = try options.local_cache_directory.handle.makeOpenPath(artifact_sub_dir, .{}); owned_link_dir = artifact_dir; const link_artifact_directory: Directory = .{ .handle = artifact_dir, @@ -2173,7 +2173,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { // LLD might drop some symbols as unused during LTO and GCing, therefore, // we force mark them for resolution here. - var tls_index_sym = switch (comp.getTarget().cpu.arch) { + const tls_index_sym = switch (comp.getTarget().cpu.arch) { .x86 => "__tls_index", else => "_tls_index", }; @@ -2576,7 +2576,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void var artifact_dir = try comp.local_cache_directory.handle.openDir(o_sub_path, .{}); defer artifact_dir.close(); - var dir_path = try comp.local_cache_directory.join(comp.gpa, &.{o_sub_path}); + const dir_path = try comp.local_cache_directory.join(comp.gpa, &.{o_sub_path}); defer comp.gpa.free(dir_path); module.zig_cache_artifact_directory = .{ @@ -4961,7 +4961,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32 var cli_diagnostics = resinator.cli.Diagnostics.init(comp.gpa); defer cli_diagnostics.deinit(); - var options = resinator.cli.parse(comp.gpa, resinator_args.items, &cli_diagnostics) catch |err| switch (err) { + const options = resinator.cli.parse(comp.gpa, resinator_args.items, &cli_diagnostics) catch |err| switch (err) { error.ParseError => { return comp.failWin32ResourceCli(win32_resource, &cli_diagnostics); }, @@ -5062,7 +5062,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32 log.warn("failed to delete '{s}': {s}", .{ out_dep_path, @errorName(err) }); }; - var full_input = std.fs.cwd().readFileAlloc(arena, out_rcpp_path, std.math.maxInt(usize)) catch |err| switch (err) { + const full_input = std.fs.cwd().readFileAlloc(arena, out_rcpp_path, std.math.maxInt(usize)) catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, else => |e| { 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 var mapping_results = try resinator.source_mapping.parseAndRemoveLineCommands(arena, full_input, full_input, .{ .initial_filename = rc_src.src_path }); defer mapping_results.mappings.deinit(arena); - var final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); + const final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); var output_file = zig_cache_tmp_dir.createFile(out_res_path, .{}) catch |err| { return comp.failWin32Resource(win32_resource, "failed to create output file '{s}': {s}", .{ out_res_path, @errorName(err) }); diff --git a/src/Package/Fetch/git.zig b/src/Package/Fetch/git.zig index 1fdf5152d6ae7487f75255b54a53fd061db9e196..827b608cc67a46212381b2d0c645f20067c76def 100644 --- a/src/Package/Fetch/git.zig +++ b/src/Package/Fetch/git.zig @@ -83,7 +83,7 @@ pub const Repository = struct { ) !void { try repository.odb.seekOid(commit_oid); const tree_oid = tree_oid: { - var commit_object = try repository.odb.readObject(); + const commit_object = try repository.odb.readObject(); if (commit_object.type != .commit) return error.NotACommit; break :tree_oid try getCommitTree(commit_object.data); }; @@ -122,14 +122,14 @@ pub const Repository = struct { var file = try dir.createFile(entry.name, .{}); defer file.close(); try repository.odb.seekOid(entry.oid); - var file_object = try repository.odb.readObject(); + const file_object = try repository.odb.readObject(); if (file_object.type != .blob) return error.InvalidFile; try file.writeAll(file_object.data); try file.sync(); }, .symlink => { try repository.odb.seekOid(entry.oid); - var symlink_object = try repository.odb.readObject(); + const symlink_object = try repository.odb.readObject(); if (symlink_object.type != .blob) return error.InvalidFile; const link_name = symlink_object.data; dir.symLink(link_name, entry.name, .{}) catch |e| { @@ -1230,7 +1230,7 @@ fn resolveDeltaChain( const delta_offset = delta_offsets[i]; try pack.seekTo(delta_offset); const delta_header = try EntryHeader.read(pack.reader()); - var delta_data = try readObjectRaw(allocator, pack.reader(), delta_header.uncompressedLength()); + const delta_data = try readObjectRaw(allocator, pack.reader(), delta_header.uncompressedLength()); defer allocator.free(delta_data); var delta_stream = std.io.fixedBufferStream(delta_data); const delta_reader = delta_stream.reader(); @@ -1238,7 +1238,7 @@ fn resolveDeltaChain( const expanded_size = try readSizeVarInt(delta_reader); const expanded_alloc_size = std.math.cast(usize, expanded_size) orelse return error.ObjectTooLarge; - var expanded_data = try allocator.alloc(u8, expanded_alloc_size); + const expanded_data = try allocator.alloc(u8, expanded_alloc_size); errdefer allocator.free(expanded_data); var expanded_delta_stream = std.io.fixedBufferStream(expanded_data); var base_stream = std.io.fixedBufferStream(base_data); @@ -1259,7 +1259,7 @@ fn readObjectRaw(allocator: Allocator, reader: anytype, size: u64) ![]u8 { var buffered_reader = std.io.bufferedReader(reader); var decompress_stream = try std.compress.zlib.decompressStream(allocator, buffered_reader.reader()); defer decompress_stream.deinit(); - var data = try allocator.alloc(u8, alloc_size); + const data = try allocator.alloc(u8, alloc_size); errdefer allocator.free(data); try decompress_stream.reader().readNoEof(data); _ = decompress_stream.reader().readByte() catch |e| switch (e) { @@ -1290,14 +1290,14 @@ fn expandDelta(base_object: anytype, delta_reader: anytype, writer: anytype) !vo size2: bool, size3: bool, } = @bitCast(inst.value); - var offset_parts: packed struct { offset1: u8, offset2: u8, offset3: u8, offset4: u8 } = .{ + const offset_parts: packed struct { offset1: u8, offset2: u8, offset3: u8, offset4: u8 } = .{ .offset1 = if (available.offset1) try delta_reader.readByte() else 0, .offset2 = if (available.offset2) try delta_reader.readByte() else 0, .offset3 = if (available.offset3) try delta_reader.readByte() else 0, .offset4 = if (available.offset4) try delta_reader.readByte() else 0, }; const offset: u32 = @bitCast(offset_parts); - var size_parts: packed struct { size1: u8, size2: u8, size3: u8 } = .{ + const size_parts: packed struct { size1: u8, size2: u8, size3: u8 } = .{ .size1 = if (available.size1) try delta_reader.readByte() else 0, .size2 = if (available.size2) try delta_reader.readByte() else 0, .size3 = if (available.size3) try delta_reader.readByte() else 0, @@ -1414,7 +1414,7 @@ test "packfile indexing and checkout" { defer walker.deinit(); while (try walker.next()) |entry| { if (entry.kind != .file) continue; - var path = try testing.allocator.dupe(u8, entry.path); + const path = try testing.allocator.dupe(u8, entry.path); errdefer testing.allocator.free(path); mem.replaceScalar(u8, path, std.fs.path.sep, '/'); try actual_files.append(testing.allocator, path); diff --git a/src/Sema.zig b/src/Sema.zig index 9672f1bae0970dd74696b1d7259e5a515e04562f..d8f87f50e0a45f0e627ddf3147001ab9ca909a1c 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -22899,7 +22899,7 @@ fn checkSimdBinOp( const rhs_ty = sema.typeOf(uncasted_rhs); try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); - var vec_len: ?usize = if (lhs_ty.zigTypeTag(mod) == .Vector) lhs_ty.vectorLen(mod) else null; + const vec_len: ?usize = if (lhs_ty.zigTypeTag(mod) == .Vector) lhs_ty.vectorLen(mod) else null; const result_ty = try sema.resolvePeerTypes(block, src, &.{ uncasted_lhs, uncasted_rhs }, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src }, }); @@ -23286,8 +23286,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); try sema.checkVectorElemType(block, elem_ty_src, elem_ty); - var a = try sema.resolveInst(extra.a); - var b = try sema.resolveInst(extra.b); + const a = try sema.resolveInst(extra.a); + const b = try sema.resolveInst(extra.b); var mask = try sema.resolveInst(extra.mask); var mask_ty = sema.typeOf(mask); @@ -23328,7 +23328,7 @@ fn analyzeShuffle( .child = elem_ty.toIntern(), }); - var maybe_a_len = switch (sema.typeOf(a).zigTypeTag(mod)) { + const maybe_a_len = switch (sema.typeOf(a).zigTypeTag(mod)) { .Array, .Vector => sema.typeOf(a).arrayLen(mod), .Undefined => null, else => return sema.fail(block, a_src, "expected vector or array with element type '{}', found '{}'", .{ @@ -23336,7 +23336,7 @@ fn analyzeShuffle( sema.typeOf(a).fmt(sema.mod), }), }; - var maybe_b_len = switch (sema.typeOf(b).zigTypeTag(mod)) { + const maybe_b_len = switch (sema.typeOf(b).zigTypeTag(mod)) { .Array, .Vector => sema.typeOf(b).arrayLen(mod), .Undefined => null, 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 const call_src = inst_data.src(); const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; - var func = try sema.resolveInst(extra.callee); + const func = try sema.resolveInst(extra.callee); const modifier_ty = try sema.getBuiltinType("CallModifier"); const air_ref = try sema.resolveInst(extra.modifier); @@ -23859,7 +23859,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(sema.mod)}); } - var resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod)); + const resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod)); for (resolved_args, 0..) |*resolved, i| { resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(i), args_ty); } @@ -33274,8 +33274,8 @@ fn resolvePeerTypes( else => {}, } - var peer_tys = try sema.arena.alloc(?Type, instructions.len); - var peer_vals = try sema.arena.alloc(?Value, instructions.len); + const peer_tys = try sema.arena.alloc(?Type, instructions.len); + const peer_vals = try sema.arena.alloc(?Value, instructions.len); for (instructions, peer_tys, peer_vals) |inst, *ty, *val| { ty.* = sema.typeOf(inst); diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index 0e56a1cda187a0eff0eaaebbd42d946e3545c881..c52fc3391526c268658224363a61241a63a512c4 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -2648,6 +2648,11 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { // conventions var next_register: usize = 0; var next_stack_offset: u32 = 0; + // TODO: this is never assigned, which is a bug, but I don't know how this code works + // well enough to try and fix it. I *think* `next_register += next_stack_offset` is + // supposed to be `next_stack_offset += param_size` in every case where it appears. + _ = &next_stack_offset; + const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 }; for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| { diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index 40f134ec90ce6245262ceb8cdf671fc6f9cdb30e..be624c8d957bf4fc00a6077d815c4425e9a9a627 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -4481,6 +4481,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView) var next_register: usize = 0; var next_stack_offset: u32 = 0; + // TODO: this is never assigned, which is a bug, but I don't know how this code works + // well enough to try and fix it. I *think* `next_register += next_stack_offset` is + // supposed to be `next_stack_offset += param_size` in every case where it appears. + _ = &next_stack_offset; // The caller puts the argument in %o0-%o5, which becomes %i0-%i5 inside the callee. const argument_registers = switch (role) { diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 7c752490c67e77543fef2346af1cdb57be218150..da0226b54ce6ae222ca84e047be5eb2c8a415903 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -2139,7 +2139,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { const mod = func.bin_file.base.options.module.?; const child_type = func.typeOfIndex(inst).childType(mod); - var result = result: { + const result = result: { if (!child_type.isFnOrHasRuntimeBitsIgnoreComptime(mod)) { break :result try func.allocStack(Type.usize); // create pointer to void } @@ -5001,7 +5001,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { return func.finishAir(inst, try WValue.toLocal(.stack, func, elem_ty), &.{ bin_op.lhs, bin_op.rhs }); }, else => { - var stack_vec = try func.allocStack(array_ty); + const stack_vec = try func.allocStack(array_ty); try func.store(stack_vec, array, array_ty, 0); // Is a non-unrolled vector (v128) @@ -5944,7 +5944,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro rhs.free(func); }; - var bin_op = try (try func.binOp(lhs, rhs, lhs_ty, op)).toLocal(func, lhs_ty); + const bin_op = try (try func.binOp(lhs, rhs, lhs_ty, op)).toLocal(func, lhs_ty); var result = if (wasm_bits != int_info.bits) blk: { break :blk try (try func.wrapOperand(bin_op, lhs_ty)).toLocal(func, lhs_ty); } else bin_op; @@ -6335,7 +6335,7 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { const lhs_ext = try func.fpext(lhs, ty, Type.f32); const addend_ext = try func.fpext(addend, ty, Type.f32); // call to compiler-rt `fn fmaf(f32, f32, f32) f32` - var result = try func.callIntrinsic( + const result = try func.callIntrinsic( "fmaf", &.{ .f32_type, .f32_type, .f32_type }, Type.f32, diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 822ff0ec2dbef25d2d2b1b45b676fe9263fd375b..ed3863462b1d7d7112d7c68a9dd4e55170065f49 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -2181,7 +2181,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void { const ret_reg = param_regs[0]; const enum_mcv = MCValue{ .register = param_regs[1] }; - var exitlude_jump_relocs = try self.gpa.alloc(Mir.Inst.Index, enum_ty.enumFieldCount(mod)); + const exitlude_jump_relocs = try self.gpa.alloc(Mir.Inst.Index, enum_ty.enumFieldCount(mod)); defer self.gpa.free(exitlude_jump_relocs); const data_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp); diff --git a/src/arch/x86_64/Disassembler.zig b/src/arch/x86_64/Disassembler.zig index b15327fd21319e027e8c89325203d08e4102c01e..e0117fa17b7894079aecc95a90c1775aba90bd2e 100644 --- a/src/arch/x86_64/Disassembler.zig +++ b/src/arch/x86_64/Disassembler.zig @@ -234,13 +234,12 @@ fn inst(encoding: Encoding, args: struct { op3: Instruction.Operand = .none, op4: Instruction.Operand = .none, }) Instruction { - var i = Instruction{ .encoding = encoding, .prefix = args.prefix, .ops = .{ + return .{ .encoding = encoding, .prefix = args.prefix, .ops = .{ args.op1, args.op2, args.op3, args.op4, } }; - return i; } const Prefixes = struct { diff --git a/src/arch/x86_64/Lower.zig b/src/arch/x86_64/Lower.zig index b26cbe15038b74fc6257ca66ad2ed994c211567a..0c309991f6b07bf35acd8b13d01af865aba5f3dd 100644 --- a/src/arch/x86_64/Lower.zig +++ b/src/arch/x86_64/Lower.zig @@ -342,7 +342,7 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand) .Lib => lower.bin_file.options.link_mode == .Static, }; - var emit_prefix = prefix; + const emit_prefix = prefix; var emit_mnemonic = mnemonic; var emit_ops_storage: [4]Operand = undefined; const emit_ops = emit_ops_storage[0..ops.len]; diff --git a/src/arch/x86_64/encoder.zig b/src/arch/x86_64/encoder.zig index 517dd1af8dd5fe75b9f231381e22849740a3f46c..b499ccfdca1a48f21fcb15efa9a5d7a141b0d714 100644 --- a/src/arch/x86_64/encoder.zig +++ b/src/arch/x86_64/encoder.zig @@ -244,7 +244,7 @@ pub const Instruction = struct { }), }, .imm => |imm| if (enc_op.isSigned()) { - var imms = imm.asSigned(enc_op.immBitSize()); + const imms = imm.asSigned(enc_op.immBitSize()); if (imms < 0) try writer.writeByte('-'); try writer.print("0x{x}", .{@abs(imms)}); } 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 const given_fmt = try std.fmt.allocPrint(testing.allocator, "{x}", .{std.fmt.fmtSliceHexLower(given)}); defer testing.allocator.free(given_fmt); const idx = std.mem.indexOfDiff(u8, expected_fmt, given_fmt).?; - var padding = try testing.allocator.alloc(u8, idx + 5); + const padding = try testing.allocator.alloc(u8, idx + 5); defer testing.allocator.free(padding); @memset(padding, ' '); std.debug.print("\nASM: {s}\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ diff --git a/src/aro_translate_c.zig b/src/aro_translate_c.zig index a13867be30f5f76cb5b166deb1ffeb1db8dfd91a..cd9e4fa5cb310d9861d85e0b7e5392e05572eceb 100644 --- a/src/aro_translate_c.zig +++ b/src/aro_translate_c.zig @@ -346,7 +346,7 @@ fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void { defer block_scope.deinit(); var scope = &block_scope.base; - _ = scope; + _ = &scope; var param_id: c_uint = 0; for (proto_payload.data.params, fn_ty.data.func.params) |*param, param_info| { @@ -534,7 +534,7 @@ fn transFnType( ctx: FnProtoContext, ) !ZigNode { const param_count: usize = fn_ty.data.func.params.len; - var fn_params = try c.arena.alloc(ast.Payload.Param, param_count); + const fn_params = try c.arena.alloc(ast.Payload.Param, param_count); for (fn_ty.data.func.params, fn_params) |param_info, *param_node| { const param_ty = param_info.ty; diff --git a/src/codegen.zig b/src/codegen.zig index 94f1f6ea0eba5be3a8b12533597a7fced1369d6a..c624998e7bb3d1d0344a06ad174820871e3a8e61 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -368,7 +368,7 @@ pub fn generateSymbol( .bytes => |bytes| try code.appendSlice(bytes), .elems, .repeated_elem => { var index: u64 = 0; - var len_including_sentinel = + const len_including_sentinel = array_type.len + @intFromBool(array_type.sentinel != .none); while (index < len_including_sentinel) : (index += 1) { switch (try generateSymbol(bin_file, src_loc, .{ diff --git a/src/codegen/llvm/BitcodeReader.zig b/src/codegen/llvm/BitcodeReader.zig index 3232d586081c8662c4d52829334d42e40af12198..668e610a6990bd27d50882986d8e52e878a3421c 100644 --- a/src/codegen/llvm/BitcodeReader.zig +++ b/src/codegen/llvm/BitcodeReader.zig @@ -410,7 +410,7 @@ fn readVbr(bc: *BitcodeReader, comptime T: type, bits: u7) !T { var result: u64 = 0; var shift: u6 = 0; while (true) { - var chunk = try bc.readFixed(u64, bits); + const chunk = try bc.readFixed(u64, bits); result |= (chunk & (chunk_msb - 1)) << shift; if (chunk & chunk_msb == 0) break; shift += chunk_bits; diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index dcb3329c571f6880ae8fe4678c95c43d8de67ce0..8bee639b60b0d96dfffa9d5b81688f392c354837 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -1284,7 +1284,7 @@ const DeclGen = struct { const elem_ty = ty.childType(mod); const elem_ty_ref = try self.resolveType(elem_ty, .indirect); - var total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel(mod)) orelse { + const total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel(mod)) orelse { return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(mod)}); }; const ty_ref = if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) blk: { @@ -2115,7 +2115,7 @@ const DeclGen = struct { const child_ty = ty.childType(mod); const vector_len = ty.vectorLen(mod); - var constituents = try self.gpa.alloc(IdRef, vector_len); + const constituents = try self.gpa.alloc(IdRef, vector_len); defer self.gpa.free(constituents); for (constituents, 0..) |*constituent, i| { @@ -2312,7 +2312,7 @@ const DeclGen = struct { if (ty.isVector(mod)) { const child_ty = ty.childType(mod); const vector_len = ty.vectorLen(mod); - var constituents = try self.gpa.alloc(IdRef, vector_len); + const constituents = try self.gpa.alloc(IdRef, vector_len); defer self.gpa.free(constituents); for (constituents, 0..) |*constituent, i| { @@ -2727,7 +2727,7 @@ const DeclGen = struct { const child_ty = ty.childType(mod); const vector_len = ty.vectorLen(mod); - var constituents = try self.gpa.alloc(IdRef, vector_len); + const constituents = try self.gpa.alloc(IdRef, vector_len); defer self.gpa.free(constituents); for (constituents, 0..) |*constituent, i| { diff --git a/src/link/C.zig b/src/link/C.zig index 40dfc0771d69a69d9ae4cd271583936bb2652174..f97f19f85bb6278c6ef6b5d38da4f7d058cf4f8e 100644 --- a/src/link/C.zig +++ b/src/link/C.zig @@ -103,7 +103,7 @@ pub fn openPath(gpa: Allocator, sub_path: []const u8, options: link.Options) !*C }); errdefer file.close(); - var c_file = try gpa.create(C); + const c_file = try gpa.create(C); errdefer gpa.destroy(c_file); c_file.* = .{ diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 0d26e24b2db103ca194b040aabb528c76b3ee7cf..16736ab1af83f0830cb6931547f31903518851b7 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -563,7 +563,7 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme // First we look for an appropriately sized free list node. // The list is unordered. We'll just take the first thing that works. - var vaddr = blk: { + const vaddr = blk: { var i: usize = 0; while (i < free_list.items.len) { const big_atom_index = free_list.items[i]; @@ -815,7 +815,7 @@ fn writeAtom(self: *Coff, atom_index: Atom.Index, code: []u8) !void { } fn debugMem(allocator: Allocator, handle: std.ChildProcess.Id, pvaddr: std.os.windows.LPVOID, code: []const u8) !void { - var buffer = try allocator.alloc(u8, code.len); + const buffer = try allocator.alloc(u8, code.len); defer allocator.free(buffer); const memread = try std.os.windows.ReadProcessMemory(handle, pvaddr, buffer); 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: &code_buffer, .none, ); - var code = switch (res) { + const code = switch (res) { .ok => code_buffer.items, .fail => |em| { decl.analysis = .codegen_failure; @@ -1132,7 +1132,7 @@ fn lowerConst(self: *Coff, name: []const u8, tv: TypedValue, required_alignment: const res = try codegen.generateSymbol(&self.base, src_loc, tv, &code_buffer, .none, .{ .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, }); - var code = switch (res) { + const code = switch (res) { .ok => code_buffer.items, .fail => |em| return .{ .fail = em }, }; @@ -1196,7 +1196,7 @@ pub fn updateDecl( }, &code_buffer, .none, .{ .parent_atom_index = atom.getSymbolIndex().?, }); - var code = switch (res) { + const code = switch (res) { .ok => code_buffer.items, .fail => |em| { decl.analysis = .codegen_failure; diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 385f09c2fc3d7d7df0f285919835f42b560a80ee..8c889fa30d48765953126787e27e384133115598 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -303,7 +303,7 @@ pub const DeclState = struct { // DW.AT.name, DW.FORM.string try dbg_info_buffer.writer().print("{d}\x00", .{field_index}); // DW.AT.type, DW.FORM.ref4 - var index = dbg_info_buffer.items.len; + const index = dbg_info_buffer.items.len; try dbg_info_buffer.resize(index + 4); try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); // DW.AT.data_member_location, DW.FORM.udata @@ -329,7 +329,7 @@ pub const DeclState = struct { // DW.AT.name, DW.FORM.string try dbg_info_buffer.writer().print("{d}\x00", .{field_index}); // DW.AT.type, DW.FORM.ref4 - var index = dbg_info_buffer.items.len; + const index = dbg_info_buffer.items.len; try dbg_info_buffer.resize(index + 4); try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); // DW.AT.data_member_location, DW.FORM.udata @@ -350,7 +350,7 @@ pub const DeclState = struct { dbg_info_buffer.appendSliceAssumeCapacity(field_name); dbg_info_buffer.appendAssumeCapacity(0); // DW.AT.type, DW.FORM.ref4 - var index = dbg_info_buffer.items.len; + const index = dbg_info_buffer.items.len; try dbg_info_buffer.resize(index + 4); try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); // DW.AT.data_member_location, DW.FORM.udata diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 3883f76268fbaeb42e7faa34f47b1df7343a0d20..e64ad222ad85b50fc6f849f3e64f4683c808500c 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -967,7 +967,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node // --verbose-link if (self.base.options.verbose_link) try self.dumpArgv(comp); - var csu = try CsuObjects.init(arena, self.base.options, comp); + const csu = try CsuObjects.init(arena, self.base.options, comp); const compiler_rt_path: ?[]const u8 = blk: { if (comp.compiler_rt_lib) |x| break :blk x.full_object_path; if (comp.compiler_rt_obj) |x| break :blk x.full_object_path; @@ -1493,7 +1493,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { } else null; const gc_sections = self.base.options.gc_sections orelse false; - var csu = try CsuObjects.init(arena, self.base.options, comp); + const csu = try CsuObjects.init(arena, self.base.options, comp); const compiler_rt_path: ?[]const u8 = blk: { if (comp.compiler_rt_lib) |x| break :blk x.full_object_path; 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 try argv.append(full_out_path); // csu prelude - var csu = try CsuObjects.init(arena, self.base.options, comp); + const csu = try CsuObjects.init(arena, self.base.options, comp); if (csu.crt0) |v| try argv.append(v); if (csu.crti) |v| try argv.append(v); if (csu.crtbegin) |v| try argv.append(v); @@ -3852,7 +3852,7 @@ fn sortPhdrs(self: *Elf) error{OutOfMemory}!void { backlinks[entry.phndx] = @as(u16, @intCast(i)); } - var slice = try self.phdrs.toOwnedSlice(gpa); + const slice = try self.phdrs.toOwnedSlice(gpa); defer gpa.free(slice); try self.phdrs.ensureTotalCapacityPrecise(gpa, slice.len); @@ -3957,7 +3957,7 @@ fn sortShdrs(self: *Elf) !void { backlinks[entry.shndx] = @as(u16, @intCast(i)); } - var slice = try self.shdrs.toOwnedSlice(gpa); + const slice = try self.shdrs.toOwnedSlice(gpa); defer gpa.free(slice); try self.shdrs.ensureTotalCapacityPrecise(gpa, slice.len); diff --git a/src/link/Elf/eh_frame.zig b/src/link/Elf/eh_frame.zig index 73857d03d2527470527845468a7e98eda0b6bc6c..1d24285b30c024ac747848d69c3c6da5d6bd86c8 100644 --- a/src/link/Elf/eh_frame.zig +++ b/src/link/Elf/eh_frame.zig @@ -217,7 +217,7 @@ pub const Iterator = struct { var stream = std.io.fixedBufferStream(it.data[it.pos..]); const reader = stream.reader(); - var size = try reader.readInt(u32, .little); + const size = try reader.readInt(u32, .little); if (size == 0xFFFFFFFF) @panic("TODO"); const id = try reader.readInt(u32, .little); diff --git a/src/link/MachO.zig b/src/link/MachO.zig index f0938a3c1962ce0cbea1537cd865661be3c03cc0..67c9aaac05e7a99862a5e818d29e67e86cbf5377 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -2252,7 +2252,7 @@ pub fn updateFunc(self: *MachO, mod: *Module, func_index: InternPool.Index, air: else try codegen.generateFunction(&self.base, decl.srcLoc(mod), func_index, air, liveness, &code_buffer, .none); - var code = switch (res) { + const code = switch (res) { .ok => code_buffer.items, .fail => |em| { decl.analysis = .codegen_failure; @@ -2332,7 +2332,7 @@ fn lowerConst( const res = try codegen.generateSymbol(&self.base, src_loc, tv, &code_buffer, .none, .{ .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, }); - var code = switch (res) { + const code = switch (res) { .ok => code_buffer.items, .fail => |em| return .{ .fail = em }, }; @@ -2418,7 +2418,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo .parent_atom_index = sym_index, }); - var code = switch (res) { + const code = switch (res) { .ok => code_buffer.items, .fail => |em| { decl.analysis = .codegen_failure; @@ -2587,7 +2587,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D .parent_atom_index = init_sym_index, }); - var code = switch (res) { + const code = switch (res) { .ok => code_buffer.items, .fail => |em| { decl.analysis = .codegen_failure; @@ -3427,7 +3427,7 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm // First we look for an appropriately sized free list node. // The list is unordered. We'll just take the first thing that works. - var vaddr = blk: { + const vaddr = blk: { var i: usize = 0; while (i < free_list.items.len) { const big_atom_index = free_list.items[i]; @@ -3971,7 +3971,7 @@ fn writeDyldInfoData(self: *MachO) !void { link_seg.filesize = needed_size; assert(mem.isAlignedGeneric(u64, link_seg.fileoff + link_seg.filesize, @alignOf(u64))); - var buffer = try gpa.alloc(u8, needed_size); + const buffer = try gpa.alloc(u8, needed_size); defer gpa.free(buffer); @memset(buffer, 0); @@ -5228,7 +5228,7 @@ fn reportMissingLibraryError( ) error{OutOfMemory}!void { const gpa = self.base.allocator; try self.misc_errors.ensureUnusedCapacity(gpa, 1); - var notes = try gpa.alloc(File.ErrorMsg, checked_paths.len); + const notes = try gpa.alloc(File.ErrorMsg, checked_paths.len); errdefer gpa.free(notes); for (checked_paths, notes) |path, *note| { note.* = .{ .msg = try std.fmt.allocPrint(gpa, "tried {s}", .{path}) }; diff --git a/src/link/MachO/Archive.zig b/src/link/MachO/Archive.zig index 6bdc6d916d6bd41c90bb49592104c658bd55f7c7..ba3915f51b285f7515bcf45deeb7fdbafb97da8a 100644 --- a/src/link/MachO/Archive.zig +++ b/src/link/MachO/Archive.zig @@ -98,7 +98,7 @@ pub fn parse(self: *Archive, allocator: Allocator, reader: anytype) !void { _ = try reader.readBytesNoEof(SARMAG); self.header = try reader.readStruct(ar_hdr); const name_or_length = try self.header.nameOrLength(); - var embedded_name = try parseName(allocator, name_or_length, reader); + const embedded_name = try parseName(allocator, name_or_length, reader); log.debug("parsing archive '{s}' at '{s}'", .{ embedded_name, self.name }); defer allocator.free(embedded_name); @@ -124,7 +124,7 @@ fn parseName(allocator: Allocator, name_or_length: ar_hdr.NameOrLength, reader: fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !void { const symtab_size = try reader.readInt(u32, .little); - var symtab = try allocator.alloc(u8, symtab_size); + const symtab = try allocator.alloc(u8, symtab_size); defer allocator.free(symtab); reader.readNoEof(symtab) catch { @@ -133,7 +133,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! }; const strtab_size = try reader.readInt(u32, .little); - var strtab = try allocator.alloc(u8, strtab_size); + const strtab = try allocator.alloc(u8, strtab_size); defer allocator.free(strtab); reader.readNoEof(strtab) catch { diff --git a/src/link/MachO/Dylib.zig b/src/link/MachO/Dylib.zig index 91411dc572d862b2f9c00c94ef3c92cc77ed45b3..65d503b1ae230d35165029ec1e760d561eabc46e 100644 --- a/src/link/MachO/Dylib.zig +++ b/src/link/MachO/Dylib.zig @@ -167,7 +167,7 @@ pub fn parseFromBinary( .REEXPORT_DYLIB => { if (should_lookup_reexports) { // Parse install_name to dependent dylib. - var id = try Id.fromLoadCommand( + const id = try Id.fromLoadCommand( allocator, cmd.cast(macho.dylib_command).?, cmd.getDylibPathName(), @@ -410,7 +410,7 @@ pub fn parseFromStub( log.debug(" (found re-export '{s}')", .{lib}); - var dep_id = try Id.default(allocator, lib); + const dep_id = try Id.default(allocator, lib); try dependent_libs.writeItem(.{ .id = dep_id, .parent = dylib_id }); } } @@ -527,7 +527,7 @@ pub fn parseFromStub( log.debug(" (found re-export '{s}')", .{lib}); - var dep_id = try Id.default(allocator, lib); + const dep_id = try Id.default(allocator, lib); try dependent_libs.writeItem(.{ .id = dep_id, .parent = dylib_id }); } } diff --git a/src/link/MachO/Trie.zig b/src/link/MachO/Trie.zig index d86338f84b5e543f157d3cfadebfe54582b76960..98add0315cf943757e0e08ae3d896ae93d406b19 100644 --- a/src/link/MachO/Trie.zig +++ b/src/link/MachO/Trie.zig @@ -150,7 +150,7 @@ pub fn deinit(self: *Trie, allocator: Allocator) void { } test "Trie node count" { - var gpa = testing.allocator; + const gpa = testing.allocator; var trie: Trie = .{}; defer trie.deinit(gpa); try trie.init(gpa); @@ -196,7 +196,7 @@ test "Trie node count" { } test "Trie basic" { - var gpa = testing.allocator; + const gpa = testing.allocator; var trie: Trie = .{}; defer trie.deinit(gpa); try trie.init(gpa); @@ -254,7 +254,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void { const given_fmt = try std.fmt.allocPrint(testing.allocator, "{x}", .{std.fmt.fmtSliceHexLower(given)}); defer testing.allocator.free(given_fmt); const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?; - var padding = try testing.allocator.alloc(u8, idx + 5); + const padding = try testing.allocator.alloc(u8, idx + 5); defer testing.allocator.free(padding); @memset(padding, ' '); 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" { 0x3, 0x0, 0x80, 0x20, 0x0, // terminal node }; - var buffer = try gpa.alloc(u8, trie.size); + const buffer = try gpa.alloc(u8, trie.size); defer gpa.free(buffer); var stream = std.io.fixedBufferStream(buffer); { @@ -331,7 +331,7 @@ test "parse Trie from byte stream" { try trie.finalize(gpa); - var out_buffer = try gpa.alloc(u8, trie.size); + const out_buffer = try gpa.alloc(u8, trie.size); defer gpa.free(out_buffer); var out_stream = std.io.fixedBufferStream(out_buffer); _ = try trie.write(out_stream.writer()); @@ -362,7 +362,7 @@ test "ordering bug" { 0x00, 0x12, 0x03, 0x00, 0xD8, 0x0A, 0x00, }; - var buffer = try gpa.alloc(u8, trie.size); + const buffer = try gpa.alloc(u8, trie.size); defer gpa.free(buffer); var stream = std.io.fixedBufferStream(buffer); // Writing finalized trie again should yield the same result. @@ -426,7 +426,7 @@ pub const Node = struct { // To: A -> C -> B const mid = try allocator.create(Node); mid.* = .{ .base = self.base }; - var to_label = try allocator.dupe(u8, edge.label[match..]); + const to_label = try allocator.dupe(u8, edge.label[match..]); allocator.free(edge.label); const to_node = edge.to; edge.to = mid; @@ -573,7 +573,7 @@ pub const Node = struct { /// Updates offset of this node in the output byte stream. fn finalize(self: *Node, offset_in_trie: u64) !FinalizeResult { var stream = std.io.countingWriter(std.io.null_writer); - var writer = stream.writer(); + const writer = stream.writer(); var node_size: u64 = 0; if (self.terminal_info) |info| { diff --git a/src/link/MachO/UnwindInfo.zig b/src/link/MachO/UnwindInfo.zig index c588b65ea3b7c9126c97d31826840508b12a258a..be6c9dbb34538c0adf4135fa03071f07eab5b104 100644 --- a/src/link/MachO/UnwindInfo.zig +++ b/src/link/MachO/UnwindInfo.zig @@ -417,7 +417,7 @@ pub fn collect(info: *UnwindInfo, macho_file: *MachO) !void { gop.value_ptr.count += 1; } - var slice = common_encodings_counts.values(); + const slice = common_encodings_counts.values(); mem.sort(CommonEncWithCount, slice, {}, CommonEncWithCount.greaterThan); var i: u7 = 0; diff --git a/src/link/MachO/eh_frame.zig b/src/link/MachO/eh_frame.zig index 189d9b25cdd49c254e79901fab7c3d3b217989c8..0f021a569cc1ada45aa4054a2af40107cc4af166 100644 --- a/src/link/MachO/eh_frame.zig +++ b/src/link/MachO/eh_frame.zig @@ -586,7 +586,7 @@ pub const Iterator = struct { var stream = std.io.fixedBufferStream(it.data[it.pos..]); const reader = stream.reader(); - var size = try reader.readInt(u32, .little); + const size = try reader.readInt(u32, .little); if (size == 0xFFFFFFFF) { log.debug("MachO doesn't support 64bit DWARF CFI __eh_frame records", .{}); return error.BadDwarfCfi; diff --git a/src/link/MachO/load_commands.zig b/src/link/MachO/load_commands.zig index 669e806728d45ddb8dc6350e84aa32f0a098ab65..f06441573997c78f0ba7a44fd90b7dc802f55da0 100644 --- a/src/link/MachO/load_commands.zig +++ b/src/link/MachO/load_commands.zig @@ -112,7 +112,7 @@ pub fn calcMinHeaderPad(gpa: Allocator, options: *const link.Options, ctx: CalcL log.debug("minimum requested headerpad size 0x{x}", .{padding + @sizeOf(macho.mach_header_64)}); if (options.headerpad_max_install_names) { - var min_headerpad_size: u32 = try calcLCsSize(gpa, options, ctx, true); + const min_headerpad_size: u32 = try calcLCsSize(gpa, options, ctx, true); log.debug("headerpad_max_install_names minimum headerpad size 0x{x}", .{ min_headerpad_size + @sizeOf(macho.mach_header_64), }); diff --git a/src/link/MachO/zld.zig b/src/link/MachO/zld.zig index 79433b3b1ba9a23d3ccbca36e1392de8998511f0..e627b91f11dae5f6e305c53a3992dcd42649118c 100644 --- a/src/link/MachO/zld.zig +++ b/src/link/MachO/zld.zig @@ -503,7 +503,7 @@ pub fn linkWithZld( const size = math.cast(usize, linkedit.fileoff - start) orelse return error.Overflow; if (size > 0) { log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start }); - var padding = try gpa.alloc(u8, size); + const padding = try gpa.alloc(u8, size); defer gpa.free(padding); @memset(padding, 0); try macho_file.base.file.?.pwriteAll(padding, start); diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig index d8b6f39f7632ecc652211d9e71a2d2ba7b43cb8c..4221aa7dee27f36820dc019c27cc41063c28a08d 100644 --- a/src/link/Plan9.zig +++ b/src/link/Plan9.zig @@ -300,7 +300,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Plan9 { else => return error.UnsupportedP9Architecture, }; - var arena_allocator = std.heap.ArenaAllocator.init(gpa); + const arena_allocator = std.heap.ArenaAllocator.init(gpa); const self = try gpa.create(Plan9); self.* = .{ @@ -467,7 +467,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I const sym_index = try self.allocateSymbolIndex(); const new_atom_idx = try self.createAtom(); - var info: Atom = .{ + const info: Atom = .{ .type = .d, .offset = null, .sym_index = sym_index, @@ -496,7 +496,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: Module.Decl.I }, }; // duped_code is freed when the unnamed const is freed - var duped_code = try self.base.allocator.dupe(u8, code); + const duped_code = try self.base.allocator.dupe(u8, code); errdefer self.base.allocator.free(duped_code); const new_atom = self.getAtomPtr(new_atom_idx); new_atom.* = info; @@ -1024,7 +1024,7 @@ pub fn freeDecl(self: *Plan9, decl_index: Module.Decl.Index) void { const decl = mod.declPtr(decl_index); const is_fn = decl.val.isFuncBody(mod); if (is_fn) { - var symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(mod)).?; + const symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(mod)).?; var submap = symidx_and_submap.functions; if (submap.fetchSwapRemove(decl_index)) |removed_entry| { self.base.allocator.free(removed_entry.value.code); @@ -1204,7 +1204,7 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind }, }; // duped_code is freed when the atom is freed - var duped_code = try self.base.allocator.dupe(u8, code); + const duped_code = try self.base.allocator.dupe(u8, code); errdefer self.base.allocator.free(duped_code); self.getAtomPtr(atom_index).code = .{ .code_ptr = duped_code.ptr, @@ -1489,7 +1489,7 @@ pub fn lowerAnonDecl(self: *Plan9, decl_val: InternPool.Index, src_loc: Module.S // to put it in some location. // ... const gpa = self.base.allocator; - var gop = try self.anon_decls.getOrPut(gpa, decl_val); + const gop = try self.anon_decls.getOrPut(gpa, decl_val); const mod = self.base.options.module.?; if (!gop.found_existing) { const ty = mod.intern_pool.typeOf(decl_val).toType(); diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 2677184c12ee285e8376ef5c45bc251901c46a2f..da8753ac29f9e0b8dde7bbb39941e57b9184e8ce 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -860,7 +860,7 @@ fn resolveSymbolsInArchives(wasm: *Wasm) !void { // Parse object and and resolve symbols again before we check remaining // undefined symbols. const object_file_index = @as(u16, @intCast(wasm.objects.items.len)); - var object = try archive.parseObject(wasm.base.allocator, offset.items[0]); + const object = try archive.parseObject(wasm.base.allocator, offset.items[0]); try wasm.objects.append(wasm.base.allocator, object); try wasm.resolveSymbolsInObject(object_file_index); @@ -1344,7 +1344,7 @@ pub fn deinit(wasm: *Wasm) void { /// Will re-use slots when a symbol was freed at an earlier stage. pub fn allocateSymbol(wasm: *Wasm) !u32 { try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1); - var symbol: Symbol = .{ + const symbol: Symbol = .{ .name = std.math.maxInt(u32), // will be set after updateDecl as well as during atom creation for decls .flags = @intFromEnum(Symbol.Flag.WASM_SYM_BINDING_LOCAL), .tag = .undefined, // will be set after updateDecl @@ -1655,7 +1655,7 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !u3 symbol.setUndefined(true); const sym_index = if (wasm.symbols_free_list.popOrNull()) |index| index else blk: { - var index = @as(u32, @intCast(wasm.symbols.items.len)); + const index: u32 = @intCast(wasm.symbols.items.len); try wasm.symbols.ensureUnusedCapacity(wasm.base.allocator, 1); wasm.symbols.items.len += 1; break :blk index; @@ -2632,7 +2632,7 @@ fn setupImports(wasm: *Wasm) !void { // We copy the import to a new import to ensure the names contain references // to the internal string table, rather than of the object file. - var new_imp: types.Import = .{ + const new_imp: types.Import = .{ .module_name = try wasm.string_table.put(wasm.base.allocator, object.string_table.get(import.module_name)), .name = try wasm.string_table.put(wasm.base.allocator, object.string_table.get(import.name)), .kind = import.kind, @@ -3800,7 +3800,7 @@ fn writeToFile( const table_loc = wasm.findGlobalSymbol("__indirect_function_table").?; const table_sym = table_loc.getSymbol(wasm); - var flags: u32 = if (table_sym.index == 0) 0x0 else 0x02; // passive with implicit 0-index table or set table index manually + const flags: u32 = if (table_sym.index == 0) 0x0 else 0x02; // passive with implicit 0-index table or set table index manually try leb.writeULEB128(binary_writer, flags); if (flags == 0x02) { try leb.writeULEB128(binary_writer, table_sym.index); diff --git a/src/link/Wasm/Object.zig b/src/link/Wasm/Object.zig index 359ff20d945415d6291c4efaef4eb51f22f91350..4f5dae8c09a462581651687d2df36943f7ec466e 100644 --- a/src/link/Wasm/Object.zig +++ b/src/link/Wasm/Object.zig @@ -252,7 +252,7 @@ fn checkLegacyIndirectFunctionTable(object: *Object) !?Symbol { return error.MissingTableSymbols; } - var table_import: types.Import = for (object.imports) |imp| { + const table_import: types.Import = for (object.imports) |imp| { if (imp.kind == .table) { break imp; } @@ -512,7 +512,7 @@ fn Parser(comptime ReaderType: type) type { try assertEnd(reader); }, .code => { - var start = reader.context.bytes_left; + const start = reader.context.bytes_left; var index: u32 = 0; const count = try readLeb(u32, reader); while (index < count) : (index += 1) { @@ -532,7 +532,7 @@ fn Parser(comptime ReaderType: type) type { } }, .data => { - var start = reader.context.bytes_left; + const start = reader.context.bytes_left; var index: u32 = 0; const count = try readLeb(u32, reader); while (index < count) : (index += 1) { diff --git a/src/link/tapi/yaml.zig b/src/link/tapi/yaml.zig index 5e3602f620cb9ef9dc035160ae42be3ea3cdc912..7afa229401c5728cbd30c91cabcfb94e6853a56d 100644 --- a/src/link/tapi/yaml.zig +++ b/src/link/tapi/yaml.zig @@ -491,7 +491,7 @@ pub fn stringify(allocator: Allocator, input: anytype, writer: anytype) !void { var arena = ArenaAllocator.init(allocator); defer arena.deinit(); - var maybe_value = try Value.encode(arena.allocator(), input); + const maybe_value = try Value.encode(arena.allocator(), input); if (maybe_value) |value| { // TODO should we output as an explicit doc? diff --git a/src/main.zig b/src/main.zig index 7c451c242be0476f58d32f3681e934fad57a050b..6bab14df567ccc8225940fa8466ebcc976675de7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4479,7 +4479,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { try stdout_writer.writeByte('\n'); } - var full_input = full_input: { + const full_input = full_input: { if (options.preprocess != .no) { if (!build_options.have_llvm) { fatal("clang not available: compiler built without LLVM extensions", .{}); @@ -4526,7 +4526,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { } if (process.can_spawn) { - var result = std.ChildProcess.run(.{ + const result = std.ChildProcess.run(.{ .allocator = gpa, .argv = argv.items, .max_output_bytes = std.math.maxInt(u32), @@ -4593,7 +4593,7 @@ fn cmdRc(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { var mapping_results = try resinator.source_mapping.parseAndRemoveLineCommands(gpa, full_input, full_input, .{ .initial_filename = options.input_filename }); defer mapping_results.mappings.deinit(gpa); - var final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); + const final_input = resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); var output_file = std.fs.cwd().createFile(options.output_filename, .{}) catch |err| { 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 { const libc_installation: ?*LibCInstallation = libc: { if (input_file) |libc_file| { - var libc = try arena.create(LibCInstallation); + const libc = try arena.create(LibCInstallation); libc.* = LibCInstallation.parse(arena, libc_file, cross_target) catch |err| { fatal("unable to parse libc file at path {s}: {s}", .{ libc_file, @errorName(err) }); }; @@ -4781,7 +4781,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void { const target = cross_target.toTarget(); const is_native_abi = cross_target.isNativeAbi(); - var libc_dirs = Compilation.detectLibCIncludeDirs( + const libc_dirs = Compilation.detectLibCIncludeDirs( arena, zig_lib_directory.path.?, target, @@ -4960,7 +4960,7 @@ pub const usage_build = pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { const work_around_btrfs_bug = builtin.os.tag == .linux and EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); - var color: Color = .auto; + const color: Color = .auto; // We want to release all the locks before executing the child process, so we make a nice // 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, /// Initialize the arguments from a Response File. "*.rsp" fn initArgIteratorResponseFile(allocator: Allocator, resp_file_path: []const u8) !ArgIteratorResponseFile { const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit - var cmd_line = try fs.cwd().readFileAlloc(allocator, resp_file_path, max_bytes); + const cmd_line = try fs.cwd().readFileAlloc(allocator, resp_file_path, max_bytes); errdefer allocator.free(cmd_line); return ArgIteratorResponseFile.initTakeOwnership(allocator, cmd_line); diff --git a/src/resinator/bmp.zig b/src/resinator/bmp.zig index 1c7e0f6aaddcfd9e1209110753b75a628396105c..134ee81966c2a4ca194a11a8eefde62d93b52bff 100644 --- a/src/resinator/bmp.zig +++ b/src/resinator/bmp.zig @@ -120,7 +120,7 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { var dib_header_buf: [@sizeOf(BITMAPCOREHEADER)]u8 align(@alignOf(BITMAPCOREHEADER)) = undefined; std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .little); reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; - var dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf); + const dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf); structFieldsLittleToNative(BITMAPCOREHEADER, dib_header); // > The size of the color palette is calculated from the BitsPerPixel value. diff --git a/src/resinator/cli.zig b/src/resinator/cli.zig index 50dbed5ad69d8a6b742e61a33ca619278f6b7b3a..7fb6573c22a83341e50fd41263ca48386f512f53 100644 --- a/src/resinator/cli.zig +++ b/src/resinator/cli.zig @@ -163,15 +163,15 @@ pub const Options = struct { // we shouldn't change anything. if (val_ptr.* == .undefine) return; // Otherwise, the new value takes precedence. - var duped_value = try self.allocator.dupe(u8, value); + const duped_value = try self.allocator.dupe(u8, value); errdefer self.allocator.free(duped_value); val_ptr.deinit(self.allocator); val_ptr.* = .{ .define = duped_value }; return; } - var duped_key = try self.allocator.dupe(u8, identifier); + const duped_key = try self.allocator.dupe(u8, identifier); errdefer self.allocator.free(duped_key); - var duped_value = try self.allocator.dupe(u8, value); + const duped_value = try self.allocator.dupe(u8, value); errdefer self.allocator.free(duped_value); try self.symbols.put(self.allocator, duped_key, .{ .define = duped_value }); } @@ -183,7 +183,7 @@ pub const Options = struct { action.* = .{ .undefine = {} }; return; } - var duped_key = try self.allocator.dupe(u8, identifier); + const duped_key = try self.allocator.dupe(u8, identifier); errdefer self.allocator.free(duped_key); try self.symbols.put(self.allocator, duped_key, .{ .undefine = {} }); } @@ -828,7 +828,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn } } - var positionals = args[arg_i..]; + const positionals = args[arg_i..]; if (positionals.len < 1) { var err_details = Diagnostics.ErrorDetails{ .print_args = false, .arg_index = arg_i }; diff --git a/src/resinator/code_pages.zig b/src/resinator/code_pages.zig index 4b9a87ce7a5547593f8807728d93859687b05b78..be89ed3f02c7a4758afd3adca64968ed318df5eb 100644 --- a/src/resinator/code_pages.zig +++ b/src/resinator/code_pages.zig @@ -302,8 +302,8 @@ pub const Utf8 = struct { pub fn decode(bytes: []const u8) Codepoint { std.debug.assert(bytes.len > 0); - var first_byte = bytes[0]; - var expected_len = sequenceLength(first_byte) orelse { + const first_byte = bytes[0]; + const expected_len = sequenceLength(first_byte) orelse { return .{ .value = Codepoint.invalid, .byte_len = 1 }; }; if (expected_len == 1) return .{ .value = first_byte, .byte_len = 1 }; @@ -367,7 +367,7 @@ pub const Utf8 = struct { test "Utf8.WellFormedDecoder" { const invalid_utf8 = "\xF0\x80"; - var decoded = Utf8.WellFormedDecoder.decode(invalid_utf8); + const decoded = Utf8.WellFormedDecoder.decode(invalid_utf8); try std.testing.expectEqual(Codepoint.invalid, decoded.value); try std.testing.expectEqual(@as(usize, 2), decoded.byte_len); } diff --git a/src/resinator/comments.zig b/src/resinator/comments.zig index cfb27ae34174524b60bc8396e5e43326c483c4a0..a631b8bb9384f75d66ea2e1499d9e92f0eb64ba0 100644 --- a/src/resinator/comments.zig +++ b/src/resinator/comments.zig @@ -206,9 +206,9 @@ inline fn handleMultilineCarriageReturn( } pub fn removeCommentsAlloc(allocator: Allocator, source: []const u8, source_mappings: ?*SourceMappings) ![]u8 { - var buf = try allocator.alloc(u8, source.len); + const buf = try allocator.alloc(u8, source.len); errdefer allocator.free(buf); - var result = removeComments(source, buf, source_mappings); + const result = removeComments(source, buf, source_mappings); return allocator.realloc(buf, result.len); } @@ -326,7 +326,7 @@ test "remove comments with mappings" { try mappings.set(allocator, 3, .{ .start_line = 3, .end_line = 3, .filename_offset = 0 }); defer mappings.deinit(allocator); - var result = removeComments(&mut_source, &mut_source, &mappings); + const result = removeComments(&mut_source, &mut_source, &mappings); try std.testing.expectEqualStrings("blahblah", result); try std.testing.expectEqual(@as(usize, 1), mappings.mapping.items.len); @@ -335,6 +335,6 @@ test "remove comments with mappings" { test "in place" { var mut_source = "blah /* comment */ blah".*; - var result = removeComments(&mut_source, &mut_source, null); + const result = removeComments(&mut_source, &mut_source, null); try std.testing.expectEqualStrings("blah blah", result); } diff --git a/src/resinator/compile.zig b/src/resinator/compile.zig index ae0232a7372d348143ea654a67292c02ad563073..2f768b2b3108a95586aee68be9fed5ddb4f00a93 100644 --- a/src/resinator/compile.zig +++ b/src/resinator/compile.zig @@ -666,7 +666,7 @@ pub const Compiler = struct { }, }, .dib => { - var bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes)); + const bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes)); if (native_endian == .big) { std.mem.byteSwapAllFields(ico.BitmapHeader, bitmap_header); } @@ -1773,13 +1773,13 @@ pub const Compiler = struct { } try data_writer.writeByteNTimes(0, num_padding); - var style = if (control.style) |style_expression| + const style = if (control.style) |style_expression| // Certain styles are implied by the control type evaluateFlagsExpressionWithDefault(res.ControlClass.getImpliedStyle(control_type), style_expression, self.source, self.input_code_pages) else res.ControlClass.getImpliedStyle(control_type); - var exstyle = if (control.exstyle) |exstyle_expression| + const exstyle = if (control.exstyle) |exstyle_expression| evaluateFlagsExpressionWithDefault(0, exstyle_expression, self.source, self.input_code_pages) else 0; @@ -3205,7 +3205,7 @@ pub const StringTable = struct { const trimmed_string = trim: { // Two NUL characters in a row act as a terminator // Note: This is only the case for STRINGTABLE strings - var trimmed = trimToDoubleNUL(u16, utf16_string); + const trimmed = trimToDoubleNUL(u16, utf16_string); // We also want to trim any trailing NUL characters break :trim std.mem.trimRight(u16, trimmed, &[_]u16{0}); }; diff --git a/src/resinator/lang.zig b/src/resinator/lang.zig index d43380fa052b0c8e9e5e34b939206ddeac0ef2cd..513d775bae39613655a384b81d52c569f84ab5ab 100644 --- a/src/resinator/lang.zig +++ b/src/resinator/lang.zig @@ -98,7 +98,7 @@ pub fn tagToId(tag: []const u8) error{InvalidLanguageTag}!?LanguageId { var normalized_buf: [longest_known_tag]u8 = undefined; // To allow e.g. `de-de_phoneb` to get looked up as `de-de`, we need to // omit the suffix, but only if the tag contains a valid alternate sort order. - var tag_to_normalize = if (parsed.isSuffixValidSortOrder()) tag[0 .. tag.len - (parsed.suffix.?.len + 1)] else tag; + const tag_to_normalize = if (parsed.isSuffixValidSortOrder()) tag[0 .. tag.len - (parsed.suffix.?.len + 1)] else tag; const normalized_tag = normalizeTag(tag_to_normalize, &normalized_buf); return std.meta.stringToEnum(LanguageId, normalized_tag) orelse { // special case for a tag that has been mapped to the same ID diff --git a/src/resinator/parse.zig b/src/resinator/parse.zig index 2e528bea657b837a2046b96bd8ab3e8b022a9c64..68537b94f6bb80ecab17af1a4b461d3a14db24eb 100644 --- a/src/resinator/parse.zig +++ b/src/resinator/parse.zig @@ -100,7 +100,7 @@ pub const Parser = struct { // because it almost always leads to unhelpful error messages // (usually it will end up with bogus things like 'file // not found: {') - var statement = try self.parseStatement(); + const statement = try self.parseStatement(); try statements.append(statement); } } @@ -698,7 +698,7 @@ pub const Parser = struct { .dlginclude => { const common_resource_attributes = try self.parseCommonResourceAttributes(); - var filename_expression = try self.parseExpression(.{ + const filename_expression = try self.parseExpression(.{ .allowed_types = .{ .string = true }, }); @@ -756,7 +756,7 @@ pub const Parser = struct { return &node.base; } - var filename_expression = try self.parseExpression(.{ + const filename_expression = try self.parseExpression(.{ // Don't tell the user that numbers are accepted since we error on // number expressions and regular number literals are treated as unquoted // literals rather than numbers, so from the users perspective @@ -934,8 +934,8 @@ pub const Parser = struct { style = try optional_param_parser.parse(.{ .not_expression_allowed = true }); } - var exstyle: ?*Node = try optional_param_parser.parse(.{ .not_expression_allowed = true }); - var help_id: ?*Node = switch (resource) { + const exstyle: ?*Node = try optional_param_parser.parse(.{ .not_expression_allowed = true }); + const help_id: ?*Node = switch (resource) { .dialogex => try optional_param_parser.parse(.{}), else => null, }; @@ -1526,7 +1526,7 @@ pub const Parser = struct { pub fn toErrorDetails(options: ParseExpressionOptions, token: Token) ErrorDetails { // TODO: expected_types_override interaction with is_known_to_be_number_expression? - var expected_types = options.expected_types_override orelse ErrorDetails.ExpectedTypes{ + const expected_types = options.expected_types_override orelse ErrorDetails.ExpectedTypes{ .number = options.allowed_types.number, .number_expression = options.allowed_types.number, .string_literal = options.allowed_types.string and !options.is_known_to_be_number_expression, diff --git a/src/resinator/res.zig b/src/resinator/res.zig index 7db3f0d7499531b537aac0b185aa1681ceb9ee3a..86102b4e772ce74b71d270304a8550f97bdd63d1 100644 --- a/src/resinator/res.zig +++ b/src/resinator/res.zig @@ -357,7 +357,7 @@ pub const NameOrOrdinal = union(enum) { /// RC compiler would have allowed them, so that a proper warning/error /// can be emitted. pub fn maybeNonAsciiOrdinalFromString(bytes: SourceBytes) ?NameOrOrdinal { - var buf = bytes.slice; + const buf = bytes.slice; const radix = 10; if (buf.len > 2 and buf[0] == '0') { switch (buf[1]) { @@ -514,7 +514,7 @@ test "NameOrOrdinal" { { var expected = blk: { // the input before the 𐐷 character, but uppercased - var expected_u8_bytes = "00614982008907933748980730280674788429543776231864944218790698304852300002973622122844631429099469274282385299397783838528QFFL7SHNSIETG0QKLR1UYPBTUV1PMFQRRA0VJDG354GQEDJMUPGPP1W1EXVNTZVEIZ6K3IPQM1AWGEYALMEODYVEZGOD3MFMGEY8FNR4JUETTB1PZDEWSNDRGZUA8SNXP3NGO"; + const expected_u8_bytes = "00614982008907933748980730280674788429543776231864944218790698304852300002973622122844631429099469274282385299397783838528QFFL7SHNSIETG0QKLR1UYPBTUV1PMFQRRA0VJDG354GQEDJMUPGPP1W1EXVNTZVEIZ6K3IPQM1AWGEYALMEODYVEZGOD3MFMGEY8FNR4JUETTB1PZDEWSNDRGZUA8SNXP3NGO"; var buf: [256:0]u16 = undefined; for (expected_u8_bytes, 0..) |byte, i| { buf[i] = std.mem.nativeToLittle(u16, byte); diff --git a/src/resinator/source_mapping.zig b/src/resinator/source_mapping.zig index 27e888f87a04c3c87764f3133f50e8ba685c0a8b..f8f99de401a5b0eb7bb56ea844cd8c082eba6076 100644 --- a/src/resinator/source_mapping.zig +++ b/src/resinator/source_mapping.zig @@ -251,7 +251,7 @@ pub fn handleLineCommand(allocator: Allocator, line_command: []const u8, current } pub fn parseAndRemoveLineCommandsAlloc(allocator: Allocator, source: []const u8, options: ParseAndRemoveLineCommandsOptions) !ParseLineCommandsResult { - var buf = try allocator.alloc(u8, source.len); + const buf = try allocator.alloc(u8, source.len); errdefer allocator.free(buf); var result = try parseAndRemoveLineCommands(allocator, source, buf, options); result.result = try allocator.realloc(buf, result.result.len); @@ -440,7 +440,7 @@ pub const SourceMappings = struct { } pub fn set(self: *SourceMappings, allocator: Allocator, line_num: usize, span: SourceSpan) !void { - var ptr = try self.expandAndGet(allocator, line_num); + const ptr = try self.expandAndGet(allocator, line_num); ptr.* = span; } diff --git a/src/translate_c.zig b/src/translate_c.zig index 73dc7b8c1933affac750b20413f62d7a89353bfa..ea4cdf860af4739e6d3b3d53d569d2f160a25fd2 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -456,7 +456,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void { block_scope.return_type = return_qt; defer block_scope.deinit(); - var scope = &block_scope.base; + const scope = &block_scope.base; var param_id: c_uint = 0; for (proto_node.data.params) |*param| { @@ -1363,7 +1363,7 @@ fn transSimpleOffsetOfExpr(c: *Context, expr: *const clang.OffsetOfExpr) TransEr if (c.decl_table.get(@intFromPtr(record_decl.getCanonicalDecl()))) |type_name| { const type_node = try Tag.type.create(c.arena, type_name); - var raw_field_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(field_decl)).getName_bytes_begin()); + const raw_field_name = try c.str(@as(*const clang.NamedDecl, @ptrCast(field_decl)).getName_bytes_begin()); const quoted_field_name = try std.fmt.allocPrint(c.arena, "\"{s}\"", .{raw_field_name}); const field_name_node = try Tag.string_literal.create(c.arena, quoted_field_name); @@ -1967,7 +1967,7 @@ fn transBoolExpr( return Node{ .tag_if_small_enough = @intFromEnum(([2]Tag{ .true_literal, .false_literal })[@intFromBool(is_zero)]) }; } - var res = try transExpr(c, scope, expr, used); + const res = try transExpr(c, scope, expr, used); if (isBoolRes(res)) { return maybeSuppressResult(c, used, res); } @@ -3477,7 +3477,7 @@ fn cIsFunctionDeclRef(expr: *const clang.Expr) bool { fn transCallExpr(c: *Context, scope: *Scope, stmt: *const clang.CallExpr, result_used: ResultUsed) TransError!Node { const callee = stmt.getCallee(); - var raw_fn_expr = try transExpr(c, scope, callee, .used); + const raw_fn_expr = try transExpr(c, scope, callee, .used); var is_ptr = false; const fn_ty = qualTypeGetFnProto(callee.getType(), &is_ptr); @@ -5889,7 +5889,7 @@ fn escapeUnprintables(ctx: *Context, m: *MacroCtx) ![]const u8 { const formatter = std.fmt.fmtSliceEscapeLower(zigified); const encoded_size = @as(usize, @intCast(std.fmt.count("{s}", .{formatter}))); - var output = try ctx.arena.alloc(u8, encoded_size); + const output = try ctx.arena.alloc(u8, encoded_size); return std.fmt.bufPrint(output, "{s}", .{formatter}) catch |err| switch (err) { error.NoSpaceLeft => unreachable, else => |e| return e, diff --git a/src/value.zig b/src/value.zig index 6af43063d18eddab70d0c5e73f635412ef380b41..256b537573aa1337511f2ef1a1640f1bdc9d57c5 100644 --- a/src/value.zig +++ b/src/value.zig @@ -2136,7 +2136,7 @@ pub const Value = struct { lhs_bigint.limbs.len + rhs_bigint.limbs.len, ); var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined }; - var limbs_buffer = try arena.alloc( + const limbs_buffer = try arena.alloc( std.math.big.Limb, std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1), ); @@ -2249,7 +2249,7 @@ pub const Value = struct { ), ); var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined }; - var limbs_buffer = try arena.alloc( + const limbs_buffer = try arena.alloc( std.math.big.Limb, std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1), ); @@ -2788,7 +2788,7 @@ pub const Value = struct { lhs_bigint.limbs.len + rhs_bigint.limbs.len, ); var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined }; - var limbs_buffer = try allocator.alloc( + const limbs_buffer = try allocator.alloc( std.math.big.Limb, std.math.big.int.calcMulLimbsBufferLen(lhs_bigint.limbs.len, rhs_bigint.limbs.len, 1), ); diff --git a/src/windows_sdk.zig b/src/windows_sdk.zig index 85c10226bd528ed93119da403ee4c0037cf830f8..d6add063d81fb308def96ddccae422f5ec1c7509 100644 --- a/src/windows_sdk.zig +++ b/src/windows_sdk.zig @@ -69,7 +69,7 @@ fn iterateAndFilterBySemVer(iterator: *std.fs.IterableDir.Iterator, allocator: s try dirs_filtered_list.append(subfolder_name_allocated); } - var dirs_filtered_slice = try dirs_filtered_list.toOwnedSlice(); + const dirs_filtered_slice = try dirs_filtered_list.toOwnedSlice(); // Keep in mind that order of these names is not guaranteed by Windows, // so we cannot just reverse or "while (popOrNull())" this ArrayList. std.mem.sortUnstable([]const u8, dirs_filtered_slice, {}, struct { @@ -129,7 +129,7 @@ const RegistryUtf8 = struct { const value_utf16le = try registry_utf16le.getString(allocator, subkey_utf16le, value_name_utf16le); defer allocator.free(value_utf16le); - var value_utf8: []u8 = std.unicode.utf16leToUtf8Alloc(allocator, value_utf16le) catch |err| switch (err) { + const value_utf8: []u8 = std.unicode.utf16leToUtf8Alloc(allocator, value_utf16le) catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, else => return error.StringNotFound, }; @@ -246,7 +246,7 @@ const RegistryUtf16Le = struct { else => return error.NotAString, } - var value_utf16le_buf: []u16 = try allocator.alloc(u16, std.math.divCeil(u32, value_utf16le_buf_size, 2) catch unreachable); + const value_utf16le_buf: []u16 = try allocator.alloc(u16, std.math.divCeil(u32, value_utf16le_buf_size, 2) catch unreachable); errdefer allocator.free(value_utf16le_buf); return_code_int = windows.advapi32.RegGetValueW( @@ -354,7 +354,7 @@ pub const Windows10Sdk = struct { defer v10_key.closeKey(); const path: []const u8 = path10: { - var path_maybe_with_trailing_slash = v10_key.getString(allocator, "", "InstallationFolder") catch |err| switch (err) { + const path_maybe_with_trailing_slash = v10_key.getString(allocator, "", "InstallationFolder") catch |err| switch (err) { error.NotAString => return error.Windows10SdkNotFound, error.ValueNameNotFound => return error.Windows10SdkNotFound, error.StringNotFound => return error.Windows10SdkNotFound, @@ -381,7 +381,7 @@ pub const Windows10Sdk = struct { const version: []const u8 = version10: { // note(dimenus): Microsoft doesn't include the .0 in the ProductVersion key.... - var version_without_0 = v10_key.getString(allocator, "", "ProductVersion") catch |err| switch (err) { + const version_without_0 = v10_key.getString(allocator, "", "ProductVersion") catch |err| switch (err) { error.NotAString => return error.Windows10SdkNotFound, error.ValueNameNotFound => return error.Windows10SdkNotFound, error.StringNotFound => return error.Windows10SdkNotFound, @@ -445,7 +445,7 @@ pub const Windows81Sdk = struct { /// After finishing work, call `free(allocator)`. fn find(allocator: std.mem.Allocator, roots_key: *const RegistryUtf8) error{ OutOfMemory, Windows81SdkNotFound, PathTooLong, VersionTooLong }!Windows81Sdk { const path: []const u8 = path81: { - var path_maybe_with_trailing_slash = roots_key.getString(allocator, "", "KitsRoot81") catch |err| switch (err) { + const path_maybe_with_trailing_slash = roots_key.getString(allocator, "", "KitsRoot81") catch |err| switch (err) { error.NotAString => return error.Windows81SdkNotFound, error.ValueNameNotFound => return error.Windows81SdkNotFound, error.StringNotFound => return error.Windows81SdkNotFound, @@ -752,7 +752,7 @@ const MsvcLibDir = struct { const config_subkey = std.fmt.bufPrint(config_subkey_buf[0..], "Software\\Microsoft\\VisualStudio\\{s}_Config", .{vs_version}) catch unreachable; - var source_directories_value = visualstudio_registry.getString(allocator, config_subkey, "Source Directories") catch |err| switch (err) { + const source_directories_value = visualstudio_registry.getString(allocator, config_subkey, "Source Directories") catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, else => continue, }; @@ -768,7 +768,7 @@ const MsvcLibDir = struct { var source_directories_splitted = std.mem.splitScalar(u8, source_directories, ';'); const msvc_dir: []const u8 = msvc_dir: { - var msvc_include_dir_maybe_with_trailing_slash = try allocator.dupe(u8, source_directories_splitted.first()); + const msvc_include_dir_maybe_with_trailing_slash = try allocator.dupe(u8, source_directories_splitted.first()); 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)) { allocator.free(msvc_include_dir_maybe_with_trailing_slash); @@ -833,7 +833,7 @@ const MsvcLibDir = struct { const vs7_key = RegistryUtf8.openKey("SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7") catch return error.PathNotFound; defer vs7_key.closeKey(); try_vs7_key: { - var path_maybe_with_trailing_slash = vs7_key.getString(allocator, "", "14.0") catch |err| switch (err) { + const path_maybe_with_trailing_slash = vs7_key.getString(allocator, "", "14.0") catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, else => break :try_vs7_key, }; -- 2.54.0 From 38b373bf0b78bfe3b332c9fbb115e2ce3e9768d0 Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 17 Nov 2023 04:46:23 +0000 Subject: [PATCH 11/15] cases: add compile error test for never-mutated local variable --- .../compile_errors/var_never_mutated.zig | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/cases/compile_errors/var_never_mutated.zig diff --git a/test/cases/compile_errors/var_never_mutated.zig b/test/cases/compile_errors/var_never_mutated.zig new file mode 100644 index 0000000000000000000000000000000000000000..e6594e93442d73d3afcc5792508c6ebddce76fdb --- /dev/null +++ b/test/cases/compile_errors/var_never_mutated.zig @@ -0,0 +1,28 @@ +fn entry0() void { + var a: u32 = 1 + 2; + _ = a; +} + +fn entry1() void { + const a: u32 = 1; + const b: u32 = 2; + var c = a + b; + const d = c; + _ = d; +} + +fn entry2() void { + var a: u32 = 123; + foo(a); +} + +fn foo(_: u32) void {} + +// error +// +// :2:9: error: local variable is never mutated +// :2:9: note: consider using 'const' +// :9:9: error: local variable is never mutated +// :9:9: note: consider using 'const' +// :15:9: error: local variable is never mutated +// :15:9: note: consider using 'const' -- 2.54.0 From 3c585730f2d259963716684ede87dcfce2607973 Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 17 Nov 2023 04:58:49 +0000 Subject: [PATCH 12/15] AstGen: preserve result type in comptime block --- src/AstGen.zig | 28 +++++++++++++++++++++------- test/behavior/cast.zig | 5 +++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index be6e88af0ac4b7939519853bb559a6788fb4d0ef..0d1fa6c06194323ae34c2b96d4df0f9f40684abb 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -1971,6 +1971,17 @@ fn comptimeExpr( .block_two, .block_two_semicolon, .block, .block_semicolon => { const token_tags = tree.tokens.items(.tag); const lbrace = main_tokens[node]; + // Careful! We can't pass in the real result location here, since it may + // refer to runtime memory. A runtime-to-comptime boundary has to remove + // result location information, compute the result, and copy it to the true + // result location at runtime. We do this below as well. + const ty_only_ri: ResultInfo = .{ + .ctx = ri.ctx, + .rl = if (try ri.rl.resultType(gz, node)) |res_ty| + .{ .coerced_ty = res_ty } + else + .none, + }; if (token_tags[lbrace - 1] == .colon and token_tags[lbrace - 2] == .identifier) { @@ -1985,17 +1996,13 @@ fn comptimeExpr( else stmts[0..2]; - // Careful! We can't pass in the real result location here, since it may - // refer to runtime memory. A runtime-to-comptime boundary has to remove - // result location information, compute the result, and copy it to the true - // result location at runtime. We do this below as well. - const block_ref = try labeledBlockExpr(gz, scope, .{ .rl = .none }, node, stmt_slice, true); + const block_ref = try labeledBlockExpr(gz, scope, ty_only_ri, node, stmt_slice, true); return rvalue(gz, ri, block_ref, node); }, .block, .block_semicolon => { const stmts = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs]; // Replace result location and copy back later - see above. - const block_ref = try labeledBlockExpr(gz, scope, .{ .rl = .none }, node, stmts, true); + const block_ref = try labeledBlockExpr(gz, scope, ty_only_ri, node, stmts, true); return rvalue(gz, ri, block_ref, node); }, else => unreachable, @@ -2013,7 +2020,14 @@ fn comptimeExpr( const block_inst = try gz.makeBlockInst(.block_comptime, node); // Replace result location and copy back later - see above. - const block_result = try expr(&block_scope, scope, .{ .rl = .none }, node); + const ty_only_ri: ResultInfo = .{ + .ctx = ri.ctx, + .rl = if (try ri.rl.resultType(gz, node)) |res_ty| + .{ .coerced_ty = res_ty } + else + .none, + }; + const block_result = try expr(&block_scope, scope, ty_only_ri, node); if (!gz.refIsNoReturn(block_result)) { _ = try block_scope.addBreak(.@"break", block_inst, block_result); } diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index 486014074dbd2ada59edcfee08608590f841a055..3bbb1e9a9a10d9e6e28bfd11d8ddcdff2090056a 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -2522,3 +2522,8 @@ test "@intCast vector of signed integer" { try expect(y[2] == 3); try expect(y[3] == 4); } + +test "result type is preserved into comptime block" { + const x: u32 = comptime @intCast(123); + try expect(x == 123); +} -- 2.54.0 From ff838d86315ccb49f9c3de839458508fda857231 Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 17 Nov 2023 13:16:39 +0000 Subject: [PATCH 13/15] translate-c: work around unnecessary uses of 'var' --- src/translate_c/common.zig | 8 ++ test/translate_c.zig | 178 +++++++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+) diff --git a/src/translate_c/common.zig b/src/translate_c/common.zig index c26ab2798ba282e4e2225591ac4967c2dff95717..478f41626ba3a849947576395740b1953892eb77 100644 --- a/src/translate_c/common.zig +++ b/src/translate_c/common.zig @@ -291,6 +291,14 @@ pub fn ScopeExtra(comptime Context: type, comptime Type: type) type { } pub fn skipVariableDiscard(inner: *Scope, name: []const u8) void { + if (true) { + // TODO: due to 'local variable is never mutated' errors, we can + // only skip discards if a variable is used as an lvalue, which + // we don't currently have detection for in translate-c. + // Once #17584 is completed, perhaps we can do away with this + // logic entirely, and instead rely on render to fixup code. + return; + } var scope = inner; while (true) { switch (scope.id) { diff --git a/test/translate_c.zig b/test/translate_c.zig index 2df0f8c6cf1354422ed75520d0605c188a2b8fae..fb4ab33480d4b3d0ada3b876a2ccc6503ca6d33e 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -37,6 +37,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo(arg_a: c_int) void { \\ var a = arg_a; + \\ _ = &a; \\ while (true) { \\ if (a != 0) break; \\ } @@ -81,9 +82,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo(arg_x: c_ulong) c_ulong { \\ var x = arg_x; + \\ _ = &x; \\ const union_unnamed_1 = extern union { \\ _x: c_ulong, \\ }; + \\ _ = &union_unnamed_1; \\ return (union_unnamed_1{ \\ ._x = x, \\ })._x; @@ -142,6 +145,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub extern fn bar(...) c_int; \\pub export fn foo() void { \\ var a: c_int = undefined; + \\ _ = &a; \\ if (a != 0) a = 2 else _ = bar(); \\} }); @@ -194,6 +198,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ B: c_int = @import("std").mem.zeroes(c_int), \\ C: c_int = @import("std").mem.zeroes(c_int), \\ }; + \\ _ = &struct_Foo; \\ var a: struct_Foo = struct_Foo{ \\ .A = @as(c_int, 0), \\ .B = 0, @@ -206,6 +211,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ B: c_int = @import("std").mem.zeroes(c_int), \\ C: c_int = @import("std").mem.zeroes(c_int), \\ }; + \\ _ = &struct_Foo_1; \\ var a_2: struct_Foo_1 = struct_Foo_1{ \\ .A = @as(c_int, 0), \\ .B = 0, @@ -242,6 +248,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ }; \\ _ = &union_unnamed_1; \\ const Foo = union_unnamed_1; + \\ _ = &Foo; \\ var a: Foo = Foo{ \\ .A = @as(c_int, 0), \\ }; @@ -254,6 +261,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ }; \\ _ = &union_unnamed_2; \\ const Foo_1 = union_unnamed_2; + \\ _ = &Foo_1; \\ var a_2: Foo_1 = Foo_1{ \\ .A = @as(c_int, 0), \\ }; @@ -268,6 +276,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\#define MEM_PHYSICAL_TO_K0(x) (void*)((uint32_t)(x) + SYS_BASE_CACHED) , &[_][]const u8{ \\pub inline fn MEM_PHYSICAL_TO_K0(x: anytype) ?*anyopaque { + \\ _ = &x; \\ return @import("std").zig.c_translation.cast(?*anyopaque, @import("std").zig.c_translation.cast(u32, x) + SYS_BASE_CACHED); \\} }); @@ -310,6 +319,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\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)); , \\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))) { + \\ _ = &p; \\ 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)); \\} }); @@ -390,6 +400,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const Color = struct_Color; , \\pub inline fn CLITERAL(@"type": anytype) @TypeOf(@"type") { + \\ _ = &@"type"; \\ return @"type"; \\} , @@ -407,6 +418,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\}; , \\pub inline fn A(_x: anytype) MyCStruct { + \\ _ = &_x; \\ return @import("std").mem.zeroInit(MyCStruct, .{ \\ .x = _x, \\ }); @@ -438,6 +450,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0) , &[_][]const u8{ \\pub inline fn __ferror_unlocked_body(_fp: anytype) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0)) { + \\ _ = &_fp; \\ return (_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0); \\} }); @@ -447,6 +460,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\#define BAR 1 && 2 > 4 , &[_][]const u8{ \\pub inline fn FOO(x: anytype) @TypeOf(@intFromBool(x >= @as(c_int, 0)) + @intFromBool(x >= @as(c_int, 0))) { + \\ _ = &x; \\ return @intFromBool(x >= @as(c_int, 0)) + @intFromBool(x >= @as(c_int, 0)); \\} , @@ -512,6 +526,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\}; , \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) { + \\ _ = &x; \\ return blk_1: { \\ _ = &x; \\ _ = @as(c_int, 3); @@ -642,6 +657,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\}; \\pub export fn foo(arg_x: [*c]outer) void { \\ var x = arg_x; + \\ _ = &x; \\ x.*.unnamed_0.unnamed_0.y = @as(c_int, @bitCast(@as(c_uint, x.*.unnamed_0.x))); \\} }); @@ -728,6 +744,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const struct_opaque_2 = opaque {}; \\pub export fn function(arg_opaque_1: ?*struct_opaque) void { \\ var opaque_1 = arg_opaque_1; + \\ _ = &opaque_1; \\ var cast: ?*struct_opaque_2 = @as(?*struct_opaque_2, @ptrCast(opaque_1)); \\ _ = &cast; \\} @@ -827,6 +844,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_int = undefined; + \\ _ = &a; \\ _ = @as(c_int, 1); \\ _ = "hey"; \\ _ = @as(c_int, 1) + @as(c_int, 1); @@ -912,6 +930,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub extern fn foo() void; \\pub export fn bar() void { \\ var func_ptr: ?*anyopaque = @as(?*anyopaque, @ptrCast(&foo)); + \\ _ = &func_ptr; \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @as(?*const fn () callconv(.C) void, @ptrFromInt(@as(c_ulong, @intCast(@intFromPtr(func_ptr))))); \\ _ = &typed_func_ptr; \\} @@ -953,8 +972,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn s() c_int { \\ var a: c_int = undefined; + \\ _ = &a; \\ var b: c_int = undefined; + \\ _ = &b; \\ var c: c_int = undefined; + \\ _ = &c; \\ c = a + b; \\ c = a - b; \\ c = a * b; @@ -964,8 +986,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} \\pub export fn u() c_uint { \\ var a: c_uint = undefined; + \\ _ = &a; \\ var b: c_uint = undefined; + \\ _ = &b; \\ var c: c_uint = undefined; + \\ _ = &c; \\ c = a +% b; \\ c = a -% b; \\ c = a *% b; @@ -1361,6 +1386,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() void { \\ var a: c_int = undefined; \\ _ = &a; + \\ _ = &a; \\} }); @@ -1372,6 +1398,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() ?*anyopaque { \\ var x: [*c]c_ushort = undefined; + \\ _ = &x; \\ return @as(?*anyopaque, @ptrCast(x)); \\} }); @@ -1496,6 +1523,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() void { \\ { \\ var i: c_int = 0; + \\ _ = &i; \\ while (i != 0) : (i += 1) {} \\ } \\} @@ -1519,6 +1547,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var i: c_int = undefined; + \\ _ = &i; \\ { \\ i = 3; \\ while (i != 0) : (i -= 1) {} @@ -1562,6 +1591,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn ptrcast() [*c]f32 { \\ var a: [*c]c_int = undefined; + \\ _ = &a; \\ return @as([*c]f32, @ptrCast(@alignCast(a))); \\} }); @@ -1574,6 +1604,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn ptrptrcast() [*c][*c]f32 { \\ var a: [*c][*c]c_int = undefined; + \\ _ = &a; \\ return @as([*c][*c]f32, @ptrCast(@alignCast(a))); \\} }); @@ -1597,6 +1628,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn test_ptr_cast() void { \\ var p: ?*anyopaque = undefined; + \\ _ = &p; \\ { \\ var to_char: [*c]u8 = @as([*c]u8, @ptrCast(@alignCast(p))); \\ _ = &to_char; @@ -1633,8 +1665,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn while_none_bool() c_int { \\ var a: c_int = undefined; + \\ _ = &a; \\ var b: f32 = undefined; + \\ _ = &b; \\ var c: ?*anyopaque = undefined; + \\ _ = &c; \\ while (a != 0) return 0; \\ while (b != 0) return 1; \\ while (c != null) return 2; @@ -1655,8 +1690,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn for_none_bool() c_int { \\ var a: c_int = undefined; + \\ _ = &a; \\ var b: f32 = undefined; + \\ _ = &b; \\ var c: ?*anyopaque = undefined; + \\ _ = &c; \\ while (a != 0) return 0; \\ while (b != 0) return 1; \\ while (c != null) return 2; @@ -1693,6 +1731,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var x: [*c]c_int = undefined; + \\ _ = &x; \\ x.* = 1; \\} }); @@ -1706,7 +1745,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() c_int { \\ var x: c_int = 1234; + \\ _ = &x; \\ var ptr: [*c]c_int = &x; + \\ _ = &ptr; \\ return ptr.*; \\} }); @@ -1719,6 +1760,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() c_int { \\ var x: c_int = undefined; + \\ _ = &x; \\ return ~x; \\} }); @@ -1736,8 +1778,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() c_int { \\ var a: c_int = undefined; + \\ _ = &a; \\ var b: f32 = undefined; + \\ _ = &b; \\ var c: ?*anyopaque = undefined; + \\ _ = &c; \\ return @intFromBool(!(a == @as(c_int, 0))); \\ return @intFromBool(!(a != 0)); \\ return @intFromBool(!(b != 0)); @@ -2051,10 +2096,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub extern var c: c_int; , \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * @as(c_int, 2)) { + \\ _ = &c_1; \\ return c_1 * @as(c_int, 2); \\} , \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) { + \\ _ = &L; + \\ _ = &b; \\ return L + b; \\} , @@ -2109,7 +2157,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ var c_1 = arg_c_1; \\ _ = &c_1; \\ var a_2: c_int = undefined; + \\ _ = &a_2; \\ var b_3: u8 = 123; + \\ _ = &b_3; \\ b_3 = @as(u8, @bitCast(@as(i8, @truncate(a_2)))); \\ { \\ var d: c_int = 5; @@ -2150,7 +2200,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_int = undefined; + \\ _ = &a; \\ var b: c_int = undefined; + \\ _ = &b; \\ a = blk: { \\ const tmp = @as(c_int, 2); \\ b = tmp; @@ -2180,11 +2232,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() c_int { \\ var a: c_int = 5; + \\ _ = &a; \\ while (true) { \\ a = 2; \\ } \\ while (true) { \\ var a_1: c_int = 4; + \\ _ = &a_1; \\ a_1 = 9; \\ return blk: { \\ _ = @as(c_int, 6); @@ -2193,6 +2247,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ } \\ while (true) { \\ var a_1: c_int = 2; + \\ _ = &a_1; \\ a_1 = 12; \\ } \\ while (true) { @@ -2214,10 +2269,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() void { \\ { \\ var i: c_int = 2; + \\ _ = &i; \\ var b: c_int = 4; \\ _ = &b; \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) { \\ var a: c_int = 2; + \\ _ = &a; \\ _ = blk: { \\ _ = blk_1: { \\ a = 6; @@ -2309,7 +2366,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn switch_fn(arg_i: c_int) void { \\ var i = arg_i; + \\ _ = &i; \\ var res: c_int = 0; + \\ _ = &res; \\ while (true) { \\ switch (i) { \\ @as(c_int, 0) => { @@ -2398,7 +2457,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn max(arg_a: c_int) void { \\ var a = arg_a; + \\ _ = &a; \\ var tmp: c_int = undefined; + \\ _ = &tmp; \\ tmp = a; \\ a = tmp; \\} @@ -2412,8 +2473,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn max(arg_a: c_int) void { \\ var a = arg_a; + \\ _ = &a; \\ var b: c_int = undefined; + \\ _ = &b; \\ var c: c_int = undefined; + \\ _ = &c; \\ c = blk: { \\ const tmp = a; \\ b = tmp; @@ -2442,6 +2506,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn int_from_float(arg_a: f32) c_int { \\ var a = arg_a; + \\ _ = &a; \\ return @as(c_int, @intFromFloat(a)); \\} }); @@ -2505,11 +2570,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_int = 2; + \\ _ = &a; \\ while (true) { \\ a = a - @as(c_int, 1); \\ if (!(a != 0)) break; \\ } \\ var b: c_int = 2; + \\ _ = &b; \\ while (true) { \\ b = b - @as(c_int, 1); \\ if (!(b != 0)) break; @@ -2550,21 +2617,37 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const SomeTypedef = c_int; \\pub export fn and_or_non_bool(arg_a: c_int, arg_b: f32, arg_c: ?*anyopaque) c_int { \\ var a = arg_a; + \\ _ = &a; \\ var b = arg_b; + \\ _ = &b; \\ var c = arg_c; + \\ _ = &c; \\ var d: enum_Foo = @as(c_uint, @bitCast(FooA)); + \\ _ = &d; \\ var e: c_int = @intFromBool((a != 0) and (b != 0)); + \\ _ = &e; \\ var f: c_int = @intFromBool((b != 0) and (c != null)); + \\ _ = &f; \\ var g: c_int = @intFromBool((a != 0) and (c != null)); + \\ _ = &g; \\ var h: c_int = @intFromBool((a != 0) or (b != 0)); + \\ _ = &h; \\ var i: c_int = @intFromBool((b != 0) or (c != null)); + \\ _ = &i; \\ var j: c_int = @intFromBool((a != 0) or (c != null)); + \\ _ = &j; \\ var k: c_int = @intFromBool((a != 0) or (@as(c_int, @bitCast(d)) != 0)); + \\ _ = &k; \\ var l: c_int = @intFromBool((@as(c_int, @bitCast(d)) != 0) and (b != 0)); + \\ _ = &l; \\ var m: c_int = @intFromBool((c != null) or (d != 0)); + \\ _ = &m; \\ var td: SomeTypedef = 44; + \\ _ = &td; \\ var o: c_int = @intFromBool((td != 0) or (b != 0)); + \\ _ = &o; \\ var p: c_int = @intFromBool((c != null) and (td != 0)); + \\ _ = &p; \\ return (((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p; \\} , @@ -2604,7 +2687,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { \\ var a = arg_a; + \\ _ = &a; \\ var b = arg_b; + \\ _ = &b; \\ return (a & b) ^ (a | b); \\} }); @@ -2623,14 +2708,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int { \\ var a = arg_a; + \\ _ = &a; \\ var b = arg_b; + \\ _ = &b; \\ var c: c_int = @intFromBool(a < b); + \\ _ = &c; \\ var d: c_int = @intFromBool(a > b); + \\ _ = &d; \\ var e: c_int = @intFromBool(a <= b); + \\ _ = &e; \\ var f: c_int = @intFromBool(a >= b); + \\ _ = &f; \\ var g: c_int = @intFromBool(c < d); + \\ _ = &g; \\ var h: c_int = @intFromBool(e < f); + \\ _ = &h; \\ var i: c_int = @intFromBool(g < h); + \\ _ = &i; \\ return i; \\} }); @@ -2646,7 +2740,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { \\ var a = arg_a; + \\ _ = &a; \\ var b = arg_b; + \\ _ = &b; \\ if (a == b) return a; \\ if (a != b) return b; \\ return a; @@ -2663,6 +2759,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const yes = [*c]u8; \\pub export fn foo() void { \\ var a: yes = undefined; + \\ _ = &a; \\ if (a != null) { \\ _ = @as(c_int, 2); \\ } @@ -2682,6 +2779,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ return blk: { \\ var a: c_int = 1; \\ _ = &a; + \\ _ = &a; \\ break :blk a; \\ }; \\} @@ -2707,6 +2805,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export var b: f32 = 2.0; \\pub export fn foo() void { \\ var c: [*c]struct_Foo = undefined; + \\ _ = &c; \\ _ = a.b; \\ _ = c.*.b; \\} @@ -2726,6 +2825,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export var array: [100]c_int = [1]c_int{0} ** 100; \\pub export fn foo(arg_index: c_int) c_int { \\ var index = arg_index; + \\ _ = &index; \\ return array[@as(c_uint, @intCast(index))]; \\} , @@ -2740,7 +2840,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: [10]c_int = undefined; + \\ _ = &a; \\ var i: c_int = 0; + \\ _ = &i; \\ a[@as(c_uint, @intCast(i))] = 0; \\} }); @@ -2753,7 +2855,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: [10]c_longlong = undefined; + \\ _ = &a; \\ var i: c_longlong = 0; + \\ _ = &i; \\ a[@as(usize, @intCast(i))] = 0; \\} }); @@ -2766,7 +2870,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: [10]c_uint = undefined; + \\ _ = &a; \\ var i: c_uint = 0; + \\ _ = &i; \\ a[i] = 0; \\} }); @@ -2776,6 +2882,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\int bar(int x) { return x; } , &[_][]const u8{ \\pub inline fn CALL(arg: anytype) @TypeOf(bar(arg)) { + \\ _ = &arg; \\ return bar(arg); \\} }); @@ -2801,7 +2908,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { \\ var a = arg_a; + \\ _ = &a; \\ var b = arg_b; + \\ _ = &b; \\ if ((a < b) or (a == b)) return b; \\ if ((a >= b) and (a == b)) return a; \\ return a; @@ -2823,7 +2932,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int { \\ var a = arg_a; + \\ _ = &a; \\ var b = arg_b; + \\ _ = &b; \\ if (a < b) return b; \\ if (a < b) return b else return a; \\ if (a < b) {} else {} @@ -2874,9 +2985,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\; \\pub export fn if_none_bool(arg_a: c_int, arg_b: f32, arg_c: ?*anyopaque, arg_d: enum_SomeEnum) c_int { \\ var a = arg_a; + \\ _ = &a; \\ var b = arg_b; + \\ _ = &b; \\ var c = arg_c; + \\ _ = &c; \\ var d = arg_d; + \\ _ = &d; \\ if (a != 0) return 0; \\ if (b != 0) return 1; \\ if (c != null) return 2; @@ -2904,6 +3019,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn abs(arg_a: c_int) c_int { \\ var a = arg_a; + \\ _ = &a; \\ return if (a < @as(c_int, 0)) -a else a; \\} }); @@ -2924,16 +3040,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo1(arg_a: c_uint) c_uint { \\ var a = arg_a; + \\ _ = &a; \\ a +%= 1; \\ return a; \\} \\pub export fn foo2(arg_a: c_int) c_int { \\ var a = arg_a; + \\ _ = &a; \\ a += 1; \\ return a; \\} \\pub export fn foo3(arg_a: [*c]c_int) [*c]c_int { \\ var a = arg_a; + \\ _ = &a; \\ a += 1; \\ return a; \\} @@ -2959,7 +3078,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} \\pub export fn bar() void { \\ var f: ?*const fn () callconv(.C) void = &foo; + \\ _ = &f; \\ var b: ?*const fn () callconv(.C) c_int = &baz; + \\ _ = &b; \\ f.?(); \\ f.?(); \\ foo(); @@ -2985,7 +3106,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var i: c_int = 0; + \\ _ = &i; \\ var u: c_uint = 0; + \\ _ = &u; \\ i += 1; \\ i -= 1; \\ u +%= 1; @@ -3024,7 +3147,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn log2(arg_a: c_uint) c_int { \\ var a = arg_a; + \\ _ = &a; \\ var i: c_int = 0; + \\ _ = &i; \\ while (a > @as(c_uint, @bitCast(@as(c_int, 0)))) { \\ a >>= @intCast(@as(c_int, 1)); \\ } @@ -3044,7 +3169,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn log2(arg_a: u32) c_int { \\ var a = arg_a; + \\ _ = &a; \\ var i: c_int = 0; + \\ _ = &i; \\ while (a > @as(u32, @bitCast(@as(c_int, 0)))) { \\ a >>= @intCast(@as(c_int, 1)); \\ } @@ -3072,7 +3199,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_int = 0; + \\ _ = &a; \\ var b: c_uint = 0; + \\ _ = &b; \\ a += blk: { \\ const ref = &a; \\ ref.* += @as(c_int, 1); @@ -3151,6 +3280,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_uint = 0; + \\ _ = &a; \\ a +%= blk: { \\ const ref = &a; \\ ref.* +%= @as(c_uint, @bitCast(@as(c_int, 1))); @@ -3210,7 +3340,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var i: c_int = 0; + \\ _ = &i; \\ var u: c_uint = 0; + \\ _ = &u; \\ i += 1; \\ i -= 1; \\ u +%= 1; @@ -3305,6 +3437,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub fn bar() callconv(.C) void {} \\pub export fn foo(arg_baz: ?*const fn () callconv(.C) [*c]c_int) void { \\ var baz = arg_baz; + \\ _ = &baz; \\ bar(); \\ _ = baz.?(); \\} @@ -3375,10 +3508,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\#define MAX(a, b) ((b) > (a) ? (b) : (a)) , &[_][]const u8{ \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) { + \\ _ = &a; + \\ _ = &b; \\ return if (b < a) b else a; \\} , \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) { + \\ _ = &a; + \\ _ = &b; \\ return if (b > a) b else a; \\} }); @@ -3390,7 +3527,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int { \\ var p = arg_p; + \\ _ = &p; \\ var x = arg_x; + \\ _ = &x; \\ return blk: { \\ const tmp = x; \\ (blk_1: { @@ -3417,6 +3556,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} \\pub export fn bar(arg_x: c_long) c_ushort { \\ var x = arg_x; + \\ _ = &x; \\ return @as(c_ushort, @bitCast(@as(c_short, @truncate(x)))); \\} }); @@ -3429,6 +3569,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo(arg_bar_1: c_int) void { \\ var bar_1 = arg_bar_1; + \\ _ = &bar_1; \\ bar_1 = 2; \\} \\pub export var bar: c_int = 4; @@ -3442,6 +3583,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo(arg_bar_1: c_int) void { \\ var bar_1 = arg_bar_1; + \\ _ = &bar_1; \\ bar_1 = 2; \\} , @@ -3475,10 +3617,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} \\pub export fn bar(arg_a: [*c]const c_int) void { \\ var a = arg_a; + \\ _ = &a; \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a))))); \\} \\pub export fn baz(arg_a: [*c]volatile c_int) void { \\ var a = arg_a; + \\ _ = &a; \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a))))); \\} }); @@ -3493,9 +3637,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo(arg_x: bool) bool { \\ var x = arg_x; + \\ _ = &x; \\ var a: bool = @as(c_int, @intFromBool(x)) != @as(c_int, 1); + \\ _ = &a; \\ var b: bool = @as(c_int, @intFromBool(a)) != @as(c_int, 0); + \\ _ = &b; \\ var c: bool = @intFromPtr(&foo) != 0; + \\ _ = &c; \\ return foo(@as(c_int, @intFromBool(c)) != @as(c_int, @intFromBool(b))); \\} }); @@ -3506,7 +3654,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} , &[_][]const u8{ \\pub export fn max(x: c_int, arg_y: c_int) c_int { + \\ _ = &x; \\ var y = arg_y; + \\ _ = &y; \\ return if (x > y) x else y; \\} }); @@ -3567,6 +3717,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ , &[_][]const u8{ \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen) { + \\ _ = &dpy; \\ return @import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen; \\} }); @@ -3809,6 +3960,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ const foo = struct { \\ var static: struct_FOO = @import("std").mem.zeroes(struct_FOO); \\ }; + \\ _ = &foo; \\ return foo.static.x; \\} }); @@ -3830,12 +3982,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn bar(arg_x: c_int, arg_y: c_int) c_int { \\ var x = arg_x; + \\ _ = &x; \\ var y = arg_y; \\ _ = &y; \\ return x; \\} , \\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A) { + \\ _ = &A; \\ _ = &B; \\ return A; \\} @@ -3911,6 +4065,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_int = undefined; + \\ _ = &a; \\ if ((blk: { \\ const tmp = @intFromBool(@as(c_int, 1) > @as(c_int, 0)); \\ a = tmp; @@ -3929,7 +4084,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: S = undefined; + \\ _ = &a; \\ var b: S = undefined; + \\ _ = &b; \\ var c: c_longlong = @divExact(@as(c_longlong, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8)); \\ _ = &c; \\} @@ -3944,7 +4101,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: S = undefined; + \\ _ = &a; \\ var b: S = undefined; + \\ _ = &b; \\ var c: c_long = @divExact(@as(c_long, @bitCast(@intFromPtr(a) -% @intFromPtr(b))), @sizeOf(u8)); \\ _ = &c; \\} @@ -3973,7 +4132,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var n: c_int = undefined; + \\ _ = &n; \\ var tmp: c_int = 1; + \\ _ = &tmp; \\ if ((blk: { \\ const tmp_1 = tmp; \\ n = tmp_1; @@ -3990,7 +4151,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var tmp: c_int = undefined; + \\ _ = &tmp; \\ var n: c_int = 1; + \\ _ = &n; \\ if ((blk: { \\ const tmp_1 = n; \\ tmp = tmp_1; @@ -4007,7 +4170,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var n: c_int = undefined; + \\ _ = &n; \\ var ref: c_int = 1; + \\ _ = &ref; \\ if ((blk: { \\ const tmp = blk_1: { \\ const ref_2 = &ref; @@ -4028,7 +4193,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var n: c_int = undefined; + \\ _ = &n; \\ var ref: c_int = 1; + \\ _ = &ref; \\ if ((blk: { \\ const tmp = blk_1: { \\ const ref_2 = &ref; @@ -4050,7 +4217,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var n: c_int = undefined; + \\ _ = &n; \\ var ref: c_int = 1; + \\ _ = &ref; \\ if ((blk: { \\ const ref_1 = &n; \\ ref_1.* += ref; @@ -4067,7 +4236,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var ref: c_int = undefined; + \\ _ = &ref; \\ var n: c_int = 1; + \\ _ = &n; \\ if ((blk: { \\ const ref_1 = &ref; \\ ref_1.* += n; @@ -4085,8 +4256,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var f: c_int = 1; + \\ _ = &f; \\ var n: c_int = undefined; + \\ _ = &n; \\ var cond_temp: c_int = 1; + \\ _ = &cond_temp; \\ if ((blk: { \\ const tmp = blk_1: { \\ const cond_temp_2 = cond_temp; @@ -4107,8 +4281,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var cond_temp: c_int = 1; + \\ _ = &cond_temp; \\ var n: c_int = undefined; + \\ _ = &n; \\ var f: c_int = 1; + \\ _ = &f; \\ if ((blk: { \\ const tmp = blk_1: { \\ const cond_temp_2 = f; @@ -4149,6 +4326,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn somefunc() void { \\ var y: c_int = undefined; + \\ _ = &y; \\ _ = blk: { \\ y = 1; \\ }; -- 2.54.0 From 766306793a6e48bb2c102ab110c530691e1f0f8c Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 18 Nov 2023 18:22:55 +0000 Subject: [PATCH 14/15] std: correct faulty test --- lib/std/meta.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 827b8f847cb11de3962e65212520418b7daedffa..78df8c1bed9d8a32b93141018b34f0f5307ddae0 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -845,7 +845,6 @@ test "std.meta.eql" { try testing.expect(eql(a1, a2)); try testing.expect(!eql(a1, a3)); - try testing.expect(!eql(a1[0..], a2[0..])); const EU = struct { fn tst(err: bool) !u8 { -- 2.54.0 From 9cf6c1ad11bb5f0247ff3458cba5f3bd156d1fb9 Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 18 Nov 2023 18:23:08 +0000 Subject: [PATCH 15/15] behavior: work around LLVM bug See #18034 --- test/behavior/align.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/behavior/align.zig b/test/behavior/align.zig index 4458bc49e9d69a09c302b8513082b9092d8598a8..6bc78d3b6cbe27589c3043568278a985a73e0f3e 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -581,6 +581,10 @@ test "comptime alloc alignment" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_llvm and builtin.target.cpu.arch == .x86) { + // https://github.com/ziglang/zig/issues/18034 + return error.SkipZigTest; + } comptime var bytes1 = [_]u8{0}; _ = &bytes1; -- 2.54.0