structstd.debug.simple_panic[src]

This namespace is the default one used by the Zig compiler to emit various kinds of safety panics, due to the logic in std.builtin.panic.

Since Zig does not have interfaces, this file serves as an example template for users to provide their own alternative panic handling.

As an alternative, see std.debug.FullPanic.

Functions

Functioncall[src]

pub fn call(msg: []const u8, ra: ?usize) noreturn

Prints the message to stderr without a newline and then traps.

Explicit calls to @panic lower to calling this function.

Parameters

msg: []const u8
ra: ?usize

Source Code

Source code
pub fn call(msg: []const u8, ra: ?usize) noreturn {
    @branchHint(.cold);
    _ = ra;
    std.debug.lockStdErr();
    const stderr = std.io.getStdErr();
    stderr.writeAll(msg) catch {};
    @trap();
}

FunctionsentinelMismatch[src]

pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn

Parameters

found: @TypeOf(expected)

Source Code

Source code
pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn {
    _ = found;
    call("sentinel mismatch", null);
}

FunctionunwrapError[src]

pub fn unwrapError(err: anyerror) noreturn

Parameters

err: anyerror

Source Code

Source code
pub fn unwrapError(err: anyerror) noreturn {
    _ = &err;
    call("attempt to unwrap error", null);
}

FunctionoutOfBounds[src]

pub fn outOfBounds(index: usize, len: usize) noreturn

Parameters

index: usize
len: usize

Source Code

Source code
pub fn outOfBounds(index: usize, len: usize) noreturn {
    _ = index;
    _ = len;
    call("index out of bounds", null);
}

FunctionstartGreaterThanEnd[src]

pub fn startGreaterThanEnd(start: usize, end: usize) noreturn

Parameters

start: usize
end: usize

Source Code

Source code
pub fn startGreaterThanEnd(start: usize, end: usize) noreturn {
    _ = start;
    _ = end;
    call("start index is larger than end index", null);
}

FunctioninactiveUnionField[src]

pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn

Parameters

accessed: @TypeOf(active)

Source Code

Source code
pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn {
    _ = accessed;
    call("access of inactive union field", null);
}

FunctionsliceCastLenRemainder[src]

pub fn sliceCastLenRemainder(src_len: usize) noreturn

Parameters

src_len: usize

Source Code

Source code
pub fn sliceCastLenRemainder(src_len: usize) noreturn {
    _ = src_len;
    call("slice length does not divide exactly into destination elements", null);
}

FunctionreachedUnreachable[src]

pub fn reachedUnreachable() noreturn

Source Code

Source code
pub fn reachedUnreachable() noreturn {
    call("reached unreachable code", null);
}

FunctionunwrapNull[src]

pub fn unwrapNull() noreturn

Source Code

Source code
pub fn unwrapNull() noreturn {
    call("attempt to use null value", null);
}

FunctioncastToNull[src]

pub fn castToNull() noreturn

Source Code

Source code
pub fn castToNull() noreturn {
    call("cast causes pointer to be null", null);
}

FunctionincorrectAlignment[src]

pub fn incorrectAlignment() noreturn

Source Code

Source code
pub fn incorrectAlignment() noreturn {
    call("incorrect alignment", null);
}

FunctioninvalidErrorCode[src]

pub fn invalidErrorCode() noreturn

Source Code

Source code
pub fn invalidErrorCode() noreturn {
    call("invalid error code", null);
}

FunctioncastTruncatedData[src]

pub fn castTruncatedData() noreturn

Source Code

Source code
pub fn castTruncatedData() noreturn {
    call("integer cast truncated bits", null);
}

FunctionnegativeToUnsigned[src]

pub fn negativeToUnsigned() noreturn

Source Code

Source code
pub fn negativeToUnsigned() noreturn {
    call("attempt to cast negative value to unsigned integer", null);
}

FunctionintegerOverflow[src]

pub fn integerOverflow() noreturn

Source Code

Source code
pub fn integerOverflow() noreturn {
    call("integer overflow", null);
}

FunctionshlOverflow[src]

pub fn shlOverflow() noreturn

Source Code

Source code
pub fn shlOverflow() noreturn {
    call("left shift overflowed bits", null);
}

FunctionshrOverflow[src]

pub fn shrOverflow() noreturn

Source Code

Source code
pub fn shrOverflow() noreturn {
    call("right shift overflowed bits", null);
}

FunctiondivideByZero[src]

pub fn divideByZero() noreturn

Source Code

Source code
pub fn divideByZero() noreturn {
    call("division by zero", null);
}

FunctionexactDivisionRemainder[src]

pub fn exactDivisionRemainder() noreturn

Source Code

Source code
pub fn exactDivisionRemainder() noreturn {
    call("exact division produced remainder", null);
}

FunctionintegerPartOutOfBounds[src]

pub fn integerPartOutOfBounds() noreturn

Source Code

