Skip to content

Commit b2030cb

Browse files
authored
std.meta.eql: use == directly when comparing packed structs (#21982)
1 parent c894ac0 commit b2030cb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/std/meta.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,13 +737,15 @@ test TagPayload {
737737
try testing.expect(MovedEvent == @TypeOf(e.Moved));
738738
}
739739

740-
/// Compares two of any type for equality. Containers are compared on a field-by-field basis,
741-
/// where possible. Pointers are not followed.
740+
/// Compares two of any type for equality. Containers that do not support comparison
741+
/// on their own are compared on a field-by-field basis. Pointers are not followed.
742742
pub fn eql(a: anytype, b: @TypeOf(a)) bool {
743743
const T = @TypeOf(a);
744744

745745
switch (@typeInfo(T)) {
746746
.@"struct" => |info| {
747+
if (info.layout == .@"packed") return a == b;
748+
747749
inline for (info.fields) |field_info| {
748750
if (!eql(@field(a, field_info.name), @field(b, field_info.name))) return false;
749751
}

0 commit comments

Comments
 (0)