mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
`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".
144 lines
2.6 KiB
Zig
144 lines
2.6 KiB
Zig
//! This namespace can be used with `pub const panic = std.debug.no_panic;` in the root file.
|
|
//! It emits as little code as possible, for testing purposes.
|
|
//!
|
|
//! For a functional alternative, see `std.debug.FullPanic`.
|
|
|
|
const std = @import("../std.zig");
|
|
|
|
pub fn call(_: []const u8, _: ?usize) noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn sentinelMismatch(_: anytype, _: anytype) noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn unwrapError(_: anyerror) noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn outOfBounds(_: usize, _: usize) noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn startGreaterThanEnd(_: usize, _: usize) noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn inactiveUnionField(_: anytype, _: anytype) noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn sliceCastLenRemainder(_: usize) noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn reachedUnreachable() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn unwrapNull() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn castToNull() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn incorrectAlignment() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn invalidErrorCode() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn integerOutOfBounds() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn integerOverflow() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn shlOverflow() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn shrOverflow() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn divideByZero() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn exactDivisionRemainder() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn integerPartOutOfBounds() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn corruptSwitch() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn shiftRhsTooBig() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn invalidEnumValue() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn forLenMismatch() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
/// 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);
|
|
@trap();
|
|
}
|
|
|
|
pub fn memcpyAlias() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|
|
|
|
pub fn noreturnReturned() noreturn {
|
|
@branchHint(.cold);
|
|
@trap();
|
|
}
|