Skip to content

Commit 743f03e

Browse files
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 <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 6125d0c commit 743f03e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

doc/go_spec.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification",
3-
"Subtitle": "Version of Jun 28, 2021",
3+
"Subtitle": "Version of Jul 1, 2021",
44
"Path": "/ref/spec"
55
}-->
66

@@ -6782,15 +6782,17 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
67826782

67836783
<p>
67846784
The function <code>Slice</code> returns a slice whose underlying array starts at <code>ptr</code>
6785-
and whose length and capacity are <code>len</code>:
6785+
and whose length and capacity are <code>len</code>.
6786+
<code>Slice(ptr, len)</code> is equivalent to
67866787
</p>
67876788

67886789
<pre>
67896790
(*[len]ArbitraryType)(unsafe.Pointer(ptr))[:]
67906791
</pre>
67916792

67926793
<p>
6793-
As a special case, if <code>ptr</code> is <code>nil</code> and <code>len</code> is zero,
6794+
except that, as a special case, if <code>ptr</code>
6795+
is <code>nil</code> and <code>len</code> is zero,
67946796
<code>Slice</code> returns <code>nil</code>.
67956797
</p>
67966798

src/unsafe/unsafe.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,13 @@ func Alignof(x ArbitraryType) uintptr
217217
func Add(ptr Pointer, len IntegerType) Pointer
218218

219219
// The function Slice returns a slice whose underlying array starts at ptr
220-
// and whose length and capacity are len:
220+
// and whose length and capacity are len.
221+
// Slice(ptr, len) is equivalent to
221222
//
222223
// (*[len]ArbitraryType)(unsafe.Pointer(ptr))[:]
223224
//
224-
// As a special case, if ptr is nil and len is zero, Slice returns nil.
225+
// except that, as a special case, if ptr is nil and len is zero,
226+
// Slice returns nil.
225227
//
226228
// The len argument must be of integer type or an untyped constant.
227229
// A constant len argument must be non-negative and representable by a value of type int;

0 commit comments

Comments
 (0)