Skip to content

Commit e5b4762

Browse files
Docs fix array/pointer/slice type coercion section (#9392)
* removed deprecated coercion: [X]T => [] const T * Fixed tests and added desc for first test * Improved heading
1 parent 8ad23d7 commit e5b4762

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

doc/langref.html.in

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5337,16 +5337,15 @@ test "implicit cast to comptime_int" {
53375337
}
53385338
{#code_end#}
53395339
{#header_close#}
5340-
{#header_open|Type Coercion: Arrays and Pointers#}
5341-
{#code_begin|test|coerce_arrays_and_ptrs#}
5340+
{#header_open|Type Coercion: Slices, Arrays and Pointers#}
5341+
{#code_begin|test|coerce__slices_arrays_and_ptrs#}
53425342
const std = @import("std");
53435343
const expect = std.testing.expect;
53445344

5345-
// This cast exists primarily so that string literals can be
5346-
// passed to functions that accept const slices. However
5347-
// it is probably going to be removed from the language when
5348-
// https://github.com/ziglang/zig/issues/265 is implemented.
5349-
test "[N]T to []const T" {
5345+
// You can assign constant pointers to arrays to a slice with
5346+
// const modifier on the element type. Useful in particular for
5347+
// String literals.
5348+
test "*const [N]T to []const T" {
53505349
var x1: []const u8 = "hello";
53515350
var x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
53525351
try expect(std.mem.eql(u8, x1, x2));
@@ -5356,7 +5355,7 @@ test "[N]T to []const T" {
53565355
}
53575356

53585357
// Likewise, it works when the destination type is an error union.
5359-
test "[N]T to E![]const T" {
5358+
test "*const [N]T to E![]const T" {
53605359
var x1: anyerror![]const u8 = "hello";
53615360
var x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
53625361
try expect(std.mem.eql(u8, try x1, try x2));
@@ -5366,7 +5365,7 @@ test "[N]T to E![]const T" {
53665365
}
53675366

53685367
// Likewise, it works when the destination type is an optional.
5369-
test "[N]T to ?[]const T" {
5368+
test "*const [N]T to ?[]const T" {
53705369
var x1: ?[]const u8 = "hello";
53715370
var x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
53725371
try expect(std.mem.eql(u8, x1.?, x2.?));

0 commit comments

Comments
 (0)