From 6b8ae6fffb71128169de447851244869aebb882b Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Sat, 26 Sep 2020 09:05:11 -0600 Subject: [PATCH] langref: update for opaque {} syntax --- doc/docgen.zig | 1 + doc/langref.html.in | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/doc/docgen.zig b/doc/docgen.zig index 50523d0948..52f373f5b1 100644 --- a/doc/docgen.zig +++ b/doc/docgen.zig @@ -808,6 +808,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token: .Keyword_noalias, .Keyword_noinline, .Keyword_nosuspend, + .Keyword_opaque, .Keyword_or, .Keyword_orelse, .Keyword_packed, diff --git a/doc/langref.html.in b/doc/langref.html.in index 690614ff99..021fc76289 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -1988,7 +1988,7 @@ test "null terminated array" {
  • Supports slice syntax: {#syntax#}ptr[start..end]{#endsyntax#}
  • Supports pointer arithmetic: {#syntax#}ptr + x{#endsyntax#}, {#syntax#}ptr - x{#endsyntax#}
  • {#syntax#}T{#endsyntax#} must have a known size, which means that it cannot be - {#syntax#}c_void{#endsyntax#} or any other {#link|opaque type|Opaque Types#}.
  • + {#syntax#}c_void{#endsyntax#} or any other {#link|opaque type|opaque#}. @@ -5545,7 +5545,7 @@ test "turn HashMap into a set with void" {

    {#syntax#}void{#endsyntax#} is distinct from {#syntax#}c_void{#endsyntax#}, which is defined like this: - {#syntax#}pub const c_void = @Type(.Opaque);{#endsyntax#}. + {#syntax#}pub const c_void = opaque {};{#endsyntax#}. {#syntax#}void{#endsyntax#} has a known size of 0 bytes, and {#syntax#}c_void{#endsyntax#} has an unknown, but non-zero, size.

    @@ -8471,7 +8471,7 @@ test "integer truncation" {

  • {#link|Error Set Type#}
  • {#link|Error Union Type#}
  • {#link|Vectors#}
  • -
  • {#link|Opaque Types#}
  • +
  • {#link|opaque#}
  • {#link|@Frame#}
  • {#syntax#}anyframe{#endsyntax#}
  • {#link|struct#}
  • @@ -8547,17 +8547,18 @@ fn foo(comptime T: type, ptr: *T) T { {#header_close#} {#header_close#} - {#header_open|Opaque Types#} + {#header_open|opaque#}

    - {#syntax#}@Type(.Opaque){#endsyntax#} creates a new type with an unknown (but non-zero) size and alignment. + {#syntax#}opaque {}{#endsyntax#} declares a new type with an unknown (but non-zero) size and alignment. + It can have declarations like structs, unions, or enums.

    This is typically used for type safety when interacting with C code that does not expose struct details. Example:

    {#code_begin|test_err|expected type '*Derp', found '*Wat'#} -const Derp = @Type(.Opaque); -const Wat = @Type(.Opaque); +const Derp = opaque {}; +const Wat = opaque {}; extern fn bar(d: *Derp) void; fn foo(w: *Wat) callconv(.C) void {