根据 std.builtin.panic 中的逻辑,此命名空间是 Zig 编译器默认用来生成各种安全检查 panic 的命名空间。
由于 Zig 没有接口,此文件可作为示例模板,供用户实现自定义的替代 panic 处理。
另一种方案参见 std.debug.FullPanic。
stdcallsentinelMismatchunwrapErroroutOfBoundsstartGreaterThanEndinactiveUnionFieldsliceCastLenRemainderreachedUnreachableunwrapNullcastToNullincorrectAlignmentinvalidErrorCodeunexpectedErrorCodeintegerOutOfBoundsintegerOverflowshlOverflowshrOverflowdivideByZeroexactDivisionRemainderintegerPartOutOfBoundscorruptSwitchshiftRhsTooBiginvalidEnumValueforLenMismatchcopyLenMismatchmemcpyAliasnoreturnReturnedloadUninstantiableType
std.debug.simple_panic.call
函数
向 stderr 打印消息但不换行,然后触发陷阱。
显式调用 @panic 会降级为调用此函数。
pub fn call(msg: []const u8, ra: ?usize) noreturn
参数
msg: []const u8
ra: ?usize
std.debug.simple_panic.castToNull
函数
pub fn castToNull() noreturn
std.debug.simple_panic.copyLenMismatch
函数
pub fn copyLenMismatch() noreturn
std.debug.simple_panic.corruptSwitch
函数
pub fn corruptSwitch() noreturn
std.debug.simple_panic.divideByZero
函数
pub fn divideByZero() noreturn
std.debug.simple_panic.exactDivisionRemainder
函数
pub fn exactDivisionRemainder() noreturn
std.debug.simple_panic.forLenMismatch
函数
pub fn forLenMismatch() noreturn
std.debug.simple_panic.inactiveUnionField
函数
pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn
参数
accessed: @TypeOf(active)
std.debug.simple_panic.incorrectAlignment
函数
pub fn incorrectAlignment() noreturn
std.debug.simple_panic.integerOutOfBounds
函数
pub fn integerOutOfBounds() noreturn
std.debug.simple_panic.integerOverflow
函数
pub fn integerOverflow() noreturn
std.debug.simple_panic.integerPartOutOfBounds
函数
pub fn integerPartOutOfBounds() noreturn
std.debug.simple_panic.invalidEnumValue
函数
pub fn invalidEnumValue() noreturn
std.debug.simple_panic.invalidErrorCode
函数
pub fn invalidErrorCode() noreturn
std.debug.simple_panic.loadUninstantiableType
函数
pub fn loadUninstantiableType() noreturn
std.debug.simple_panic.memcpyAlias
函数
pub fn memcpyAlias() noreturn
std.debug.simple_panic.noreturnReturned
函数
pub fn noreturnReturned() noreturn
std.debug.simple_panic.outOfBounds
函数
pub fn outOfBounds(index: usize, len: usize) noreturn
参数
index: usize
len: usize
std.debug.simple_panic.reachedUnreachable
函数
pub fn reachedUnreachable() noreturn
std.debug.simple_panic.sentinelMismatch
函数
pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn
参数
found: @TypeOf(expected)
std.debug.simple_panic.shiftRhsTooBig
函数
pub fn shiftRhsTooBig() noreturn
std.debug.simple_panic.shlOverflow
函数
pub fn shlOverflow() noreturn
std.debug.simple_panic.shrOverflow
函数
pub fn shrOverflow() noreturn
std.debug.simple_panic.sliceCastLenRemainder
函数
pub fn sliceCastLenRemainder(src_len: usize) noreturn
参数
src_len: usize
std.debug.simple_panic.startGreaterThanEnd
函数
pub fn startGreaterThanEnd(start: usize, end: usize) noreturn
参数
start: usize
end: usize
std.debug.simple_panic.std
别名
别名目标 std
std.debug.simple_panic.unexpectedErrorCode
函数
pub fn unexpectedErrorCode(err: anyerror) noreturn
参数
err: anyerror
std.debug.simple_panic.unwrapError
函数
pub fn unwrapError(err: anyerror) noreturn
参数
err: anyerror
std.debug.simple_panic.unwrapNull
函数
pub fn unwrapNull() noreturn
源码
std/debug/simple_panic.zig
//! 根据 `std.builtin.panic` 中的逻辑,此命名空间是 Zig 编译器默认用来生成各种安全检查 panic 的命名空间。
//!
//! 由于 Zig 没有接口,此文件可作为示例模板,供用户实现自定义的替代 panic 处理。
//!
//! 另一种方案参见 `std.debug.FullPanic`。
//!
//!
const std = @import("../std.zig");
/// 向 stderr 打印消息但不换行,然后触发陷阱。
///
/// 显式调用 `@panic` 会降级为调用此函数。
pub fn call(msg: []const u8, ra: ?usize) noreturn {
@branchHint(.cold);
_ = ra;
const stderr_writer = &std.debug.lockStderr(&.{}).file_writer.interface;
stderr_writer.writeAll(msg) catch {};
@trap();
}
pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn {
@branchHint(.cold);
_ = found;
call("sentinel mismatch", null);
}
pub fn unwrapError(err: anyerror) noreturn {
@branchHint(.cold);
_ = &err;
call("attempt to unwrap error", null);
}
pub fn outOfBounds(index: usize, len: usize) noreturn {
@branchHint(.cold);
_ = index;
_ = len;
call("index out of bounds", null);
}
pub fn startGreaterThanEnd(start: usize, end: usize) noreturn {
@branchHint(.cold);
_ = start;
_ = end;
call("start index is larger than end index", null);
}
pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn {
@branchHint(.cold);
_ = accessed;
call("access of inactive union field", null);
}
pub fn sliceCastLenRemainder(src_len: usize) noreturn {
@branchHint(.cold);
_ = src_len;
call("slice length does not divide exactly into destination elements", null);
}
pub fn reachedUnreachable() noreturn {
@branchHint(.cold);
call("reached unreachable code", null);
}
pub fn unwrapNull() noreturn {
@branchHint(.cold);
call("attempt to use null value", null);
}
pub fn castToNull() noreturn {
@branchHint(.cold);
call("cast causes pointer to be null", null);
}
pub fn incorrectAlignment() noreturn {
@branchHint(.cold);
call("incorrect alignment", null);
}
pub fn invalidErrorCode() noreturn {
@branchHint(.cold);
call("invalid error code", null);
}
pub fn unexpectedErrorCode(err: anyerror) noreturn {
@branchHint(.cold);
_ = err;
call("unexpected error code", null);
}
pub fn integerOutOfBounds() noreturn {
@branchHint(.cold);
call("integer does not fit in destination type", null);
}
pub fn integerOverflow() noreturn {
@branchHint(.cold);
call("integer overflow", null);
}
pub fn shlOverflow() noreturn {
@branchHint(.cold);
call("left shift overflowed bits", null);
}
pub fn shrOverflow() noreturn {
@branchHint(.cold);
call("right shift overflowed bits", null);
}
pub fn divideByZero() noreturn {
@branchHint(.cold);
call("division by zero", null);
}
pub fn exactDivisionRemainder() noreturn {
@branchHint(.cold);
call("exact division produced remainder", null);
}
pub fn integerPartOutOfBounds() noreturn {
@branchHint(.cold);
call("integer part of floating point value out of bounds", null);
}
pub fn corruptSwitch() noreturn {
@branchHint(.cold);
call("switch on corrupt value", null);
}
pub fn shiftRhsTooBig() noreturn {
@branchHint(.cold);
call("shift amount is greater than the type size", null);
}
pub fn invalidEnumValue() noreturn {
@branchHint(.cold);
call("invalid enum value", null);
}
pub fn forLenMismatch() noreturn {
@branchHint(.cold);
call("for loop over objects with non-equal lengths", null);
}
pub fn copyLenMismatch() noreturn {
@branchHint(.cold);
call("source and destination have non-equal lengths", null);
}
pub fn memcpyAlias() noreturn {
@branchHint(.cold);
call("@memcpy arguments alias", null);
}
pub fn noreturnReturned() noreturn {
@branchHint(.cold);
call("'noreturn' function returned", null);
}
pub fn loadUninstantiableType() noreturn {
call("attempt to load uninstantiable type", null);
}