Source code
pub fn integerPartOutOfBounds() noreturn {
    call("integer part of floating point value out of bounds", null);
}

FunctioncorruptSwitch[src]

pub fn corruptSwitch() noreturn

Source Code

Source code
pub fn corruptSwitch() noreturn {
    call("switch on corrupt value", null);
}

FunctionshiftRhsTooBig[src]

pub fn shiftRhsTooBig() noreturn

Source Code

Source code
pub fn shiftRhsTooBig() noreturn {
    call("shift amount is greater than the type size", null);
}

FunctioninvalidEnumValue[src]

pub fn invalidEnumValue() noreturn

Source Code

Source code
pub fn invalidEnumValue() noreturn {
    call("invalid enum value", null);
}

FunctionforLenMismatch[src]

pub fn forLenMismatch() noreturn

Source Code

Source code
pub fn forLenMismatch() noreturn {
    call("for loop over objects with non-equal lengths", null);
}

FunctionmemcpyLenMismatch[src]

pub fn memcpyLenMismatch() noreturn

Source Code

Source code
pub fn memcpyLenMismatch() noreturn {
    call("@memcpy arguments have non-equal lengths", null);
}

FunctionmemcpyAlias[src]

pub fn memcpyAlias() noreturn

Source Code

Source code
pub fn memcpyAlias() noreturn {
    call("@memcpy arguments alias", null);
}

FunctionnoreturnReturned[src]

pub fn noreturnReturned() noreturn

Source Code

Source code
pub fn noreturnReturned() noreturn {
    call("'noreturn' function returned", null);
}

Source Code

Source code
//! This namespace is the default one used by the Zig compiler to emit various
//! kinds of safety panics, due to the logic in `std.builtin.panic`.
//!
//! Since Zig does not have interfaces, this file serves as an example template
//! for users to provide their own alternative panic handling.
//!
//! As an alternative, see `std.debug.FullPanic`.

const std = @import("../std.zig");

/// Prints the message to stderr without a newline and then traps.
///
/// Explicit calls to `@panic` lower to calling this function.
pub fn call(msg: []const u8, ra: ?usize) noreturn {
    @branchHint(.cold);
    _ = ra;
    std.debug.lockStdErr();
    const stderr = std.io.getStdErr();
    stderr.writeAll(msg) catch {};
    @trap();
}

pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn {
    _ = found;
    call("sentinel mismatch", null);
}

pub fn unwrapError(err: anyerror) noreturn {
    _ = &err;
    call("attempt to unwrap error", null);
}

pub fn outOfBounds(index: usize, len: usize) noreturn {
    _ = index;
    _ = len;
    call("index out of bounds", null);
}

pub fn startGreaterThanEnd(start: usize, end: usize) noreturn {
    _ = start;
    _ = end;
    call("start index is larger than end index", null);
}

pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn {
    _ = accessed;
    call("access of inactive union field", null);
}

pub fn sliceCastLenRemainder(src_len: usize) noreturn {
    _ = src_len;
    call("slice length does not divide exactly into destination elements", null);
}

pub fn reachedUnreachable() noreturn {
    call("reached unreachable code", null);
}

pub fn unwrapNull() noreturn {
    call("attempt to use null value", null);
}

pub fn castToNull() noreturn {
    call("cast causes pointer to be null", null);
}

pub fn incorrectAlignment() noreturn {
    call("incorrect alignment", null);
}

pub fn invalidErrorCode() noreturn {
    call("invalid error code", null);
}

pub fn castTruncatedData() noreturn {
    call("integer cast truncated bits", null);
}

pub fn negativeToUnsigned() noreturn {
    call("attempt to cast negative value to unsigned integer", null);
}

pub fn integerOverflow() noreturn {
    call("integer overflow", null);
}

pub fn shlOverflow() noreturn {
    call("left shift overflowed bits", null);
}

pub fn shrOverflow() noreturn {
    call("right shift overflowed bits", null);
}

pub fn divideByZero() noreturn {
    call("division by zero", null);
}

pub fn exactDivisionRemainder() noreturn {
    call("exact division produced remainder", null);
}

pub fn integerPartOutOfBounds() noreturn {
    call("integer part of floating point value out of bounds", null);
}

pub fn corruptSwitch() noreturn {
    call("switch on corrupt value", null);
}

pub fn shiftRhsTooBig() noreturn {
    call("shift amount is greater than the type size", null);
}

pub fn invalidEnumValue() noreturn {
    call("invalid enum value", null);
}

pub fn forLenMismatch() noreturn {
    call("for loop over objects with non-equal lengths", null);
}

pub fn memcpyLenMismatch() noreturn {
    call("@memcpy arguments have non-equal lengths", null);
}

pub fn memcpyAlias() noreturn {
    call("@memcpy arguments alias", null);
}

pub fn noreturnReturned() noreturn {
    call("'noreturn' function returned", null);
}