Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Namespace

simple_panic

Public Namespace

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.

Namespaces

Functions

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.

pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn
pub fn unwrapError(err: anyerror) noreturn
pub fn outOfBounds(index: usize, len: usize) noreturn
pub fn startGreaterThanEnd(start: usize, end: usize) noreturn
pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn
pub fn sliceCastLenRemainder(src_len: usize) noreturn
pub fn reachedUnreachable() noreturn
pub fn unwrapNull() noreturn
pub fn castToNull() noreturn
pub fn incorrectAlignment() noreturn
pub fn invalidErrorCode() noreturn
pub fn unexpectedErrorCode(err: anyerror) noreturn
pub fn integerOutOfBounds() noreturn
pub fn integerOverflow() noreturn
pub fn shlOverflow() noreturn
pub fn shrOverflow() noreturn
pub fn divideByZero() noreturn
pub fn exactDivisionRemainder() noreturn
pub fn integerPartOutOfBounds() noreturn
pub fn corruptSwitch() noreturn
pub fn shiftRhsTooBig() noreturn
pub fn invalidEnumValue() noreturn
pub fn forLenMismatch() noreturn
pub fn copyLenMismatch() noreturn
pub fn memcpyAlias() noreturn
pub fn noreturnReturned() noreturn
pub fn loadUninstantiableType() noreturn

File

debug/simple_panic.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//! 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;
    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);
}