From b5970a834169d35a01bd76d933fca7664719b91b Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Tue, 21 Nov 2023 02:24:32 -0800 Subject: [PATCH] Fix 'local variable is never mutated' errors --- src/bmp.zig | 2 +- src/cli.zig | 10 +++++----- src/code_pages.zig | 6 +++--- src/comments.zig | 8 ++++---- src/compile.zig | 8 ++++---- src/lang.zig | 2 +- src/main.zig | 14 +++++++------- src/parse.zig | 12 ++++++------ src/res.zig | 4 ++-- src/source_mapping.zig | 12 ++++++------ test/fuzz_rc.zig | 4 ++-- test/fuzz_winafl.zig | 2 +- test/fuzzy_ascii_strings.zig | 2 +- test/fuzzy_bitmaps.zig | 4 ++-- test/fuzzy_code_pages.zig | 2 +- test/fuzzy_fonts.zig | 2 +- test/fuzzy_icons.zig | 2 +- test/fuzzy_name_or_ordinal.zig | 2 +- test/fuzzy_number_expressions.zig | 2 +- test/fuzzy_numbers.zig | 2 +- test/fuzzy_stringtable.zig | 2 +- test/parse.zig | 2 +- test/utils.zig | 28 ++++++++++++++-------------- 23 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/bmp.zig b/src/bmp.zig index 1c7e0f6..134ee81 100644 --- a/src/bmp.zig +++ b/src/bmp.zig @@ -120,7 +120,7 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { var dib_header_buf: [@sizeOf(BITMAPCOREHEADER)]u8 align(@alignOf(BITMAPCOREHEADER)) = undefined; std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .little); reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; - var dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf); + const dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf); structFieldsLittleToNative(BITMAPCOREHEADER, dib_header); // > The size of the color palette is calculated from the BitsPerPixel value. diff --git a/src/cli.zig b/src/cli.zig index 50dbed5..7fb6573 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -163,15 +163,15 @@ pub const Options = struct { // we shouldn't change anything. if (val_ptr.* == .undefine) return; // Otherwise, the new value takes precedence. - var duped_value = try self.allocator.dupe(u8, value); + const duped_value = try self.allocator.dupe(u8, value); errdefer self.allocator.free(duped_value); val_ptr.deinit(self.allocator); val_ptr.* = .{ .define = duped_value }; return; } - var duped_key = try self.allocator.dupe(u8, identifier); + const duped_key = try self.allocator.dupe(u8, identifier); errdefer self.allocator.free(duped_key); - var duped_value = try self.allocator.dupe(u8, value); + const duped_value = try self.allocator.dupe(u8, value); errdefer self.allocator.free(duped_value); try self.symbols.put(self.allocator, duped_key, .{ .define = duped_value }); } @@ -183,7 +183,7 @@ pub const Options = struct { action.* = .{ .undefine = {} }; return; } - var duped_key = try self.allocator.dupe(u8, identifier); + const duped_key = try self.allocator.dupe(u8, identifier); errdefer self.allocator.free(duped_key); try self.symbols.put(self.allocator, duped_key, .{ .undefine = {} }); } @@ -828,7 +828,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn } } - var positionals = args[arg_i..]; + const positionals = args[arg_i..]; if (positionals.len < 1) { var err_details = Diagnostics.ErrorDetails{ .print_args = false, .arg_index = arg_i }; diff --git a/src/code_pages.zig b/src/code_pages.zig index 4b9a87c..be89ed3 100644 --- a/src/code_pages.zig +++ b/src/code_pages.zig @@ -302,8 +302,8 @@ pub const Utf8 = struct { pub fn decode(bytes: []const u8) Codepoint { std.debug.assert(bytes.len > 0); - var first_byte = bytes[0]; - var expected_len = sequenceLength(first_byte) orelse { + const first_byte = bytes[0]; + const expected_len = sequenceLength(first_byte) orelse { return .{ .value = Codepoint.invalid, .byte_len = 1 }; }; if (expected_len == 1) return .{ .value = first_byte, .byte_len = 1 }; @@ -367,7 +367,7 @@ pub const Utf8 = struct { test "Utf8.WellFormedDecoder" { const invalid_utf8 = "\xF0\x80"; - var decoded = Utf8.WellFormedDecoder.decode(invalid_utf8); + const decoded = Utf8.WellFormedDecoder.decode(invalid_utf8); try std.testing.expectEqual(Codepoint.invalid, decoded.value); try std.testing.expectEqual(@as(usize, 2), decoded.byte_len); } diff --git a/src/comments.zig b/src/comments.zig index 7b63838..67504bb 100644 --- a/src/comments.zig +++ b/src/comments.zig @@ -214,9 +214,9 @@ inline fn handleMultilineCarriageReturn( } pub fn removeCommentsAlloc(allocator: Allocator, source: []const u8, source_mappings: ?*SourceMappings) ![]u8 { - var buf = try allocator.alloc(u8, source.len); + const buf = try allocator.alloc(u8, source.len); errdefer allocator.free(buf); - var result = try removeComments(source, buf, source_mappings); + const result = try removeComments(source, buf, source_mappings); return allocator.realloc(buf, result.len); } @@ -344,7 +344,7 @@ test "remove comments with mappings" { try mappings.set(3, 3, 0); defer mappings.deinit(allocator); - var result = try removeComments(&mut_source, &mut_source, &mappings); + const result = try removeComments(&mut_source, &mut_source, &mappings); try std.testing.expectEqualStrings("blahblah", result); try std.testing.expectEqual(@as(usize, 1), mappings.end_line); @@ -353,6 +353,6 @@ test "remove comments with mappings" { test "in place" { var mut_source = "blah /* comment */ blah".*; - var result = try removeComments(&mut_source, &mut_source, null); + const result = try removeComments(&mut_source, &mut_source, null); try std.testing.expectEqualStrings("blah blah", result); } diff --git a/src/compile.zig b/src/compile.zig index f75b699..add39ea 100644 --- a/src/compile.zig +++ b/src/compile.zig @@ -735,7 +735,7 @@ pub const Compiler = struct { }, }, .dib => { - var bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes)); + const bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes)); if (native_endian == .big) { std.mem.byteSwapAllFields(ico.BitmapHeader, bitmap_header); } @@ -1843,13 +1843,13 @@ pub const Compiler = struct { } try data_writer.writeByteNTimes(0, num_padding); - var style = if (control.style) |style_expression| + const style = if (control.style) |style_expression| // Certain styles are implied by the control type evaluateFlagsExpressionWithDefault(res.ControlClass.getImpliedStyle(control_type), style_expression, self.source, self.input_code_pages) else res.ControlClass.getImpliedStyle(control_type); - var exstyle = if (control.exstyle) |exstyle_expression| + const exstyle = if (control.exstyle) |exstyle_expression| evaluateFlagsExpressionWithDefault(0, exstyle_expression, self.source, self.input_code_pages) else 0; @@ -3263,7 +3263,7 @@ pub const StringTable = struct { const trimmed_string = trim: { // Two NUL characters in a row act as a terminator // Note: This is only the case for STRINGTABLE strings - var trimmed = trimToDoubleNUL(u16, utf16_string); + const trimmed = trimToDoubleNUL(u16, utf16_string); // We also want to trim any trailing NUL characters break :trim std.mem.trimRight(u16, trimmed, &[_]u16{0}); }; diff --git a/src/lang.zig b/src/lang.zig index d43380f..513d775 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -98,7 +98,7 @@ pub fn tagToId(tag: []const u8) error{InvalidLanguageTag}!?LanguageId { var normalized_buf: [longest_known_tag]u8 = undefined; // To allow e.g. `de-de_phoneb` to get looked up as `de-de`, we need to // omit the suffix, but only if the tag contains a valid alternate sort order. - var tag_to_normalize = if (parsed.isSuffixValidSortOrder()) tag[0 .. tag.len - (parsed.suffix.?.len + 1)] else tag; + const tag_to_normalize = if (parsed.isSuffixValidSortOrder()) tag[0 .. tag.len - (parsed.suffix.?.len + 1)] else tag; const normalized_tag = normalizeTag(tag_to_normalize, &normalized_buf); return std.meta.stringToEnum(LanguageId, normalized_tag) orelse { // special case for a tag that has been mapped to the same ID diff --git a/src/main.zig b/src/main.zig index 392f045..cf0f6a3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -23,7 +23,7 @@ pub fn main() !void { const stderr_config = std.io.tty.detectConfig(stderr); var options = options: { - var args = try std.process.argsAlloc(allocator); + const args = try std.process.argsAlloc(allocator); defer std.process.argsFree(allocator, args); var cli_diagnostics = cli.Diagnostics.init(allocator); @@ -60,7 +60,7 @@ pub fn main() !void { try stdout_writer.writeByte('\n'); } - var full_input = full_input: { + const full_input = full_input: { if (options.preprocess != .no) { var argv = std.ArrayList([]const u8).init(allocator); defer argv.deinit(); @@ -118,7 +118,7 @@ pub fn main() !void { try stdout_writer.print("{s}\n\n", .{argv.items[argv.items.len - 1]}); } - var result = std.ChildProcess.run(.{ + const result = std.ChildProcess.run(.{ .allocator = allocator, .argv = argv.items, .max_output_bytes = std.math.maxInt(u32), @@ -173,7 +173,7 @@ pub fn main() !void { // may be a mismatch in how the line directive strings are parsed versus // how they are escaped/written by the preprocessor. - var final_input = removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings) catch |err| switch (err) { + const final_input = removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings) catch |err| switch (err) { error.InvalidSourceMappingCollapse => { try renderErrorMessage(stderr.writer(), stderr_config, .err, "failed during comment removal; this is a known bug", .{}); std.os.exit(1); @@ -302,7 +302,7 @@ const Preprocessor = enum { try argv.appendSlice(pre.getCommandArgs()); try argv.append("--version"); - var result = std.ChildProcess.run(.{ + const result = std.ChildProcess.run(.{ .allocator = allocator, .argv = argv.items, .max_output_bytes = std.math.maxInt(u16), @@ -385,7 +385,7 @@ const Preprocessor = enum { fn zigSupportsLibcIncludesOption(allocator: std.mem.Allocator) !bool { if (Preprocessor.zig_supports_libc_includes_option == null) { - var result = std.ChildProcess.run(.{ + const result = std.ChildProcess.run(.{ .allocator = allocator, .argv = &.{ "zig", "libc", "-includes" }, .max_output_bytes = std.math.maxInt(u16), @@ -407,7 +407,7 @@ const Preprocessor = enum { } fn getIncludeDirsFromZig(allocator: std.mem.Allocator, target: []const u8) ![]const []const u8 { - var result = try std.ChildProcess.run(.{ + const result = try std.ChildProcess.run(.{ .allocator = allocator, .argv = &.{ "zig", "libc", "-includes", "-target", target }, .max_output_bytes = std.math.maxInt(u16), diff --git a/src/parse.zig b/src/parse.zig index 7b67e23..ed43f9d1 100644 --- a/src/parse.zig +++ b/src/parse.zig @@ -100,7 +100,7 @@ pub const Parser = struct { // because it almost always leads to unhelpful error messages // (usually it will end up with bogus things like 'file // not found: {') - var statement = try self.parseStatement(); + const statement = try self.parseStatement(); try statements.append(statement); } } @@ -712,7 +712,7 @@ pub const Parser = struct { .dlginclude => { const common_resource_attributes = try self.parseCommonResourceAttributes(); - var filename_expression = try self.parseExpression(.{ + const filename_expression = try self.parseExpression(.{ .allowed_types = .{ .string = true }, }); @@ -770,7 +770,7 @@ pub const Parser = struct { return &node.base; } - var filename_expression = try self.parseExpression(.{ + const filename_expression = try self.parseExpression(.{ // Don't tell the user that numbers are accepted since we error on // number expressions and regular number literals are treated as unquoted // literals rather than numbers, so from the users perspective @@ -948,8 +948,8 @@ pub const Parser = struct { style = try optional_param_parser.parse(.{ .not_expression_allowed = true }); } - var exstyle: ?*Node = try optional_param_parser.parse(.{ .not_expression_allowed = true }); - var help_id: ?*Node = switch (resource) { + const exstyle: ?*Node = try optional_param_parser.parse(.{ .not_expression_allowed = true }); + const help_id: ?*Node = switch (resource) { .dialogex => try optional_param_parser.parse(.{}), else => null, }; @@ -1540,7 +1540,7 @@ pub const Parser = struct { pub fn toErrorDetails(options: ParseExpressionOptions, token: Token) ErrorDetails { // TODO: expected_types_override interaction with is_known_to_be_number_expression? - var expected_types = options.expected_types_override orelse ErrorDetails.ExpectedTypes{ + const expected_types = options.expected_types_override orelse ErrorDetails.ExpectedTypes{ .number = options.allowed_types.number, .number_expression = options.allowed_types.number, .string_literal = options.allowed_types.string and !options.is_known_to_be_number_expression, diff --git a/src/res.zig b/src/res.zig index c8d22fc..991e0b8 100644 --- a/src/res.zig +++ b/src/res.zig @@ -357,7 +357,7 @@ pub const NameOrOrdinal = union(enum) { /// RC compiler would have allowed them, so that a proper warning/error /// can be emitted. pub fn maybeNonAsciiOrdinalFromString(bytes: SourceBytes) ?NameOrOrdinal { - var buf = bytes.slice; + const buf = bytes.slice; const radix = 10; if (buf.len > 2 and buf[0] == '0') { switch (buf[1]) { @@ -514,7 +514,7 @@ test "NameOrOrdinal" { { var expected = blk: { // the input before the 𐐷 character, but uppercased - var expected_u8_bytes = "00614982008907933748980730280674788429543776231864944218790698304852300002973622122844631429099469274282385299397783838528QFFL7SHNSIETG0QKLR1UYPBTUV1PMFQRRA0VJDG354GQEDJMUPGPP1W1EXVNTZVEIZ6K3IPQM1AWGEYALMEODYVEZGOD3MFMGEY8FNR4JUETTB1PZDEWSNDRGZUA8SNXP3NGO"; + const expected_u8_bytes = "00614982008907933748980730280674788429543776231864944218790698304852300002973622122844631429099469274282385299397783838528QFFL7SHNSIETG0QKLR1UYPBTUV1PMFQRRA0VJDG354GQEDJMUPGPP1W1EXVNTZVEIZ6K3IPQM1AWGEYALMEODYVEZGOD3MFMGEY8FNR4JUETTB1PZDEWSNDRGZUA8SNXP3NGO"; var buf: [256:0]u16 = undefined; for (expected_u8_bytes, 0..) |byte, i| { buf[i] = std.mem.nativeToLittle(u16, byte); diff --git a/src/source_mapping.zig b/src/source_mapping.zig index 89bd72c..37f0b47 100644 --- a/src/source_mapping.zig +++ b/src/source_mapping.zig @@ -244,7 +244,7 @@ pub fn handleLineCommand(allocator: Allocator, line_command: []const u8, current } pub fn parseAndRemoveLineCommandsAlloc(allocator: Allocator, source: []const u8, options: ParseAndRemoveLineCommandsOptions) !ParseLineCommandsResult { - var buf = try allocator.alloc(u8, source.len); + const buf = try allocator.alloc(u8, source.len); errdefer allocator.free(buf); var result = try parseAndRemoveLineCommands(allocator, source, buf, options); result.result = try allocator.realloc(buf, result.result.len); @@ -487,15 +487,15 @@ pub const SourceMappings = struct { /// Note: `line_num` and `corresponding_line_num` start at 1 pub fn set(self: *SourceMappings, line_num: usize, corresponding_line_num: usize, filename_offset: u32) !void { - var maybe_node = self.findNode(line_num); + const maybe_node = self.findNode(line_num); - var need_new_node = need_new_node: { + const need_new_node = need_new_node: { if (maybe_node) |node| { if (node.key.filename_offset != filename_offset) { break :need_new_node true; } - var exist_delta = @as(i64, @intCast(node.key.corresponding_start_line)) - @as(i64, @intCast(node.key.start_line)); - var cur_delta = @as(i64, @intCast(corresponding_line_num)) - @as(i64, @intCast(line_num)); + const exist_delta = @as(i64, @intCast(node.key.corresponding_start_line)) - @as(i64, @intCast(node.key.start_line)); + const cur_delta = @as(i64, @intCast(corresponding_line_num)) - @as(i64, @intCast(line_num)); if (exist_delta != cur_delta) { break :need_new_node true; } @@ -551,7 +551,7 @@ pub const SourceMappings = struct { pub fn collapse(self: *SourceMappings, line_num: usize, num_following_lines_to_collapse: usize) !void { std.debug.assert(num_following_lines_to_collapse > 0); var node = self.findNode(line_num).?; - var span_diff = num_following_lines_to_collapse; + const span_diff = num_following_lines_to_collapse; if (node.key.start_line != line_num) { const offset = line_num - node.key.start_line; const key = Source{ diff --git a/test/fuzz_rc.zig b/test/fuzz_rc.zig index 7a5ac5a..f965050 100644 --- a/test/fuzz_rc.zig +++ b/test/fuzz_rc.zig @@ -13,7 +13,7 @@ pub fn zigMain() !void { const allocator = gpa.allocator(); const stdin = std.io.getStdIn(); - var data = try stdin.readToEndAlloc(allocator, std.math.maxInt(usize)); + const data = try stdin.readToEndAlloc(allocator, std.math.maxInt(usize)); defer allocator.free(data); const dummy_filename = "fuzz.rc"; @@ -21,7 +21,7 @@ pub fn zigMain() !void { var mapping_results = try resinator.source_mapping.parseAndRemoveLineCommands(allocator, data, data, .{ .initial_filename = dummy_filename }); defer mapping_results.mappings.deinit(allocator); - var final_input = try resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); + const final_input = try resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); var diagnostics = resinator.errors.Diagnostics.init(allocator); defer diagnostics.deinit(); diff --git a/test/fuzz_winafl.zig b/test/fuzz_winafl.zig index 68d9211..3e38f5a 100644 --- a/test/fuzz_winafl.zig +++ b/test/fuzz_winafl.zig @@ -49,7 +49,7 @@ pub fn main() !void { } { - var tmp_dir = try std.process.getEnvVarOwned(allocator, "TEMP"); + const tmp_dir = try std.process.getEnvVarOwned(allocator, "TEMP"); defer allocator.free(tmp_dir); std.mem.copy(u8, &tmp_buf, tmp_dir); diff --git a/test/fuzzy_ascii_strings.zig b/test/fuzzy_ascii_strings.zig index 50547a1..f9af14c 100644 --- a/test/fuzzy_ascii_strings.zig +++ b/test/fuzzy_ascii_strings.zig @@ -66,7 +66,7 @@ test "single char escapes" { test "fuzz" { const allocator = std.testing.allocator; var random = std.rand.DefaultPrng.init(0); - var rand = random.random(); + const rand = random.random(); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); diff --git a/test/fuzzy_bitmaps.zig b/test/fuzzy_bitmaps.zig index f266a03..07b0b2a 100644 --- a/test/fuzzy_bitmaps.zig +++ b/test/fuzzy_bitmaps.zig @@ -34,7 +34,7 @@ test "BITMAP fuzz" { const bmp_file_header_len = 14; const dib_header_len = 40; - var real_data_size = random_bytes_len + bmp_file_header_len + dib_header_len; + const real_data_size = random_bytes_len + bmp_file_header_len + dib_header_len; const reported_data_size = if (rand.boolean()) // essentially `real_data_size -| rand.int(i8)` @@ -70,7 +70,7 @@ test "BITMAP fuzz" { // and now a bunch of random bytes try image_buffer.ensureUnusedCapacity(random_bytes_len); - var slice_to_fill = image_buffer.unusedCapacitySlice()[0..random_bytes_len]; + const slice_to_fill = image_buffer.unusedCapacitySlice()[0..random_bytes_len]; rand.bytes(slice_to_fill); image_buffer.items.len += random_bytes_len; diff --git a/test/fuzzy_code_pages.zig b/test/fuzzy_code_pages.zig index 1e3eb73..a8da0d1 100644 --- a/test/fuzzy_code_pages.zig +++ b/test/fuzzy_code_pages.zig @@ -61,7 +61,7 @@ test "windows-1252 mappings" { test "fuzz" { const allocator = std.testing.allocator; var random = std.rand.DefaultPrng.init(0); - var rand = random.random(); + const rand = random.random(); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); diff --git a/test/fuzzy_fonts.zig b/test/fuzzy_fonts.zig index ac84fdd..da678d1 100644 --- a/test/fuzzy_fonts.zig +++ b/test/fuzzy_fonts.zig @@ -30,7 +30,7 @@ test "FONT fuzz" { // Just a bunch of random bytes const random_bytes_len = rand.uintLessThanBiased(u32, max_file_len); try font_buffer.ensureUnusedCapacity(random_bytes_len); - var slice_to_fill = font_buffer.unusedCapacitySlice()[0..random_bytes_len]; + const slice_to_fill = font_buffer.unusedCapacitySlice()[0..random_bytes_len]; rand.bytes(slice_to_fill); font_buffer.items.len += random_bytes_len; diff --git a/test/fuzzy_icons.zig b/test/fuzzy_icons.zig index 1b4ae8d..2619d6a 100644 --- a/test/fuzzy_icons.zig +++ b/test/fuzzy_icons.zig @@ -71,7 +71,7 @@ test "ICON fuzz" { // and now a bunch of random bytes try icon_buffer.ensureUnusedCapacity(random_bytes_len); - var slice_to_fill = icon_buffer.unusedCapacitySlice()[0..random_bytes_len]; + const slice_to_fill = icon_buffer.unusedCapacitySlice()[0..random_bytes_len]; rand.bytes(slice_to_fill); icon_buffer.items.len += random_bytes_len; diff --git a/test/fuzzy_name_or_ordinal.zig b/test/fuzzy_name_or_ordinal.zig index a17aa8d..8618cfc 100644 --- a/test/fuzzy_name_or_ordinal.zig +++ b/test/fuzzy_name_or_ordinal.zig @@ -6,7 +6,7 @@ const iterations = fuzzy_options.max_iterations; test { const allocator = std.testing.allocator; var random = std.rand.DefaultPrng.init(0); - var rand = random.random(); + const rand = random.random(); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); diff --git a/test/fuzzy_number_expressions.zig b/test/fuzzy_number_expressions.zig index c6dd669..1794826 100644 --- a/test/fuzzy_number_expressions.zig +++ b/test/fuzzy_number_expressions.zig @@ -6,7 +6,7 @@ const iterations = fuzzy_options.max_iterations; test { const allocator = std.testing.allocator; var random = std.rand.DefaultPrng.init(0); - var rand = random.random(); + const rand = random.random(); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); diff --git a/test/fuzzy_numbers.zig b/test/fuzzy_numbers.zig index 1033e72..c88fe24 100644 --- a/test/fuzzy_numbers.zig +++ b/test/fuzzy_numbers.zig @@ -6,7 +6,7 @@ const iterations = fuzzy_options.max_iterations; test { const allocator = std.testing.allocator; var random = std.rand.DefaultPrng.init(0); - var rand = random.random(); + const rand = random.random(); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); diff --git a/test/fuzzy_stringtable.zig b/test/fuzzy_stringtable.zig index 7f1821e..7c1ddb4 100644 --- a/test/fuzzy_stringtable.zig +++ b/test/fuzzy_stringtable.zig @@ -6,7 +6,7 @@ const iterations = fuzzy_options.max_iterations; test "fuzz" { const allocator = std.testing.allocator; var random = std.rand.DefaultPrng.init(0); - var rand = random.random(); + const rand = random.random(); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); diff --git a/test/parse.zig b/test/parse.zig index 91e5b9f..0641f1a 100644 --- a/test/parse.zig +++ b/test/parse.zig @@ -2218,7 +2218,7 @@ fn testParseErrorDetails(expected_details: []const ExpectedErrorDetails, source: const tree: ?*resinator.ast.Tree = tree: { var lexer = resinator.lex.Lexer.init(source, .{}); var parser = resinator.parse.Parser.init(&lexer, .{}); - var tree = parser.parse(allocator, &diagnostics) catch |err| switch (err) { + const tree = parser.parse(allocator, &diagnostics) catch |err| switch (err) { error.OutOfMemory => |e| return e, error.ParseError => { if (!expect_fail) { diff --git a/test/utils.zig b/test/utils.zig index a05400e..34912bc 100644 --- a/test/utils.zig +++ b/test/utils.zig @@ -177,7 +177,7 @@ pub fn getResinatorResultFromFile(allocator: Allocator, input_filepath: []const if (!options.run_preprocessor) { result.rc_data = try options.cwd.readFileAlloc(allocator, input_filepath, std.math.maxInt(usize)); } - var data = result.rc_data orelse result.pre.?.preprocessor.stdout; + const data = result.rc_data orelse result.pre.?.preprocessor.stdout; var mapping_results = try resinator.source_mapping.parseAndRemoveLineCommands( allocator, @@ -187,7 +187,7 @@ pub fn getResinatorResultFromFile(allocator: Allocator, input_filepath: []const ); defer mapping_results.mappings.deinit(allocator); - var final_input = try resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); + const final_input = try resinator.comments.removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings); result.processed_rc = final_input; // TODO: Somehow make this re-usable between calls @@ -221,7 +221,7 @@ pub fn runPreprocessor(allocator: Allocator, input_filepath: []const u8, options var result = ResinatorResult.PreprocessResult{}; - var data = try options.cwd.readFileAlloc(allocator, input_filepath, std.math.maxInt(usize)); + const data = try options.cwd.readFileAlloc(allocator, input_filepath, std.math.maxInt(usize)); defer allocator.free(data); if (inputContainsKnownPreprocessorDifference(data)) { @@ -282,7 +282,7 @@ pub fn getWin32Result(allocator: Allocator, source: []const u8, options: GetResu pub fn getWin32ResultFromFile(allocator: Allocator, input_path: []const u8, options: GetResultOptions) !Win32Result { const output_path = options.output_path orelse "test_win32.res"; - var exec_result = try std.ChildProcess.run(.{ + const exec_result = try std.ChildProcess.run(.{ .allocator = allocator, .argv = &[_][]const u8{ // Note: This relies on `rc.exe` being in the PATH @@ -313,7 +313,7 @@ pub fn randomNumberLiteral(allocator: Allocator, rand: std.rand.Random, comptime errdefer buf.deinit(); const Prefix = enum { none, minus, complement }; - var prefix = rand.enumValue(Prefix); + const prefix = rand.enumValue(Prefix); switch (prefix) { .none => {}, @@ -377,12 +377,12 @@ const dicts = struct { }; pub fn randomAlpha(rand: std.rand.Random) u8 { - var index = rand.uintLessThanBiased(u8, dicts.alpha.len); + const index = rand.uintLessThanBiased(u8, dicts.alpha.len); return dicts.alpha[index]; } pub fn randomAlphanumeric(rand: std.rand.Random) u8 { - var index = rand.uintLessThanBiased(u8, dicts.alphanumeric.len); + const index = rand.uintLessThanBiased(u8, dicts.alphanumeric.len); return dicts.alphanumeric[index]; } @@ -393,14 +393,14 @@ pub fn randomNumeric(rand: std.rand.Random) u8 { /// Includes Windows-1252 encoded ¹ ² ³ pub fn randomNumericRC(rand: std.rand.Random) u8 { const dict = dicts.digits ++ [_]u8{ '\xb2', '\xb3', '\xb9' }; - var index = rand.uintLessThanBiased(u8, dict.len); + const index = rand.uintLessThanBiased(u8, dict.len); return dict[index]; } /// Includes Windows-1252 encoded ¹ ² ³ pub fn randomAlphanumericRC(rand: std.rand.Random) u8 { const dict = dicts.alphanumeric ++ [_]u8{ '\xb2', '\xb3', '\xb9' }; - var index = rand.uintLessThanBiased(u8, dict.len); + const index = rand.uintLessThanBiased(u8, dict.len); return dict[index]; } @@ -413,7 +413,7 @@ pub fn randomOperator(rand: std.rand.Random) u8 { pub fn randomAsciiStringLiteral(allocator: Allocator, rand: std.rand.Random) ![]const u8 { // max string literal length is 4097 so this will generate some invalid string literals // need at least two for the "" - var slice_len = rand.uintAtMostBiased(u16, 256) + 2; + const slice_len = rand.uintAtMostBiased(u16, 256) + 2; var buf = try allocator.alloc(u8, slice_len); errdefer allocator.free(buf); @@ -470,12 +470,12 @@ pub fn randomAlphanumExtendedBytes(allocator: Allocator, rand: std.rand.Random) }; const dict = dicts.alphanumeric ++ extended; // at least 1 byte - var slice_len = rand.uintAtMostBiased(u16, 512) + 1; - var buf = try allocator.alloc(u8, slice_len); + const slice_len = rand.uintAtMostBiased(u16, 512) + 1; + const buf = try allocator.alloc(u8, slice_len); errdefer allocator.free(buf); for (buf) |*c| { - var index = rand.uintLessThanBiased(u8, dict.len); + const index = rand.uintLessThanBiased(u8, dict.len); var byte = dict[index]; // swap out e/E to avoid 'expected exponent value' errors if (byte == 'e' or byte == 'E') byte += 1; @@ -586,7 +586,7 @@ pub const KPermutationsIterator = struct { if (tail > 0) { var swap_in: usize = 0; - var pivot: usize = self.indexes[tail - 1]; + const pivot: usize = self.indexes[tail - 1]; if (pivot >= self.indexes[n - 1]) { swap_in = tail;