authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-10 05:27:17+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-19 09:55:07+00:00
log51595d6b75d8ac2443a2c142c71f2a617c12fe96
tree0e3045793aa36cc8569181cc790d270c4f056806
parentbaabc6013ea4f44082e69375214e76b5d803c5cb
signaturelock-open Commit is signed but in an unrecognized format.

lib: correct unnecessary uses of 'var'


174 files changed, 738 insertions(+), 711 deletions(-)

lib/build_runner.zig+1-1
......@@ -24,7 +24,7 @@ pub fn main() !void {
2424 };
2525 const arena = thread_safe_arena.allocator();
2626
27 var args = try process.argsAlloc(arena);
27 const args = try process.argsAlloc(arena);
2828
2929 // skip my own exe name
3030 var arg_idx: usize = 1;
lib/compiler_rt/absvdi2_test.zig+1-1
......@@ -3,7 +3,7 @@ const testing = @import("std").testing;
33const __absvdi2 = @import("absvdi2.zig").__absvdi2;
44
55fn test__absvdi2(a: i64, expected: i64) !void {
6 var result = __absvdi2(a);
6 const result = __absvdi2(a);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/absvsi2_test.zig+1-1
......@@ -3,7 +3,7 @@ const testing = @import("std").testing;
33const __absvsi2 = @import("absvsi2.zig").__absvsi2;
44
55fn test__absvsi2(a: i32, expected: i32) !void {
6 var result = __absvsi2(a);
6 const result = __absvsi2(a);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/absvti2_test.zig+1-1
......@@ -3,7 +3,7 @@ const testing = @import("std").testing;
33const __absvti2 = @import("absvti2.zig").__absvti2;
44
55fn test__absvti2(a: i128, expected: i128) !void {
6 var result = __absvti2(a);
6 const result = __absvti2(a);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/addo.zig+1-1
......@@ -18,7 +18,7 @@ comptime {
1818inline fn addoXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
1919 @setRuntimeSafety(builtin.is_test);
2020 overflow.* = 0;
21 var sum: ST = a +% b;
21 const sum: ST = a +% b;
2222 // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract
2323 // Let sum = a +% b == a + b + carry == wraparound addition.
2424 // Overflow in a+b+carry occurs, iff a and b have opposite signs
lib/compiler_rt/addodi4_test.zig+2-2
......@@ -6,8 +6,8 @@ const math = std.math;
66fn test__addodi4(a: i64, b: i64) !void {
77 var result_ov: c_int = undefined;
88 var expected_ov: c_int = undefined;
9 var result = addv.__addodi4(a, b, &result_ov);
10 var expected: i64 = simple_addodi4(a, b, &expected_ov);
9 const result = addv.__addodi4(a, b, &result_ov);
10 const expected: i64 = simple_addodi4(a, b, &expected_ov);
1111 try testing.expectEqual(expected, result);
1212 try testing.expectEqual(expected_ov, result_ov);
1313}
lib/compiler_rt/addosi4_test.zig+2-2
......@@ -4,8 +4,8 @@ const testing = @import("std").testing;
44fn test__addosi4(a: i32, b: i32) !void {
55 var result_ov: c_int = undefined;
66 var expected_ov: c_int = undefined;
7 var result = addv.__addosi4(a, b, &result_ov);
8 var expected: i32 = simple_addosi4(a, b, &expected_ov);
7 const result = addv.__addosi4(a, b, &result_ov);
8 const expected: i32 = simple_addosi4(a, b, &expected_ov);
99 try testing.expectEqual(expected, result);
1010 try testing.expectEqual(expected_ov, result_ov);
1111}
lib/compiler_rt/addoti4_test.zig+2-2
......@@ -6,8 +6,8 @@ const math = std.math;
66fn test__addoti4(a: i128, b: i128) !void {
77 var result_ov: c_int = undefined;
88 var expected_ov: c_int = undefined;
9 var result = addv.__addoti4(a, b, &result_ov);
10 var expected: i128 = simple_addoti4(a, b, &expected_ov);
9 const result = addv.__addoti4(a, b, &result_ov);
10 const expected: i128 = simple_addoti4(a, b, &expected_ov);
1111 try testing.expectEqual(expected, result);
1212 try testing.expectEqual(expected_ov, result_ov);
1313}
lib/compiler_rt/bswapdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");
22const testing = @import("std").testing;
33
44fn test__bswapdi2(a: u64, expected: u64) !void {
5 var result = bswap.__bswapdi2(a);
5 const result = bswap.__bswapdi2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/bswapsi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");
22const testing = @import("std").testing;
33
44fn test__bswapsi2(a: u32, expected: u32) !void {
5 var result = bswap.__bswapsi2(a);
5 const result = bswap.__bswapsi2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/bswapti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");
22const testing = @import("std").testing;
33
44fn test__bswapti2(a: u128, expected: u128) !void {
5 var result = bswap.__bswapti2(a);
5 const result = bswap.__bswapti2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/ceil.zig+1-1
......@@ -32,7 +32,7 @@ pub fn __ceilh(x: f16) callconv(.C) f16 {
3232
3333pub fn ceilf(x: f32) callconv(.C) f32 {
3434 var u: u32 = @bitCast(x);
35 var e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
35 const e = @as(i32, @intCast((u >> 23) & 0xFF)) - 0x7F;
3636 var m: u32 = undefined;
3737
3838 // TODO: Shouldn't need this explicit check.
lib/compiler_rt/clzdi2_test.zig+2-2
......@@ -2,8 +2,8 @@ const clz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__clzdi2(a: u64, expected: i64) !void {
5 var x: i64 = @bitCast(a);
6 var result = clz.__clzdi2(x);
5 const x: i64 = @bitCast(a);
6 const result = clz.__clzdi2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/clzti2_test.zig+2-2
......@@ -2,8 +2,8 @@ const clz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__clzti2(a: u128, expected: i64) !void {
5 var x: i128 = @bitCast(a);
6 var result = clz.__clzti2(x);
5 const x: i128 = @bitCast(a);
6 const result = clz.__clzti2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/cmpdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__cmpdi2(a: i64, b: i64, expected: i64) !void {
5 var result = cmp.__cmpdi2(a, b);
5 const result = cmp.__cmpdi2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/cmpsi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__cmpsi2(a: i32, b: i32, expected: i32) !void {
5 var result = cmp.__cmpsi2(a, b);
5 const result = cmp.__cmpsi2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/cmpti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__cmpti2(a: i128, b: i128, expected: i128) !void {
5 var result = cmp.__cmpti2(a, b);
5 const result = cmp.__cmpti2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/ctzdi2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzdi2(a: u64, expected: i32) !void {
5 var x: i64 = @bitCast(a);
6 var result = ctz.__ctzdi2(x);
5 const x: i64 = @bitCast(a);
6 const result = ctz.__ctzdi2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/ctzsi2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzsi2(a: u32, expected: i32) !void {
5 var x: i32 = @bitCast(a);
6 var result = ctz.__ctzsi2(x);
5 const x: i32 = @bitCast(a);
6 const result = ctz.__ctzsi2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/ctzti2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ctz = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ctzti2(a: u128, expected: i32) !void {
5 var x: i128 = @bitCast(a);
6 var result = ctz.__ctzti2(x);
5 const x: i128 = @bitCast(a);
6 const result = ctz.__ctzti2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/divc3_test.zig+20-20
......@@ -19,20 +19,20 @@ test {
1919
2020fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void {
2121 {
22 var a: T = 1.0;
23 var b: T = 0.0;
24 var c: T = -1.0;
25 var d: T = 0.0;
22 const a: T = 1.0;
23 const b: T = 0.0;
24 const c: T = -1.0;
25 const d: T = 0.0;
2626
2727 const result = f(a, b, c, d);
2828 try expect(result.real == -1.0);
2929 try expect(result.imag == 0.0);
3030 }
3131 {
32 var a: T = 1.0;
33 var b: T = 0.0;
34 var c: T = -4.0;
35 var d: T = 0.0;
32 const a: T = 1.0;
33 const b: T = 0.0;
34 const c: T = -4.0;
35 const d: T = 0.0;
3636
3737 const result = f(a, b, c, d);
3838 try expect(result.real == -0.25);
......@@ -41,10 +41,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
4141 {
4242 // if the first operand is an infinity and the second operand is a finite number, then the
4343 // result of the / operator is an infinity;
44 var a: T = -math.inf(T);
45 var b: T = 0.0;
46 var c: T = -4.0;
47 var d: T = 1.0;
44 const a: T = -math.inf(T);
45 const b: T = 0.0;
46 const c: T = -4.0;
47 const d: T = 1.0;
4848
4949 const result = f(a, b, c, d);
5050 try expect(result.real == math.inf(T));
......@@ -53,10 +53,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
5353 {
5454 // if the first operand is a finite number and the second operand is an infinity, then the
5555 // result of the / operator is a zero;
56 var a: T = 17.2;
57 var b: T = 0.0;
58 var c: T = -math.inf(T);
59 var d: T = 0.0;
56 const a: T = 17.2;
57 const b: T = 0.0;
58 const c: T = -math.inf(T);
59 const d: T = 0.0;
6060
6161 const result = f(a, b, c, d);
6262 try expect(result.real == -0.0);
......@@ -65,10 +65,10 @@ fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
6565 {
6666 // if the first operand is a nonzero finite number or an infinity and the second operand is
6767 // a zero, then the result of the / operator is an infinity
68 var a: T = 1.1;
69 var b: T = 0.1;
70 var c: T = 0.0;
71 var d: T = 0.0;
68 const a: T = 1.1;
69 const b: T = 0.1;
70 const c: T = 0.0;
71 const d: T = 0.0;
7272
7373 const result = f(a, b, c, d);
7474 try expect(result.real == math.inf(T));
lib/compiler_rt/divxf3.zig+2-2
......@@ -162,7 +162,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
162162 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
163163 // Right shift the quotient if it falls in the [1,2) range and adjust the
164164 // exponent accordingly.
165 var quotient: u64 = if (quotient128 < (integerBit << 1)) b: {
165 const quotient: u64 = if (quotient128 < (integerBit << 1)) b: {
166166 quotientExponent -= 1;
167167 break :b @intCast(quotient128);
168168 } else @intCast(quotient128 >> 1);
......@@ -177,7 +177,7 @@ pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
177177 //
178178 // If r is greater than 1/2 ulp(q)*b, then q rounds up. Otherwise, we
179179 // already have the correct result. The exact halfway case cannot occur.
180 var residual: u64 = -%(quotient *% q63b);
180 const residual: u64 = -%(quotient *% q63b);
181181
182182 const writtenExponent = quotientExponent + exponentBias;
183183 if (writtenExponent >= maxExponent) {
lib/compiler_rt/emutls.zig+11-11
......@@ -57,8 +57,8 @@ const simple_allocator = struct {
5757
5858 /// Resize a slice.
5959 pub fn reallocSlice(comptime T: type, slice: []T, len: usize) []T {
60 var c_ptr: *anyopaque = @ptrCast(slice.ptr);
61 var new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort()));
60 const c_ptr: *anyopaque = @ptrCast(slice.ptr);
61 const new_array: [*]T = @ptrCast(@alignCast(std.c.realloc(c_ptr, @sizeOf(T) * len) orelse abort()));
6262 return new_array[0..len];
6363 }
6464
......@@ -78,7 +78,7 @@ const ObjectArray = struct {
7878
7979 /// create a new ObjectArray with n slots. must call deinit() to deallocate.
8080 pub fn init(n: usize) *ObjectArray {
81 var array = simple_allocator.alloc(ObjectArray);
81 const array = simple_allocator.alloc(ObjectArray);
8282
8383 array.* = ObjectArray{
8484 .slots = simple_allocator.allocSlice(?ObjectPointer, n),
......@@ -166,7 +166,7 @@ const current_thread_storage = struct {
166166 const size = @max(16, index);
167167
168168 // create a new array and store it.
169 var array: *ObjectArray = ObjectArray.init(size);
169 const array: *ObjectArray = ObjectArray.init(size);
170170 current_thread_storage.setspecific(array);
171171 return array;
172172 }
......@@ -304,13 +304,13 @@ const emutls_control = extern struct {
304304test "simple_allocator" {
305305 if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;
306306
307 var data1: *[64]u8 = simple_allocator.alloc([64]u8);
307 const data1: *[64]u8 = simple_allocator.alloc([64]u8);
308308 defer simple_allocator.free(data1);
309309 for (data1) |*c| {
310310 c.* = 0xff;
311311 }
312312
313 var data2: [*]u8 = simple_allocator.advancedAlloc(@alignOf(u8), 64);
313 const data2: [*]u8 = simple_allocator.advancedAlloc(@alignOf(u8), 64);
314314 defer simple_allocator.free(data2);
315315 for (data2[0..63]) |*c| {
316316 c.* = 0xff;
......@@ -324,7 +324,7 @@ test "__emutls_get_address zeroed" {
324324 try expect(ctl.object.index == 0);
325325
326326 // retrieve a variable from ctl
327 var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
327 const x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
328328 try expect(ctl.object.index != 0); // index has been allocated for this ctl
329329 try expect(x.* == 0); // storage has been zeroed
330330
......@@ -332,7 +332,7 @@ test "__emutls_get_address zeroed" {
332332 x.* = 1234;
333333
334334 // retrieve a variable from ctl (same ctl)
335 var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
335 const y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
336336
337337 try expect(y.* == 1234); // same content that x.*
338338 try expect(x == y); // same pointer
......@@ -345,7 +345,7 @@ test "__emutls_get_address with default_value" {
345345 var ctl = emutls_control.init(usize, &value);
346346 try expect(ctl.object.index == 0);
347347
348 var x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
348 const x: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
349349 try expect(ctl.object.index != 0);
350350 try expect(x.* == 5678); // storage initialized with default value
351351
......@@ -354,7 +354,7 @@ test "__emutls_get_address with default_value" {
354354
355355 try expect(value == 5678); // the default value didn't change
356356
357 var y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
357 const y: *usize = @ptrCast(@alignCast(__emutls_get_address(&ctl)));
358358 try expect(y.* == 9012); // the modified storage persists
359359}
360360
......@@ -364,7 +364,7 @@ test "test default_value with differents sizes" {
364364 const testType = struct {
365365 fn _testType(comptime T: type, value: T) !void {
366366 var ctl = emutls_control.init(T, &value);
367 var x = ctl.get_typed_pointer(T);
367 const x = ctl.get_typed_pointer(T);
368368 try expect(x.* == value);
369369 }
370370 }._testType;
lib/compiler_rt/exp.zig+1-1
......@@ -117,7 +117,7 @@ pub fn exp(x_: f64) callconv(.C) f64 {
117117 const P5: f64 = 4.13813679705723846039e-08;
118118
119119 var x = x_;
120 var ux: u64 = @bitCast(x);
120 const ux: u64 = @bitCast(x);
121121 var hx = ux >> 32;
122122 const sign: i32 = @intCast(hx >> 31);
123123 hx &= 0x7FFFFFFF;
lib/compiler_rt/exp2.zig+1-1
......@@ -38,7 +38,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
3838 const P3: f32 = 0x1.c6b348p-5;
3939 const P4: f32 = 0x1.3b2c9cp-7;
4040
41 var u: u32 = @bitCast(x);
41 const u: u32 = @bitCast(x);
4242 const ix = u & 0x7FFFFFFF;
4343
4444 // |x| > 126
lib/compiler_rt/ffsdi2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ffsdi2(a: u64, expected: i32) !void {
5 var x = @as(i64, @bitCast(a));
6 var result = ffs.__ffsdi2(x);
5 const x = @as(i64, @bitCast(a));
6 const result = ffs.__ffsdi2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/ffssi2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ffssi2(a: u32, expected: i32) !void {
5 var x = @as(i32, @bitCast(a));
6 var result = ffs.__ffssi2(x);
5 const x = @as(i32, @bitCast(a));
6 const result = ffs.__ffssi2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/ffsti2_test.zig+2-2
......@@ -2,8 +2,8 @@ const ffs = @import("count0bits.zig");
22const testing = @import("std").testing;
33
44fn test__ffsti2(a: u128, expected: i32) !void {
5 var x = @as(i128, @bitCast(a));
6 var result = ffs.__ffsti2(x);
5 const x = @as(i128, @bitCast(a));
6 const result = ffs.__ffsti2(x);
77 try testing.expectEqual(expected, result);
88}
99
lib/compiler_rt/float_from_int.zig+3-3
......@@ -18,12 +18,12 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
1818 const max_exp = exp_bias;
1919
2020 // Sign
21 var abs_val = if (@TypeOf(x) == comptime_int or @typeInfo(@TypeOf(x)).Int.signedness == .signed) @abs(x) else x;
21 const abs_val = if (@TypeOf(x) == comptime_int or @typeInfo(@TypeOf(x)).Int.signedness == .signed) @abs(x) else x;
2222 const sign_bit = if (x < 0) @as(uT, 1) << (float_bits - 1) else 0;
2323 var result: uT = sign_bit;
2424
2525 // Compute significand
26 var exp = int_bits - @clz(abs_val) - 1;
26 const exp = int_bits - @clz(abs_val) - 1;
2727 if (int_bits <= fractional_bits or exp <= fractional_bits) {
2828 const shift_amt = fractional_bits - @as(math.Log2Int(uT), @intCast(exp));
2929
......@@ -31,7 +31,7 @@ pub fn floatFromInt(comptime T: type, x: anytype) T {
3131 result = @as(uT, @intCast(abs_val)) << shift_amt;
3232 result ^= implicit_bit; // Remove implicit integer bit
3333 } else {
34 var shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits);
34 const shift_amt: math.Log2Int(Z) = @intCast(exp - fractional_bits);
3535 const exact_tie: bool = @ctz(abs_val) == shift_amt - 1;
3636
3737 // Shift down result and remove implicit integer bit
lib/compiler_rt/fma.zig+16-16
......@@ -59,13 +59,13 @@ pub fn fma(x: f64, y: f64, z: f64) callconv(.C) f64 {
5959 }
6060
6161 const x1 = math.frexp(x);
62 var ex = x1.exponent;
63 var xs = x1.significand;
62 const ex = x1.exponent;
63 const xs = x1.significand;
6464 const x2 = math.frexp(y);
65 var ey = x2.exponent;
66 var ys = x2.significand;
65 const ey = x2.exponent;
66 const ys = x2.significand;
6767 const x3 = math.frexp(z);
68 var ez = x3.exponent;
68 const ez = x3.exponent;
6969 var zs = x3.significand;
7070
7171 var spread = ex + ey - ez;
......@@ -118,13 +118,13 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.C) f128 {
118118 }
119119
120120 const x1 = math.frexp(x);
121 var ex = x1.exponent;
122 var xs = x1.significand;
121 const ex = x1.exponent;
122 const xs = x1.significand;
123123 const x2 = math.frexp(y);
124 var ey = x2.exponent;
125 var ys = x2.significand;
124 const ey = x2.exponent;
125 const ys = x2.significand;
126126 const x3 = math.frexp(z);
127 var ez = x3.exponent;
127 const ez = x3.exponent;
128128 var zs = x3.significand;
129129
130130 var spread = ex + ey - ez;
......@@ -181,15 +181,15 @@ fn dd_mul(a: f64, b: f64) dd {
181181 var p = a * split;
182182 var ha = a - p;
183183 ha += p;
184 var la = a - ha;
184 const la = a - ha;
185185
186186 p = b * split;
187187 var hb = b - p;
188188 hb += p;
189 var lb = b - hb;
189 const lb = b - hb;
190190
191191 p = ha * hb;
192 var q = ha * lb + la * hb;
192 const q = ha * lb + la * hb;
193193
194194 ret.hi = p + q;
195195 ret.lo = p - ret.hi + q + la * lb;
......@@ -301,15 +301,15 @@ fn dd_mul128(a: f128, b: f128) dd128 {
301301 var p = a * split;
302302 var ha = a - p;
303303 ha += p;
304 var la = a - ha;
304 const la = a - ha;
305305
306306 p = b * split;
307307 var hb = b - p;
308308 hb += p;
309 var lb = b - hb;
309 const lb = b - hb;
310310
311311 p = ha * hb;
312 var q = ha * lb + la * hb;
312 const q = ha * lb + la * hb;
313313
314314 ret.hi = p + q;
315315 ret.lo = p - ret.hi + q + la * lb;
lib/compiler_rt/fmod.zig+8-8
......@@ -81,13 +81,13 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
8181 if (expB == 0) expB = normalize(f80, &bRep);
8282
8383 var highA: u64 = 0;
84 var highB: u64 = 0;
84 const highB: u64 = 0;
8585 var lowA: u64 = @truncate(aRep);
86 var lowB: u64 = @truncate(bRep);
86 const lowB: u64 = @truncate(bRep);
8787
8888 while (expA > expB) : (expA -= 1) {
8989 var high = highA -% highB;
90 var low = lowA -% lowB;
90 const low = lowA -% lowB;
9191 if (lowA < lowB) {
9292 high -%= 1;
9393 }
......@@ -104,7 +104,7 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
104104 }
105105
106106 var high = highA -% highB;
107 var low = lowA -% lowB;
107 const low = lowA -% lowB;
108108 if (lowA < lowB) {
109109 high -%= 1;
110110 }
......@@ -194,13 +194,13 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
194194
195195 // OR in extra non-stored mantissa digit
196196 var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
197 var highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
197 const highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
198198 var lowA: u64 = aPtr_u64[low_index];
199 var lowB: u64 = bPtr_u64[low_index];
199 const lowB: u64 = bPtr_u64[low_index];
200200
201201 while (expA > expB) : (expA -= 1) {
202202 var high = highA -% highB;
203 var low = lowA -% lowB;
203 const low = lowA -% lowB;
204204 if (lowA < lowB) {
205205 high -%= 1;
206206 }
......@@ -217,7 +217,7 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
217217 }
218218
219219 var high = highA -% highB;
220 var low = lowA -% lowB;
220 const low = lowA -% lowB;
221221 if (lowA < lowB) {
222222 high -= 1;
223223 }
lib/compiler_rt/mulc3.zig+1-1
......@@ -25,7 +25,7 @@ pub inline fn mulc3(comptime T: type, a_in: T, b_in: T, c_in: T, d_in: T) Comple
2525 const zero: T = 0.0;
2626 const one: T = 1.0;
2727
28 var z = Complex(T){
28 const z: Complex(T) = .{
2929 .real = ac - bd,
3030 .imag = ad + bc,
3131 };
lib/compiler_rt/mulc3_test.zig+16-16
......@@ -19,20 +19,20 @@ test {
1919
2020fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void {
2121 {
22 var a: T = 1.0;
23 var b: T = 0.0;
24 var c: T = -1.0;
25 var d: T = 0.0;
22 const a: T = 1.0;
23 const b: T = 0.0;
24 const c: T = -1.0;
25 const d: T = 0.0;
2626
2727 const result = f(a, b, c, d);
2828 try expect(result.real == -1.0);
2929 try expect(result.imag == 0.0);
3030 }
3131 {
32 var a: T = 1.0;
33 var b: T = 0.0;
34 var c: T = -4.0;
35 var d: T = 0.0;
32 const a: T = 1.0;
33 const b: T = 0.0;
34 const c: T = -4.0;
35 const d: T = 0.0;
3636
3737 const result = f(a, b, c, d);
3838 try expect(result.real == -4.0);
......@@ -41,10 +41,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
4141 {
4242 // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,
4343 // then the result of the * operator is an infinity;
44 var a: T = math.inf(T);
45 var b: T = -math.inf(T);
46 var c: T = 1.0;
47 var d: T = 0.0;
44 const a: T = math.inf(T);
45 const b: T = -math.inf(T);
46 const c: T = 1.0;
47 const d: T = 0.0;
4848
4949 const result = f(a, b, c, d);
5050 try expect(result.real == math.inf(T));
......@@ -53,10 +53,10 @@ fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)
5353 {
5454 // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,
5555 // then the result of the * operator is an infinity;
56 var a: T = math.inf(T);
57 var b: T = -1.0;
58 var c: T = 1.0;
59 var d: T = math.inf(T);
56 const a: T = math.inf(T);
57 const b: T = -1.0;
58 const c: T = 1.0;
59 const d: T = math.inf(T);
6060
6161 const result = f(a, b, c, d);
6262 try expect(result.real == math.inf(T));
lib/compiler_rt/mulo.zig+2-2
......@@ -20,7 +20,7 @@ comptime {
2020inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
2121 overflow.* = 0;
2222 const min = math.minInt(ST);
23 var res: ST = a *% b;
23 const res: ST = a *% b;
2424 // Hacker's Delight section Overflow subsection Multiplication
2525 // case a=-2^{31}, b=-1 problem, because
2626 // on some machines a*b = -2^{31} with overflow
......@@ -41,7 +41,7 @@ inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int)
4141 };
4242 const min = math.minInt(ST);
4343 const max = math.maxInt(ST);
44 var res: EST = @as(EST, a) * @as(EST, b);
44 const res: EST = @as(EST, a) * @as(EST, b);
4545 //invariant: -2^{bitwidth(EST)} < res < 2^{bitwidth(EST)-1}
4646 if (res < min or max < res)
4747 overflow.* = 1;
lib/compiler_rt/negdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const neg = @import("negXi2.zig");
22const testing = @import("std").testing;
33
44fn test__negdi2(a: i64, expected: i64) !void {
5 var result = neg.__negdi2(a);
5 const result = neg.__negdi2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/negsi2_test.zig+1-1
......@@ -5,7 +5,7 @@ const testing = std.testing;
55const print = std.debug.print;
66
77fn test__negsi2(a: i32, expected: i32) !void {
8 var result = neg.__negsi2(a);
8 const result = neg.__negsi2(a);
99 try testing.expectEqual(expected, result);
1010}
1111
lib/compiler_rt/negti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const neg = @import("negXi2.zig");
22const testing = @import("std").testing;
33
44fn test__negti2(a: i128, expected: i128) !void {
5 var result = neg.__negti2(a);
5 const result = neg.__negti2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/negvdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const negv = @import("negv.zig");
22const testing = @import("std").testing;
33
44fn test__negvdi2(a: i64, expected: i64) !void {
5 var result = negv.__negvdi2(a);
5 const result = negv.__negvdi2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/negvsi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const negv = @import("negv.zig");
22const testing = @import("std").testing;
33
44fn test__negvsi2(a: i32, expected: i32) !void {
5 var result = negv.__negvsi2(a);
5 const result = negv.__negvsi2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/negvti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const negv = @import("negv.zig");
22const testing = @import("std").testing;
33
44fn test__negvti2(a: i128, expected: i128) !void {
5 var result = negv.__negvti2(a);
5 const result = negv.__negvti2(a);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/paritydi2_test.zig+3-3
......@@ -13,8 +13,8 @@ fn paritydi2Naive(a: i64) i32 {
1313}
1414
1515fn test__paritydi2(a: i64) !void {
16 var x = parity.__paritydi2(a);
17 var expected: i64 = paritydi2Naive(a);
16 const x = parity.__paritydi2(a);
17 const expected: i64 = paritydi2Naive(a);
1818 try testing.expectEqual(expected, x);
1919}
2020
......@@ -30,7 +30,7 @@ test "paritydi2" {
3030 var rnd = RndGen.init(42);
3131 var i: u32 = 0;
3232 while (i < 10_000) : (i += 1) {
33 var rand_num = rnd.random().int(i64);
33 const rand_num = rnd.random().int(i64);
3434 try test__paritydi2(rand_num);
3535 }
3636}
lib/compiler_rt/paritysi2_test.zig+3-3
......@@ -13,8 +13,8 @@ fn paritysi2Naive(a: i32) i32 {
1313}
1414
1515fn test__paritysi2(a: i32) !void {
16 var x = parity.__paritysi2(a);
17 var expected: i32 = paritysi2Naive(a);
16 const x = parity.__paritysi2(a);
17 const expected: i32 = paritysi2Naive(a);
1818 try testing.expectEqual(expected, x);
1919}
2020
......@@ -30,7 +30,7 @@ test "paritysi2" {
3030 var rnd = RndGen.init(42);
3131 var i: u32 = 0;
3232 while (i < 10_000) : (i += 1) {
33 var rand_num = rnd.random().int(i32);
33 const rand_num = rnd.random().int(i32);
3434 try test__paritysi2(rand_num);
3535 }
3636}
lib/compiler_rt/parityti2_test.zig+3-3
......@@ -13,8 +13,8 @@ fn parityti2Naive(a: i128) i32 {
1313}
1414
1515fn test__parityti2(a: i128) !void {
16 var x = parity.__parityti2(a);
17 var expected: i128 = parityti2Naive(a);
16 const x = parity.__parityti2(a);
17 const expected: i128 = parityti2Naive(a);
1818 try testing.expectEqual(expected, x);
1919}
2020
......@@ -30,7 +30,7 @@ test "parityti2" {
3030 var rnd = RndGen.init(42);
3131 var i: u32 = 0;
3232 while (i < 10_000) : (i += 1) {
33 var rand_num = rnd.random().int(i128);
33 const rand_num = rnd.random().int(i128);
3434 try test__parityti2(rand_num);
3535 }
3636}
lib/compiler_rt/popcountdi2_test.zig+1-1
......@@ -29,7 +29,7 @@ test "popcountdi2" {
2929 var rnd = RndGen.init(42);
3030 var i: u32 = 0;
3131 while (i < 10_000) : (i += 1) {
32 var rand_num = rnd.random().int(i64);
32 const rand_num = rnd.random().int(i64);
3333 try test__popcountdi2(rand_num);
3434 }
3535}
lib/compiler_rt/popcountsi2_test.zig+1-1
......@@ -29,7 +29,7 @@ test "popcountsi2" {
2929 var rnd = RndGen.init(42);
3030 var i: u32 = 0;
3131 while (i < 10_000) : (i += 1) {
32 var rand_num = rnd.random().int(i32);
32 const rand_num = rnd.random().int(i32);
3333 try test__popcountsi2(rand_num);
3434 }
3535}
lib/compiler_rt/popcountti2_test.zig+1-1
......@@ -29,7 +29,7 @@ test "popcountti2" {
2929 var rnd = RndGen.init(42);
3030 var i: u32 = 0;
3131 while (i < 10_000) : (i += 1) {
32 var rand_num = rnd.random().int(i128);
32 const rand_num = rnd.random().int(i128);
3333 try test__popcountti2(rand_num);
3434 }
3535}
lib/compiler_rt/powiXf2_test.zig+5-5
......@@ -9,27 +9,27 @@ const testing = std.testing;
99const math = std.math;
1010
1111fn test__powihf2(a: f16, b: i32, expected: f16) !void {
12 var result = powiXf2.__powihf2(a, b);
12 const result = powiXf2.__powihf2(a, b);
1313 try testing.expectEqual(expected, result);
1414}
1515
1616fn test__powisf2(a: f32, b: i32, expected: f32) !void {
17 var result = powiXf2.__powisf2(a, b);
17 const result = powiXf2.__powisf2(a, b);
1818 try testing.expectEqual(expected, result);
1919}
2020
2121fn test__powidf2(a: f64, b: i32, expected: f64) !void {
22 var result = powiXf2.__powidf2(a, b);
22 const result = powiXf2.__powidf2(a, b);
2323 try testing.expectEqual(expected, result);
2424}
2525
2626fn test__powitf2(a: f128, b: i32, expected: f128) !void {
27 var result = powiXf2.__powitf2(a, b);
27 const result = powiXf2.__powitf2(a, b);
2828 try testing.expectEqual(expected, result);
2929}
3030
3131fn test__powixf2(a: f80, b: i32, expected: f80) !void {
32 var result = powiXf2.__powixf2(a, b);
32 const result = powiXf2.__powixf2(a, b);
3333 try testing.expectEqual(expected, result);
3434}
3535
lib/compiler_rt/subo.zig+1-1
......@@ -27,7 +27,7 @@ pub fn __suboti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
2727
2828inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
2929 overflow.* = 0;
30 var sum: ST = a -% b;
30 const sum: ST = a -% b;
3131 // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract
3232 // Let sum = a -% b == a - b - carry == wraparound subtraction.
3333 // Overflow in a-b-carry occurs, iff a and b have opposite signs
lib/compiler_rt/subodi4_test.zig+2-2
......@@ -6,8 +6,8 @@ const math = std.math;
66fn test__subodi4(a: i64, b: i64) !void {
77 var result_ov: c_int = undefined;
88 var expected_ov: c_int = undefined;
9 var result = subo.__subodi4(a, b, &result_ov);
10 var expected: i64 = simple_subodi4(a, b, &expected_ov);
9 const result = subo.__subodi4(a, b, &result_ov);
10 const expected: i64 = simple_subodi4(a, b, &expected_ov);
1111 try testing.expectEqual(expected, result);
1212 try testing.expectEqual(expected_ov, result_ov);
1313}
lib/compiler_rt/subosi4_test.zig+2-2
......@@ -4,8 +4,8 @@ const testing = @import("std").testing;
44fn test__subosi4(a: i32, b: i32) !void {
55 var result_ov: c_int = undefined;
66 var expected_ov: c_int = undefined;
7 var result = subo.__subosi4(a, b, &result_ov);
8 var expected: i32 = simple_subosi4(a, b, &expected_ov);
7 const result = subo.__subosi4(a, b, &result_ov);
8 const expected: i32 = simple_subosi4(a, b, &expected_ov);
99 try testing.expectEqual(expected, result);
1010 try testing.expectEqual(expected_ov, result_ov);
1111}
lib/compiler_rt/suboti4_test.zig+2-2
......@@ -6,8 +6,8 @@ const math = std.math;
66fn test__suboti4(a: i128, b: i128) !void {
77 var result_ov: c_int = undefined;
88 var expected_ov: c_int = undefined;
9 var result = subo.__suboti4(a, b, &result_ov);
10 var expected: i128 = simple_suboti4(a, b, &expected_ov);
9 const result = subo.__suboti4(a, b, &result_ov);
10 const expected: i128 = simple_suboti4(a, b, &expected_ov);
1111 try testing.expectEqual(expected, result);
1212 try testing.expectEqual(expected_ov, result_ov);
1313}
lib/compiler_rt/ucmpdi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__ucmpdi2(a: u64, b: u64, expected: i32) !void {
5 var result = cmp.__ucmpdi2(a, b);
5 const result = cmp.__ucmpdi2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/ucmpsi2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__ucmpsi2(a: u32, b: u32, expected: i32) !void {
5 var result = cmp.__ucmpsi2(a, b);
5 const result = cmp.__ucmpsi2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/ucmpti2_test.zig+1-1
......@@ -2,7 +2,7 @@ const cmp = @import("cmp.zig");
22const testing = @import("std").testing;
33
44fn test__ucmpti2(a: u128, b: u128, expected: i32) !void {
5 var result = cmp.__ucmpti2(a, b);
5 const result = cmp.__ucmpti2(a, b);
66 try testing.expectEqual(expected, result);
77}
88
lib/compiler_rt/udivmod.zig+4-4
......@@ -52,7 +52,7 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T {
5252 if (rhat >= b) break;
5353 }
5454
55 var un21 = un64 *% b +% un1 -% q1 *% v;
55 const un21 = un64 *% b +% un1 -% q1 *% v;
5656
5757 // Compute the second quotient digit
5858 var q0 = un21 / vn1;
......@@ -101,8 +101,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
101101 return 0;
102102 }
103103
104 var a: [2]HalfT = @bitCast(a_);
105 var b: [2]HalfT = @bitCast(b_);
104 const a: [2]HalfT = @bitCast(a_);
105 const b: [2]HalfT = @bitCast(b_);
106106 var q: [2]HalfT = undefined;
107107 var r: [2]HalfT = undefined;
108108
......@@ -125,7 +125,7 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
125125 }
126126
127127 // 0 <= shift <= 63
128 var shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]);
128 const shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]);
129129 var af: T = @bitCast(a);
130130 var bf = @as(T, @bitCast(b)) << shift;
131131 q = @bitCast(@as(T, 0));
lib/compiler_rt/udivmodei4.zig+2-2
......@@ -116,7 +116,7 @@ pub fn __udivei4(r_q: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize)
116116 @setRuntimeSafety(builtin.is_test);
117117 const u = u_p[0 .. bits / 32];
118118 const v = v_p[0 .. bits / 32];
119 var q = r_q[0 .. bits / 32];
119 const q = r_q[0 .. bits / 32];
120120 @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable;
121121}
122122
......@@ -124,7 +124,7 @@ pub fn __umodei4(r_p: [*]u32, u_p: [*]const u32, v_p: [*]const u32, bits: usize)
124124 @setRuntimeSafety(builtin.is_test);
125125 const u = u_p[0 .. bits / 32];
126126 const v = v_p[0 .. bits / 32];
127 var r = r_p[0 .. bits / 32];
127 const r = r_p[0 .. bits / 32];
128128 @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable;
129129}
130130
lib/std/Build/Cache.zig+1-1
......@@ -141,7 +141,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath {
141141 var i: u8 = 1; // Start at 1 to skip over checking the null prefix.
142142 while (i < prefixes_slice.len) : (i += 1) {
143143 const p = prefixes_slice[i].path.?;
144 var sub_path = getPrefixSubpath(gpa, p, resolved_path) catch |err| switch (err) {
144 const sub_path = getPrefixSubpath(gpa, p, resolved_path) catch |err| switch (err) {
145145 error.NotASubPath => continue,
146146 else => |e| return e,
147147 };
lib/std/Build/Cache/DepTokenizer.zig+3-3
......@@ -950,7 +950,7 @@ fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void {
950950
951951fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {
952952 var buf: [80]u8 = undefined;
953 var text = try std.fmt.bufPrint(buf[0..], "{s} {d} bytes ", .{ label, bytes.len });
953 const text = try std.fmt.bufPrint(buf[0..], "{s} {d} bytes ", .{ label, bytes.len });
954954 try out.writeAll(text);
955955 var i: usize = text.len;
956956 const end = 79;
......@@ -983,12 +983,12 @@ fn hexDump(out: anytype, bytes: []const u8) !void {
983983 try printDecValue(out, offset, 8);
984984 try out.writeAll(":");
985985 try out.writeAll(" ");
986 var end1 = @min(offset + n, offset + 8);
986 const end1 = @min(offset + n, offset + 8);
987987 for (bytes[offset..end1]) |b| {
988988 try out.writeAll(" ");
989989 try printHexValue(out, b, 2);
990990 }
991 var end2 = offset + n;
991 const end2 = offset + n;
992992 if (end2 > end1) {
993993 try out.writeAll(" ");
994994 for (bytes[end1..end2]) |b| {
lib/std/Build/Step/CheckObject.zig+1-1
......@@ -293,7 +293,7 @@ const Check = struct {
293293
294294/// Creates a new empty sequence of actions.
295295pub fn checkStart(self: *CheckObject) void {
296 var new_check = Check.create(self.step.owner.allocator);
296 const new_check = Check.create(self.step.owner.allocator);
297297 self.checks.append(new_check) catch @panic("OOM");
298298}
299299
lib/std/Build/Step/ConfigHeader.zig+2-2
......@@ -307,8 +307,8 @@ fn render_cmake(
307307 values: std.StringArrayHashMap(Value),
308308 src_path: []const u8,
309309) !void {
310 var build = step.owner;
311 var allocator = build.allocator;
310 const build = step.owner;
311 const allocator = build.allocator;
312312
313313 var values_copy = try values.clone();
314314 defer values_copy.deinit();
lib/std/Build/Step/Run.zig+1-1
......@@ -301,7 +301,7 @@ pub fn addPathDir(self: *Run, search_path: []const u8) void {
301301 const env_map = getEnvMapInternal(self);
302302
303303 const key = "PATH";
304 var prev_path = env_map.get(key);
304 const prev_path = env_map.get(key);
305305
306306 if (prev_path) |pp| {
307307 const new_path = b.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path });
lib/std/Progress.zig+1
......@@ -397,6 +397,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any
397397
398398test "basic functionality" {
399399 var disable = true;
400 _ = &disable;
400401 if (disable) {
401402 // This test is disabled because it uses time.sleep() and is therefore slow. It also
402403 // prints bogus progress data to stderr.
lib/std/Thread/WaitGroup.zig+1-1
......@@ -25,7 +25,7 @@ pub fn finish(self: *WaitGroup) void {
2525}
2626
2727pub fn wait(self: *WaitGroup) void {
28 var state = self.state.fetchAdd(is_waiting, .Acquire);
28 const state = self.state.fetchAdd(is_waiting, .Acquire);
2929 assert(state & is_waiting == 0);
3030
3131 if ((state / one_pending) > 0) {
lib/std/array_hash_map.zig+3-3
......@@ -2076,11 +2076,11 @@ test "iterator hash map" {
20762076 try reset_map.putNoClobber(1, 22);
20772077 try reset_map.putNoClobber(2, 33);
20782078
2079 var keys = [_]i32{
2079 const keys = [_]i32{
20802080 0, 2, 1,
20812081 };
20822082
2083 var values = [_]i32{
2083 const values = [_]i32{
20842084 11, 33, 22,
20852085 };
20862086
......@@ -2116,7 +2116,7 @@ test "iterator hash map" {
21162116 }
21172117
21182118 it.reset();
2119 var entry = it.next().?;
2119 const entry = it.next().?;
21202120 try testing.expect(entry.key_ptr.* == first_entry.key_ptr.*);
21212121 try testing.expect(entry.value_ptr.* == first_entry.value_ptr.*);
21222122}
lib/std/array_list.zig+2-2
......@@ -979,7 +979,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
979979 pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
980980 if (self.capacity >= new_capacity) return;
981981
982 var better_capacity = growCapacity(self.capacity, new_capacity);
982 const better_capacity = growCapacity(self.capacity, new_capacity);
983983 return self.ensureTotalCapacityPrecise(allocator, better_capacity);
984984 }
985985
......@@ -1159,7 +1159,7 @@ test "std.ArrayList/ArrayListUnmanaged.init" {
11591159 }
11601160
11611161 {
1162 var list = ArrayListUnmanaged(i32){};
1162 const list = ArrayListUnmanaged(i32){};
11631163
11641164 try testing.expect(list.items.len == 0);
11651165 try testing.expect(list.capacity == 0);
lib/std/atomic/Atomic.zig+1-1
......@@ -125,7 +125,7 @@ pub fn Atomic(comptime T: type) type {
125125 @compileError(@tagName(Ordering.Unordered) ++ " is only allowed on atomic loads and stores");
126126 }
127127
128 comptime var success_is_stronger = switch (failure) {
128 const success_is_stronger = switch (failure) {
129129 .SeqCst => success == .SeqCst,
130130 .AcqRel => @compileError(@tagName(failure) ++ " implies " ++ @tagName(Ordering.Release) ++ " which is only allowed on success"),
131131 .Acquire => success == .SeqCst or success == .AcqRel or success == .Acquire,
lib/std/atomic/queue.zig+2-2
......@@ -175,11 +175,11 @@ const puts_per_thread = 500;
175175const put_thread_count = 3;
176176
177177test "std.atomic.Queue" {
178 var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);
178 const plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);
179179 defer std.heap.page_allocator.free(plenty_of_memory);
180180
181181 var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory);
182 var a = fixed_buffer_allocator.threadSafeAllocator();
182 const a = fixed_buffer_allocator.threadSafeAllocator();
183183
184184 var queue = Queue(i32).init();
185185 var context = Context{
lib/std/atomic/stack.zig+2-2
......@@ -85,11 +85,11 @@ const puts_per_thread = 500;
8585const put_thread_count = 3;
8686
8787test "std.atomic.stack" {
88 var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);
88 const plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024);
8989 defer std.heap.page_allocator.free(plenty_of_memory);
9090
9191 var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory);
92 var a = fixed_buffer_allocator.threadSafeAllocator();
92 const a = fixed_buffer_allocator.threadSafeAllocator();
9393
9494 var stack = Stack(i32).init();
9595 var context = Context{
lib/std/base64.zig+11-11
......@@ -239,7 +239,7 @@ pub const Base64Decoder = struct {
239239 if ((bits & invalid_char_tst) != 0) return error.InvalidCharacter;
240240 std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .little);
241241 }
242 var remaining = source[fast_src_idx..];
242 const remaining = source[fast_src_idx..];
243243 for (remaining, fast_src_idx..) |c, src_idx| {
244244 const d = decoder.char_to_index[c];
245245 if (d == invalid_char) {
......@@ -259,7 +259,7 @@ pub const Base64Decoder = struct {
259259 return error.InvalidPadding;
260260 }
261261 if (leftover_idx == null) return;
262 var leftover = source[leftover_idx.?..];
262 const leftover = source[leftover_idx.?..];
263263 if (decoder.pad_char) |pad_char| {
264264 const padding_len = acc_len / 2;
265265 var padding_chars: usize = 0;
......@@ -338,7 +338,7 @@ pub const Base64DecoderWithIgnore = struct {
338338 if (decoder.pad_char != null and padding_len != 0) return error.InvalidPadding;
339339 return dest_idx;
340340 }
341 var leftover = source[leftover_idx.?..];
341 const leftover = source[leftover_idx.?..];
342342 if (decoder.pad_char) |pad_char| {
343343 var padding_chars: usize = 0;
344344 for (leftover) |c| {
......@@ -483,7 +483,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
483483 // Base64Decoder
484484 {
485485 var buffer: [0x100]u8 = undefined;
486 var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];
486 const decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];
487487 try codecs.Decoder.decode(decoded, expected_encoded);
488488 try testing.expectEqualSlices(u8, expected_decoded, decoded);
489489 }
......@@ -492,8 +492,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
492492 {
493493 const decoder_ignore_nothing = codecs.decoderWithIgnore("");
494494 var buffer: [0x100]u8 = undefined;
495 var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
496 var written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
495 const decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
496 const written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
497497 try testing.expect(written <= decoded.len);
498498 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
499499 }
......@@ -502,8 +502,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
502502fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void {
503503 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
504504 var buffer: [0x100]u8 = undefined;
505 var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
506 var written = try decoder_ignore_space.decode(decoded, encoded);
505 const decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
506 const written = try decoder_ignore_space.decode(decoded, encoded);
507507 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
508508}
509509
......@@ -511,7 +511,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void
511511 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
512512 var buffer: [0x100]u8 = undefined;
513513 if (codecs.Decoder.calcSizeForSlice(encoded)) |decoded_size| {
514 var decoded = buffer[0..decoded_size];
514 const decoded = buffer[0..decoded_size];
515515 if (codecs.Decoder.decode(decoded, encoded)) |_| {
516516 return error.ExpectedError;
517517 } else |err| if (err != expected_err) return err;
......@@ -525,7 +525,7 @@ fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void
525525fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {
526526 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
527527 var buffer: [0x100]u8 = undefined;
528 var decoded = buffer[0 .. (try codecs.Decoder.calcSizeForSlice(encoded)) - 1];
528 const decoded = buffer[0 .. (try codecs.Decoder.calcSizeForSlice(encoded)) - 1];
529529 if (decoder_ignore_space.decode(decoded, encoded)) |_| {
530530 return error.ExpectedError;
531531 } else |err| if (err != error.NoSpaceLeft) return err;
......@@ -534,7 +534,7 @@ fn testNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {
534534fn testFourBytesDestNoSpaceLeftError(codecs: Codecs, encoded: []const u8) !void {
535535 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
536536 var buffer: [0x100]u8 = undefined;
537 var decoded = buffer[0..4];
537 const decoded = buffer[0..4];
538538 if (decoder_ignore_space.decode(decoded, encoded)) |_| {
539539 return error.ExpectedError;
540540 } else |err| if (err != error.NoSpaceLeft) return err;
lib/std/buf_map.zig+1-2
......@@ -15,8 +15,7 @@ pub const BufMap = struct {
1515 /// That allocator will be used for both backing allocations
1616 /// and string deduplication.
1717 pub fn init(allocator: Allocator) BufMap {
18 var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) };
19 return self;
18 return .{ .hash_map = BufMapHashMap.init(allocator) };
2019 }
2120
2221 /// Free the backing storage of the map, as well as all
lib/std/buf_set.zig+4-5
......@@ -17,8 +17,7 @@ pub const BufSet = struct {
1717 /// be used internally for both backing allocations and
1818 /// string duplication.
1919 pub fn init(a: Allocator) BufSet {
20 var self = BufSet{ .hash_map = BufSetHashMap.init(a) };
21 return self;
20 return .{ .hash_map = BufSetHashMap.init(a) };
2221 }
2322
2423 /// Free a BufSet along with all stored keys.
......@@ -76,8 +75,8 @@ pub const BufSet = struct {
7675 self: *const BufSet,
7776 new_allocator: Allocator,
7877 ) Allocator.Error!BufSet {
79 var cloned_hashmap = try self.hash_map.cloneWithAllocator(new_allocator);
80 var cloned = BufSet{ .hash_map = cloned_hashmap };
78 const cloned_hashmap = try self.hash_map.cloneWithAllocator(new_allocator);
79 const cloned = BufSet{ .hash_map = cloned_hashmap };
8180 var it = cloned.hash_map.keyIterator();
8281 while (it.next()) |key_ptr| {
8382 key_ptr.* = try cloned.copy(key_ptr.*);
......@@ -134,7 +133,7 @@ test "BufSet clone" {
134133}
135134
136135test "BufSet.clone with arena" {
137 var allocator = std.testing.allocator;
136 const allocator = std.testing.allocator;
138137 var arena = std.heap.ArenaAllocator.init(allocator);
139138 defer arena.deinit();
140139
lib/std/builtin.zig+3-4
......@@ -777,9 +777,8 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr
777777 }
778778
779779 var fmt: [256]u8 = undefined;
780 var slice = try std.fmt.bufPrint(&fmt, "\r\nerr: {s}\r\n", .{exit_msg});
781
782 var len = try std.unicode.utf8ToUtf16Le(utf16, slice);
780 const slice = try std.fmt.bufPrint(&fmt, "\r\nerr: {s}\r\n", .{exit_msg});
781 const len = try std.unicode.utf8ToUtf16Le(utf16, slice);
783782
784783 utf16[len] = 0;
785784
......@@ -790,7 +789,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr
790789 };
791790
792791 var exit_size: usize = 0;
793 var exit_data = ExitData.create_exit_data(msg, &exit_size) catch null;
792 const exit_data = ExitData.create_exit_data(msg, &exit_size) catch null;
794793
795794 if (exit_data) |data| {
796795 if (uefi.system_table.std_err) |out| {
lib/std/child_process.zig+1-1
......@@ -847,7 +847,7 @@ pub const ChildProcess = struct {
847847 }
848848
849849 windowsCreateProcessPathExt(self.allocator, &dir_buf, &app_buf, PATHEXT, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {
850 var original_err = switch (no_path_err) {
850 const original_err = switch (no_path_err) {
851851 error.FileNotFound, error.InvalidExe, error.AccessDenied => |e| e,
852852 error.UnrecoverableInvalidExe => return error.InvalidExe,
853853 else => |e| return e,
lib/std/coff.zig+1-1
......@@ -1075,7 +1075,7 @@ pub const Coff = struct {
10751075 var stream = std.io.fixedBufferStream(data);
10761076 const reader = stream.reader();
10771077 try stream.seekTo(pe_pointer_offset);
1078 var coff_header_offset = try reader.readInt(u32, .little);
1078 const coff_header_offset = try reader.readInt(u32, .little);
10791079 try stream.seekTo(coff_header_offset);
10801080 var buf: [4]u8 = undefined;
10811081 try reader.readNoEof(&buf);
lib/std/compress/deflate/bits_utils.zig+2-2
......@@ -15,7 +15,7 @@ test "bitReverse" {
1515 out: u16,
1616 };
1717
18 var reverse_bits_tests = [_]ReverseBitsTest{
18 const reverse_bits_tests = [_]ReverseBitsTest{
1919 .{ .in = 1, .bit_count = 1, .out = 1 },
2020 .{ .in = 1, .bit_count = 2, .out = 2 },
2121 .{ .in = 1, .bit_count = 3, .out = 4 },
......@@ -27,7 +27,7 @@ test "bitReverse" {
2727 };
2828
2929 for (reverse_bits_tests) |h| {
30 var v = bitReverse(u16, h.in, h.bit_count);
30 const v = bitReverse(u16, h.in, h.bit_count);
3131 try std.testing.expectEqual(h.out, v);
3232 }
3333}
lib/std/compress/deflate/compressor.zig+25-25
......@@ -156,8 +156,8 @@ fn levels(compression: Compression) CompressionLevel {
156156// up to length 'max'. Both slices must be at least 'max'
157157// bytes in size.
158158fn matchLen(a: []u8, b: []u8, max: u32) u32 {
159 var bounded_a = a[0..max];
160 var bounded_b = b[0..max];
159 const bounded_a = a[0..max];
160 const bounded_b = b[0..max];
161161 for (bounded_a, 0..) |av, i| {
162162 if (bounded_b[i] != av) {
163163 return @as(u32, @intCast(i));
......@@ -191,7 +191,7 @@ fn bulkHash4(b: []u8, dst: []u32) u32 {
191191 @as(u32, b[0]) << 24;
192192
193193 dst[0] = (hb *% hash_mul) >> (32 - hash_bits);
194 var end = b.len - min_match_length + 1;
194 const end = b.len - min_match_length + 1;
195195 var i: u32 = 1;
196196 while (i < end) : (i += 1) {
197197 hb = (hb << 8) | @as(u32, b[i + 3]);
......@@ -305,7 +305,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
305305 }
306306 self.hash_offset += window_size;
307307 if (self.hash_offset > max_hash_offset) {
308 var delta = self.hash_offset - 1;
308 const delta = self.hash_offset - 1;
309309 self.hash_offset -= delta;
310310 self.chain_head -|= delta;
311311
......@@ -369,31 +369,31 @@ pub fn Compressor(comptime WriterType: anytype) type {
369369 }
370370 // Add all to window.
371371 @memcpy(self.window[0..b.len], b);
372 var n = b.len;
372 const n = b.len;
373373
374374 // Calculate 256 hashes at the time (more L1 cache hits)
375 var loops = (n + 256 - min_match_length) / 256;
375 const loops = (n + 256 - min_match_length) / 256;
376376 var j: usize = 0;
377377 while (j < loops) : (j += 1) {
378 var index = j * 256;
378 const index = j * 256;
379379 var end = index + 256 + min_match_length - 1;
380380 if (end > n) {
381381 end = n;
382382 }
383 var to_check = self.window[index..end];
384 var dst_size = to_check.len - min_match_length + 1;
383 const to_check = self.window[index..end];
384 const dst_size = to_check.len - min_match_length + 1;
385385
386386 if (dst_size <= 0) {
387387 continue;
388388 }
389389
390 var dst = self.hash_match[0..dst_size];
390 const dst = self.hash_match[0..dst_size];
391391 _ = self.bulk_hasher(to_check, dst);
392392 var new_h: u32 = 0;
393393 for (dst, 0..) |val, i| {
394 var di = i + index;
394 const di = i + index;
395395 new_h = val;
396 var hh = &self.hash_head[new_h & hash_mask];
396 const hh = &self.hash_head[new_h & hash_mask];
397397 // Get previous value with the same hash.
398398 // Our chain should point to the previous value.
399399 self.hash_prev[di & window_mask] = hh.*;
......@@ -447,13 +447,13 @@ pub fn Compressor(comptime WriterType: anytype) type {
447447 }
448448
449449 var w_end = win[pos + length];
450 var w_pos = win[pos..];
451 var min_index = pos -| window_size;
450 const w_pos = win[pos..];
451 const min_index = pos -| window_size;
452452
453453 var i = prev_head;
454454 while (tries > 0) : (tries -= 1) {
455455 if (w_end == win[i + length]) {
456 var n = matchLen(win[i..], w_pos, min_match_look);
456 const n = matchLen(win[i..], w_pos, min_match_look);
457457
458458 if (n > length and (n > min_match_length or pos - i <= 4096)) {
459459 length = n;
......@@ -565,7 +565,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
565565 while (true) {
566566 assert(self.index <= self.window_end);
567567
568 var lookahead = self.window_end -| self.index;
568 const lookahead = self.window_end -| self.index;
569569 if (lookahead < min_match_length + max_match_length) {
570570 if (!self.sync) {
571571 break;
......@@ -590,16 +590,16 @@ pub fn Compressor(comptime WriterType: anytype) type {
590590 if (self.index < self.max_insert_index) {
591591 // Update the hash
592592 self.hash = hash4(self.window[self.index .. self.index + min_match_length]);
593 var hh = &self.hash_head[self.hash & hash_mask];
593 const hh = &self.hash_head[self.hash & hash_mask];
594594 self.chain_head = @as(u32, @intCast(hh.*));
595595 self.hash_prev[self.index & window_mask] = @as(u32, @intCast(self.chain_head));
596596 hh.* = @as(u32, @intCast(self.index + self.hash_offset));
597597 }
598 var prev_length = self.length;
599 var prev_offset = self.offset;
598 const prev_length = self.length;
599 const prev_offset = self.offset;
600600 self.length = min_match_length - 1;
601601 self.offset = 0;
602 var min_index = self.index -| window_size;
602 const min_index = self.index -| window_size;
603603
604604 if (self.hash_offset <= self.chain_head and
605605 self.chain_head - self.hash_offset >= min_index and
......@@ -610,7 +610,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
610610 prev_length < self.compression_level.lazy))
611611 {
612612 {
613 var fmatch = self.findMatch(
613 const fmatch = self.findMatch(
614614 self.index,
615615 self.chain_head -| self.hash_offset,
616616 min_match_length - 1,
......@@ -658,7 +658,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
658658 self.hash = hash4(self.window[index .. index + min_match_length]);
659659 // Get previous value with the same hash.
660660 // Our chain should point to the previous value.
661 var hh = &self.hash_head[self.hash & hash_mask];
661 const hh = &self.hash_head[self.hash & hash_mask];
662662 self.hash_prev[index & window_mask] = hh.*;
663663 // Set the head of the hash chain to us.
664664 hh.* = @as(u32, @intCast(index + self.hash_offset));
......@@ -740,7 +740,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
740740 // compressed form of data to its underlying writer.
741741 while (buf.len > 0) {
742742 try self.step();
743 var filled = self.fill(buf);
743 const filled = self.fill(buf);
744744 buf = buf[filled..];
745745 }
746746
......@@ -1097,12 +1097,12 @@ test "bulkHash4" {
10971097 while (j < out.len) : (j += 1) {
10981098 var y = out[0..j];
10991099
1100 var dst = try testing.allocator.alloc(u32, y.len - min_match_length + 1);
1100 const dst = try testing.allocator.alloc(u32, y.len - min_match_length + 1);
11011101 defer testing.allocator.free(dst);
11021102
11031103 _ = bulkHash4(y, dst);
11041104 for (dst, 0..) |got, i| {
1105 var want = hash4(y[i..]);
1105 const want = hash4(y[i..]);
11061106 try testing.expectEqual(want, got);
11071107 }
11081108 }
lib/std/compress/deflate/compressor_test.zig+16-16
......@@ -27,7 +27,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
2727 var whole_buf = std.ArrayList(u8).init(testing.allocator);
2828 defer whole_buf.deinit();
2929
30 var multi_writer = io.multiWriter(.{
30 const multi_writer = io.multiWriter(.{
3131 divided_buf.writer(),
3232 whole_buf.writer(),
3333 }).writer();
......@@ -48,7 +48,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
4848 defer decomp.deinit();
4949
5050 // Write first half of the input and flush()
51 var half: usize = (input.len + 1) / 2;
51 const half: usize = (input.len + 1) / 2;
5252 var half_len: usize = half - 0;
5353 {
5454 _ = try comp.writer().writeAll(input[0..half]);
......@@ -57,10 +57,10 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
5757 try comp.flush();
5858
5959 // Read back
60 var decompressed = try testing.allocator.alloc(u8, half_len);
60 const decompressed = try testing.allocator.alloc(u8, half_len);
6161 defer testing.allocator.free(decompressed);
6262
63 var read = try decomp.reader().readAll(decompressed); // read at least half
63 const read = try decomp.reader().readAll(decompressed); // read at least half
6464 try testing.expectEqual(half_len, read);
6565 try testing.expectEqualSlices(u8, input[0..half], decompressed);
6666 }
......@@ -74,7 +74,7 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
7474 try comp.close();
7575
7676 // Read back
77 var decompressed = try testing.allocator.alloc(u8, half_len);
77 const decompressed = try testing.allocator.alloc(u8, half_len);
7878 defer testing.allocator.free(decompressed);
7979
8080 var read = try decomp.reader().readAll(decompressed);
......@@ -94,11 +94,11 @@ fn testSync(level: deflate.Compression, input: []const u8) !void {
9494 try comp.close();
9595
9696 // stream should work for ordinary reader too (reading whole_buf in one go)
97 var whole_buf_reader = io.fixedBufferStream(whole_buf.items).reader();
97 const whole_buf_reader = io.fixedBufferStream(whole_buf.items).reader();
9898 var decomp = try decompressor(testing.allocator, whole_buf_reader, null);
9999 defer decomp.deinit();
100100
101 var decompressed = try testing.allocator.alloc(u8, input.len);
101 const decompressed = try testing.allocator.alloc(u8, input.len);
102102 defer testing.allocator.free(decompressed);
103103
104104 _ = try decomp.reader().readAll(decompressed);
......@@ -125,10 +125,10 @@ fn testToFromWithLevelAndLimit(level: deflate.Compression, input: []const u8, li
125125 var decomp = try decompressor(testing.allocator, fib.reader(), null);
126126 defer decomp.deinit();
127127
128 var decompressed = try testing.allocator.alloc(u8, input.len);
128 const decompressed = try testing.allocator.alloc(u8, input.len);
129129 defer testing.allocator.free(decompressed);
130130
131 var read: usize = try decomp.reader().readAll(decompressed);
131 const read: usize = try decomp.reader().readAll(decompressed);
132132 try testing.expectEqual(input.len, read);
133133 try testing.expectEqualSlices(u8, input, decompressed);
134134
......@@ -153,7 +153,7 @@ fn testToFromWithLimit(input: []const u8, limit: [11]u32) !void {
153153}
154154
155155test "deflate/inflate" {
156 var limits = [_]u32{0} ** 11;
156 const limits = [_]u32{0} ** 11;
157157
158158 var test0 = [_]u8{};
159159 var test1 = [_]u8{0x11};
......@@ -313,7 +313,7 @@ test "decompressor dictionary" {
313313 try comp.writer().writeAll(text);
314314 try comp.close();
315315
316 var decompressed = try testing.allocator.alloc(u8, text.len);
316 const decompressed = try testing.allocator.alloc(u8, text.len);
317317 defer testing.allocator.free(decompressed);
318318
319319 var decomp = try decompressor(
......@@ -432,7 +432,7 @@ test "deflate/inflate string" {
432432 };
433433
434434 inline for (deflate_inflate_string_tests) |t| {
435 var golden = @embedFile("testdata/" ++ t.filename);
435 const golden = @embedFile("testdata/" ++ t.filename);
436436 try testToFromWithLimit(golden, t.limit);
437437 }
438438}
......@@ -466,14 +466,14 @@ test "inflate reset" {
466466 var decomp = try decompressor(testing.allocator, fib.reader(), null);
467467 defer decomp.deinit();
468468
469 var decompressed_0: []u8 = try decomp.reader()
469 const decompressed_0: []u8 = try decomp.reader()
470470 .readAllAlloc(testing.allocator, math.maxInt(usize));
471471 defer testing.allocator.free(decompressed_0);
472472
473473 fib = io.fixedBufferStream(compressed_strings[1].items);
474474 try decomp.reset(fib.reader(), null);
475475
476 var decompressed_1: []u8 = try decomp.reader()
476 const decompressed_1: []u8 = try decomp.reader()
477477 .readAllAlloc(testing.allocator, math.maxInt(usize));
478478 defer testing.allocator.free(decompressed_1);
479479
......@@ -513,14 +513,14 @@ test "inflate reset dictionary" {
513513 var decomp = try decompressor(testing.allocator, fib.reader(), dict);
514514 defer decomp.deinit();
515515
516 var decompressed_0: []u8 = try decomp.reader()
516 const decompressed_0: []u8 = try decomp.reader()
517517 .readAllAlloc(testing.allocator, math.maxInt(usize));
518518 defer testing.allocator.free(decompressed_0);
519519
520520 fib = io.fixedBufferStream(compressed_strings[1].items);
521521 try decomp.reset(fib.reader(), dict);
522522
523 var decompressed_1: []u8 = try decomp.reader()
523 const decompressed_1: []u8 = try decomp.reader()
524524 .readAllAlloc(testing.allocator, math.maxInt(usize));
525525 defer testing.allocator.free(decompressed_1);
526526
lib/std/compress/deflate/decompressor.zig+25-25
......@@ -136,11 +136,11 @@ const HuffmanDecoder = struct {
136136
137137 self.min = min;
138138 if (max > huffman_chunk_bits) {
139 var num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits));
139 const num_links = @as(u32, 1) << @as(u5, @intCast(max - huffman_chunk_bits));
140140 self.link_mask = @as(u32, @intCast(num_links - 1));
141141
142142 // create link tables
143 var link = next_code[huffman_chunk_bits + 1] >> 1;
143 const link = next_code[huffman_chunk_bits + 1] >> 1;
144144 self.links = try self.allocator.alloc([]u16, huffman_num_chunks - link);
145145 self.sub_chunks = ArrayList(u32).init(self.allocator);
146146 self.initialized = true;
......@@ -148,7 +148,7 @@ const HuffmanDecoder = struct {
148148 while (j < huffman_num_chunks) : (j += 1) {
149149 var reverse = @as(u32, @intCast(bu.bitReverse(u16, @as(u16, @intCast(j)), 16)));
150150 reverse >>= @as(u32, @intCast(16 - huffman_chunk_bits));
151 var off = j - @as(u32, @intCast(link));
151 const off = j - @as(u32, @intCast(link));
152152 if (sanity) {
153153 // check we are not overwriting an existing chunk
154154 assert(self.chunks[reverse] == 0);
......@@ -168,9 +168,9 @@ const HuffmanDecoder = struct {
168168 if (n == 0) {
169169 continue;
170170 }
171 var ncode = next_code[n];
171 const ncode = next_code[n];
172172 next_code[n] += 1;
173 var chunk = @as(u16, @intCast((li << huffman_value_shift) | n));
173 const chunk = @as(u16, @intCast((li << huffman_value_shift) | n));
174174 var reverse = @as(u16, @intCast(bu.bitReverse(u16, @as(u16, @intCast(ncode)), 16)));
175175 reverse >>= @as(u4, @intCast(16 - n));
176176 if (n <= huffman_chunk_bits) {
......@@ -187,14 +187,14 @@ const HuffmanDecoder = struct {
187187 self.chunks[off] = chunk;
188188 }
189189 } else {
190 var j = reverse & (huffman_num_chunks - 1);
190 const j = reverse & (huffman_num_chunks - 1);
191191 if (sanity) {
192192 // Expect an indirect chunk
193193 assert(self.chunks[j] & huffman_count_mask == huffman_chunk_bits + 1);
194194 // Longer codes should have been
195195 // associated with a link table above.
196196 }
197 var value = self.chunks[j] >> huffman_value_shift;
197 const value = self.chunks[j] >> huffman_value_shift;
198198 var link_tab = self.links[value];
199199 reverse >>= huffman_chunk_bits;
200200 var off = reverse;
......@@ -354,8 +354,8 @@ pub fn Decompressor(comptime ReaderType: type) type {
354354 fn init(allocator: Allocator, in_reader: ReaderType, dict: ?[]const u8) !Self {
355355 fixed_huffman_decoder = try fixedHuffmanDecoderInit(allocator);
356356
357 var bits = try allocator.create([max_num_lit + max_num_dist]u32);
358 var codebits = try allocator.create([num_codes]u32);
357 const bits = try allocator.create([max_num_lit + max_num_dist]u32);
358 const codebits = try allocator.create([num_codes]u32);
359359
360360 var dd = ddec.DictDecoder{};
361361 try dd.init(allocator, max_match_offset, dict);
......@@ -416,7 +416,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
416416 }
417417 self.final = self.b & 1 == 1;
418418 self.b >>= 1;
419 var typ = self.b & 3;
419 const typ = self.b & 3;
420420 self.b >>= 2;
421421 self.nb -= 1 + 2;
422422 switch (typ) {
......@@ -494,21 +494,21 @@ pub fn Decompressor(comptime ReaderType: type) type {
494494 while (self.nb < 5 + 5 + 4) {
495495 try self.moreBits();
496496 }
497 var nlit = @as(u32, @intCast(self.b & 0x1F)) + 257;
497 const nlit = @as(u32, @intCast(self.b & 0x1F)) + 257;
498498 if (nlit > max_num_lit) {
499499 corrupt_input_error_offset = self.roffset;
500500 self.err = InflateError.CorruptInput;
501501 return InflateError.CorruptInput;
502502 }
503503 self.b >>= 5;
504 var ndist = @as(u32, @intCast(self.b & 0x1F)) + 1;
504 const ndist = @as(u32, @intCast(self.b & 0x1F)) + 1;
505505 if (ndist > max_num_dist) {
506506 corrupt_input_error_offset = self.roffset;
507507 self.err = InflateError.CorruptInput;
508508 return InflateError.CorruptInput;
509509 }
510510 self.b >>= 5;
511 var nclen = @as(u32, @intCast(self.b & 0xF)) + 4;
511 const nclen = @as(u32, @intCast(self.b & 0xF)) + 4;
512512 // num_codes is 19, so nclen is always valid.
513513 self.b >>= 4;
514514 self.nb -= 5 + 5 + 4;
......@@ -536,9 +536,9 @@ pub fn Decompressor(comptime ReaderType: type) type {
536536 // HLIT + 257 code lengths, HDIST + 1 code lengths,
537537 // using the code length Huffman code.
538538 i = 0;
539 var n = nlit + ndist;
539 const n = nlit + ndist;
540540 while (i < n) {
541 var x = try self.huffSym(&self.hd1);
541 const x = try self.huffSym(&self.hd1);
542542 if (x < 16) {
543543 // Actual length.
544544 self.bits[i] = x;
......@@ -618,7 +618,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
618618 switch (self.step_state) {
619619 .init => {
620620 // Read literal and/or (length, distance) according to RFC section 3.2.3.
621 var v = try self.huffSym(self.hl.?);
621 const v = try self.huffSym(self.hl.?);
622622 var n: u32 = 0; // number of bits extra
623623 var length: u32 = 0;
624624 switch (v) {
......@@ -699,7 +699,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
699699 switch (dist) {
700700 0...3 => dist += 1,
701701 4...max_num_dist - 1 => { // 4...29
702 var nb = @as(u32, @intCast(dist - 2)) >> 1;
702 const nb = @as(u32, @intCast(dist - 2)) >> 1;
703703 // have 1 bit in bottom of dist, need nb more.
704704 var extra = (dist & 1) << @as(u5, @intCast(nb));
705705 while (self.nb < nb) {
......@@ -757,14 +757,14 @@ pub fn Decompressor(comptime ReaderType: type) type {
757757 self.b = 0;
758758
759759 // Length then ones-complement of length.
760 var nr: u32 = 4;
760 const nr: u32 = 4;
761761 self.inner_reader.readNoEof(self.buf[0..nr]) catch {
762762 self.err = InflateError.UnexpectedEndOfStream;
763763 return InflateError.UnexpectedEndOfStream;
764764 };
765765 self.roffset += @as(u64, @intCast(nr));
766 var n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8;
767 var nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8;
766 const n = @as(u32, @intCast(self.buf[0])) | @as(u32, @intCast(self.buf[1])) << 8;
767 const nn = @as(u32, @intCast(self.buf[2])) | @as(u32, @intCast(self.buf[3])) << 8;
768768 if (@as(u16, @intCast(nn)) != @as(u16, @truncate(~n))) {
769769 corrupt_input_error_offset = self.roffset;
770770 self.err = InflateError.CorruptInput;
......@@ -789,7 +789,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
789789 buf = buf[0..self.copy_len];
790790 }
791791
792 var cnt = try self.inner_reader.read(buf);
792 const cnt = try self.inner_reader.read(buf);
793793 if (cnt < buf.len) {
794794 self.err = InflateError.UnexpectedEndOfStream;
795795 }
......@@ -819,7 +819,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
819819 }
820820
821821 fn moreBits(self: *Self) InflateError!void {
822 var c = self.inner_reader.readByte() catch |e| {
822 const c = self.inner_reader.readByte() catch |e| {
823823 if (e == error.EndOfStream) {
824824 return InflateError.UnexpectedEndOfStream;
825825 }
......@@ -845,7 +845,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
845845 var b = self.b;
846846 while (true) {
847847 while (nb < n) {
848 var c = self.inner_reader.readByte() catch |e| {
848 const c = self.inner_reader.readByte() catch |e| {
849849 self.b = b;
850850 self.nb = nb;
851851 if (e == error.EndOfStream) {
......@@ -1053,7 +1053,7 @@ test "inflate A Tale of Two Cities (1859) intro" {
10531053 defer decomp.deinit();
10541054
10551055 var got: [700]u8 = undefined;
1056 var got_len = try decomp.reader().read(&got);
1056 const got_len = try decomp.reader().read(&got);
10571057 try testing.expectEqual(@as(usize, 616), got_len);
10581058 try testing.expectEqualSlices(u8, expected, got[0..expected.len]);
10591059}
......@@ -1117,6 +1117,6 @@ fn decompress(input: []const u8) !void {
11171117 const reader = fib.reader();
11181118 var decomp = try decompressor(allocator, reader, null);
11191119 defer decomp.deinit();
1120 var output = try decomp.reader().readAllAlloc(allocator, math.maxInt(usize));
1120 const output = try decomp.reader().readAllAlloc(allocator, math.maxInt(usize));
11211121 defer std.testing.allocator.free(output);
11221122}
lib/std/compress/deflate/deflate_fast.zig+32-32
......@@ -30,7 +30,7 @@ const table_size = 1 << table_bits; // Size of the table.
3030const buffer_reset = math.maxInt(i32) - max_store_block_size * 2;
3131
3232fn load32(b: []u8, i: i32) u32 {
33 var s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4];
33 const s = b[@as(usize, @intCast(i)) .. @as(usize, @intCast(i)) + 4];
3434 return @as(u32, @intCast(s[0])) |
3535 @as(u32, @intCast(s[1])) << 8 |
3636 @as(u32, @intCast(s[2])) << 16 |
......@@ -38,7 +38,7 @@ fn load32(b: []u8, i: i32) u32 {
3838}
3939
4040fn load64(b: []u8, i: i32) u64 {
41 var s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))];
41 const s = b[@as(usize, @intCast(i))..@as(usize, @intCast(i + 8))];
4242 return @as(u64, @intCast(s[0])) |
4343 @as(u64, @intCast(s[1])) << 8 |
4444 @as(u64, @intCast(s[2])) << 16 |
......@@ -117,7 +117,7 @@ pub const DeflateFast = struct {
117117 // s_limit is when to stop looking for offset/length copies. The input_margin
118118 // lets us use a fast path for emitLiteral in the main loop, while we are
119119 // looking for copies.
120 var s_limit = @as(i32, @intCast(src.len - input_margin));
120 const s_limit = @as(i32, @intCast(src.len - input_margin));
121121
122122 // next_emit is where in src the next emitLiteral should start from.
123123 var next_emit: i32 = 0;
......@@ -147,18 +147,18 @@ pub const DeflateFast = struct {
147147 var candidate: TableEntry = undefined;
148148 while (true) {
149149 s = next_s;
150 var bytes_between_hash_lookups = skip >> 5;
150 const bytes_between_hash_lookups = skip >> 5;
151151 next_s = s + bytes_between_hash_lookups;
152152 skip += bytes_between_hash_lookups;
153153 if (next_s > s_limit) {
154154 break :outer;
155155 }
156156 candidate = self.table[next_hash & table_mask];
157 var now = load32(src, next_s);
157 const now = load32(src, next_s);
158158 self.table[next_hash & table_mask] = .{ .offset = s + self.cur, .val = cv };
159159 next_hash = hash(now);
160160
161 var offset = s - (candidate.offset - self.cur);
161 const offset = s - (candidate.offset - self.cur);
162162 if (offset > max_match_offset or cv != candidate.val) {
163163 // Out of range or not matched.
164164 cv = now;
......@@ -187,8 +187,8 @@ pub const DeflateFast = struct {
187187 // Extend the 4-byte match as long as possible.
188188 //
189189 s += 4;
190 var t = candidate.offset - self.cur + 4;
191 var l = self.matchLen(s, t, src);
190 const t = candidate.offset - self.cur + 4;
191 const l = self.matchLen(s, t, src);
192192
193193 // matchToken is flate's equivalent of Snappy's emitCopy. (length,offset)
194194 dst[tokens_count.*] = token.matchToken(
......@@ -209,20 +209,20 @@ pub const DeflateFast = struct {
209209 // are faster as one load64 call (with some shifts) instead of
210210 // three load32 calls.
211211 var x = load64(src, s - 1);
212 var prev_hash = hash(@as(u32, @truncate(x)));
212 const prev_hash = hash(@as(u32, @truncate(x)));
213213 self.table[prev_hash & table_mask] = TableEntry{
214214 .offset = self.cur + s - 1,
215215 .val = @as(u32, @truncate(x)),
216216 };
217217 x >>= 8;
218 var curr_hash = hash(@as(u32, @truncate(x)));
218 const curr_hash = hash(@as(u32, @truncate(x)));
219219 candidate = self.table[curr_hash & table_mask];
220220 self.table[curr_hash & table_mask] = TableEntry{
221221 .offset = self.cur + s,
222222 .val = @as(u32, @truncate(x)),
223223 };
224224
225 var offset = s - (candidate.offset - self.cur);
225 const offset = s - (candidate.offset - self.cur);
226226 if (offset > max_match_offset or @as(u32, @truncate(x)) != candidate.val) {
227227 cv = @as(u32, @truncate(x >> 8));
228228 next_hash = hash(cv);
......@@ -261,7 +261,7 @@ pub const DeflateFast = struct {
261261 // If we are inside the current block
262262 if (t >= 0) {
263263 var b = src[@as(usize, @intCast(t))..];
264 var a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))];
264 const a = src[@as(usize, @intCast(s))..@as(usize, @intCast(s1))];
265265 b = b[0..a.len];
266266 // Extend the match to be as long as possible.
267267 for (a, 0..) |_, i| {
......@@ -273,7 +273,7 @@ pub const DeflateFast = struct {
273273 }
274274
275275 // We found a match in the previous block.
276 var tp = @as(i32, @intCast(self.prev_len)) + t;
276 const tp = @as(i32, @intCast(self.prev_len)) + t;
277277 if (tp < 0) {
278278 return 0;
279279 }
......@@ -293,7 +293,7 @@ pub const DeflateFast = struct {
293293
294294 // If we reached our limit, we matched everything we are
295295 // allowed to in the previous block and we return.
296 var n = @as(i32, @intCast(b.len));
296 const n = @as(i32, @intCast(b.len));
297297 if (@as(u32, @intCast(s + n)) == s1) {
298298 return n;
299299 }
......@@ -366,7 +366,7 @@ test "best speed match 1/3" {
366366 .cur = 0,
367367 };
368368 var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 };
369 var got: i32 = e.matchLen(3, -3, &current);
369 const got: i32 = e.matchLen(3, -3, &current);
370370 try expectEqual(@as(i32, 6), got);
371371 }
372372 {
......@@ -379,7 +379,7 @@ test "best speed match 1/3" {
379379 .cur = 0,
380380 };
381381 var current = [_]u8{ 2, 4, 5, 0, 1, 2, 3, 4, 5 };
382 var got: i32 = e.matchLen(3, -3, &current);
382 const got: i32 = e.matchLen(3, -3, &current);
383383 try expectEqual(@as(i32, 3), got);
384384 }
385385 {
......@@ -392,7 +392,7 @@ test "best speed match 1/3" {
392392 .cur = 0,
393393 };
394394 var current = [_]u8{ 3, 4, 5, 0, 1, 2, 3, 4, 5 };
395 var got: i32 = e.matchLen(3, -3, &current);
395 const got: i32 = e.matchLen(3, -3, &current);
396396 try expectEqual(@as(i32, 2), got);
397397 }
398398 {
......@@ -405,7 +405,7 @@ test "best speed match 1/3" {
405405 .cur = 0,
406406 };
407407 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
408 var got: i32 = e.matchLen(0, -1, &current);
408 const got: i32 = e.matchLen(0, -1, &current);
409409 try expectEqual(@as(i32, 4), got);
410410 }
411411 {
......@@ -418,7 +418,7 @@ test "best speed match 1/3" {
418418 .cur = 0,
419419 };
420420 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
421 var got: i32 = e.matchLen(4, -7, &current);
421 const got: i32 = e.matchLen(4, -7, &current);
422422 try expectEqual(@as(i32, 5), got);
423423 }
424424 {
......@@ -431,7 +431,7 @@ test "best speed match 1/3" {
431431 .cur = 0,
432432 };
433433 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
434 var got: i32 = e.matchLen(0, -1, &current);
434 const got: i32 = e.matchLen(0, -1, &current);
435435 try expectEqual(@as(i32, 0), got);
436436 }
437437 {
......@@ -444,7 +444,7 @@ test "best speed match 1/3" {
444444 .cur = 0,
445445 };
446446 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };
447 var got: i32 = e.matchLen(1, 0, &current);
447 const got: i32 = e.matchLen(1, 0, &current);
448448 try expectEqual(@as(i32, 0), got);
449449 }
450450}
......@@ -462,7 +462,7 @@ test "best speed match 2/3" {
462462 .cur = 0,
463463 };
464464 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };
465 var got: i32 = e.matchLen(1, -5, &current);
465 const got: i32 = e.matchLen(1, -5, &current);
466466 try expectEqual(@as(i32, 0), got);
467467 }
468468 {
......@@ -475,7 +475,7 @@ test "best speed match 2/3" {
475475 .cur = 0,
476476 };
477477 var current = [_]u8{ 9, 2, 2, 2, 1, 2, 3, 4, 5 };
478 var got: i32 = e.matchLen(1, -1, &current);
478 const got: i32 = e.matchLen(1, -1, &current);
479479 try expectEqual(@as(i32, 0), got);
480480 }
481481 {
......@@ -488,7 +488,7 @@ test "best speed match 2/3" {
488488 .cur = 0,
489489 };
490490 var current = [_]u8{ 2, 2, 2, 2, 1, 2, 3, 4, 5 };
491 var got: i32 = e.matchLen(1, 0, &current);
491 const got: i32 = e.matchLen(1, 0, &current);
492492 try expectEqual(@as(i32, 3), got);
493493 }
494494 {
......@@ -501,7 +501,7 @@ test "best speed match 2/3" {
501501 .cur = 0,
502502 };
503503 var current = [_]u8{ 3, 4, 5 };
504 var got: i32 = e.matchLen(0, -3, &current);
504 const got: i32 = e.matchLen(0, -3, &current);
505505 try expectEqual(@as(i32, 3), got);
506506 }
507507}
......@@ -564,11 +564,11 @@ test "best speed match 2/2" {
564564 };
565565
566566 for (cases) |c| {
567 var previous = try testing.allocator.alloc(u8, c.previous);
567 const previous = try testing.allocator.alloc(u8, c.previous);
568568 defer testing.allocator.free(previous);
569569 @memset(previous, 0);
570570
571 var current = try testing.allocator.alloc(u8, c.current);
571 const current = try testing.allocator.alloc(u8, c.current);
572572 defer testing.allocator.free(current);
573573 @memset(current, 0);
574574
......@@ -579,7 +579,7 @@ test "best speed match 2/2" {
579579 .allocator = undefined,
580580 .cur = 0,
581581 };
582 var got: i32 = e.matchLen(c.s, c.t, current);
582 const got: i32 = e.matchLen(c.s, c.t, current);
583583 try expectEqual(@as(i32, c.expected), got);
584584 }
585585}
......@@ -609,10 +609,10 @@ test "best speed shift offsets" {
609609 // Second part should pick up matches from the first block.
610610 tokens_count = 0;
611611 enc.encode(&tokens, &tokens_count, &test_data);
612 var want_first_tokens = tokens_count;
612 const want_first_tokens = tokens_count;
613613 tokens_count = 0;
614614 enc.encode(&tokens, &tokens_count, &test_data);
615 var want_second_tokens = tokens_count;
615 const want_second_tokens = tokens_count;
616616
617617 try expect(want_first_tokens > want_second_tokens);
618618
......@@ -657,7 +657,7 @@ test "best speed reset" {
657657 const ArrayList = std.ArrayList;
658658
659659 const input_size = 65536;
660 var input = try testing.allocator.alloc(u8, input_size);
660 const input = try testing.allocator.alloc(u8, input_size);
661661 defer testing.allocator.free(input);
662662
663663 var i: usize = 0;
......@@ -699,7 +699,7 @@ test "best speed reset" {
699699 // Reset until we are right before the wraparound.
700700 // Each reset adds max_match_offset to the offset.
701701 i = 0;
702 var limit = (buffer_reset - input.len - o - max_match_offset) / max_match_offset;
702 const limit = (buffer_reset - input.len - o - max_match_offset) / max_match_offset;
703703 while (i < limit) : (i += 1) {
704704 // skip ahead to where we are close to wrap around...
705705 comp.reset(discard.writer());
lib/std/compress/deflate/deflate_fast_test.zig+9-9
......@@ -39,18 +39,18 @@ test "best speed" {
3939 var tc_15 = [_]u32{ 65536, 129 };
4040 var tc_16 = [_]u32{ 65536, 65536, 256 };
4141 var tc_17 = [_]u32{ 65536, 65536, 65536 };
42 var test_cases = [_][]u32{
42 const test_cases = [_][]u32{
4343 &tc_01, &tc_02, &tc_03, &tc_04, &tc_05, &tc_06, &tc_07, &tc_08, &tc_09, &tc_10,
4444 &tc_11, &tc_12, &tc_13, &tc_14, &tc_15, &tc_16, &tc_17,
4545 };
4646
4747 for (test_cases) |tc| {
48 var firsts = [_]u32{ 1, 65534, 65535, 65536, 65537, 131072 };
48 const firsts = [_]u32{ 1, 65534, 65535, 65536, 65537, 131072 };
4949
5050 for (firsts) |first_n| {
5151 tc[0] = first_n;
5252
53 var to_flush = [_]bool{ false, true };
53 const to_flush = [_]bool{ false, true };
5454 for (to_flush) |flush| {
5555 var compressed = ArrayList(u8).init(testing.allocator);
5656 defer compressed.deinit();
......@@ -75,14 +75,14 @@ test "best speed" {
7575
7676 try comp.close();
7777
78 var decompressed = try testing.allocator.alloc(u8, want.items.len);
78 const decompressed = try testing.allocator.alloc(u8, want.items.len);
7979 defer testing.allocator.free(decompressed);
8080
8181 var fib = io.fixedBufferStream(compressed.items);
8282 var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null);
8383 defer decomp.deinit();
8484
85 var read = try decomp.reader().readAll(decompressed);
85 const read = try decomp.reader().readAll(decompressed);
8686 _ = decomp.close();
8787
8888 try testing.expectEqual(want.items.len, read);
......@@ -109,7 +109,7 @@ test "best speed max match offset" {
109109 for (extras) |extra| {
110110 var offset_adj: i32 = -5;
111111 while (offset_adj <= 5) : (offset_adj += 1) {
112 var offset = deflate_const.max_match_offset + offset_adj;
112 const offset = deflate_const.max_match_offset + offset_adj;
113113
114114 // Make src to be a []u8 of the form
115115 // fmt("{s}{s}{s}{s}{s}", .{abc, zeros0, xyzMaybe, abc, zeros1})
......@@ -119,7 +119,7 @@ test "best speed max match offset" {
119119 // zeros1 is between 0 and 30 zeros.
120120 // The difference between the two abc's will be offset, which
121121 // is max_match_offset plus or minus a small adjustment.
122 var src_len: usize = @as(usize, @intCast(offset + @as(i32, abc.len) + @as(i32, @intCast(extra))));
122 const src_len: usize = @as(usize, @intCast(offset + @as(i32, abc.len) + @as(i32, @intCast(extra))));
123123 var src = try testing.allocator.alloc(u8, src_len);
124124 defer testing.allocator.free(src);
125125
......@@ -143,13 +143,13 @@ test "best speed max match offset" {
143143 try comp.writer().writeAll(src);
144144 _ = try comp.close();
145145
146 var decompressed = try testing.allocator.alloc(u8, src.len);
146 const decompressed = try testing.allocator.alloc(u8, src.len);
147147 defer testing.allocator.free(decompressed);
148148
149149 var fib = io.fixedBufferStream(compressed.items);
150150 var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null);
151151 defer decomp.deinit();
152 var read = try decomp.reader().readAll(decompressed);
152 const read = try decomp.reader().readAll(decompressed);
153153 _ = decomp.close();
154154
155155 try testing.expectEqual(src.len, read);
lib/std/compress/deflate/dict_decoder.zig+7-7
......@@ -123,7 +123,7 @@ pub const DictDecoder = struct {
123123 // This invariant must be kept: 0 < dist <= histSize()
124124 pub fn writeCopy(self: *Self, dist: u32, length: u32) u32 {
125125 assert(0 < dist and dist <= self.histSize());
126 var dst_base = self.wr_pos;
126 const dst_base = self.wr_pos;
127127 var dst_pos = dst_base;
128128 var src_pos: i32 = @as(i32, @intCast(dst_pos)) - @as(i32, @intCast(dist));
129129 var end_pos = dst_pos + length;
......@@ -175,12 +175,12 @@ pub const DictDecoder = struct {
175175 // This invariant must be kept: 0 < dist <= histSize()
176176 pub fn tryWriteCopy(self: *Self, dist: u32, length: u32) u32 {
177177 var dst_pos = self.wr_pos;
178 var end_pos = dst_pos + length;
178 const end_pos = dst_pos + length;
179179 if (dst_pos < dist or end_pos > self.hist.len) {
180180 return 0;
181181 }
182 var dst_base = dst_pos;
183 var src_pos = dst_pos - dist;
182 const dst_base = dst_pos;
183 const src_pos = dst_pos - dist;
184184
185185 // Copy possibly overlapping section before destination position.
186186 while (dst_pos < end_pos) {
......@@ -195,7 +195,7 @@ pub const DictDecoder = struct {
195195 // emitted to the user. The data returned by readFlush must be fully consumed
196196 // before calling any other DictDecoder methods.
197197 pub fn readFlush(self: *Self) []u8 {
198 var to_read = self.hist[self.rd_pos..self.wr_pos];
198 const to_read = self.hist[self.rd_pos..self.wr_pos];
199199 self.rd_pos = self.wr_pos;
200200 if (self.wr_pos == self.hist.len) {
201201 self.wr_pos = 0;
......@@ -279,7 +279,7 @@ test "dictionary decoder" {
279279 length: u32, // Length of copy or insertion
280280 };
281281
282 var poem_refs = [_]PoemRefs{
282 const poem_refs = [_]PoemRefs{
283283 .{ .dist = 0, .length = 38 }, .{ .dist = 33, .length = 3 }, .{ .dist = 0, .length = 48 },
284284 .{ .dist = 79, .length = 3 }, .{ .dist = 0, .length = 11 }, .{ .dist = 34, .length = 5 },
285285 .{ .dist = 0, .length = 6 }, .{ .dist = 23, .length = 7 }, .{ .dist = 0, .length = 8 },
......@@ -368,7 +368,7 @@ test "dictionary decoder" {
368368 fn writeString(dst_dd: *DictDecoder, dst: anytype, str: []const u8) !void {
369369 var string = str;
370370 while (string.len > 0) {
371 var cnt = DictDecoder.copy(dst_dd.writeSlice(), string);
371 const cnt = DictDecoder.copy(dst_dd.writeSlice(), string);
372372 dst_dd.writeMark(cnt);
373373 string = string[cnt..];
374374 if (dst_dd.availWrite() == 0) {
lib/std/compress/deflate/huffman_bit_writer.zig+43-43
......@@ -134,7 +134,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
134134 self.bits |= @as(u64, @intCast(b)) << @as(u6, @intCast(self.nbits));
135135 self.nbits += nb;
136136 if (self.nbits >= 48) {
137 var bits = self.bits;
137 const bits = self.bits;
138138 self.bits >>= 48;
139139 self.nbits -= 48;
140140 var n = self.nbytes;
......@@ -224,7 +224,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
224224 while (size != bad_code) : (in_index += 1) {
225225 // INVARIANT: We have seen "count" copies of size that have not yet
226226 // had output generated for them.
227 var next_size = codegen[in_index];
227 const next_size = codegen[in_index];
228228 if (next_size == size) {
229229 count += 1;
230230 continue;
......@@ -295,12 +295,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
295295 while (num_codegens > 4 and self.codegen_freq[codegen_order[num_codegens - 1]] == 0) {
296296 num_codegens -= 1;
297297 }
298 var header = 3 + 5 + 5 + 4 + (3 * num_codegens) +
298 const header = 3 + 5 + 5 + 4 + (3 * num_codegens) +
299299 self.codegen_encoding.bitLength(self.codegen_freq[0..]) +
300300 self.codegen_freq[16] * 2 +
301301 self.codegen_freq[17] * 3 +
302302 self.codegen_freq[18] * 7;
303 var size = header +
303 const size = header +
304304 lit_enc.bitLength(self.literal_freq) +
305305 off_enc.bitLength(self.offset_freq) +
306306 extra_bits;
......@@ -339,7 +339,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
339339 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));
340340 self.nbits += @as(u32, @intCast(c.len));
341341 if (self.nbits >= 48) {
342 var bits = self.bits;
342 const bits = self.bits;
343343 self.bits >>= 48;
344344 self.nbits -= 48;
345345 var n = self.nbytes;
......@@ -386,13 +386,13 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
386386
387387 var i: u32 = 0;
388388 while (i < num_codegens) : (i += 1) {
389 var value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len));
389 const value = @as(u32, @intCast(self.codegen_encoding.codes[codegen_order[i]].len));
390390 try self.writeBits(@as(u32, @intCast(value)), 3);
391391 }
392392
393393 i = 0;
394394 while (true) {
395 var code_word: u32 = @as(u32, @intCast(self.codegen[i]));
395 const code_word: u32 = @as(u32, @intCast(self.codegen[i]));
396396 i += 1;
397397 if (code_word == bad_code) {
398398 break;
......@@ -458,14 +458,14 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
458458 return;
459459 }
460460
461 var lit_and_off = self.indexTokens(tokens);
462 var num_literals = lit_and_off.num_literals;
463 var num_offsets = lit_and_off.num_offsets;
461 const lit_and_off = self.indexTokens(tokens);
462 const num_literals = lit_and_off.num_literals;
463 const num_offsets = lit_and_off.num_offsets;
464464
465465 var extra_bits: u32 = 0;
466 var ret = storedSizeFits(input);
467 var stored_size = ret.size;
468 var storable = ret.storable;
466 const ret = storedSizeFits(input);
467 const stored_size = ret.size;
468 const storable = ret.storable;
469469
470470 if (storable) {
471471 // We only bother calculating the costs of the extra bits required by
......@@ -504,12 +504,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
504504 &self.offset_encoding,
505505 );
506506 self.codegen_encoding.generate(self.codegen_freq[0..], 7);
507 var dynamic_size = self.dynamicSize(
507 const dynamic_size = self.dynamicSize(
508508 &self.literal_encoding,
509509 &self.offset_encoding,
510510 extra_bits,
511511 );
512 var dyn_size = dynamic_size.size;
512 const dyn_size = dynamic_size.size;
513513 num_codegens = dynamic_size.num_codegens;
514514
515515 if (dyn_size < size) {
......@@ -551,9 +551,9 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
551551 return;
552552 }
553553
554 var total_tokens = self.indexTokens(tokens);
555 var num_literals = total_tokens.num_literals;
556 var num_offsets = total_tokens.num_offsets;
554 const total_tokens = self.indexTokens(tokens);
555 const num_literals = total_tokens.num_literals;
556 const num_offsets = total_tokens.num_offsets;
557557
558558 // Generate codegen and codegenFrequencies, which indicates how to encode
559559 // the literal_encoding and the offset_encoding.
......@@ -564,15 +564,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
564564 &self.offset_encoding,
565565 );
566566 self.codegen_encoding.generate(self.codegen_freq[0..], 7);
567 var dynamic_size = self.dynamicSize(&self.literal_encoding, &self.offset_encoding, 0);
568 var size = dynamic_size.size;
569 var num_codegens = dynamic_size.num_codegens;
567 const dynamic_size = self.dynamicSize(&self.literal_encoding, &self.offset_encoding, 0);
568 const size = dynamic_size.size;
569 const num_codegens = dynamic_size.num_codegens;
570570
571571 // Store bytes, if we don't get a reasonable improvement.
572572
573 var stored_size = storedSizeFits(input);
574 var ssize = stored_size.size;
575 var storable = stored_size.storable;
573 const stored_size = storedSizeFits(input);
574 const ssize = stored_size.size;
575 const storable = stored_size.storable;
576576 if (storable and ssize < (size + (size >> 4))) {
577577 try self.writeStoredHeader(input.?.len, eof);
578578 try self.writeBytes(input.?);
......@@ -611,8 +611,8 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
611611 self.literal_freq[token.literal(t)] += 1;
612612 continue;
613613 }
614 var length = token.length(t);
615 var offset = token.offset(t);
614 const length = token.length(t);
615 const offset = token.offset(t);
616616 self.literal_freq[length_codes_start + token.lengthCode(length)] += 1;
617617 self.offset_freq[token.offsetCode(offset)] += 1;
618618 }
......@@ -660,21 +660,21 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
660660 continue;
661661 }
662662 // Write the length
663 var length = token.length(t);
664 var length_code = token.lengthCode(length);
663 const length = token.length(t);
664 const length_code = token.lengthCode(length);
665665 try self.writeCode(le_codes[length_code + length_codes_start]);
666 var extra_length_bits = @as(u32, @intCast(length_extra_bits[length_code]));
666 const extra_length_bits = @as(u32, @intCast(length_extra_bits[length_code]));
667667 if (extra_length_bits > 0) {
668 var extra_length = @as(u32, @intCast(length - length_base[length_code]));
668 const extra_length = @as(u32, @intCast(length - length_base[length_code]));
669669 try self.writeBits(extra_length, extra_length_bits);
670670 }
671671 // Write the offset
672 var offset = token.offset(t);
673 var offset_code = token.offsetCode(offset);
672 const offset = token.offset(t);
673 const offset_code = token.offsetCode(offset);
674674 try self.writeCode(oe_codes[offset_code]);
675 var extra_offset_bits = @as(u32, @intCast(offset_extra_bits[offset_code]));
675 const extra_offset_bits = @as(u32, @intCast(offset_extra_bits[offset_code]));
676676 if (extra_offset_bits > 0) {
677 var extra_offset = @as(u32, @intCast(offset - offset_base[offset_code]));
677 const extra_offset = @as(u32, @intCast(offset - offset_base[offset_code]));
678678 try self.writeBits(extra_offset, extra_offset_bits);
679679 }
680680 }
......@@ -718,15 +718,15 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
718718 &self.huff_offset,
719719 );
720720 self.codegen_encoding.generate(self.codegen_freq[0..], 7);
721 var dynamic_size = self.dynamicSize(&self.literal_encoding, &self.huff_offset, 0);
722 var size = dynamic_size.size;
721 const dynamic_size = self.dynamicSize(&self.literal_encoding, &self.huff_offset, 0);
722 const size = dynamic_size.size;
723723 num_codegens = dynamic_size.num_codegens;
724724
725725 // Store bytes, if we don't get a reasonable improvement.
726726
727 var stored_size_ret = storedSizeFits(input);
728 var ssize = stored_size_ret.size;
729 var storable = stored_size_ret.storable;
727 const stored_size_ret = storedSizeFits(input);
728 const ssize = stored_size_ret.size;
729 const storable = stored_size_ret.storable;
730730
731731 if (storable and ssize < (size + (size >> 4))) {
732732 try self.writeStoredHeader(input.len, eof);
......@@ -736,18 +736,18 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type {
736736
737737 // Huffman.
738738 try self.writeDynamicHeader(num_literals, num_offsets, num_codegens, eof);
739 var encoding = self.literal_encoding.codes[0..257];
739 const encoding = self.literal_encoding.codes[0..257];
740740 var n = self.nbytes;
741741 for (input) |t| {
742742 // Bitwriting inlined, ~30% speedup
743 var c = encoding[t];
743 const c = encoding[t];
744744 self.bits |= @as(u64, @intCast(c.code)) << @as(u6, @intCast(self.nbits));
745745 self.nbits += @as(u32, @intCast(c.len));
746746 if (self.nbits < 48) {
747747 continue;
748748 }
749749 // Store 6 bytes
750 var bits = self.bits;
750 const bits = self.bits;
751751 self.bits >>= 48;
752752 self.nbits -= 48;
753753 var bytes = self.bytes[n..][0..6];
......@@ -1679,7 +1679,7 @@ fn testWriterEOF(ttype: TestType, ht_tokens: []const token.Token, input: []const
16791679
16801680 try bw.flush();
16811681
1682 var b = buf.items;
1682 const b = buf.items;
16831683 try expect(b.len > 0);
16841684 try expect(b[0] & 1 == 1);
16851685}
lib/std/compress/deflate/huffman_code.zig+8-8
......@@ -96,7 +96,7 @@ pub const HuffmanEncoder = struct {
9696 mem.sort(LiteralNode, self.lfs, {}, byFreq);
9797
9898 // Get the number of literals for each bit count
99 var bit_count = self.bitCounts(list, max_bits);
99 const bit_count = self.bitCounts(list, max_bits);
100100 // And do the assignment
101101 self.assignEncodingAndSize(bit_count, list);
102102 }
......@@ -128,7 +128,7 @@ pub const HuffmanEncoder = struct {
128128 // that should be encoded in i bits.
129129 fn bitCounts(self: *HuffmanEncoder, list: []LiteralNode, max_bits_to_use: usize) []u32 {
130130 var max_bits = max_bits_to_use;
131 var n = list.len;
131 const n = list.len;
132132
133133 assert(max_bits < max_bits_limit);
134134
......@@ -184,10 +184,10 @@ pub const HuffmanEncoder = struct {
184184 continue;
185185 }
186186
187 var prev_freq = l.last_freq;
187 const prev_freq = l.last_freq;
188188 if (l.next_char_freq < l.next_pair_freq) {
189189 // The next item on this row is a leaf node.
190 var next = leaf_counts[level][level] + 1;
190 const next = leaf_counts[level][level] + 1;
191191 l.last_freq = l.next_char_freq;
192192 // Lower leaf_counts are the same of the previous node.
193193 leaf_counts[level][level] = next;
......@@ -236,7 +236,7 @@ pub const HuffmanEncoder = struct {
236236
237237 var bit_count = self.bit_count[0 .. max_bits + 1];
238238 var bits: u32 = 1;
239 var counts = &leaf_counts[max_bits];
239 const counts = &leaf_counts[max_bits];
240240 {
241241 var level = max_bits;
242242 while (level > 0) : (level -= 1) {
......@@ -267,7 +267,7 @@ pub const HuffmanEncoder = struct {
267267 // are encoded using "bits" bits, and get the values
268268 // code, code + 1, .... The code values are
269269 // assigned in literal order (not frequency order).
270 var chunk = list[list.len - @as(u32, @intCast(bits)) ..];
270 const chunk = list[list.len - @as(u32, @intCast(bits)) ..];
271271
272272 self.lns = chunk;
273273 mem.sort(LiteralNode, self.lns, {}, byLiteral);
......@@ -303,7 +303,7 @@ pub fn newHuffmanEncoder(allocator: Allocator, size: u32) !HuffmanEncoder {
303303
304304// Generates a HuffmanCode corresponding to the fixed literal table
305305pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder {
306 var h = try newHuffmanEncoder(allocator, deflate_const.max_num_frequencies);
306 const h = try newHuffmanEncoder(allocator, deflate_const.max_num_frequencies);
307307 var codes = h.codes;
308308 var ch: u16 = 0;
309309
......@@ -338,7 +338,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder {
338338}
339339
340340pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder {
341 var h = try newHuffmanEncoder(allocator, 30);
341 const h = try newHuffmanEncoder(allocator, 30);
342342 var codes = h.codes;
343343 for (codes, 0..) |_, ch| {
344344 codes[ch] = HuffCode{ .code = bu.bitReverse(u16, @as(u16, @intCast(ch)), 5), .len = 5 };
lib/std/compress/zstandard.zig+1-1
......@@ -268,7 +268,7 @@ test "zstandard decompression" {
268268 const compressed3 = @embedFile("testdata/rfc8478.txt.zst.3");
269269 const compressed19 = @embedFile("testdata/rfc8478.txt.zst.19");
270270
271 var buffer = try std.testing.allocator.alloc(u8, uncompressed.len);
271 const buffer = try std.testing.allocator.alloc(u8, uncompressed.len);
272272 defer std.testing.allocator.free(buffer);
273273
274274 const res3 = try decompress.decode(buffer, compressed3, true);
lib/std/compress/zstandard/decode/huffman.zig+1-1
......@@ -54,7 +54,7 @@ fn decodeFseHuffmanTreeSlice(src: []const u8, compressed_size: usize, weights: *
5454
5555 const start_index = std.math.cast(usize, counting_reader.bytes_read) orelse
5656 return error.MalformedHuffmanTree;
57 var huff_data = src[start_index..compressed_size];
57 const huff_data = src[start_index..compressed_size];
5858 var huff_bits: readers.ReverseBitReader = undefined;
5959 huff_bits.init(huff_data) catch return error.MalformedHuffmanTree;
6060
lib/std/compress/zstandard/decompress.zig+2-2
......@@ -304,7 +304,7 @@ pub fn decodeZstandardFrame(
304304
305305 var frame_context = context: {
306306 var fbs = std.io.fixedBufferStream(src[consumed_count..]);
307 var source = fbs.reader();
307 const source = fbs.reader();
308308 const frame_header = try decodeZstandardHeader(source);
309309 consumed_count += fbs.pos;
310310 break :context FrameContext.init(
......@@ -447,7 +447,7 @@ pub fn decodeZstandardFrameArrayList(
447447
448448 var frame_context = context: {
449449 var fbs = std.io.fixedBufferStream(src[consumed_count..]);
450 var source = fbs.reader();
450 const source = fbs.reader();
451451 const frame_header = try decodeZstandardHeader(source);
452452 consumed_count += fbs.pos;
453453 break :context try FrameContext.init(frame_header, window_size_max, verify_checksum);
lib/std/crypto/25519/curve25519.zig+1-1
......@@ -129,7 +129,7 @@ test "non-affine edwards25519 to curve25519 projection" {
129129 const skh = "90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e";
130130 var sk: [32]u8 = undefined;
131131 _ = std.fmt.hexToBytes(&sk, skh) catch unreachable;
132 var edp = try crypto.ecc.Edwards25519.basePoint.mul(sk);
132 const edp = try crypto.ecc.Edwards25519.basePoint.mul(sk);
133133 const xp = try Curve25519.fromEdwards25519(edp);
134134 const expected_hex = "cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378";
135135 var expected: [32]u8 = undefined;
lib/std/crypto/25519/field.zig+1-1
......@@ -416,7 +416,7 @@ pub const Fe = struct {
416416
417417 /// Compute the square root of `x2`, returning `error.NotSquare` if `x2` was not a square
418418 pub fn sqrt(x2: Fe) NotSquareError!Fe {
419 var x2_copy = x2;
419 const x2_copy = x2;
420420 const x = x2.uncheckedSqrt();
421421 const check = x.sq().sub(x2_copy);
422422 if (check.isZero()) {
lib/std/crypto/Certificate.zig+1-1
......@@ -982,7 +982,7 @@ pub const rsa = struct {
982982 if (mgf_len > mgf_out_buf.len) { // Modulus > 4096 bits
983983 return error.InvalidSignature;
984984 }
985 var mgf_out = mgf_out_buf[0 .. ((mgf_len - 1) / Hash.digest_length + 1) * Hash.digest_length];
985 const mgf_out = mgf_out_buf[0 .. ((mgf_len - 1) / Hash.digest_length + 1) * Hash.digest_length];
986986 var dbMask = try MGF1(Hash, mgf_out, h, mgf_len);
987987
988988 // 8. Let DB = maskedDB \xor dbMask.
lib/std/crypto/aes.zig+1-1
......@@ -47,7 +47,7 @@ test "ctr" {
4747 };
4848
4949 var out: [exp_out.len]u8 = undefined;
50 var ctx = Aes128.initEnc(key);
50 const ctx = Aes128.initEnc(key);
5151 ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.big);
5252 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
5353}
lib/std/crypto/aes_ocb.zig+1-1
......@@ -95,7 +95,7 @@ fn AesOcb(comptime Aes: anytype) type {
9595 var ktop_: Block = undefined;
9696 aes_enc_ctx.encrypt(&ktop_, &nx);
9797 const ktop = mem.readInt(u128, &ktop_, .big);
98 var stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56)));
98 const stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56)));
9999 var offset: Block = undefined;
100100 mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .big);
101101 return offset;
lib/std/crypto/argon2.zig+1-1
......@@ -565,7 +565,7 @@ const PhcFormatHasher = struct {
565565 const expected_hash = hash_result.hash.constSlice();
566566 var hash_buf: [max_hash_len]u8 = undefined;
567567 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;
568 var hash = hash_buf[0..expected_hash.len];
568 const hash = hash_buf[0..expected_hash.len];
569569
570570 try kdf(allocator, hash, password, hash_result.salt.constSlice(), params, mode);
571571 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;
lib/std/crypto/ascon.zig+1-2
......@@ -42,8 +42,7 @@ pub fn State(comptime endian: std.builtin.Endian) type {
4242
4343 /// Initialize the state from u64 words in native endianness.
4444 pub fn initFromWords(initial_state: [5]u64) Self {
45 var state = Self{ .st = initial_state };
46 return state;
45 return .{ .st = initial_state };
4746 }
4847
4948 /// Initialize the state for Ascon XOF
lib/std/crypto/bcrypt.zig+1-1
......@@ -431,7 +431,7 @@ pub fn bcrypt(
431431 const trimmed_len = @min(password.len, password_buf.len - 1);
432432 @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]);
433433 password_buf[trimmed_len] = 0;
434 var passwordZ = password_buf[0 .. trimmed_len + 1];
434 const passwordZ = password_buf[0 .. trimmed_len + 1];
435435 state.expand(salt[0..], passwordZ);
436436
437437 const rounds: u64 = @as(u64, 1) << params.rounds_log;
lib/std/crypto/blake3.zig+1-1
......@@ -241,7 +241,7 @@ const Output = struct {
241241 var out_block_it = ChunkIterator.init(output, 2 * OUT_LEN);
242242 var output_block_counter: usize = 0;
243243 while (out_block_it.next()) |out_block| {
244 var words = compress(
244 const words = compress(
245245 self.input_chaining_value,
246246 self.block_words,
247247 self.block_len,
lib/std/crypto/ecdsa.zig+1-1
......@@ -201,7 +201,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
201201 const scalar_encoded_length = Curve.scalar.encoded_length;
202202 const h_len = @max(Hash.digest_length, scalar_encoded_length);
203203 var h: [h_len]u8 = [_]u8{0} ** h_len;
204 var h_slice = h[h_len - Hash.digest_length .. h_len];
204 const h_slice = h[h_len - Hash.digest_length .. h_len];
205205 self.h.final(h_slice);
206206
207207 std.debug.assert(h.len >= scalar_encoded_length);
lib/std/crypto/pbkdf2.zig+2-4
......@@ -255,10 +255,8 @@ test "Very large dk_len" {
255255 const c = 1;
256256 const dk_len = 1 << 33;
257257
258 var dk = try std.testing.allocator.alloc(u8, dk_len);
259 defer {
260 std.testing.allocator.free(dk);
261 }
258 const dk = try std.testing.allocator.alloc(u8, dk_len);
259 defer std.testing.allocator.free(dk);
262260
263261 // Just verify this doesn't crash with an overflow
264262 try pbkdf2(dk, p, s, c, HmacSha1);
lib/std/crypto/pcurves/common.zig+1-1
......@@ -71,7 +71,7 @@ pub fn Field(comptime params: FieldParams) type {
7171
7272 /// Unpack a field element.
7373 pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe {
74 var s = if (endian == .little) s_ else orderSwap(s_);
74 const s = if (endian == .little) s_ else orderSwap(s_);
7575 try rejectNonCanonical(s, .little);
7676 var limbs_z: NonMontgomeryDomainFieldElement = undefined;
7777 fiat.fromBytes(&limbs_z, s);
lib/std/crypto/poly1305.zig+3-3
......@@ -90,8 +90,8 @@ pub const Poly1305 = struct {
9090 h2 = t2 & 3;
9191
9292 // Add c*(4+1)
93 var cclo = t2 & ~@as(u64, 3);
94 var cchi = t3;
93 const cclo = t2 & ~@as(u64, 3);
94 const cchi = t3;
9595 v = @addWithOverflow(h0, cclo);
9696 h0 = v[0];
9797 v = add(h1, cchi, v[1]);
......@@ -163,7 +163,7 @@ pub const Poly1305 = struct {
163163
164164 var h0 = st.h[0];
165165 var h1 = st.h[1];
166 var h2 = st.h[2];
166 const h2 = st.h[2];
167167
168168 // H - (2^130 - 5)
169169 var v = @subWithOverflow(h0, 0xfffffffffffffffb);
lib/std/crypto/salsa20.zig+3-3
......@@ -605,8 +605,8 @@ test "xsalsa20poly1305 box" {
605605 crypto.random.bytes(&msg);
606606 crypto.random.bytes(&nonce);
607607
608 var kp1 = try Box.KeyPair.create(null);
609 var kp2 = try Box.KeyPair.create(null);
608 const kp1 = try Box.KeyPair.create(null);
609 const kp2 = try Box.KeyPair.create(null);
610610 try Box.seal(boxed[0..], msg[0..], nonce, kp1.public_key, kp2.secret_key);
611611 try Box.open(msg2[0..], boxed[0..], nonce, kp2.public_key, kp1.secret_key);
612612}
......@@ -617,7 +617,7 @@ test "xsalsa20poly1305 sealedbox" {
617617 var boxed: [msg.len + SealedBox.seal_length]u8 = undefined;
618618 crypto.random.bytes(&msg);
619619
620 var kp = try Box.KeyPair.create(null);
620 const kp = try Box.KeyPair.create(null);
621621 try SealedBox.seal(boxed[0..], msg[0..], kp.public_key);
622622 try SealedBox.open(msg2[0..], boxed[0..], kp);
623623}
lib/std/crypto/scrypt.zig+7-7
......@@ -87,8 +87,8 @@ fn integerify(b: []align(16) const u32, r: u30) u64 {
8787}
8888
8989fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void {
90 var x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]);
91 var y: []align(16) u32 = @alignCast(xy[32 * r ..]);
90 const x: []align(16) u32 = @alignCast(xy[0 .. 32 * r]);
91 const y: []align(16) u32 = @alignCast(xy[32 * r ..]);
9292
9393 for (x, 0..) |*v1, j| {
9494 v1.* = mem.readInt(u32, b[4 * j ..][0..4], .little);
......@@ -191,9 +191,9 @@ pub fn kdf(
191191 params.r > max_int / 256 or
192192 n > max_int / 128 / @as(u64, params.r)) return KdfError.WeakParameters;
193193
194 var xy = try allocator.alignedAlloc(u32, 16, 64 * params.r);
194 const xy = try allocator.alignedAlloc(u32, 16, 64 * params.r);
195195 defer allocator.free(xy);
196 var v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r);
196 const v = try allocator.alignedAlloc(u32, 16, 32 * n * params.r);
197197 defer allocator.free(v);
198198 var dk = try allocator.alignedAlloc(u8, 16, params.p * 128 * params.r);
199199 defer allocator.free(dk);
......@@ -263,7 +263,7 @@ const crypt_format = struct {
263263 const value = self.constSlice();
264264 const len = Codec.encodedLen(value.len);
265265 if (len > buf.len) return EncodingError.NoSpaceLeft;
266 var encoded = buf[0..len];
266 const encoded = buf[0..len];
267267 Codec.encode(encoded, value);
268268 return encoded;
269269 }
......@@ -439,7 +439,7 @@ const PhcFormatHasher = struct {
439439 const expected_hash = hash_result.hash.constSlice();
440440 var hash_buf: [max_hash_len]u8 = undefined;
441441 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;
442 var hash = hash_buf[0..expected_hash.len];
442 const hash = hash_buf[0..expected_hash.len];
443443 try kdf(allocator, hash, password, hash_result.salt.constSlice(), params);
444444 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;
445445 }
......@@ -487,7 +487,7 @@ const CryptFormatHasher = struct {
487487 const expected_hash = hash_result.hash.constSlice();
488488 var hash_buf: [max_hash_len]u8 = undefined;
489489 if (expected_hash.len > hash_buf.len) return HasherError.InvalidEncoding;
490 var hash = hash_buf[0..expected_hash.len];
490 const hash = hash_buf[0..expected_hash.len];
491491 try kdf(allocator, hash, password, hash_result.salt, params);
492492 if (!mem.eql(u8, hash, expected_hash)) return HasherError.PasswordVerificationFailed;
493493 }
lib/std/crypto/tls/Client.zig+3-3
......@@ -491,7 +491,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
491491 try all_extd.ensure(4);
492492 const et = all_extd.decode(tls.ExtensionType);
493493 const ext_size = all_extd.decode(u16);
494 var extd = try all_extd.sub(ext_size);
494 const extd = try all_extd.sub(ext_size);
495495 _ = extd;
496496 switch (et) {
497497 .server_name => {},
......@@ -516,7 +516,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
516516 while (!certs_decoder.eof()) {
517517 try certs_decoder.ensure(3);
518518 const cert_size = certs_decoder.decode(u24);
519 var certd = try certs_decoder.sub(cert_size);
519 const certd = try certs_decoder.sub(cert_size);
520520
521521 const subject_cert: Certificate = .{
522522 .buffer = certd.buf,
......@@ -552,7 +552,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
552552
553553 try certs_decoder.ensure(2);
554554 const total_ext_size = certs_decoder.decode(u16);
555 var all_extd = try certs_decoder.sub(total_ext_size);
555 const all_extd = try certs_decoder.sub(total_ext_size);
556556 _ = all_extd;
557557 }
558558 },
lib/std/debug.zig+4-4
......@@ -812,7 +812,7 @@ pub fn writeStackTraceWindows(
812812 var addr_buf: [1024]usize = undefined;
813813 const n = walkStackWindows(addr_buf[0..], context);
814814 const addrs = addr_buf[0..n];
815 var start_i: usize = if (start_addr) |saddr| blk: {
815 const start_i: usize = if (start_addr) |saddr| blk: {
816816 for (addrs, 0..) |addr, i| {
817817 if (addr == saddr) break :blk i;
818818 }
......@@ -1158,7 +1158,7 @@ pub fn readElfDebugInfo(
11581158 var zlib_stream = std.compress.zlib.decompressStream(allocator, section_stream.reader()) catch continue;
11591159 defer zlib_stream.deinit();
11601160
1161 var decompressed_section = try allocator.alloc(u8, chdr.ch_size);
1161 const decompressed_section = try allocator.alloc(u8, chdr.ch_size);
11621162 errdefer allocator.free(decompressed_section);
11631163
11641164 const read = zlib_stream.reader().readAll(decompressed_section) catch continue;
......@@ -2046,7 +2046,7 @@ pub const ModuleDebugInfo = switch (native_os) {
20462046 };
20472047
20482048 try DW.openDwarfDebugInfo(&di, allocator);
2049 var info = OFileInfo{
2049 const info = OFileInfo{
20502050 .di = di,
20512051 .addr_table = addr_table,
20522052 };
......@@ -2122,7 +2122,7 @@ pub const ModuleDebugInfo = switch (native_os) {
21222122
21232123 // Check if its debug infos are already in the cache
21242124 const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0);
2125 var o_file_info = self.ofiles.getPtr(o_file_path) orelse
2125 const o_file_info = self.ofiles.getPtr(o_file_path) orelse
21262126 (self.loadOFile(allocator, o_file_path) catch |err| switch (err) {
21272127 error.FileNotFound,
21282128 error.MissingDebugInfo,
lib/std/dwarf.zig+5-5
......@@ -622,7 +622,7 @@ fn parseFormValue(allocator: mem.Allocator, in_stream: anytype, form_id: u64, en
622622 return parseFormValue(allocator, in_stream, child_form_id, endian, is_64);
623623 }
624624 const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64));
625 var frame = try allocator.create(F);
625 const frame = try allocator.create(F);
626626 defer allocator.destroy(frame);
627627 return await @asyncCall(frame, {}, parseFormValue, .{ allocator, in_stream, child_form_id, endian, is_64 });
628628 },
......@@ -1034,7 +1034,7 @@ pub const DwarfInfo = struct {
10341034 // specified by DW_AT.low_pc or to some other value encoded
10351035 // in the list itself.
10361036 // If no starting value is specified use zero.
1037 var base_address = compile_unit.die.getAttrAddr(di, AT.low_pc, compile_unit.*) catch |err| switch (err) {
1037 const base_address = compile_unit.die.getAttrAddr(di, AT.low_pc, compile_unit.*) catch |err| switch (err) {
10381038 error.MissingDebugInfo => @as(u64, 0), // TODO https://github.com/ziglang/zig/issues/11135
10391039 else => return err,
10401040 };
......@@ -1438,7 +1438,7 @@ pub const DwarfInfo = struct {
14381438 if (opcode == LNS.extended_op) {
14391439 const op_size = try leb.readULEB128(u64, in);
14401440 if (op_size < 1) return badDwarf();
1441 var sub_op = try in.readByte();
1441 const sub_op = try in.readByte();
14421442 switch (sub_op) {
14431443 LNE.end_sequence => {
14441444 prog.end_sequence = true;
......@@ -2308,7 +2308,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo
23082308 else => return badDwarf(),
23092309 };
23102310
2311 var base = switch (enc & EH.PE.rel_mask) {
2311 const base = switch (enc & EH.PE.rel_mask) {
23122312 EH.PE.pcrel => ctx.pc_rel_base,
23132313 EH.PE.textrel => ctx.text_rel_base orelse return error.PointerBaseNotSpecified,
23142314 EH.PE.datarel => ctx.data_rel_base orelse return error.PointerBaseNotSpecified,
......@@ -2624,7 +2624,7 @@ pub const CommonInformationEntry = struct {
26242624 var has_aug_data = false;
26252625
26262626 var aug_str_len: usize = 0;
2627 var aug_str_start = stream.pos;
2627 const aug_str_start = stream.pos;
26282628 var aug_byte = try reader.readByte();
26292629 while (aug_byte != 0) : (aug_byte = try reader.readByte()) {
26302630 switch (aug_byte) {
lib/std/dwarf/expressions.zig+4-4
......@@ -443,7 +443,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
443443 OP.xderef_type,
444444 => {
445445 if (self.stack.items.len == 0) return error.InvalidExpression;
446 var addr = try self.stack.items[self.stack.items.len - 1].asIntegral();
446 const addr = try self.stack.items[self.stack.items.len - 1].asIntegral();
447447 const addr_space_identifier: ?usize = switch (opcode) {
448448 OP.xderef,
449449 OP.xderef_size,
......@@ -1350,7 +1350,7 @@ test "DWARF expressions" {
13501350
13511351 // Arithmetic and Logical Operations
13521352 {
1353 var context = ExpressionContext{};
1353 const context = ExpressionContext{};
13541354
13551355 stack_machine.reset();
13561356 program.clearRetainingCapacity();
......@@ -1474,7 +1474,7 @@ test "DWARF expressions" {
14741474
14751475 // Control Flow Operations
14761476 {
1477 var context = ExpressionContext{};
1477 const context = ExpressionContext{};
14781478 const expected = .{
14791479 .{ OP.le, 1, 1, 0 },
14801480 .{ OP.ge, 1, 0, 1 },
......@@ -1531,7 +1531,7 @@ test "DWARF expressions" {
15311531
15321532 // Type conversions
15331533 {
1534 var context = ExpressionContext{};
1534 const context = ExpressionContext{};
15351535 stack_machine.reset();
15361536 program.clearRetainingCapacity();
15371537
lib/std/enums.zig+4-1
......@@ -123,6 +123,7 @@ pub fn directEnumArray(
123123test "std.enums.directEnumArray" {
124124 const E = enum(i4) { a = 4, b = 6, c = 2 };
125125 var runtime_false: bool = false;
126 _ = &runtime_false;
126127 const array = directEnumArray(E, bool, 4, .{
127128 .a = true,
128129 .b = runtime_false,
......@@ -165,6 +166,7 @@ pub fn directEnumArrayDefault(
165166test "std.enums.directEnumArrayDefault" {
166167 const E = enum(i4) { a = 4, b = 6, c = 2 };
167168 var runtime_false: bool = false;
169 _ = &runtime_false;
168170 const array = directEnumArrayDefault(E, bool, false, 4, .{
169171 .a = true,
170172 .b = runtime_false,
......@@ -179,6 +181,7 @@ test "std.enums.directEnumArrayDefault" {
179181test "std.enums.directEnumArrayDefault slice" {
180182 const E = enum(i4) { a = 4, b = 6, c = 2 };
181183 var runtime_b = "b";
184 _ = &runtime_b;
182185 const array = directEnumArrayDefault(E, []const u8, "default", 4, .{
183186 .a = "a",
184187 .b = runtime_b,
......@@ -196,7 +199,7 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
196199 return comptime blk: {
197200 const V = @TypeOf(value);
198201 if (V == E) break :blk value;
199 var name: ?[]const u8 = switch (@typeInfo(V)) {
202 const name: ?[]const u8 = switch (@typeInfo(V)) {
200203 .EnumLiteral, .Enum => @tagName(value),
201204 .Pointer => if (std.meta.trait.isZigString(V)) value else null,
202205 else => null,
lib/std/event/group.zig+1-1
......@@ -66,7 +66,7 @@ pub fn Group(comptime ReturnType: type) type {
6666 /// `func` must be async and have return type `ReturnType`.
6767 /// Thread-safe.
6868 pub fn call(self: *Self, comptime func: anytype, args: anytype) error{OutOfMemory}!void {
69 var frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args)));
69 const frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args)));
7070 errdefer self.allocator.destroy(frame);
7171 const node = try self.allocator.create(AllocStack.Node);
7272 errdefer self.allocator.destroy(node);
lib/std/event/loop.zig+1-1
......@@ -753,7 +753,7 @@ pub const Loop = struct {
753753 }
754754 };
755755
756 var run_frame = try alloc.create(@Frame(Wrapper.run));
756 const run_frame = try alloc.create(@Frame(Wrapper.run));
757757 run_frame.* = async Wrapper.run(args, self, alloc);
758758 }
759759
lib/std/event/rwlock.zig+4-4
......@@ -228,7 +228,7 @@ test "std.event.RwLock" {
228228}
229229fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {
230230 var read_nodes: [100]Loop.NextTickNode = undefined;
231 for (read_nodes) |*read_node| {
231 for (&read_nodes) |*read_node| {
232232 const frame = allocator.create(@Frame(readRunner)) catch @panic("memory");
233233 read_node.data = frame;
234234 frame.* = async readRunner(lock);
......@@ -236,19 +236,19 @@ fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void {
236236 }
237237
238238 var write_nodes: [shared_it_count]Loop.NextTickNode = undefined;
239 for (write_nodes) |*write_node| {
239 for (&write_nodes) |*write_node| {
240240 const frame = allocator.create(@Frame(writeRunner)) catch @panic("memory");
241241 write_node.data = frame;
242242 frame.* = async writeRunner(lock);
243243 Loop.instance.?.onNextTick(write_node);
244244 }
245245
246 for (write_nodes) |*write_node| {
246 for (&write_nodes) |*write_node| {
247247 const casted = @as(*const @Frame(writeRunner), @ptrCast(write_node.data));
248248 await casted;
249249 allocator.destroy(casted);
250250 }
251 for (read_nodes) |*read_node| {
251 for (&read_nodes) |*read_node| {
252252 const casted = @as(*const @Frame(readRunner), @ptrCast(read_node.data));
253253 await casted;
254254 allocator.destroy(casted);
lib/std/fmt.zig+11-9
......@@ -1296,10 +1296,10 @@ pub fn formatFloatDecimal(
12961296 errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal);
12971297
12981298 // exp < 0 means the leading is always 0 as errol result is normalized.
1299 var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
1299 const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
13001300
13011301 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
1302 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
1302 const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
13031303
13041304 if (num_digits_whole > 0) {
13051305 // We may have to zero pad, for instance 1e4 requires zero padding.
......@@ -1354,10 +1354,10 @@ pub fn formatFloatDecimal(
13541354 }
13551355 } else {
13561356 // exp < 0 means the leading is always 0 as errol result is normalized.
1357 var num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
1357 const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
13581358
13591359 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
1360 var num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
1360 const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
13611361
13621362 if (num_digits_whole > 0) {
13631363 // We may have to zero pad, for instance 1e4 requires zero padding.
......@@ -2218,6 +2218,7 @@ test "slice" {
22182218 }
22192219 {
22202220 var runtime_zero: usize = 0;
2221 _ = &runtime_zero;
22212222 const value = @as([*]align(1) const []const u8, @ptrFromInt(0xdeadbeef))[runtime_zero..runtime_zero];
22222223 try expectFmt("slice: []const u8@deadbeef\n", "slice: {*}\n", .{value});
22232224 }
......@@ -2232,6 +2233,7 @@ test "slice" {
22322233 {
22332234 var int_slice = [_]u32{ 1, 4096, 391891, 1111111111 };
22342235 var runtime_zero: usize = 0;
2236 _ = &runtime_zero;
22352237 try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {any}", .{int_slice[runtime_zero..]});
22362238 try expectFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {d}", .{int_slice[runtime_zero..]});
22372239 try expectFmt("int: { 1, 1000, 5fad3, 423a35c7 }", "int: {x}", .{int_slice[runtime_zero..]});
......@@ -2794,14 +2796,14 @@ test "padding" {
27942796}
27952797
27962798test "decimal float padding" {
2797 var number: f32 = 3.1415;
2799 const number: f32 = 3.1415;
27982800 try expectFmt("left-pad: **3.141\n", "left-pad: {d:*>7.3}\n", .{number});
27992801 try expectFmt("center-pad: *3.141*\n", "center-pad: {d:*^7.3}\n", .{number});
28002802 try expectFmt("right-pad: 3.141**\n", "right-pad: {d:*<7.3}\n", .{number});
28012803}
28022804
28032805test "sci float padding" {
2804 var number: f32 = 3.1415;
2806 const number: f32 = 3.1415;
28052807 try expectFmt("left-pad: **3.141e+00\n", "left-pad: {e:*>11.3}\n", .{number});
28062808 try expectFmt("center-pad: *3.141e+00*\n", "center-pad: {e:*^11.3}\n", .{number});
28072809 try expectFmt("right-pad: 3.141e+00**\n", "right-pad: {e:*<11.3}\n", .{number});
......@@ -2825,7 +2827,7 @@ test "named arguments" {
28252827}
28262828
28272829test "runtime width specifier" {
2828 var width: usize = 9;
2830 const width: usize = 9;
28292831 try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });
28302832 try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });
28312833 try expectFmt(" hello", "{s:[1]}", .{ "hello", width });
......@@ -2833,8 +2835,8 @@ test "runtime width specifier" {
28332835}
28342836
28352837test "runtime precision specifier" {
2836 var number: f32 = 3.1415;
2837 var precision: usize = 2;
2838 const number: f32 = 3.1415;
2839 const precision: usize = 2;
28382840 try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });
28392841 try expectFmt("3.14e+00", "{:1.[precision]}", .{ .number = number, .precision = precision });
28402842}
lib/std/fmt/errol.zig+2-2
......@@ -367,8 +367,8 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
367367 var lo = ((fpprev(val) - n) + mid) / 2.0;
368368 var hi = ((fpnext(val) - n) + mid) / 2.0;
369369
370 var buf_index = u64toa(u, buffer);
371 var exp = @as(i32, @intCast(buf_index));
370 const buf_index = u64toa(u, buffer);
371 const exp: i32 = @intCast(buf_index);
372372 var j = buf_index;
373373 buffer[j] = 0;
374374
lib/std/fmt/parse_float/parse.zig+2-2
......@@ -105,7 +105,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
105105 // parse initial digits before dot
106106 var mantissa: MantissaT = 0;
107107 tryParseDigits(MantissaT, stream, &mantissa, info.base);
108 var int_end = stream.offsetTrue();
108 const int_end = stream.offsetTrue();
109109 var n_digits = @as(isize, @intCast(stream.offsetTrue()));
110110 // the base being 16 implies a 0x prefix, which shouldn't be included in the digit count
111111 if (info.base == 16) n_digits -= 2;
......@@ -188,7 +188,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
188188 // than 19 digits. That means we must have a decimal
189189 // point, and at least 1 fractional digit.
190190 stream.advance(1);
191 var marker = stream.offsetTrue();
191 const marker = stream.offsetTrue();
192192 tryParseNDigits(MantissaT, stream, &mantissa, info.base, info.max_mantissa_digits);
193193 break :blk @as(i64, @intCast(marker)) - @as(i64, @intCast(stream.offsetTrue()));
194194 }
lib/std/fs.zig+2-2
......@@ -1689,7 +1689,7 @@ pub const Dir = struct {
16891689 }
16901690 if (builtin.os.tag == .windows) {
16911691 var dir_path_buffer: [os.windows.PATH_MAX_WIDE]u16 = undefined;
1692 var dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer);
1692 const dir_path = try os.windows.GetFinalPathNameByHandle(self.fd, .{}, &dir_path_buffer);
16931693 if (builtin.link_libc) {
16941694 return os.chdirW(dir_path);
16951695 }
......@@ -1810,7 +1810,7 @@ pub const Dir = struct {
18101810 const base_flags = w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA |
18111811 w.SYNCHRONIZE | w.FILE_TRAVERSE;
18121812 const flags: u32 = if (iterable) base_flags | w.FILE_LIST_DIRECTORY else base_flags;
1813 var dir = try self.makeOpenDirAccessMaskW(sub_path_w, flags, .{
1813 const dir = try self.makeOpenDirAccessMaskW(sub_path_w, flags, .{
18141814 .no_follow = args.no_follow,
18151815 .create_disposition = w.FILE_OPEN,
18161816 });
lib/std/fs/get_app_data_dir.zig+4
......@@ -57,6 +57,10 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi
5757 },
5858 .haiku => {
5959 var dir_path_ptr: [*:0]u8 = undefined;
60 if (true) {
61 _ = &dir_path_ptr;
62 @compileError("TODO: init dir_path_ptr");
63 }
6064 // TODO look into directory_which
6165 const be_user_settings = 0xbbe;
6266 const rc = os.system.find_directory(be_user_settings, -1, true, dir_path_ptr, 1);
lib/std/fs/test.zig+1-1
......@@ -80,7 +80,7 @@ const TestContext = struct {
8080 transform_fn: *const PathType.TransformFn,
8181
8282 pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext {
83 var tmp = tmpIterableDir(.{});
83 const tmp = tmpIterableDir(.{});
8484 return .{
8585 .path_type = path_type,
8686 .arena = ArenaAllocator.init(allocator),
lib/std/fs/watch.zig+3-3
......@@ -116,7 +116,7 @@ pub fn Watch(comptime V: type) type {
116116 },
117117 };
118118
119 var buf = try allocator.alloc(Event.Error!Event, event_buf_count);
119 const buf = try allocator.alloc(Event.Error!Event, event_buf_count);
120120 self.channel.init(buf);
121121 self.os_data.putter_frame = async self.linuxEventPutter();
122122 return self;
......@@ -132,7 +132,7 @@ pub fn Watch(comptime V: type) type {
132132 },
133133 };
134134
135 var buf = try allocator.alloc(Event.Error!Event, event_buf_count);
135 const buf = try allocator.alloc(Event.Error!Event, event_buf_count);
136136 self.channel.init(buf);
137137 return self;
138138 },
......@@ -147,7 +147,7 @@ pub fn Watch(comptime V: type) type {
147147 },
148148 };
149149
150 var buf = try allocator.alloc(Event.Error!Event, event_buf_count);
150 const buf = try allocator.alloc(Event.Error!Event, event_buf_count);
151151 self.channel.init(buf);
152152 return self;
153153 },
lib/std/hash/auto_hash.zig+1
......@@ -280,6 +280,7 @@ test "hash slice shallow" {
280280 const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 };
281281 // TODO audit deep/shallow - maybe it has the wrong behavior with respect to array pointers and slices
282282 var runtime_zero: usize = 0;
283 _ = &runtime_zero;
283284 const a = array1[runtime_zero..];
284285 const b = array2[runtime_zero..];
285286 const c = array1[runtime_zero..3];
lib/std/hash/cityhash.zig+1-1
......@@ -271,7 +271,7 @@ pub const CityHash64 = struct {
271271 var b1: u64 = b;
272272 a1 +%= w;
273273 b1 = rotr64(b1 +% a1 +% z, 21);
274 var c: u64 = a1;
274 const c: u64 = a1;
275275 a1 +%= x;
276276 a1 +%= y;
277277 b1 +%= rotr64(a1, 44);
lib/std/hash/murmur.zig+25-31
......@@ -134,7 +134,7 @@ pub const Murmur2_64 = struct {
134134 const m: u64 = 0xc6a4a7935bd1e995;
135135 const len: u64 = 4;
136136 var h1: u64 = seed ^ (len *% m);
137 var k1: u64 = v;
137 const k1: u64 = v;
138138 h1 ^= k1;
139139 h1 *%= m;
140140 h1 ^= h1 >> 47;
......@@ -282,16 +282,14 @@ pub const Murmur3_32 = struct {
282282const verify = @import("verify.zig");
283283
284284test "murmur2_32" {
285 var v0: u32 = 0x12345678;
286 var v1: u64 = 0x1234567812345678;
287 var v0le: u32 = v0;
288 var v1le: u64 = v1;
289 if (native_endian == .big) {
290 v0le = @byteSwap(v0le);
291 v1le = @byteSwap(v1le);
292 }
293 try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0));
294 try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1));
285 const v0: u32 = 0x12345678;
286 const v1: u64 = 0x1234567812345678;
287 const v0le: u32, const v1le: u64 = switch (native_endian) {
288 .little => .{ v0, v1 },
289 .big => .{ @byteSwap(v0), @byteSwap(v1) },
290 };
291 try testing.expectEqual(Murmur2_32.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur2_32.hashUint32(v0));
292 try testing.expectEqual(Murmur2_32.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1));
295293}
296294
297295test "murmur2_32 smhasher" {
......@@ -306,16 +304,14 @@ test "murmur2_32 smhasher" {
306304}
307305
308306test "murmur2_64" {
309 var v0: u32 = 0x12345678;
310 var v1: u64 = 0x1234567812345678;
311 var v0le: u32 = v0;
312 var v1le: u64 = v1;
313 if (native_endian == .big) {
314 v0le = @byteSwap(v0le);
315 v1le = @byteSwap(v1le);
316 }
317 try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0));
318 try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1));
307 const v0: u32 = 0x12345678;
308 const v1: u64 = 0x1234567812345678;
309 const v0le: u32, const v1le: u64 = switch (native_endian) {
310 .little => .{ v0, v1 },
311 .big => .{ @byteSwap(v0), @byteSwap(v1) },
312 };
313 try testing.expectEqual(Murmur2_64.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur2_64.hashUint32(v0));
314 try testing.expectEqual(Murmur2_64.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1));
319315}
320316
321317test "mumur2_64 smhasher" {
......@@ -330,16 +326,14 @@ test "mumur2_64 smhasher" {
330326}
331327
332328test "murmur3_32" {
333 var v0: u32 = 0x12345678;
334 var v1: u64 = 0x1234567812345678;
335 var v0le: u32 = v0;
336 var v1le: u64 = v1;
337 if (native_endian == .big) {
338 v0le = @byteSwap(v0le);
339 v1le = @byteSwap(v1le);
340 }
341 try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0));
342 try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1));
329 const v0: u32 = 0x12345678;
330 const v1: u64 = 0x1234567812345678;
331 const v0le: u32, const v1le: u64 = switch (native_endian) {
332 .little => .{ v0, v1 },
333 .big => .{ @byteSwap(v0), @byteSwap(v1) },
334 };
335 try testing.expectEqual(Murmur3_32.hash(@as([*]const u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0));
336 try testing.expectEqual(Murmur3_32.hash(@as([*]const u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1));
343337}
344338
345339test "mumur3_32 smhasher" {
lib/std/hash_map.zig+4-4
......@@ -1484,8 +1484,8 @@ pub fn HashMapUnmanaged(
14841484
14851485 var i: Size = 0;
14861486 var metadata = self.metadata.?;
1487 var keys_ptr = self.keys();
1488 var values_ptr = self.values();
1487 const keys_ptr = self.keys();
1488 const values_ptr = self.values();
14891489 while (i < self.capacity()) : (i += 1) {
14901490 if (metadata[i].isUsed()) {
14911491 other.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], new_ctx);
......@@ -1521,8 +1521,8 @@ pub fn HashMapUnmanaged(
15211521 const old_capacity = self.capacity();
15221522 var i: Size = 0;
15231523 var metadata = self.metadata.?;
1524 var keys_ptr = self.keys();
1525 var values_ptr = self.values();
1524 const keys_ptr = self.keys();
1525 const values_ptr = self.values();
15261526 while (i < old_capacity) : (i += 1) {
15271527 if (metadata[i].isUsed()) {
15281528 map.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], ctx);
lib/std/heap.zig+9-9
......@@ -81,10 +81,10 @@ const CAllocator = struct {
8181 // Thin wrapper around regular malloc, overallocate to account for
8282 // alignment padding and store the original malloc()'ed pointer before
8383 // the aligned address.
84 var unaligned_ptr = @as([*]u8, @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null));
84 const unaligned_ptr = @as([*]u8, @ptrCast(c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null));
8585 const unaligned_addr = @intFromPtr(unaligned_ptr);
8686 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment);
87 var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
87 const aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
8888 getHeader(aligned_ptr).* = unaligned_ptr;
8989
9090 return aligned_ptr;
......@@ -661,12 +661,12 @@ test "FixedBufferAllocator.reset" {
661661 const X = 0xeeeeeeeeeeeeeeee;
662662 const Y = 0xffffffffffffffff;
663663
664 var x = try allocator.create(u64);
664 const x = try allocator.create(u64);
665665 x.* = X;
666666 try testing.expectError(error.OutOfMemory, allocator.create(u64));
667667
668668 fba.reset();
669 var y = try allocator.create(u64);
669 const y = try allocator.create(u64);
670670 y.* = Y;
671671
672672 // we expect Y to have overwritten X.
......@@ -691,9 +691,9 @@ test "FixedBufferAllocator Reuse memory on realloc" {
691691 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);
692692 const allocator = fixed_buffer_allocator.allocator();
693693
694 var slice0 = try allocator.alloc(u8, 5);
694 const slice0 = try allocator.alloc(u8, 5);
695695 try testing.expect(slice0.len == 5);
696 var slice1 = try allocator.realloc(slice0, 10);
696 const slice1 = try allocator.realloc(slice0, 10);
697697 try testing.expect(slice1.ptr == slice0.ptr);
698698 try testing.expect(slice1.len == 10);
699699 try testing.expectError(error.OutOfMemory, allocator.realloc(slice1, 11));
......@@ -706,8 +706,8 @@ test "FixedBufferAllocator Reuse memory on realloc" {
706706 var slice0 = try allocator.alloc(u8, 2);
707707 slice0[0] = 1;
708708 slice0[1] = 2;
709 var slice1 = try allocator.alloc(u8, 2);
710 var slice2 = try allocator.realloc(slice0, 4);
709 const slice1 = try allocator.alloc(u8, 2);
710 const slice2 = try allocator.realloc(slice0, 4);
711711 try testing.expect(slice0.ptr != slice2.ptr);
712712 try testing.expect(slice1.ptr != slice2.ptr);
713713 try testing.expect(slice2[0] == 1);
......@@ -757,7 +757,7 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void {
757757 allocator.free(slice);
758758
759759 // Zero-length allocation
760 var empty = try allocator.alloc(u8, 0);
760 const empty = try allocator.alloc(u8, 0);
761761 allocator.free(empty);
762762 // Allocation with zero-sized types
763763 const zero_bit_ptr = try allocator.create(u0);
lib/std/heap/arena_allocator.zig+1-1
......@@ -257,7 +257,7 @@ test "ArenaAllocator (reset with preheating)" {
257257 rounds -= 1;
258258 _ = arena_allocator.reset(.retain_capacity);
259259 var alloced_bytes: usize = 0;
260 var total_size: usize = random.intRangeAtMost(usize, 256, 16384);
260 const total_size: usize = random.intRangeAtMost(usize, 256, 16384);
261261 while (alloced_bytes < total_size) {
262262 const size = random.intRangeAtMost(usize, 16, 256);
263263 const alignment = 32;
lib/std/heap/general_purpose_allocator.zig+3-3
......@@ -512,7 +512,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
512512 var buckets = &self.buckets[bucket_index];
513513 const slot_count = @divExact(page_size, size_class);
514514 if (self.cur_buckets[bucket_index] == null or self.cur_buckets[bucket_index].?.alloc_cursor == slot_count) {
515 var new_bucket = try self.createBucket(size_class);
515 const new_bucket = try self.createBucket(size_class);
516516 errdefer self.freeBucket(new_bucket, size_class);
517517 const node = try self.bucket_node_pool.create();
518518 node.key = new_bucket;
......@@ -526,7 +526,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
526526 const slot_index = bucket.alloc_cursor;
527527 bucket.alloc_cursor += 1;
528528
529 var used_bits_byte = bucket.usedBits(slot_index / 8);
529 const used_bits_byte = bucket.usedBits(slot_index / 8);
530530 const used_bit_index: u3 = @as(u3, @intCast(slot_index % 8)); // TODO cast should be unnecessary
531531 used_bits_byte.* |= (@as(u8, 1) << used_bit_index);
532532 bucket.used_count += 1;
......@@ -915,7 +915,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
915915 if (bucket.used_count == 0) {
916916 var entry = self.buckets[bucket_index].getEntryFor(bucket);
917917 // save the node for destruction/insertion into in empty_buckets
918 var node = entry.node.?;
918 const node = entry.node.?;
919919 entry.set(null);
920920 if (self.cur_buckets[bucket_index] == bucket) {
921921 self.cur_buckets[bucket_index] = null;
lib/std/heap/memory_pool.zig+1-1
......@@ -172,7 +172,7 @@ test "memory pool: preheating (success)" {
172172}
173173
174174test "memory pool: preheating (failure)" {
175 var failer = std.testing.failing_allocator;
175 const failer = std.testing.failing_allocator;
176176 try std.testing.expectError(error.OutOfMemory, MemoryPool(u32).initPreheated(failer, 5));
177177}
178178
lib/std/http/Client.zig+1-1
......@@ -144,7 +144,7 @@ pub const ConnectionPool = struct {
144144 pool.mutex.lock();
145145 defer pool.mutex.unlock();
146146
147 var next = pool.free.first;
147 const next = pool.free.first;
148148 _ = next;
149149 while (pool.free_len > new_size) {
150150 const popped = pool.free.popFirst() orelse unreachable;
lib/std/http/protocol.zig+6-9
......@@ -765,10 +765,9 @@ test "HeadersParser.read length" {
765765 var r = HeadersParser.initDynamic(256);
766766 defer r.header_bytes.deinit(std.testing.allocator);
767767 const data = "GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 5\r\n\r\nHello";
768 var fbs = std.io.fixedBufferStream(data);
769768
770 var conn = MockBufferedConnection{
771 .conn = fbs,
769 var conn: MockBufferedConnection = .{
770 .conn = std.io.fixedBufferStream(data),
772771 };
773772
774773 while (true) { // read headers
......@@ -796,10 +795,9 @@ test "HeadersParser.read chunked" {
796795 var r = HeadersParser.initDynamic(256);
797796 defer r.header_bytes.deinit(std.testing.allocator);
798797 const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\n\r\n";
799 var fbs = std.io.fixedBufferStream(data);
800798
801 var conn = MockBufferedConnection{
802 .conn = fbs,
799 var conn: MockBufferedConnection = .{
800 .conn = std.io.fixedBufferStream(data),
803801 };
804802
805803 while (true) { // read headers
......@@ -826,10 +824,9 @@ test "HeadersParser.read chunked trailer" {
826824 var r = HeadersParser.initDynamic(256);
827825 defer r.header_bytes.deinit(std.testing.allocator);
828826 const data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n2\r\nHe\r\n2\r\nll\r\n1\r\no\r\n0\r\nContent-Type: text/plain\r\n\r\n";
829 var fbs = std.io.fixedBufferStream(data);
830827
831 var conn = MockBufferedConnection{
832 .conn = fbs,
828 var conn: MockBufferedConnection = .{
829 .conn = std.io.fixedBufferStream(data),
833830 };
834831
835832 while (true) { // read headers
lib/std/io/Reader/test.zig+8-8
......@@ -91,13 +91,13 @@ test "Reader.readUntilDelimiterAlloc returns ArrayLists with bytes read until th
9191 const reader = fis.reader();
9292
9393 {
94 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
94 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
9595 defer a.free(result);
9696 try std.testing.expectEqualStrings("0000", result);
9797 }
9898
9999 {
100 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
100 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
101101 defer a.free(result);
102102 try std.testing.expectEqualStrings("1234", result);
103103 }
......@@ -112,7 +112,7 @@ test "Reader.readUntilDelimiterAlloc returns an empty ArrayList" {
112112 const reader = fis.reader();
113113
114114 {
115 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
115 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
116116 defer a.free(result);
117117 try std.testing.expectEqualStrings("", result);
118118 }
......@@ -126,7 +126,7 @@ test "Reader.readUntilDelimiterAlloc returns StreamTooLong, then an ArrayList wi
126126
127127 try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterAlloc(a, '\n', 5));
128128
129 var result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
129 const result = try reader.readUntilDelimiterAlloc(a, '\n', 5);
130130 defer a.free(result);
131131 try std.testing.expectEqualStrings("67", result);
132132}
......@@ -219,13 +219,13 @@ test "Reader.readUntilDelimiterOrEofAlloc returns ArrayLists with bytes read unt
219219 const reader = fis.reader();
220220
221221 {
222 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
222 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
223223 defer a.free(result);
224224 try std.testing.expectEqualStrings("0000", result);
225225 }
226226
227227 {
228 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
228 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
229229 defer a.free(result);
230230 try std.testing.expectEqualStrings("1234", result);
231231 }
......@@ -240,7 +240,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns an empty ArrayList" {
240240 const reader = fis.reader();
241241
242242 {
243 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
243 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
244244 defer a.free(result);
245245 try std.testing.expectEqualStrings("", result);
246246 }
......@@ -254,7 +254,7 @@ test "Reader.readUntilDelimiterOrEofAlloc returns StreamTooLong, then an ArrayLi
254254
255255 try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiterOrEofAlloc(a, '\n', 5));
256256
257 var result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
257 const result = (try reader.readUntilDelimiterOrEofAlloc(a, '\n', 5)).?;
258258 defer a.free(result);
259259 try std.testing.expectEqualStrings("67", result);
260260}
lib/std/io/buffered_reader.zig+15-10
......@@ -131,8 +131,9 @@ test "io.BufferedReader Block" {
131131
132132 // len out == block
133133 {
134 var block_reader = BlockReader.init(block, 2);
135 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };
134 var test_buf_reader: BufferedReader(4, BlockReader) = .{
135 .unbuffered_reader = BlockReader.init(block, 2),
136 };
136137 var out_buf: [4]u8 = undefined;
137138 _ = try test_buf_reader.read(&out_buf);
138139 try testing.expectEqualSlices(u8, &out_buf, block);
......@@ -143,8 +144,9 @@ test "io.BufferedReader Block" {
143144
144145 // len out < block
145146 {
146 var block_reader = BlockReader.init(block, 2);
147 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };
147 var test_buf_reader: BufferedReader(4, BlockReader) = .{
148 .unbuffered_reader = BlockReader.init(block, 2),
149 };
148150 var out_buf: [3]u8 = undefined;
149151 _ = try test_buf_reader.read(&out_buf);
150152 try testing.expectEqualSlices(u8, &out_buf, "012");
......@@ -157,8 +159,9 @@ test "io.BufferedReader Block" {
157159
158160 // len out > block
159161 {
160 var block_reader = BlockReader.init(block, 2);
161 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };
162 var test_buf_reader: BufferedReader(4, BlockReader) = .{
163 .unbuffered_reader = BlockReader.init(block, 2),
164 };
162165 var out_buf: [5]u8 = undefined;
163166 _ = try test_buf_reader.read(&out_buf);
164167 try testing.expectEqualSlices(u8, &out_buf, "01230");
......@@ -169,8 +172,9 @@ test "io.BufferedReader Block" {
169172
170173 // len out == 0
171174 {
172 var block_reader = BlockReader.init(block, 2);
173 var test_buf_reader = BufferedReader(4, BlockReader){ .unbuffered_reader = block_reader };
175 var test_buf_reader: BufferedReader(4, BlockReader) = .{
176 .unbuffered_reader = BlockReader.init(block, 2),
177 };
174178 var out_buf: [0]u8 = undefined;
175179 _ = try test_buf_reader.read(&out_buf);
176180 try testing.expectEqualSlices(u8, &out_buf, "");
......@@ -178,8 +182,9 @@ test "io.BufferedReader Block" {
178182
179183 // len bufreader buf > block
180184 {
181 var block_reader = BlockReader.init(block, 2);
182 var test_buf_reader = BufferedReader(5, BlockReader){ .unbuffered_reader = block_reader };
185 var test_buf_reader: BufferedReader(5, BlockReader) = .{
186 .unbuffered_reader = BlockReader.init(block, 2),
187 };
183188 var out_buf: [4]u8 = undefined;
184189 _ = try test_buf_reader.read(&out_buf);
185190 try testing.expectEqualSlices(u8, &out_buf, block);
lib/std/io/test.zig+2-2
......@@ -167,13 +167,13 @@ test "updateTimes" {
167167 file.close();
168168 tmp.dir.deleteFile(tmp_file_name) catch {};
169169 }
170 var stat_old = try file.stat();
170 const stat_old = try file.stat();
171171 // Set atime and mtime to 5s before
172172 try file.updateTimes(
173173 stat_old.atime - 5 * std.time.ns_per_s,
174174 stat_old.mtime - 5 * std.time.ns_per_s,
175175 );
176 var stat_new = try file.stat();
176 const stat_new = try file.stat();
177177 try expect(stat_new.atime < stat_old.atime);
178178 try expect(stat_new.mtime < stat_old.mtime);
179179}
lib/std/json/dynamic_test.zig+9-9
......@@ -190,15 +190,15 @@ test "Value.jsonStringify" {
190190 var obj = ObjectMap.init(testing.allocator);
191191 defer obj.deinit();
192192 try obj.putNoClobber("a", .{ .string = "b" });
193 var array = [_]Value{
194 Value.null,
195 Value{ .bool = true },
196 Value{ .integer = 42 },
197 Value{ .number_string = "43" },
198 Value{ .float = 42 },
199 Value{ .string = "weeee" },
200 Value{ .array = Array.fromOwnedSlice(undefined, &vals) },
201 Value{ .object = obj },
193 const array = [_]Value{
194 .null,
195 .{ .bool = true },
196 .{ .integer = 42 },
197 .{ .number_string = "43" },
198 .{ .float = 42 },
199 .{ .string = "weeee" },
200 .{ .array = Array.fromOwnedSlice(undefined, &vals) },
201 .{ .object = obj },
202202 };
203203 var buffer: [0x1000]u8 = undefined;
204204 var fbs = std.io.fixedBufferStream(&buffer);
lib/std/json/static_test.zig+9-9
......@@ -533,7 +533,7 @@ test "parse into struct with misc fields" {
533533 string: []const u8,
534534 };
535535 };
536 var document_str =
536 const document_str =
537537 \\{
538538 \\ "int": 420,
539539 \\ "float": 3.14,
......@@ -588,7 +588,7 @@ test "parse into struct with strings and arrays with sentinels" {
588588 data: [:99]const i32,
589589 simple_data: []const i32,
590590 };
591 var document_str =
591 const document_str =
592592 \\{
593593 \\ "language": "zig",
594594 \\ "language_without_sentinel": "zig again!",
......@@ -634,7 +634,7 @@ test "parse into struct ignoring unknown fields" {
634634 language: []const u8,
635635 };
636636
637 var str =
637 const str =
638638 \\{
639639 \\ "int": 420,
640640 \\ "float": 3.14,
......@@ -685,7 +685,7 @@ test "parse into tuple" {
685685 std.meta.Tuple(&.{ u8, []const u8, u8 }),
686686 Union,
687687 });
688 var str =
688 const str =
689689 \\[
690690 \\ 420,
691691 \\ 3.14,
......@@ -789,7 +789,7 @@ test "parse into vector" {
789789 vec_i32: @Vector(4, i32),
790790 vec_f32: @Vector(2, f32),
791791 };
792 var s =
792 const s =
793793 \\{
794794 \\ "vec_f32": [1.5, 2.5],
795795 \\ "vec_i32": [4, 5, 6, 7]
......@@ -821,7 +821,7 @@ test "json parse partial" {
821821 num: u32,
822822 yes: bool,
823823 };
824 var str =
824 const str =
825825 \\{
826826 \\ "outer": {
827827 \\ "key1": {
......@@ -835,7 +835,7 @@ test "json parse partial" {
835835 \\ }
836836 \\}
837837 ;
838 var allocator = testing.allocator;
838 const allocator = testing.allocator;
839839 var scanner = JsonScanner.initCompleteInput(allocator, str);
840840 defer scanner.deinit();
841841
......@@ -876,13 +876,13 @@ test "json parse allocate when streaming" {
876876 not_const: []u8,
877877 is_const: []const u8,
878878 };
879 var str =
879 const str =
880880 \\{
881881 \\ "not_const": "non const string",
882882 \\ "is_const": "const string"
883883 \\}
884884 ;
885 var allocator = testing.allocator;
885 const allocator = testing.allocator;
886886 var arena = ArenaAllocator.init(allocator);
887887 defer arena.deinit();
888888
lib/std/math.zig+2-1
......@@ -427,6 +427,7 @@ test "clamp" {
427427
428428 // Mix of comptime and non-comptime
429429 var i: i32 = 1;
430 _ = &i;
430431 try testing.expect(std.math.clamp(i, 0, 1) == 1);
431432}
432433
......@@ -1113,7 +1114,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
11131114 comptime assert(info.signedness == .unsigned);
11141115 const PromotedType = std.meta.Int(info.signedness, info.bits + 1);
11151116 const overflowBit = @as(PromotedType, 1) << info.bits;
1116 var x = ceilPowerOfTwoPromote(T, value);
1117 const x = ceilPowerOfTwoPromote(T, value);
11171118 if (overflowBit & x != 0) {
11181119 return error.Overflow;
11191120 }
lib/std/math/atan.zig+2-2
......@@ -143,8 +143,8 @@ fn atan64(x_: f64) f64 {
143143 };
144144
145145 var x = x_;
146 var ux = @as(u64, @bitCast(x));
147 var ix = @as(u32, @intCast(ux >> 32));
146 const ux: u64 = @bitCast(x);
147 var ix: u32 = @intCast(ux >> 32);
148148 const sign = ix >> 31;
149149 ix &= 0x7FFFFFFF;
150150
lib/std/math/atan2.zig+8-8
......@@ -104,7 +104,7 @@ fn atan2_32(y: f32, x: f32) f32 {
104104 }
105105
106106 // z = atan(|y / x|) with correct underflow
107 var z = z: {
107 const z = z: {
108108 if ((m & 2) != 0 and iy + (26 << 23) < ix) {
109109 break :z 0.0;
110110 } else {
......@@ -129,13 +129,13 @@ fn atan2_64(y: f64, x: f64) f64 {
129129 return x + y;
130130 }
131131
132 var ux = @as(u64, @bitCast(x));
133 var ix = @as(u32, @intCast(ux >> 32));
134 var lx = @as(u32, @intCast(ux & 0xFFFFFFFF));
132 const ux: u64 = @bitCast(x);
133 var ix: u32 = @intCast(ux >> 32);
134 const lx: u32 = @intCast(ux & 0xFFFFFFFF);
135135
136 var uy = @as(u64, @bitCast(y));
137 var iy = @as(u32, @intCast(uy >> 32));
138 var ly = @as(u32, @intCast(uy & 0xFFFFFFFF));
136 const uy: u64 = @bitCast(y);
137 var iy: u32 = @intCast(uy >> 32);
138 const ly: u32 = @intCast(uy & 0xFFFFFFFF);
139139
140140 // x = 1.0
141141 if ((ix -% 0x3FF00000) | lx == 0) {
......@@ -194,7 +194,7 @@ fn atan2_64(y: f64, x: f64) f64 {
194194 }
195195
196196 // z = atan(|y / x|) with correct underflow
197 var z = z: {
197 const z = z: {
198198 if ((m & 2) != 0 and iy +% (64 << 20) < ix) {
199199 break :z 0.0;
200200 } else {
lib/std/math/big/int.zig+5-5
......@@ -797,7 +797,7 @@ pub const Mutable = struct {
797797 // 0b0..01..1000 with @log2(@sizeOf(Limb)) consecutive ones
798798 const endian_mask: usize = (@sizeOf(Limb) - 1) << 3;
799799
800 var bytes = std.mem.sliceAsBytes(r.limbs);
800 const bytes = std.mem.sliceAsBytes(r.limbs);
801801 var bits = std.packed_int_array.PackedIntSliceEndian(u1, .little).init(bytes, limbs_required * @bitSizeOf(Limb));
802802
803803 var k: usize = 0;
......@@ -1407,7 +1407,7 @@ pub const Mutable = struct {
14071407 }
14081408
14091409 // Avoid copying u to s by swapping u and s
1410 var tmp_s = s;
1410 const tmp_s = s;
14111411 s = u;
14121412 u = tmp_s;
14131413 }
......@@ -1911,7 +1911,7 @@ pub const Mutable = struct {
19111911 var positive = true;
19121912 if (signedness == .signed) {
19131913 const total_bits = bit_offset + bit_count;
1914 var last_byte = switch (endian) {
1914 const last_byte = switch (endian) {
19151915 .little => ((total_bits + 7) / 8) - 1,
19161916 .big => buffer.len - ((total_bits + 7) / 8),
19171917 };
......@@ -3161,7 +3161,7 @@ pub const Managed = struct {
31613161
31623162 /// r = a ^ b
31633163 pub fn bitXor(r: *Managed, a: *const Managed, b: *const Managed) !void {
3164 var cap = @max(a.len(), b.len()) + @intFromBool(a.isPositive() != b.isPositive());
3164 const cap = @max(a.len(), b.len()) + @intFromBool(a.isPositive() != b.isPositive());
31653165 try r.ensureCapacity(cap);
31663166
31673167 var m = r.toMutable();
......@@ -4178,7 +4178,7 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
41784178 // most significant bit set.
41794179 // Square the result if the current bit is zero, square and multiply by a if
41804180 // it is one.
4181 var exp_bits = 32 - 1 - b_leading_zeros;
4181 const exp_bits = 32 - 1 - b_leading_zeros;
41824182 var exp = b << @as(u5, @intCast(1 + b_leading_zeros));
41834183
41844184 var i: usize = 0;
lib/std/math/big/int_test.zig+28-9
......@@ -300,20 +300,18 @@ test "big.int twos complement limit set" {
300300 };
301301
302302 inline for (test_types) |T| {
303 // To work around 'control flow attempts to use compile-time variable at runtime'
304 const U = T;
305 const int_info = @typeInfo(U).Int;
303 const int_info = @typeInfo(T).Int;
306304
307305 var a = try Managed.init(testing.allocator);
308306 defer a.deinit();
309307
310308 try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits);
311 var max: U = maxInt(U);
312 try testing.expect(max == try a.to(U));
309 const max: T = maxInt(T);
310 try testing.expect(max == try a.to(T));
313311
314312 try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits);
315 var min: U = minInt(U);
316 try testing.expect(min == try a.to(U));
313 const min: T = minInt(T);
314 try testing.expect(min == try a.to(T));
317315 }
318316}
319317
......@@ -519,6 +517,9 @@ test "big.int add multi-single" {
519517test "big.int add multi-multi" {
520518 var op1: u128 = 0xefefefef7f7f7f7f;
521519 var op2: u128 = 0xfefefefe9f9f9f9f;
520 // These must be runtime-known to prevent this comparison being tautological, as the
521 // compiler uses `std.math.big.int` internally to add these values at comptime.
522 _ = .{ &op1, &op2 };
522523 var a = try Managed.initSet(testing.allocator, op1);
523524 defer a.deinit();
524525 var b = try Managed.initSet(testing.allocator, op2);
......@@ -833,6 +834,7 @@ test "big.int sub multi-single" {
833834test "big.int sub multi-multi" {
834835 var op1: u128 = 0xefefefefefefefefefefefef;
835836 var op2: u128 = 0xabababababababababababab;
837 _ = .{ &op1, &op2 };
836838
837839 var a = try Managed.initSet(testing.allocator, op1);
838840 defer a.deinit();
......@@ -920,6 +922,8 @@ test "big.int mul multi-multi" {
920922
921923 var op1: u256 = 0x998888efefefefefefefef;
922924 var op2: u256 = 0x333000abababababababab;
925 _ = .{ &op1, &op2 };
926
923927 var a = try Managed.initSet(testing.allocator, op1);
924928 defer a.deinit();
925929 var b = try Managed.initSet(testing.allocator, op2);
......@@ -1042,6 +1046,8 @@ test "big.int mulWrap multi-multi unsigned" {
10421046
10431047 var op1: u256 = 0x998888efefefefefefefef;
10441048 var op2: u256 = 0x333000abababababababab;
1049 _ = .{ &op1, &op2 };
1050
10451051 var a = try Managed.initSet(testing.allocator, op1);
10461052 defer a.deinit();
10471053 var b = try Managed.initSet(testing.allocator, op2);
......@@ -1164,6 +1170,7 @@ test "big.int div single-single with rem" {
11641170test "big.int div multi-single no rem" {
11651171 var op1: u128 = 0xffffeeeeddddcccc;
11661172 var op2: u128 = 34;
1173 _ = .{ &op1, &op2 };
11671174
11681175 var a = try Managed.initSet(testing.allocator, op1);
11691176 defer a.deinit();
......@@ -1183,6 +1190,7 @@ test "big.int div multi-single no rem" {
11831190test "big.int div multi-single with rem" {
11841191 var op1: u128 = 0xffffeeeeddddcccf;
11851192 var op2: u128 = 34;
1193 _ = .{ &op1, &op2 };
11861194
11871195 var a = try Managed.initSet(testing.allocator, op1);
11881196 defer a.deinit();
......@@ -1202,6 +1210,7 @@ test "big.int div multi-single with rem" {
12021210test "big.int div multi>2-single" {
12031211 var op1: u128 = 0xfefefefefefefefefefefefefefefefe;
12041212 var op2: u128 = 0xefab8;
1213 _ = .{ &op1, &op2 };
12051214
12061215 var a = try Managed.initSet(testing.allocator, op1);
12071216 defer a.deinit();
......@@ -2106,6 +2115,8 @@ test "big.int sat shift-left signed multi positive" {
21062115 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
21072116
21082117 var x: SignedDoubleLimb = 1;
2118 _ = &x;
2119
21092120 const shift = @bitSizeOf(SignedDoubleLimb) - 1;
21102121
21112122 var a = try Managed.initSet(testing.allocator, x);
......@@ -2119,6 +2130,8 @@ test "big.int sat shift-left signed multi negative" {
21192130 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
21202131
21212132 var x: SignedDoubleLimb = -1;
2133 _ = &x;
2134
21222135 const shift = @bitSizeOf(SignedDoubleLimb) - 1;
21232136
21242137 var a = try Managed.initSet(testing.allocator, x);
......@@ -2130,6 +2143,8 @@ test "big.int sat shift-left signed multi negative" {
21302143
21312144test "big.int bitNotWrap unsigned simple" {
21322145 var x: u10 = 123;
2146 _ = &x;
2147
21332148 var a = try Managed.initSet(testing.allocator, x);
21342149 defer a.deinit();
21352150
......@@ -2149,6 +2164,8 @@ test "big.int bitNotWrap unsigned multi" {
21492164
21502165test "big.int bitNotWrap signed simple" {
21512166 var x: i11 = -456;
2167 _ = &x;
2168
21522169 var a = try Managed.initSet(testing.allocator, -456);
21532170 defer a.deinit();
21542171
......@@ -2306,6 +2323,8 @@ test "big.int bitwise xor simple" {
23062323test "big.int bitwise xor multi-limb" {
23072324 var x: DoubleLimb = maxInt(Limb) + 1;
23082325 var y: DoubleLimb = maxInt(Limb);
2326 _ = .{ &x, &y };
2327
23092328 var a = try Managed.initSet(testing.allocator, x);
23102329 defer a.deinit();
23112330 var b = try Managed.initSet(testing.allocator, y);
......@@ -2548,7 +2567,7 @@ test "big.int gcd one large" {
25482567
25492568test "big.int mutable to managed" {
25502569 const allocator = testing.allocator;
2551 var limbs_buf = try allocator.alloc(Limb, 8);
2570 const limbs_buf = try allocator.alloc(Limb, 8);
25522571 defer allocator.free(limbs_buf);
25532572
25542573 var a = Mutable.init(limbs_buf, 0xdeadbeef);
......@@ -2965,7 +2984,7 @@ test "big int conversion write twos complement zero" {
29652984 // (2) should correctly interpret bytes based on the provided endianness
29662985 // (3) should ignore any bits from bit_count to 8 * abi_size
29672986
2968 var bit_count: usize = 12 * 8 + 1;
2987 const bit_count: usize = 12 * 8 + 1;
29692988 var buffer: []const u8 = undefined;
29702989
29712990 buffer = &([_]u8{0} ** 13);
lib/std/math/cbrt.zig+2-2
......@@ -102,7 +102,7 @@ fn cbrt64(x: f64) f64 {
102102
103103 // cbrt to 23 bits
104104 // cbrt(x) = t * cbrt(x / t^3) ~= t * P(t^3 / x)
105 var r = (t * t) * (t / x);
105 const r = (t * t) * (t / x);
106106 t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4));
107107
108108 // Round t away from 0 to 23 bits
......@@ -113,7 +113,7 @@ fn cbrt64(x: f64) f64 {
113113 // one step newton to 53 bits
114114 const s = t * t;
115115 var q = x / s;
116 var w = t + t;
116 const w = t + t;
117117 q = (q - t) / (w + q);
118118
119119 return t + t * q;
lib/std/math/complex/atan.zig+2-2
......@@ -55,7 +55,7 @@ fn atan32(z: Complex(f32)) Complex(f32) {
5555 }
5656
5757 var t = 0.5 * math.atan2(f32, 2.0 * x, a);
58 var w = redupif32(t);
58 const w = redupif32(t);
5959
6060 t = y - 1.0;
6161 a = x2 + t * t;
......@@ -104,7 +104,7 @@ fn atan64(z: Complex(f64)) Complex(f64) {
104104 }
105105
106106 var t = 0.5 * math.atan2(f64, 2.0 * x, a);
107 var w = redupif64(t);
107 const w = redupif64(t);
108108
109109 t = y - 1.0;
110110 a = x2 + t * t;
lib/std/math/ilogb.zig+2-2
......@@ -38,8 +38,8 @@ fn ilogbX(comptime T: type, x: T) i32 {
3838
3939 const absMask = signBit - 1;
4040
41 var u = @as(Z, @bitCast(x)) & absMask;
42 var e = @as(i32, @intCast(u >> significandBits));
41 const u = @as(Z, @bitCast(x)) & absMask;
42 const e: i32 = @intCast(u >> significandBits);
4343
4444 if (e == 0) {
4545 if (u == 0) {
lib/std/math/log1p.zig+4-4
......@@ -33,8 +33,8 @@ fn log1p_32(x: f32) f32 {
3333 const Lg3: f32 = 0x91e9ee.0p-25;
3434 const Lg4: f32 = 0xf89e26.0p-26;
3535
36 const u = @as(u32, @bitCast(x));
37 var ix = u;
36 const u: u32 = @bitCast(x);
37 const ix = u;
3838 var k: i32 = 1;
3939 var f: f32 = undefined;
4040 var c: f32 = undefined;
......@@ -112,8 +112,8 @@ fn log1p_64(x: f64) f64 {
112112 const Lg6: f64 = 1.531383769920937332e-01;
113113 const Lg7: f64 = 1.479819860511658591e-01;
114114
115 var ix = @as(u64, @bitCast(x));
116 var hx = @as(u32, @intCast(ix >> 32));
115 const ix: u64 = @bitCast(x);
116 const hx: u32 = @intCast(ix >> 32);
117117 var k: i32 = 1;
118118 var c: f64 = undefined;
119119 var f: f64 = undefined;
lib/std/math/sqrt.zig+1-1
......@@ -50,7 +50,7 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
5050 }
5151
5252 while (one != 0) {
53 var c = op >= res + one;
53 const c = op >= res + one;
5454 if (c) op -= res + one;
5555 res >>= 1;
5656 if (c) res += one;
lib/std/mem.zig+13-12
......@@ -403,11 +403,11 @@ test "zeroes" {
403403 b: u32,
404404 };
405405
406 var c = zeroes(C_union);
406 const c = zeroes(C_union);
407407 try testing.expectEqual(@as(u8, 0), c.a);
408408 try testing.expectEqual(@as(u32, 0), c.b);
409409
410 comptime var comptime_union = zeroes(C_union);
410 const comptime_union = comptime zeroes(C_union);
411411 try testing.expectEqual(@as(u8, 0), comptime_union.a);
412412 try testing.expectEqual(@as(u32, 0), comptime_union.b);
413413
......@@ -3399,7 +3399,7 @@ test "reverseIterator" {
33993399 try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*);
34003400 try testing.expectEqual(@as(?*const i32, null), it.nextPtr());
34013401
3402 var mut_slice: []i32 = &array;
3402 const mut_slice: []i32 = &array;
34033403 var mut_it = reverseIterator(mut_slice);
34043404 mut_it.nextPtr().?.* += 1;
34053405 mut_it.nextPtr().?.* += 2;
......@@ -3419,7 +3419,7 @@ test "reverseIterator" {
34193419 try testing.expectEqual(@as(?i32, 3), it.nextPtr().?.*);
34203420 try testing.expectEqual(@as(?*const i32, null), it.nextPtr());
34213421
3422 var mut_ptr_to_array: *[2]i32 = &array;
3422 const mut_ptr_to_array: *[2]i32 = &array;
34233423 var mut_it = reverseIterator(mut_ptr_to_array);
34243424 mut_it.nextPtr().?.* += 1;
34253425 mut_it.nextPtr().?.* += 2;
......@@ -3581,7 +3581,7 @@ test "replacementSize" {
35813581
35823582/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.
35833583pub fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, needle: []const T, replacement: []const T) Allocator.Error![]T {
3584 var output = try allocator.alloc(T, replacementSize(T, input, needle, replacement));
3584 const output = try allocator.alloc(T, replacementSize(T, input, needle, replacement));
35853585 _ = replace(T, input, needle, replacement, output);
35863586 return output;
35873587}
......@@ -3693,8 +3693,8 @@ pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) {
36933693test "alignPointer" {
36943694 const S = struct {
36953695 fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void {
3696 var ptr = @as(T, @ptrFromInt(base));
3697 var aligned = alignPointer(ptr, align_to);
3696 const ptr: T = @ptrFromInt(base);
3697 const aligned = alignPointer(ptr, align_to);
36983698 try testing.expectEqual(expected, @intFromPtr(aligned));
36993699 }
37003700 };
......@@ -3848,7 +3848,7 @@ test "bytesAsValue" {
38483848 .big => "\xC0\xDE\xFA\xCE",
38493849 .little => "\xCE\xFA\xDE\xC0",
38503850 }.*;
3851 var codeface = bytesAsValue(u32, &codeface_bytes);
3851 const codeface = bytesAsValue(u32, &codeface_bytes);
38523852 try testing.expect(codeface.* == 0xC0DEFACE);
38533853 codeface.* = 0;
38543854 for (codeface_bytes) |b|
......@@ -3941,6 +3941,7 @@ test "bytesAsSlice" {
39413941 {
39423942 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
39433943 var runtime_zero: usize = 0;
3944 _ = &runtime_zero;
39443945 const slice = bytesAsSlice(u16, bytes[runtime_zero..]);
39453946 try testing.expect(slice.len == 2);
39463947 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
......@@ -3957,6 +3958,7 @@ test "bytesAsSlice keeps pointer alignment" {
39573958 {
39583959 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
39593960 var runtime_zero: usize = 0;
3961 _ = &runtime_zero;
39603962 const numbers = bytesAsSlice(u32, bytes[runtime_zero..]);
39613963 try comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
39623964 }
......@@ -3967,8 +3969,8 @@ test "bytesAsSlice on a packed struct" {
39673969 a: u8,
39683970 };
39693971
3970 var b = [1]u8{9};
3971 var f = bytesAsSlice(F, &b);
3972 const b: [1]u8 = .{9};
3973 const f = bytesAsSlice(F, &b);
39723974 try testing.expect(f[0].a == 9);
39733975}
39743976
......@@ -4120,8 +4122,7 @@ pub const alignForwardGeneric = @compileError("renamed to alignForward");
41204122/// result eventually gets discarded.
41214123// TODO: use @declareSideEffect() when it is available - https://github.com/ziglang/zig/issues/6168
41224124pub fn doNotOptimizeAway(val: anytype) void {
4123 var a: u8 = 0;
4124 if (@typeInfo(@TypeOf(.{a})).Struct.fields[0].is_comptime) return;
4125 if (@inComptime()) return;
41254126
41264127 const max_gp_register_bits = @bitSizeOf(c_long);
41274128 const t = @typeInfo(@TypeOf(val));
lib/std/meta.zig+9-7
......@@ -738,7 +738,7 @@ test "std.meta.TagPayload" {
738738 },
739739 };
740740 const MovedEvent = TagPayload(Event, Event.Moved);
741 var e: Event = undefined;
741 const e: Event = .{ .Moved = undefined };
742742 try testing.expect(MovedEvent == @TypeOf(e.Moved));
743743}
744744
......@@ -839,9 +839,9 @@ test "std.meta.eql" {
839839 try testing.expect(eql(u_1, u_3));
840840 try testing.expect(!eql(u_1, u_2));
841841
842 var a1 = "abcdef".*;
843 var a2 = "abcdef".*;
844 var a3 = "ghijkl".*;
842 const a1 = "abcdef".*;
843 const a2 = "abcdef".*;
844 const a3 = "ghijkl".*;
845845
846846 try testing.expect(eql(a1, a2));
847847 try testing.expect(!eql(a1, a3));
......@@ -859,9 +859,9 @@ test "std.meta.eql" {
859859 try testing.expect(!eql(EU.tst(false), EU.tst(true)));
860860
861861 const V = @Vector(4, u32);
862 var v1: V = @splat(1);
863 var v2: V = @splat(1);
864 var v3: V = @splat(2);
862 const v1: V = @splat(1);
863 const v2: V = @splat(1);
864 const v3: V = @splat(2);
865865
866866 try testing.expect(eql(v1, v2));
867867 try testing.expect(!eql(v1, v3));
......@@ -879,6 +879,8 @@ test "intToEnum with error return" {
879879
880880 var zero: u8 = 0;
881881 var one: u16 = 1;
882 _ = &zero;
883 _ = &one;
882884 try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
883885 try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
884886 try testing.expect(intToEnum(E3, zero) catch unreachable == E3.A);
lib/std/meta/trait.zig+5-2
......@@ -225,6 +225,7 @@ test "isSingleItemPtr" {
225225 try comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
226226 try comptime testing.expect(!isSingleItemPtr(@TypeOf(array)));
227227 var runtime_zero: usize = 0;
228 _ = &runtime_zero;
228229 try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
229230}
230231
......@@ -253,6 +254,7 @@ pub fn isSlice(comptime T: type) bool {
253254test "isSlice" {
254255 const array = [_]u8{0} ** 10;
255256 var runtime_zero: usize = 0;
257 _ = &runtime_zero;
256258 try testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
257259 try testing.expect(!isSlice(@TypeOf(array)));
258260 try testing.expect(!isSlice(@TypeOf(&array[0])));
......@@ -341,8 +343,9 @@ pub fn isConstPtr(comptime T: type) bool {
341343}
342344
343345test "isConstPtr" {
344 var t = @as(u8, 0);
345 const c = @as(u8, 0);
346 var t: u8 = 0;
347 t = t;
348 const c: u8 = 0;
346349 try testing.expect(isConstPtr(*const @TypeOf(t)));
347350 try testing.expect(isConstPtr(@TypeOf(&c)));
348351 try testing.expect(!isConstPtr(*@TypeOf(t)));
lib/std/net.zig+4-4
......@@ -662,7 +662,7 @@ pub fn connectUnixSocket(path: []const u8) !Stream {
662662fn if_nametoindex(name: []const u8) !u32 {
663663 if (builtin.target.os.tag == .linux) {
664664 var ifr: os.ifreq = undefined;
665 var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
665 const sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
666666 defer os.closeSocket(sockfd);
667667
668668 @memcpy(ifr.ifrn.name[0..name.len], name);
......@@ -1375,7 +1375,7 @@ fn linuxLookupNameFromDns(
13751375 rc: ResolvConf,
13761376 port: u16,
13771377) !void {
1378 var ctx = dpc_ctx{
1378 const ctx = dpc_ctx{
13791379 .addrs = addrs,
13801380 .canon = canon,
13811381 .port = port,
......@@ -1591,8 +1591,8 @@ fn resMSendRc(
15911591 }};
15921592 const retry_interval = timeout / attempts;
15931593 var next: u32 = 0;
1594 var t2: u64 = @as(u64, @bitCast(std.time.milliTimestamp()));
1595 var t0 = t2;
1594 var t2: u64 = @bitCast(std.time.milliTimestamp());
1595 const t0 = t2;
15961596 var t1 = t2 - retry_interval;
15971597
15981598 var servfail_retry: usize = undefined;
lib/std/net/test.zig+5-5
......@@ -33,12 +33,12 @@ test "parse and render IPv6 addresses" {
3333 "::ffff:123.5.123.5",
3434 };
3535 for (ips, 0..) |ip, i| {
36 var addr = net.Address.parseIp6(ip, 0) catch unreachable;
36 const addr = net.Address.parseIp6(ip, 0) catch unreachable;
3737 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
3838 try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
3939
4040 if (builtin.os.tag == .linux) {
41 var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
41 const addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
4242 var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;
4343 try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));
4444 }
......@@ -80,7 +80,7 @@ test "parse and render IPv4 addresses" {
8080 "123.255.0.91",
8181 "127.0.0.1",
8282 }) |ip| {
83 var addr = net.Address.parseIp4(ip, 0) catch unreachable;
83 const addr = net.Address.parseIp4(ip, 0) catch unreachable;
8484 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
8585 try std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
8686 }
......@@ -303,10 +303,10 @@ test "listen on a unix socket, send bytes, receive bytes" {
303303 var server = net.StreamServer.init(.{});
304304 defer server.deinit();
305305
306 var socket_path = try generateFileName("socket.unix");
306 const socket_path = try generateFileName("socket.unix");
307307 defer testing.allocator.free(socket_path);
308308
309 var socket_addr = try net.Address.initUnix(socket_path);
309 const socket_addr = try net.Address.initUnix(socket_path);
310310 defer std.fs.cwd().deleteFile(socket_path) catch {};
311311 try server.listen(socket_addr);
312312
lib/std/os.zig+6-6
......@@ -4642,7 +4642,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr
46424642 const path_w = try windows.sliceToPrefixedFileW(dirfd, path);
46434643 return faccessatW(dirfd, path_w.span().ptr, mode, flags);
46444644 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {
4645 var resolved = RelativePathWasi{ .dir_fd = dirfd, .relative_path = path };
4645 const resolved = RelativePathWasi{ .dir_fd = dirfd, .relative_path = path };
46464646
46474647 const file = blk: {
46484648 break :blk fstatat(dirfd, path, flags);
......@@ -4775,7 +4775,7 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
47754775 }
47764776 }
47774777
4778 var fds: [2]fd_t = try pipe();
4778 const fds: [2]fd_t = try pipe();
47794779 errdefer {
47804780 close(fds[0]);
47814781 close(fds[1]);
......@@ -6709,7 +6709,7 @@ pub fn dn_expand(
67096709 // loop invariants: p<end, dest<dend
67106710 if ((p[0] & 0xc0) != 0) {
67116711 if (p + 1 == end) return error.InvalidDnsPacket;
6712 var j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1];
6712 const j = ((p[0] & @as(usize, 0x3f)) << 8) | p[1];
67136713 if (len == std.math.maxInt(usize)) len = @intFromPtr(p) + 2 - @intFromPtr(comp_dn.ptr);
67146714 if (j >= msg.len) return error.InvalidDnsPacket;
67156715 p = msg.ptr + j;
......@@ -7285,7 +7285,7 @@ pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError;
72857285pub const TimerFdSetError = TimerFdGetError || error{Canceled};
72867286
72877287pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t {
7288 var rc = linux.timerfd_create(clokid, flags);
7288 const rc = linux.timerfd_create(clokid, flags);
72897289 return switch (errno(rc)) {
72907290 .SUCCESS => @as(fd_t, @intCast(rc)),
72917291 .INVAL => unreachable,
......@@ -7299,7 +7299,7 @@ pub fn timerfd_create(clokid: i32, flags: u32) TimerFdCreateError!fd_t {
72997299}
73007300
73017301pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec, old_value: ?*linux.itimerspec) TimerFdSetError!void {
7302 var rc = linux.timerfd_settime(fd, flags, new_value, old_value);
7302 const rc = linux.timerfd_settime(fd, flags, new_value, old_value);
73037303 return switch (errno(rc)) {
73047304 .SUCCESS => {},
73057305 .BADF => error.InvalidHandle,
......@@ -7312,7 +7312,7 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const linux.itimerspec,
73127312
73137313pub fn timerfd_gettime(fd: i32) TimerFdGetError!linux.itimerspec {
73147314 var curr_value: linux.itimerspec = undefined;
7315 var rc = linux.timerfd_gettime(fd, &curr_value);
7315 const rc = linux.timerfd_gettime(fd, &curr_value);
73167316 return switch (errno(rc)) {
73177317 .SUCCESS => return curr_value,
73187318 .BADF => error.InvalidHandle,
lib/std/os/linux.zig+1
......@@ -1326,6 +1326,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
13261326 next_unsent = i + 1;
13271327 break;
13281328 }
1329 size += iov.iov_len;
13291330 }
13301331 }
13311332 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG.EOR)
lib/std/os/linux/io_uring.zig+20-19
......@@ -137,7 +137,7 @@ pub const IO_Uring = struct {
137137 // We must therefore use wrapping addition and subtraction to avoid a runtime crash.
138138 const next = self.sq.sqe_tail +% 1;
139139 if (next -% head > self.sq.sqes.len) return error.SubmissionQueueFull;
140 var sqe = &self.sq.sqes[self.sq.sqe_tail & self.sq.mask];
140 const sqe = &self.sq.sqes[self.sq.sqe_tail & self.sq.mask];
141141 self.sq.sqe_tail = next;
142142 return sqe;
143143 }
......@@ -279,7 +279,7 @@ pub const IO_Uring = struct {
279279 const ready = self.cq_ready();
280280 const count = @min(cqes.len, ready);
281281 var head = self.cq.head.*;
282 var tail = head +% count;
282 const tail = head +% count;
283283 // TODO Optimize this by using 1 or 2 memcpy's (if the tail wraps) rather than a loop.
284284 var i: usize = 0;
285285 // Do not use "less-than" operator since head and tail may wrap:
......@@ -1916,7 +1916,7 @@ test "splice/read" {
19161916 var buffer_read = [_]u8{98} ** 20;
19171917 _ = try file_src.write(&buffer_write);
19181918
1919 var fds = try os.pipe();
1919 const fds = try os.pipe();
19201920 const pipe_offset: u64 = std.math.maxInt(u64);
19211921
19221922 const sqe_splice_to_pipe = try ring.splice(0x11111111, fd_src, 0, fds[1], pipe_offset, buffer_write.len);
......@@ -2045,6 +2045,7 @@ test "openat" {
20452045 // Workaround for LLVM bug: https://github.com/ziglang/zig/issues/12014
20462046 const path_addr = if (builtin.zig_backend == .stage2_llvm) p: {
20472047 var workaround = path;
2048 _ = &workaround;
20482049 break :p @intFromPtr(workaround);
20492050 } else @intFromPtr(path);
20502051
......@@ -2199,7 +2200,7 @@ test "sendmsg/recvmsg" {
21992200 var iovecs_recv = [_]os.iovec{
22002201 os.iovec{ .iov_base = &buffer_recv, .iov_len = buffer_recv.len },
22012202 };
2202 var addr = [_]u8{0} ** 4;
2203 const addr = [_]u8{0} ** 4;
22032204 var address_recv = net.Address.initIp4(addr, 0);
22042205 var msg_recv: os.msghdr = os.msghdr{
22052206 .name = &address_recv.any,
......@@ -2676,7 +2677,7 @@ test "shutdown" {
26762677 var slen: os.socklen_t = address.getOsSockLen();
26772678 try os.getsockname(server, &address.any, &slen);
26782679
2679 var shutdown_sqe = try ring.shutdown(0x445445445, server, os.linux.SHUT.RD);
2680 const shutdown_sqe = try ring.shutdown(0x445445445, server, os.linux.SHUT.RD);
26802681 try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode);
26812682 try testing.expectEqual(@as(i32, server), shutdown_sqe.fd);
26822683
......@@ -2702,7 +2703,7 @@ test "shutdown" {
27022703 const server = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);
27032704 defer os.close(server);
27042705
2705 var shutdown_sqe = ring.shutdown(0x445445445, server, os.linux.SHUT.RD) catch |err| switch (err) {
2706 const shutdown_sqe = ring.shutdown(0x445445445, server, os.linux.SHUT.RD) catch |err| switch (err) {
27062707 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
27072708 };
27082709 try testing.expectEqual(linux.IORING_OP.SHUTDOWN, shutdown_sqe.opcode);
......@@ -2740,7 +2741,7 @@ test "renameat" {
27402741
27412742 // Submit renameat
27422743
2743 var sqe = try ring.renameat(
2744 const sqe = try ring.renameat(
27442745 0x12121212,
27452746 tmp.dir.fd,
27462747 old_path,
......@@ -2807,7 +2808,7 @@ test "unlinkat" {
28072808
28082809 // Submit unlinkat
28092810
2810 var sqe = try ring.unlinkat(
2811 const sqe = try ring.unlinkat(
28112812 0x12121212,
28122813 tmp.dir.fd,
28132814 path,
......@@ -2854,7 +2855,7 @@ test "mkdirat" {
28542855
28552856 // Submit mkdirat
28562857
2857 var sqe = try ring.mkdirat(
2858 const sqe = try ring.mkdirat(
28582859 0x12121212,
28592860 tmp.dir.fd,
28602861 path,
......@@ -2902,7 +2903,7 @@ test "symlinkat" {
29022903
29032904 // Submit symlinkat
29042905
2905 var sqe = try ring.symlinkat(
2906 const sqe = try ring.symlinkat(
29062907 0x12121212,
29072908 path,
29082909 tmp.dir.fd,
......@@ -2953,7 +2954,7 @@ test "linkat" {
29532954
29542955 // Submit linkat
29552956
2956 var sqe = try ring.linkat(
2957 const sqe = try ring.linkat(
29572958 0x12121212,
29582959 tmp.dir.fd,
29592960 first_path,
......@@ -3032,7 +3033,7 @@ test "provide_buffers: read" {
30323033
30333034 var i: usize = 0;
30343035 while (i < buffers.len) : (i += 1) {
3035 var sqe = try ring.read(0xdededede, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3036 const sqe = try ring.read(0xdededede, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
30363037 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);
30373038 try testing.expectEqual(@as(i32, fd), sqe.fd);
30383039 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3058,7 +3059,7 @@ test "provide_buffers: read" {
30583059 // This read should fail
30593060
30603061 {
3061 var sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3062 const sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
30623063 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);
30633064 try testing.expectEqual(@as(i32, fd), sqe.fd);
30643065 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3097,7 +3098,7 @@ test "provide_buffers: read" {
30973098 // Final read which should work
30983099
30993100 {
3100 var sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3101 const sqe = try ring.read(0xdfdfdfdf, fd, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
31013102 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);
31023103 try testing.expectEqual(@as(i32, fd), sqe.fd);
31033104 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3158,7 +3159,7 @@ test "remove_buffers" {
31583159 // Remove 3 buffers
31593160
31603161 {
3161 var sqe = try ring.remove_buffers(0xbababababa, 3, group_id);
3162 const sqe = try ring.remove_buffers(0xbababababa, 3, group_id);
31623163 try testing.expectEqual(linux.IORING_OP.REMOVE_BUFFERS, sqe.opcode);
31633164 try testing.expectEqual(@as(i32, 3), sqe.fd);
31643165 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3270,7 +3271,7 @@ test "provide_buffers: accept/connect/send/recv" {
32703271
32713272 var i: usize = 0;
32723273 while (i < buffers.len) : (i += 1) {
3273 var sqe = try ring.recv(0xdededede, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3274 const sqe = try ring.recv(0xdededede, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
32743275 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);
32753276 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);
32763277 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3299,7 +3300,7 @@ test "provide_buffers: accept/connect/send/recv" {
32993300 // This recv should fail
33003301
33013302 {
3302 var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3303 const sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
33033304 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);
33043305 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);
33053306 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3349,7 +3350,7 @@ test "provide_buffers: accept/connect/send/recv" {
33493350 @memset(mem.sliceAsBytes(&buffers), 1);
33503351
33513352 {
3352 var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
3353 const sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
33533354 try testing.expectEqual(linux.IORING_OP.RECV, sqe.opcode);
33543355 try testing.expectEqual(@as(i32, socket_test_harness.client), sqe.fd);
33553356 try testing.expectEqual(@as(u64, 0), sqe.addr);
......@@ -3477,7 +3478,7 @@ test "accept multishot" {
34773478 var nr: usize = 4; // number of clients to connect
34783479 while (nr > 0) : (nr -= 1) {
34793480 // connect client
3480 var client = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);
3481 const client = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0);
34813482 errdefer os.closeSocket(client);
34823483 try os.connect(client, &address.any, address.getOsSockLen());
34833484
lib/std/os/plan9.zig+1-1
......@@ -278,7 +278,7 @@ pub fn sbrk(n: usize) usize {
278278 bloc = @intFromPtr(&ExecData.end);
279279 bloc_max = @intFromPtr(&ExecData.end);
280280 }
281 var bl = std.mem.alignForward(usize, bloc, std.mem.page_size);
281 const bl = std.mem.alignForward(usize, bloc, std.mem.page_size);
282282 const n_aligned = std.mem.alignForward(usize, n, std.mem.page_size);
283283 if (bl + n_aligned > bloc_max) {
284284 // we need to allocate
lib/std/os/test.zig+15-15
......@@ -58,7 +58,7 @@ test "chdir smoke test" {
5858 {
5959 // Create a tmp directory
6060 var tmp_dir_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
61 var tmp_dir_path = path: {
61 const tmp_dir_path = path: {
6262 var allocator = std.heap.FixedBufferAllocator.init(&tmp_dir_buf);
6363 break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{ old_cwd, "zig-test-tmp" });
6464 };
......@@ -72,7 +72,7 @@ test "chdir smoke test" {
7272
7373 // On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase
7474 var resolved_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
75 var resolved_cwd = path: {
75 const resolved_cwd = path: {
7676 var allocator = std.heap.FixedBufferAllocator.init(&resolved_cwd_buf);
7777 break :path try fs.path.resolve(allocator.allocator(), &[_][]const u8{new_cwd});
7878 };
......@@ -523,7 +523,7 @@ test "pipe" {
523523 if (native_os == .windows or native_os == .wasi)
524524 return error.SkipZigTest;
525525
526 var fds = try os.pipe();
526 const fds = try os.pipe();
527527 try expect((try os.write(fds[1], "hello")) == 5);
528528 var buf: [16]u8 = undefined;
529529 try expect((try os.read(fds[0], buf[0..])) == 5);
......@@ -533,7 +533,7 @@ test "pipe" {
533533}
534534
535535test "argsAlloc" {
536 var args = try std.process.argsAlloc(std.testing.allocator);
536 const args = try std.process.argsAlloc(std.testing.allocator);
537537 std.process.argsFree(std.testing.allocator, args);
538538}
539539
......@@ -1087,7 +1087,7 @@ test "timerfd" {
10871087 return error.SkipZigTest;
10881088
10891089 const linux = os.linux;
1090 var tfd = try os.timerfd_create(linux.CLOCK.MONOTONIC, linux.TFD.CLOEXEC);
1090 const tfd = try os.timerfd_create(linux.CLOCK.MONOTONIC, linux.TFD.CLOEXEC);
10911091 defer os.close(tfd);
10921092
10931093 // Fire event 10_000_000ns = 10ms after the os.timerfd_settime call.
......@@ -1097,8 +1097,8 @@ test "timerfd" {
10971097 var fds: [1]os.pollfd = .{.{ .fd = tfd, .events = os.linux.POLL.IN, .revents = 0 }};
10981098 try expectEqual(@as(usize, 1), try os.poll(&fds, -1)); // -1 => infinite waiting
10991099
1100 var git = try os.timerfd_gettime(tfd);
1101 var expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } };
1100 const git = try os.timerfd_gettime(tfd);
1101 const expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } };
11021102 try expectEqual(expect_disarmed_timer, git);
11031103}
11041104
......@@ -1128,11 +1128,11 @@ test "read with empty buffer" {
11281128 break :blk try fs.realpathAlloc(allocator, relative_path);
11291129 };
11301130
1131 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1131 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
11321132 var file = try fs.cwd().createFile(file_path, .{ .read = true });
11331133 defer file.close();
11341134
1135 var bytes = try allocator.alloc(u8, 0);
1135 const bytes = try allocator.alloc(u8, 0);
11361136
11371137 _ = try os.read(file.handle, bytes);
11381138}
......@@ -1153,11 +1153,11 @@ test "pread with empty buffer" {
11531153 break :blk try fs.realpathAlloc(allocator, relative_path);
11541154 };
11551155
1156 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1156 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
11571157 var file = try fs.cwd().createFile(file_path, .{ .read = true });
11581158 defer file.close();
11591159
1160 var bytes = try allocator.alloc(u8, 0);
1160 const bytes = try allocator.alloc(u8, 0);
11611161
11621162 _ = try os.pread(file.handle, bytes, 0);
11631163}
......@@ -1178,11 +1178,11 @@ test "write with empty buffer" {
11781178 break :blk try fs.realpathAlloc(allocator, relative_path);
11791179 };
11801180
1181 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1181 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
11821182 var file = try fs.cwd().createFile(file_path, .{});
11831183 defer file.close();
11841184
1185 var bytes = try allocator.alloc(u8, 0);
1185 const bytes = try allocator.alloc(u8, 0);
11861186
11871187 _ = try os.write(file.handle, bytes);
11881188}
......@@ -1203,11 +1203,11 @@ test "pwrite with empty buffer" {
12031203 break :blk try fs.realpathAlloc(allocator, relative_path);
12041204 };
12051205
1206 var file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
1206 const file_path: []u8 = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" });
12071207 var file = try fs.cwd().createFile(file_path, .{});
12081208 defer file.close();
12091209
1210 var bytes = try allocator.alloc(u8, 0);
1210 const bytes = try allocator.alloc(u8, 0);
12111211
12121212 _ = try os.pwrite(file.handle, bytes, 0);
12131213}
lib/std/os/uefi.zig+3-4
......@@ -149,11 +149,10 @@ pub const TimeCapabilities = extern struct {
149149pub const FileHandle = *opaque {};
150150
151151test "GUID formatting" {
152 var bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 };
152 const bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 };
153 const guid: Guid = @bitCast(bytes);
153154
154 var guid = @as(Guid, @bitCast(bytes));
155
156 var str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid});
155 const str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid});
157156 defer std.testing.allocator.free(str);
158157
159158 try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));
lib/std/os/uefi/device_path.zig+2-2
......@@ -213,7 +213,7 @@ pub const DevicePath = union(Type) {
213213 // multiple adr entries can optionally follow
214214 pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 {
215215 // self.length is a minimum of 8 with one adr which is size 4.
216 var entries = (self.length - 4) / @sizeOf(u32);
216 const entries = (self.length - 4) / @sizeOf(u32);
217217 return @as([*]align(1) const u32, @ptrCast(&self.adr))[0..entries];
218218 }
219219 };
......@@ -431,7 +431,7 @@ pub const DevicePath = union(Type) {
431431 device_product_id: u16 align(1),
432432
433433 pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 {
434 var serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16);
434 const serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16);
435435 return @as([*]align(1) const u16, @ptrCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(UsbWwidDevicePath)))[0..serial_len];
436436 }
437437 };
lib/std/os/uefi/pool_allocator.zig+1-1
......@@ -34,7 +34,7 @@ const UefiPoolAllocator = struct {
3434 const unaligned_addr = @intFromPtr(unaligned_ptr);
3535 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), ptr_align);
3636
37 var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
37 const aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
3838 getHeader(aligned_ptr).* = unaligned_ptr;
3939
4040 return aligned_ptr;
lib/std/os/uefi/protocol/device_path.zig+2-3
......@@ -43,7 +43,7 @@ pub const DevicePath = extern struct {
4343
4444 /// Creates a file device path from the existing device path and a file path.
4545 pub fn create_file_device_path(self: *DevicePath, allocator: Allocator, path: [:0]align(1) const u16) !*DevicePath {
46 var path_size = self.size();
46 const path_size = self.size();
4747
4848 // 2 * (path.len + 1) for the path and its null terminator, which are u16s
4949 // DevicePath for the extra node before the end
......@@ -82,8 +82,7 @@ pub const DevicePath = extern struct {
8282 // Got the associated union type for self.type, now
8383 // we need to initialize it and its subtype
8484 if (self.type == enum_value) {
85 var subtype = self.initSubtype(ufield.type);
86
85 const subtype = self.initSubtype(ufield.type);
8786 if (subtype) |sb| {
8887 // e.g. return .{ .Hardware = .{ .Pci = @ptrCast(...) } }
8988 return @unionInit(uefi.DevicePath, ufield.name, sb);
lib/std/os/windows.zig+3-3
......@@ -1166,7 +1166,7 @@ test "QueryObjectName" {
11661166 const handle = tmp.dir.fd;
11671167 var out_buffer: [PATH_MAX_WIDE]u16 = undefined;
11681168
1169 var result_path = try QueryObjectName(handle, &out_buffer);
1169 const result_path = try QueryObjectName(handle, &out_buffer);
11701170 const required_len_in_u16 = result_path.len + @divExact(@intFromPtr(result_path.ptr) - @intFromPtr(&out_buffer), 2) + 1;
11711171 //insufficient size
11721172 try std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));
......@@ -2045,8 +2045,8 @@ pub fn eqlIgnoreCaseUtf8(a: []const u8, b: []const u8) bool {
20452045 };
20462046
20472047 while (true) {
2048 var a_cp = a_utf8_it.nextCodepoint() orelse break;
2049 var b_cp = b_utf8_it.nextCodepoint() orelse return false;
2048 const a_cp = a_utf8_it.nextCodepoint() orelse break;
2049 const b_cp = b_utf8_it.nextCodepoint() orelse return false;
20502050
20512051 if (a_cp <= std.math.maxInt(u16) and b_cp <= std.math.maxInt(u16)) {
20522052 if (a_cp != b_cp and upcaseImpl(@intCast(a_cp)) != upcaseImpl(@intCast(b_cp))) {
lib/std/pdb.zig+1-1
......@@ -897,7 +897,7 @@ const Msf = struct {
897897 return error.UnhandledBigDirectoryStream; // cf. BlockMapAddr comment.
898898
899899 try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr);
900 var dir_blocks = try allocator.alloc(u32, dir_block_count);
900 const dir_blocks = try allocator.alloc(u32, dir_block_count);
901901 for (dir_blocks) |*b| {
902902 b.* = try in.readInt(u32, .little);
903903 }
lib/std/priority_dequeue.zig+5-5
......@@ -82,8 +82,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar
8282 };
8383
8484 fn getStartForSiftUp(self: Self, child: T, index: usize) StartIndexAndLayer {
85 var child_index = index;
86 var parent_index = parentIndex(child_index);
85 const child_index = index;
86 const parent_index = parentIndex(child_index);
8787 const parent = self.items[parent_index];
8888
8989 const min_layer = self.nextIsMinLayer();
......@@ -115,7 +115,7 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar
115115 fn doSiftUp(self: *Self, start_index: usize, target_order: Order) void {
116116 var child_index = start_index;
117117 while (child_index > 2) {
118 var grandparent_index = grandparentIndex(child_index);
118 const grandparent_index = grandparentIndex(child_index);
119119 const child = self.items[child_index];
120120 const grandparent = self.items[grandparent_index];
121121
......@@ -286,8 +286,8 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar
286286 }
287287
288288 fn bestItemAtIndices(self: Self, index1: usize, index2: usize, target_order: Order) ItemAndIndex {
289 var item1 = self.getItem(index1);
290 var item2 = self.getItem(index2);
289 const item1 = self.getItem(index1);
290 const item2 = self.getItem(index2);
291291 return self.bestItem(item1, item2, target_order);
292292 }
293293
lib/std/priority_queue.zig+1-1
......@@ -470,7 +470,7 @@ test "std.PriorityQueue: remove at index" {
470470 break idx;
471471 idx += 1;
472472 } else unreachable;
473 var sorted_items = [_]u32{ 1, 3, 4, 5, 8, 9 };
473 const sorted_items = [_]u32{ 1, 3, 4, 5, 8, 9 };
474474 try expectEqual(queue.removeIndex(two_idx), 2);
475475
476476 var i: usize = 0;
lib/std/process.zig+12-12
......@@ -298,9 +298,9 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap {
298298 return result;
299299 }
300300
301 var environ = try allocator.alloc([*:0]u8, environ_count);
301 const environ = try allocator.alloc([*:0]u8, environ_count);
302302 defer allocator.free(environ);
303 var environ_buf = try allocator.alloc(u8, environ_buf_size);
303 const environ_buf = try allocator.alloc(u8, environ_buf_size);
304304 defer allocator.free(environ_buf);
305305
306306 const environ_get_ret = os.wasi.environ_get(environ.ptr, environ_buf.ptr);
......@@ -412,7 +412,7 @@ pub fn hasEnvVar(allocator: Allocator, key: []const u8) error{OutOfMemory}!bool
412412}
413413
414414test "os.getEnvVarOwned" {
415 var ga = std.testing.allocator;
415 const ga = std.testing.allocator;
416416 try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
417417}
418418
......@@ -477,10 +477,10 @@ pub const ArgIteratorWasi = struct {
477477 return &[_][:0]u8{};
478478 }
479479
480 var argv = try allocator.alloc([*:0]u8, count);
480 const argv = try allocator.alloc([*:0]u8, count);
481481 defer allocator.free(argv);
482482
483 var argv_buf = try allocator.alloc(u8, buf_size);
483 const argv_buf = try allocator.alloc(u8, buf_size);
484484
485485 switch (w.args_get(argv.ptr, argv_buf.ptr)) {
486486 .SUCCESS => {},
......@@ -551,7 +551,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
551551
552552 /// cmd_line_utf8 MUST remain valid and constant while using this instance
553553 pub fn init(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self {
554 var buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);
554 const buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);
555555 errdefer allocator.free(buffer);
556556
557557 return Self{
......@@ -564,7 +564,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
564564
565565 /// cmd_line_utf8 will be free'd (with the allocator) on deinit()
566566 pub fn initTakeOwnership(allocator: Allocator, cmd_line_utf8: []const u8) InitError!Self {
567 var buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);
567 const buffer = try allocator.alloc(u8, cmd_line_utf8.len + 1);
568568 errdefer allocator.free(buffer);
569569
570570 return Self{
......@@ -577,8 +577,8 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
577577
578578 /// cmd_line_utf16le MUST be encoded UTF16-LE, and is converted to UTF-8 in an internal buffer
579579 pub fn initUtf16le(allocator: Allocator, cmd_line_utf16le: [*:0]const u16) InitUtf16leError!Self {
580 var utf16le_slice = mem.sliceTo(cmd_line_utf16le, 0);
581 var cmd_line = std.unicode.utf16leToUtf8Alloc(allocator, utf16le_slice) catch |err| switch (err) {
580 const utf16le_slice = mem.sliceTo(cmd_line_utf16le, 0);
581 const cmd_line = std.unicode.utf16leToUtf8Alloc(allocator, utf16le_slice) catch |err| switch (err) {
582582 error.ExpectedSecondSurrogateHalf,
583583 error.DanglingSurrogateHalf,
584584 error.UnexpectedSecondSurrogateHalf,
......@@ -588,7 +588,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
588588 };
589589 errdefer allocator.free(cmd_line);
590590
591 var buffer = try allocator.alloc(u8, cmd_line.len + 1);
591 const buffer = try allocator.alloc(u8, cmd_line.len + 1);
592592 errdefer allocator.free(buffer);
593593
594594 return Self{
......@@ -681,7 +681,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
681681 0 => {
682682 self.emitBackslashes(backslash_count);
683683 self.buffer[self.end] = 0;
684 var token = self.buffer[self.start..self.end :0];
684 const token = self.buffer[self.start..self.end :0];
685685 self.end += 1;
686686 self.start = self.end;
687687 return token;
......@@ -713,7 +713,7 @@ pub fn ArgIteratorGeneral(comptime options: ArgIteratorGeneralOptions) type {
713713 self.emitCharacter(character);
714714 } else {
715715 self.buffer[self.end] = 0;
716 var token = self.buffer[self.start..self.end :0];
716 const token = self.buffer[self.start..self.end :0];
717717 self.end += 1;
718718 self.start = self.end;
719719 return token;
lib/std/rand/test.zig+2-2
......@@ -332,13 +332,13 @@ test "Random float chi-square goodness of fit" {
332332 while (i < num_numbers) : (i += 1) {
333333 const rand_f32 = random.float(f32);
334334 const rand_f64 = random.float(f64);
335 var f32_put = try f32_hist.getOrPut(@as(u32, @intFromFloat(rand_f32 * @as(f32, @floatFromInt(num_buckets)))));
335 const f32_put = try f32_hist.getOrPut(@as(u32, @intFromFloat(rand_f32 * @as(f32, @floatFromInt(num_buckets)))));
336336 if (f32_put.found_existing) {
337337 f32_put.value_ptr.* += 1;
338338 } else {
339339 f32_put.value_ptr.* = 1;
340340 }
341 var f64_put = try f64_hist.getOrPut(@as(u32, @intFromFloat(rand_f64 * @as(f64, @floatFromInt(num_buckets)))));
341 const f64_put = try f64_hist.getOrPut(@as(u32, @intFromFloat(rand_f64 * @as(f64, @floatFromInt(num_buckets)))));
342342 if (f64_put.found_existing) {
343343 f64_put.value_ptr.* += 1;
344344 } else {
lib/std/sort.zig+1-1
......@@ -387,7 +387,7 @@ test "sort fuzz testing" {
387387 var i: usize = 0;
388388 while (i < test_case_count) : (i += 1) {
389389 const array_size = random.intRangeLessThan(usize, 0, 1000);
390 var array = try testing.allocator.alloc(i32, array_size);
390 const array = try testing.allocator.alloc(i32, array_size);
391391 defer testing.allocator.free(array);
392392 // populate with random data
393393 for (array) |*item| {
lib/std/sort/block.zig+2-2
......@@ -302,8 +302,8 @@ pub fn block(
302302 } else {
303303 iterator.begin();
304304 while (!iterator.finished()) {
305 var A = iterator.nextRange();
306 var B = iterator.nextRange();
305 const A = iterator.nextRange();
306 const B = iterator.nextRange();
307307
308308 if (lessThan(context, items[B.end - 1], items[A.start])) {
309309 // the two ranges are in reverse order, so a simple rotation should fix it
lib/std/sort/pdq.zig+4-4
......@@ -276,10 +276,10 @@ fn chosePivot(a: usize, b: usize, pivot: *usize, context: anytype) Hint {
276276 // max_swaps is the maximum number of swaps allowed in this function
277277 const max_swaps = 4 * 3;
278278
279 var len = b - a;
280 var i = a + len / 4 * 1;
281 var j = a + len / 4 * 2;
282 var k = a + len / 4 * 3;
279 const len = b - a;
280 const i = a + len / 4 * 1;
281 const j = a + len / 4 * 2;
282 const k = a + len / 4 * 3;
283283 var swaps: usize = 0;
284284
285285 if (len >= 8) {
lib/std/tar.zig+1-1
......@@ -218,7 +218,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
218218 if (file_size == 0 and unstripped_file_name.len == 0) return;
219219 const file_name = try stripComponents(unstripped_file_name, options.strip_components);
220220
221 var file = dir.createFile(file_name, .{}) catch |err| switch (err) {
221 const file = dir.createFile(file_name, .{}) catch |err| switch (err) {
222222 error.FileNotFound => again: {
223223 const code = code: {
224224 if (std.fs.path.dirname(file_name)) |dir_name| {
lib/std/testing.zig+10-10
......@@ -399,7 +399,7 @@ fn SliceDiffer(comptime T: type) type {
399399
400400 pub fn write(self: Self, writer: anytype) !void {
401401 for (self.expected, 0..) |value, i| {
402 var full_index = self.start_index + i;
402 const full_index = self.start_index + i;
403403 const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true;
404404 if (diff) try self.ttyconf.setColor(writer, .red);
405405 if (@typeInfo(T) == .Pointer) {
......@@ -424,7 +424,7 @@ const BytesDiffer = struct {
424424 // to avoid having to calculate diffs twice per chunk
425425 var diffs: std.bit_set.IntegerBitSet(16) = .{ .mask = 0 };
426426 for (chunk, 0..) |byte, i| {
427 var absolute_byte_index = (expected_iterator.index - chunk.len) + i;
427 const absolute_byte_index = (expected_iterator.index - chunk.len) + i;
428428 const diff = if (absolute_byte_index < self.actual.len) self.actual[absolute_byte_index] != byte else true;
429429 if (diff) diffs.set(i);
430430 try self.writeByteDiff(writer, "{X:0>2} ", byte, diff);
......@@ -565,13 +565,13 @@ pub fn tmpDir(opts: std.fs.Dir.OpenDirOptions) TmpDir {
565565 var sub_path: [TmpDir.sub_path_len]u8 = undefined;
566566 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
567567
568 var cwd = std.fs.cwd();
568 const cwd = std.fs.cwd();
569569 var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch
570570 @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir");
571571 defer cache_dir.close();
572 var parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
572 const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
573573 @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir");
574 var dir = parent_dir.makeOpenPath(&sub_path, opts) catch
574 const dir = parent_dir.makeOpenPath(&sub_path, opts) catch
575575 @panic("unable to make tmp dir for testing: unable to make and open the tmp dir");
576576
577577 return .{
......@@ -587,13 +587,13 @@ pub fn tmpIterableDir(opts: std.fs.Dir.OpenDirOptions) TmpIterableDir {
587587 var sub_path: [TmpIterableDir.sub_path_len]u8 = undefined;
588588 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
589589
590 var cwd = std.fs.cwd();
590 const cwd = std.fs.cwd();
591591 var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch
592592 @panic("unable to make tmp dir for testing: unable to make and open zig-cache dir");
593593 defer cache_dir.close();
594 var parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
594 const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
595595 @panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir");
596 var dir = parent_dir.makeOpenPathIterable(&sub_path, opts) catch
596 const dir = parent_dir.makeOpenPathIterable(&sub_path, opts) catch
597597 @panic("unable to make tmp dir for testing: unable to make and open the tmp dir");
598598
599599 return .{
......@@ -618,8 +618,8 @@ test "expectEqual nested array" {
618618}
619619
620620test "expectEqual vector" {
621 var a: @Vector(4, u32) = @splat(4);
622 var b: @Vector(4, u32) = @splat(4);
621 const a: @Vector(4, u32) = @splat(4);
622 const b: @Vector(4, u32) = @splat(4);
623623
624624 try expectEqual(a, b);
625625}
lib/std/treap.zig+1-1
......@@ -379,7 +379,7 @@ test "std.Treap: insert, find, replace, remove" {
379379 const key = node.key;
380380
381381 // find the entry by-key and by-node after having been inserted.
382 var entry = treap.getEntryFor(node.key);
382 const entry = treap.getEntryFor(node.key);
383383 try testing.expectEqual(entry.key, key);
384384 try testing.expectEqual(entry.node, node);
385385 try testing.expectEqual(entry.node, treap.getEntryForExisting(node).node);
lib/std/unicode.zig+1-1
......@@ -242,7 +242,7 @@ pub fn utf8ValidateSlice(input: []const u8) bool {
242242 s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
243243 };
244244
245 var n = remaining.len;
245 const n = remaining.len;
246246 var i: usize = 0;
247247 while (i < n) {
248248 const first_byte = remaining[i];
lib/std/zig/Parse.zig+1-2
......@@ -3516,7 +3516,6 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers {
35163516 var saw_const = false;
35173517 var saw_volatile = false;
35183518 var saw_allowzero = false;
3519 var saw_addrspace = false;
35203519 while (true) {
35213520 switch (p.token_tags[p.tok_i]) {
35223521 .keyword_align => {
......@@ -3557,7 +3556,7 @@ fn parsePtrModifiers(p: *Parse) !PtrModifiers {
35573556 saw_allowzero = true;
35583557 },
35593558 .keyword_addrspace => {
3560 if (saw_addrspace) {
3559 if (result.addrspace_node != 0) {
35613560 try p.warn(.extra_addrspace_qualifier);
35623561 }
35633562 result.addrspace_node = try p.parseAddrSpace();
lib/std/zig/c_translation.zig+8-7
......@@ -129,6 +129,7 @@ test "cast" {
129129 try testing.expectEqual(@as(?*anyopaque, @ptrFromInt(2)), cast(?*anyopaque, @as(*u8, @ptrFromInt(2))));
130130
131131 var foo: c_int = -1;
132 _ = &foo;
132133 try testing.expect(cast(*anyopaque, -1) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
133134 try testing.expect(cast(*anyopaque, foo) == @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
134135 try testing.expect(cast(?*anyopaque, -1) == @as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))));
......@@ -601,22 +602,22 @@ test "WL_CONTAINER_OF" {
601602 a: u32 = 0,
602603 b: u32 = 0,
603604 };
604 var x = S{};
605 var y = S{};
606 var ptr = Macros.WL_CONTAINER_OF(&x.b, &y, "b");
605 const x = S{};
606 const y = S{};
607 const ptr = Macros.WL_CONTAINER_OF(&x.b, &y, "b");
607608 try testing.expectEqual(&x, ptr);
608609}
609610
610611test "CAST_OR_CALL casting" {
611 var arg = @as(c_int, 1000);
612 var casted = Macros.CAST_OR_CALL(u8, arg);
612 const arg: c_int = 1000;
613 const casted = Macros.CAST_OR_CALL(u8, arg);
613614 try testing.expectEqual(cast(u8, arg), casted);
614615
615616 const S = struct {
616617 x: u32 = 0,
617618 };
618 var s = S{};
619 var casted_ptr = Macros.CAST_OR_CALL(*u8, &s);
619 var s: S = .{};
620 const casted_ptr = Macros.CAST_OR_CALL(*u8, &s);
620621 try testing.expectEqual(cast(*u8, &s), casted_ptr);
621622}
622623
lib/std/zig/perf_test.zig+1-1
......@@ -32,7 +32,7 @@ pub fn main() !void {
3232
3333fn testOnce() usize {
3434 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
35 var allocator = fixed_buf_alloc.allocator();
35 const allocator = fixed_buf_alloc.allocator();
3636 _ = std.zig.Ast.parse(allocator, source, .zig) catch @panic("parse failure");
3737 return fixed_buf_alloc.end_index;
3838}
lib/std/zig/render.zig+1-1
......@@ -3495,7 +3495,7 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
34953495 /// Turns all one-shot indents into regular indents
34963496 /// Returns number of indents that must now be manually popped
34973497 pub fn lockOneShotIndent(self: *Self) usize {
3498 var locked_count = self.indent_one_shot_count;
3498 const locked_count = self.indent_one_shot_count;
34993499 self.indent_one_shot_count = 0;
35003500 return locked_count;
35013501 }
lib/std/zig/string_literal.zig+1-1
......@@ -288,7 +288,7 @@ test "parse" {
288288
289289 var fixed_buf_mem: [64]u8 = undefined;
290290 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(&fixed_buf_mem);
291 var alloc = fixed_buf_alloc.allocator();
291 const alloc = fixed_buf_alloc.allocator();
292292
293293 try expectError(error.InvalidLiteral, parseAlloc(alloc, "\"\\x6\""));
294294 try expect(eql(u8, "foo\nbar", try parseAlloc(alloc, "\"foo\\nbar\"")));
lib/std/zig/system/NativeTargetInfo.zig+1-1
......@@ -189,7 +189,7 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {
189189 // native CPU architecture as being different than the current target), we use this:
190190 const cpu_arch = cross_target.getCpuArch();
191191
192 var cpu = switch (cross_target.cpu_model) {
192 const cpu = switch (cross_target.cpu_model) {
193193 .native => detectNativeCpuAndFeatures(cpu_arch, os, cross_target),
194194 .baseline => Target.Cpu.baseline(cpu_arch),
195195 .determined_by_cpu_arch => if (cross_target.cpu_arch == null)