commit 34d780f4bbefa8344cae5da49fe84bed83d8274f (tree)
parent ce1f28a7497903cf00431d6976c162c37683232a
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date: Thu, 5 Mar 2026 22:13:22 +0000
langref: update for language changes
Diffstat:
4 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/doc/langref.html.in b/doc/langref.html.in
@@ -2103,8 +2103,9 @@ or
less than {#syntax#}1 << 29{#endsyntax#}.
</p>
<p>
- In Zig, a pointer type has an alignment value. If the value is equal to the
- alignment of the underlying type, it can be omitted from the type:
+ Pointer types may explicitly specify an alignment in bytes. If it is not
+ specified, the alignment is assumed to be equal to the alignment of the
+ underlying type.
</p>
{#code|test_variable_alignment.zig#}
diff --git a/doc/langref/test_comptime_invalid_error_code.zig b/doc/langref/test_comptime_invalid_error_code.zig
@@ -1,8 +1,5 @@
comptime {
- const err = error.AnError;
- const number = @intFromError(err) + 10;
- const invalid_err = @errorFromInt(number);
- _ = invalid_err;
+ _ = @errorFromInt(12345);
}
-// test_error=integer value '11' represents no error
+// test_error=integer value '12345' represents no error
diff --git a/doc/langref/test_missized_packed_struct.zig b/doc/langref/test_missized_packed_struct.zig
@@ -3,4 +3,4 @@ test "missized packed struct" {
_ = S{ .a = 4, .b = 2 };
}
-// test_error=backing integer type 'u32' has bit size 32 but the struct fields have a total bit size of 24
+// test_error=backing integer bit width does not match total bit width of fields
diff --git a/doc/langref/test_variable_alignment.zig b/doc/langref/test_variable_alignment.zig
@@ -1,15 +1,20 @@
const std = @import("std");
const builtin = @import("builtin");
+const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "variable alignment" {
var x: i32 = 1234;
- const align_of_i32 = @alignOf(@TypeOf(x));
+
try expectEqual(*i32, @TypeOf(&x));
- try expectEqual(*align(align_of_i32) i32, *i32);
- if (builtin.target.cpu.arch == .x86_64) {
- try expectEqual(4, @typeInfo(*i32).pointer.alignment);
- }
+
+ try expect(@intFromPtr(&x) % @alignOf(i32) == 0);
+
+ // The implicitly-aligned pointer can be coerced to be explicitly-aligned to
+ // the alignment of the underlying type `i32`:
+ const ptr: *align(@alignOf(i32)) i32 = &x;
+
+ try expectEqual(1234, ptr.*);
}
// test