diff options
632 files changed, 3285 insertions, 2015 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in index 72e23a1011..41cd06a4a6 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" { </p> {#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#} <p>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" { </p> {#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 { <p>At runtime:</p> {#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 { <p>At compile-time:</p> {#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 { <p>At compile-time:</p> {#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#} <p>At runtime:</p> {#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 diff --git a/lib/build_runner.zig b/lib/build_runner.zig index 3eb405914f..a5e537c43c 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 e861ef0ff3..ad6f9f63b3 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 9c74ebee67..d0a2cbc341 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 fbed961775..62f5d76fa5 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 5248dfb8b8..2663dc5cae 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 f70a80a5b2..92f8e9c1f2 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 a8f81d70d1..3494909f50 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 dd0f4e3d3c..dc85830df9 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 a425179920..78e1492b4f 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 912d3b2819..4a138f88c5 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 6a164a28b3..c190961dc3 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 baa9edbee4..41ce1c00d8 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 b4b120e754..decb28421e 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 9477a34f70..cc2bbb163f 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 a6d136b875..3291a6564f 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 caf3599974..c418c2e14a 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 50f84e9952..3f83f2fa9c 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 7850ac53c4..eb7822de70 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 c273c959fe..e545d22c33 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 2b881bbf8a..70a0cd0a77 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 525e2f70fc..4056168e1e 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 baa39cd61c..84a7da0fc3 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 01c090deab..3a04012925 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 65a6adb440..6b8ac04076 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 84bbe19d73..5ffb73c4f5 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 135052bf39..1845990231 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 38435a9e4b..24cb24eb3d 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 a0686b33e4..b5bc73f3b3 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 5ef511a4bf..66f5eb0587 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 accc4ed36c..ad775db5dd 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 7c40298f32..08e1ff892c 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 0033df70b6..eea753245f 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 b07ecd12ae..6495f1cfe1 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 d40554da10..ec77068fc6 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 2bb6ad29a8..a4bb0217ad 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 608a44c12f..2584de2136 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 37841573c1..d58f9c8f27 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 25a7213f69..8d791c5371 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 4e0c27c9ae..f502b65d2b 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 aa50f2bd43..dd183481e8 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 92f8e6a53e..fdcbe3ac68 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 804dc74c33..ec1820c4fd 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 f934ee9021..587cc1890f 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 daf2c1f183..b3967c410b 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 497b62516f..bf30e069aa 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 b873bcd449..4d242a8328 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 dfa676a5a8..7bd43c73c3 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 b3542a9e9d..a14dd5e18e 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 687e97c71c..2dd717e14b 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 6c7ae97c25..8644e8100e 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 f42fe3edce..68ad0ff72f 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 00c10e52be..5efc8daffe 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 cbca4b33cf..161438ab78 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 56f2dc61fb..6b3f7fdf21 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 1075cb0f31..a9705f317d 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 064a3b842e..194f45a23d 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 a5943be6bb..283a3d1f5f 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 0e5224edc0..9edc53cbb2 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 d27c8d6d27..d826916727 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 87d02e2f93..9f040349c6 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 3d26d25070..5555b03e94 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 7d3b8b8b1c..fef89a228f 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 c8be6658db..f2274db86a 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 bf5f6581ac..b82a037e14 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 e50eb92041..24655046a9 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 e38ada0c20..892e9633d5 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 e8d37507d3..552f2f9510 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 1f19869fd6..0fc622cf63 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 8d0effd05b..ce84e640d1 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 f20a581972..4de5e01e0f 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 90ee86e12d..46c10f82f8 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 4042bc2743..19c704c9a5 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 b3edbcd76a..1d79302860 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 b2bf09ef2a..e9214cbd79 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 4b440dc44e..97a557d0da 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 72de63f162..e41b097636 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 140284ea5e..1f765e3fdc 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 4e7f46db42..8e86bc09f3 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 a11548fa1f..3a2668762e 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 08f6079aa5..ca9a978ad1 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 75fdd359dd..72a3f6310b 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 18813b0b28..27c8b0a7af 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 4fea45f863..c484d71fad 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 225d6a9c69..4d9421acac 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 13fb1ac5f2..9fc5cac7e5 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 c33d87379a..a012312ab1 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 d5d70d00e4..48f167922e 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 401616f1b8..e18093f4c2 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 9303e3c522..8318269d87 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 d043099f50..f5752888fc 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 05353a3c82..879710d848 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 4e6d391799..8440590a98 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 521f9c922e..7691f14590 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 720f264d16..7c505f542f 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 04becf6789..d87211fb1e 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 6f8a32ea21..321923525b 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 2e0318369b..cb11950228 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 4a6815ae05..ccf40f59ce 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 67e1b630c1..d9fd344c19 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 b83db0a317..7f4c1b0157 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 cf16476d92..96943b06f1 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 5f6b1e4c14..af564a1e52 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 9247ab4047..0ce9f7b132 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 7b4aa0fdec..97864c03ff 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 729ff0de9b..61acab7793 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 b3b546c4d0..0ee090dae1 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 639d90b12a..6d513000f4 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 883312d176..58cf09fbf5 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 47ddf74fd5..0f017a0ca0 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 ed049079b6..e21b1b9af1 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 af686d6448..760ebca786 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 a31df31312..841119aa02 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 6cda6716b7..fd8116edaa 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 ae203e5260..904cea5e7f 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 9a11c7cb29..6786aec4b0 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 280c8888e6..e6485093ca 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 c5c6c585eb..78e2cab104 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 cd240da964..781949321d 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 a9299f245d..65a52f6b56 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 40a412bf3c..2353c8962e 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 0c61242e56..ec8679f6b2 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 69a99eccd3..09f2e609f4 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 6dc6df3998..b79d73f0e9 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 722bdd8f3e..af86adacc1 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 eb9896d40a..9b66975a09 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 4fe9c80380..e757095803 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 42fce98457..166a94fbcf 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 efc1d78cc4..40a81e3956 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 6de0fe1e53..c02446e53f 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 326c00e9b6..1e9f35eaf9 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 82b0d89044..e3d296584c 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 57471e2b03..1710cdc948 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 bf85bdab7e..0e7a86df60 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 b3ed7b7bca..93b1b88f32 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 346da746d0..f02ef18246 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 a925f2c4b2..e1f423e3c1 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 22745ee4d5..db0273eda8 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 381fc43f7d..b932b6d624 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 735a2250c9..6f4bb13189 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 4cfdcecec9..4545823ece 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 0dd5381cd9..b4a9ee3838 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 73fe2e7757..bd0f8ca754 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 75dee47fa7..78df8c1bed 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,13 +839,12 @@ 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)); - try testing.expect(!eql(a1[0..], a2[0..])); const EU = struct { fn tst(err: bool) !u8 { @@ -859,9 +858,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 +878,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 e00fac261c..3d3a1099fa 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 9e32fe613f..7e15effe54 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 0fe53a7b9f..5e98ee2a4d 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 1ae5157d8b..cf388f76e9 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<end, dest<dend if ((p[0] & 0xc0) != 0) { if (p + 1 == end) return error.InvalidDnsPacket; - var j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1]; + const j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1]; if (len == std.math.maxInt(usize)) len = @intFromPtr(p) + 2 - @intFromPtr(comp_dn.ptr); if (j >= 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 9163eb98a9..97ad952562 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 3b282422ae..2219d95832 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 9334171221..b42fd52245 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 f4a67f1035..40e0991e5f 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 535b88a262..7ad01e58e7 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 b15654e8a7..55a3763d66 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 3f64a2f3f6..aa9798c6e5 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 396398252d..a08eee193c 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 b0c0ce5be0..efc3f5574d 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 acc8aa1ec7..d0623145a0 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 31ae965286..dc3981b65e 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 a568eeadcf..74f7cb6885 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 518def4215..d736fbe8df 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 d02c016357..d498985097 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 e110a8beb8..f354e80df6 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 fe6e628653..4c94fb78ad 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 0e1595b82c..d74c7788a4 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 bdbec87e39..15727fdebf 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 95f1b156c1..09507a2392 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 383dc1802a..a555b49495 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 bd73a3bea3..2eadccda9e 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 0187c09108..cc4f296229 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 9a700a7a97..e9581b9e41 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 a53dee7fa8..2a893013d9 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 d6e862a922..23e5ee83b4 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 53b1ab7ca8..8ba2fc2f65 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 ba0d699f91..88a8a3742e 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) diff --git a/src/Air.zig b/src/Air.zig index 8bcc4dbf92..9bf0bd5eca 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 5638216ed1..0d1fa6c061 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); } @@ -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); } @@ -2941,11 +2955,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, @@ -6699,7 +6721,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(); @@ -7579,7 +7601,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); @@ -8149,7 +8174,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); @@ -10948,6 +10973,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/Autodoc.zig b/src/Autodoc.zig index cd64b5e2cf..754c29cec3 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 529ba9d33b..4917f40b29 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 1fdf5152d6..827b608cc6 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 9672f1bae0..d8f87f50e0 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 0e56a1cda1..c52fc33915 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 40f134ec90..be624c8d95 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 7c752490c6..da0226b54c 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 822ff0ec2d..ed3863462b 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 b15327fd21..e0117fa17b 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 b26cbe1503..0c309991f6 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 517dd1af8d..b499ccfdca 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 a13867be30..cd9e4fa5cb 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 94f1f6ea0e..c624998e7b 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 3232d58608..668e610a69 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 dcb3329c57..8bee639b60 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 40dfc0771d..f97f19f85b 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 0d26e24b2d..16736ab1af 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 385f09c2fc..8c889fa30d 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 3883f76268..e64ad222ad 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 73857d03d2..1d24285b30 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 ee09137759..67c9aaac05 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; } } @@ -2250,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; @@ -2330,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 }, }; @@ -2416,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; @@ -2585,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; @@ -3425,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]; @@ -3969,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); @@ -5226,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 6bdc6d916d..ba3915f51b 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 91411dc572..65d503b1ae 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 d86338f84b..98add0315c 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 c588b65ea3..be6c9dbb34 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 189d9b25cd..0f021a569c 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 669e806728..f064415739 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 79433b3b1b..e627b91f11 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 d8b6f39f76..4221aa7dee 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 2677184c12..da8753ac29 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 359ff20d94..4f5dae8c09 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 5e3602f620..7afa229401 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 7c451c242b..6bab14df56 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 1c7e0f6aad..134ee81966 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 50dbed5ad6..7fb6573c22 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 4b9a87ce7a..be89ed3f02 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 cfb27ae341..a631b8bb93 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 ae0232a737..2f768b2b31 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 d43380fa05..513d775bae 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 2e528bea65..68537b94f6 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 7db3f0d749..86102b4e77 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 27e888f87a..f8f99de401 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 73dc7b8c19..ea4cdf860a 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/translate_c/ast.zig b/src/translate_c/ast.zig index 0381f58cf9..8330e6785f 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 { diff --git a/src/translate_c/common.zig b/src/translate_c/common.zig index c26ab2798b..478f41626b 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/src/value.zig b/src/value.zig index 6af43063d1..256b537573 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 85c10226bd..d6add063d8 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, }; diff --git a/test/behavior/abs.zig b/test/behavior/abs.zig index 51ade3dbcf..fad29a1a58 100644 --- a/test/behavior/abs.zig +++ b/test/behavior/abs.zig @@ -16,26 +16,32 @@ test "@abs integers" { fn testAbsIntegers() !void { { var x: i32 = -1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: i32 = 0; + _ = &x; try expect(@abs(x) == 0); } { var x: i32 = 1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: i64 = std.math.minInt(i64); + _ = &x; try expect(@abs(x) == @as(u64, -std.math.minInt(i64))); } { var x: i5 = -1; + _ = &x; try expect(@abs(x) == 1); } { var x: i5 = -5; + _ = &x; try expect(@abs(x) == 5); } comptime { @@ -56,22 +62,27 @@ test "@abs unsigned integers" { fn testAbsUnsignedIntegers() !void { { var x: u32 = 1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: u32 = 0; + _ = &x; try expect(@abs(x) == 0); } { var x: u32 = 1000; + _ = &x; try expect(@abs(x) == 1000); } { var x: u5 = 1; + _ = &x; try expect(@abs(x) == 1); } { var x: u5 = 5; + _ = &x; try expect(@abs(x) == 5); } comptime { @@ -102,27 +113,33 @@ test "@abs floats" { fn testAbsFloats(comptime T: type) !void { { var x: T = -2.62; + _ = &x; try expect(@abs(x) == 2.62); } { var x: T = 2.62; + _ = &x; try expect(@abs(x) == 2.62); } { var x: T = 0.0; + _ = &x; try expect(@abs(x) == 0.0); } { var x: T = -std.math.pi; + _ = &x; try expect(@abs(x) == std.math.pi); } { var x: T = -std.math.inf(T); + _ = &x; try expect(@abs(x) == std.math.inf(T)); } { var x: T = std.math.inf(T); + _ = &x; try expect(@abs(x) == std.math.inf(T)); } comptime { @@ -164,31 +181,37 @@ fn testAbsIntVectors(comptime len: comptime_int) !void { { var x: I32 = @splat(-10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: I32 = @splat(10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: I32 = @splat(0); var y: U32 = @splat(0); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: I64 = @splat(-10); var y: U64 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); } { var x: I64 = @splat(std.math.minInt(i64)); var y: U64 = @splat(-std.math.minInt(i64)); + _ = .{ &x, &y }; try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); } { var x = std.simd.repeat(len, @Vector(4, i32){ -2, 5, std.math.minInt(i32), -7 }); var y = std.simd.repeat(len, @Vector(4, u32){ 2, 5, -std.math.minInt(i32), 7 }); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } } @@ -225,26 +248,31 @@ fn testAbsUnsignedIntVectors(comptime len: comptime_int) !void { { var x: U32 = @splat(10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: U32 = @splat(10); var y: U32 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: U32 = @splat(0); var y: U32 = @splat(0); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } { var x: U64 = @splat(10); var y: U64 = @splat(10); + _ = .{ &x, &y }; try expect(std.mem.eql(u64, &@as([len]u64, y), &@as([len]u64, @abs(x)))); } { var x = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); var y = std.simd.repeat(len, @Vector(3, u32){ 2, 5, 7 }); + _ = .{ &x, &y }; try expect(std.mem.eql(u32, &@as([len]u32, y), &@as([len]u32, @abs(x)))); } } @@ -346,26 +374,31 @@ fn testAbsFloatVectors(comptime T: type, comptime len: comptime_int) !void { { var x: V = @splat(-7.5); var y: V = @splat(7.5); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(7.5); var y: V = @splat(7.5); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(0.0); var y: V = @splat(0.0); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(-std.math.pi); var y: V = @splat(std.math.pi); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } { var x: V = @splat(std.math.pi); var y: V = @splat(std.math.pi); + _ = .{ &x, &y }; try expect(std.mem.eql(T, &@as([len]T, y), &@as([len]T, @abs(x)))); } } diff --git a/test/behavior/align.zig b/test/behavior/align.zig index 7b95cf8a56..6bc78d3b6c 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); } @@ -577,12 +581,16 @@ 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; + _ = &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 +599,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 +646,7 @@ test "alignment of zero-bit types is respected" { var s32: S align(32) = .{}; var zero: usize = 0; + _ = &zero; try expect(@intFromPtr(&s) % @alignOf(usize) == 0); try expect(@intFromPtr(&s.arr) % @alignOf(usize) == 0); diff --git a/test/behavior/alignof.zig b/test/behavior/alignof.zig index 0443b2d6b3..81d1e49fdf 100644 --- a/test/behavior/alignof.zig +++ b/test/behavior/alignof.zig @@ -31,6 +31,7 @@ test "correct alignment for elements and slices of aligned array" { var buf: [1024]u8 align(64) = undefined; var start: usize = 1; var end: usize = undefined; + _ = .{ &start, &end }; try expect(@alignOf(@TypeOf(buf[start..end])) == @alignOf(*u8)); try expect(@alignOf(@TypeOf(&buf[start..end])) == @alignOf(*u8)); try expect(@alignOf(@TypeOf(&buf[start])) == @alignOf(*u8)); diff --git a/test/behavior/array.zig b/test/behavior/array.zig index 2586770c6f..e9a7f4b9c0 100644 --- a/test/behavior/array.zig +++ b/test/behavior/array.zig @@ -138,6 +138,7 @@ test "array literal with specified size" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var array = [2]u8{ 1, 2 }; + _ = &array; try expect(array[0] == 1); try expect(array[1] == 2); } @@ -146,7 +147,7 @@ test "array len field" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var arr = [4]u8{ 0, 0, 0, 0 }; - var ptr = &arr; + const ptr = &arr; try expect(arr.len == 4); try comptime expect(arr.len == 4); try expect(ptr.len == 4); @@ -163,7 +164,8 @@ test "array with sentinels" { { var zero_sized: [0:0xde]u8 = [_:0xde]u8{}; try expect(zero_sized[0] == 0xde); - var reinterpreted = @as(*[1]u8, @ptrCast(&zero_sized)); + var reinterpreted: *[1]u8 = @ptrCast(&zero_sized); + _ = &reinterpreted; try expect(reinterpreted[0] == 0xde); } var arr: [3:0x55]u8 = undefined; @@ -225,6 +227,7 @@ test "implicit comptime in array type size" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var arr: [plusOne(10)]bool = undefined; + _ = &arr; try expect(arr.len == 11); } @@ -281,6 +284,7 @@ test "anonymous list literal syntax" { const S = struct { fn doTheTest() !void { var array: [4]u8 = .{ 1, 2, 3, 4 }; + _ = &array; try expect(array[0] == 1); try expect(array[1] == 2); try expect(array[2] == 3); @@ -365,6 +369,7 @@ test "runtime initialize array elem and then implicit cast to slice" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var two: i32 = 2; + _ = &two; const x: []const i32 = &[_]i32{two}; try expect(x[0] == 2); } @@ -472,6 +477,7 @@ test "anonymous literal in array" { .{ .a = 3 }, .{ .b = 3 }, }; + _ = &array; try expect(array[0].a == 3); try expect(array[0].b == 4); try expect(array[1].a == 2); @@ -489,8 +495,10 @@ test "access the null element of a null terminated array" { const S = struct { fn doTheTest() !void { var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' }; + _ = &array; try expect(array[4] == 0); var len: usize = 4; + _ = &len; try expect(array[len] == 0); } }; @@ -510,6 +518,7 @@ test "type deduction for array subscript expression" { try expect(@as(u8, 0xAA) == array[if (v0) 1 else 0]); var v1 = false; try expect(@as(u8, 0x55) == array[if (v1) 1 else 0]); + _ = .{ &array, &v0, &v1 }; } }; try S.doTheTest(); @@ -529,7 +538,7 @@ test "sentinel element count towards the ABI size calculation" { fill_post: u8 = 0xAA, }; var x = T{}; - var as_slice = mem.asBytes(&x); + const as_slice = mem.asBytes(&x); try expect(@as(usize, 3) == as_slice.len); try expect(@as(u8, 0x55) == as_slice[0]); try expect(@as(u8, 0xAA) == as_slice[2]); @@ -559,6 +568,7 @@ test "zero-sized array with recursive type definition" { }; var t: S = .{ .list = .{ .s = undefined } }; + _ = &t; try expect(@as(usize, 0) == t.list.x); } @@ -576,15 +586,17 @@ test "type coercion of anon struct literal to array" { fn doTheTest() !void { var x1: u8 = 42; + _ = &x1; const t1 = .{ x1, 56, 54 }; - var arr1: [3]u8 = t1; + const arr1: [3]u8 = t1; try expect(arr1[0] == 42); try expect(arr1[1] == 56); try expect(arr1[2] == 54); var x2: U = .{ .a = 42 }; + _ = &x2; const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } }; - var arr2: [3]U = t2; + const arr2: [3]U = t2; try expect(arr2[0].a == 42); try expect(arr2[1].b == true); try expect(mem.eql(u8, arr2[2].c, "hello")); @@ -608,15 +620,17 @@ test "type coercion of pointer to anon struct literal to pointer to array" { fn doTheTest() !void { var x1: u8 = 42; + _ = &x1; const t1 = &.{ x1, 56, 54 }; - var arr1: *const [3]u8 = t1; + const arr1: *const [3]u8 = t1; try expect(arr1[0] == 42); try expect(arr1[1] == 56); try expect(arr1[2] == 54); var x2: U = .{ .a = 42 }; + _ = &x2; const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } }; - var arr2: *const [3]U = t2; + const arr2: *const [3]U = t2; try expect(arr2[0].a == 42); try expect(arr2[1].b == true); try expect(mem.eql(u8, arr2[2].c, "hello")); @@ -656,6 +670,7 @@ test "array init of container level array variable" { } noinline fn bar(x: usize, y: usize) void { var tmp: [2]usize = .{ x, y }; + _ = &tmp; pair = tmp; } }; @@ -668,6 +683,7 @@ test "array init of container level array variable" { test "runtime initialized sentinel-terminated array literal" { var c: u16 = 300; + _ = &c; const f = &[_:0x9999]u16{c}; const g = @as(*const [4]u8, @ptrCast(f)); try std.testing.expect(g[2] == 0x99); @@ -681,6 +697,7 @@ test "array of array agregate init" { var a = [1]u32{11} ** 10; var b = [1][10]u32{a} ** 2; + _ = .{ &a, &b }; try std.testing.expect(b[1][1] == 11); } @@ -778,6 +795,7 @@ test "runtime side-effects in comptime-known array init" { test "slice initialized through reference to anonymous array init provides result types" { var my_u32: u32 = 123; var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; const foo: []const u16 = &.{ @intCast(my_u32), @intCast(my_u64), @@ -790,6 +808,7 @@ test "slice initialized through reference to anonymous array init provides resul test "pointer to array initialized through reference to anonymous array init provides result types" { var my_u32: u32 = 123; var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; const foo: *const [4]u16 = &.{ @intCast(my_u32), @intCast(my_u64), diff --git a/test/behavior/asm.zig b/test/behavior/asm.zig index ca7497225e..acb17ea004 100644 --- a/test/behavior/asm.zig +++ b/test/behavior/asm.zig @@ -180,6 +180,7 @@ test "asm modifiers (AArch64)" { if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly var x: u32 = 15; + _ = &x; const double = asm ("add %[ret:w], %[in:w], %[in:w]" : [ret] "=r" (-> u32), : [in] "r" (x), diff --git a/test/behavior/async_fn.zig b/test/behavior/async_fn.zig index 7eaa5c78d0..a8efbcfa8c 100644 --- a/test/behavior/async_fn.zig +++ b/test/behavior/async_fn.zig @@ -137,11 +137,13 @@ test "@frameSize" { fn doTheTest() !void { { var ptr = @as(fn (i32) callconv(.Async) void, @ptrCast(other)); + _ = &ptr; const size = @frameSize(ptr); try expect(size == @sizeOf(@Frame(other))); } { var ptr = @as(fn () callconv(.Async) void, @ptrCast(first)); + _ = &ptr; const size = @frameSize(ptr); try expect(size == @sizeOf(@Frame(first))); } @@ -153,7 +155,7 @@ test "@frameSize" { fn other(param: i32) void { _ = param; var local: i32 = undefined; - _ = local; + _ = &local; suspend {} } }; @@ -239,7 +241,7 @@ test "coroutine await" { await_seq('a'); var p = async await_amain(); - _ = p; + _ = &p; await_seq('f'); resume await_a_promise; await_seq('i'); @@ -279,7 +281,7 @@ test "coroutine await early return" { early_seq('a'); var p = async early_amain(); - _ = p; + _ = &p; early_seq('f'); try expect(early_final_result == 1234); try expect(std.mem.eql(u8, &early_points, "abcdef")); @@ -329,6 +331,7 @@ test "async fn pointer in a struct field" { bar: fn (*i32) callconv(.Async) void, }; var foo = Foo{ .bar = simpleAsyncFn2 }; + _ = &foo; var bytes: [64]u8 align(16) = undefined; const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); try comptime expect(@TypeOf(f) == anyframe->void); @@ -367,6 +370,7 @@ test "@asyncCall with return type" { } }; var foo = Foo{ .bar = Foo.middle }; + _ = &foo; var bytes: [150]u8 align(16) = undefined; var aresult: i32 = 0; _ = @asyncCall(&bytes, &aresult, foo.bar, .{}); @@ -385,6 +389,7 @@ test "async fn with inferred error set" { fn doTheTest() !void { var frame: [1]@Frame(middle) = undefined; var fn_ptr = middle; + _ = &fn_ptr; var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined; _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{}); resume global_frame; @@ -827,7 +832,7 @@ test "alignment of local variables in async functions" { const S = struct { fn doTheTest() !void { var y: u8 = 123; - _ = y; + _ = &y; var x: u8 align(128) = 1; try expect(@intFromPtr(&x) % 128 == 0); } @@ -843,7 +848,7 @@ test "no reason to resolve frame still works" { } fn simpleNothing() void { var x: i32 = 1234; - _ = x; + _ = &x; } test "async call a generic function" { @@ -913,13 +918,14 @@ test "struct parameter to async function is copied to the frame" { if (x == 0) return; clobberStack(x - 1); var y: i32 = x; - _ = y; + _ = &y; } fn bar(f: *@Frame(foo)) void { var pt = Point{ .x = 1, .y = 2 }; + _ = &pt; f.* = async foo(pt); - var result = await f; + const result = await f; expect(result == 1) catch @panic("test failure"); } @@ -1141,6 +1147,7 @@ test "@asyncCall using the result location inside the frame" { bar: fn (*i32) callconv(.Async) i32, }; var foo = Foo{ .bar = S.simple2 }; + _ = &foo; var bytes: [64]u8 align(16) = undefined; const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); try comptime expect(@TypeOf(f) == anyframe->i32); @@ -1465,7 +1472,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" { // the for loop spills still happen even though there is a VarDecl in scope // before the suspend. var anything = true; - _ = anything; + _ = &anything; suspend { global_frame = @frame(); } @@ -1538,6 +1545,7 @@ test "async function passed align(16) arg after align(8) arg" { fn foo() void { var a: u128 = 99; + _ = &a; bar(10, .{a}) catch unreachable; } @@ -1590,6 +1598,7 @@ test "async function call resolves target fn frame, runtime func" { const stack_size = 1000; var stack_frame: [stack_size]u8 align(std.Target.stack_align) = undefined; var func: fn () callconv(.Async) anyerror!void = bar; + _ = &func; return await @asyncCall(&stack_frame, {}, func, .{}); } @@ -1614,6 +1623,7 @@ test "properly spill optional payload capture value" { fn foo() void { var opt: ?usize = 1234; + _ = &opt; if (opt) |x| { bar(); global_int += x; @@ -1863,6 +1873,7 @@ test "@asyncCall with pass-by-value arguments" { var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; // The function pointer must not be comptime-known. var t = S.f; + _ = &t; var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, .{ .f0 = 1, .f1 = 2 }, @@ -1870,7 +1881,7 @@ test "@asyncCall with pass-by-value arguments" { [_]u8{ 1, 2, 3, 4, 5 }, F2, }); - _ = frame_ptr; + _ = &frame_ptr; } test "@asyncCall with arguments having non-standard alignment" { @@ -1893,6 +1904,7 @@ test "@asyncCall with arguments having non-standard alignment" { var buffer: [1024]u8 align(@alignOf(@Frame(S.f))) = undefined; // The function pointer must not be comptime-known. var t = S.f; + _ = &t; var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 }); - _ = frame_ptr; + _ = &frame_ptr; } diff --git a/test/behavior/await_struct.zig b/test/behavior/await_struct.zig index bc1420f96a..4175a90cd9 100644 --- a/test/behavior/await_struct.zig +++ b/test/behavior/await_struct.zig @@ -14,7 +14,7 @@ test "coroutine await struct" { await_seq('a'); var p = async await_amain(); - _ = p; + _ = &p; await_seq('f'); resume await_a_promise; await_seq('i'); diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index 30b6286658..c2ec18d0fe 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -118,6 +118,7 @@ fn thisIsAColdFn() void { test "unicode escape in character literal" { var a: u24 = '\u{01f4a9}'; + _ = &a; try expect(a == 128169); } @@ -362,6 +363,7 @@ test "variable is allowed to be a pointer to an opaque type" { } fn hereIsAnOpaqueType(ptr: *OpaqueA) *OpaqueA { var a = ptr; + _ = &a; return a; } @@ -441,6 +443,7 @@ test "double implicit cast in same expression" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x = @as(i32, @as(u16, nine())); + _ = &x; try expect(x == 9); } fn nine() u8 { @@ -570,6 +573,7 @@ test "comptime cast fn to ptr" { test "equality compare fn ptrs" { var a = &emptyFn; + _ = &a; try expect(a == a); } @@ -611,6 +615,7 @@ test "global constant is loaded with a runtime-known index" { const S = struct { fn doTheTest() !void { var index: usize = 1; + _ = &index; const ptr = &pieces[index].field; try expect(ptr.* == 2); } @@ -785,6 +790,7 @@ test "variable name containing underscores does not shadow int primitive" { test "if expression type coercion" { var cond: bool = true; + _ = &cond; const x: u16 = if (cond) 1 else 0; try expect(@as(u16, x) == 1); } @@ -825,6 +831,7 @@ test "discarding the result of various expressions" { test "labeled block implicitly ends in a break" { var a = false; + _ = &a; blk: { if (a) break :blk; } @@ -852,6 +859,7 @@ test "catch in block has correct result location" { test "labeled block with runtime branch forwards its result location type to break statements" { const E = enum { a, b }; var a = false; + _ = &a; const e: E = blk: { if (a) { break :blk .a; @@ -872,8 +880,7 @@ test "try in labeled block doesn't cast to wrong type" { }; const s: ?*S = blk: { var a = try S.foo(); - - _ = a; + _ = &a; break :blk null; }; _ = s; @@ -894,6 +901,7 @@ test "weird array and tuple initializations" { const E = enum { a, b }; const S = struct { e: E }; var a = false; + _ = &a; const b = S{ .e = .a }; _ = &[_]S{ @@ -1009,6 +1017,7 @@ test "switch inside @as gets correct type" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: u32 = 0; + _ = &a; var b: [2]u32 = undefined; b[0] = @as(u32, switch (a) { 1 => 1, @@ -1110,7 +1119,8 @@ test "orelse coercion as function argument" { } }; var optional: ?Loc = .{}; - var foo = Container.init(optional orelse .{}); + _ = &optional; + const foo = Container.init(optional orelse .{}); try expect(foo.a.?.start == -1); } @@ -1153,6 +1163,7 @@ test "arrays and vectors with big integers" { test "pointer to struct literal with runtime field is constant" { const S = struct { data: usize }; var runtime_zero: usize = 0; + _ = &runtime_zero; const ptr = &S{ .data = runtime_zero }; try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_const); } @@ -1163,6 +1174,7 @@ test "integer compare" { var z: T = 0; var p: T = 123; var n: T = -123; + _ = .{ &z, &p, &n }; try expect(z == z and z != p and z != n); try expect(p == p and p != n and n == n); try expect(z > n and z < p and z >= n and z <= p); @@ -1180,6 +1192,7 @@ test "integer compare" { fn doTheTestUnsigned(comptime T: type) !void { var z: T = 0; var p: T = 123; + _ = .{ &z, &p }; try expect(z == z and z != p); try expect(p == p); try expect(z < p and z <= p); diff --git a/test/behavior/bit_shifting.zig b/test/behavior/bit_shifting.zig index 8b605385d2..b47dfa23c1 100644 --- a/test/behavior/bit_shifting.zig +++ b/test/behavior/bit_shifting.zig @@ -99,9 +99,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c // #2225 test "comptime shr of BigInt" { comptime { - var n0 = 0xdeadbeef0000000000000000; + const n0 = 0xdeadbeef0000000000000000; try expect(n0 >> 64 == 0xdeadbeef); - var n1 = 17908056155735594659; + const n1 = 17908056155735594659; try expect(n1 >> 64 == 0); } } diff --git a/test/behavior/bitcast.zig b/test/behavior/bitcast.zig index 846a1c33af..131a8ee0ac 100644 --- a/test/behavior/bitcast.zig +++ b/test/behavior/bitcast.zig @@ -149,8 +149,9 @@ test "bitcast literal [4]u8 param to u32" { } test "bitcast generates a temporary value" { - var y = @as(u16, 0x55AA); - const x = @as(u16, @bitCast(@as([2]u8, @bitCast(y)))); + var y: u16 = 0x55AA; + _ = &y; + const x: u16 = @bitCast(@as([2]u8, @bitCast(y))); try expect(y == x); } @@ -171,7 +172,8 @@ test "@bitCast packed structs at runtime and comptime" { const S = struct { fn doTheTest() !void { var full = Full{ .number = 0x1234 }; - var two_halves = @as(Divided, @bitCast(full)); + _ = &full; + const two_halves: Divided = @bitCast(full); try expect(two_halves.half1 == 0x34); try expect(two_halves.quarter3 == 0x2); try expect(two_halves.quarter4 == 0x1); @@ -195,7 +197,8 @@ test "@bitCast extern structs at runtime and comptime" { const S = struct { fn doTheTest() !void { var full = Full{ .number = 0x1234 }; - var two_halves = @as(TwoHalves, @bitCast(full)); + _ = &full; + const two_halves: TwoHalves = @bitCast(full); switch (native_endian) { .big => { try expect(two_halves.half1 == 0x12); @@ -225,8 +228,9 @@ test "bitcast packed struct to integer and back" { const S = struct { fn doTheTest() !void { var move = LevelUpMove{ .move_id = 1, .level = 2 }; - var v = @as(u16, @bitCast(move)); - var back_to_a_move = @as(LevelUpMove, @bitCast(v)); + _ = &move; + const v: u16 = @bitCast(move); + const back_to_a_move: LevelUpMove = @bitCast(v); try expect(back_to_a_move.move_id == 1); try expect(back_to_a_move.level == 2); } @@ -312,7 +316,8 @@ test "@bitCast packed struct of floats" { const S = struct { fn doTheTest() !void { var foo = Foo{}; - var v = @as(Foo2, @bitCast(foo)); + _ = &foo; + const v: Foo2 = @bitCast(foo); try expect(v.a == foo.a); try expect(v.b == foo.b); try expect(v.c == foo.c); @@ -354,10 +359,12 @@ test "comptime @bitCast packed struct to int and back" { // S -> Int var s: S = .{}; + _ = &s; try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{}))); // Int -> S var i: Int = 0; + _ = &i; const rt_cast = @as(S, @bitCast(i)); const ct_cast = comptime @as(S, @bitCast(@as(Int, 0))); inline for (@typeInfo(S).Struct.fields) |field| { @@ -376,6 +383,7 @@ test "comptime bitcast with fields following f80" { const FloatT = extern struct { f: f80, x: u128 align(16) }; const x: FloatT = .{ .f = 0.5, .x = 123 }; var x_as_uint: u256 = comptime @as(u256, @bitCast(x)); + _ = &x_as_uint; try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f); try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x); @@ -428,6 +436,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u16, bitCastWrapper16(snan_f16_const)); var snan_f16_var = math.snan(f16); + _ = &snan_f16_var; try expectEqual(snan_u16, @as(u16, @bitCast(snan_f16_var))); try expectEqual(snan_u16, bitCastWrapper16(snan_f16_var)); @@ -437,6 +446,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u32, bitCastWrapper32(snan_f32_const)); var snan_f32_var = math.snan(f32); + _ = &snan_f32_var; try expectEqual(snan_u32, @as(u32, @bitCast(snan_f32_var))); try expectEqual(snan_u32, bitCastWrapper32(snan_f32_var)); @@ -446,6 +456,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u64, bitCastWrapper64(snan_f64_const)); var snan_f64_var = math.snan(f64); + _ = &snan_f64_var; try expectEqual(snan_u64, @as(u64, @bitCast(snan_f64_var))); try expectEqual(snan_u64, bitCastWrapper64(snan_f64_var)); @@ -455,6 +466,7 @@ test "bitcast nan float does not modify signaling bit" { try expectEqual(snan_u128, bitCastWrapper128(snan_f128_const)); var snan_f128_var = math.snan(f128); + _ = &snan_f128_var; try expectEqual(snan_u128, @as(u128, @bitCast(snan_f128_var))); try expectEqual(snan_u128, bitCastWrapper128(snan_f128_var)); } diff --git a/test/behavior/bitreverse.zig b/test/behavior/bitreverse.zig index b254910e46..a179e120e8 100644 --- a/test/behavior/bitreverse.zig +++ b/test/behavior/bitreverse.zig @@ -86,11 +86,30 @@ fn testBitReverse() !void { try expect(@bitReverse(@as(i24, -6773785)) == @bitReverse(neg24)); var neg32: i32 = -16773785; try expect(@bitReverse(@as(i32, -16773785)) == @bitReverse(neg32)); + + _ = .{ + &num0, + &num5, + &num8, + &num16, + &num24, + &num32, + &num40, + &num48, + &num56, + &num64, + &num128, + &neg8, + &neg16, + &neg24, + &neg32, + }; } fn vector8() !void { var v = @Vector(2, u8){ 0x12, 0x23 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0x48); try expect(result[1] == 0xc4); } @@ -109,7 +128,8 @@ test "bitReverse vectors u8" { fn vector16() !void { var v = @Vector(2, u16){ 0x1234, 0x2345 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0x2c48); try expect(result[1] == 0xa2c4); } @@ -128,7 +148,8 @@ test "bitReverse vectors u16" { fn vector24() !void { var v = @Vector(2, u24){ 0x123456, 0x234567 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0x6a2c48); try expect(result[1] == 0xe6a2c4); } @@ -147,7 +168,8 @@ test "bitReverse vectors u24" { fn vector0() !void { var v = @Vector(2, u0){ 0, 0 }; - var result = @bitReverse(v); + _ = &v; + const result = @bitReverse(v); try expect(result[0] == 0); try expect(result[1] == 0); } diff --git a/test/behavior/bugs/10147.zig b/test/behavior/bugs/10147.zig index a1fe9bff68..b8d6090479 100644 --- a/test/behavior/bugs/10147.zig +++ b/test/behavior/bugs/10147.zig @@ -10,9 +10,11 @@ test "test calling @clz on both vector and scalar inputs" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u32 = 0x1; + _ = &x; var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 }; - var a = @clz(x); - var b = @clz(y); + _ = &y; + const a = @clz(x); + const b = @clz(y); try std.testing.expectEqual(@as(u6, 31), a); try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b); } diff --git a/test/behavior/bugs/10970.zig b/test/behavior/bugs/10970.zig index 539dfaff71..cd1c78ad98 100644 --- a/test/behavior/bugs/10970.zig +++ b/test/behavior/bugs/10970.zig @@ -9,6 +9,7 @@ test "breaking from a loop in an if statement" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var cond = true; + _ = &cond; const opt = while (cond) { if (retOpt()) |opt| { break opt; diff --git a/test/behavior/bugs/11046.zig b/test/behavior/bugs/11046.zig index a13e02e45c..3c08dc649e 100644 --- a/test/behavior/bugs/11046.zig +++ b/test/behavior/bugs/11046.zig @@ -2,6 +2,7 @@ const builtin = @import("builtin"); fn foo() !void { var a = true; + _ = &a; if (a) return error.Foo; return error.Bar; } diff --git a/test/behavior/bugs/11139.zig b/test/behavior/bugs/11139.zig index 7af8b59101..93b25f3921 100644 --- a/test/behavior/bugs/11139.zig +++ b/test/behavior/bugs/11139.zig @@ -21,5 +21,6 @@ fn storeArrayOfArrayOfStructs() u8 { S{ .x = 15 }, }, }; + _ = &cases; return cases[0][0].x; } diff --git a/test/behavior/bugs/11159.zig b/test/behavior/bugs/11159.zig index 352491fefc..56ffb45b82 100644 --- a/test/behavior/bugs/11159.zig +++ b/test/behavior/bugs/11159.zig @@ -4,7 +4,7 @@ const builtin = @import("builtin"); test { const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); var a: T = .{ 0, 0 }; - _ = a; + _ = &a; } test { @@ -13,7 +13,7 @@ test { comptime y: u32 = 0, }; var a: S = .{}; - _ = a; + _ = &a; var b = S{}; - _ = b; + _ = &b; } diff --git a/test/behavior/bugs/11162.zig b/test/behavior/bugs/11162.zig index 6b4cef78e7..918cf1c793 100644 --- a/test/behavior/bugs/11162.zig +++ b/test/behavior/bugs/11162.zig @@ -6,8 +6,9 @@ test "aggregate initializers should allow initializing comptime fields, verifyin if (true) return error.SkipZigTest; // TODO var x: u32 = 15; + _ = &x; const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); - var a: T = .{ -1234, 5678, x + 1 }; + const a: T = .{ -1234, 5678, x + 1 }; try expect(a[0] == -1234); try expect(a[1] == 5678); diff --git a/test/behavior/bugs/11165.zig b/test/behavior/bugs/11165.zig index e23861ddc1..ff4695f647 100644 --- a/test/behavior/bugs/11165.zig +++ b/test/behavior/bugs/11165.zig @@ -18,7 +18,7 @@ test "bytes" { }; var u_2 = U{ .s = s_1 }; - _ = u_2; + _ = &u_2; } test "aggregate" { @@ -40,5 +40,5 @@ test "aggregate" { }; var u_2 = U{ .s = s_1 }; - _ = u_2; + _ = &u_2; } diff --git a/test/behavior/bugs/11181.zig b/test/behavior/bugs/11181.zig index 8abccc40c3..7819fe0ad8 100644 --- a/test/behavior/bugs/11181.zig +++ b/test/behavior/bugs/11181.zig @@ -21,5 +21,5 @@ test "var inferred array of slices" { .{ .v = false }, }, }; - _ = decls; + _ = &decls; } diff --git a/test/behavior/bugs/12000.zig b/test/behavior/bugs/12000.zig index d7b856d2f5..d13e402d87 100644 --- a/test/behavior/bugs/12000.zig +++ b/test/behavior/bugs/12000.zig @@ -11,5 +11,6 @@ test { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO var t: T = .{ .next = null }; + _ = &t; try std.testing.expect(t.next == null); } diff --git a/test/behavior/bugs/12025.zig b/test/behavior/bugs/12025.zig index 92f8aff0aa..73eca7c99b 100644 --- a/test/behavior/bugs/12025.zig +++ b/test/behavior/bugs/12025.zig @@ -5,6 +5,7 @@ test { .foo = &1, .bar = &2, }; + _ = &st; inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| { _ = field; diff --git a/test/behavior/bugs/12092.zig b/test/behavior/bugs/12092.zig index e5e89a9c58..673a0f1f47 100644 --- a/test/behavior/bugs/12092.zig +++ b/test/behavior/bugs/12092.zig @@ -19,6 +19,7 @@ test { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO var baz: u32 = 24; + _ = &baz; try takeFoo(&.{ .a = .{ .b = baz, diff --git a/test/behavior/bugs/12498.zig b/test/behavior/bugs/12498.zig index 3e4bafc2db..fd9ee98d29 100644 --- a/test/behavior/bugs/12498.zig +++ b/test/behavior/bugs/12498.zig @@ -4,5 +4,6 @@ const expect = std.testing.expect; const S = struct { a: usize }; test "lazy abi size used in comparison" { var rhs: i32 = 100; + _ = &rhs; try expect(@sizeOf(S) < rhs); } diff --git a/test/behavior/bugs/12776.zig b/test/behavior/bugs/12776.zig index 91df319dec..8195a9df6f 100644 --- a/test/behavior/bugs/12776.zig +++ b/test/behavior/bugs/12776.zig @@ -22,6 +22,7 @@ const CPU = packed struct { } fn tick(self: *CPU) !void { var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F); + _ = &queued_interrupts; if (self.interrupts and queued_interrupts != 0) { self.interrupts = false; } diff --git a/test/behavior/bugs/12891.zig b/test/behavior/bugs/12891.zig index 354d9e856e..20caab294c 100644 --- a/test/behavior/bugs/12891.zig +++ b/test/behavior/bugs/12891.zig @@ -4,26 +4,31 @@ const builtin = @import("builtin"); test "issue12891" { const f = 10.0; var i: usize = 0; + _ = &i; try std.testing.expect(i < f); } test "nan" { const f = comptime std.math.nan(f64); var i: usize = 0; + _ = &i; try std.testing.expect(!(f < i)); } test "inf" { const f = comptime std.math.inf(f64); var i: usize = 0; + _ = &i; try std.testing.expect(f > i); } test "-inf < 0" { const f = comptime -std.math.inf(f64); var i: usize = 0; + _ = &i; try std.testing.expect(f < i); } test "inf >= 1" { const f = comptime std.math.inf(f64); var i: usize = 1; + _ = &i; try std.testing.expect(f >= i); } test "isNan(nan * 1)" { diff --git a/test/behavior/bugs/12972.zig b/test/behavior/bugs/12972.zig index 3c256a19f8..f27a6bac8d 100644 --- a/test/behavior/bugs/12972.zig +++ b/test/behavior/bugs/12972.zig @@ -12,6 +12,7 @@ test { f(&.{c}); var v: u8 = 42; + _ = &v; f(&[_:null]?u8{v}); f(&.{v}); } diff --git a/test/behavior/bugs/12984.zig b/test/behavior/bugs/12984.zig index 75f2747eda..5cbb021ba9 100644 --- a/test/behavior/bugs/12984.zig +++ b/test/behavior/bugs/12984.zig @@ -16,5 +16,5 @@ test "simple test" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO var c: CustomDraw = undefined; - _ = c; + _ = &c; } diff --git a/test/behavior/bugs/13128.zig b/test/behavior/bugs/13128.zig index b87513d510..fff5be8e7e 100644 --- a/test/behavior/bugs/13128.zig +++ b/test/behavior/bugs/13128.zig @@ -18,6 +18,7 @@ test "runtime union init, most-aligned field != largest" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u8 = 1; + _ = &x; try foo(.{ .x = x }); const val: U = @unionInit(U, "x", x); diff --git a/test/behavior/bugs/13159.zig b/test/behavior/bugs/13159.zig index eec01658e6..db28f9e5be 100644 --- a/test/behavior/bugs/13159.zig +++ b/test/behavior/bugs/13159.zig @@ -13,5 +13,6 @@ test { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var foo = Bar.Baz.fizz; + _ = &foo; try expect(foo == .fizz); } diff --git a/test/behavior/bugs/13285.zig b/test/behavior/bugs/13285.zig index 15ebfa5804..a50cf71e55 100644 --- a/test/behavior/bugs/13285.zig +++ b/test/behavior/bugs/13285.zig @@ -8,7 +8,7 @@ test { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: Crasher = undefined; - var crasher_ptr = &a; + const crasher_ptr = &a; var crasher_local = crasher_ptr.*; const crasher_local_ptr = &crasher_local; crasher_local_ptr.lets_crash = 1; diff --git a/test/behavior/bugs/13366.zig b/test/behavior/bugs/13366.zig index 9b08bcd3fc..c87f122929 100644 --- a/test/behavior/bugs/13366.zig +++ b/test/behavior/bugs/13366.zig @@ -18,9 +18,11 @@ test { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO var a: u32 = 16; + _ = &a; var reason = .{ .c_import = .{ .a = a } }; var block = Block{ .reason = &reason, }; + _ = █ try expect(block.reason.?.c_import.a == 16); } diff --git a/test/behavior/bugs/13714.zig b/test/behavior/bugs/13714.zig index f11dac3676..b1902720c5 100644 --- a/test/behavior/bugs/13714.zig +++ b/test/behavior/bugs/13714.zig @@ -1,4 +1,5 @@ comptime { var image: [1]u8 = undefined; + _ = ℑ _ = @shlExact(@as(u16, image[0]), 8); } diff --git a/test/behavior/bugs/13785.zig b/test/behavior/bugs/13785.zig index 53d03f5413..e3c71d954c 100644 --- a/test/behavior/bugs/13785.zig +++ b/test/behavior/bugs/13785.zig @@ -9,5 +9,6 @@ test { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var a: u8 = 0; + _ = &a; try std.io.null_writer.print("\n{} {}\n", .{ a, S{} }); } diff --git a/test/behavior/bugs/1381.zig b/test/behavior/bugs/1381.zig index c9ea2102f5..090883e875 100644 --- a/test/behavior/bugs/1381.zig +++ b/test/behavior/bugs/1381.zig @@ -20,6 +20,7 @@ test "union that needs padding bytes inside an array" { A{ .B = B{ .D = 1 } }, A{ .B = B{ .D = 1 } }, }; + _ = &as; const a = as[0].B; try std.testing.expect(a.D == 1); diff --git a/test/behavior/bugs/1442.zig b/test/behavior/bugs/1442.zig index 02170ccabe..3d02686c48 100644 --- a/test/behavior/bugs/1442.zig +++ b/test/behavior/bugs/1442.zig @@ -12,5 +12,6 @@ test "const error union field alignment" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var union_or_err: anyerror!Union = Union{ .Color = 1234 }; + _ = &union_or_err; try std.testing.expect((union_or_err catch unreachable).Color == 1234); } diff --git a/test/behavior/bugs/1500.zig b/test/behavior/bugs/1500.zig index cc12c5d0be..ac0d76f879 100644 --- a/test/behavior/bugs/1500.zig +++ b/test/behavior/bugs/1500.zig @@ -8,6 +8,7 @@ const B = *const fn (A) void; test "allow these dependencies" { var a: A = undefined; var b: B = undefined; + _ = .{ &a, &b }; if (false) { a; b; diff --git a/test/behavior/bugs/1735.zig b/test/behavior/bugs/1735.zig index 68f851e578..0115143b94 100644 --- a/test/behavior/bugs/1735.zig +++ b/test/behavior/bugs/1735.zig @@ -45,6 +45,6 @@ test "initialization" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - var t = a.init(); + const t = a.init(); try std.testing.expect(t.foo.len == 0); } diff --git a/test/behavior/bugs/2557.zig b/test/behavior/bugs/2557.zig index 05cf8156c0..3f05b628ab 100644 --- a/test/behavior/bugs/2557.zig +++ b/test/behavior/bugs/2557.zig @@ -2,5 +2,5 @@ test { var a = if (true) { return; } else true; - _ = a; + _ = &a; } diff --git a/test/behavior/bugs/3468.zig b/test/behavior/bugs/3468.zig index adf3db3306..293e608aec 100644 --- a/test/behavior/bugs/3468.zig +++ b/test/behavior/bugs/3468.zig @@ -3,4 +3,5 @@ test "pointer deref next to assignment" { var a:i32=2; var b=&a; b.*=3; + _=&b; } diff --git a/test/behavior/bugs/3586.zig b/test/behavior/bugs/3586.zig index 1952714728..5bc682b149 100644 --- a/test/behavior/bugs/3586.zig +++ b/test/behavior/bugs/3586.zig @@ -12,5 +12,5 @@ test "fixed" { var ctr = Container{ .params = NoteParams{}, }; - _ = ctr; + _ = &ctr; } diff --git a/test/behavior/bugs/4560.zig b/test/behavior/bugs/4560.zig index ca9a34ea89..4f6e456755 100644 --- a/test/behavior/bugs/4560.zig +++ b/test/behavior/bugs/4560.zig @@ -11,6 +11,7 @@ test "fixed" { .max_distance_from_start_index = 456, }, }; + _ = &s; try std.testing.expect(s.a == 1); try std.testing.expect(s.b.size == 123); try std.testing.expect(s.b.max_distance_from_start_index == 456); diff --git a/test/behavior/bugs/6047.zig b/test/behavior/bugs/6047.zig index 9e6547a116..0288a52627 100644 --- a/test/behavior/bugs/6047.zig +++ b/test/behavior/bugs/6047.zig @@ -6,6 +6,7 @@ fn getError() !void { fn getError2() !void { var a: u8 = 'c'; + _ = &a; try if (a == 'a') getError() else if (a == 'b') getError() else getError(); } diff --git a/test/behavior/bugs/624.zig b/test/behavior/bugs/624.zig index a0a93c0104..14d6bbdfb1 100644 --- a/test/behavior/bugs/624.zig +++ b/test/behavior/bugs/624.zig @@ -25,5 +25,6 @@ test "foo" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var allocator = ContextAllocator{ .n = 10 }; + _ = &allocator; try expect(allocator.n == 10); } diff --git a/test/behavior/bugs/656.zig b/test/behavior/bugs/656.zig index 004f442165..a44ccb3647 100644 --- a/test/behavior/bugs/656.zig +++ b/test/behavior/bugs/656.zig @@ -22,6 +22,7 @@ fn foo(a: bool, b: bool) !void { var prefix_op = PrefixOp{ .AddrOf = Value{ .align_expr = 1234 }, }; + _ = &prefix_op; if (a) {} else { switch (prefix_op) { PrefixOp.AddrOf => |addr_of_info| { diff --git a/test/behavior/bugs/6781.zig b/test/behavior/bugs/6781.zig index eb1f9766d1..fdbb1dd917 100644 --- a/test/behavior/bugs/6781.zig +++ b/test/behavior/bugs/6781.zig @@ -51,7 +51,8 @@ pub const JournalHeader = packed struct { return @as(u128, @bitCast(target[0..hash_chain_root_size].*)); } else { var array = target[0..hash_chain_root_size].*; - return @as(u128, @bitCast(array)); + _ = &array; + return @bitCast(array); } } diff --git a/test/behavior/bugs/679.zig b/test/behavior/bugs/679.zig index 6420e7f99f..81de1bb038 100644 --- a/test/behavior/bugs/679.zig +++ b/test/behavior/bugs/679.zig @@ -14,5 +14,6 @@ const Element = struct { test "false dependency loop in struct definition" { const listType = ElementList; var x: listType = 42; + _ = &x; try expect(x == 42); } diff --git a/test/behavior/bugs/6905.zig b/test/behavior/bugs/6905.zig index be96efaace..2d473e108c 100644 --- a/test/behavior/bugs/6905.zig +++ b/test/behavior/bugs/6905.zig @@ -6,13 +6,15 @@ test "sentinel-terminated 0-length slices" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO - var u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; + const u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; var index: u8 = 2; - var slice = u32s[index..index :2]; - var array_ptr = u32s[2..2 :2]; + _ = &index; + const slice = u32s[index..index :2]; + const array_ptr = u32s[2..2 :2]; const comptime_known_array_value = u32s[2..2 :2].*; var runtime_array_value = u32s[2..2 :2].*; + _ = &runtime_array_value; try expect(slice[0] == 2); try expect(array_ptr[0] == 2); diff --git a/test/behavior/bugs/7187.zig b/test/behavior/bugs/7187.zig index bb2e82af89..0af9512963 100644 --- a/test/behavior/bugs/7187.zig +++ b/test/behavior/bugs/7187.zig @@ -5,7 +5,7 @@ const expect = std.testing.expect; test "miscompilation with bool return type" { var x: usize = 1; var y: bool = getFalse(); - _ = y; + _ = .{ &x, &y }; try expect(x == 1); } diff --git a/test/behavior/bugs/726.zig b/test/behavior/bugs/726.zig index c544e422a4..e6fd6a92b3 100644 --- a/test/behavior/bugs/726.zig +++ b/test/behavior/bugs/726.zig @@ -7,7 +7,8 @@ test "@ptrCast from const to nullable" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO const c: u8 = 4; - var x: ?*const u8 = @as(?*const u8, @ptrCast(&c)); + var x: ?*const u8 = @ptrCast(&c); + _ = &x; try expect(x.?.* == 4); } @@ -19,6 +20,7 @@ test "@ptrCast from var in empty struct to nullable" { const container = struct { var c: u8 = 4; }; - var x: ?*const u8 = @as(?*const u8, @ptrCast(&container.c)); + var x: ?*const u8 = @ptrCast(&container.c); + _ = &x; try expect(x.?.* == 4); } diff --git a/test/behavior/bugs/7325.zig b/test/behavior/bugs/7325.zig index 3652553b51..85c3b385f0 100644 --- a/test/behavior/bugs/7325.zig +++ b/test/behavior/bugs/7325.zig @@ -85,6 +85,7 @@ test { var param: ParamType = .{ .one_of = .{ .name = "name" }, }; + _ = ¶m; var arg: CallArg = .{ .value = .{ .literal_enum_value = .{ @@ -92,6 +93,7 @@ test { }, }, }; + _ = &arg; const result = try genExpression(arg.value); switch (result) { diff --git a/test/behavior/bugs/9584.zig b/test/behavior/bugs/9584.zig index 6f3223c362..0e41307bf4 100644 --- a/test/behavior/bugs/9584.zig +++ b/test/behavior/bugs/9584.zig @@ -60,6 +60,7 @@ test { .g = false, .h = false, }; + _ = &flags; var x = X{ .x = flags, }; diff --git a/test/behavior/byteswap.zig b/test/behavior/byteswap.zig index 88c5372364..3cbf35a40c 100644 --- a/test/behavior/byteswap.zig +++ b/test/behavior/byteswap.zig @@ -56,7 +56,8 @@ test "@byteSwap integers" { fn vector8() !void { var v = @Vector(2, u8){ 0x12, 0x13 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0x12); try expect(result[1] == 0x13); } @@ -75,7 +76,8 @@ test "@byteSwap vectors u8" { fn vector16() !void { var v = @Vector(2, u16){ 0x1234, 0x2345 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0x3412); try expect(result[1] == 0x4523); } @@ -94,7 +96,8 @@ test "@byteSwap vectors u16" { fn vector24() !void { var v = @Vector(2, u24){ 0x123456, 0x234567 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0x563412); try expect(result[1] == 0x674523); } @@ -113,7 +116,8 @@ test "@byteSwap vectors u24" { fn vector0() !void { var v = @Vector(2, u0){ 0, 0 }; - var result = @byteSwap(v); + _ = &v; + const result = @byteSwap(v); try expect(result[0] == 0); try expect(result[1] == 0); } diff --git a/test/behavior/call.zig b/test/behavior/call.zig index 61aa48803b..a476ba1788 100644 --- a/test/behavior/call.zig +++ b/test/behavior/call.zig @@ -47,6 +47,7 @@ test "basic invocations" { { // call of non comptime-known function var alias_foo = &foo; + _ = &alias_foo; try expect(@call(.no_async, alias_foo, .{}) == 1234); try expect(@call(.never_tail, alias_foo, .{}) == 1234); try expect(@call(.never_inline, alias_foo, .{}) == 1234); @@ -66,6 +67,7 @@ test "tuple parameters" { }.add; var a: i32 = 12; var b: i32 = 34; + _ = .{ &a, &b }; try expect(@call(.auto, add, .{ a, 34 }) == 46); try expect(@call(.auto, add, .{ 12, b }) == 46); try expect(@call(.auto, add, .{ a, b }) == 46); @@ -101,6 +103,7 @@ test "result location of function call argument through runtime condition and st } }; var runtime = true; + _ = &runtime; try namespace.foo(.{ .e = if (!runtime) .a else .b, }); @@ -445,6 +448,7 @@ test "non-anytype generic parameters provide result type" { var rt_u16: u16 = 123; var rt_u32: u32 = 0x10000222; + _ = .{ &rt_u16, &rt_u32 }; try S.f(u8, @intCast(rt_u16)); try S.f(u8, @intCast(123)); @@ -470,6 +474,7 @@ test "argument to generic function has correct result type" { fn doTheTest() !void { var t = true; + _ = &t; // Since the enum literal passes through a runtime conditional here, these can only // compile if RLS provides the correct result type to the argument diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index aeb7a8f1fa..3bbb1e9a9a 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); @@ -2446,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); +} diff --git a/test/behavior/cast_int.zig b/test/behavior/cast_int.zig index 23e5a614f8..8a832f7820 100644 --- a/test/behavior/cast_int.zig +++ b/test/behavior/cast_int.zig @@ -12,7 +12,8 @@ test "@intCast i32 to u7" { var x: u128 = maxInt(u128); var y: i32 = 120; - var z = x >> @as(u7, @intCast(y)); + _ = .{ &x, &y }; + const z = x >> @as(u7, @intCast(y)); try expect(z == 0xff); } @@ -23,20 +24,24 @@ test "coerce i8 to i32 and @intCast back" { var x: i8 = -5; var y: i32 = -5; + _ = .{ &x, &y }; try expect(y == x); var x2: i32 = -5; var y2: i8 = -5; + _ = .{ &x2, &y2 }; try expect(y2 == @as(i8, @intCast(x2))); } test "coerce non byte-sized integers accross 32bits boundary" { { var v: u21 = 6417; + _ = &v; const a: u32 = v; const b: u64 = v; const c: u64 = a; var w: u64 = 0x1234567812345678; + _ = &w; const d: u21 = @truncate(w); const e: u60 = d; try expectEqual(@as(u32, 6417), a); @@ -48,10 +53,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { { var v: u10 = 234; + _ = &v; const a: u32 = v; const b: u64 = v; const c: u64 = a; var w: u64 = 0x1234567812345678; + _ = &w; const d: u10 = @truncate(w); const e: u60 = d; try expectEqual(@as(u32, 234), a); @@ -62,10 +69,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { } { var v: u7 = 11; + _ = &v; const a: u32 = v; const b: u64 = v; const c: u64 = a; var w: u64 = 0x1234567812345678; + _ = &w; const d: u7 = @truncate(w); const e: u60 = d; try expectEqual(@as(u32, 11), a); @@ -77,10 +86,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { { var v: i21 = -6417; + _ = &v; const a: i32 = v; const b: i64 = v; const c: i64 = a; var w: i64 = -12345; + _ = &w; const d: i21 = @intCast(w); const e: i60 = d; try expectEqual(@as(i32, -6417), a); @@ -92,10 +103,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { { var v: i10 = -234; + _ = &v; const a: i32 = v; const b: i64 = v; const c: i64 = a; var w: i64 = -456; + _ = &w; const d: i10 = @intCast(w); const e: i60 = d; try expectEqual(@as(i32, -234), a); @@ -106,10 +119,12 @@ test "coerce non byte-sized integers accross 32bits boundary" { } { var v: i7 = -11; + _ = &v; const a: i32 = v; const b: i64 = v; const c: i64 = a; var w: i64 = -42; + _ = &w; const d: i7 = @intCast(w); const e: i60 = d; try expectEqual(@as(i32, -11), a); @@ -152,7 +167,7 @@ test "load non byte-sized optional value" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // note: this bug is triggered by the == operator, expectEqual will hide it - var opt: ?Piece = try Piece.charToPiece('p'); + const opt: ?Piece = try Piece.charToPiece('p'); try expect(opt.?.type == .PAWN); try expect(opt.?.color == .BLACK); diff --git a/test/behavior/comptime_memory.zig b/test/behavior/comptime_memory.zig index 4245f332d6..bfeaa339b2 100644 --- a/test/behavior/comptime_memory.zig +++ b/test/behavior/comptime_memory.zig @@ -280,7 +280,7 @@ test "dance on linker values" { if (ptr_size > @sizeOf(Bits)) try doTypePunBitsTest(&weird_ptr[1]); - var arr_bytes = @as(*[2][ptr_size]u8, @ptrCast(&arr)); + const arr_bytes: *[2][ptr_size]u8 = @ptrCast(&arr); var rebuilt_bytes: [ptr_size]u8 = undefined; var i: usize = 0; diff --git a/test/behavior/destructure.zig b/test/behavior/destructure.zig index 4d7c336daa..c2a5ca329a 100644 --- a/test/behavior/destructure.zig +++ b/test/behavior/destructure.zig @@ -7,6 +7,7 @@ test "simple destructure" { fn doTheTest() !void { var x: u32 = undefined; x, const y, var z: u64 = .{ 1, @as(u16, 2), 3 }; + _ = &z; comptime assert(@TypeOf(y) == u16); @@ -25,6 +26,7 @@ test "destructure with comptime syntax" { fn doTheTest() void { comptime var x: f32 = undefined; comptime x, const y, var z = .{ 0.5, 123, 456 }; // z is a comptime var + _ = &z; comptime assert(@TypeOf(y) == comptime_int); comptime assert(@TypeOf(z) == comptime_int); @@ -112,6 +114,7 @@ test "destructure of comptime-known tuple is comptime-known" { test "destructure of comptime-known tuple where some destinations are runtime-known is comptime-known" { var z: u32 = undefined; var x: u8, const y, z = .{ 1, 2, 3 }; + _ = &x; comptime assert(@TypeOf(y) == comptime_int); comptime assert(y == 2); @@ -122,6 +125,7 @@ test "destructure of comptime-known tuple where some destinations are runtime-kn test "destructure of tuple with comptime fields results in some comptime-known values" { var runtime: u32 = 42; + _ = &runtime; const a, const b, const c, const d = .{ 123, runtime, 456, runtime }; // a, c are comptime-known diff --git a/test/behavior/empty_union.zig b/test/behavior/empty_union.zig index 40bdd627f3..f05feacfaf 100644 --- a/test/behavior/empty_union.zig +++ b/test/behavior/empty_union.zig @@ -5,12 +5,14 @@ const expect = std.testing.expect; test "switch on empty enum" { const E = enum {}; var e: E = undefined; + _ = &e; switch (e) {} } test "switch on empty enum with a specified tag type" { const E = enum(u8) {}; var e: E = undefined; + _ = &e; switch (e) {} } @@ -19,6 +21,7 @@ test "switch on empty auto numbered tagged union" { const U = union(enum(u8)) {}; var u: U = undefined; + _ = &u; switch (u) {} } @@ -28,6 +31,7 @@ test "switch on empty tagged union" { const E = enum {}; const U = union(E) {}; var u: U = undefined; + _ = &u; switch (u) {} } diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig index efd0295a97..d203476afc 100644 --- a/test/behavior/enum.zig +++ b/test/behavior/enum.zig @@ -579,6 +579,7 @@ test "enum literal cast to enum" { var color1: Color = .Auto; var color2 = Color.Auto; + _ = .{ &color1, &color2 }; try expect(color1 == color2); } @@ -663,7 +664,8 @@ test "empty non-exhaustive enum" { const E = enum(u8) { _ }; fn doTheTest(y: u8) !void { - var e = @as(E, @enumFromInt(y)); + var e: E = @enumFromInt(y); + _ = &e; try expect(switch (e) { _ => true, }); @@ -858,6 +860,7 @@ test "comparison operator on enum with one member is comptime-known" { const State = enum { Start }; test "switch on enum with one member is comptime-known" { var state = State.Start; + _ = &state; switch (state) { State.Start => return, } @@ -917,7 +920,8 @@ test "enum literal casting to tagged union" { var t = true; var x: Arch = .x86_64; - var y = if (t) x else .x86_64; + _ = .{ &t, &x }; + const y = if (t) x else .x86_64; switch (y) { .x86_64 => {}, else => @panic("fail"), @@ -1031,6 +1035,7 @@ test "tag name with assigned enum values" { B = 0, }; var b = LocalFoo.B; + _ = &b; try expect(mem.eql(u8, @tagName(b), "B")); } @@ -1055,6 +1060,7 @@ test "tag name with signed enum values" { delta = 65, }; var b = LocalFoo.bravo; + _ = &b; try expect(mem.eql(u8, @tagName(b), "bravo")); } @@ -1135,13 +1141,13 @@ test "tag name functions are unique" { const E = enum { a, b }; var b = E.a; var a = @tagName(b); - _ = a; + _ = .{ &a, &b }; } { const E = enum { a, b, c, d, e, f }; var b = E.a; var a = @tagName(b); - _ = a; + _ = .{ &a, &b }; } } @@ -1189,6 +1195,7 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" { test "runtime int to enum with one possible value" { const E = enum { one }; var runtime: usize = 0; + _ = &runtime; if (@as(E, @enumFromInt(runtime)) != .one) { @compileError("test failed"); } diff --git a/test/behavior/error.zig b/test/behavior/error.zig index dfd511af2e..715cd6e445 100644 --- a/test/behavior/error.zig +++ b/test/behavior/error.zig @@ -102,8 +102,7 @@ test "widen cast integer payload of error union function call" { const S = struct { fn errorable() !u64 { - var x = @as(u64, try number()); - return x; + return @as(u64, try number()); } fn number() anyerror!u32 { @@ -119,7 +118,7 @@ test "debug info for optional error set" { const SomeError = error{ Hello, Hello2 }; var a_local_variable: ?SomeError = null; - _ = a_local_variable; + _ = &a_local_variable; } test "implicit cast to optional to error union to return result loc" { @@ -160,6 +159,7 @@ fn entry() void { fn entryPtr() void { var ptr = &bar2; + _ = &ptr; fooPtr(ptr); } @@ -226,9 +226,9 @@ const Set1 = error{ A, B }; const Set2 = error{ A, C }; fn testExplicitErrorSetCast(set1: Set1) !void { - var x = @as(Set2, @errorCast(set1)); + const x: Set2 = @errorCast(set1); try expect(@TypeOf(x) == Set2); - var y = @as(Set1, @errorCast(x)); + const y: Set1 = @errorCast(x); try expect(@TypeOf(y) == Set1); try expect(y == error.A); } @@ -408,17 +408,17 @@ test "nested error union function call in optional unwrap" { }; fn errorable() !i32 { - var x: Foo = (try getFoo()) orelse return error.Other; + const x: Foo = (try getFoo()) orelse return error.Other; return x.a; } fn errorable2() !i32 { - var x: Foo = (try getFoo2()) orelse return error.Other; + const x: Foo = (try getFoo2()) orelse return error.Other; return x.a; } fn errorable3() !i32 { - var x: Foo = (try getFoo3()) orelse return error.Other; + const x: Foo = (try getFoo3()) orelse return error.Other; return x.a; } @@ -673,6 +673,7 @@ test "peer type resolution of two different error unions" { const a: error{B}!void = {}; const b: error{A}!void = {}; var cond = true; + _ = &cond; const err = if (cond) a else b; try err; } @@ -681,6 +682,7 @@ test "coerce error set to the current inferred error set" { const S = struct { fn foo() !void { var a = false; + _ = &a; if (a) { const b: error{A}!void = error.A; return b; @@ -831,6 +833,7 @@ test "alignment of wrapping an error union payload" { fn foo() anyerror!I { var i: I = .{ .x = 1234 }; + _ = &i; return i; } }; @@ -842,6 +845,7 @@ test "compare error union and error set" { var a: anyerror = error.Foo; var b: anyerror!u32 = error.Bar; + _ = &a; try expect(a != b); try expect(b != a); @@ -863,6 +867,7 @@ fn non_errorable() void { // This test is needed because stage 2's fix for #1923 means that catch blocks interact // with the error return trace index. var x: error{Foo}!void = {}; + _ = &x; return x catch {}; } @@ -902,6 +907,7 @@ test "optional error union return type" { const S = struct { fn foo() ?anyerror!u32 { var x: u32 = 1234; + _ = &x; return @as(anyerror!u32, x); } }; diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig index 39e9e32484..ac09066552 100644 --- a/test/behavior/eval.zig +++ b/test/behavior/eval.zig @@ -37,6 +37,7 @@ fn gimme1or2(comptime a: bool) i32 { const x: i32 = 1; const y: i32 = 2; comptime var z: i32 = if (a) x else y; + _ = &z; return z; } test "inline variable gets result of const if" { @@ -74,6 +75,7 @@ test "constant expressions" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var array: [array_size]u8 = undefined; + _ = &array; try expect(@sizeOf(@TypeOf(array)) == 20); } const array_size: u8 = 20; @@ -129,7 +131,7 @@ test "pointer to type" { comptime { var T: type = i32; try expect(T == i32); - var ptr = &T; + const ptr = &T; try expect(@TypeOf(ptr) == *type); ptr.* = f32; try expect(T == f32); @@ -372,6 +374,7 @@ fn doNothingWithType(comptime T: type) void { test "zero extend from u0 to u1" { var zero_u0: u0 = 0; var zero_u1: u1 = zero_u0; + _ = .{ &zero_u0, &zero_u1 }; try expect(zero_u1 == 0); } @@ -408,6 +411,7 @@ test "inline for with same type but different values" { var res: usize = 0; inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| { var a: T = undefined; + _ = &a; res += a.len; } try expect(res == 5); @@ -460,9 +464,9 @@ test "comptime shl" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - var a: u128 = 3; - var b: u7 = 63; - var c: u128 = 3 << 63; + const a: u128 = 3; + const b: u7 = 63; + const c: u128 = 3 << 63; try expect((a << b) == c); } @@ -489,6 +493,7 @@ test "comptime shlWithOverflow" { const ct_shifted = @shlWithOverflow(~@as(u64, 0), 16)[0]; var a = ~@as(u64, 0); + _ = &a; const rt_shifted = @shlWithOverflow(a, 16)[0]; try expect(ct_shifted == rt_shifted); @@ -521,7 +526,8 @@ test "runtime 128 bit integer division" { var a: u128 = 152313999999999991610955792383; var b: u128 = 10000000000000000000; - var c = a / b; + _ = .{ &a, &b }; + const c = a / b; try expect(c == 15231399999); } @@ -555,6 +561,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var runtime = [1]i32{3}; + _ = &runtime; comptime var i: usize = 0; inline while (i < 2) : (i += 1) { const result = if (i == 0) [1]i32{2} else runtime; @@ -692,7 +699,7 @@ test "call method with comptime pass-by-non-copying-value self parameter" { }; const s = S{ .a = 2 }; - var b = s.b(); + const b = s.b(); try expect(b == 2); } @@ -759,7 +766,8 @@ test "array concatenation peer resolves element types - value" { var a = [2]u3{ 1, 7 }; var b = [3]u8{ 200, 225, 255 }; - var c = a ++ b; + _ = .{ &a, &b }; + const c = a ++ b; comptime assert(@TypeOf(c) == [5]u8); try expect(c[0] == 1); try expect(c[1] == 7); @@ -775,7 +783,7 @@ test "array concatenation peer resolves element types - pointer" { var a = [2]u3{ 1, 7 }; var b = [3]u8{ 200, 225, 255 }; - var c = &a ++ &b; + const c = &a ++ &b; comptime assert(@TypeOf(c) == *[5]u8); try expect(c[0] == 1); try expect(c[1] == 7); @@ -791,14 +799,15 @@ test "array concatenation sets the sentinel - value" { var a = [2]u3{ 1, 7 }; var b = [3:69]u8{ 200, 225, 255 }; - var c = a ++ b; + _ = .{ &a, &b }; + const c = a ++ b; comptime assert(@TypeOf(c) == [5:69]u8); try expect(c[0] == 1); try expect(c[1] == 7); try expect(c[2] == 200); try expect(c[3] == 225); try expect(c[4] == 255); - var ptr: [*]const u8 = &c; + const ptr: [*]const u8 = &c; try expect(ptr[5] == 69); } @@ -808,14 +817,14 @@ test "array concatenation sets the sentinel - pointer" { var a = [2]u3{ 1, 7 }; var b = [3:69]u8{ 200, 225, 255 }; - var c = &a ++ &b; + const c = &a ++ &b; comptime assert(@TypeOf(c) == *[5:69]u8); try expect(c[0] == 1); try expect(c[1] == 7); try expect(c[2] == 200); try expect(c[3] == 225); try expect(c[4] == 255); - var ptr: [*]const u8 = c; + const ptr: [*]const u8 = c; try expect(ptr[5] == 69); } @@ -825,13 +834,14 @@ test "array multiplication sets the sentinel - value" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a = [2:7]u3{ 1, 6 }; - var b = a ** 2; + _ = &a; + const b = a ** 2; comptime assert(@TypeOf(b) == [4:7]u3); try expect(b[0] == 1); try expect(b[1] == 6); try expect(b[2] == 1); try expect(b[3] == 6); - var ptr: [*]const u3 = &b; + const ptr: [*]const u3 = &b; try expect(ptr[4] == 7); } @@ -841,13 +851,13 @@ test "array multiplication sets the sentinel - pointer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a = [2:7]u3{ 1, 6 }; - var b = &a ** 2; + const b = &a ** 2; comptime assert(@TypeOf(b) == *[4:7]u3); try expect(b[0] == 1); try expect(b[1] == 6); try expect(b[2] == 1); try expect(b[3] == 6); - var ptr: [*]const u3 = b; + const ptr: [*]const u3 = b; try expect(ptr[4] == 7); } @@ -913,8 +923,8 @@ test "comptime pointer load through elem_ptr" { .x = i, }; } - var ptr = @as([*]S, @ptrCast(&array)); - var x = ptr[0].x; + var ptr: [*]S = @ptrCast(&array); + const x = ptr[0].x; assert(x == 0); ptr += 1; assert(ptr[1].x == 2); @@ -953,11 +963,12 @@ test "closure capture type of runtime-known parameter" { const S = struct { fn b(c: anytype) !void { const D = struct { c: @TypeOf(c) }; - var d = D{ .c = c }; + const d: D = .{ .c = c }; try expect(d.c == 1234); } }; var c: i32 = 1234; + _ = &c; try S.b(c); } @@ -966,6 +977,7 @@ test "closure capture type of runtime-known var" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 1234; + _ = &x; const S = struct { val: @TypeOf(x + 100) }; const s: S = .{ .val = x }; try expect(s.val == 1234); @@ -977,6 +989,7 @@ test "comptime break passing through runtime condition converted to runtime brea const S = struct { fn doTheTest() !void { var runtime: u8 = 'b'; + _ = &runtime; inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { bar(); if (byte == runtime) { @@ -1010,6 +1023,7 @@ test "comptime break to outer loop passing through runtime condition converted t const S = struct { fn doTheTest() !void { var runtime: u8 = 'b'; + _ = &runtime; outer: inline for ([3]u8{ 'A', 'B', 'C' }) |outer_byte| { inline for ([3]u8{ 'a', 'b', 'c' }) |byte| { bar(outer_byte); @@ -1387,6 +1401,7 @@ test "break from inline loop depends on runtime condition" { test "inline for inside a runtime condition" { var a = false; + _ = &a; if (a) { const arr = .{ 1, 2, 3 }; inline for (arr) |val| { @@ -1522,6 +1537,7 @@ test "non-optional and optional array elements concatenated" { const array = [1]u8{'A'} ++ [1]?u8{null}; var index: usize = 0; + _ = &index; try expect(array[index].? == 'A'); } @@ -1556,6 +1572,7 @@ test "container level const and var have unique addresses" { var v: @This() = c; }; var p = &S.c; + _ = &p; try std.testing.expect(p.x == S.c.x); S.v.x = 2; try std.testing.expect(p.x == S.c.x); @@ -1625,7 +1642,8 @@ test "inline for loop of functions returning error unions" { test "if inside a switch" { var condition = true; var wave_type: u32 = 0; - var sample: i32 = switch (wave_type) { + _ = .{ &condition, &wave_type }; + const sample: i32 = switch (wave_type) { 0 => if (condition) 2 else 3, 1 => 100, 2 => 200, @@ -1673,6 +1691,7 @@ test "@inComptime" { comptime { var foo = [3]u8{ 0x55, 0x55, 0x55 }; var bar = [2]u8{ 1, 2 }; + _ = .{ &foo, &bar }; foo[0..2].* = bar; assert(foo[0] == 1); assert(foo[1] == 2); diff --git a/test/behavior/extern_struct_zero_size_fields.zig b/test/behavior/extern_struct_zero_size_fields.zig index 1b13532f11..592ec85f50 100644 --- a/test/behavior/extern_struct_zero_size_fields.zig +++ b/test/behavior/extern_struct_zero_size_fields.zig @@ -17,5 +17,5 @@ const T = extern struct { test { var t: T = .{}; - _ = t; + _ = &t; } diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig index f114f30fa9..e1c870bce6 100644 --- a/test/behavior/floatop.zig +++ b/test/behavior/floatop.zig @@ -42,6 +42,8 @@ test "add f80/f128/c_longdouble" { fn testAdd(comptime T: type) !void { var one_point_two_five: T = 1.25; var two_point_seven_five: T = 2.75; + _ = &one_point_two_five; + _ = &two_point_seven_five; try expect(one_point_two_five + two_point_seven_five == 4); } @@ -74,6 +76,8 @@ test "sub f80/f128/c_longdouble" { fn testSub(comptime T: type) !void { var one_point_two_five: T = 1.25; var two_point_seven_five: T = 2.75; + _ = &one_point_two_five; + _ = &two_point_seven_five; try expect(one_point_two_five - two_point_seven_five == -1.5); } @@ -106,6 +110,8 @@ test "mul f80/f128/c_longdouble" { fn testMul(comptime T: type) !void { var one_point_two_five: T = 1.25; var two_point_seven_five: T = 2.75; + _ = &one_point_two_five; + _ = &two_point_seven_five; try expect(one_point_two_five * two_point_seven_five == 3.4375); } @@ -152,6 +158,7 @@ fn testCmp(comptime T: type) !void { { // No decimal part var x: T = 1.0; + _ = &x; try expect(x == 1.0); try expect(x != 0.0); try expect(x > 0.0); @@ -162,6 +169,7 @@ fn testCmp(comptime T: type) !void { { // Non-zero decimal part var x: T = 1.5; + _ = &x; try expect(x != 1.0); try expect(x != 2.0); try expect(x > 1.0); @@ -184,6 +192,7 @@ fn testCmp(comptime T: type) !void { math.floatMax(T), math.inf(T), }; + _ = &edges; for (edges, 0..) |rhs, rhs_i| { for (edges, 0..) |lhs, lhs_i| { const no_nan = lhs_i != 5 and rhs_i != 5; @@ -212,6 +221,7 @@ test "different sized float comparisons" { fn testDifferentSizedFloatComparisons() !void { var a: f16 = 1; var b: f64 = 2; + _ = .{ &a, &b }; try expect(a < b); } @@ -240,7 +250,8 @@ test "negative f128 intFromFloat at compile-time" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; const a: f128 = -2; - var b = @as(i64, @intFromFloat(a)); + var b: i64 = @intFromFloat(a); + _ = &b; try expect(@as(i64, -2) == b); } @@ -331,6 +342,28 @@ fn testSqrt(comptime T: type) !void { try expect(math.isNan(@sqrt(neg_one))); var nan: T = math.nan(T); try expect(math.isNan(@sqrt(nan))); + + _ = .{ + &four, + &nine, + &twenty_five, + &sixty_four, + &one_point_one, + &two, + &three_point_six, + &sixty_four_point_one, + &twelve, + &thirteen, + &fourteen, + &a, + &b, + &c, + &inf, + &zero, + &neg_zero, + &neg_one, + &nan, + }; } test "@sqrt with vectors" { @@ -345,7 +378,8 @@ test "@sqrt with vectors" { fn testSqrtWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @sqrt(v); + _ = &v; + const result = @sqrt(v); try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon)); @@ -394,8 +428,10 @@ test "@sin f80/f128/c_longdouble" { fn testSin(comptime T: type) !void { const eps = epsForType(T); var zero: T = 0; + _ = &zero; try expect(@sin(zero) == 0); var pi: T = math.pi; + _ = π try expect(math.approxEqAbs(T, @sin(pi), 0, eps)); try expect(math.approxEqAbs(T, @sin(pi / 2.0), 1, eps)); try expect(math.approxEqAbs(T, @sin(pi / 4.0), 0.7071067811865475, eps)); @@ -414,7 +450,8 @@ test "@sin with vectors" { fn testSinWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @sin(v); + _ = &v; + const result = @sin(v); try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon)); @@ -463,8 +500,10 @@ test "@cos f80/f128/c_longdouble" { fn testCos(comptime T: type) !void { const eps = epsForType(T); var zero: T = 0; + _ = &zero; try expect(@cos(zero) == 1); var pi: T = math.pi; + _ = π try expect(math.approxEqAbs(T, @cos(pi), -1, eps)); try expect(math.approxEqAbs(T, @cos(pi / 2.0), 0, eps)); try expect(math.approxEqAbs(T, @cos(pi / 4.0), 0.7071067811865475, eps)); @@ -483,7 +522,8 @@ test "@cos with vectors" { fn testCosWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @cos(v); + _ = &v; + const result = @cos(v); try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon)); @@ -532,8 +572,10 @@ test "@tan f80/f128/c_longdouble" { fn testTan(comptime T: type) !void { const eps = epsForType(T); var zero: T = 0; + _ = &zero; try expect(@tan(zero) == 0); var pi: T = math.pi; + _ = π try expect(math.approxEqAbs(T, @tan(pi), 0, eps)); try expect(math.approxEqAbs(T, @tan(pi / 3.0), 1.732050807568878, eps)); try expect(math.approxEqAbs(T, @tan(pi / 4.0), 1, eps)); @@ -552,7 +594,8 @@ test "@tan with vectors" { fn testTanWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; - var result = @tan(v); + _ = &v; + const result = @tan(v); try expect(math.approxEqAbs(f32, @tan(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @tan(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @tan(@as(f32, 3.3)), result[2], epsilon)); @@ -600,11 +643,17 @@ test "@exp f80/f128/c_longdouble" { fn testExp(comptime T: type) !void { const eps = epsForType(T); + var zero: T = 0; + _ = &zero; try expect(@exp(zero) == 1); + var two: T = 2; + _ = &two; try expect(math.approxEqAbs(T, @exp(two), 7.389056098930650, eps)); + var five: T = 5; + _ = &five; try expect(math.approxEqAbs(T, @exp(five), 148.4131591025766, eps)); } @@ -621,7 +670,8 @@ test "@exp with vectors" { fn testExpWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @exp(v); + _ = &v; + const result = @exp(v); try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon)); @@ -675,6 +725,7 @@ fn testExp2(comptime T: type) !void { try expect(math.approxEqAbs(T, @exp2(one_point_five), 2.8284271247462, eps)); var four_point_five: T = 4.5; try expect(math.approxEqAbs(T, @exp2(four_point_five), 22.627416997969, eps)); + _ = .{ &two, &one_point_five, &four_point_five }; } test "@exp2 with @vectors" { @@ -690,7 +741,8 @@ test "@exp2 with @vectors" { fn testExp2WithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @exp2(v); + _ = &v; + const result = @exp2(v); try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon)); @@ -744,6 +796,7 @@ fn testLog(comptime T: type) !void { try expect(math.approxEqAbs(T, @log(two), 0.6931471805599, eps)); var five: T = 5; try expect(math.approxEqAbs(T, @log(five), 1.6094379124341, eps)); + _ = .{ &e, &two, &five }; } test "@log with @vectors" { @@ -756,7 +809,8 @@ test "@log with @vectors" { { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @log(v); + _ = &v; + const result = @log(v); try expect(@log(@as(f32, 1.1)) == result[0]); try expect(@log(@as(f32, 2.2)) == result[1]); try expect(@log(@as(f32, 0.3)) == result[2]); @@ -811,6 +865,7 @@ fn testLog2(comptime T: type) !void { try expect(math.approxEqAbs(T, @log2(six), 2.5849625007212, eps)); var ten: T = 10; try expect(math.approxEqAbs(T, @log2(ten), 3.3219280948874, eps)); + _ = .{ &four, &six, &ten }; } test "@log2 with vectors" { @@ -830,7 +885,8 @@ test "@log2 with vectors" { fn testLog2WithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @log2(v); + _ = &v; + const result = @log2(v); try expect(@log2(@as(f32, 1.1)) == result[0]); try expect(@log2(@as(f32, 2.2)) == result[1]); try expect(@log2(@as(f32, 0.3)) == result[2]); @@ -884,6 +940,7 @@ fn testLog10(comptime T: type) !void { try expect(math.approxEqAbs(T, @log10(fifteen), 1.176091259056, eps)); var fifty: T = 50; try expect(math.approxEqAbs(T, @log10(fifty), 1.698970004336, eps)); + _ = .{ &hundred, &fifteen, &fifty }; } test "@log10 with vectors" { @@ -899,7 +956,8 @@ test "@log10 with vectors" { fn testLog10WithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; - var result = @log10(v); + _ = &v; + const result = @log10(v); try expect(@log10(@as(f32, 1.1)) == result[0]); try expect(@log10(@as(f32, 2.2)) == result[1]); try expect(@log10(@as(f32, 0.3)) == result[2]); @@ -987,6 +1045,26 @@ fn testFabs(comptime T: type) !void { try expect(math.isPositiveInf(@abs(neg_inf))); var nan: T = math.nan(T); try expect(math.isNan(@abs(nan))); + + _ = .{ + &two_point_five, + &neg_two_point_five, + &twelve, + &neg_fourteen, + &one, + &neg_one, + &min, + &neg_min, + &max, + &neg_max, + &zero, + &neg_zero, + &true_min, + &neg_true_min, + &inf, + &neg_inf, + &nan, + }; } test "@abs with vectors" { @@ -1001,7 +1079,8 @@ test "@abs with vectors" { fn testFabsWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @abs(v); + _ = &v; + const result = @abs(v); try expect(math.approxEqAbs(f32, @abs(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @abs(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @abs(@as(f32, 0.3)), result[2], epsilon)); @@ -1070,6 +1149,17 @@ fn testFloor(comptime T: type) !void { try expect(@floor(fourteen_point_seven) == 14.0); var neg_fourteen_point_seven: T = -14.7; try expect(@floor(neg_fourteen_point_seven) == -15.0); + + _ = .{ + &two_point_one, + &neg_two_point_one, + &three_point_five, + &neg_three_point_five, + &twelve, + &neg_twelve, + &fourteen_point_seven, + &neg_fourteen_point_seven, + }; } test "@floor with vectors" { @@ -1086,7 +1176,8 @@ test "@floor with vectors" { fn testFloorWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @floor(v); + _ = &v; + const result = @floor(v); try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon)); @@ -1155,6 +1246,17 @@ fn testCeil(comptime T: type) !void { try expect(@ceil(fourteen_point_seven) == 15.0); var neg_fourteen_point_seven: T = -14.7; try expect(@ceil(neg_fourteen_point_seven) == -14.0); + + _ = .{ + &two_point_one, + &neg_two_point_one, + &three_point_five, + &neg_three_point_five, + &twelve, + &neg_twelve, + &fourteen_point_seven, + &neg_fourteen_point_seven, + }; } test "@ceil with vectors" { @@ -1171,7 +1273,8 @@ test "@ceil with vectors" { fn testCeilWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @ceil(v); + _ = &v; + const result = @ceil(v); try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon)); @@ -1250,6 +1353,17 @@ fn testTrunc(comptime T: type) !void { try expect(@trunc(fourteen_point_seven) == 14.0); var neg_fourteen_point_seven: T = -14.7; try expect(@trunc(neg_fourteen_point_seven) == -14.0); + + _ = .{ + &two_point_one, + &neg_two_point_one, + &three_point_five, + &neg_three_point_five, + &twelve, + &neg_twelve, + &fourteen_point_seven, + &neg_fourteen_point_seven, + }; } test "@trunc with vectors" { @@ -1266,7 +1380,8 @@ test "@trunc with vectors" { fn testTruncWithVectors() !void { var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; - var result = @trunc(v); + _ = &v; + const result = @trunc(v); try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon)); try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon)); try expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon)); @@ -1365,6 +1480,27 @@ fn testNeg(comptime T: type) !void { var neg_nan: T = -math.nan(T); try expect(math.isNan(-neg_nan)); try expect(!math.signbit(-neg_nan)); + + _ = .{ + &two_point_five, + &neg_two_point_five, + &twelve, + &neg_fourteen, + &one, + &neg_one, + &min, + &neg_min, + &max, + &neg_max, + &zero, + &neg_zero, + &true_min, + &neg_true_min, + &inf, + &neg_inf, + &nan, + &neg_nan, + }; } test "eval @setFloatMode at compile-time" { diff --git a/test/behavior/fn.zig b/test/behavior/fn.zig index ddfc9648c2..4f8dd35490 100644 --- a/test/behavior/fn.zig +++ b/test/behavior/fn.zig @@ -21,6 +21,7 @@ fn testLocVars(b: i32) void { test "mutable local variables" { var zero: i32 = 0; + _ = &zero; try expect(zero == 0); var i = @as(i32, 0); @@ -70,7 +71,7 @@ fn outer(y: u32) *const fn (u32) u32 { test "return inner function which references comptime variable of outer function" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - var func = outer(10); + const func = outer(10); try expect(func(3) == 7); } @@ -259,7 +260,7 @@ test "implicit cast fn call result to optional in field result" { const S = struct { fn entry() !void { - var x = Foo{ + const x = Foo{ .field = optionalPtr(), }; try expect(x.field.?.* == 999); @@ -386,6 +387,7 @@ test "ability to give comptime types and non comptime types to same parameter" { const S = struct { fn doTheTest() !void { var x: i32 = 1; + _ = &x; try expect(foo(x) == 10); try expect(foo(i32) == 20); } @@ -413,11 +415,11 @@ test "import passed byref to function in return type" { const S = struct { fn get() @import("std").ArrayListUnmanaged(i32) { - var x: @import("std").ArrayListUnmanaged(i32) = .{}; + const x: @import("std").ArrayListUnmanaged(i32) = .{}; return x; } }; - var list = S.get(); + const list = S.get(); try expect(list.items.len == 0); } @@ -434,11 +436,13 @@ test "implicit cast function to function ptr" { } }; var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue; + _ = &fnPtr1; try expect(fnPtr1() == 123); const S2 = struct { extern fn someFunctionThatReturnsAValue() c_int; }; var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue; + _ = &fnPtr2; try expect(fnPtr2() == 123); } @@ -588,5 +592,6 @@ test "pointer to alias behaves same as pointer to function" { const bar = foo; }; var a = &S.bar; + _ = &a; try std.testing.expect(S.foo() == a()); } diff --git a/test/behavior/fn_in_struct_in_comptime.zig b/test/behavior/fn_in_struct_in_comptime.zig index 0acadbc5ea..40410d4aea 100644 --- a/test/behavior/fn_in_struct_in_comptime.zig +++ b/test/behavior/fn_in_struct_in_comptime.zig @@ -5,8 +5,7 @@ fn get_foo() fn (*u8) usize { comptime { return struct { fn func(ptr: *u8) usize { - var u = @intFromPtr(ptr); - return u; + return @intFromPtr(ptr); } }.func; } diff --git a/test/behavior/for.zig b/test/behavior/for.zig index 5a41f75077..a43fc2305b 100644 --- a/test/behavior/for.zig +++ b/test/behavior/for.zig @@ -26,7 +26,7 @@ test "break from outer for loop" { } fn testBreakOuter() !void { - var array = "aoeu"; + const array = "aoeu"; var count: usize = 0; outer: for (array) |_| { for (array) |_| { @@ -43,7 +43,7 @@ test "continue outer for loop" { } fn testContinueOuter() !void { - var array = "aoeu"; + const array = "aoeu"; var counter: usize = 0; outer: for (array) |_| { for (array) |_| { @@ -137,7 +137,7 @@ test "2 break statements and an else" { fn entry(t: bool, f: bool) !void { var buf: [10]u8 = undefined; var ok = false; - ok = for (buf) |item| { + ok = for (&buf) |*item| { _ = item; if (f) break false; if (t) break true; @@ -201,7 +201,7 @@ test "for on slice with allowzero ptr" { const S = struct { fn doTheTest(slice: []const u8) !void { - var ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len]; + const ptr = @as([*]allowzero const u8, @ptrCast(slice.ptr))[0..slice.len]; for (ptr, 0..) |x, i| try expect(x == i + 1); for (ptr, 0..) |*x, i| try expect(x.* == i + 1); } @@ -230,6 +230,7 @@ test "for loop with else branch" { { var x = [_]u32{ 1, 2 }; + _ = &x; const q = for (x) |y| { if ((y & 1) != 0) continue; break y * 2; @@ -238,6 +239,7 @@ test "for loop with else branch" { } { var x = [_]u32{ 1, 2 }; + _ = &x; const q = for (x) |y| { if ((y & 1) != 0) continue; break y * 2; @@ -310,6 +312,7 @@ test "slice and two counters, one is offset and one is runtime" { const slice: []const u8 = "blah"; var start: usize = 0; + _ = &start; for (slice, start..4, 1..5) |a, b, c| { if (a == 'b') { @@ -394,6 +397,7 @@ test "inline for with slice as the comptime-known" { const comptime_slice = "hello"; var runtime_i: usize = 3; + _ = &runtime_i; const S = struct { var ok: usize = 0; @@ -424,6 +428,7 @@ test "inline for with counter as the comptime-known" { var runtime_slice = "hello"; var runtime_i: usize = 3; + _ = &runtime_i; const S = struct { var ok: usize = 0; @@ -484,14 +489,16 @@ test "inferred alloc ptr of for loop" { { var cond = false; - var opt = for (0..1) |_| { + _ = &cond; + const opt = for (0..1) |_| { if (cond) break cond; } else null; try expectEqual(@as(?bool, null), opt); } { var cond = true; - var opt = for (0..1) |_| { + _ = &cond; + const opt = for (0..1) |_| { if (cond) break cond; } else null; try expectEqual(@as(?bool, true), opt); diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index d52ad20677..d0c97bdbf3 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -102,6 +102,7 @@ test "type constructed by comptime function call" { fn SimpleList(comptime L: usize) type { var mutable_T = u8; + _ = &mutable_T; const T = mutable_T; return struct { array: [L]T, @@ -238,6 +239,7 @@ test "function parameter is generic" { } }; var rng: u32 = 2; + _ = &rng; S.init(rng, S.fill); } diff --git a/test/behavior/if.zig b/test/behavior/if.zig index 68ea986c05..c4dfd04f71 100644 --- a/test/behavior/if.zig +++ b/test/behavior/if.zig @@ -61,6 +61,7 @@ test "unwrap mutable global var" { test "labeled break inside comptime if inside runtime if" { var answer: i32 = 0; var c = true; + _ = &c; if (c) { answer = if (true) blk: { break :blk @as(i32, 42); @@ -73,6 +74,7 @@ test "const result loc, runtime if cond, else unreachable" { const Num = enum { One, Two }; var t = true; + _ = &t; const x = if (t) Num.Two else unreachable; try expect(x == .Two); } @@ -103,6 +105,7 @@ test "if prongs cast to expected type instead of peer type resolution" { try expect(x == 2); var b = true; + _ = &b; const y: i32 = if (b) 1 else 2; try expect(y == 1); } @@ -118,10 +121,11 @@ test "if peer expressions inferred optional type" { var self: []const u8 = "abcdef"; var index: usize = 0; - var left_index = (index << 1) + 1; - var right_index = left_index + 1; - var left = if (left_index < self.len) self[left_index] else null; - var right = if (right_index < self.len) self[right_index] else null; + _ = .{ &self, &index }; + const left_index = (index << 1) + 1; + const right_index = left_index + 1; + const left = if (left_index < self.len) self[left_index] else null; + const right = if (right_index < self.len) self[right_index] else null; try expect(left_index < self.len); try expect(right_index < self.len); try expect(left.? == 98); @@ -135,6 +139,7 @@ test "if-else expression with runtime condition result location is inferred opti const A = struct { b: u64, c: u64 }; var d: bool = true; + _ = &d; const e = if (d) A{ .b = 15, .c = 30 } else null; try expect(e != null); } @@ -142,7 +147,8 @@ test "if-else expression with runtime condition result location is inferred opti test "result location with inferred type ends up being pointer to comptime_int" { var a: ?u32 = 1234; var b: u32 = 2000; - var c = if (a) |d| blk: { + _ = .{ &a, &b }; + const c = if (a) |d| blk: { if (d < b) break :blk @as(u32, 1); break :blk 0; } else @as(u32, 0); @@ -152,6 +158,7 @@ test "result location with inferred type ends up being pointer to comptime_int" test "if-@as-if chain" { var fast = true; var very_fast = false; + _ = .{ &fast, &very_fast }; const num_frames = if (fast) @as(u32, if (very_fast) 16 else 4) diff --git a/test/behavior/inline_switch.zig b/test/behavior/inline_switch.zig index deb4518820..59dc7096b9 100644 --- a/test/behavior/inline_switch.zig +++ b/test/behavior/inline_switch.zig @@ -22,6 +22,7 @@ test "inline prong ranges" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: usize = 0; + _ = &x; switch (x) { inline 0...20, 24 => |item| { if (item > 25) @compileError("bad"); @@ -36,6 +37,7 @@ test "inline switch enums" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: E = .a; + _ = &x; switch (x) { inline .a, .b => |aorb| if (aorb != .a and aorb != .b) @compileError("bad"), inline .c, .d => |cord| if (cord != .c and cord != .d) @compileError("bad"), @@ -49,6 +51,7 @@ test "inline switch unions" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: U = .a; + _ = &x; switch (x) { inline .a, .b => |aorb, tag| { if (tag == .a) { @@ -74,6 +77,7 @@ test "inline else bool" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a = true; + _ = &a; switch (a) { true => {}, inline else => |val| if (val != false) @compileError("bad"), @@ -86,6 +90,7 @@ test "inline else error" { const Err = error{ a, b, c }; var a = Err.a; + _ = &a; switch (a) { error.a => {}, inline else => |val| comptime if (val == error.a) @compileError("bad"), @@ -98,6 +103,7 @@ test "inline else enum" { const E2 = enum(u8) { a = 2, b = 3, c = 4, d = 5 }; var a: E2 = .a; + _ = &a; switch (a) { .a, .b => {}, inline else => |val| comptime if (@intFromEnum(val) < 4) @compileError("bad"), @@ -109,6 +115,7 @@ test "inline else int with gaps" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: u8 = 0; + _ = &a; switch (a) { 1...125, 128...254 => {}, inline else => |val| { @@ -126,6 +133,7 @@ test "inline else int all values" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var a: u2 = 0; + _ = &a; switch (a) { inline else => |val| { if (val != 0 and diff --git a/test/behavior/int128.zig b/test/behavior/int128.zig index 01e6bc42ac..7287cd1ab2 100644 --- a/test/behavior/int128.zig +++ b/test/behavior/int128.zig @@ -39,6 +39,7 @@ test "undefined 128 bit int" { var undef: u128 = undefined; var undef_signed: i128 = undefined; + _ = .{ &undef, &undef_signed }; try expect(undef == 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and @as(u128, @bitCast(undef_signed)) == undef); } @@ -73,6 +74,7 @@ test "truncate int128" { { var buff: u128 = maxInt(u128); + _ = &buff; try expect(@as(u64, @truncate(buff)) == maxInt(u64)); try expect(@as(u90, @truncate(buff)) == maxInt(u90)); try expect(@as(u128, @truncate(buff)) == maxInt(u128)); @@ -80,6 +82,7 @@ test "truncate int128" { { var buff: i128 = maxInt(i128); + _ = &buff; try expect(@as(i64, @truncate(buff)) == -1); try expect(@as(i90, @truncate(buff)) == -1); try expect(@as(i128, @truncate(buff)) == maxInt(i128)); diff --git a/test/behavior/int_comparison_elision.zig b/test/behavior/int_comparison_elision.zig index c384f62086..9ac9e1fca1 100644 --- a/test/behavior/int_comparison_elision.zig +++ b/test/behavior/int_comparison_elision.zig @@ -30,6 +30,7 @@ fn testIntEdges(comptime T: type) void { const max = maxInt(T); var runtime_val: T = undefined; + _ = &runtime_val; if (min > runtime_val) @compileError("analyzed impossible branch"); if (min <= runtime_val) {} else @compileError("analyzed impossible branch"); diff --git a/test/behavior/int_div.zig b/test/behavior/int_div.zig index 12368f0fba..bc570434ce 100644 --- a/test/behavior/int_div.zig +++ b/test/behavior/int_div.zig @@ -100,11 +100,13 @@ test "large integer division" { { var numerator: u256 = 99999999999999999997315645440; var divisor: u256 = 10000000000000000000000000000; + _ = .{ &numerator, &divisor }; try expect(numerator / divisor == 9); } { var numerator: u256 = 99999999999999999999000000000000000000000; var divisor: u256 = 10000000000000000000000000000000000000000; + _ = .{ &numerator, &divisor }; try expect(numerator / divisor == 9); } } diff --git a/test/behavior/math.zig b/test/behavior/math.zig index 3a5f753dd8..ab54c9e4a9 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -624,7 +624,8 @@ const DivResult = struct { test "bit shift a u1" { var x: u1 = 1; - var y = x << 0; + _ = &x; + const y = x << 0; try expect(y == 1); } @@ -692,7 +693,8 @@ test "128-bit multiplication" { { var a: u128 = 0xffffffffffffffff; var b: u128 = 100; - var c = a * b; + _ = .{ &a, &b }; + const c = a * b; try expect(c == 0x63ffffffffffffff9c); } } @@ -704,18 +706,21 @@ test "@addWithOverflow" { { var a: u8 = 250; + _ = &a; const ov = @addWithOverflow(a, 100); try expect(ov[0] == 94); try expect(ov[1] == 1); } { var a: u8 = 100; + _ = &a; const ov = @addWithOverflow(a, 150); try expect(ov[0] == 250); try expect(ov[1] == 0); } { var a: u8 = 200; + _ = &a; var b: u8 = 99; var ov = @addWithOverflow(a, b); try expect(ov[0] == 43); @@ -729,6 +734,7 @@ test "@addWithOverflow" { { var a: usize = 6; var b: usize = 6; + _ = .{ &a, &b }; const ov = @addWithOverflow(a, b); try expect(ov[0] == 12); try expect(ov[1] == 0); @@ -737,6 +743,7 @@ test "@addWithOverflow" { { var a: isize = -6; var b: isize = -6; + _ = .{ &a, &b }; const ov = @addWithOverflow(a, b); try expect(ov[0] == -12); try expect(ov[1] == 0); @@ -772,18 +779,21 @@ test "basic @mulWithOverflow" { { var a: u8 = 86; + _ = &a; const ov = @mulWithOverflow(a, 3); try expect(ov[0] == 2); try expect(ov[1] == 1); } { var a: u8 = 85; + _ = &a; const ov = @mulWithOverflow(a, 3); try expect(ov[0] == 255); try expect(ov[1] == 0); } var a: u8 = 123; + _ = &a; var b: u8 = 2; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 246); @@ -802,6 +812,7 @@ test "extensive @mulWithOverflow" { { var a: u5 = 3; + _ = &a; var b: u5 = 10; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 30); @@ -815,6 +826,7 @@ test "extensive @mulWithOverflow" { { var a: i5 = 3; + _ = &a; var b: i5 = -5; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -15); @@ -828,6 +840,7 @@ test "extensive @mulWithOverflow" { { var a: u8 = 3; + _ = &a; var b: u8 = 85; var ov = @mulWithOverflow(a, b); @@ -842,6 +855,7 @@ test "extensive @mulWithOverflow" { { var a: i8 = 3; + _ = &a; var b: i8 = -42; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -126); @@ -855,6 +869,7 @@ test "extensive @mulWithOverflow" { { var a: u14 = 3; + _ = &a; var b: u14 = 0x1555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0x3fff); @@ -868,6 +883,7 @@ test "extensive @mulWithOverflow" { { var a: i14 = 3; + _ = &a; var b: i14 = -0xaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x1ffe); @@ -880,6 +896,7 @@ test "extensive @mulWithOverflow" { { var a: u16 = 3; + _ = &a; var b: u16 = 0x5555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0xffff); @@ -893,6 +910,7 @@ test "extensive @mulWithOverflow" { { var a: i16 = 3; + _ = &a; var b: i16 = -0x2aaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x7ffe); @@ -906,6 +924,7 @@ test "extensive @mulWithOverflow" { { var a: u30 = 3; + _ = &a; var b: u30 = 0x15555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0x3fffffff); @@ -919,6 +938,7 @@ test "extensive @mulWithOverflow" { { var a: i30 = 3; + _ = &a; var b: i30 = -0xaaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x1ffffffe); @@ -932,6 +952,7 @@ test "extensive @mulWithOverflow" { { var a: u32 = 3; + _ = &a; var b: u32 = 0x55555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0xffffffff); @@ -945,6 +966,7 @@ test "extensive @mulWithOverflow" { { var a: i32 = 3; + _ = &a; var b: i32 = -0x2aaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x7ffffffe); @@ -967,6 +989,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: u62 = 3; + _ = &a; var b: u62 = 0x1555555555555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0x3fffffffffffffff); @@ -980,6 +1003,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: i62 = 3; + _ = &a; var b: i62 = -0xaaaaaaaaaaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x1ffffffffffffffe); @@ -993,6 +1017,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: u64 = 3; + _ = &a; var b: u64 = 0x5555555555555555; var ov = @mulWithOverflow(a, b); try expect(ov[0] == 0xffffffffffffffff); @@ -1006,6 +1031,7 @@ test "@mulWithOverflow bitsize > 32" { { var a: i64 = 3; + _ = &a; var b: i64 = -0x2aaaaaaaaaaaaaaa; var ov = @mulWithOverflow(a, b); try expect(ov[0] == -0x7ffffffffffffffe); @@ -1025,12 +1051,14 @@ test "@subWithOverflow" { { var a: u8 = 1; + _ = &a; const ov = @subWithOverflow(a, 2); try expect(ov[0] == 255); try expect(ov[1] == 1); } { var a: u8 = 1; + _ = &a; const ov = @subWithOverflow(a, 1); try expect(ov[0] == 0); try expect(ov[1] == 0); @@ -1038,6 +1066,7 @@ test "@subWithOverflow" { { var a: u8 = 1; + _ = &a; var b: u8 = 2; var ov = @subWithOverflow(a, b); try expect(ov[0] == 255); @@ -1051,6 +1080,7 @@ test "@subWithOverflow" { { var a: usize = 6; var b: usize = 6; + _ = .{ &a, &b }; const ov = @subWithOverflow(a, b); try expect(ov[0] == 0); try expect(ov[1] == 0); @@ -1059,6 +1089,7 @@ test "@subWithOverflow" { { var a: isize = -6; var b: isize = -6; + _ = .{ &a, &b }; const ov = @subWithOverflow(a, b); try expect(ov[0] == 0); try expect(ov[1] == 0); @@ -1072,6 +1103,7 @@ test "@shlWithOverflow" { { var a: u4 = 2; + _ = &a; var b: u2 = 1; var ov = @shlWithOverflow(a, b); try expect(ov[0] == 4); @@ -1085,6 +1117,7 @@ test "@shlWithOverflow" { { var a: i9 = 127; + _ = &a; var b: u4 = 1; var ov = @shlWithOverflow(a, b); try expect(ov[0] == 254); @@ -1108,6 +1141,7 @@ test "@shlWithOverflow" { } { var a: u16 = 0b0000_0000_0000_0011; + _ = &a; var b: u4 = 15; var ov = @shlWithOverflow(a, b); try expect(ov[0] == 0b1000_0000_0000_0000); @@ -1124,24 +1158,28 @@ test "overflow arithmetic with u0 values" { { var a: u0 = 0; + _ = &a; const ov = @addWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); } { var a: u0 = 0; + _ = &a; const ov = @subWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); } { var a: u0 = 0; + _ = &a; const ov = @mulWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); } { var a: u0 = 0; + _ = &a; const ov = @shlWithOverflow(a, 0); try expect(ov[1] == 0); try expect(ov[1] == 0); @@ -1157,6 +1195,7 @@ test "allow signed integer division/remainder when values are comptime-known and try expect(-6 % 3 == 0); var undef: i32 = undefined; + _ = &undef; if (0 % undef != 0) { @compileError("0 as numerator should return comptime zero independent of denominator"); } @@ -1183,18 +1222,22 @@ test "quad hex float literal parsing accurate" { fn doTheTest() !void { { var f: f128 = 0x1.2eab345678439abcdefea56782346p+5; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x40042eab345678439abcdefea5678234); } { var f: f128 = 0x1.edcb34a235253948765432134674fp-1; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x3ffeedcb34a235253948765432134675); // round-to-even } { var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x3fcd353e45674d89abacc3a2ebf3ff50); } { var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9; + _ = &f; try expect(@as(u128, @bitCast(f)) == 0x3ff6ed8764648369535adf4be3214568); } const exp2ft = [_]f64{ @@ -1294,6 +1337,7 @@ test "shift left/right on u0 operand" { fn doTheTest() !void { var x: u0 = 0; var y: u0 = 0; + _ = .{ &x, &y }; try expectEqual(@as(u0, 0), x << 0); try expectEqual(@as(u0, 0), x >> 0); try expectEqual(@as(u0, 0), x << y); @@ -1310,7 +1354,7 @@ test "shift left/right on u0 operand" { test "comptime float rem int" { comptime { - var x = @as(f32, 1) % 2; + const x = @as(f32, 1) % 2; try expect(x == 1.0); } } @@ -1511,7 +1555,8 @@ test "vector integer addition" { fn doTheTest() !void { var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; - var result = a + b; + _ = .{ &a, &b }; + const result = a + b; var result_array: [4]i32 = result; const expected = [_]i32{ 6, 8, 10, 12 }; try expectEqualSlices(i32, &expected, &result_array); @@ -1552,6 +1597,7 @@ test "NaN comparison f80" { fn testNanEqNan(comptime F: type) !void { var nan1 = math.nan(F); var nan2 = math.nan(F); + _ = .{ &nan1, &nan2 }; try expect(nan1 != nan2); try expect(!(nan1 == nan2)); try expect(!(nan1 > nan2)); @@ -1571,6 +1617,7 @@ test "vector comparison" { fn doTheTest() !void { var a: @Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 }; var b: @Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 }; + _ = .{ &a, &b }; try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false })); try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false })); try expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false })); @@ -1609,7 +1656,8 @@ test "signed zeros are represented properly" { fn testOne(comptime T: type) !void { const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); var as_fp_val = -@as(T, 0.0); - var as_uint_val = @as(ST, @bitCast(as_fp_val)); + _ = &as_fp_val; + const as_uint_val: ST = @bitCast(as_fp_val); // Ensure the sign bit is set. try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1); } diff --git a/test/behavior/maximum_minimum.zig b/test/behavior/maximum_minimum.zig index 7d19f1dcdc..f7cb1ee513 100644 --- a/test/behavior/maximum_minimum.zig +++ b/test/behavior/maximum_minimum.zig @@ -15,6 +15,7 @@ test "@max" { var x: i32 = 10; var y: f32 = 0.68; var nan: f32 = std.math.nan(f32); + _ = .{ &x, &y, &nan }; try expect(@as(i32, 10) == @max(@as(i32, -3), x)); try expect(@as(f32, 3.2) == @max(@as(f32, 3.2), y)); try expect(y == @max(nan, y)); @@ -38,17 +39,20 @@ test "@max on vectors" { fn doTheTest() !void { var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; - var x = @max(a, b); + const x = @max(a, b); + _ = .{ &a, &b }; try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 2147483647, 2147483647, 30, 40 })); var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 }; - var y = @max(c, d); + const y = @max(c, d); + _ = .{ &c, &d }; try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ 0, 0.42, -0.64, 7.8 })); var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 }; - var z = @max(e, f); + const z = @max(e, f); + _ = .{ &e, &f }; try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 })); } }; @@ -66,6 +70,7 @@ test "@min" { var x: i32 = 10; var y: f32 = 0.68; var nan: f32 = std.math.nan(f32); + _ = .{ &x, &y, &nan }; try expect(@as(i32, -3) == @min(@as(i32, -3), x)); try expect(@as(f32, 0.68) == @min(@as(f32, 3.2), y)); try expect(y == @min(nan, y)); @@ -89,17 +94,20 @@ test "@min for vectors" { fn doTheTest() !void { var a: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var b: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; - var x = @min(a, b); + _ = .{ &a, &b }; + const x = @min(a, b); try expect(mem.eql(i32, &@as([4]i32, x), &[4]i32{ 1, -2, 3, 4 })); var c: @Vector(4, f32) = [4]f32{ 0, 0.4, -2.4, 7.8 }; var d: @Vector(4, f32) = [4]f32{ -0.23, 0.42, -0.64, 0.9 }; - var y = @min(c, d); + _ = .{ &c, &d }; + const y = @min(c, d); try expect(mem.eql(f32, &@as([4]f32, y), &[4]f32{ -0.23, 0.4, -2.4, 0.9 })); var e: @Vector(2, f32) = [2]f32{ 0, std.math.nan(f32) }; var f: @Vector(2, f32) = [2]f32{ std.math.nan(f32), 0 }; - var z = @max(e, f); + _ = .{ &e, &f }; + const z = @max(e, f); try expect(mem.eql(f32, &@as([2]f32, z), &[2]f32{ 0, 0 })); } }; @@ -119,6 +127,7 @@ test "@min/max for floats" { fn doTheTest(comptime T: type) !void { var x: T = -3.14; var y: T = 5.27; + _ = .{ &x, &y }; try expectEqual(x, @min(x, y)); try expectEqual(x, @min(y, x)); try expectEqual(y, @max(x, y)); @@ -126,6 +135,7 @@ test "@min/max for floats" { if (T != comptime_float) { var nan: T = std.math.nan(T); + _ = &nan; try expectEqual(y, @max(nan, y)); try expectEqual(y, @max(y, nan)); } @@ -175,6 +185,7 @@ test "@min/@max notices bounds" { var x: u16 = 20; const y = 30; var z: u32 = 100; + _ = .{ &x, &z }; const min = @min(x, y, z); const max = @max(x, y, z); try expectEqual(x, min); @@ -194,6 +205,7 @@ test "@min/@max notices vector bounds" { var x: @Vector(2, u16) = .{ 140, 40 }; const y: @Vector(2, u64) = .{ 5, 100 }; var z: @Vector(2, u32) = .{ 10, 300 }; + _ = .{ &x, &z }; const min = @min(x, y, z); const max = @max(x, y, z); try expectEqual(@Vector(2, u32){ 5, 40 }, min); @@ -224,6 +236,7 @@ test "@min/@max notices bounds from types" { var x: u16 = 123; var y: u32 = 456; var z: u8 = 10; + _ = .{ &x, &y, &z }; const min = @min(x, y, z); const max = @max(x, y, z); @@ -246,6 +259,7 @@ test "@min/@max notices bounds from vector types" { var x: @Vector(2, u16) = .{ 30, 67 }; var y: @Vector(2, u32) = .{ 20, 500 }; var z: @Vector(2, u8) = .{ 60, 15 }; + _ = .{ &x, &y, &z }; const min = @min(x, y, z); const max = @max(x, y, z); @@ -263,6 +277,7 @@ test "@min/@max notices bounds from types when comptime-known value is undef" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 1_000_000; + _ = &x; const y: u16 = undefined; // y is comptime-known, but is undef, so bounds cannot be refined using its value @@ -285,6 +300,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx)) return error.SkipZigTest; var x: @Vector(2, u32) = .{ 1_000_000, 12345 }; + _ = &x; const y: @Vector(2, u16) = .{ 10, undefined }; // y is comptime-known, but an element is undef, so bounds cannot be refined using its value @@ -302,6 +318,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known test "@min/@max of signed and unsigned runtime integers" { var x: i32 = -1; var y: u31 = 1; + _ = .{ &x, &y }; const min = @min(x, y); const max = @max(x, y); diff --git a/test/behavior/memcpy.zig b/test/behavior/memcpy.zig index 8d9880ccb0..33f6c0f34c 100644 --- a/test/behavior/memcpy.zig +++ b/test/behavior/memcpy.zig @@ -57,6 +57,7 @@ fn testMemcpyDestManyPtr() !void { var str = "hello".*; var buf: [5]u8 = undefined; var len: usize = 5; + _ = &len; @memcpy(@as([*]u8, @ptrCast(&buf)), @as([*]const u8, @ptrCast(&str))[0..len]); try expect(buf[0] == 'h'); try expect(buf[1] == 'e'); diff --git a/test/behavior/memset.zig b/test/behavior/memset.zig index e3cf646f87..966443f9cc 100644 --- a/test/behavior/memset.zig +++ b/test/behavior/memset.zig @@ -46,7 +46,8 @@ fn testMemsetSlice() !void { // memset slice to non-undefined, ABI size == 1 var array: [20]u8 = undefined; var len = array.len; - var slice = array[0..len]; + _ = &len; + const slice = array[0..len]; @memset(slice, 'A'); try expect(slice[0] == 'A'); try expect(slice[11] == 'A'); @@ -56,7 +57,8 @@ fn testMemsetSlice() !void { // memset slice to non-undefined, ABI size > 1 var array: [20]u32 = undefined; var len = array.len; - var slice = array[0..len]; + _ = &len; + const slice = array[0..len]; @memset(slice, 1234); try expect(slice[0] == 1234); try expect(slice[11] == 1234); @@ -111,6 +113,7 @@ test "memset with large array element, runtime known" { const A = [128]u64; var buf: [5]A = undefined; var runtime_known_element = [_]u64{0} ** 128; + _ = &runtime_known_element; @memset(&buf, runtime_known_element); for (buf[0]) |elem| try expect(elem == 0); for (buf[1]) |elem| try expect(elem == 0); diff --git a/test/behavior/muladd.zig b/test/behavior/muladd.zig index b17c95a24e..3bdba835f9 100644 --- a/test/behavior/muladd.zig +++ b/test/behavior/muladd.zig @@ -21,12 +21,14 @@ fn testMulAdd() !void { var a: f32 = 5.5; var b: f32 = 2.5; var c: f32 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f32, a, b, c) == 20); } { var a: f64 = 5.5; var b: f64 = 2.5; var c: f64 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f64, a, b, c) == 20); } } @@ -46,6 +48,7 @@ fn testMulAdd16() !void { var a: f16 = 5.5; var b: f16 = 2.5; var c: f16 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f16, a, b, c) == 20); } @@ -65,6 +68,7 @@ fn testMulAdd80() !void { var a: f16 = 5.5; var b: f80 = 2.5; var c: f80 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f80, a, b, c) == 20); } @@ -84,6 +88,7 @@ fn testMulAdd128() !void { var a: f16 = 5.5; var b: f128 = 2.5; var c: f128 = 6.25; + _ = .{ &a, &b, &c }; try expect(@mulAdd(f128, a, b, c) == 20); } @@ -91,7 +96,8 @@ fn vector16() !void { var a = @Vector(4, f16){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f16){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f16){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f16), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f16), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); @@ -115,7 +121,8 @@ fn vector32() !void { var a = @Vector(4, f32){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f32){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f32){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f32), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f32), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); @@ -139,7 +146,8 @@ fn vector64() !void { var a = @Vector(4, f64){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f64){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f64){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f64), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f64), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); @@ -163,7 +171,8 @@ fn vector80() !void { var a = @Vector(4, f80){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f80){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f80){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f80), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f80), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); try expect(x[2] == 20); @@ -187,7 +196,8 @@ fn vector128() !void { var a = @Vector(4, f128){ 5.5, 5.5, 5.5, 5.5 }; var b = @Vector(4, f128){ 2.5, 2.5, 2.5, 2.5 }; var c = @Vector(4, f128){ 6.25, 6.25, 6.25, 6.25 }; - var x = @mulAdd(@Vector(4, f128), a, b, c); + _ = .{ &a, &b, &c }; + const x = @mulAdd(@Vector(4, f128), a, b, c); try expect(x[0] == 20); try expect(x[1] == 20); diff --git a/test/behavior/null.zig b/test/behavior/null.zig index 3fe6e663e1..20afa21cb8 100644 --- a/test/behavior/null.zig +++ b/test/behavior/null.zig @@ -134,6 +134,7 @@ test "optional pointer to 0 bit type null value at runtime" { const EmptyStruct = struct {}; var x: ?*EmptyStruct = null; + _ = &x; try expect(x == null); } diff --git a/test/behavior/optional.zig b/test/behavior/optional.zig index 648b698842..d6dd27db3b 100644 --- a/test/behavior/optional.zig +++ b/test/behavior/optional.zig @@ -11,7 +11,7 @@ test "passing an optional integer as a parameter" { const S = struct { fn entry() bool { - var x: i32 = 1234; + const x: i32 = 1234; return foo(x); } @@ -29,7 +29,7 @@ test "optional pointer to size zero struct" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var e = EmptyStruct{}; - var o: ?*EmptyStruct = &e; + const o: ?*EmptyStruct = &e; try expect(o != null); } @@ -63,6 +63,7 @@ test "optional with void type" { x: ?void, }; var x = Foo{ .x = null }; + _ = &x; try expect(x.x == null); } @@ -102,6 +103,7 @@ test "nested optional field in struct" { var s = S1{ .x = S2{ .y = 127 }, }; + _ = &s; try expect(s.x.?.y == 127); } @@ -120,6 +122,8 @@ fn test_cmp_optional_non_optional() !void { var five: i32 = 5; var int_n: ?i32 = null; + _ = .{ &ten, &opt_ten, &five, &int_n }; + try expect(int_n != ten); try expect(opt_ten == ten); try expect(opt_ten != five); @@ -208,7 +212,7 @@ test "self-referential struct through a slice of optional" { }; }; - var n = S.Node.new(); + const n = S.Node.new(); try expect(n.data == null); } @@ -252,7 +256,7 @@ test "0-bit child type coerced to optional return ptr result location" { const S = struct { fn doTheTest() !void { var y = Foo{}; - var z = y.thing(); + const z = y.thing(); try expect(z != null); } @@ -425,6 +429,7 @@ test "alignment of wrapping an optional payload" { fn foo() ?I { var i: I = .{ .x = 1234 }; + _ = &i; return i; } }; @@ -450,15 +455,16 @@ test "peer type resolution in nested if expressions" { const Thing = struct { n: i32 }; var a = false; var b = false; + _ = .{ &a, &b }; - var result1 = if (a) + const result1 = if (a) Thing{ .n = 1 } else null; try expect(result1 == null); try expect(@TypeOf(result1) == ?Thing); - var result2 = if (a) + const result2 = if (a) Thing{ .n = 0 } else if (b) Thing{ .n = 1 } @@ -486,5 +492,6 @@ test "cast slice to const slice nested in error union and optional" { test "variable of optional of noreturn" { var null_opv: ?noreturn = null; + _ = &null_opv; try std.testing.expectEqual(@as(?noreturn, null), null_opv); } diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig index a8665a02ea..60e8d6d93a 100644 --- a/test/behavior/packed-struct.zig +++ b/test/behavior/packed-struct.zig @@ -479,10 +479,9 @@ test "load pointer from packed struct" { y: u32, }; var a: A = .{ .index = 123 }; - var b_list: []const B = &.{.{ .x = &a, .y = 99 }}; + const b_list: []const B = &.{.{ .x = &a, .y = 99 }}; for (b_list) |b| { - var i = b.x.index; - try expect(i == 123); + try expect(b.x.index == 123); } } @@ -770,6 +769,7 @@ test "nested packed struct field access test" { }; var arg = a{ .b = hld{ .c = 1, .d = 2 }, .g = mld{ .h = 6, .i = 8 } }; + _ = &arg; try std.testing.expect(arg.b.c == 1); try std.testing.expect(arg.b.d == 2); try std.testing.expect(arg.g.h == 6); @@ -790,6 +790,7 @@ test "nested packed struct at non-zero offset" { }; var k: u8 = 123; + _ = &k; var v: A = .{ .p1 = .{ .a = k + 1, .b = k }, .p2 = .{ .a = k + 1, .b = k }, @@ -833,6 +834,7 @@ test "nested packed struct at non-zero offset 2" { fn doTheTest() !void { var k: u8 = 123; + _ = &k; var v: A = .{ .p1 = .{ .a = k + 1, .b = k }, .p2 = .{ .a = k + 1, .b = k }, @@ -877,6 +879,7 @@ test "runtime init of unnamed packed struct type" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var z: u8 = 123; + _ = &z; try (packed struct { x: u8, pub fn m(s: @This()) !void { @@ -941,6 +944,7 @@ test "packed struct initialized in bitcast" { const T = packed struct { val: u8 }; var val: u8 = 123; + _ = &val; const t = @as(u8, @bitCast(T{ .val = val })); try expect(t == val); } @@ -976,7 +980,8 @@ test "store undefined to packed result location" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u4 = 0; - var s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined }; + _ = &x; + const s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined }; try expectEqual(x, s.x); } @@ -1004,7 +1009,7 @@ test "field access of packed struct smaller than its abi size inside struct init } }; - var s = S.init(true); + const s = S.init(true); // note: this bug is triggered by the == operator, expectEqual will hide it try expect(@as(i2, 0) == s.ps.x); try expect(@as(i2, 1) == s.ps.y); diff --git a/test/behavior/pointers.zig b/test/behavior/pointers.zig index 52e3e68c3f..3e3e67cc4e 100644 --- a/test/behavior/pointers.zig +++ b/test/behavior/pointers.zig @@ -11,7 +11,7 @@ test "dereference pointer" { fn testDerefPtr() !void { var x: i32 = 1234; - var y = &x; + const y = &x; y.* += 1; try expect(x == 1235); } @@ -53,8 +53,8 @@ test "implicit cast single item pointer to C pointer and back" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var y: u8 = 11; - var x: [*c]u8 = &y; - var z: *u8 = x; + const x: [*c]u8 = &y; + const z: *u8 = x; z.* += 1; try expect(y == 12); } @@ -74,6 +74,7 @@ test "assigning integer to C pointer" { var ptr2: [*c]u8 = x; var ptr3: [*c]u8 = 1; var ptr4: [*c]u8 = y; + _ = .{ &x, &y, &ptr, &ptr2, &ptr3, &ptr4 }; try expect(ptr == ptr2); try expect(ptr3 == ptr4); @@ -88,6 +89,7 @@ test "C pointer comparison and arithmetic" { fn doTheTest() !void { var ptr1: [*c]u32 = 0; var ptr2 = ptr1 + 10; + _ = &ptr1; try expect(ptr1 == 0); try expect(ptr1 >= 0); try expect(ptr1 <= 0); @@ -125,14 +127,15 @@ fn testDerefPtrOneVal() !void { } test "peer type resolution with C pointers" { - var ptr_one: *u8 = undefined; - var ptr_many: [*]u8 = undefined; - var ptr_c: [*c]u8 = undefined; + const ptr_one: *u8 = undefined; + const ptr_many: [*]u8 = undefined; + const ptr_c: [*c]u8 = undefined; var t = true; - var x1 = if (t) ptr_one else ptr_c; - var x2 = if (t) ptr_many else ptr_c; - var x3 = if (t) ptr_c else ptr_one; - var x4 = if (t) ptr_c else ptr_many; + _ = &t; + const x1 = if (t) ptr_one else ptr_c; + const x2 = if (t) ptr_many else ptr_c; + const x3 = if (t) ptr_c else ptr_one; + const x4 = if (t) ptr_c else ptr_many; try expect(@TypeOf(x1) == [*c]u8); try expect(@TypeOf(x2) == [*c]u8); try expect(@TypeOf(x3) == [*c]u8); @@ -141,8 +144,9 @@ test "peer type resolution with C pointers" { test "peer type resolution with C pointer and const pointer" { var ptr_c: [*c]u8 = undefined; - const ptr_const: u8 = undefined; - try expect(@TypeOf(ptr_c, &ptr_const) == [*c]const u8); + var ptr_const: *const u8 = &undefined; + _ = .{ &ptr_c, &ptr_const }; + try expect(@TypeOf(ptr_c, ptr_const) == [*c]const u8); } test "implicit casting between C pointer and optional non-C pointer" { @@ -151,9 +155,10 @@ test "implicit casting between C pointer and optional non-C pointer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var slice: []const u8 = "aoeu"; + _ = &slice; const opt_many_ptr: ?[*]const u8 = slice.ptr; var ptr_opt_many_ptr = &opt_many_ptr; - var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; + const c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; try expect(c_ptr.*.* == 'a'); ptr_opt_many_ptr = c_ptr; try expect(ptr_opt_many_ptr.*.?[1] == 'o'); @@ -192,11 +197,12 @@ test "allowzero pointer and slice" { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - var ptr = @as([*]allowzero i32, @ptrFromInt(0)); - var opt_ptr: ?[*]allowzero i32 = ptr; + var ptr: [*]allowzero i32 = @ptrFromInt(0); + const opt_ptr: ?[*]allowzero i32 = ptr; try expect(opt_ptr != null); try expect(@intFromPtr(ptr) == 0); var runtime_zero: usize = 0; + _ = &runtime_zero; var slice = ptr[runtime_zero..10]; try comptime expect(@TypeOf(slice) == []allowzero i32); try expect(@intFromPtr(&slice[5]) == 20); @@ -211,6 +217,7 @@ test "assign null directly to C pointer and test null equality" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: [*c]i32 = null; + _ = &x; try expect(x == null); try expect(null == x); try expect(!(x != null)); @@ -236,7 +243,7 @@ test "assign null directly to C pointer and test null equality" { try comptime expect((y orelse ptr_othery) == ptr_othery); var n: i32 = 1234; - var x1: [*c]i32 = &n; + const x1: [*c]i32 = &n; try expect(!(x1 == null)); try expect(!(null == x1)); try expect(x1 != null); @@ -279,9 +286,9 @@ test "null terminated pointer" { const S = struct { fn doTheTest() !void { var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' }; - var zero_ptr: [*:0]const u8 = @as([*:0]const u8, @ptrCast(&array_with_zero)); - var no_zero_ptr: [*]const u8 = zero_ptr; - var zero_ptr_again = @as([*:0]const u8, @ptrCast(no_zero_ptr)); + const zero_ptr: [*:0]const u8 = @ptrCast(&array_with_zero); + const no_zero_ptr: [*]const u8 = zero_ptr; + const zero_ptr_again: [*:0]const u8 = @ptrCast(no_zero_ptr); try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello")); } }; @@ -296,7 +303,7 @@ test "allow any sentinel" { const S = struct { fn doTheTest() !void { var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 }; - var ptr: [*:std.math.minInt(i32)]i32 = &array; + const ptr: [*:std.math.minInt(i32)]i32 = &array; try expect(ptr[4] == std.math.minInt(i32)); } }; @@ -317,6 +324,7 @@ test "pointer sentinel with enums" { fn doTheTest() !void { var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; + _ = &ptr; try expect(ptr[4] == .sentinel); // TODO this should be try comptime expect, see #3731 } }; @@ -332,6 +340,7 @@ test "pointer sentinel with optional element" { const S = struct { fn doTheTest() !void { var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; + _ = &ptr; try expect(ptr[4] == null); // TODO this should be try comptime expect, see #3731 } }; @@ -348,6 +357,7 @@ test "pointer sentinel with +inf" { fn doTheTest() !void { const inf_f32 = comptime std.math.inf(f32); var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 }; + _ = &ptr; try expect(ptr[4] == inf_f32); // TODO this should be try comptime expect, see #3731 } }; @@ -366,6 +376,7 @@ test "pointer arithmetic affects the alignment" { { var ptr: [*]align(8) u32 = undefined; var x: usize = 1; + _ = .{ &ptr, &x }; try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8); const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4 @@ -380,6 +391,7 @@ test "pointer arithmetic affects the alignment" { { var ptr: [*]align(8) [3]u8 = undefined; var x: usize = 1; + _ = .{ &ptr, &x }; const ptr1 = ptr + 17; // 3 * 17 = 51 try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1); @@ -467,8 +479,8 @@ test "array slicing to slice" { const S = struct { fn doTheTest() !void { var str: [5]i32 = [_]i32{ 1, 2, 3, 4, 5 }; - var sub: *[2]i32 = str[1..3]; - var slice: []i32 = sub; // used to cause failures + const sub: *[2]i32 = str[1..3]; + const slice: []i32 = sub; // used to cause failures try testing.expect(slice.len == 2); try testing.expect(slice[0] == 2); } @@ -495,7 +507,8 @@ test "ptrCast comptime known slice to C pointer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO const s: [:0]const u8 = "foo"; - var p = @as([*c]const u8, @ptrCast(s)); + var p: [*c]const u8 = @ptrCast(s); + _ = &p; try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0)); } @@ -527,6 +540,7 @@ test "pointer to array has explicit alignment" { test "result type preserved through multiple references" { const S = struct { x: u32 }; var my_u64: u64 = 12345; + _ = &my_u64; const foo: *const *const *const S = &&&.{ .x = @intCast(my_u64), }; diff --git a/test/behavior/popcount.zig b/test/behavior/popcount.zig index eda7346a2d..261019c65f 100644 --- a/test/behavior/popcount.zig +++ b/test/behavior/popcount.zig @@ -26,6 +26,7 @@ test "@popCount 128bit integer" { { var x: u128 = 0b11111111000110001100010000100001000011000011100101010001; + _ = &x; try expect(@popCount(x) == 24); } @@ -35,30 +36,37 @@ test "@popCount 128bit integer" { fn testPopCountIntegers() !void { { var x: u32 = 0xffffffff; + _ = &x; try expect(@popCount(x) == 32); } { var x: u5 = 0x1f; + _ = &x; try expect(@popCount(x) == 5); } { var x: u32 = 0xaa; + _ = &x; try expect(@popCount(x) == 4); } { var x: u32 = 0xaaaaaaaa; + _ = &x; try expect(@popCount(x) == 16); } { var x: u32 = 0xaaaaaaaa; + _ = &x; try expect(@popCount(x) == 16); } { var x: i16 = -1; + _ = &x; try expect(@popCount(x) == 16); } { var x: i8 = -120; + _ = &x; try expect(@popCount(x) == 2); } comptime { @@ -81,12 +89,14 @@ test "@popCount vectors" { fn testPopCountVectors() !void { { var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8; + _ = &x; const expected = [1]u6{32} ** 8; const result: [8]u6 = @popCount(x); try expect(std.mem.eql(u6, &expected, &result)); } { var x: @Vector(8, i16) = [1]i16{-1} ** 8; + _ = &x; const expected = [1]u5{16} ** 8; const result: [8]u5 = @popCount(x); try expect(std.mem.eql(u5, &expected, &result)); diff --git a/test/behavior/prefetch.zig b/test/behavior/prefetch.zig index d4baa649d0..e98e848393 100644 --- a/test/behavior/prefetch.zig +++ b/test/behavior/prefetch.zig @@ -6,6 +6,7 @@ test "@prefetch()" { var a: [2]u32 = .{ 42, 42 }; var a_len = a.len; + _ = &a_len; @prefetch(&a, .{}); diff --git a/test/behavior/ptrcast.zig b/test/behavior/ptrcast.zig index 635a4df843..4e9283b3a4 100644 --- a/test/behavior/ptrcast.zig +++ b/test/behavior/ptrcast.zig @@ -71,8 +71,8 @@ fn testReinterpretBytesAsExternStruct() !void { c: u8, }; - var ptr = @as(*const S, @ptrCast(&bytes)); - var val = ptr.c; + const ptr: *const S = @ptrCast(&bytes); + const val = ptr.c; try expect(val == 5); } @@ -95,8 +95,8 @@ fn testReinterpretExternStructAsExternStruct() !void { a: u32 align(2), c: u8, }; - var ptr = @as(*const S2, @ptrCast(&bytes)); - var val = ptr.c; + const ptr: *const S2 = @ptrCast(&bytes); + const val = ptr.c; try expect(val == 5); } @@ -121,8 +121,8 @@ fn testReinterpretOverAlignedExternStructAsExternStruct() !void { a2: u16, c: u8, }; - var ptr = @as(*const S2, @ptrCast(&bytes)); - var val = ptr.c; + const ptr: *const S2 = @ptrCast(&bytes); + const val = ptr.c; try expect(val == 5); } @@ -138,13 +138,13 @@ test "lower reinterpreted comptime field ptr (with under-aligned fields)" { c: u8, }; comptime var ptr = @as(*const S, @ptrCast(&bytes)); - var val = &ptr.c; + const val = &ptr.c; try expect(val.* == 5); // Test lowering an elem ptr comptime var src_value = S{ .a = 15, .c = 5 }; comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); - var val2 = &ptr2[4]; + const val2 = &ptr2[4]; try expect(val2.* == 5); } @@ -160,13 +160,13 @@ test "lower reinterpreted comptime field ptr" { c: u8, }; comptime var ptr = @as(*const S, @ptrCast(&bytes)); - var val = &ptr.c; + const val = &ptr.c; try expect(val.* == 5); // Test lowering an elem ptr comptime var src_value = S{ .a = 15, .c = 5 }; comptime var ptr2 = @as(*[@sizeOf(S)]u8, @ptrCast(&src_value)); - var val2 = &ptr2[4]; + const val2 = &ptr2[4]; try expect(val2.* == 5); } @@ -233,9 +233,9 @@ test "implicit optional pointer to optional anyopaque pointer" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO var buf: [4]u8 = "aoeu".*; - var x: ?[*]u8 = &buf; - var y: ?*anyopaque = x; - var z = @as(*[4]u8, @ptrCast(y)); + const x: ?[*]u8 = &buf; + const y: ?*anyopaque = x; + const z: *[4]u8 = @ptrCast(y); try expect(std.mem.eql(u8, z, "aoeu")); } @@ -276,7 +276,7 @@ test "@ptrCast undefined value at comptime" { } }; comptime { - var x = S.transmute([]u8, i32, undefined); + const x = S.transmute([]u8, i32, undefined); _ = x; } } diff --git a/test/behavior/ptrfromint.zig b/test/behavior/ptrfromint.zig index 72244aa7d1..89706be891 100644 --- a/test/behavior/ptrfromint.zig +++ b/test/behavior/ptrfromint.zig @@ -9,6 +9,7 @@ test "casting integer address to function pointer" { fn addressToFunction() void { var addr: usize = 0xdeadbee0; + _ = &addr; _ = @as(*const fn () void, @ptrFromInt(addr)); } diff --git a/test/behavior/saturating_arithmetic.zig b/test/behavior/saturating_arithmetic.zig index 30d1aa712e..82d10d9540 100644 --- a/test/behavior/saturating_arithmetic.zig +++ b/test/behavior/saturating_arithmetic.zig @@ -246,9 +246,11 @@ test "saturating shl uses the LHS type" { const lhs_const: u8 = 1; var lhs_var: u8 = 1; + _ = &lhs_var; const rhs_const: usize = 8; var rhs_var: usize = 8; + _ = &rhs_var; try expect((lhs_const <<| 8) == 255); try expect((lhs_const <<| rhs_const) == 255); diff --git a/test/behavior/select.zig b/test/behavior/select.zig index 66cc0a49b0..de717e5e5b 100644 --- a/test/behavior/select.zig +++ b/test/behavior/select.zig @@ -19,7 +19,8 @@ fn selectVectors() !void { var a = @Vector(4, bool){ true, false, true, false }; var b = @Vector(4, i32){ -1, 4, 999, -31 }; var c = @Vector(4, i32){ -5, 1, 0, 1234 }; - var abc = @select(i32, a, b, c); + _ = .{ &a, &b, &c }; + const abc = @select(i32, a, b, c); try expect(abc[0] == -1); try expect(abc[1] == 1); try expect(abc[2] == 999); @@ -28,7 +29,8 @@ fn selectVectors() !void { var x = @Vector(4, bool){ false, false, false, true }; var y = @Vector(4, f32){ 0.001, 33.4, 836, -3381.233 }; var z = @Vector(4, f32){ 0.0, 312.1, -145.9, 9993.55 }; - var xyz = @select(f32, x, y, z); + _ = .{ &x, &y, &z }; + const xyz = @select(f32, x, y, z); try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); } @@ -48,7 +50,8 @@ fn selectArrays() !void { var a = [4]bool{ false, true, false, true }; var b = [4]usize{ 0, 1, 2, 3 }; var c = [4]usize{ 4, 5, 6, 7 }; - var abc = @select(usize, a, b, c); + _ = .{ &a, &b, &c }; + const abc = @select(usize, a, b, c); try expect(abc[0] == 4); try expect(abc[1] == 1); try expect(abc[2] == 6); @@ -57,6 +60,7 @@ fn selectArrays() !void { var x = [4]bool{ false, false, false, true }; var y = [4]f32{ 0.001, 33.4, 836, -3381.233 }; var z = [4]f32{ 0.0, 312.1, -145.9, 9993.55 }; - var xyz = @select(f32, x, y, z); + _ = .{ &x, &y, &z }; + const xyz = @select(f32, x, y, z); try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); } diff --git a/test/behavior/shuffle.zig b/test/behavior/shuffle.zig index 6137c66f1f..e9d7706ff4 100644 --- a/test/behavior/shuffle.zig +++ b/test/behavior/shuffle.zig @@ -13,7 +13,9 @@ test "@shuffle int" { const S = struct { fn doTheTest() !void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; + _ = &v; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; + _ = &x; const mask = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; var res = @shuffle(i32, v, x, mask); try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 })); @@ -29,12 +31,14 @@ test "@shuffle int" { // Upcasting of b var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; + _ = &v2; const mask3 = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; res = @shuffle(i32, x, v2, mask3); try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 })); // Upcasting of a var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; + _ = &v3; const mask4 = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; res = @shuffle(i32, v3, x, mask4); try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 })); @@ -55,9 +59,11 @@ test "@shuffle bool 1" { const S = struct { fn doTheTest() !void { var x: @Vector(4, bool) = [4]bool{ false, true, false, true }; + _ = &x; var v: @Vector(2, bool) = [2]bool{ true, false }; + _ = &v; const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; - var res = @shuffle(bool, x, v, mask); + const res = @shuffle(bool, x, v, mask); try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false })); } }; @@ -81,9 +87,11 @@ test "@shuffle bool 2" { const S = struct { fn doTheTest() !void { var x: @Vector(3, bool) = [3]bool{ false, true, false }; + _ = &x; var v: @Vector(2, bool) = [2]bool{ true, false }; + _ = &v; const mask = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; - var res = @shuffle(bool, x, v, mask); + const res = @shuffle(bool, x, v, mask); try expect(mem.eql(bool, &@as([4]bool, res), &[4]bool{ false, false, true, false })); } }; diff --git a/test/behavior/sizeof_and_typeof.zig b/test/behavior/sizeof_and_typeof.zig index 74b02d7fdb..00f891a70f 100644 --- a/test/behavior/sizeof_and_typeof.zig +++ b/test/behavior/sizeof_and_typeof.zig @@ -22,20 +22,24 @@ test "@TypeOf() with multiple arguments" { var var_1: u32 = undefined; var var_2: u8 = undefined; var var_3: u64 = undefined; + _ = .{ &var_1, &var_2, &var_3 }; try comptime expect(@TypeOf(var_1, var_2, var_3) == u64); } { var var_1: f16 = undefined; var var_2: f32 = undefined; var var_3: f64 = undefined; + _ = .{ &var_1, &var_2, &var_3 }; try comptime expect(@TypeOf(var_1, var_2, var_3) == f64); } { var var_1: u16 = undefined; + _ = &var_1; try comptime expect(@TypeOf(var_1, 0xffff) == u16); } { var var_1: f32 = undefined; + _ = &var_1; try comptime expect(@TypeOf(var_1, 3.1415) == f32); } } @@ -269,6 +273,7 @@ test "runtime instructions inside typeof in comptime only scope" { { var y: i8 = 2; + _ = &y; const i: [2]i8 = [_]i8{ 1, y }; const T = struct { a: @TypeOf(i) = undefined, // causes crash @@ -279,6 +284,7 @@ test "runtime instructions inside typeof in comptime only scope" { } { var y: i8 = 2; + _ = &y; const i = .{ 1, y }; const T = struct { b: @TypeOf(i[1]) = undefined, diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig index c95bc293ef..7ceabf05cf 100644 --- a/test/behavior/slice.zig +++ b/test/behavior/slice.zig @@ -23,7 +23,7 @@ comptime { }; const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong }; const list: []const type = &unsigned; - var pos = S.indexOfScalar(type, list, c_ulong).?; + const pos = S.indexOfScalar(type, list, c_ulong).?; if (pos != 1) @compileError("bad pos"); } @@ -36,13 +36,14 @@ test "slicing" { var slice = array[5..10]; - if (slice.len != 5) unreachable; + try expect(slice.len == 5); const ptr = &slice[0]; - if (ptr.* != 1234) unreachable; + try expect(ptr.* == 1234); var slice_rest = array[10..]; - if (slice_rest.len != 10) unreachable; + _ = &slice_rest; + try expect(slice_rest.len == 10); } test "const slice" { @@ -79,7 +80,7 @@ test "access len index of sentinel-terminated slice" { const S = struct { fn doTheTest() !void { var slice: [:0]const u8 = "hello"; - + _ = &slice; try expect(slice.len == 5); try expect(slice[5] == 0); } @@ -208,6 +209,7 @@ test "slice string literal has correct type" { try expect(@TypeOf(array[0..]) == *const [4]i32); } var runtime_zero: usize = 0; + _ = &runtime_zero; try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8); const array = [_]i32{ 1, 2, 3, 4 }; try comptime expect(@TypeOf(array[runtime_zero..]) == []const i32); @@ -219,7 +221,8 @@ test "result location zero sized array inside struct field implicit cast to slic const E = struct { entries: []u32, }; - var foo = E{ .entries = &[_]u32{} }; + var foo: E = .{ .entries = &[_]u32{} }; + _ = &foo; try expect(foo.entries.len == 0); } @@ -242,7 +245,8 @@ test "C pointer" { var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf"; var len: u32 = 10; - var slice = buf[0..len]; + _ = &len; + const slice = buf[0..len]; try expect(mem.eql(u8, "kjdhfkjdhf", slice)); } @@ -255,6 +259,7 @@ test "C pointer slice access" { const c_ptr = @as([*c]const u32, @ptrCast(&buf)); var runtime_zero: usize = 0; + _ = &runtime_zero; try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1])); try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1])); @@ -306,11 +311,13 @@ test "obtaining a null terminated slice" { _ = ptr; var runtime_len: usize = 3; + _ = &runtime_len; const ptr2 = buf[0..runtime_len :0]; // ptr2 is a null-terminated slice try comptime expect(@TypeOf(ptr2) == [:0]u8); try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8); var runtime_zero: usize = 0; + _ = &runtime_zero; try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8); } @@ -338,8 +345,8 @@ test "@ptrCast slice to pointer" { const S = struct { fn doTheTest() !void { var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff }; - var slice: []align(@alignOf(u16)) u8 = &array; - var ptr = @as(*u16, @ptrCast(slice)); + const slice: []align(@alignOf(u16)) u8 = &array; + const ptr: *u16 = @ptrCast(slice); try expect(ptr.* == 65535); } }; @@ -357,8 +364,8 @@ test "slice multi-pointer without end" { fn testPointer() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; - var pointer: [*]u8 = &array; - var slice = pointer[1..]; + const pointer: [*]u8 = &array; + const slice = pointer[1..]; try comptime expect(@TypeOf(slice) == [*]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -366,13 +373,13 @@ test "slice multi-pointer without end" { fn testPointerZ() !void { var array = [5:0]u8{ 1, 2, 3, 4, 5 }; - var pointer: [*:0]u8 = &array; + const pointer: [*:0]u8 = &array; try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8); try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8); - var slice = pointer[1..]; + const slice = pointer[1..]; try comptime expect(@TypeOf(slice) == [*:0]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -413,7 +420,7 @@ test "slice syntax resulting in pointer-to-array" { fn testArray() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; - var slice = array[1..3]; + const slice = array[1..3]; try comptime expect(@TypeOf(slice) == *[2]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -430,12 +437,12 @@ test "slice syntax resulting in pointer-to-array" { fn testArray0() !void { { var array = [0]u8{}; - var slice = array[0..0]; + const slice = array[0..0]; try comptime expect(@TypeOf(slice) == *[0]u8); } { var array = [0:0]u8{}; - var slice = array[0..0]; + const slice = array[0..0]; try comptime expect(@TypeOf(slice) == *[0:0]u8); try expect(slice[0] == 0); } @@ -443,7 +450,7 @@ test "slice syntax resulting in pointer-to-array" { fn testArrayAlign() !void { var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; - var slice = array[4..5]; + const slice = array[4..5]; try comptime expect(@TypeOf(slice) == *align(4) [1]u8); try expect(slice[0] == 5); try comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8); @@ -452,7 +459,7 @@ test "slice syntax resulting in pointer-to-array" { fn testPointer() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; var pointer: [*]u8 = &array; - var slice = pointer[1..3]; + const slice = pointer[1..3]; try comptime expect(@TypeOf(slice) == *[2]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -467,7 +474,7 @@ test "slice syntax resulting in pointer-to-array" { fn testPointer0() !void { var pointer: [*]const u0 = &[1]u0{0}; - var slice = pointer[0..1]; + const slice = pointer[0..1]; try comptime expect(@TypeOf(slice) == *const [1]u0); try expect(slice[0] == 0); } @@ -475,7 +482,7 @@ test "slice syntax resulting in pointer-to-array" { fn testPointerAlign() !void { var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; var pointer: [*]align(4) u8 = &array; - var slice = pointer[4..5]; + const slice = pointer[4..5]; try comptime expect(@TypeOf(slice) == *align(4) [1]u8); try expect(slice[0] == 5); try comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8); @@ -484,7 +491,7 @@ test "slice syntax resulting in pointer-to-array" { fn testSlice() !void { var array = [5]u8{ 1, 2, 3, 4, 5 }; var src_slice: []u8 = &array; - var slice = src_slice[1..3]; + const slice = src_slice[1..3]; try comptime expect(@TypeOf(slice) == *[2]u8); try expect(slice[0] == 2); try expect(slice[1] == 3); @@ -513,7 +520,7 @@ test "slice syntax resulting in pointer-to-array" { fn testSliceAlign() !void { var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; var src_slice: []align(4) u8 = &array; - var slice = src_slice[4..5]; + const slice = src_slice[4..5]; try comptime expect(@TypeOf(slice) == *align(4) [1]u8); try expect(slice[0] == 5); try comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8); @@ -616,13 +623,13 @@ test "slice pointer-to-array zero length" { { var array = [0]u8{}; var src_slice: []u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try expect(@TypeOf(slice) == *[0]u8); } { var array = [0:0]u8{}; var src_slice: [:0]u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try expect(@TypeOf(slice) == *[0:0]u8); } } @@ -630,13 +637,13 @@ test "slice pointer-to-array zero length" { { var array = [0]u8{}; var src_slice: []u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try comptime expect(@TypeOf(slice) == *[0]u8); } { var array = [0:0]u8{}; var src_slice: [:0]u8 = &array; - var slice = src_slice[0..0]; + const slice = src_slice[0..0]; try comptime expect(@TypeOf(slice) == *[0]u8); } } @@ -655,17 +662,19 @@ test "type coercion of pointer to anon struct literal to pointer to slice" { fn doTheTest() !void { var x1: u8 = 42; + _ = &x1; const t1 = &.{ x1, 56, 54 }; - var slice1: []const u8 = t1; + const slice1: []const u8 = t1; try expect(slice1.len == 3); try expect(slice1[0] == 42); try expect(slice1[1] == 56); try expect(slice1[2] == 54); var x2: []const u8 = "hello"; + _ = &x2; const t2 = &.{ x2, ", ", "world!" }; // @compileLog(@TypeOf(t2)); - var slice2: []const []const u8 = t2; + const slice2: []const []const u8 = t2; try expect(slice2.len == 3); try expect(mem.eql(u8, slice2[0], "hello")); try expect(mem.eql(u8, slice2[1], ", ")); @@ -680,6 +689,7 @@ test "array concat of slices gives ptr to array" { comptime { var a: []const u8 = "aoeu"; var b: []const u8 = "asdf"; + _ = .{ &a, &b }; const c = a ++ b; try expect(std.mem.eql(u8, c, "aoeuasdf")); try expect(@TypeOf(c) == *const [8]u8); @@ -689,6 +699,7 @@ test "array concat of slices gives ptr to array" { test "array mult of slice gives ptr to array" { comptime { var a: []const u8 = "aoeu"; + _ = &a; const c = a ** 2; try expect(std.mem.eql(u8, c, "aoeuaoeu")); try expect(@TypeOf(c) == *const [8]u8); @@ -736,7 +747,7 @@ test "slicing array with sentinel as end index" { const S = struct { fn do() !void { var array = [_:0]u8{ 1, 2, 3, 4 }; - var slice = array[4..5]; + const slice = array[4..5]; try expect(slice.len == 1); try expect(slice[0] == 0); try expect(@TypeOf(slice) == *[1]u8); @@ -754,8 +765,8 @@ test "slicing slice with sentinel as end index" { const S = struct { fn do() !void { var array = [_:0]u8{ 1, 2, 3, 4 }; - var src_slice: [:0]u8 = &array; - var slice = src_slice[4..5]; + const src_slice: [:0]u8 = &array; + const slice = src_slice[4..5]; try expect(slice.len == 1); try expect(slice[0] == 0); try expect(@TypeOf(slice) == *[1]u8); @@ -820,6 +831,7 @@ test "global slice field access" { test "slice of void" { var n: usize = 10; + _ = &n; var arr: [12]void = undefined; const slice = @as([]void, &arr)[0..n]; try expect(slice.len == n); @@ -827,7 +839,7 @@ test "slice of void" { test "slice with dereferenced value" { var a: usize = 0; - var idx: *usize = &a; + const idx: *usize = &a; _ = blk: { var array = [_]u8{}; break :blk array[idx.*..]; diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 08954dfd68..97ccb3212f 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -254,7 +254,8 @@ test "struct field init with catch" { const S = struct { fn doTheTest() !void { var x: anyerror!isize = 1; - var req = Foo{ + _ = &x; + const req = Foo{ .field = x catch undefined, }; try expect(req.field == 1); @@ -505,7 +506,7 @@ test "packed struct fields are ordered from LSB to MSB" { var all: u64 = 0x7765443322221111; var bytes: [8]u8 align(@alignOf(Bitfields)) = undefined; @memcpy(bytes[0..8], @as([*]u8, @ptrCast(&all))); - var bitfields = @as(*Bitfields, @ptrCast(&bytes)).*; + const bitfields = @as(*Bitfields, @ptrCast(&bytes)).*; try expect(bitfields.f1 == 0x1111); try expect(bitfields.f2 == 0x2222); @@ -545,7 +546,7 @@ test "zero-bit field in packed struct" { y: void, }; var x: S = undefined; - _ = x; + _ = &x; } test "packed struct with non-ABI-aligned field" { @@ -624,6 +625,7 @@ test "default struct initialization fields" { .b = 5, }; var five: i32 = 5; + _ = &five; const y = S{ .b = five, }; @@ -714,7 +716,7 @@ test "pointer to packed struct member in a stack variable" { }; var s = S{ .a = 2, .b = 0 }; - var b_ptr = &s.b; + const b_ptr = &s.b; try expect(s.b == 0); b_ptr.* = 2; try expect(s.b == 2); @@ -727,6 +729,7 @@ test "packed struct with u0 field access" { f0: u0, }; var s = S{ .f0 = 0 }; + _ = &s; try comptime expect(s.f0 == 0); } @@ -788,7 +791,7 @@ test "fn with C calling convention returns struct by value" { const S = struct { fn entry() !void { - var x = makeBar(10); + const x = makeBar(10); try expect(@as(i32, 10) == x.handle); } @@ -827,6 +830,7 @@ test "non-packed struct with u128 entry in union" { var s = &sx; try expect(@intFromPtr(&s.f2) - @intFromPtr(&s.f1) == @offsetOf(S, "f2")); var v2 = U{ .Num = 123 }; + _ = &v2; s.f2 = v2; try expect(s.f2.Num == 123); } @@ -852,7 +856,7 @@ test "packed struct field passed to generic function" { var p: S.P = undefined; p.b = 29; - var loaded = S.genericReadPackedField(&p.b); + const loaded = S.genericReadPackedField(&p.b); try expect(loaded == 29); } @@ -871,6 +875,7 @@ test "anonymous struct literal syntax" { .x = 1, .y = 2, }; + _ = &p; try expect(p.x == 1); try expect(p.y == 2); } @@ -920,6 +925,7 @@ test "fully anonymous list literal" { test "tuple assigned to variable" { var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) }; + _ = &vec; try expect(vec.@"0" == 22); try expect(vec.@"1" == 55); try expect(vec.@"2" == 99); @@ -940,6 +946,7 @@ test "comptime struct field" { comptime std.debug.assert(@sizeOf(T) == 4); var foo: T = undefined; + _ = &foo; try comptime expect(foo.b == 1234); } @@ -950,7 +957,7 @@ test "tuple element initialized with fn call" { const S = struct { fn doTheTest() !void { - var x = .{foo()}; + const x = .{foo()}; try expectEqualSlices(u8, x[0], "hi"); } fn foo() []const u8 { @@ -977,6 +984,7 @@ test "struct with union field" { var True = Value{ .kind = .{ .Bool = true }, }; + _ = &True; try expect(@as(u32, 2) == True.ref); try expect(True.kind.Bool); } @@ -996,6 +1004,7 @@ test "struct with 0-length union array field" { }; var s: S = undefined; + _ = &s; try expectEqual(@as(usize, 0), s.zero_length.len); } @@ -1019,10 +1028,11 @@ test "type coercion of anon struct literal to struct" { fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = .{ .A = 123, .B = "foo", .C = {} }; const t1 = .{ .A = y, .B = "foo", .C = {} }; const y0: S2 = t0; - var y1: S2 = t1; + const y1: S2 = t1; try expect(y0.A == 123); try expect(std.mem.eql(u8, y0.B, "foo")); try expect(y0.C == {}); @@ -1057,10 +1067,11 @@ test "type coercion of pointer to anon struct literal to pointer to struct" { fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = &.{ .A = 123, .B = "foo", .C = {} }; const t1 = &.{ .A = y, .B = "foo", .C = {} }; const y0: *const S2 = t0; - var y1: *const S2 = t1; + const y1: *const S2 = t1; try expect(y0.A == 123); try expect(std.mem.eql(u8, y0.B, "foo")); try expect(y0.C == {}); @@ -1161,8 +1172,8 @@ test "anon init through error unions and optionals" { } fn doTheTest() !void { - var a = try (try foo()).?; - var b = try bar().?; + const a = try (try foo()).?; + const b = try bar().?; try expect(a.a + b[1] == 3); } }; @@ -1227,8 +1238,8 @@ test "typed init through error unions and optionals" { } fn doTheTest() !void { - var a = try (try foo()).?; - var b = try bar().?; + const a = try (try foo()).?; + const b = try bar().?; try expect(a.a + b[1] == 3); } }; @@ -1243,6 +1254,7 @@ test "initialize struct with empty literal" { const S = struct { x: i32 = 1234 }; var s: S = .{}; + _ = &s; try expect(s.x == 1234); } @@ -1301,10 +1313,10 @@ test "packed struct field access via pointer" { fn doTheTest() !void { const S = packed struct { a: u30 }; var s1: S = .{ .a = 1 }; - var s2 = &s1; + const s2 = &s1; try expect(s2.a == 1); var s3: S = undefined; - var s4 = &s3; + const s4 = &s3; _ = s4; } }; @@ -1343,6 +1355,7 @@ test "struct field init value is size of the struct" { }; }; var s: namespace.S = .{ .blah = 1234 }; + _ = &s; try expect(s.size == 4); } @@ -1362,6 +1375,7 @@ test "under-aligned struct field" { data: U align(4), }; var runtime: usize = 1234; + _ = &runtime; const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } }; const array = @as(*const [12]u8, @ptrCast(ptr)); const result = std.mem.readInt(u64, array[4..12], native_endian); @@ -1509,6 +1523,7 @@ test "function pointer in struct returns the struct" { } }; var a = A.f(); + _ = &a; try expect(a.f == A.f); } @@ -1538,7 +1553,8 @@ test "optional field init with tuple" { a: ?struct { b: u32 }, }; var a: u32 = 0; - var b = S{ + _ = &a; + const b = S{ .a = .{ .b = a }, }; try expect(b.a.?.b == a); @@ -1550,7 +1566,8 @@ test "if inside struct init inside if" { const MyStruct = struct { x: u32 }; const b: u32 = 5; var i: u32 = 1; - var my_var = if (i < 5) + _ = &i; + const my_var = if (i < 5) MyStruct{ .x = 1 + if (i > 0) b else 0, } @@ -1599,7 +1616,7 @@ test "instantiate struct with comptime field" { var things = struct { comptime foo: i8 = 1, }{}; - + _ = &things; comptime std.debug.assert(things.foo == 1); } @@ -1608,7 +1625,7 @@ test "instantiate struct with comptime field" { comptime foo: i8 = 1, }; var things = T{}; - + _ = &things; comptime std.debug.assert(things.foo == 1); } @@ -1616,7 +1633,7 @@ test "instantiate struct with comptime field" { var things: struct { comptime foo: i8 = 1, } = .{}; - + _ = &things; comptime std.debug.assert(things.foo == 1); } @@ -1624,7 +1641,7 @@ test "instantiate struct with comptime field" { var things: struct { comptime foo: i8 = 1, } = undefined; // Segmentation fault at address 0x0 - + _ = &things; comptime std.debug.assert(things.foo == 1); } } @@ -1755,6 +1772,7 @@ test "runtime side-effects in comptime-known struct init" { test "pointer to struct initialized through reference to anonymous initializer provides result types" { const S = struct { a: u8, b: u16, c: *const anyopaque }; var my_u16: u16 = 0xABCD; + _ = &my_u16; const s: *const S = &.{ // intentionally out of order .c = @ptrCast("hello"), @@ -1792,6 +1810,7 @@ test "initializer uses own alignment" { }; var s: S = .{}; + _ = &s; try expectEqual(4, @alignOf(S)); try expectEqual(@as(usize, 5), s.x); } @@ -1802,6 +1821,7 @@ test "initializer uses own size" { }; var s: S = .{}; + _ = &s; try expectEqual(4, @sizeOf(S)); try expectEqual(@as(usize, 5), s.x); } @@ -1815,6 +1835,7 @@ test "initializer takes a pointer to a variable inside its struct" { fn doTheTest() !void { var foo: S = .{}; + _ = &foo; try expectEqual(&S.instance, foo.s); } }; @@ -1839,6 +1860,7 @@ test "circular dependency through pointer field of a struct" { }; }; var outer: S.StructOuter = .{}; + _ = &outer; try expect(outer.middle.outer == null); try expect(outer.middle.inner == null); } @@ -1855,5 +1877,6 @@ test "field calls do not force struct field init resolution" { } }; var s: S = .{}; + _ = &s; try expect(s.x == 123); } diff --git a/test/behavior/struct_contains_null_ptr_itself.zig b/test/behavior/struct_contains_null_ptr_itself.zig index 7f0182af22..d0cb3ef443 100644 --- a/test/behavior/struct_contains_null_ptr_itself.zig +++ b/test/behavior/struct_contains_null_ptr_itself.zig @@ -7,6 +7,7 @@ test "struct contains null pointer which contains original struct" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: ?*NodeLineComment = null; + _ = &x; try expect(x == null); } diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig index 37cf8b7c6f..ae4923609f 100644 --- a/test/behavior/switch.zig +++ b/test/behavior/switch.zig @@ -157,6 +157,7 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool { test "u0" { var val: u0 = 0; + _ = &val; switch (val) { 0 => try expect(val == 0), } @@ -164,6 +165,7 @@ test "u0" { test "undefined.u0" { var val: u0 = undefined; + _ = &val; switch (val) { 0 => try expect(val == 0), } @@ -173,6 +175,7 @@ test "switch with disjoint range" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var q: u8 = 0; + _ = &q; switch (q) { 0...125 => {}, 127...255 => {}, @@ -183,12 +186,8 @@ test "switch with disjoint range" { test "switch variable for range and multiple prongs" { const S = struct { fn doTheTest() !void { - var u: u8 = 16; - try doTheSwitch(u); - try comptime doTheSwitch(u); - var v: u8 = 42; - try doTheSwitch(v); - try comptime doTheSwitch(v); + try doTheSwitch(16); + try doTheSwitch(42); } fn doTheSwitch(q: u8) !void { switch (q) { @@ -198,7 +197,8 @@ test "switch variable for range and multiple prongs" { } } }; - _ = S; + try S.doTheTest(); + try comptime S.doTheTest(); } var state: u32 = 0; @@ -322,7 +322,8 @@ test "switch on union with some prongs capturing" { }; var x: X = X{ .b = 10 }; - var y: i32 = switch (x) { + _ = &x; + const y: i32 = switch (x) { .a => unreachable, .b => |b| b + 1, }; @@ -357,6 +358,7 @@ test "anon enum literal used in switch on union enum" { }; var foo = Foo{ .a = 1234 }; + _ = &foo; switch (foo) { .a => |x| { try expect(x == 1234); @@ -406,6 +408,7 @@ test "switch on integer with else capturing expr" { const S = struct { fn doTheTest() !void { var x: i32 = 5; + _ = &x; switch (x + 10) { 14 => @panic("fail"), 16 => @panic("fail"), @@ -606,6 +609,7 @@ test "switch on error set with single else" { const S = struct { fn doTheTest() !void { var some: error{Foo} = error.Foo; + _ = &some; try expect(switch (some) { else => blk: { break :blk true; @@ -672,7 +676,8 @@ test "enum value without tag name used as switch item" { b = 2, _, }; - var e: E = @as(E, @enumFromInt(0)); + var e: E = @enumFromInt(0); + _ = &e; switch (e) { @as(E, @enumFromInt(0)) => {}, .a => return error.TestFailed, @@ -685,6 +690,7 @@ test "switch item sizeof" { const S = struct { fn doTheTest() !void { var a: usize = 0; + _ = &a; switch (a) { @sizeOf(struct {}) => {}, else => return error.TestFailed, @@ -699,6 +705,7 @@ test "comptime inline switch" { const U = union(enum) { a: type, b: type }; const value = comptime blk: { var u: U = .{ .a = u32 }; + _ = &u; break :blk switch (u) { inline .a, .b => |v| v, }; @@ -814,6 +821,7 @@ test "peer type resolution on switch captures ignores unused payload bits" { // This is runtime-known so the following store isn't comptime-known. var rt: u32 = 123; + _ = &rt; val = .{ .a = rt }; // will not necessarily zero remaning payload memory // Fields intentionally backwards here diff --git a/test/behavior/truncate.zig b/test/behavior/truncate.zig index 4fc095b66c..3d128b7656 100644 --- a/test/behavior/truncate.zig +++ b/test/behavior/truncate.zig @@ -4,58 +4,62 @@ const expect = std.testing.expect; test "truncate u0 to larger integer allowed and has comptime-known result" { var x: u0 = 0; + _ = &x; const y = @as(u8, @truncate(x)); try comptime expect(y == 0); } test "truncate.u0.literal" { - var z = @as(u0, @truncate(0)); + const z: u0 = @truncate(0); try expect(z == 0); } test "truncate.u0.const" { const c0: usize = 0; - var z = @as(u0, @truncate(c0)); + const z: u0 = @truncate(c0); try expect(z == 0); } test "truncate.u0.var" { var d: u8 = 2; - var z = @as(u0, @truncate(d)); + _ = &d; + const z: u0 = @truncate(d); try expect(z == 0); } test "truncate i0 to larger integer allowed and has comptime-known result" { var x: i0 = 0; - const y = @as(i8, @truncate(x)); + _ = &x; + const y: i8 = @truncate(x); try comptime expect(y == 0); } test "truncate.i0.literal" { - var z = @as(i0, @truncate(0)); + const z: i0 = @truncate(0); try expect(z == 0); } test "truncate.i0.const" { const c0: isize = 0; - var z = @as(i0, @truncate(c0)); + const z: i0 = @truncate(c0); try expect(z == 0); } test "truncate.i0.var" { var d: i8 = 2; - var z = @as(i0, @truncate(d)); + _ = &d; + const z: i0 = @truncate(d); try expect(z == 0); } test "truncate on comptime integer" { - var x = @as(u16, @truncate(9999)); + const x: u16 = @truncate(9999); try expect(x == 9999); - var y = @as(u16, @truncate(-21555)); + const y: u16 = @truncate(-21555); try expect(y == 0xabcd); - var z = @as(i16, @truncate(-65537)); + const z: i16 = @truncate(-65537); try expect(z == -1); - var w = @as(u1, @truncate(1 << 100)); + const w: u1 = @truncate(1 << 100); try expect(w == 0); } @@ -69,7 +73,8 @@ test "truncate on vectors" { const S = struct { fn doTheTest() !void { var v1: @Vector(4, u16) = .{ 0xaabb, 0xccdd, 0xeeff, 0x1122 }; - var v2: @Vector(4, u8) = @truncate(v1); + _ = &v1; + const v2: @Vector(4, u8) = @truncate(v1); try expect(std.mem.eql(u8, &@as([4]u8, v2), &[4]u8{ 0xbb, 0xdd, 0xff, 0x22 })); } }; diff --git a/test/behavior/tuple.zig b/test/behavior/tuple.zig index 63e2cde46e..039a96d29f 100644 --- a/test/behavior/tuple.zig +++ b/test/behavior/tuple.zig @@ -15,9 +15,10 @@ test "tuple concatenation" { fn doTheTest() !void { var a: i32 = 1; var b: i32 = 2; - var x = .{a}; - var y = .{b}; - var c = x ++ y; + _ = .{ &a, &b }; + const x = .{a}; + const y = .{b}; + const c = x ++ y; try expect(@as(i32, 1) == c[0]); try expect(@as(i32, 2) == c[1]); } @@ -119,7 +120,7 @@ test "tuple initializer for var" { .id = @as(usize, 2), .name = Bytes{ .id = 20 }, }; - _ = tmp; + _ = &tmp; } }; @@ -157,6 +158,7 @@ test "array-like initializer for tuple types" { const S = struct { fn doTheTest() !void { var obj: T = .{ -1234, 128 }; + _ = &obj; try expect(@as(i32, -1234) == obj[0]); try expect(@as(u8, 128) == obj[1]); } @@ -171,6 +173,7 @@ test "anon struct as the result from a labeled block" { fn doTheTest() !void { const precomputed = comptime blk: { var x: i32 = 1234; + _ = &x; break :blk .{ .x = x, }; @@ -188,6 +191,7 @@ test "tuple as the result from a labeled block" { fn doTheTest() !void { const precomputed = comptime blk: { var x: i32 = 1234; + _ = &x; break :blk .{x}; }; try expect(precomputed[0] == 1234); @@ -201,13 +205,13 @@ test "tuple as the result from a labeled block" { test "initializing tuple with explicit type" { const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); var a = T{ 0, 0 }; - _ = a; + _ = &a; } test "initializing anon struct with explicit type" { const T = @TypeOf(.{ .foo = @as(i32, 1), .bar = @as(i32, 2) }); var a = T{ .foo = 1, .bar = 2 }; - _ = a; + _ = &a; } test "fieldParentPtr of tuple" { @@ -216,6 +220,7 @@ test "fieldParentPtr of tuple" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 0; + _ = &x; const tuple = .{ x, x }; try testing.expect(&tuple == @fieldParentPtr(@TypeOf(tuple), "1", &tuple[1])); } @@ -226,18 +231,21 @@ test "fieldParentPtr of anon struct" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: u32 = 0; + _ = &x; const anon_st = .{ .foo = x, .bar = x }; try testing.expect(&anon_st == @fieldParentPtr(@TypeOf(anon_st), "bar", &anon_st.bar)); } test "offsetOf tuple" { var x: u32 = 0; + _ = &x; const T = @TypeOf(.{ x, x }); try expect(@offsetOf(T, "1") == @sizeOf(u32)); } test "offsetOf anon struct" { var x: u32 = 0; + _ = &x; const T = @TypeOf(.{ .foo = x, .bar = x }); try expect(@offsetOf(T, "bar") == @sizeOf(u32)); } @@ -247,8 +255,10 @@ test "initializing tuple with mixed comptime-runtime fields" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u32 = 15; + _ = &x; const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); var a: T = .{ -1234, 5678, x + 1 }; + _ = &a; try expect(a[2] == 16); } @@ -257,8 +267,10 @@ test "initializing anon struct with mixed comptime-runtime fields" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var x: u32 = 15; + _ = &x; const T = @TypeOf(.{ .foo = @as(i32, -1234), .bar = x }); var a: T = .{ .foo = -1234, .bar = x + 1 }; + _ = &a; try expect(a.bar == 16); } @@ -338,6 +350,7 @@ test "tuple type with void field and a runtime field" { const T = std.meta.Tuple(&[_]type{ usize, void }); var t: T = .{ 5, {} }; + _ = &t; try expect(t[0] == 5); } @@ -352,6 +365,7 @@ test "branching inside tuple literal" { } }; var a = false; + _ = &a; try S.foo(.{if (a) @as(u32, 5678) else @as(u32, 1234)}); } @@ -363,6 +377,7 @@ test "tuple initialized with a runtime known value" { const E = union(enum) { e: []const u8 }; const W = union(enum) { w: E }; var e = E{ .e = "test" }; + _ = &e; const w = .{W{ .w = e }}; try expectEqualStrings(w[0].w.e, "test"); } @@ -388,6 +403,7 @@ test "nested runtime conditionals in tuple initializer" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var data: u8 = 0; + _ = &data; const x = .{ if (data != 0) "" else switch (@as(u1, @truncate(data))) { 0 => "up", @@ -446,8 +462,9 @@ test "coerce anon tuple to tuple" { var x: u8 = 1; var y: u16 = 2; - var t = .{ x, y }; - var s: struct { u8, u16 } = t; + _ = .{ &x, &y }; + const t = .{ x, y }; + const s: struct { u8, u16 } = t; try expectEqual(x, s[0]); try expectEqual(y, s[1]); } diff --git a/test/behavior/tuple_declarations.zig b/test/behavior/tuple_declarations.zig index 8ffc25613d..e3730b3995 100644 --- a/test/behavior/tuple_declarations.zig +++ b/test/behavior/tuple_declarations.zig @@ -38,17 +38,19 @@ test "Tuple declaration usage" { const T = struct { u32, []const u8 }; var t: T = .{ 1, "foo" }; + _ = &t; try expect(t[0] == 1); try expectEqualStrings(t[1], "foo"); - var mul = t ** 3; + const mul = t ** 3; try expect(@TypeOf(mul) != T); try expect(mul.len == 6); try expect(mul[2] == 1); try expectEqualStrings(mul[3], "foo"); var t2: T = .{ 2, "bar" }; - var cat = t ++ t2; + _ = &t2; + const cat = t ++ t2; try expect(@TypeOf(cat) != T); try expect(cat.len == 4); try expect(cat[2] == 2); diff --git a/test/behavior/type.zig b/test/behavior/type.zig index 7d0147c508..64c4c85669 100644 --- a/test/behavior/type.zig +++ b/test/behavior/type.zig @@ -410,7 +410,8 @@ test "Type.Union" { .decls = &.{}, }, }); - var packed_untagged = PackedUntagged{ .signed = -1 }; + var packed_untagged: PackedUntagged = .{ .signed = -1 }; + _ = &packed_untagged; try testing.expectEqual(@as(i32, -1), packed_untagged.signed); try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned); @@ -529,7 +530,7 @@ test "reified struct field name from optional payload" { .decls = &.{}, .is_tuple = false, } }); - var t: T = .{ .a = 123 }; + const t: T = .{ .a = 123 }; try std.testing.expect(t.a == 123); } } diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig index bc4737a552..63f2ecb30f 100644 --- a/test/behavior/type_info.zig +++ b/test/behavior/type_info.zig @@ -417,7 +417,7 @@ test "typeInfo with comptime parameter in struct fn def" { } }; comptime var info = @typeInfo(S); - _ = info; + _ = &info; } test "type info: vectors" { diff --git a/test/behavior/union.zig b/test/behavior/union.zig index 338db47036..804cea47f8 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -171,6 +171,7 @@ test "constant tagged union with payload" { var empty = TaggedUnionWithPayload{ .Empty = {} }; var full = TaggedUnionWithPayload{ .Full = 13 }; + _ = .{ &empty, &full }; shouldBeEmpty(empty); shouldBeNotEmpty(full); } @@ -254,6 +255,7 @@ fn bar(value: Payload) error{TestUnexpectedResult}!i32 { fn testComparison() !void { var x = Payload{ .A = 42 }; + _ = &x; try expect(x == .A); try expect(x != .B); try expect(x != .C); @@ -288,6 +290,7 @@ test "cast union to tag type of union" { fn testCastUnionToTag() !void { var u = TheUnion{ .B = 1234 }; + _ = &u; try expect(@as(TheTag, u) == TheTag.B); } @@ -303,6 +306,7 @@ test "cast tag type of union to union" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: Value2 = Letter2.B; + _ = &x; try expect(@as(Letter2, x) == Letter2.B); } const Letter2 = enum { A, B, C }; @@ -318,6 +322,7 @@ test "implicit cast union to its tag type" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: Value2 = Letter2.B; + _ = &x; try expect(x == Letter2.B); try giveMeLetterB(x); } @@ -356,6 +361,7 @@ test "simple union(enum(u32))" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x = MultipleChoice.C; + _ = &x; try expect(x == MultipleChoice.C); try expect(@intFromEnum(@as(Tag(MultipleChoice), x)) == 60); } @@ -420,9 +426,11 @@ test "union with only 1 field casted to its enum type" { }; var e = Expr{ .Literal = Literal{ .Bool = true } }; + _ = &e; const ExprTag = Tag(Expr); try comptime expect(Tag(ExprTag) == u0); var t = @as(ExprTag, e); + _ = &t; try expect(t == Expr.Literal); } @@ -494,6 +502,7 @@ test "union initializer generates padding only if needed" { }; var v = U{ .A = 532 }; + _ = &v; try expect(v.A == 532); } @@ -506,6 +515,7 @@ test "runtime tag name with single field" { }; var v = U{ .A = 42 }; + _ = &v; try expect(std.mem.eql(u8, @tagName(v), "A")); } @@ -698,8 +708,9 @@ test "union with only 1 field casted to its enum type which has enum value speci }; var e = Expr{ .Literal = Literal{ .Bool = true } }; + _ = &e; try comptime expect(Tag(ExprTag) == comptime_int); - comptime var t = @as(ExprTag, e); + const t = comptime @as(ExprTag, e); try expect(t == Expr.Literal); try expect(@intFromEnum(t) == 33); try comptime expect(@intFromEnum(t) == 33); @@ -719,6 +730,7 @@ test "@intFromEnum works on unions" { const a = Bar{ .A = true }; var b = Bar{ .B = undefined }; var c = Bar.C; + _ = .{ &b, &c }; try expect(@intFromEnum(a) == 0); try expect(@intFromEnum(b) == 1); try expect(@intFromEnum(c) == 2); @@ -800,11 +812,13 @@ test "@unionInit stored to a const" { fn doTheTest() !void { { var t = true; + _ = &t; const u = @unionInit(U, "boolean", t); try expect(u.boolean); } { var byte: u8 = 69; + _ = &byte; const u = @unionInit(U, "byte", byte); try expect(u.byte == 69); } @@ -849,7 +863,7 @@ test "@unionInit can modify a pointer value" { }; var value: UnionInitEnum = undefined; - var value_ptr = &value; + const value_ptr = &value; value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true); try expect(value.Boolean == true); @@ -906,7 +920,8 @@ test "anonymous union literal syntax" { fn doTheTest() !void { var i: Number = .{ .int = 42 }; - var f = makeNumber(); + _ = &i; + const f = makeNumber(); try expect(i.int == 42); try expect(f.float == 12.34); } @@ -934,9 +949,11 @@ test "function call result coerces from tagged union to the tag" { fn doTheTest() !void { var x: ArchTag = getArch1(); + _ = &x; try expect(x == .One); var y: ArchTag = getArch2(); + _ = &y; try expect(y == .Two); } @@ -965,14 +982,17 @@ test "cast from anonymous struct to union" { }; fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = .{ .A = 123 }; const t1 = .{ .B = "foo" }; const t2 = .{ .C = {} }; const t3 = .{ .A = y }; const x0: U = t0; var x1: U = t1; + _ = &x1; const x2: U = t2; var x3: U = t3; + _ = &x3; try expect(x0.A == 123); try expect(std.mem.eql(u8, x1.B, "foo")); try expect(x2 == .C); @@ -996,14 +1016,17 @@ test "cast from pointer to anonymous struct to pointer to union" { }; fn doTheTest() !void { var y: u32 = 42; + _ = &y; const t0 = &.{ .A = 123 }; const t1 = &.{ .B = "foo" }; const t2 = &.{ .C = {} }; const t3 = &.{ .A = y }; const x0: *const U = t0; var x1: *const U = t1; + _ = &x1; const x2: *const U = t2; var x3: *const U = t3; + _ = &x3; try expect(x0.A == 123); try expect(std.mem.eql(u8, x1.B, "foo")); try expect(x2.* == .C); @@ -1031,6 +1054,7 @@ test "switching on non exhaustive union" { }; fn doTheTest() !void { var a = U{ .a = 2 }; + _ = &a; switch (a) { .a => |val| try expect(val == 2), .b => return error.Fail, @@ -1055,11 +1079,13 @@ test "containers with single-field enums" { fn doTheTest() !void { var array1 = [1]A{A{ .f1 = {} }}; var array2 = [1]B{B{ .f1 = {} }}; + _ = .{ &array1, &array2 }; try expect(array1[0] == .f1); try expect(array2[0] == .f1); var struct1 = C{ .a = A{ .f1 = {} } }; var struct2 = D{ .a = B{ .f1 = {} } }; + _ = .{ &struct1, &struct2 }; try expect(struct1.a == .f1); try expect(struct2.a == .f1); } @@ -1092,8 +1118,9 @@ test "@unionInit on union with tag but no fields" { fn doTheTest() !void { var data: Data = .{ .no_op = {} }; - _ = data; + _ = &data; var o = Data.decode(&[_]u8{}); + _ = &o; try expectEqual(Type.no_op, o); } }; @@ -1156,6 +1183,7 @@ test "union with no result loc initiated with a runtime value" { } }; var a: u32 = 1; + _ = &a; U.foo(U{ .a = a }); } @@ -1174,6 +1202,7 @@ test "union with a large struct field" { fn foo(_: @This()) void {} }; var s: S = undefined; + _ = &s; U.foo(U{ .s = s }); } @@ -1207,6 +1236,7 @@ test "union tag is set when initiated as a temporary value at runtime" { } }; var b: u32 = 1; + _ = &b; try (U{ .b = b }).doTheTest(); } @@ -1226,6 +1256,7 @@ test "extern union most-aligned field is smaller" { un: [110]u8, }; var a: ?U = .{ .un = [_]u8{0} ** 110 }; + _ = &a; try expect(a != null); } @@ -1246,6 +1277,7 @@ test "return an extern union from C calling convention" { fn bar(arg_u: U) callconv(.C) U { var u = arg_u; + _ = &u; return u; } }; @@ -1324,13 +1356,16 @@ test "@unionInit uses tag value instead of field index" { a: usize, }; var i: isize = -1; + _ = &i; var u = @unionInit(U, "b", i); { var a = u.b; + _ = &a; try expect(a == i); } { var a = &u.b; + _ = &a; try expect(a.* == i); } try expect(@intFromEnum(u) == 255); @@ -1508,7 +1543,7 @@ test "coerce enum literal to union in result loc" { b: u8, fn doTest(c: bool) !void { - var u = if (c) .a else @This(){ .b = 0 }; + const u = if (c) .a else @This(){ .b = 0 }; try expect(u == .a); } }; @@ -1947,6 +1982,7 @@ test "packed union initialized via reintepreted struct field initializer" { }; var s: S = .{}; + _ = &s; try expect(s.u.a == littleToNativeEndian(u32, 0xddccbbaa)); try expect(s.u.b == if (endian == .little) 0xaa else 0xdd); } @@ -1966,6 +2002,7 @@ test "store of comptime reinterpreted memory to extern union" { }; var u: U = reinterpreted; + _ = &u; try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); try expect(u.b == 0xaa); } @@ -1985,6 +2022,7 @@ test "store of comptime reinterpreted memory to packed union" { }; var u: U = reinterpreted; + _ = &u; try expect(u.a == littleToNativeEndian(u32, 0xddccbbaa)); try expect(u.b == if (endian == .little) 0xaa else 0xdd); } @@ -2018,6 +2056,7 @@ test "pass register-sized field as non-register-sized union" { }; var x: usize = 42; + _ = &x; try S.taggedUnion(.{ .x = x }); try S.untaggedUnion(.{ .x = x }); try S.externUnion(.{ .x = x }); @@ -2039,6 +2078,7 @@ test "circular dependency through pointer field of a union" { }; }; var outer: S.UnionOuter = .{}; + _ = &outer; try expect(outer.u.outer == null); try expect(outer.u.inner == null); } @@ -2057,5 +2097,6 @@ test "pass nested union with rls" { }; var c: u7 = 32; + _ = &c; try expectEqual(@as(u7, 32), Union.getC(.{ .b = .{ .c = c } })); } diff --git a/test/behavior/var_args.zig b/test/behavior/var_args.zig index 7fda8b208a..b0dccc1383 100644 --- a/test/behavior/var_args.zig +++ b/test/behavior/var_args.zig @@ -147,6 +147,7 @@ test "simple variadic function" { var runtime: bool = true; var a: i32 = 1; var b: i32 = 2; + _ = .{ &runtime, &a, &b }; try expect(1 == S.add(1, if (runtime) a else b)); } } diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig index a1b9a4f66e..a9569d1b1b 100644 --- a/test/behavior/vector.zig +++ b/test/behavior/vector.zig @@ -40,6 +40,7 @@ test "vector wrap operators" { try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 })); var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; try expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 })); + _ = .{ &v, &x, &z }; } }; try S.doTheTest(); @@ -57,6 +58,7 @@ test "vector bin compares with mem.eql" { fn doTheTest() !void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; + _ = .{ &v, &x }; try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false })); try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true })); try expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false })); @@ -81,6 +83,7 @@ test "vector int operators" { fn doTheTest() !void { var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; + _ = .{ &v, &x }; try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 })); try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 })); try expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 })); @@ -105,6 +108,7 @@ test "vector float operators" { fn doTheTest() !void { var v: @Vector(4, T) = [4]T{ 10, 20, 30, 40 }; var x: @Vector(4, T) = [4]T{ 1, 2, 3, 4 }; + _ = .{ &v, &x }; try expect(mem.eql(T, &@as([4]T, v + x), &[4]T{ 11, 22, 33, 44 })); try expect(mem.eql(T, &@as([4]T, v - x), &[4]T{ 9, 18, 27, 36 })); try expect(mem.eql(T, &@as([4]T, v * x), &[4]T{ 10, 40, 90, 160 })); @@ -126,6 +130,7 @@ test "vector bit operators" { fn doTheTest() !void { var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; + _ = .{ &v, &x }; try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); try expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); @@ -143,6 +148,7 @@ test "implicit cast vector to array" { const S = struct { fn doTheTest() !void { var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; + _ = &a; var result_array: [4]i32 = a; result_array = a; try expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 })); @@ -160,8 +166,9 @@ test "array to vector" { const S = struct { fn doTheTest() !void { var foo: f32 = 3.14; - var arr = [4]f32{ foo, 1.5, 0.0, 0.0 }; - var vec: @Vector(4, f32) = arr; + _ = &foo; + const arr = [4]f32{ foo, 1.5, 0.0, 0.0 }; + const vec: @Vector(4, f32) = arr; try expect(mem.eql(f32, &@as([4]f32, vec), &arr)); } }; @@ -180,25 +187,28 @@ test "array vector coercion - odd sizes" { const S = struct { fn doTheTest() !void { var foo1: i48 = 124578; - var vec1: @Vector(2, i48) = [2]i48{ foo1, 1 }; - var arr1: [2]i48 = vec1; + _ = &foo1; + const vec1: @Vector(2, i48) = [2]i48{ foo1, 1 }; + const arr1: [2]i48 = vec1; try expect(vec1[0] == foo1 and vec1[1] == 1); try expect(arr1[0] == foo1 and arr1[1] == 1); var foo2: u4 = 5; - var vec2: @Vector(2, u4) = [2]u4{ foo2, 1 }; - var arr2: [2]u4 = vec2; + _ = &foo2; + const vec2: @Vector(2, u4) = [2]u4{ foo2, 1 }; + const arr2: [2]u4 = vec2; try expect(vec2[0] == foo2 and vec2[1] == 1); try expect(arr2[0] == foo2 and arr2[1] == 1); var foo3: u13 = 13; - var vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 }; - var arr3: [3]u13 = vec3; + _ = &foo3; + const vec3: @Vector(3, u13) = [3]u13{ foo3, 0, 1 }; + const arr3: [3]u13 = vec3; try expect(vec3[0] == foo3 and vec3[1] == 0 and vec3[2] == 1); try expect(arr3[0] == foo3 and arr3[1] == 0 and arr3[2] == 1); - var arr4 = [4:0]u24{ foo3, foo2, 0, 1 }; - var vec4: @Vector(4, u24) = arr4; + const arr4 = [4:0]u24{ foo3, foo2, 0, 1 }; + const vec4: @Vector(4, u24) = arr4; try expect(vec4[0] == foo3 and vec4[1] == foo2 and vec4[2] == 0 and vec4[3] == 1); } }; @@ -217,8 +227,9 @@ test "array to vector with element type coercion" { const S = struct { fn doTheTest() !void { var foo: f16 = 3.14; - var arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 }; - var vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 }; + _ = &foo; + const arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 }; + const vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 }; try std.testing.expect(std.mem.eql(f32, &@as([4]f32, vec), &arr32)); } }; @@ -237,7 +248,8 @@ test "peer type resolution with coercible element types" { var b: @Vector(2, u8) = .{ 1, 2 }; var a: @Vector(2, u16) = .{ 2, 1 }; var t: bool = true; - var c = if (t) a else b; + _ = .{ &a, &b, &t }; + const c = if (t) a else b; try std.testing.expect(@TypeOf(c) == @Vector(2, u16)); } }; @@ -285,22 +297,26 @@ test "vector casts of sizes not divisible by 8" { fn doTheTest() !void { { var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; - var x: [4]u3 = v; + _ = &v; + const x: [4]u3 = v; try expect(mem.eql(u3, &x, &@as([4]u3, v))); } { var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; - var x: [4]u2 = v; + _ = &v; + const x: [4]u2 = v; try expect(mem.eql(u2, &x, &@as([4]u2, v))); } { var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; - var x: [4]u1 = v; + _ = &v; + const x: [4]u1 = v; try expect(mem.eql(u1, &x, &@as([4]u1, v))); } { var v: @Vector(4, bool) = [4]bool{ false, false, true, false }; - var x: [4]bool = v; + _ = &v; + const x: [4]bool = v; try expect(mem.eql(bool, &x, &@as([4]bool, v))); } } @@ -327,7 +343,8 @@ test "vector @splat" { fn testForT(comptime N: comptime_int, v: anytype) !void { const T = @TypeOf(v); var vec: @Vector(N, T) = @splat(v); - var as_array = @as([N]T, vec); + _ = &vec; + const as_array = @as([N]T, vec); for (as_array) |elem| try expect(v == elem); } fn doTheTest() !void { @@ -412,6 +429,7 @@ test "load vector elements via runtime index" { const S = struct { fn doTheTest() !void { var v: @Vector(4, i32) = [_]i32{ 1, 2, 3, undefined }; + _ = &v; var i: u32 = 0; try expect(v[i] == 1); i += 1; @@ -461,7 +479,7 @@ test "initialize vector which is a struct field" { var foo = Vec4Obj{ .data = [_]f32{ 1, 2, 3, 4 }, }; - _ = foo; + _ = &foo; } }; try S.doTheTest(); @@ -481,6 +499,7 @@ test "vector comparison operators" { const V = @Vector(4, bool); var v1: V = [_]bool{ true, false, true, false }; var v2: V = [_]bool{ false, true, false, true }; + _ = .{ &v1, &v2 }; try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v1))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v2))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v2))); @@ -491,6 +510,7 @@ test "vector comparison operators" { var v1: @Vector(4, u32) = @splat(0xc0ffeeee); var v2: @Vector(4, c_uint) = v1; var v3: @Vector(4, u32) = @splat(0xdeadbeef); + _ = .{ &v1, &v2, &v3 }; try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v2))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v3))); try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v3))); @@ -499,6 +519,7 @@ test "vector comparison operators" { { // Comptime-known LHS/RHS var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 }; + _ = &v1; const v2: @Vector(4, u32) = @splat(2); const v3: @Vector(4, bool) = [_]bool{ true, false, true, false }; try expect(mem.eql(bool, &@as([4]bool, v3), &@as([4]bool, v1 == v2))); @@ -604,7 +625,7 @@ test "vector bitwise not operator" { const S = struct { fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void { - var y = ~x; + const y = ~x; for (@as([4]T, y), 0..) |v, i| { try expect(~x[i] == v); } @@ -640,14 +661,14 @@ test "vector shift operators" { const TX = @typeInfo(@TypeOf(x)).Array.child; const TY = @typeInfo(@TypeOf(y)).Array.child; - var xv = @as(@Vector(N, TX), x); - var yv = @as(@Vector(N, TY), y); + const xv = @as(@Vector(N, TX), x); + const yv = @as(@Vector(N, TY), y); - var z0 = xv >> yv; + const z0 = xv >> yv; for (@as([N]TX, z0), 0..) |v, i| { try expect(x[i] >> y[i] == v); } - var z1 = xv << yv; + const z1 = xv << yv; for (@as([N]TX, z1), 0..) |v, i| { try expect(x[i] << y[i] == v); } @@ -657,10 +678,10 @@ test "vector shift operators" { const TX = @typeInfo(@TypeOf(x)).Array.child; const TY = @typeInfo(@TypeOf(y)).Array.child; - var xv = @as(@Vector(N, TX), x); - var yv = @as(@Vector(N, TY), y); + const xv = @as(@Vector(N, TX), x); + const yv = @as(@Vector(N, TY), y); - var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv); + const z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv); for (@as([N]TX, z), 0..) |v, i| { const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i]; try expect(check == v); @@ -734,7 +755,7 @@ test "vector reduce operation" { const N = @typeInfo(@TypeOf(x)).Array.len; const TX = @typeInfo(@TypeOf(x)).Array.child; - var r = @reduce(op, @as(@Vector(N, TX), x)); + const r = @reduce(op, @as(@Vector(N, TX), x)); switch (@typeInfo(TX)) { .Int, .Bool => try expect(expected == r), .Float => { @@ -892,7 +913,8 @@ test "mask parameter of @shuffle is comptime scope" { const __v4hi = @Vector(4, i16); var v4_a = __v4hi{ 0, 0, 0, 0 }; var v4_b = __v4hi{ 0, 0, 0, 0 }; - var shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){ + _ = .{ &v4_a, &v4_b }; + const shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){ std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len), @@ -915,7 +937,8 @@ test "saturating add" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 255, 254, 1 }; var rhs = u8x3{ 1, 2, 255 }; - var result = lhs +| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs +| rhs; const expected = u8x3{ 255, 255, 255 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -923,7 +946,8 @@ test "saturating add" { const i8x3 = @Vector(3, i8); var lhs = i8x3{ 127, 126, 1 }; var rhs = i8x3{ 1, 2, 127 }; - var result = lhs +| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs +| rhs; const expected = i8x3{ 127, 127, 127 }; try expect(mem.eql(i8, &@as([3]i8, expected), &@as([3]i8, result))); } @@ -947,7 +971,8 @@ test "saturating subtraction" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 0, 0, 0 }; var rhs = u8x3{ 255, 255, 255 }; - var result = lhs -| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs -| rhs; const expected = u8x3{ 0, 0, 0 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -973,7 +998,8 @@ test "saturating multiplication" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 2, 2, 2 }; var rhs = u8x3{ 255, 255, 255 }; - var result = lhs *| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs *| rhs; const expected = u8x3{ 255, 255, 255 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -997,7 +1023,8 @@ test "saturating shift-left" { const u8x3 = @Vector(3, u8); var lhs = u8x3{ 1, 1, 1 }; var rhs = u8x3{ 255, 255, 255 }; - var result = lhs <<| rhs; + _ = .{ &lhs, &rhs }; + const result = lhs <<| rhs; const expected = u8x3{ 255, 255, 255 }; try expect(mem.eql(u8, &@as([3]u8, expected), &@as([3]u8, result))); } @@ -1040,29 +1067,33 @@ test "@addWithOverflow" { { var lhs = @Vector(4, u8){ 250, 250, 250, 250 }; var rhs = @Vector(4, u8){ 0, 5, 6, 10 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, i8){ -125, -125, 125, 125 }; var rhs = @Vector(4, i8){ -3, -4, 2, 3 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, u1){ 0, 0, 1, 1 }; var rhs = @Vector(4, u1){ 0, 1, 0, 1 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 0, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, u0){ 0, 0, 0, 0 }; var rhs = @Vector(4, u0){ 0, 0, 0, 0 }; - var overflow = @addWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 0, 0 }; + _ = .{ &lhs, &rhs }; + const overflow = @addWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 0, 0 }; try expectEqual(expected, overflow); } } @@ -1084,15 +1115,17 @@ test "@subWithOverflow" { { var lhs = @Vector(2, u8){ 5, 5 }; var rhs = @Vector(2, u8){ 5, 6 }; - var overflow = @subWithOverflow(lhs, rhs)[1]; - var expected: @Vector(2, u1) = .{ 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @subWithOverflow(lhs, rhs)[1]; + const expected: @Vector(2, u1) = .{ 0, 1 }; try expectEqual(expected, overflow); } { var lhs = @Vector(4, i8){ -120, -120, 120, 120 }; var rhs = @Vector(4, i8){ 8, 9, -7, -8 }; - var overflow = @subWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @subWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; try expectEqual(expected, overflow); } } @@ -1113,8 +1146,9 @@ test "@mulWithOverflow" { fn doTheTest() !void { var lhs = @Vector(4, u8){ 10, 10, 10, 10 }; var rhs = @Vector(4, u8){ 25, 26, 0, 30 }; - var overflow = @mulWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @mulWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 1, 0, 1 }; try expectEqual(expected, overflow); } }; @@ -1134,8 +1168,9 @@ test "@shlWithOverflow" { fn doTheTest() !void { var lhs = @Vector(4, u8){ 0, 1, 8, 255 }; var rhs = @Vector(4, u3){ 7, 7, 7, 7 }; - var overflow = @shlWithOverflow(lhs, rhs)[1]; - var expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; + _ = .{ &lhs, &rhs }; + const overflow = @shlWithOverflow(lhs, rhs)[1]; + const expected: @Vector(4, u1) = .{ 0, 0, 1, 1 }; try expectEqual(expected, overflow); } }; @@ -1161,8 +1196,8 @@ test "loading the second vector from a slice of vectors" { @Vector(2, u8){ 0, 1 }, @Vector(2, u8){ 2, 3 }, }; - var a: []const @Vector(2, u8) = &small_bases; - var a4 = a[1][1]; + const a: []const @Vector(2, u8) = &small_bases; + const a4 = a[1][1]; try expect(a4 == 3); } @@ -1183,6 +1218,7 @@ test "array of vectors is copied" { Vec3{ -345, -311, 381 }, Vec3{ -661, -816, -575 }, }; + _ = &points; var points2: [20]Vec3 = undefined; points2[0..points.len].* = points; try std.testing.expectEqual(points2[6], Vec3{ -345, -311, 381 }); @@ -1244,6 +1280,7 @@ test "zero multiplicand" { const zeros = @Vector(2, u32){ 0.0, 0.0 }; var ones = @Vector(2, u32){ 1.0, 1.0 }; + _ = &ones; _ = (ones * zeros)[0]; _ = (zeros * zeros)[0]; @@ -1266,6 +1303,7 @@ test "@intCast to u0" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; var zeros = @Vector(2, u32){ 0, 0 }; + _ = &zeros; const casted = @as(@Vector(2, u0), @intCast(zeros)); _ = casted[0]; @@ -1292,7 +1330,8 @@ test "array operands to shuffle are coerced to vectors" { const mask = [5]i32{ -1, 0, 1, 2, 3 }; var a = [5]u32{ 3, 5, 7, 9, 0 }; - var b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask); + _ = &a; + const b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask); try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b); } @@ -1320,6 +1359,7 @@ test "store packed vector element" { var v = @Vector(4, u1){ 1, 1, 1, 1 }; try expectEqual(@Vector(4, u1){ 1, 1, 1, 1 }, v); var index: usize = 0; + _ = &index; v[index] = 0; try expectEqual(@Vector(4, u1){ 0, 1, 1, 1 }, v); } @@ -1337,6 +1377,7 @@ test "store to vector in slice" { }; var s: []@Vector(3, f32) = &v; var i: usize = 1; + _ = &i; s[i] = s[0]; try expectEqual(v[1], v[0]); } @@ -1378,6 +1419,7 @@ test "store vector with memset" { var kc = @Vector(2, i4){ 2, 3 }; var kd = @Vector(2, u8){ 4, 5 }; var ke = @Vector(2, i9){ 6, 7 }; + _ = .{ &ka, &kb, &kc, &kd, &ke }; @memset(&a, ka); @memset(&b, kb); @memset(&c, kc); @@ -1410,6 +1452,7 @@ test "compare vectors with different element types" { var a: @Vector(2, u8) = .{ 1, 2 }; var b: @Vector(2, u9) = .{ 3, 0 }; + _ = .{ &a, &b }; try expectEqual(@Vector(2, bool){ true, false }, a < b); } @@ -1465,8 +1508,9 @@ test "bitcast to vector with different child type" { const VecB = @Vector(4, u32); var vec_a = VecA{ 1, 1, 1, 1, 1, 1, 1, 1 }; - var vec_b: VecB = @bitCast(vec_a); - var vec_c: VecA = @bitCast(vec_b); + _ = &vec_a; + const vec_b: VecB = @bitCast(vec_a); + const vec_c: VecA = @bitCast(vec_b); try expectEqual(vec_a, vec_c); } }; diff --git a/test/behavior/void.zig b/test/behavior/void.zig index 8c6269123d..42c57ca3a6 100644 --- a/test/behavior/void.zig +++ b/test/behavior/void.zig @@ -38,16 +38,18 @@ test "void optional" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO var x: ?void = {}; + _ = &x; try expect(x != null); } test "void array as a local variable initializer" { var x = [_]void{{}} ** 1004; + _ = &x[0]; _ = x[0]; } const void_constant = {}; test "reference to void constants" { var a = void_constant; - _ = a; + _ = &a; } diff --git a/test/behavior/wasm.zig b/test/behavior/wasm.zig index 11bf6cff05..c7d12be29d 100644 --- a/test/behavior/wasm.zig +++ b/test/behavior/wasm.zig @@ -4,6 +4,7 @@ const builtin = @import("builtin"); test "memory size and grow" { var prev = @wasmMemorySize(0); + _ = &prev; try expect(prev == @wasmMemoryGrow(0, 1)); try expect(prev + 1 == @wasmMemorySize(0)); } diff --git a/test/behavior/widening.zig b/test/behavior/widening.zig index f44f577dcb..3badb40169 100644 --- a/test/behavior/widening.zig +++ b/test/behavior/widening.zig @@ -15,6 +15,7 @@ test "integer widening" { var d: u64 = c; var e: u64 = d; var f: u128 = e; + _ = .{ &a, &b, &c, &d, &e, &f }; try expect(f == a); } @@ -33,6 +34,7 @@ test "implicit unsigned integer to signed integer" { var a: u8 = 250; var b: i16 = a; + _ = .{ &a, &b }; try expect(b == 250); } @@ -47,10 +49,12 @@ test "float widening" { var b: f32 = a; var c: f64 = b; var d: f128 = c; + _ = .{ &a, &b, &c, &d }; try expect(a == b); try expect(b == c); try expect(c == d); var e: f80 = c; + _ = &e; try expect(c == e); } @@ -63,6 +67,7 @@ test "float widening f16 to f128" { var x: f16 = 12.34; var y: f128 = x; + _ = .{ &x, &y }; try expect(x == y); } diff --git a/test/c_abi/main.zig b/test/c_abi/main.zig index f8aac77eb5..d845f89eee 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/cases/adding_numbers_at_runtime_and_comptime.2.zig b/test/cases/adding_numbers_at_runtime_and_comptime.2.zig index 6643d811fc..d6d8755dc3 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 43e815d621..6164e70569 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 ac9dce3079..01c4a5ca3c 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 7c464f48c9..e841299606 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 fdee492d22..2b244b194a 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 63e045c258..721a921743 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 f461bcc0af..f6a8755178 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 0ffb5e2230..d8b369764f 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 d626059e10..680d82a919 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 fcc7245ad9..aa1d62bcde 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 78c10f56b7..5b08fecc04 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 0297f1e7a4..75d78d522a 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 f0f8910e14..b3fd9fc289 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 5c9c5be68a..b6e04e609e 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 634a47fb0c..ae69df2c55 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 a20f664694..fb2741cab6 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 e6c4f5d52b..a9d62b96e3 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 621b8ead25..3e529d5e30 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 3ec79c7c53..0764dc9472 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 c10a146cf0..c0188477b8 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 c2a0ad088d..21c67e151c 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 49ef3b4d4d..176ace28db 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 404f5019be..b59de233c5 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 ecb06aa254..409a8e0f93 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 f3e51a1bed..5defb463c2 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 cee23d0540..416ba80097 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 0f06bae1dd..4bcb9bd237 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 1e66ca3776..b9e6f24a55 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 3d7bde7364..0189d0f09c 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 23e00cd057..ce28145269 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 b2da9f32d9..155df733fb 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 0aa93f48bd..405af4f235 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 1f8b097ae2..4f595a95da 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 6a7de57352..f91b6a4ef2 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 d90e53eb46..af0fb5c72e 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 4dde5860ba..b266d86ed8 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 4dac0d4fa3..4e7341bff5 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 3999140009..da00a0eeb7 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 affdb953d7..52b866afcf 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 d845dc7930..804baed45f 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 cfcbfba889..fb3488ce95 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 97bc6a09bd..b62524f6de 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 bdf7bec458..6ab99bf00d 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 90685ce566..8a5ef27d62 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 bfc22cca25..9933c95435 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 b553d492ae..912bf6ba3c 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 0641d8e3f9..cbc380c8fe 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 523ee2491a..c85eb8427d 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 3669cda3bf..3b7abe53f6 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 9955194f95..ae239d300e 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 e366e0cb03..1a7305904b 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 f73dfeb38a..e1a16be60a 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 8c0166ad2d..c072c7ef9d 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 140ddb6ed1..24a7644ce1 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 116f5a8948..502feb4326 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 9813df24db..3480dc8aa7 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 fa1fc21568..1698fdeaed 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 36a17d734b..792fd9fb0d 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 39d9474016..3d6628b799 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 ef041c9539..0fb11fc05f 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 653b7ffcfb..e9746f7e16 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 b7b40d3178..d4dda81788 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 64a97a7a5b..9813951a8b 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 7d25931aaa..2142521fd1 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 d93e8bc73d..9e6bfd8003 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 d38738dae7..465a0f466e 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 b2a7312c52..d3462ed898 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 194274a1ed..fb1e60cb3d 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 965454ef03..f4837c812e 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 391ecbdf1a..6a23da4cb6 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 54d62e6d37..55b8b1bde7 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 0eef1c3374..fe6f3c202e 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 e6753a5911..2724af3059 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 5e6a321db2..e9fb8c0066 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 40055a70b9..425eb99e9c 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 d1b22d86b7..aa3719816c 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 c0cb470eee..95ace47530 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 fda8ffe453..ace946453e 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 1ce744d6d7..6efed3eb81 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 fa12e2824c..81d0fbda1b 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 1ba03c6d50..2550c88d27 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 27e4d81e55..7c71da914d 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 69457965bb..17117713ed 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 d9f27da4aa..7fc562fd69 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 8365cdfa73..bc2cfa158d 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 c695b7393d..dbebf07e0b 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 6ba69f8d3e..5ac9ed454f 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 7dab294d4a..498a0c80b7 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 b2b73b1524..7c258adce7 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 3e1190cc32..74df2d3de9 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 733585a748..e3a13785e1 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 c0b1193fb1..515ac855ce 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 cafca1ee55..e20b2861cc 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 647b51b475..08e19cd46a 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 701241a403..aada601c79 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 fedfaf2d07..a1beac65f2 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 bb920138e1..05189c7b0c 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 fde58f69e5..9720ff90f1 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 4aa0e623c7..93eefea144 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 1fbfda9646..c7fe0d8b40 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 568c416062..4c25f9d93f 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 3ce73a9fab..a0247139ea 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 fabee524c7..995ef8d9b1 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 c730f80e6f..9a8d765c04 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 ccea6708e4..6ce431461b 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 d108903c82..4fa396190a 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 78261f182f..d30db5733d 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 da4503cefe..a8d4675ac8 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 5e5b57680c..617e638627 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 ecdc6c14c9..ed3c402ef9 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 b51635ad30..3738f89492 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 2f7686c93d..28d3c2445e 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 dc6f715c2f..caadf6c5d9 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 821a0a8c69..169a69a75a 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 33b5d1f3b6..4f80b61865 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 55af9c1185..26b31dd506 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 eceb5db50e..21991c66eb 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 cddd91384b..2b3738cd2f 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 7724632069..d6bf372a88 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 e443b3daa9..1c2a8215d7 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 000b5d1e6a..82056640fd 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 23c3917b44..c9f6c1e2e4 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 a230dd3e5b..afe3484a41 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 a5c7f041a5..95f6fa4122 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 a880b16fca..70fab8e8c1 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 2b09c722be..332fc0d895 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 2d52fca43e..5d3205e3f7 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 1e52c52609..71fcbb1892 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 3edebf7b1f..0c94bdf11e 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 d7a93edfcd..05b6855582 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 d82986a60a..e96caecfb6 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 672eea8ddc..6703ac14ca 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 ff8c96a0b6..7a3922dd1f 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 d78891bb2b..886b9687d4 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 c6566bb46a..6792be129a 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 95bba054b3..7d397c85b3 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 bffaa770ec..a1ae3f937b 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 d2182d8ad0..7cef1c7516 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 0355971cf9..23e77a08c1 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 4043f305a0..8285d344e2 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 965d8e2177..5ce8c76f4d 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 edd19bd7de..ba7b30186e 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 ca8adade01..9d22dba037 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 31f6f37815..3641b0e71c 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 1ef459421a..1e65797153 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 2e0ee4ed3b..3f54800db1 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 29934668b0..500de6bcf0 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 7064ebb1b6..0b3d02a224 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 85ffc5b4b6..9f14492b57 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 41b5b6803d..63c116b7bc 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 bdd03c8db7..51f0e458a9 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 b40c1beddd..ee04a43844 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 e67cd952d3..de460bf35c 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 3f5b71d530..29b5c7d7d1 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 821ac6c256..d2f8fc4536 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 2e69afd0a9..cab4c6bdfb 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 26d224de85..210f30a1b3 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 e97a098f40..931028dd2f 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 2c7334bedb..1e37caa556 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 dfcbf6849c..cc008ea9ee 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 67184271eb..1cecfdbada 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 e773cdb4a0..ae8dc121c6 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 ee688c362b..6b21cd2759 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 ce140b64a8..02f9a57a2b 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 e813ea1d55..4bfa1a81a2 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 e99f093c95..c2bec83afd 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 b0528e17bd..21b00ac545 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 0142f422f4..300e67827b 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 d3e747822b..fb2145b3ad 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 8d4a3fb999..eb5d5fc630 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 6fe7112aab..a49ebb4b81 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 5051dfbbe0..ec3b4c1795 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 0e57481d35..5eda780431 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 7d3a740e16..7794571353 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 9f606b0426..08c8635c0e 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 7518165e93..c1595aa67f 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 893d3c4e01..c1594d55fb 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 85fb0065d1..31fe909a4b 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 7f2c74a8a6..18c4ee8a6b 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 42c1328bb6..76da6949b1 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 3024f1dee8..9502032a93 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 4fa7691a11..e9d761b714 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 7636b501fd..70313fa5f5 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 0007ff1327..0a00ebcf14 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 f198a72efe..de305be576 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 b6de7d5bf5..967307441b 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 cf6fc141de..096cab16ad 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 c2b28f67ab..04960635a0 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 72c17929c0..b32e707ebd 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 46dc08be62..72f05b92a6 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 32aa446f9a..2ca3f0be24 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 a88393b99f..ea6f2c9fd3 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 28eaa9bad8..4538a8e269 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 b34dfa8e07..d4d64dc8ba 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 aae7370851..24f4ff9bdd 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 4f72914216..a1475fafe7 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 da2fefbad5..31a027b7c0 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 44eb58e014..6a5fafbb25 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 6b70c0eaf4..ad04f9b1a7 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 df0a2df093..341256afef 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 9020e9d5d7..206b00800e 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 index 4b0ae462d6..29ff47a5bf 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 0842e98895..d3b7e45f18 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 c52f614657..437d100c0e 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/var_never_mutated.zig b/test/cases/compile_errors/var_never_mutated.zig new file mode 100644 index 0000000000..e6594e9344 --- /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' diff --git a/test/cases/compile_errors/variable_with_type_noreturn.zig b/test/cases/compile_errors/variable_with_type_noreturn.zig index 837a6e6965..0b04e1eacb 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 2e47a4fc1e..0dd0e60ee8 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 e33f48e6a5..b3e83f202a 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 e2f81d2b5f..37f5fcb018 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 d6f142f24a..bebaffb748 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 7ca643f591..07b7c71551 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 2b64d8f906..fa3e93bfbf 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 14fb074c76..7044e0fb2a 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 054d69250c..d914ab45b5 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 76a06f3d4b..bd3d878fa7 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 2d5ba338c7..9b2dfdb58e 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 9c7c12903b..42ed310b6f 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 71c3e3521a..3e4ee60925 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 934106dd79..7679a87361 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 20afacfb68..c2dd7b9fa8 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 355698e4b6..89646e4681 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 526e1a110d..792bc88412 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 b66c7d78c0..cc61263aa7 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 d37f826272..2661e3bc19 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 bbc8dd34da..d6d121e1d6 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 96d52d1de1..0204cef926 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 16f95fdfe8..3b3e034ab2 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 e30cf58ef8..6b774ea9be 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 c64909c7fe..31a86c96e3 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 ddcd41bf16..adf0a4da4d 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 895f7e658b..3a951f9361 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 7d52fc0f17..110a9c511d 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 8a6f419f4a..2c768d6be9 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 f2df242792..5698a66dcf 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 f7e59e1c02..0d0b63f636 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 31093729ba..8afbc51f53 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 39909f93b8..9982ca9ab8 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 e602bf1c80..49841ac593 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 26e81b8909..4bba10fc36 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 b610c6d2e9..0464db3542 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 d513c10282..849914fbb5 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 3ba3d3124c..3e62c5346b 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 b97c2acf02..0cb7029237 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 1a31593058..3d7cdb3b1d 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 8c9f76e2aa..a33da87f0f 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 41cff07e32..f8c448855e 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 92e98d4777..c9ae253df7 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 afb8aa7eb8..3952ab9baa 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 a541771df1..e23cd1fcf6 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 dd3d9bd3bf..f742834d15 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 6ea136bc01..5523970168 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 cc8c01db9e..c5df2b276f 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 871e203f61..ee21b947d7 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 0cfcddbfee..70f854def5 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 a376b66fdb..6e2af616b9 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 cf2da08f0c..d87a7bf6aa 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 b5cb887c31..6ca36abccb 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 70acc5fa65..4214b5db4b 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 66298993c0..d1f4f651d3 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 a435219233..bd3313265a 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 5749be9e36..9dda4d0a9e 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 6ec47f52fb..fdf8dc17ce 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 e03974f08d..8970e06516 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 fb3f5aa307..420da72a5c 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 d89f7d4ebe..a038c0ee44 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 8107bc1738..ced81d948d 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 53e72e90fe..6346d9f1a1 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 9052913691..87c812eddc 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 71d0690b5d..2e3b4d25d5 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 ef0485ae60..83d489ab56 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 2f27bebd55..abb3cc42f0 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 eda9de20d2..dd73a50112 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 6ef049c6a1..862f2dcfdb 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 ec56953730..ae76d4dec1 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 bd35f35422..9bd4c42007 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 6f42ad5aa4..32676f7c1c 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 c553b46189..21c26eeb4e 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 4549f7c3e3..8678eccec6 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 8c2c160c68..5f8becad17 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 bc475d9800..82c0342121 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 03a8938d9e..306cf73ebf 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 b1d3cbf080..7593284301 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 558b5a1e2d..cfc064d671 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 d0c0e43f8f..f4a79fa772 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 fe503bf212..d93e1ccb47 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 24f40d8402..1506d822d1 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 e0b55db3bf..6225dda3ff 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 5f7702ef2c..823572c863 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 715a813b65..283398adbc 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 7ad8101c37..fa4f9ed26c 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; } diff --git a/test/compare_output.zig b/test/compare_output.zig index bcdc642a1e..d30b6714c9 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 29be3af0ac..465f85f9f6 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 c8265a4165..f533af37d7 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 4cbed184c3..3f5168f841 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 c45458fb21..47fe7946ec 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 50e0421e2a..57513a49c6 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 1280118173..4bb459bdac 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 be9d6da6c3..68ef6f6588 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 a57b44c757..82e1b5b171 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 e1e2c5d376..1cb8358c9d 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); } diff --git a/test/translate_c.zig b/test/translate_c.zig index 37bf7a4878..fb4ab33480 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; @@ -123,10 +126,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) {}; \\} @@ -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,24 +198,26 @@ 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, \\ .C = 0, \\ }; - \\ _ = @TypeOf(a); + \\ _ = &a; \\ { \\ const struct_Foo_1 = extern struct { \\ A: c_int = @import("std").mem.zeroes(c_int), \\ 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, \\ .C = 0, \\ }; - \\ _ = @TypeOf(a_2); + \\ _ = &a_2; \\ } \\} }); @@ -240,24 +246,26 @@ 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; + \\ _ = &Foo; \\ 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; + \\ _ = &Foo_1; \\ var a_2: Foo_1 = Foo_1{ \\ .A = @as(c_int, 0), \\ }; - \\ _ = @TypeOf(a_2); + \\ _ = &a_2; \\ } \\} }); @@ -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)); \\} }); @@ -325,7 +335,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 +354,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 +369,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; \\} }); @@ -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)); \\} , @@ -507,11 +521,12 @@ 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; \\}; , \\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,8 +744,9 @@ 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)); - \\ _ = @TypeOf(cast); + \\ _ = &cast; \\} }); @@ -764,7 +781,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 +818,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; \\} }); @@ -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); @@ -870,7 +888,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ const v2 = struct { \\ const static: [5:0]u8 = "2.2.2".*; \\ }; - \\ _ = @TypeOf(v2); + \\ _ = &v2; \\} }); @@ -912,8 +930,9 @@ 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))))); - \\ _ = @TypeOf(typed_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; @@ -1360,7 +1385,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_int = undefined; - \\ _ = @TypeOf(a); + \\ _ = &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,25 +1628,26 @@ 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))); - \\ _ = @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; \\ } \\} }); @@ -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)); @@ -1859,11 +1904,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; \\} }); @@ -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; \\} , @@ -2107,16 +2155,18 @@ 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; + \\ _ = &a_2; \\ var b_3: u8 = 123; + \\ _ = &b_3; \\ 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; \\} }); @@ -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; - \\ _ = @TypeOf(b); + \\ _ = &b; \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) { \\ var a: c_int = 2; + \\ _ = &a; \\ _ = blk: { \\ _ = blk_1: { \\ a = 6; @@ -2228,7 +2285,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ } \\ } \\ var i: u8 = 2; - \\ _ = @TypeOf(i); + \\ _ = &i; \\} }); @@ -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)); \\} }); @@ -2465,27 +2530,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\""; \\} }); @@ -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); \\ } @@ -2681,7 +2778,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn foo() c_int { \\ return blk: { \\ var a: c_int = 1; - \\ _ = @TypeOf(a); + \\ _ = &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); \\} }); @@ -2785,7 +2892,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(); \\} }); @@ -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 {} @@ -2844,14 +2955,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; \\ } \\} }); @@ -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.?(); \\} @@ -3331,7 +3464,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)); \\} , @@ -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; \\} , @@ -3471,14 +3613,16 @@ 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; + \\ _ = &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,13 +3982,15 @@ 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; - \\ _ = @TypeOf(y); + \\ _ = &y; \\ return x; \\} , \\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A) { - \\ _ = @TypeOf(B); + \\ _ = &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,9 +4084,11 @@ 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)); - \\ _ = @TypeOf(c); + \\ _ = &c; \\} }); } else { @@ -3944,9 +4101,11 @@ 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)); - \\ _ = @TypeOf(c); + \\ _ = &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; \\ }; diff --git a/tools/gen_spirv_spec.zig b/tools/gen_spirv_spec.zig index 9427451a28..18fbd5cd81 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 3bd0647b33..410c971a60 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( |
