Skip to content

Commit f8f25f7

Browse files
committed
langref: update for opaque {} syntax
1 parent 6e27ceb commit f8f25f7

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

doc/docgen.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:
808808
.Keyword_noalias,
809809
.Keyword_noinline,
810810
.Keyword_nosuspend,
811+
.Keyword_opaque,
811812
.Keyword_or,
812813
.Keyword_orelse,
813814
.Keyword_packed,

doc/langref.html.in

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ test "null terminated array" {
19881988
<li>Supports slice syntax: {#syntax#}ptr[start..end]{#endsyntax#}</li>
19891989
<li>Supports pointer arithmetic: {#syntax#}ptr + x{#endsyntax#}, {#syntax#}ptr - x{#endsyntax#}</li>
19901990
<li>{#syntax#}T{#endsyntax#} must have a known size, which means that it cannot be
1991-
{#syntax#}c_void{#endsyntax#} or any other {#link|opaque type|Opaque Types#}.</li>
1991+
{#syntax#}c_void{#endsyntax#} or any other {#link|opaque type|opaque#}.</li>
19921992
</ul>
19931993
</li>
19941994
</ul>
@@ -5545,7 +5545,7 @@ test "turn HashMap into a set with void" {
55455545
</p>
55465546
<p>
55475547
{#syntax#}void{#endsyntax#} is distinct from {#syntax#}c_void{#endsyntax#}, which is defined like this:
5548-
{#syntax#}pub const c_void = @Type(.Opaque);{#endsyntax#}.
5548+
{#syntax#}pub const c_void = opaque {};{#endsyntax#}.
55495549
{#syntax#}void{#endsyntax#} has a known size of 0 bytes, and {#syntax#}c_void{#endsyntax#} has an unknown, but non-zero, size.
55505550
</p>
55515551
<p>
@@ -8471,7 +8471,7 @@ test "integer truncation" {
84718471
<li>{#link|Error Set Type#}</li>
84728472
<li>{#link|Error Union Type#}</li>
84738473
<li>{#link|Vectors#}</li>
8474-
<li>{#link|Opaque Types#}</li>
8474+
<li>{#link|opaque#}</li>
84758475
<li>{#link|@Frame#}</li>
84768476
<li>{#syntax#}anyframe{#endsyntax#}</li>
84778477
<li>{#link|struct#}</li>
@@ -8547,17 +8547,18 @@ fn foo(comptime T: type, ptr: *T) T {
85478547
{#header_close#}
85488548
{#header_close#}
85498549

8550-
{#header_open|Opaque Types#}
8550+
{#header_open|opaque#}
85518551
<p>
8552-
{#syntax#}@Type(.Opaque){#endsyntax#} creates a new type with an unknown (but non-zero) size and alignment.
8552+
{#syntax#}opaque {}{#endsyntax#} declares a new type with an unknown (but non-zero) size and alignment.
8553+
It can have declarations like structs, unions, or enums.
85538554
</p>
85548555
<p>
85558556
This is typically used for type safety when interacting with C code that does not expose struct details.
85568557
Example:
85578558
</p>
85588559
{#code_begin|test_err|expected type '*Derp', found '*Wat'#}
8559-
const Derp = @Type(.Opaque);
8560-
const Wat = @Type(.Opaque);
8560+
const Derp = opaque {};
8561+
const Wat = opaque {};
85618562

85628563
extern fn bar(d: *Derp) void;
85638564
fn foo(w: *Wat) callconv(.C) void {

0 commit comments

Comments
 (0)