diff --git a/lib/std/build.zig b/lib/std/build.zig index 750cff22024d..ed40a3af7f6b 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1070,7 +1070,7 @@ pub const Builder = struct { warn("truncate {s}\n", .{dest_path}); } const cwd = fs.cwd(); - var src_file = cwd.createFile(dest_path, .{}) catch |err| switch (err) { + const src_file = cwd.createFile(dest_path, .{}) catch |err| switch (err) { error.FileNotFound => blk: { if (fs.path.dirname(dest_path)) |dirname| { try cwd.makePath(dirname); @@ -2735,13 +2735,13 @@ pub const LibExeObjStep = struct { const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n"); if (self.output_dir) |output_dir| { - var src_dir = try std.fs.cwd().openDir(build_output_dir, .{ .iterate = true }); + const src_dir = try std.fs.cwd().openDir(build_output_dir, .{ .iterate = true }); defer src_dir.close(); // Create the output directory if it doesn't exist. try std.fs.cwd().makePath(output_dir); - var dest_dir = try std.fs.cwd().openDir(output_dir, .{}); + const dest_dir = try std.fs.cwd().openDir(output_dir, .{}); defer dest_dir.close(); var it = src_dir.iterate(); @@ -2951,7 +2951,7 @@ pub const InstallDirStep = struct { const self = @fieldParentPtr(InstallDirStep, "step", step); const dest_prefix = self.builder.getInstallPath(self.options.install_dir, self.options.install_subdir); const full_src_dir = self.builder.pathFromRoot(self.options.source_dir); - var src_dir = try std.fs.cwd().openDir(full_src_dir, .{ .iterate = true }); + const src_dir = try std.fs.cwd().openDir(full_src_dir, .{ .iterate = true }); defer src_dir.close(); var it = try src_dir.walk(self.builder.allocator); next_entry: while (try it.next()) |entry| { diff --git a/lib/std/build/InstallRawStep.zig b/lib/std/build/InstallRawStep.zig index 2802f1ce90b8..b962d76271fc 100644 --- a/lib/std/build/InstallRawStep.zig +++ b/lib/std/build/InstallRawStep.zig @@ -300,10 +300,10 @@ fn containsValidAddressRange(segments: []*BinaryElfSegment) bool { } fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8, format: RawFormat) !void { - var elf_file = try fs.cwd().openFile(elf_path, .{}); + const elf_file = try fs.cwd().openFile(elf_path, .{}); defer elf_file.close(); - var out_file = try fs.cwd().createFile(raw_path, .{}); + const out_file = try fs.cwd().createFile(raw_path, .{}); defer out_file.close(); var binary_elf_output = try BinaryElfOutput.parse(allocator, elf_file); diff --git a/lib/std/build/WriteFileStep.zig b/lib/std/build/WriteFileStep.zig index 5a8d806049eb..03cd72aa7745 100644 --- a/lib/std/build/WriteFileStep.zig +++ b/lib/std/build/WriteFileStep.zig @@ -94,7 +94,7 @@ fn make(step: *Step) !void { warn("unable to make path {s}: {s}\n", .{ self.output_dir, @errorName(err) }); return err; }; - var dir = try fs.cwd().openDir(self.output_dir, .{}); + const dir = try fs.cwd().openDir(self.output_dir, .{}); defer dir.close(); { var it = self.files.first; diff --git a/lib/std/debug.zig b/lib/std/debug.zig index d0344ff00c70..e63a5d966b8e 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -917,7 +917,7 @@ fn readMachODebugInfo(allocator: *mem.Allocator, macho_file: File) !ModuleDebugI fn printLineFromFileAnyOs(out_stream: anytype, line_info: LineInfo) !void { // Need this to always block even in async I/O mode, because this could potentially // be called from e.g. the event loop code crashing. - var f = try fs.cwd().openFile(line_info.file_name, .{ .intended_io_mode = .blocking }); + const f = try fs.cwd().openFile(line_info.file_name, .{ .intended_io_mode = .blocking }); defer f.close(); // TODO fstat and make sure that the file has the correct size diff --git a/lib/std/fs.zig b/lib/std/fs.zig index e43f439ad58d..be310cb4375b 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -197,7 +197,7 @@ pub const AtomicFile = struct { pub fn finish(self: *AtomicFile) !void { assert(self.file_exists); if (self.file_open) { - self.file.close(); + self.file.deinit(); self.file_open = false; } try os.renameat(self.dir.fd, self.tmp_path_buf[0..], self.dir.fd, self.dest_basename); @@ -827,7 +827,7 @@ pub const Dir = struct { } try self.name_buffer.appendSlice(base.name); if (base.kind == .Directory) { - var new_dir = top.iter.dir.openDir(base.name, .{ .iterate = true }) catch |err| switch (err) { + const new_dir = top.iter.dir.openDir(base.name, .{ .iterate = true }) catch |err| switch (err) { error.NameTooLong => unreachable, // no path sep in base.name else => |e| return e, }; @@ -905,12 +905,17 @@ pub const Dir = struct { DeviceBusy, } || os.UnexpectedError; - pub fn close(self: *Dir) void { + pub fn close(self: Dir) void { if (need_async_thread) { std.event.Loop.instance.?.close(self.fd); } else { os.close(self.fd); } + } + + /// Close and invalidate the directory. + pub fn deinit(self: *Dir) void { + self.close(); self.* = undefined; } @@ -1806,7 +1811,7 @@ pub const Dir = struct { /// it exactly fits the buffer, or it could mean the buffer was not big enough for the /// entire file. pub fn readFile(self: Dir, file_path: []const u8, buffer: []u8) ![]u8 { - var file = try self.openFile(file_path, .{}); + const file = try self.openFile(file_path, .{}); defer file.close(); const end_index = try file.readAll(buffer); @@ -1833,7 +1838,7 @@ pub const Dir = struct { comptime alignment: u29, comptime optional_sentinel: ?u8, ) !(if (optional_sentinel) |s| [:s]align(alignment) u8 else []align(alignment) u8) { - var file = try self.openFile(file_path, .{}); + const file = try self.openFile(file_path, .{}); defer file.close(); // If the file size doesn't fit a usize it'll be certainly greater than @@ -2024,7 +2029,7 @@ pub const Dir = struct { /// Writes content to the file system, creating a new file if it does not exist, truncating /// if it already exists. pub fn writeFile(self: Dir, sub_path: []const u8, data: []const u8) !void { - var file = try self.createFile(sub_path, .{}); + const file = try self.createFile(sub_path, .{}); defer file.close(); try file.writeAll(data); } @@ -2086,14 +2091,14 @@ pub const Dir = struct { dest_path: []const u8, options: CopyFileOptions, ) !PrevStatus { - var src_file = try source_dir.openFile(source_path, .{}); + const src_file = try source_dir.openFile(source_path, .{}); defer src_file.close(); const src_stat = try src_file.stat(); const actual_mode = options.override_mode orelse src_stat.mode; check_dest_stat: { const dest_stat = blk: { - var dest_file = dest_dir.openFile(dest_path, .{}) catch |err| switch (err) { + const dest_file = dest_dir.openFile(dest_path, .{}) catch |err| switch (err) { error.FileNotFound => break :check_dest_stat, else => |e| return e, }; @@ -2134,7 +2139,7 @@ pub const Dir = struct { dest_path: []const u8, options: CopyFileOptions, ) !void { - var in_file = try source_dir.openFile(source_path, .{}); + const in_file = try source_dir.openFile(source_path, .{}); defer in_file.close(); var size: ?u64 = null; @@ -2370,7 +2375,7 @@ pub fn deleteTreeAbsolute(absolute_path: []const u8) !void { CannotDeleteRootDirectory, }.CannotDeleteRootDirectory; - var dir = try cwd().openDir(dirname, .{}); + const dir = try cwd().openDir(dirname, .{}); defer dir.close(); return dir.deleteTree(path.basename(absolute_path)); diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index 268de8f3c814..a26fe0d0f59f 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -189,6 +189,12 @@ pub const File = struct { } } + /// Close and invalidate the file. + pub fn deinit(self: *File) void { + self.close(); + self.* = undefined; + } + /// Test whether the file refers to a terminal. /// See also `supportsAnsiEscapeCodes`. pub fn isTty(self: File) bool { diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index f2b584d6d465..6f1e637d4b48 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -75,14 +75,14 @@ test "openDirAbsolute" { }; { - var dir = try fs.openDirAbsolute(base_path, .{}); + const dir = try fs.openDirAbsolute(base_path, .{}); defer dir.close(); } for ([_][]const u8{ ".", ".." }) |sub_path| { const dir_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, sub_path }); defer arena.allocator.free(dir_path); - var dir = try fs.openDirAbsolute(dir_path, .{}); + const dir = try fs.openDirAbsolute(dir_path, .{}); defer dir.close(); } } @@ -90,7 +90,7 @@ test "openDirAbsolute" { test "openDir cwd parent .." { if (builtin.os.tag == .wasi) return error.SkipZigTest; - var dir = try fs.cwd().openDir("..", .{}); + const dir = try fs.cwd().openDir("..", .{}); defer dir.close(); } @@ -195,7 +195,7 @@ test "Dir.realpath smoke test" { var tmp_dir = tmpDir(.{}); defer tmp_dir.cleanup(); - var file = try tmp_dir.dir.createFile("test_file", .{ .lock = File.Lock.Shared }); + const file = try tmp_dir.dir.createFile("test_file", .{ .lock = File.Lock.Shared }); // We need to close the file immediately as otherwise on Windows we'll end up // with a sharing violation. file.close(); @@ -230,7 +230,7 @@ test "readAllAlloc" { var tmp_dir = tmpDir(.{}); defer tmp_dir.cleanup(); - var file = try tmp_dir.dir.createFile("test_file", .{ .read = true }); + const file = try tmp_dir.dir.createFile("test_file", .{ .read = true }); defer file.close(); const buf1 = try file.readToEndAlloc(testing.allocator, 1024); @@ -266,7 +266,7 @@ test "directory operations on files" { const test_file_name = "test_file"; var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true }); - file.close(); + file.deinit(); try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name)); try testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{})); @@ -287,7 +287,7 @@ test "directory operations on files" { file = try tmp_dir.dir.openFile(test_file_name, .{}); const stat = try file.stat(); try testing.expect(stat.kind == .File); - file.close(); + file.deinit(); } test "file operations on directories" { @@ -329,7 +329,7 @@ test "file operations on directories" { } // ensure the directory still exists as a sanity check - var dir = try tmp_dir.dir.openDir(test_dir_name, .{}); + const dir = try tmp_dir.dir.openDir(test_dir_name, .{}); dir.close(); } @@ -341,9 +341,9 @@ test "deleteDir" { try testing.expectError(error.FileNotFound, tmp_dir.dir.deleteDir("test_dir")); var dir = try tmp_dir.dir.makeOpenPath("test_dir", .{}); - var file = try dir.createFile("test_file", .{}); + const file = try dir.createFile("test_file", .{}); file.close(); - dir.close(); + dir.deinit(); // deleting a non-empty directory // TODO: Re-enable this check on Windows, see https://github.com/ziglang/zig/issues/5537 @@ -353,7 +353,7 @@ test "deleteDir" { dir = try tmp_dir.dir.openDir("test_dir", .{}); try dir.deleteFile("test_file"); - dir.close(); + dir.deinit(); // deleting an empty directory try tmp_dir.dir.deleteDir("test_dir"); @@ -369,25 +369,25 @@ test "Dir.rename files" { const test_file_name = "test_file"; const renamed_test_file_name = "test_file_renamed"; var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true }); - file.close(); + file.deinit(); try tmp_dir.dir.rename(test_file_name, renamed_test_file_name); // Ensure the file was renamed try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{})); file = try tmp_dir.dir.openFile(renamed_test_file_name, .{}); - file.close(); + file.deinit(); // Rename to self succeeds try tmp_dir.dir.rename(renamed_test_file_name, renamed_test_file_name); // Rename to existing file succeeds - var existing_file = try tmp_dir.dir.createFile("existing_file", .{ .read = true }); + const existing_file = try tmp_dir.dir.createFile("existing_file", .{ .read = true }); existing_file.close(); try tmp_dir.dir.rename(renamed_test_file_name, "existing_file"); try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(renamed_test_file_name, .{})); file = try tmp_dir.dir.openFile("existing_file", .{}); - file.close(); + file.deinit(); } test "Dir.rename directories" { @@ -407,7 +407,7 @@ test "Dir.rename directories" { // Put a file in the directory var file = try dir.createFile("test_file", .{ .read = true }); - file.close(); + file.deinit(); dir.close(); try tmp_dir.dir.rename("test_dir_renamed", "test_dir_renamed_again"); @@ -416,20 +416,20 @@ test "Dir.rename directories" { try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir_renamed", .{})); dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{}); file = try dir.openFile("test_file", .{}); - file.close(); + file.deinit(); dir.close(); // Try to rename to a non-empty directory now var target_dir = try tmp_dir.dir.makeOpenPath("non_empty_target_dir", .{}); file = try target_dir.createFile("filler", .{ .read = true }); - file.close(); + file.deinit(); try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.rename("test_dir_renamed_again", "non_empty_target_dir")); // Ensure the directory was not renamed dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{}); file = try dir.openFile("test_file", .{}); - file.close(); + file.deinit(); dir.close(); } @@ -440,7 +440,7 @@ test "Dir.rename file <-> dir" { var tmp_dir = tmpDir(.{}); defer tmp_dir.cleanup(); - var file = try tmp_dir.dir.createFile("test_file", .{ .read = true }); + const file = try tmp_dir.dir.createFile("test_file", .{ .read = true }); file.close(); try tmp_dir.dir.makeDir("test_dir"); try testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir")); @@ -458,13 +458,13 @@ test "rename" { const test_file_name = "test_file"; const renamed_test_file_name = "test_file_renamed"; var file = try tmp_dir1.dir.createFile(test_file_name, .{ .read = true }); - file.close(); + file.deinit(); try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name); // ensure the file was renamed try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(test_file_name, .{})); file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{}); - file.close(); + file.deinit(); } test "renameAbsolute" { @@ -492,7 +492,7 @@ test "renameAbsolute" { const test_file_name = "test_file"; const renamed_test_file_name = "test_file_renamed"; var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true }); - file.close(); + file.deinit(); try fs.renameAbsolute( try fs.path.join(allocator, &[_][]const u8{ base_path, test_file_name }), try fs.path.join(allocator, &[_][]const u8{ base_path, renamed_test_file_name }), @@ -503,7 +503,7 @@ test "renameAbsolute" { file = try tmp_dir.dir.openFile(renamed_test_file_name, .{}); const stat = try file.stat(); try testing.expect(stat.kind == .File); - file.close(); + file.deinit(); // Renaming directories const test_dir_name = "test_dir"; @@ -516,7 +516,7 @@ test "renameAbsolute" { // ensure the directory was renamed try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir(test_dir_name, .{})); - var dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{}); + const dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{}); dir.close(); } @@ -573,7 +573,7 @@ test "writev, readv" { }, }; - var src_file = try tmp.dir.createFile("test.txt", .{ .read = true }); + const src_file = try tmp.dir.createFile("test.txt", .{ .read = true }); defer src_file.close(); try src_file.writevAll(&write_vecs); @@ -615,7 +615,7 @@ test "pwritev, preadv" { }, }; - var src_file = try tmp.dir.createFile("test.txt", .{ .read = true }); + const src_file = try tmp.dir.createFile("test.txt", .{ .read = true }); defer src_file.close(); try src_file.pwritevAll(&write_vecs, 16); @@ -652,7 +652,7 @@ test "sendfile" { try tmp.dir.makePath("os_test_tmp"); defer tmp.dir.deleteTree("os_test_tmp") catch {}; - var dir = try tmp.dir.openDir("os_test_tmp", .{}); + const dir = try tmp.dir.openDir("os_test_tmp", .{}); defer dir.close(); const line1 = "line1\n"; @@ -668,12 +668,12 @@ test "sendfile" { }, }; - var src_file = try dir.createFile("sendfile1.txt", .{ .read = true }); + const src_file = try dir.createFile("sendfile1.txt", .{ .read = true }); defer src_file.close(); try src_file.writevAll(&vecs); - var dest_file = try dir.createFile("sendfile2.txt", .{ .read = true }); + const dest_file = try dir.createFile("sendfile2.txt", .{ .read = true }); defer dest_file.close(); const header1 = "header1\n"; @@ -717,16 +717,16 @@ test "copyRangeAll" { try tmp.dir.makePath("os_test_tmp"); defer tmp.dir.deleteTree("os_test_tmp") catch {}; - var dir = try tmp.dir.openDir("os_test_tmp", .{}); + const dir = try tmp.dir.openDir("os_test_tmp", .{}); defer dir.close(); - var src_file = try dir.createFile("file1.txt", .{ .read = true }); + const src_file = try dir.createFile("file1.txt", .{ .read = true }); defer src_file.close(); const data = "u6wj+JmdF3qHsFPE BUlH2g4gJCmEz0PP"; try src_file.writeAll(data); - var dest_file = try dir.createFile("file2.txt", .{ .read = true }); + const dest_file = try dir.createFile("file2.txt", .{ .read = true }); defer dest_file.close(); var written_buf: [100]u8 = undefined; @@ -959,7 +959,7 @@ test ". and .. in fs.Dir functions" { try tmp.dir.makeDir("./subdir"); try tmp.dir.access("./subdir", .{}); - var created_subdir = try tmp.dir.openDir("./subdir", .{}); + const created_subdir = try tmp.dir.openDir("./subdir", .{}); created_subdir.close(); const created_file = try tmp.dir.createFile("./subdir/../file", .{}); @@ -997,7 +997,7 @@ test ". and .. in absolute functions" { const subdir_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "./subdir" }); try fs.makeDirAbsolute(subdir_path); try fs.accessAbsolute(subdir_path, .{}); - var created_subdir = try fs.openDirAbsolute(subdir_path, .{}); + const created_subdir = try fs.openDirAbsolute(subdir_path, .{}); created_subdir.close(); const created_file_path = try fs.path.join(allocator, &[_][]const u8{ subdir_path, "../file" }); @@ -1058,7 +1058,7 @@ test "chown" { try tmp.dir.makeDir("test_dir"); - var dir = try tmp.dir.openDir("test_dir", .{ .iterate = true }); + const dir = try tmp.dir.openDir("test_dir", .{ .iterate = true }); defer dir.close(); try dir.chown(null, null); } diff --git a/lib/std/io/test.zig b/lib/std/io/test.zig index dfff7b589623..301564224ef9 100644 --- a/lib/std/io/test.zig +++ b/lib/std/io/test.zig @@ -24,7 +24,7 @@ test "write a file, read it, then delete it" { random.bytes(data[0..]); const tmp_file_name = "temp_test_file.txt"; { - var file = try tmp.dir.createFile(tmp_file_name, .{}); + const file = try tmp.dir.createFile(tmp_file_name, .{}); defer file.close(); var buf_stream = io.bufferedWriter(file.writer()); @@ -41,7 +41,7 @@ test "write a file, read it, then delete it" { } { - var file = try tmp.dir.openFile(tmp_file_name, .{}); + const file = try tmp.dir.openFile(tmp_file_name, .{}); defer file.close(); const file_size = try file.getEndPos(); @@ -66,7 +66,7 @@ test "BitStreams with File Stream" { const tmp_file_name = "temp_test_file.txt"; { - var file = try tmp.dir.createFile(tmp_file_name, .{}); + const file = try tmp.dir.createFile(tmp_file_name, .{}); defer file.close(); var bit_stream = io.bitWriter(native_endian, file.writer()); @@ -80,7 +80,7 @@ test "BitStreams with File Stream" { try bit_stream.flushBits(); } { - var file = try tmp.dir.openFile(tmp_file_name, .{}); + const file = try tmp.dir.openFile(tmp_file_name, .{}); defer file.close(); var bit_stream = io.bitReader(native_endian, file.reader()); @@ -110,7 +110,7 @@ test "File seek ops" { defer tmp.cleanup(); const tmp_file_name = "temp_test_file.txt"; - var file = try tmp.dir.createFile(tmp_file_name, .{}); + const file = try tmp.dir.createFile(tmp_file_name, .{}); defer { file.close(); tmp.dir.deleteFile(tmp_file_name) catch {}; @@ -137,7 +137,7 @@ test "setEndPos" { defer tmp.cleanup(); const tmp_file_name = "temp_test_file.txt"; - var file = try tmp.dir.createFile(tmp_file_name, .{}); + const file = try tmp.dir.createFile(tmp_file_name, .{}); defer { file.close(); tmp.dir.deleteFile(tmp_file_name) catch {}; @@ -163,7 +163,7 @@ test "updateTimes" { defer tmp.cleanup(); const tmp_file_name = "just_a_temporary_file.txt"; - var file = try tmp.dir.createFile(tmp_file_name, .{ .read = true }); + const file = try tmp.dir.createFile(tmp_file_name, .{ .read = true }); defer { file.close(); tmp.dir.deleteFile(tmp_file_name) catch {}; diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index d3c8d13bd123..33226cd6cd5f 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -773,7 +773,7 @@ test "dup & dup2" { defer tmp.cleanup(); { - var file = try tmp.dir.createFile("os_dup_test", .{}); + const file = try tmp.dir.createFile("os_dup_test", .{}); defer file.close(); var duped = std.fs.File{ .handle = try std.os.dup(file.handle) }; @@ -788,7 +788,7 @@ test "dup & dup2" { try dup2ed.writeAll("dup2"); } - var file = try tmp.dir.openFile("os_dup_test", .{}); + const file = try tmp.dir.openFile("os_dup_test", .{}); defer file.close(); var buf: [7]u8 = undefined; @@ -801,7 +801,7 @@ test "writev longer than IOV_MAX" { var tmp = tmpDir(.{}); defer tmp.cleanup(); - var file = try tmp.dir.createFile("pwritev", .{}); + const file = try tmp.dir.createFile("pwritev", .{}); defer file.close(); const iovecs = [_]os.iovec_const{.{ .iov_base = "a", .iov_len = 1 }} ** (os.IOV_MAX + 1); diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig index a8d9161981fd..bb22db2a5043 100644 --- a/lib/std/pdb.zig +++ b/lib/std/pdb.zig @@ -522,6 +522,7 @@ pub const Pdb = struct { self.in_file.close(); self.allocator.free(self.modules); self.allocator.free(self.sect_contribs); + self.* = undefined; } pub fn parseDbiStream(self: *Pdb) !void { diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 3e2518cb5281..94b6353229ee 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -859,7 +859,7 @@ pub const NativeTargetInfo = struct { const rpath_list = mem.spanZ(std.meta.assumeSentinel(strtab[rpoff_usize..].ptr, 0)); var it = mem.tokenize(u8, rpath_list, ":"); while (it.next()) |rpath| { - var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) { + const dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) { error.NameTooLong => unreachable, error.InvalidUtf8 => unreachable, error.BadPathName => unreachable, diff --git a/lib/std/zig/system/linux.zig b/lib/std/zig/system/linux.zig index 0594ff1e2f82..7899fc48407a 100644 --- a/lib/std/zig/system/linux.zig +++ b/lib/std/zig/system/linux.zig @@ -446,7 +446,7 @@ fn CpuinfoParser(comptime impl: anytype) type { } pub fn detectNativeCpuAndFeatures() ?Target.Cpu { - var f = fs.openFileAbsolute("/proc/cpuinfo", .{ .intended_io_mode = .blocking }) catch |err| switch (err) { + const f = fs.openFileAbsolute("/proc/cpuinfo", .{ .intended_io_mode = .blocking }) catch |err| switch (err) { else => return null, }; defer f.close();