mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
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:
committed by
Matthew Lugg
parent
9e949f95c1
commit
6e35138901
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1187,7 +1187,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime
|
||||
return error.MemoryLeakDetected;
|
||||
}
|
||||
},
|
||||
else => return err,
|
||||
else => |e| return e,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user