authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-30 16:27:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-30 16:33:22-07:00
loga5c96c49d0eedbce40ad9a58d1b236f1eaeabd03
treeed9cfb13cc4d9aba92b8494c6c53a82e938099e3
parent3f3003097cbf5a6ad9e0dfc29b2cafbe2e35dded

langref: mention `void{}` and empty blocks

closes #11112 closes #12496

1 files changed, 20 insertions(+), 4 deletions(-)

doc/langref.html.in+20-4
...@@ -760,7 +760,7 @@ pub fn main() void {...@@ -760,7 +760,7 @@ pub fn main() void {
760 <tr>760 <tr>
761 <th scope="row">{#syntax#}void{#endsyntax#}</th>761 <th scope="row">{#syntax#}void{#endsyntax#}</th>
762 <td>(none)</td>762 <td>(none)</td>
763 <td>0 bit type</td>763 <td>Always the value {#syntax#}void{}{#endsyntax#}</td>
764 </tr>764 </tr>
765 <tr>765 <tr>
766 <th scope="row">{#syntax#}noreturn{#endsyntax#}</th>766 <th scope="row">{#syntax#}noreturn{#endsyntax#}</th>
...@@ -1061,7 +1061,7 @@ fn addOne(number: i32) i32 {...@@ -1061,7 +1061,7 @@ fn addOne(number: i32) i32 {
1061 <p>1061 <p>
1062 Test declarations contain the {#link|keyword|Keyword Reference#} {#syntax#}test{#endsyntax#}, followed by an1062 Test declarations contain the {#link|keyword|Keyword Reference#} {#syntax#}test{#endsyntax#}, followed by an
1063 optional name written as a {#link|string literal|String Literals and Unicode Code Point Literals#}, followed1063 optional name written as a {#link|string literal|String Literals and Unicode Code Point Literals#}, followed
1064 by a {#link|block|blocks#} containing any valid Zig code that is allowed in a {#link|function|Functions#}.1064 by a {#link|block|Blocks#} containing any valid Zig code that is allowed in a {#link|function|Functions#}.
1065 </p>1065 </p>
1066 <aside>1066 <aside>
1067 By convention, non-named tests should only be used to {#link|make other tests run|Nested Container Tests#}.1067 By convention, non-named tests should only be used to {#link|make other tests run|Nested Container Tests#}.
...@@ -4024,7 +4024,7 @@ test "call foo" {...@@ -4024,7 +4024,7 @@ test "call foo" {
4024 {#code_end#}4024 {#code_end#}
4025 {#header_close#}4025 {#header_close#}
40264026
4027 {#header_open|blocks#}4027 {#header_open|Blocks#}
4028 <p>4028 <p>
4029 Blocks are used to limit the scope of variable declarations:4029 Blocks are used to limit the scope of variable declarations:
4030 </p>4030 </p>
...@@ -4088,6 +4088,22 @@ test "separate scopes" {...@@ -4088,6 +4088,22 @@ test "separate scopes" {
4088}4088}
4089 {#code_end#}4089 {#code_end#}
4090 {#header_close#}4090 {#header_close#}
4091
4092 {#header_open|Empty Blocks#}
4093 <p>An empty block is equivalent to {#syntax#}void{}{#endsyntax#}:</p>
4094 {#code_begin|test|empty_block#}
4095const std = @import("std");
4096const expect = std.testing.expect;
4097
4098test {
4099 const a = {};
4100 const b = void{};
4101 try expect(@TypeOf(a) == void);
4102 try expect(@TypeOf(b) == void);
4103 try expect(a == b);
4104}
4105 {#code_end#}
4106 {#header_close#}
4091 {#header_close#}4107 {#header_close#}
40924108
4093 {#header_open|switch#}4109 {#header_open|switch#}
...@@ -11987,7 +12003,7 @@ fn readU32Be() u32 {}...@@ -11987,7 +12003,7 @@ fn readU32Be() u32 {}
11987 {#syntax#}break{#endsyntax#} can be used with a block label to return a value from the block.12003 {#syntax#}break{#endsyntax#} can be used with a block label to return a value from the block.
11988 It can also be used to exit a loop before iteration completes naturally.12004 It can also be used to exit a loop before iteration completes naturally.
11989 <ul>12005 <ul>
11990 <li>See also {#link|blocks#}, {#link|while#}, {#link|for#}</li>12006 <li>See also {#link|Blocks#}, {#link|while#}, {#link|for#}</li>
11991 </ul>12007 </ul>
11992 </td>12008 </td>
11993 </tr>12009 </tr>