Skip to content

Commit 4cb4148

Browse files
Jonathan Marlerandrewrk
Jonathan Marler
authored andcommitted
Document sentinel type in langref
1 parent 7699b5b commit 4cb4148

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

doc/langref.html.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8363,6 +8363,7 @@ pub const TypeInfo = union(TypeId) {
83638363
alignment: comptime_int,
83648364
child: type,
83658365
is_allowzero: bool,
8366+
sentinel: var,
83668367

83678368
pub const Size = enum {
83688369
One,
@@ -8375,6 +8376,7 @@ pub const TypeInfo = union(TypeId) {
83758376
pub const Array = struct {
83768377
len: comptime_int,
83778378
child: type,
8379+
sentinel: var,
83788380
};
83798381

83808382
pub const ContainerLayout = enum {
@@ -8505,6 +8507,24 @@ pub const TypeInfo = union(TypeId) {
85058507
{#link|error sets|Error Set Type#}, the fields are guaranteed to be in the same
85068508
order as declared. For declarations, the order is unspecified.
85078509
</p>
8510+
<p>
8511+
Note that the {#syntax#}sentinel{#endsyntax#} field in {#syntax#}TypeInfo.Pointer{#endsyntax#}
8512+
and {#syntax#}TypeInfo.Array{#endsyntax#} is of type {#syntax#}var{#endsyntax#} rather
8513+
than {#syntax#}?child{#endsyntax#}. {#syntax#}TypeInfo.Pointer{#endsyntax#}
8514+
and {#syntax#}TypeInfo.Array{#endsyntax#} can be constructed with any comptime value for the
8515+
{#syntax#}sentinel{#endsyntax#} field. However, the {#syntax#}@Type{#endsyntax#} builtin will
8516+
only accept the TypeInfo struct if the sentinel value is implicitly convertible to
8517+
{#syntax#}child{#endsyntax#}. Furthermore, any {#syntax#}TypeInfo.Pointer{#endsyntax#}
8518+
or {#syntax#}TypeInfo.Array{#endsyntax#} retreived from {#syntax#}@typeInfo{#endsyntax#} will
8519+
guarantee that {#syntax#}@typeOf(sentinel){#endsyntax#} is equal to
8520+
{#syntax#}?child{#endsyntax#}. For example, {#syntax#}@typeOf(sentinel){#endsyntax#} for a
8521+
{#syntax#}TypeInfo.Pointer{#endsyntax#} constructed with
8522+
{#syntax#}TypeInfo.Pointer { ... .sentinel = 0; ... }{#endsyntax#} would be
8523+
{#syntax#}comptime_int{#endsyntax#} rather than {#syntax#}?u8{#endsyntax#}. However, if you
8524+
passed that {#syntax#}TypeInfo.Pointer{#endsyntax#} struct to
8525+
{#syntax#}@typeInfo(@Type(myPointerInfo)){#endsyntax#} then {#syntax#}@typeOf(sentinel){#endsyntax#}
8526+
would be {#syntax#}?u8{#endsyntax#}.
8527+
</p>
85088528
{#header_close#}
85098529

85108530
{#header_open|@typeName#}

0 commit comments

Comments
 (0)