authorgravatar for david.may@hey.comDavid May <david.may@hey.com> 2021-07-23 08:32:20+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-07-23 09:32:20+03:00
loge5b476209a1215a03164890d331e2013f20882a6
treeb3b57c569f62472c7fea0f783da680bbeb0a9e8b
parent8ad23d7beba9403d83ab961912d62002d9cb9602
signature Signed by PGP key 4AEE18F83AFDEB23

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 files changed, 8 insertions(+), 9 deletions(-)

doc/langref.html.in+8-9
......@@ -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#}
53425342const std = @import("std");
53435343const 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.
5349test "[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.
5348test "*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.
5359test "[N]T to E![]const T" {
5358test "*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.
5369test "[N]T to ?[]const T" {
5368test "*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.?));