Skip to content

Commit ce78396

Browse files
stephencelisxwu
andauthored
Update stdlib/public/core/Collection.swift
Co-authored-by: Xiaodi Wu <[email protected]>
1 parent 099ecbe commit ce78396

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

stdlib/public/core/Collection.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,10 @@ extension Collection where SubSequence == Self {
16641664
public mutating func removeFirst(_ k: Int) {
16651665
if k == 0 { return }
16661666
_precondition(k >= 0, "Number of elements to remove should be non-negative")
1667-
_precondition(index(startIndex, offsetBy: k, limitedBy: endIndex) != nil,
1667+
guard let idx = index(startIndex, offsetBy: k, limitedBy: endIndex) else {
1668+
_preconditionFailure("Can't remove more items from a collection than it contains")
1669+
}
1670+
self = self[idx..<endIndex]
16681671
"Can't remove more items from a collection than it contains")
16691672
self = self[index(startIndex, offsetBy: k)..<endIndex]
16701673
}

0 commit comments

Comments
 (0)