slices: clarify Insert behavior if i == len(s)

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>
This commit is contained in:
Ian Lance Taylor 2024-08-28 09:33:49 -07:00 committed by Gopher Robot
parent fe63d483f4
commit 6d52d7d22b
1 changed files with 2 additions and 2 deletions

View 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