Skip to content

Document sentinel type in langref #3861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -8351,6 +8351,7 @@ pub const TypeInfo = union(TypeId) {
alignment: comptime_int,
child: type,
is_allowzero: bool,
sentinel: var,

pub const Size = enum {
One,
Expand All @@ -8363,6 +8364,7 @@ pub const TypeInfo = union(TypeId) {
pub const Array = struct {
len: comptime_int,
child: type,
sentinel: var,
};

pub const ContainerLayout = enum {
Expand Down Expand Up @@ -8493,6 +8495,24 @@ pub const TypeInfo = union(TypeId) {
{#link|error sets|Error Set Type#}, the fields are guaranteed to be in the same
order as declared. For declarations, the order is unspecified.
</p>
<p>
Note that the {#syntax#}sentinel{#endsyntax#} field in {#syntax#}TypeInfo.Pointer{#endsyntax#}
and {#syntax#}TypeInfo.Array{#endsyntax#} is of type {#syntax#}var{#endsyntax#} rather
than {#syntax#}?child{#endsyntax#}. {#syntax#}TypeInfo.Pointer{#endsyntax#}
and {#syntax#}TypeInfo.Array{#endsyntax#} can be constructed with any comptime value for the
{#syntax#}sentinel{#endsyntax#} field. However, the {#syntax#}@Type{#endsyntax#} builtin will
only accept the TypeInfo struct if the sentinel value is implicitly convertible to
{#syntax#}child{#endsyntax#}. Furthermore, any {#syntax#}TypeInfo.Pointer{#endsyntax#}
or {#syntax#}TypeInfo.Array{#endsyntax#} retreived from {#syntax#}@typeInfo{#endsyntax#} will
guarantee that {#syntax#}@typeOf(sentinel){#endsyntax#} is equal to
{#syntax#}?child{#endsyntax#}. For example, {#syntax#}@typeOf(sentinel){#endsyntax#} for a
{#syntax#}TypeInfo.Pointer{#endsyntax#} constructed with
{#syntax#}TypeInfo.Pointer { ... .sentinel = 0; ... }{#endsyntax#} would be
{#syntax#}comptime_int{#endsyntax#} rather than {#syntax#}?u8{#endsyntax#}. However, if you
passed that {#syntax#}TypeInfo.Pointer{#endsyntax#} struct to
{#syntax#}@typeInfo(@Type(myPointerInfo)){#endsyntax#} then {#syntax#}@typeOf(sentinel){#endsyntax#}
would be {#syntax#}?u8{#endsyntax#}.
</p>
{#header_close#}

{#header_open|@typeName#}
Expand Down