diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 6880940c03..026bf21c5c 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -2183,7 +2183,7 @@ pub const Walker = struct { while (true) { if (self.stack.items.len == 0) return null; // `top` becomes invalid after appending to `self.stack`. - const top = &self.stack.items[self.stack.items.len - 1]; + var top = &self.stack.items[self.stack.items.len - 1]; const dirname_len = top.dirname_len; if (try top.dir_it.next()) |base| { self.name_buffer.shrink(dirname_len); @@ -2200,6 +2200,7 @@ pub const Walker = struct { .dir_it = new_dir.iterate(), .dirname_len = self.name_buffer.items.len, }); + top = &self.stack.items[self.stack.items.len - 1]; } } return Entry{