]> Cypherpunks repositories - gostls13.git/commitdiff
slices: clarify Insert behavior if i == len(s)
authorIan Lance Taylor <iant@golang.org>
Wed, 28 Aug 2024 16:33:49 +0000 (09:33 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 28 Aug 2024 20:02:26 +0000 (20:02 +0000)
Fixes #69104

Change-Id: Ie928239d5ef198ce36759ec4cffb7f6320ff3b82
Reviewed-on: https://go-review.googlesource.com/c/go/+/609175
Reviewed-by: Eli Bendersky <eliben@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>

src/slices/slices.go

index 200e653dde5067ac488f39148efa6820392acd58..b53419f84b511be8d73da842d20b09ef5b634896 100644 (file)
@@ -128,8 +128,8 @@ func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool {
 // returning the modified slice.
 // The elements at s[i:] are shifted up to make room.
 // In the returned slice r, r[i] == v[0],
-// and r[i+len(v)] == value originally at r[i].
-// Insert panics if i is out of range.
+// and, if i < len(s), r[i+len(v)] == value originally at r[i].
+// Insert panics if i > len(s).
 // This function is O(len(s) + len(v)).
 func Insert[S ~[]E, E any](s S, i int, v ...E) S {
        _ = s[i:] // bounds check