authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-04-29 21:51:13+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-04-30 09:03:58+01:00
logbb83883acd9dee65423e836729eb0242c5e218ca
treec81bd55f63788495753a0086ec655e10427c8f1a
parentc144003fca989780bb4dccefc2a289bcbfb9969b
signaturelock-open Commit is signed but in an unrecognized format.

langref: update for language changes


6 files changed, 10 insertions(+), 68 deletions(-)

doc/langref.html.in+6-36
...@@ -624,11 +624,6 @@...@@ -624,11 +624,6 @@
624 <td><code class="c">void</code></td>624 <td><code class="c">void</code></td>
625 <td>Used for type-erased pointers.</td>625 <td>Used for type-erased pointers.</td>
626 </tr>626 </tr>
627 <tr>
628 <th scope="row">{#syntax#}void{#endsyntax#}</th>
629 <td>(none)</td>
630 <td>Always the value {#syntax#}void{}{#endsyntax#}</td>
631 </tr>
632 <tr>627 <tr>
633 <th scope="row">{#syntax#}noreturn{#endsyntax#}</th>628 <th scope="row">{#syntax#}noreturn{#endsyntax#}</th>
634 <td>(none)</td>629 <td>(none)</td>
...@@ -1806,25 +1801,6 @@ const together = array1 ++ array2;...@@ -1806,25 +1801,6 @@ const together = array1 ++ array2;
1806mem.eql(u32, &together, &[_]u32{1,2,3,4}){#endsyntax#}</pre>1801mem.eql(u32, &together, &[_]u32{1,2,3,4}){#endsyntax#}</pre>
1807 </td>1802 </td>
1808 </tr>1803 </tr>
1809 <tr>
1810 <td>Array Multiplication</td>
1811 <td><pre>{#syntax#}a ** b{#endsyntax#}</pre></td>
1812 <td>
1813 <ul>
1814 <li>{#link|Arrays#}</li>
1815 </ul>
1816 </td>
1817 <td>
1818 <ul>
1819 <li>Only available when the length of {#syntax#}a{#endsyntax#} and {#syntax#}b{#endsyntax#} are {#link|compile-time known|comptime#}.</li>
1820 </ul>
1821 </td>
1822 <td>
1823 <pre>{#syntax#}const mem = @import("std").mem;
1824const pattern = "ab" ** 3;
1825mem.eql(u8, pattern, "ababab"){#endsyntax#}</pre>
1826 </td>
1827 </tr>
1828 <tr>1804 <tr>
1829 <td>Pointer Dereference</td>1805 <td>Pointer Dereference</td>
1830 <td><pre>{#syntax#}a.*{#endsyntax#}</pre></td>1806 <td><pre>{#syntax#}a.*{#endsyntax#}</pre></td>
...@@ -1882,7 +1858,7 @@ const B = error{Two};...@@ -1882,7 +1858,7 @@ const B = error{Two};
1882a!b1858a!b
1883x{}1859x{}
1884!x -x -%x ~x &x ?x1860!x -x -%x ~x &x ?x
1885* / % ** *% *| ||1861* / % *% *| ||
1886+ - ++ +% -% +| -|1862+ - ++ +% -% +| -|
1887<< >> <<|1863<< >> <<|
1888& ^ | orelse catch1864& ^ | orelse catch
...@@ -2371,7 +2347,7 @@ or...@@ -2371,7 +2347,7 @@ or
2371 </p>2347 </p>
2372 <p>2348 <p>
2373 Like arrays, tuples have a .len field, can be indexed (provided the index is comptime-known)2349 Like arrays, tuples have a .len field, can be indexed (provided the index is comptime-known)
2374 and work with the ++ and ** operators. They can also be iterated over with {#link|inline for#}.2350 and work with the ++ operator. They can also be iterated over with {#link|inline for#}.
2375 </p>2351 </p>
2376 {#code|test_tuples.zig#}2352 {#code|test_tuples.zig#}
23772353
...@@ -2571,7 +2547,7 @@ or...@@ -2571,7 +2547,7 @@ or
2571 {#header_close#}2547 {#header_close#}
25722548
2573 {#header_open|Empty Blocks#}2549 {#header_open|Empty Blocks#}
2574 <p>An empty block is equivalent to {#syntax#}void{}{#endsyntax#}:</p>2550 <p>An empty block returns the single value of type {#syntax#}void{#endsyntax#}:</p>
2575 {#code|test_empty_block.zig#}2551 {#code|test_empty_block.zig#}
25762552
2577 {#header_close#}2553 {#header_close#}
...@@ -3159,10 +3135,6 @@ fn createFoo(param: i32) !Foo {...@@ -3159,10 +3135,6 @@ fn createFoo(param: i32) !Foo {
3159 the verbosity and cognitive overhead of trying to make sure every exit path3135 the verbosity and cognitive overhead of trying to make sure every exit path
3160 is covered. The deallocation code is always directly following the allocation code.3136 is covered. The deallocation code is always directly following the allocation code.
3161 </p>3137 </p>
3162 <p>
3163 The {#syntax#}errdefer{#endsyntax#} statement can optionally capture the error:
3164 </p>
3165 {#code|test_errdefer_capture.zig#}
3166 {#header_close#}3138 {#header_close#}
3167 <p>3139 <p>
3168 A couple of other tidbits about error handling:3140 A couple of other tidbits about error handling:
...@@ -3627,7 +3599,7 @@ void do_a_thing(struct Foo *foo) {...@@ -3627,7 +3599,7 @@ void do_a_thing(struct Foo *foo) {
3627 <p>For some types, {#link|@sizeOf#} is 0:</p>3599 <p>For some types, {#link|@sizeOf#} is 0:</p>
3628 <ul>3600 <ul>
3629 <li>{#link|void#}</li>3601 <li>{#link|void#}</li>
3630 <li>The {#link|Integers#} {#syntax#}u0{#endsyntax#} and {#syntax#}i0{#endsyntax#}.</li>3602 <li>The {#link|integer type|Integers#} {#syntax#}u0{#endsyntax#}.</li>
3631 <li>{#link|Arrays#} and {#link|Vectors#} with len 0, or with an element type that is a zero bit type.</li>3603 <li>{#link|Arrays#} and {#link|Vectors#} with len 0, or with an element type that is a zero bit type.</li>
3632 <li>An {#link|enum#} with only 1 tag.</li>3604 <li>An {#link|enum#} with only 1 tag.</li>
3633 <li>A {#link|struct#} with all fields being zero bit types.</li>3605 <li>A {#link|struct#} with all fields being zero bit types.</li>
...@@ -8036,7 +8008,6 @@ MultiplyOp...@@ -8036,7 +8008,6 @@ MultiplyOp
8036 / ASTERISK8008 / ASTERISK
8037 / SLASH8009 / SLASH
8038 / PERCENT8010 / PERCENT
8039 / ASTERISK2
8040 / ASTERISKPERCENT8011 / ASTERISKPERCENT
8041 / ASTERISKPIPE8012 / ASTERISKPIPE
80428013
...@@ -8083,11 +8054,11 @@ LabelableExpr...@@ -8083,11 +8054,11 @@ LabelableExpr
8083# Ptr specific8054# Ptr specific
8084SliceTypeStart <- LBRACKET (COLON Expr)? RBRACKET8055SliceTypeStart <- LBRACKET (COLON Expr)? RBRACKET
80858056
8086SinglePtrTypeStart <- ASTERISK / ASTERISK28057SinglePtrTypeStart <- ASTERISK
80878058
8088ManyPtrTypeStart <- LBRACKET ASTERISK (LETTERC / COLON Expr)? RBRACKET8059ManyPtrTypeStart <- LBRACKET ASTERISK (LETTERC / COLON Expr)? RBRACKET
80898060
8090ArrayTypeStart <- LBRACKET Expr !(ASTERISK / ASTERISK2) (COLON Expr)? RBRACKET8061ArrayTypeStart <- LBRACKET Expr !ASTERISK (COLON Expr)? RBRACKET
80918062
8092# ContainerDecl specific8063# ContainerDecl specific
8093ContainerDeclAuto <- ContainerDeclType LBRACE ContainerMembers RBRACE8064ContainerDeclAuto <- ContainerDeclType LBRACE ContainerMembers RBRACE
...@@ -8215,7 +8186,6 @@ BUILTINIDENTIFIER <- '@'[A-Za-z_][A-Za-z0-9_]* skip...@@ -8215,7 +8186,6 @@ BUILTINIDENTIFIER <- '@'[A-Za-z_][A-Za-z0-9_]* skip
8215AMPERSAND <- '&' ![=] skip8186AMPERSAND <- '&' ![=] skip
8216AMPERSANDEQUAL <- '&=' skip8187AMPERSANDEQUAL <- '&=' skip
8217ASTERISK <- '*' ![*%=|] skip8188ASTERISK <- '*' ![*%=|] skip
8218ASTERISK2 <- '**' skip
8219ASTERISKEQUAL <- '*=' skip8189ASTERISKEQUAL <- '*=' skip
8220ASTERISKPERCENT <- '*%' ![=] skip8190ASTERISKPERCENT <- '*%' ![=] skip
8221ASTERISKPERCENTEQUAL <- '*%=' skip8191ASTERISKPERCENTEQUAL <- '*%=' skip
doc/langref/test_arrays.zig+2-8
...@@ -60,14 +60,8 @@ comptime {...@@ -60,14 +60,8 @@ comptime {
60 assert(mem.eql(u8, hello_world, "hello world"));60 assert(mem.eql(u8, hello_world, "hello world"));
61}61}
6262
63// ** does repeating patterns
64const pattern = "ab" ** 3;
65comptime {
66 assert(mem.eql(u8, pattern, "ababab"));
67}
68
69// initialize an array to zero63// initialize an array to zero
70const all_zero = [_]u16{0} ** 10;64const all_zero: [10]u16 = @splat(0);
7165
72comptime {66comptime {
73 assert(all_zero.len == 10);67 assert(all_zero.len == 10);
...@@ -96,7 +90,7 @@ test "compile-time array initialization" {...@@ -96,7 +90,7 @@ test "compile-time array initialization" {
96}90}
9791
98// call a function to initialize an array92// call a function to initialize an array
99var more_points = [_]Point{makePoint(3)} ** 10;93var more_points: [10]Point = @splat(makePoint(3));
100fn makePoint(x: i32) Point {94fn makePoint(x: i32) Point {
101 return Point{95 return Point{
102 .x = x,96 .x = x,
doc/langref/test_empty_block.zig-3
...@@ -3,10 +3,7 @@ const expectEqual = std.testing.expectEqual;...@@ -3,10 +3,7 @@ const expectEqual = std.testing.expectEqual;
33
4test {4test {
5 const a = {};5 const a = {};
6 const b = void{};
7 try expectEqual(void, @TypeOf(a));6 try expectEqual(void, @TypeOf(a));
8 try expectEqual(void, @TypeOf(b));
9 try expectEqual(a, b);
10}7}
118
12// test9// test
doc/langref/test_errdefer_capture.zig deleted-19
...@@ -1,19 +0,0 @@
1const std = @import("std");
2
3fn captureError(captured: *?anyerror) !void {
4 errdefer |err| {
5 captured.* = err;
6 }
7 return error.GeneralFailure;
8}
9
10test "errdefer capture" {
11 var captured: ?anyerror = null;
12
13 if (captureError(&captured)) unreachable else |err| {
14 try std.testing.expectEqual(error.GeneralFailure, captured.?);
15 try std.testing.expectEqual(error.GeneralFailure, err);
16 }
17}
18
19// test
doc/langref/test_multidimensional_arrays.zig+1-1
...@@ -24,7 +24,7 @@ test "multidimensional arrays" {...@@ -24,7 +24,7 @@ test "multidimensional arrays" {
24 }24 }
2525
26 // Initialize a multidimensional array to zeros.26 // Initialize a multidimensional array to zeros.
27 const all_zero: [4][5]f32 = .{.{0} ** 5} ** 4;27 const all_zero: [4][5]f32 = @splat(@splat(0));
28 try expectEqual(0, all_zero[0][0]);28 try expectEqual(0, all_zero[0][0]);
29}29}
3030
doc/langref/test_tuples.zig+1-1
...@@ -8,7 +8,7 @@ test "tuple" {...@@ -8,7 +8,7 @@ test "tuple" {
8 @as(f64, 12.34),8 @as(f64, 12.34),
9 true,9 true,
10 "hi",10 "hi",
11 } ++ .{false} ** 2;11 } ++ .{ false, false };
12 try expectEqual(1234, values[0]);12 try expectEqual(1234, values[0]);
13 try expectEqual(false, values[4]);13 try expectEqual(false, values[4]);
14 inline for (values, 0..) |v, i| {14 inline for (values, 0..) |v, i| {