From 743f03eeb0bdcb596b46fae51d23c0fcf0db0474 Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor
Date: Thu, 1 Jul 2021 16:52:59 -0700
Subject: [PATCH] spec, unsafe: clarify unsafe.Slice docs
For #19367
Change-Id: If0ff8ddba3b6b48e2e198cf3653e73284c7572a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/332409
Trust: Ian Lance Taylor
Reviewed-by: Matthew Dempsky
Reviewed-by: Robert Griesemer
Reviewed-by: Keith Randall
---
doc/go_spec.html | 8 +++++---
src/unsafe/unsafe.go | 6 ++++--
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/doc/go_spec.html b/doc/go_spec.html
index e0602418e8..ad21ffb1b8 100644
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,6 +1,6 @@
@@ -6782,7 +6782,8 @@ The rules for valid uses of Pointer
The function Slice
returns a slice whose underlying array starts at ptr
-and whose length and capacity are len
:
+and whose length and capacity are len
.
+Slice(ptr, len)
is equivalent to
@@ -6790,7 +6791,8 @@ and whose length and capacity are len
:
-As a special case, if ptr
is nil
and len
is zero,
+except that, as a special case, if ptr
+is nil
and len
is zero,
Slice
returns nil
.
diff --git a/src/unsafe/unsafe.go b/src/unsafe/unsafe.go
index eaf72c9618..16e3890d0b 100644
--- a/src/unsafe/unsafe.go
+++ b/src/unsafe/unsafe.go
@@ -217,11 +217,13 @@ func Alignof(x ArbitraryType) uintptr
func Add(ptr Pointer, len IntegerType) Pointer
// The function Slice returns a slice whose underlying array starts at ptr
-// and whose length and capacity are len:
+// and whose length and capacity are len.
+// Slice(ptr, len) is equivalent to
//
// (*[len]ArbitraryType)(unsafe.Pointer(ptr))[:]
//
-// As a special case, if ptr is nil and len is zero, Slice returns nil.
+// except that, as a special case, if ptr is nil and len is zero,
+// Slice returns nil.
//
// The len argument must be of integer type or an untyped constant.
// A constant len argument must be non-negative and representable by a value of type int;