Skip to content

Commit 6b1a823

Browse files
authored
Merge pull request #18017 from mlugg/var-never-mutated
compiler: add error for unnecessary use of 'var'
2 parents 325e0f5 + 9cf6c1a commit 6b1a823

File tree

632 files changed

+3285
-2015
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

632 files changed

+3285
-2015
lines changed

doc/langref.html.in

Lines changed: 121 additions & 94 deletions
Large diffs are not rendered by default.

lib/build_runner.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const testing = @import("std").testing;
33
const __absvdi2 = @import("absvdi2.zig").__absvdi2;
44

55
fn 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const testing = @import("std").testing;
33
const __absvsi2 = @import("absvsi2.zig").__absvsi2;
44

55
fn 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const testing = @import("std").testing;
33
const __absvti2 = @import("absvti2.zig").__absvti2;
44

55
fn 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ comptime {
1818
inline 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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const math = std.math;
66
fn 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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const testing = @import("std").testing;
44
fn 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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const math = std.math;
66
fn 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const bswap = @import("bswap.zig");
22
const testing = @import("std").testing;
33

44
fn 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

0 commit comments

Comments
 (0)