diff --git a/doc/go_spec.html b/doc/go_spec.html index b59b37fd55240..e0602418e803f 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -6789,11 +6789,17 @@

Package unsafe

(*[len]ArbitraryType)(unsafe.Pointer(ptr))[:] +

+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; if it is an untyped constant it is given type int. -If ptr is nil or len is negative at run time, +At run time, if len is negative, +or if ptr is nil and len is not zero, a run-time panic occurs.

diff --git a/src/unsafe/unsafe.go b/src/unsafe/unsafe.go index ecbd28c523ee9..eaf72c96181fd 100644 --- a/src/unsafe/unsafe.go +++ b/src/unsafe/unsafe.go @@ -221,8 +221,11 @@ func Add(ptr Pointer, len IntegerType) Pointer // // (*[len]ArbitraryType)(unsafe.Pointer(ptr))[:] // +// 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; // if it is an untyped constant it is given type int. -// If ptr is nil or len is negative at run time, a run-time panic occurs. +// At run time, if len is negative, or if ptr is nil and len is not zero, +// a run-time panic occurs. func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType