all: prefer else => |e| return e, over else => return err,

When switching on an error, using the captured value instead of the original
one is always preferable since its error set has been narrowed to only
contain errors which haven't already been handled by other switch prongs.

The subsequent commits will disallow this form as an unreachable `else` prong.
This commit is contained in:
Justus Klausecker 2026-01-09 04:43:31 +01:00 committed by Matthew Lugg
parent 9e949f95c1
commit 6e35138901
No known key found for this signature in database
GPG key ID: 3F5B7DCCBF4AF02E
2 changed files with 3 additions and 3 deletions

View file

@ -114,7 +114,7 @@ fn writeHeader(
if (typeflag == .symbolic_link)
header.setLinkname(link_name) catch |err| switch (err) {
error.NameTooLong => try w.writeExtendedHeader(.gnu_long_link, &.{link_name}),
else => return err,
else => |e| return e,
};
try header.write(w.underlying_writer);
}
@ -131,7 +131,7 @@ fn setPath(w: *Writer, header: *Header, sub_path: []const u8) Error!void {
&.{ w.prefix, "/", sub_path };
try w.writeExtendedHeader(.gnu_long_name, buffers);
},
else => return err,
else => |e| return e,
};
}

View file

@ -1187,7 +1187,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime
return error.MemoryLeakDetected;
}
},
else => return err,
else => |e| return e,
}
}
}