commit 213c4fc25f214a0d8763bd7976db9ae3eec0f232 (tree)
parent d764716cb5cdcf3dec07d66ce87be915327f564e
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date: Tue, 28 Apr 2026 19:31:12 +0100
lib,test: remove uses of i0
In preparation for its removal, as accepted in
https://github.com/ziglang/zig/issues/1593.
Diffstat:
22 files changed, 29 insertions(+), 128 deletions(-)
diff --git a/lib/std/Io/Reader.zig b/lib/std/Io/Reader.zig
@@ -2097,7 +2097,6 @@ test "deserialize signed LEB128" {
try testing.expectEqual(std.math.minInt(i128), testLeb128(i128, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7E"));
// Specific cases
- try testing.expectEqual(0, testLeb128(i0, "\x00"));
try testing.expectEqual(0, testLeb128(i2, "\x00"));
try testing.expectEqual(0, testLeb128(i8, "\x00"));
@@ -2134,8 +2133,6 @@ test "deserialize signed LEB128" {
try testing.expectError(error.EndOfStream, testLeb128(i128, &end_of_stream));
// Overflow
- try testing.expectError(error.Overflow, testLeb128(i0, "\x01"));
- try testing.expectError(error.Overflow, testLeb128(i0, "\x7F"));
try testing.expectError(error.Overflow, testLeb128(i8, "\x80\x01"));
try testing.expectError(error.Overflow, testLeb128(i8, "\xFF\x7E"));
try testing.expectError(error.Overflow, testLeb128(i8, "\x80\x80\x40"));
@@ -2145,7 +2142,6 @@ test "deserialize signed LEB128" {
try testing.expectError(error.Overflow, testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01"));
try testing.expectError(error.Overflow, testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
- try testing.expectError(error.Overflow, testLeb128(i0, &overflow));
try testing.expectError(error.Overflow, testLeb128(i7, &overflow));
try testing.expectError(error.Overflow, testLeb128(i8, &overflow));
try testing.expectError(error.Overflow, testLeb128(i14, &overflow));
@@ -2159,7 +2155,6 @@ test "deserialize signed LEB128" {
try testing.expectEqual(0x80, testLeb128(i64, "\x80\x81\x00"));
try testing.expectEqual(0x80, testLeb128(i64, "\x80\x81\x80\x00"));
- try testing.expectEqual(0, testLeb128(i0, &long_zero));
try testing.expectEqual(0, testLeb128(i7, &long_zero));
try testing.expectEqual(0, testLeb128(i8, &long_zero));
try testing.expectEqual(0, testLeb128(i14, &long_zero));
diff --git a/lib/std/Io/Writer.zig b/lib/std/Io/Writer.zig
@@ -1924,7 +1924,6 @@ test "serialize signed LEB128" {
try testLeb128Encoding(i128, std.math.minInt(i128), "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7E");
// Specific cases
- try testLeb128Encoding(i0, 0, "\x00");
try testLeb128Encoding(i8, 0, "\x00");
try testLeb128Encoding(i2, -1, "\x7F");
diff --git a/lib/std/json/static_test.zig b/lib/std/json/static_test.zig
@@ -22,7 +22,6 @@ const Primitives = struct {
f32: f32,
f64: f64,
u0: u0,
- i0: i0,
u1: u1,
i1: i1,
u8: u8,
@@ -35,7 +34,6 @@ const primitives_0 = Primitives{
.f32 = 0,
.f64 = 0,
.u0 = 0,
- .i0 = 0,
.u1 = 0,
.i1 = 0,
.u8 = 0,
@@ -48,7 +46,6 @@ const primitives_0_doc_0 =
\\ "f32": 0,
\\ "f64": 0,
\\ "u0": 0,
- \\ "i0": 0,
\\ "u1": 0,
\\ "i1": 0,
\\ "u8": 0,
@@ -62,7 +59,6 @@ const primitives_0_doc_1 = // looks like a float.
\\ "f32": 0.0,
\\ "f64": 0.0,
\\ "u0": 0.0,
- \\ "i0": 0.0,
\\ "u1": 0.0,
\\ "i1": 0.0,
\\ "u8": 0.0,
@@ -76,7 +72,6 @@ const primitives_1 = Primitives{
.f32 = 1073741824,
.f64 = 1152921504606846976,
.u0 = 0,
- .i0 = 0,
.u1 = 1,
.i1 = -1,
.u8 = 255,
@@ -89,7 +84,6 @@ const primitives_1_doc_0 =
\\ "f32": 1073741824,
\\ "f64": 1152921504606846976,
\\ "u0": 0,
- \\ "i0": 0,
\\ "u1": 1,
\\ "i1": -1,
\\ "u8": 255,
@@ -103,7 +97,6 @@ const primitives_1_doc_1 = // float rounding.
\\ "f32": 1073741825,
\\ "f64": 1152921504606846977,
\\ "u0": 0,
- \\ "i0": 0,
\\ "u1": 1,
\\ "i1": -1,
\\ "u8": 255,
diff --git a/lib/std/math.zig b/lib/std/math.zig
@@ -1141,13 +1141,11 @@ test isPowerOfTwo {
pub fn ByteAlignedInt(comptime T: type) type {
const info = @typeInfo(T).int;
const bits = (info.bits + 7) / 8 * 8;
- const extended_type = std.meta.Int(info.signedness, bits);
- return extended_type;
+ return @Int(info.signedness, bits);
}
test ByteAlignedInt {
try testing.expect(ByteAlignedInt(u0) == u0);
- try testing.expect(ByteAlignedInt(i0) == i0);
try testing.expect(ByteAlignedInt(u3) == u8);
try testing.expect(ByteAlignedInt(u8) == u8);
try testing.expect(ByteAlignedInt(i111) == i112);
@@ -1218,7 +1216,7 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo(
comptime assert(@typeInfo(T) == .int);
comptime assert(@typeInfo(T).int.signedness == .unsigned);
assert(value != 0);
- const PromotedType = std.meta.Int(@typeInfo(T).int.signedness, @typeInfo(T).int.bits + 1);
+ const PromotedType = @Int(@typeInfo(T).int.signedness, @typeInfo(T).int.bits + 1);
const ShiftType = std.math.Log2Int(PromotedType);
return @as(PromotedType, 1) << @as(ShiftType, @intCast(@typeInfo(T).int.bits - @clz(value - 1)));
}
@@ -1230,7 +1228,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
comptime assert(@typeInfo(T) == .int);
const info = @typeInfo(T).int;
comptime assert(info.signedness == .unsigned);
- const PromotedType = std.meta.Int(info.signedness, info.bits + 1);
+ const PromotedType = @Int(info.signedness, info.bits + 1);
const overflowBit = @as(PromotedType, 1) << info.bits;
const x = ceilPowerOfTwoPromote(T, value);
if (overflowBit & x != 0) {
@@ -1442,19 +1440,17 @@ test lerp {
/// Returns the maximum value of integer type T.
pub fn maxInt(comptime T: type) comptime_int {
- const info = @typeInfo(T);
- const bit_count = info.int.bits;
- if (bit_count == 0) return 0;
- return (1 << (bit_count - @intFromBool(info.int.signedness == .signed))) - 1;
+ const info = @typeInfo(T).int;
+ return (1 << (info.bits - @intFromBool(info.signedness == .signed))) - 1;
}
/// Returns the minimum value of integer type T.
pub fn minInt(comptime T: type) comptime_int {
- const info = @typeInfo(T);
- const bit_count = info.int.bits;
- if (info.int.signedness == .unsigned) return 0;
- if (bit_count == 0) return 0;
- return -(1 << (bit_count - 1));
+ const info = @typeInfo(T).int;
+ return switch (info.signedness) {
+ .unsigned => 0,
+ .signed => -(1 << (info.bits - 1)),
+ };
}
test maxInt {
@@ -1466,7 +1462,6 @@ test maxInt {
try testing.expect(maxInt(u64) == 18446744073709551615);
try testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
- try testing.expect(maxInt(i0) == 0);
try testing.expect(maxInt(i1) == 0);
try testing.expect(maxInt(i8) == 127);
try testing.expect(maxInt(i16) == 32767);
@@ -1486,7 +1481,6 @@ test minInt {
try testing.expect(minInt(u64) == 0);
try testing.expect(minInt(u128) == 0);
- try testing.expect(minInt(i0) == 0);
try testing.expect(minInt(i1) == -1);
try testing.expect(minInt(i8) == -128);
try testing.expect(minInt(i16) == -32768);
@@ -1710,8 +1704,8 @@ pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt {
if (@typeInfo(MaskInt) != .int)
@compileError("boolMask requires an integer mask type.");
- if (MaskInt == u0 or MaskInt == i0)
- @compileError("boolMask cannot convert to u0 or i0, they are too small.");
+ if (MaskInt == u0)
+ @compileError("boolMask cannot convert to u0, it is too small.");
// The u1 and i1 cases tend to overflow,
// so we special case them here.
diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig
@@ -602,7 +602,6 @@ test "bitcount/to" {
try testing.expectEqual(0, a.bitCountTwosComp());
try testing.expectEqual(0, try a.toInt(u0));
- try testing.expectEqual(0, try a.toInt(i0));
try a.set(-1);
try testing.expectEqual(1, a.bitCountTwosComp());
@@ -631,7 +630,6 @@ test "fits" {
try a.set(0);
try testing.expect(a.fits(u0));
- try testing.expect(a.fits(i0));
try a.set(255);
try testing.expect(!a.fits(u0));
@@ -711,7 +709,6 @@ test "twos complement limit set" {
try testTwosComplementLimit(u1);
try testTwosComplementLimit(i1);
try testTwosComplementLimit(u0);
- try testTwosComplementLimit(i0);
try testTwosComplementLimit(u65);
try testTwosComplementLimit(i65);
}
diff --git a/lib/std/math/nextafter.zig b/lib/std/math/nextafter.zig
@@ -23,7 +23,7 @@ pub fn nextAfter(comptime T: type, x: T, y: T) T {
fn nextAfterInt(comptime T: type, x: T, y: T) T {
comptime assert(@typeInfo(T) == .int or @typeInfo(T) == .comptime_int);
return if (@typeInfo(T) == .int and @bitSizeOf(T) < 2)
- // Special case for `i0`, `u0`, `i1`, and `u1`.
+ // Special case for `u0`, `i1`, and `u1`.
y
else if (y > x)
x + 1
@@ -102,7 +102,6 @@ fn nextAfterFloat(comptime T: type, x: T, y: T) T {
}
test "int" {
- try expect(nextAfter(i0, 0, 0) == 0);
try expect(nextAfter(u0, 0, 0) == 0);
try expect(nextAfter(i1, 0, 0) == 0);
try expect(nextAfter(i1, 0, -1) == -1);
diff --git a/lib/std/math/powi.zig b/lib/std/math/powi.zig
@@ -15,12 +15,12 @@ const testing = std.testing;
/// - Underflow: Absolute value of result smaller than 1
///
/// Edge case rules ordered by precedence:
-/// - powi(T, x, 0) = 1 unless T is i1, i0, u0
+/// - powi(T, x, 0) = 1 unless T is i1, u0
/// - powi(T, 0, x) = 0 when x > 0
/// - powi(T, 0, x) = Overflow
/// - powi(T, 1, y) = 1
/// - powi(T, -1, y) = -1 for y an odd integer
-/// - powi(T, -1, y) = 1 unless T is i1, i0, u0
+/// - powi(T, -1, y) = 1 unless T is i1, u0
/// - powi(T, -1, y) = Overflow
/// - powi(T, x, y) = Overflow when y >= @bitSizeOf(x)
/// - powi(T, x, y) = Underflow when y < 0
@@ -189,7 +189,6 @@ test "powi.special" {
test "powi.narrow" {
try testing.expectError(error.Overflow, powi(u0, 0, 0));
- try testing.expectError(error.Overflow, powi(i0, 0, 0));
try testing.expectError(error.Overflow, powi(i1, 0, 0));
try testing.expectError(error.Overflow, powi(i1, -1, 0));
try testing.expectError(error.Overflow, powi(i1, 0, -1));
diff --git a/lib/std/math/signbit.zig b/lib/std/math/signbit.zig
@@ -13,7 +13,6 @@ pub fn signbit(x: anytype) bool {
}
test signbit {
- try testInts(i0);
try testInts(u0);
try testInts(i1);
try testInts(u1);
diff --git a/lib/std/mem.zig b/lib/std/mem.zig
@@ -370,7 +370,6 @@ test zeroes {
comptime comptime_field: u8 = 5,
integral_types: struct {
- integer_0: i0,
integer_8: i8,
integer_16: i16,
integer_32: i32,
@@ -405,7 +404,6 @@ test zeroes {
const b = zeroes(ZigStruct);
try testing.expectEqual(@as(u8, 5), b.comptime_field);
- try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
try testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
diff --git a/lib/std/meta.zig b/lib/std/meta.zig
@@ -1067,7 +1067,7 @@ test hasUniqueRepresentation {
try testing.expect(!hasUniqueRepresentation(TestUnion4));
- inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
+ inline for ([_]type{ u8, i16, u32, i64 }) |T| {
try testing.expect(hasUniqueRepresentation(T));
try testing.expect(hasUniqueRepresentation(enum(T) { _ }));
}
diff --git a/test/behavior/atomics.zig b/test/behavior/atomics.zig
@@ -369,7 +369,6 @@ test "atomics with different types" {
try testAtomicsWithType(u24, 2, 1);
try testAtomicsWithType(u0, 0, 0);
- try testAtomicsWithType(i0, 0, 0);
try testAtomicsWithType(enum(u32) { x = 1234, y = 5678 }, .x, .y);
try testAtomicsWithType(enum(u19) { x = 1234, y = 5678 }, .x, .y);
diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig
@@ -3079,8 +3079,6 @@ test "@intFromFloat boundary cases" {
try case(u0, 1.0, .down, 0);
try case(u0, -1.0, .up, 0);
- try case(i0, 1.0, .down, 0);
- try case(i0, -1.0, .up, 0);
try case(u10, 1024.0, .down, 1023);
try case(u10, -1.0, .up, 0);
@@ -3111,7 +3109,6 @@ test "@intFromFloat vector boundary cases" {
try case(i8, .{ -129.0, 128.0 }, .{ -128, 127 });
try case(u0, .{ -1.0, 1.0 }, .{ 0, 0 });
- try case(i0, .{ -1.0, 1.0 }, .{ 0, 0 });
try case(u10, .{ -1.0, 1024.0 }, .{ 0, 1023 });
try case(i10, .{ -513.0, 512.0 }, .{ -512, 511 });
diff --git a/test/behavior/field_parent_ptr.zig b/test/behavior/field_parent_ptr.zig
@@ -1903,7 +1903,7 @@ test "@fieldParentPtr tagged union all zero-bit fields" {
const C = union(enum) {
a: u0,
- b: i0,
+ b: void,
};
{
@@ -1938,20 +1938,20 @@ test "@fieldParentPtr tagged union all zero-bit fields" {
}
{
- const c: C = .{ .b = 0 };
+ const c: C = .{ .b = {} };
const pcf = &c.b;
const pc: *const C = @alignCast(@fieldParentPtr("b", pcf));
try expect(pc == &c);
}
{
- const c: C = .{ .b = 0 };
+ const c: C = .{ .b = {} };
const pcf = &c.b;
var pc: *const C = undefined;
pc = @alignCast(@fieldParentPtr("b", pcf));
try expect(pc == &c);
}
{
- const c: C = .{ .b = 0 };
+ const c: C = .{ .b = {} };
var pcf: @TypeOf(&c.b) = undefined;
pcf = &c.b;
var pc: *const C = undefined;
@@ -1960,7 +1960,7 @@ test "@fieldParentPtr tagged union all zero-bit fields" {
}
{
var c: C = undefined;
- c = .{ .b = 0 };
+ c = .{ .b = {} };
var pcf: @TypeOf(&c.b) = undefined;
pcf = &c.b;
var pc: *C = undefined;
diff --git a/test/behavior/int_comparison_elision.zig b/test/behavior/int_comparison_elision.zig
@@ -7,7 +7,6 @@ test "int comparison elision" {
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
testIntEdges(u0);
- testIntEdges(i0);
testIntEdges(u1);
testIntEdges(i1);
testIntEdges(u4);
diff --git a/test/behavior/math.zig b/test/behavior/math.zig
@@ -401,7 +401,6 @@ test "binary not" {
try expect(not(u64, 0x0123_4567_89AB_CDEF) == 0xFEDC_BA98_7654_3210);
try expect(not(u64, 0xFEDC_BA98_7654_3210) == 0x0123_4567_89AB_CDEF);
- try expect(not(i0, 0) == 0);
try expect(not(i1, 0) == -1);
try expect(not(i1, -1) == 0);
try expect(not(i5, -2) == 1);
diff --git a/test/behavior/switch_loop.zig b/test/behavior/switch_loop.zig
@@ -547,12 +547,12 @@ test "switch loop with packed unions" {
test "switch loop with packed unions with OPV" {
const P = packed union {
a: u0,
- b: i0,
+ b: void,
fn doTheTest(p: @This()) !void {
var looped = false;
s: switch (p) {
- .{ .b = 0 } => |x| {
+ .{ .b = {} } => |x| {
comptime assert(x.a == 0);
if (looped) break :s;
looped = true;
diff --git a/test/behavior/truncate.zig b/test/behavior/truncate.zig
@@ -31,31 +31,6 @@ test "truncate.u0.var" {
try expect(z == 0);
}
-test "truncate i0 to larger integer allowed and has comptime-known result" {
- var x: i0 = 0;
- _ = &x;
- const y: i8 = @truncate(x);
- comptime assert(y == 0);
-}
-
-test "truncate.i0.literal" {
- const z: i0 = @truncate(0);
- try expect(z == 0);
-}
-
-test "truncate.i0.const" {
- const c0: isize = 0;
- const z: i0 = @truncate(c0);
- try expect(z == 0);
-}
-
-test "truncate.i0.var" {
- var d: i8 = 2;
- _ = &d;
- const z: i0 = @truncate(d);
- try expect(z == 0);
-}
-
test "truncate on comptime integer" {
const x: u16 = @truncate(9999);
try expect(x == 9999);
diff --git a/test/cases/compile_errors/leading_zero_in_integer.zig b/test/cases/compile_errors/leading_zero_in_integer.zig
@@ -3,7 +3,6 @@ export fn entry1() void {
_ = T;
}
export fn entry2() void {
- _ = i0;
_ = u0;
var x: i01 = 1;
_ = x;
@@ -18,8 +17,8 @@ export fn entry4() void {
// error
//
// :2:15: error: primitive integer type 'u000123' has leading zero
-// :8:12: error: primitive integer type 'i01' has leading zero
-// :12:9: error: number '000123' has leading zero
-// :12:9: note: use '0o' prefix for octal literals
-// :15:9: error: number '01' has leading zero
-// :15:9: note: use '0o' prefix for octal literals
+// :7:12: error: primitive integer type 'i01' has leading zero
+// :11:9: error: number '000123' has leading zero
+// :11:9: note: use '0o' prefix for octal literals
+// :14:9: error: number '01' has leading zero
+// :14:9: note: use '0o' prefix for octal literals
diff --git a/test/cases/compile_errors/zero_width_nonexhaustive_enum.zig b/test/cases/compile_errors/zero_width_nonexhaustive_enum.zig
@@ -1,9 +1,4 @@
comptime {
- const E = enum(i0) { a, _ };
- _ = @as(E, undefined);
-}
-
-comptime {
const E = enum(u0) { a, _ };
_ = @as(E, undefined);
}
@@ -16,5 +11,4 @@ comptime {
// error
//
// :2:15: error: non-exhaustive enum specifies every value
-// :7:15: error: non-exhaustive enum specifies every value
-// :12:29: error: enum tag value '1' too large for type 'u0'
+// :7:29: error: enum tag value '1' too large for type 'u0'
diff --git a/test/cases/safety/@intFromFloat cannot fit - boundary case - i0 max.zig b/test/cases/safety/@intFromFloat cannot fit - boundary case - i0 max.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
- _ = stack_trace;
- if (std.mem.eql(u8, message, "integer part of floating point value out of bounds")) {
- std.process.exit(0);
- }
- std.process.exit(1);
-}
-var x: f32 = 1.0;
-pub fn main() !void {
- _ = @as(i0, @intFromFloat(x));
- return error.TestFailed;
-}
-// run
-// backend=selfhosted,llvm
-// target=x86_64-linux,aarch64-linux
diff --git a/test/cases/safety/@intFromFloat cannot fit - boundary case - i0 min.zig b/test/cases/safety/@intFromFloat cannot fit - boundary case - i0 min.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
- _ = stack_trace;
- if (std.mem.eql(u8, message, "integer part of floating point value out of bounds")) {
- std.process.exit(0);
- }
- std.process.exit(1);
-}
-var x: f32 = -1.0;
-pub fn main() !void {
- _ = @as(i0, @intFromFloat(x));
- return error.TestFailed;
-}
-// run
-// backend=selfhosted,llvm
-// target=x86_64-linux,aarch64-linux
diff --git a/test/src/Debugger.zig b/test/src/Debugger.zig
@@ -56,7 +56,6 @@ pub fn addTestsForTarget(db: *Debugger, target: *const Target) void {
\\ u24_16777215: u24 = 16777215,
\\ u32_0: u32 = 0,
\\ u32_4294967295: u32 = 4294967295,
- \\ i0_0: i0 = 0,
\\ @"i1_-1": i1 = -1,
\\ i1_0: i1 = 0,
\\ @"i2_-2": i2 = -2,
@@ -139,7 +138,6 @@ pub fn addTestsForTarget(db: *Debugger, target: *const Target) void {
\\ (u24) .u24_16777215 = 16777215
\\ (u32) .u32_0 = 0
\\ (u32) .u32_4294967295 = 4294967295
- \\ (i0) .i0_0 = 0
\\ (i1) .@"i1_-1" = -1
\\ (i1) .i1_0 = 0
\\ (i2) .@"i2_-2" = -2