diff --git a/lib/std/math/float.zig b/lib/std/math/float.zig index a8de2dd720..fdebdf16a1 100644 --- a/lib/std/math/float.zig +++ b/lib/std/math/float.zig @@ -138,11 +138,11 @@ test "math.inf" { const inf_u64: u64 = 0x7FF0000000000000; const inf_u80: u80 = 0x7FFF8000000000000000; const inf_u128: u128 = 0x7FFF0000000000000000000000000000; - try expectEqual(inf_u16, @bitCast(inf(f16))); - try expectEqual(inf_u32, @bitCast(inf(f32))); - try expectEqual(inf_u64, @bitCast(inf(f64))); - try expectEqual(inf_u80, @bitCast(inf(f80))); - try expectEqual(inf_u128, @bitCast(inf(f128))); + try expectEqual(inf_u16, @as(u16, @bitCast(inf(f16)))); + try expectEqual(inf_u32, @as(u32, @bitCast(inf(f32)))); + try expectEqual(inf_u64, @as(u64, @bitCast(inf(f64)))); + try expectEqual(inf_u80, @as(u80, @bitCast(inf(f80)))); + try expectEqual(inf_u128, @as(u128, @bitCast(inf(f128)))); } test "math.nan" { @@ -151,11 +151,11 @@ test "math.nan" { const qnan_u64: u64 = 0x7FF8000000000000; const qnan_u80: u80 = 0x7FFFC000000000000000; const qnan_u128: u128 = 0x7FFF8000000000000000000000000000; - try expectEqual(qnan_u16, @bitCast(nan(f16))); - try expectEqual(qnan_u32, @bitCast(nan(f32))); - try expectEqual(qnan_u64, @bitCast(nan(f64))); - try expectEqual(qnan_u80, @bitCast(nan(f80))); - try expectEqual(qnan_u128, @bitCast(nan(f128))); + try expectEqual(qnan_u16, @as(u16, @bitCast(nan(f16)))); + try expectEqual(qnan_u32, @as(u32, @bitCast(nan(f32)))); + try expectEqual(qnan_u64, @as(u64, @bitCast(nan(f64)))); + try expectEqual(qnan_u80, @as(u80, @bitCast(nan(f80)))); + try expectEqual(qnan_u128, @as(u128, @bitCast(nan(f128)))); } test "math.snan" { @@ -167,9 +167,9 @@ test "math.snan" { const snan_u64: u64 = 0x7FF4000000000000; const snan_u80: u80 = 0x7FFFA000000000000000; const snan_u128: u128 = 0x7FFF4000000000000000000000000000; - try expectEqual(snan_u16, @bitCast(snan(f16))); - try expectEqual(snan_u32, @bitCast(snan(f32))); - try expectEqual(snan_u64, @bitCast(snan(f64))); - try expectEqual(snan_u80, @bitCast(snan(f80))); - try expectEqual(snan_u128, @bitCast(snan(f128))); + try expectEqual(snan_u16, @as(u16, @bitCast(snan(f16)))); + try expectEqual(snan_u32, @as(u32, @bitCast(snan(f32)))); + try expectEqual(snan_u64, @as(u64, @bitCast(snan(f64)))); + try expectEqual(snan_u80, @as(u80, @bitCast(snan(f80)))); + try expectEqual(snan_u128, @as(u128, @bitCast(snan(f128)))); } diff --git a/lib/std/mem.zig b/lib/std/mem.zig index 8e325e0b8e..1e9e9652a8 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -3262,7 +3262,7 @@ test "indexOfMax" { /// Finds the indices of the smallest and largest number in a slice. O(n). /// Returns an anonymous struct with the fields `index_min` and `index_max`. /// `slice` must not be empty. -pub fn indexOfMinMax(comptime T: type, slice: []const T) struct { index_min: usize, index_max: usize } { +pub fn indexOfMinMax(comptime T: type, slice: []const T) IndexOfMinMaxResult { assert(slice.len > 0); var minVal = slice[0]; var maxVal = slice[0]; @@ -3281,10 +3281,12 @@ pub fn indexOfMinMax(comptime T: type, slice: []const T) struct { index_min: usi return .{ .index_min = minIdx, .index_max = maxIdx }; } +pub const IndexOfMinMaxResult = struct { index_min: usize, index_max: usize }; + test "indexOfMinMax" { - try testing.expectEqual(indexOfMinMax(u8, "abcdefg"), .{ .index_min = 0, .index_max = 6 }); - try testing.expectEqual(indexOfMinMax(u8, "gabcdef"), .{ .index_min = 1, .index_max = 0 }); - try testing.expectEqual(indexOfMinMax(u8, "a"), .{ .index_min = 0, .index_max = 0 }); + try testing.expectEqual(indexOfMinMax(u8, "abcdefg"), IndexOfMinMaxResult{ .index_min = 0, .index_max = 6 }); + try testing.expectEqual(indexOfMinMax(u8, "gabcdef"), IndexOfMinMaxResult{ .index_min = 1, .index_max = 0 }); + try testing.expectEqual(indexOfMinMax(u8, "a"), IndexOfMinMaxResult{ .index_min = 0, .index_max = 0 }); } pub fn swap(comptime T: type, a: *T, b: *T) void { diff --git a/lib/std/multi_array_list.zig b/lib/std/multi_array_list.zig index 5ff5144028..7187e25f0f 100644 --- a/lib/std/multi_array_list.zig +++ b/lib/std/multi_array_list.zig @@ -842,24 +842,24 @@ test "union" { &.{ .a, .b, .b, .a, .a, .a, .a, .a, .a }, list.items(.tags), ); - try testing.expectEqual(list.get(0), .{ .a = 1 }); - try testing.expectEqual(list.get(1), .{ .b = "zigzag" }); - try testing.expectEqual(list.get(2), .{ .b = "foobar" }); - try testing.expectEqual(list.get(3), .{ .a = 4 }); - try testing.expectEqual(list.get(4), .{ .a = 5 }); - try testing.expectEqual(list.get(5), .{ .a = 6 }); - try testing.expectEqual(list.get(6), .{ .a = 7 }); - try testing.expectEqual(list.get(7), .{ .a = 8 }); - try testing.expectEqual(list.get(8), .{ .a = 9 }); + try testing.expectEqual(list.get(0), Foo{ .a = 1 }); + try testing.expectEqual(list.get(1), Foo{ .b = "zigzag" }); + try testing.expectEqual(list.get(2), Foo{ .b = "foobar" }); + try testing.expectEqual(list.get(3), Foo{ .a = 4 }); + try testing.expectEqual(list.get(4), Foo{ .a = 5 }); + try testing.expectEqual(list.get(5), Foo{ .a = 6 }); + try testing.expectEqual(list.get(6), Foo{ .a = 7 }); + try testing.expectEqual(list.get(7), Foo{ .a = 8 }); + try testing.expectEqual(list.get(8), Foo{ .a = 9 }); list.shrinkAndFree(ally, 3); try testing.expectEqual(@as(usize, 3), list.items(.tags).len); try testing.expectEqualSlices(meta.Tag(Foo), list.items(.tags), &.{ .a, .b, .b }); - try testing.expectEqual(list.get(0), .{ .a = 1 }); - try testing.expectEqual(list.get(1), .{ .b = "zigzag" }); - try testing.expectEqual(list.get(2), .{ .b = "foobar" }); + try testing.expectEqual(list.get(0), Foo{ .a = 1 }); + try testing.expectEqual(list.get(1), Foo{ .b = "zigzag" }); + try testing.expectEqual(list.get(2), Foo{ .b = "foobar" }); } test "sorting a span" { diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index f0a1f60235..10f3e80e21 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -1156,7 +1156,7 @@ test "cast function with an opaque parameter" { .func = @ptrCast(&Foo.funcImpl), }; c.func(c.ctx); - try std.testing.expectEqual(foo, .{ .x = 101, .y = 201 }); + try std.testing.expectEqual(foo, Foo{ .x = 101, .y = 201 }); } test "implicit ptr to *anyopaque" { diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig index f4aceaa82d..c684bafcb3 100644 --- a/test/behavior/packed-struct.zig +++ b/test/behavior/packed-struct.zig @@ -1033,7 +1033,7 @@ test "modify nested packed struct aligned field" { var opts = Options{}; opts.pretty_print.indent += 1; - try std.testing.expectEqual(@as(u17, 0b00000000100100000), @bitCast(opts)); + try std.testing.expectEqual(@as(u17, 0b00000000100100000), @as(u17, @bitCast(opts))); try std.testing.expect(!opts.foo); try std.testing.expect(!opts.bar); try std.testing.expect(!opts.pretty_print.enabled); diff --git a/test/behavior/type.zig b/test/behavior/type.zig index 64c4c85669..49ab54f48f 100644 --- a/test/behavior/type.zig +++ b/test/behavior/type.zig @@ -438,9 +438,9 @@ test "Type.Union" { }, }); var tagged = Tagged{ .signed = -1 }; - try testing.expectEqual(Tag.signed, tagged); + try testing.expectEqual(Tag.signed, @as(Tag, tagged)); tagged = .{ .unsigned = 1 }; - try testing.expectEqual(Tag.unsigned, tagged); + try testing.expectEqual(Tag.unsigned, @as(Tag, tagged)); } test "Type.Union from Type.Enum" { diff --git a/test/c_abi/main.zig b/test/c_abi/main.zig index d845f89eee..919d2c9083 100644 --- a/test/c_abi/main.zig +++ b/test/c_abi/main.zig @@ -946,7 +946,7 @@ test "DC: C returns to Zig" { if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; - try expectEqual(c_ret_DC(), .{ .v1 = -0.25, .v2 = 15 }); + try expectEqual(c_ret_DC(), DC{ .v1 = -0.25, .v2 = 15 }); } pub extern fn c_assert_DC(lv: DC) c_int; @@ -998,7 +998,7 @@ test "CFF: C returns to Zig" { if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; - try expectEqual(c_ret_CFF(), .{ .v1 = 39, .v2 = 0.875, .v3 = 1.0 }); + try expectEqual(c_ret_CFF(), CFF{ .v1 = 39, .v2 = 0.875, .v3 = 1.0 }); } pub extern fn c_assert_CFF(lv: CFF) c_int; pub extern fn c_assert_ret_CFF() c_int; @@ -1045,7 +1045,7 @@ test "PD: C returns to Zig" { if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; - try expectEqual(c_ret_PD(), .{ .v1 = null, .v2 = 0.5 }); + try expectEqual(c_ret_PD(), PD{ .v1 = null, .v2 = 0.5 }); } pub extern fn c_assert_PD(lv: PD) c_int; pub extern fn c_assert_ret_PD() c_int;