aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-06-01 07:41:24 +0100
committermlugg <mlugg@mlugg.co.uk>2025-06-01 12:10:57 +0100
commitc1a5caa4545264b476951e844818f2abe103f41c (patch)
treefcacbb6cb46d76b9bb31a20a7c2149cb3802b7d7 /lib/std/debug.zig
parent6daa37ded905431f3a25508a42590031b0905ab9 (diff)
downloadzig-c1a5caa4545264b476951e844818f2abe103f41c.tar.gz
zig-c1a5caa4545264b476951e844818f2abe103f41c.zip
compiler: combine `@intCast` safety checks
`castTruncatedData` was a poorly worded error (all shrinking casts "truncate bits", it's just that we assume those bits to be zext/sext of the other bits!), and `negativeToUnsigned` was a pointless distinction which forced the compiler to emit worse code (since two separate safety checks were required for casting e.g. 'i32' to 'u16') and wasn't even implemented correctly. This commit combines those safety panics into one function, `integerOutOfBounds`. The name maybe isn't perfect, but that's not hugely important; what matters is the new default message, which is clearer than the old ones: "integer does not fit in destination type".
Diffstat (limited to 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 527676566c..450c627e15 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -78,13 +78,9 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type {
@branchHint(.cold);
call("invalid error code", @returnAddress());
}
- pub fn castTruncatedData() noreturn {
+ pub fn integerOutOfBounds() noreturn {
@branchHint(.cold);
- call("integer cast truncated bits", @returnAddress());
- }
- pub fn negativeToUnsigned() noreturn {
- @branchHint(.cold);
- call("attempt to cast negative value to unsigned integer", @returnAddress());
+ call("integer does not fit in destination type", @returnAddress());
}
pub fn integerOverflow() noreturn {
@branchHint(.cold);
@@ -128,6 +124,10 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type {
}
/// Delete after next zig1.wasm update
pub const memcpyLenMismatch = copyLenMismatch;
+ /// Delete after next zig1.wasm update
+ pub const castTruncatedData = integerOutOfBounds;
+ /// Delete after next zig1.wasm update
+ pub const negativeToUnsigned = integerOutOfBounds;
pub fn copyLenMismatch() noreturn {
@branchHint(.cold);
call("source and destination arguments have non-equal lengths", @returnAddress());