zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 032bbd68a7a17b4f8167f9644430c375f43da60c (tree)
parent de23ccfad1630e30d5b5ea1278ab2f375f987568
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date:   Thu, 31 Jul 2025 02:32:32 +0100

Merge pull request #24537 from IOKG04/some-documentation-updates-0

some small langref changes
Diffstat:
Mdoc/langref.html.in | 8++++----
Mdoc/langref/test_coerce_slices_arrays_and_pointers.zig | 7+++++++
Mtest/behavior/math.zig | 2++
3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/doc/langref.html.in b/doc/langref.html.in @@ -3215,7 +3215,7 @@ fn createFoo(param: i32) !Foo { to increase their development pace. </p> <p> - Error Return Traces are enabled by default in {#link|Debug#} and {#link|ReleaseSafe#} builds and disabled by default in {#link|ReleaseFast#} and {#link|ReleaseSmall#} builds. + Error Return Traces are enabled by default in {#link|Debug#} builds and disabled by default in {#link|ReleaseFast#}, {#link|ReleaseSafe#} and {#link|ReleaseSmall#} builds. </p> <p> There are a few ways to activate this error return tracing feature: @@ -4840,7 +4840,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val <p> This builtin can be called from a {#link|comptime#} block to conditionally export symbols. When <code>ptr</code> points to a function with the C calling convention and - {#syntax#}options.linkage{#endsyntax#} is {#syntax#}.Strong{#endsyntax#}, this is equivalent to + {#syntax#}options.linkage{#endsyntax#} is {#syntax#}.strong{#endsyntax#}, this is equivalent to the {#syntax#}export{#endsyntax#} keyword used on a function: </p> {#code|export_builtin.zig#} @@ -5179,7 +5179,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val <pre>{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}</pre> <p> Modulus division. For unsigned integers this is the same as - {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}, otherwise the + {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#}, otherwise the operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled. </p> <ul> @@ -5284,7 +5284,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val <pre>{#syntax#}@rem(numerator: T, denominator: T) T{#endsyntax#}</pre> <p> Remainder division. For unsigned integers this is the same as - {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}, otherwise the + {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#}, otherwise the operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled. </p> <ul> diff --git a/doc/langref/test_coerce_slices_arrays_and_pointers.zig b/doc/langref/test_coerce_slices_arrays_and_pointers.zig @@ -67,4 +67,11 @@ test "*T to *[1]T" { try expect(z[0] == 1234); } +// Sentinel-terminated slices can be coerced into sentinel-terminated pointers +test "[:x]T to [*:x]T" { + const buf: [:0]const u8 = "hello"; + const buf2: [*:0]const u8 = buf; + try expect(buf2[4] == 'o'); +} + // test diff --git a/test/behavior/math.zig b/test/behavior/math.zig @@ -525,6 +525,8 @@ fn testIntDivision() !void { try expect(rem(i32, 10, 12) == 10); try expect(rem(i32, -14, 12) == -2); try expect(rem(i32, -2, 12) == -2); + try expect(rem(i32, 118, -12) == 10); + try expect(rem(i32, -14, -12) == -2); try expect(rem(i16, -118, 12) == -10); try expect(divTrunc(i20, 20, -5) == -4);