From 9503f8fe570eeb4a9622b5f50770861929435fb5 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 4 Feb 2026 10:27:08 -0800 Subject: [PATCH] Improve consistency of precondition failure messages More uniform message strings should feel better, and they should ever so slightly reduce code size. --- .../RigidArray/RigidArray.swift | 2 +- .../BitArray/BitArray+Extras.swift | 6 ++--- .../BitCollections/BitSet/BitSet+Extras.swift | 2 +- .../Protocols/Container.swift | 8 +++---- .../ContainersPreview/Protocols/Drain.swift | 2 +- .../Protocols/Producer.swift | 2 +- .../ContainersPreview/Types/InputSpan.swift | 2 +- .../DequeModule/Deque/Deque+Collection.swift | 14 +++++------ .../RigidDeque/RigidDeque+Insertions.swift | 2 +- .../RigidDeque/RigidDeque+Removals.swift | 8 +++---- .../RigidDeque/RigidDeque+Replacements.swift | 2 +- .../UniqueDeque/UniqueDeque+Insertions.swift | 2 +- .../UniqueDeque+Replacements.swift | 4 ++-- Sources/DequeModule/_UnsafeDequeHandle.swift | 4 ++-- .../TreeDictionary+Collection.swift | 2 +- .../TreeDictionary/TreeDictionary.swift | 2 +- .../TreeSet/TreeSet+Collection.swift | 2 +- .../TreeSet/TreeSet+Extras.swift | 2 +- .../Span+Extras.swift | 4 ++-- .../UnsafeBitSet/_UnsafeBitSet.swift | 2 +- .../UnsafeBufferPointer+Extras.swift | 12 +++++----- .../UnsafeMutableBufferPointer+Extras.swift | 12 +++++----- ...y+Partial RangeReplaceableCollection.swift | 8 +++---- ...t+Partial RangeReplaceableCollection.swift | 8 +++---- .../BigString/Basics/BigString+Contents.swift | 4 ++-- ...BigString+RangeReplaceableCollection.swift | 2 +- .../Views/BigSubstring+UTF16View.swift | 4 ++-- .../Views/BigSubstring+UTF8View.swift | 4 ++-- .../BigSubstring+UnicodeScalarView.swift | 4 ++-- .../BigString/Views/BigSubstring.swift | 4 ++-- .../Rope/Conformances/Rope+Collection.swift | 4 ++-- .../OrderedSet/OrderedSetTests.swift | 2 +- .../AssertionContexts/TestContext.swift | 4 ++-- .../MinimalTypes/_MinimalCollectionCore.swift | 24 +++++++++---------- 34 files changed, 84 insertions(+), 86 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray.swift b/Sources/BasicContainers/RigidArray/RigidArray.swift index 4f13a871..b785b573 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray.swift @@ -460,7 +460,7 @@ extension RigidArray where Element: ~Copyable { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= _count, "Index range out of bounds") - precondition(newCount >= 0, "Negative count") + precondition(newCount >= 0, "Cannot add a negative number of items") precondition( newCount - subrange.count <= freeCapacity, "RigidArray capacity overflow") diff --git a/Sources/BitCollections/BitArray/BitArray+Extras.swift b/Sources/BitCollections/BitArray/BitArray+Extras.swift index 6a41c875..a96b94e6 100644 --- a/Sources/BitCollections/BitArray/BitArray+Extras.swift +++ b/Sources/BitCollections/BitArray/BitArray+Extras.swift @@ -20,7 +20,7 @@ extension BitArray { toCount count: Int, with padding: Bool = false ) { - precondition(count >= 0, "Negative count") + precondition(count >= 0, "Cannot set a negative count") if count < _count { _removeLast(self.count - count) } else if count > _count { @@ -35,7 +35,7 @@ extension BitArray { count: Int, at index: Int ) { - precondition(count >= 0, "Can't insert a negative number of values") + precondition(count >= 0, "Cannot add a negative number of items") precondition(index >= 0 && index <= count, "Index out of bounds") guard count > 0 else { return } _extend(by: count, with: false) @@ -44,7 +44,7 @@ extension BitArray { } public mutating func append(repeating value: Bool, count: Int) { - precondition(count >= 0, "Can't append a negative number of values") + precondition(count >= 0, "Cannot add a negative number of items") guard count > 0 else { return } _extend(by: count, with: value) } diff --git a/Sources/BitCollections/BitSet/BitSet+Extras.swift b/Sources/BitCollections/BitSet/BitSet+Extras.swift index 15b8a391..b4fcf3d5 100644 --- a/Sources/BitCollections/BitSet/BitSet+Extras.swift +++ b/Sources/BitCollections/BitSet/BitSet+Extras.swift @@ -66,7 +66,7 @@ extension BitSet { } set { guard let member = UInt(exactly: member) else { - precondition(!newValue, "Can't insert a negative value to a BitSet") + precondition(!newValue, "Cannot insert a negative value to a BitSet") return } if newValue { diff --git a/Sources/ContainersPreview/Protocols/Container.swift b/Sources/ContainersPreview/Protocols/Container.swift index c33df66e..9353948d 100644 --- a/Sources/ContainersPreview/Protocols/Container.swift +++ b/Sources/ContainersPreview/Protocols/Container.swift @@ -205,7 +205,7 @@ extension Container where Self: ~Copyable & ~Escapable { let span = self.nextSpan(after: &i, maximumCount: distance) precondition( !span.isEmpty, - "Can't advance index beyond the end of the container") + "Cannot advance index beyond the end of the container") distance &-= span.count } return i @@ -222,7 +222,7 @@ extension Container where Self: ~Copyable & ~Escapable { let span = self.nextSpan(after: &j) precondition( !span.isEmpty, - "Can't advance index beyond the end of the container") + "Cannot advance index beyond the end of the container") guard span.count <= distance else { break } i = j distance &-= span.count @@ -261,7 +261,7 @@ extension Container where Self: ~Copyable & ~Escapable { let span = self.nextSpan(after: &j, maximumCount: distance) precondition( !span.isEmpty, - "Can't advance index beyond the end of the container") + "Cannot advance index beyond the end of the container") if j > limit { break } @@ -284,7 +284,7 @@ extension Container where Self: ~Copyable & ~Escapable { let span = self.nextSpan(after: &j) precondition( !span.isEmpty, - "Can't advance index beyond the end of the container") + "Cannot advance index beyond the end of the container") guard span.count <= distance, j < limit else { break } diff --git a/Sources/ContainersPreview/Protocols/Drain.swift b/Sources/ContainersPreview/Protocols/Drain.swift index 60a6d7a9..938d0d74 100644 --- a/Sources/ContainersPreview/Protocols/Drain.swift +++ b/Sources/ContainersPreview/Protocols/Drain.swift @@ -203,7 +203,7 @@ extension Drain where Self: ~Copyable & ~Escapable { public mutating func skip( upTo n: inout Int ) throws(ProducerError) -> Bool { - precondition(n >= 0, "Can't skip a negative number of elements") + precondition(n >= 0, "Cannot skip a negative number of elements") guard n > 0 else { return true } let span = drainNext(maximumCount: n) let success = span.count > 0 diff --git a/Sources/ContainersPreview/Protocols/Producer.swift b/Sources/ContainersPreview/Protocols/Producer.swift index c80ef53d..59f17608 100644 --- a/Sources/ContainersPreview/Protocols/Producer.swift +++ b/Sources/ContainersPreview/Protocols/Producer.swift @@ -200,7 +200,7 @@ extension Producer where Self: ~Copyable & ~Escapable { @inlinable @_lifetime(self: copy self) public mutating func skip(upTo n: inout Int) throws(ProducerError) -> Bool { - precondition(n > 0, "Can't skip less than 1 item") + precondition(n > 0, "Cannot skip fewer than one item") let maxBufferSize = 8 return try withTemporaryOutputSpan( of: Element.self, capacity: Swift.min(maxBufferSize, n) diff --git a/Sources/ContainersPreview/Types/InputSpan.swift b/Sources/ContainersPreview/Types/InputSpan.swift index e9bc58c6..0d9b125f 100644 --- a/Sources/ContainersPreview/Types/InputSpan.swift +++ b/Sources/ContainersPreview/Types/InputSpan.swift @@ -335,7 +335,7 @@ extension InputSpan where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(self: copy self) public mutating func removeFirst(_ k: Int) { - precondition(k >= 0, "Can't remove a negative number of elements") + precondition(k >= 0, "Cannot remove a negative number of elements") precondition(k <= _count, "InputSpan underflow") unsafe _unsafeRawAddressOfSlot( uncheckedOffset: 0 diff --git a/Sources/DequeModule/Deque/Deque+Collection.swift b/Sources/DequeModule/Deque/Deque+Collection.swift index 3c469485..1cbfcde5 100644 --- a/Sources/DequeModule/Deque/Deque+Collection.swift +++ b/Sources/DequeModule/Deque/Deque+Collection.swift @@ -757,8 +757,7 @@ extension Deque: RangeReplaceableCollection { /// this reduces the complexity to amortized O(1). @inlinable public mutating func insert(_ newElement: Element, at index: Int) { - precondition(index >= 0 && index <= count, - "Can't insert element at invalid index") + precondition(index >= 0 && index <= count, "Index out of bounds") _storage.ensureUnique(minimumCapacity: count + 1) _storage.update { target in if index == 0 { @@ -797,8 +796,7 @@ extension Deque: RangeReplaceableCollection { contentsOf newElements: __owned some Collection, at index: Int ) { - precondition(index >= 0 && index <= count, - "Can't insert elements at an invalid index") + precondition(index >= 0 && index <= count, "Index out of bounds") let newCount = newElements.count _storage.ensureUnique(minimumCapacity: count + newCount) _storage.update { target in @@ -865,8 +863,8 @@ extension Deque: RangeReplaceableCollection { @inlinable public mutating func _customRemoveLast(_ n: Int) -> Bool { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in the Collection") + precondition(n >= 0, "Cannot remove a negative number of elements") + precondition(n <= count, "Cannot remove more elements than there are in the Collection") _storage.ensureUnique() _storage.update { $0.uncheckedRemoveLast(n) } return true @@ -898,8 +896,8 @@ extension Deque: RangeReplaceableCollection { /// O(`count`). @inlinable public mutating func removeFirst(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in the Collection") + precondition(n >= 0, "Cannot remove a negative number of elements") + precondition(n <= count, "Cannot remove more elements than there are in the Collection") _storage.ensureUnique() return _storage.update { $0.uncheckedRemoveFirst(n) } } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index e569b630..a402fe96 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -99,7 +99,7 @@ extension RigidDeque where Element: ~Copyable { initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { precondition(index >= 0 && index <= self.count, "Index out of bounds") - precondition(maximumCount >= 0, "Cannot insert a negative number of items") + precondition(maximumCount >= 0, "Cannot add a negative number of items") precondition(maximumCount <= freeCapacity, "RigidDeque capacity overflow") try _handle.uncheckedInsert( maximumCount: maximumCount, at: index, initializingWith: body) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift index ef0efb8a..a5fdf033 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Removals.swift @@ -85,8 +85,8 @@ extension RigidDeque where Element: ~Copyable { /// - Complexity: O(`k`) @_alwaysEmitIntoClient public mutating func removeFirst(_ k: Int) { - precondition(k >= 0, "Can't remove a negative number of elements") - precondition(k <= count, "Can't remove more elements than there are in a RigidDeque") + precondition(k >= 0, "Cannot remove a negative number of elements") + precondition(k <= count, "Cannot remove more elements than there are in the container") _handle.uncheckedRemoveFirst(k) } @@ -103,8 +103,8 @@ extension RigidDeque where Element: ~Copyable { /// - Complexity: O(`k`) @_alwaysEmitIntoClient public mutating func removeLast(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in a RigidDeque") + precondition(n >= 0, "Cannot remove a negative number of elements") + precondition(n <= count, "Cannot remove more elements than there are in the container") _handle.uncheckedRemoveLast(n) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index 475ae2c8..174903d1 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -136,7 +136,7 @@ extension RigidDeque where Element: ~Copyable { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - precondition(maximumCount >= 0, "Can't insert a negative number of items") + precondition(maximumCount >= 0, "Cannot add a negative number of items") precondition( count - subrange.count + maximumCount <= capacity, "RigidDeque capacity overflow") diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift index e8c438b3..1c981db0 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift @@ -103,7 +103,7 @@ extension UniqueDeque where Element: ~Copyable { initializingWith body: (inout OutputSpan) throws(E) -> Void ) throws(E) { precondition(index >= 0 && index <= self.count, "Index out of bounds") - precondition(maximumCount >= 0, "Cannot insert a negative number of items") + precondition(maximumCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(maximumCount) try _storage._handle.uncheckedInsert( maximumCount: maximumCount, at: index, initializingWith: body) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift index 186d20a3..bacfd983 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift @@ -69,7 +69,7 @@ extension UniqueDeque where Element: ~Copyable { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - precondition(maximumCount >= 0, "Can't insert a negative number of items") + precondition(maximumCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(maximumCount - subrange.count) try _storage._handle.uncheckedReplaceSubrange( subrange, @@ -136,7 +136,7 @@ extension UniqueDeque where Element: ~Copyable { precondition( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - precondition(maximumCount >= 0, "Can't insert a negative number of items") + precondition(maximumCount >= 0, "Cannot add a negative number of items") _ensureFreeCapacity(maximumCount - subrange.count) try _storage._handle.uncheckedReplaceSubrange( subrange, diff --git a/Sources/DequeModule/_UnsafeDequeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift index c3c4cdde..89416880 100644 --- a/Sources/DequeModule/_UnsafeDequeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -1385,7 +1385,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { assert( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - assert(newCount >= 0, "Negative count") + assert(newCount >= 0, "Cannot add a negative number of items") assert(count + newCount - subrange.count <= capacity, "RigidDeque capacity overflow") self.mutableSegments(forOffsets: subrange).deinitialize() try _insertAfterReplace(subrange, newCount: newCount, initializingWith: initializer) @@ -1402,7 +1402,7 @@ extension _UnsafeDequeHandle where Element: ~Copyable { assert( subrange.lowerBound >= 0 && subrange.upperBound <= count, "Subrange out of bounds") - assert(newCount >= 0, "Negative count") + assert(newCount >= 0, "Cannot add a negative number of items") assert(count + newCount - subrange.count <= capacity, "RigidDeque capacity overflow") do { let removed = self.mutableSegments(forOffsets: subrange) diff --git a/Sources/HashTreeCollections/TreeDictionary/TreeDictionary+Collection.swift b/Sources/HashTreeCollections/TreeDictionary/TreeDictionary+Collection.swift index a3012eb3..06ea6bcd 100644 --- a/Sources/HashTreeCollections/TreeDictionary/TreeDictionary+Collection.swift +++ b/Sources/HashTreeCollections/TreeDictionary/TreeDictionary+Collection.swift @@ -159,7 +159,7 @@ extension TreeDictionary: Collection { @inlinable public subscript(i: Index) -> Element { precondition(_isValid(i), "Invalid index") - precondition(i._path.isOnItem, "Can't get element at endIndex") + precondition(i._path.isOnItem, "Cannot get element at endIndex") return _UnsafeHandle.read(i._path.node) { $0[item: i._path.currentItemSlot] } diff --git a/Sources/HashTreeCollections/TreeDictionary/TreeDictionary.swift b/Sources/HashTreeCollections/TreeDictionary/TreeDictionary.swift index 5152e1bf..02795f9b 100644 --- a/Sources/HashTreeCollections/TreeDictionary/TreeDictionary.swift +++ b/Sources/HashTreeCollections/TreeDictionary/TreeDictionary.swift @@ -542,7 +542,7 @@ extension TreeDictionary { @inlinable public mutating func remove(at index: Index) -> Element { precondition(_isValid(index), "Invalid index") - precondition(index._path._isItem, "Can't remove item at end index") + precondition(index._path._isItem, "Cannot remove item at end index") _invalidateIndices() let r = _root.remove(.top, at: index._path) assert(r.remainder == nil) diff --git a/Sources/HashTreeCollections/TreeSet/TreeSet+Collection.swift b/Sources/HashTreeCollections/TreeSet/TreeSet+Collection.swift index b0a8f72d..8e36ad51 100644 --- a/Sources/HashTreeCollections/TreeSet/TreeSet+Collection.swift +++ b/Sources/HashTreeCollections/TreeSet/TreeSet+Collection.swift @@ -159,7 +159,7 @@ extension TreeSet: Collection { @inlinable public subscript(position: Index) -> Element { precondition(_isValid(position), "Invalid index") - precondition(position._path.isOnItem, "Can't get element at endIndex") + precondition(position._path.isOnItem, "Cannot get element at endIndex") return _UnsafeHandle.read(position._path.node) { $0[item: position._path.currentItemSlot].key } diff --git a/Sources/HashTreeCollections/TreeSet/TreeSet+Extras.swift b/Sources/HashTreeCollections/TreeSet/TreeSet+Extras.swift index f02ac45f..f8325a5f 100644 --- a/Sources/HashTreeCollections/TreeSet/TreeSet+Extras.swift +++ b/Sources/HashTreeCollections/TreeSet/TreeSet+Extras.swift @@ -56,7 +56,7 @@ extension TreeSet { public mutating func update(_ member: Element, at index: Index) -> Element { defer { _fixLifetime(self) } precondition(_isValid(index), "Invalid index") - precondition(index._path.isOnItem, "Can't get element at endIndex") + precondition(index._path.isOnItem, "Cannot get element at endIndex") _invalidateIndices() return _UnsafeHandle.update(index._path.node) { let p = $0.itemPtr(at: index._path.currentItemSlot) diff --git a/Sources/InternalCollectionsUtilities/Span+Extras.swift b/Sources/InternalCollectionsUtilities/Span+Extras.swift index b1994564..0a94740c 100644 --- a/Sources/InternalCollectionsUtilities/Span+Extras.swift +++ b/Sources/InternalCollectionsUtilities/Span+Extras.swift @@ -16,7 +16,7 @@ extension Span where Element: ~Copyable { @_lifetime(copy self) @_alwaysEmitIntoClient package mutating func _trim(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init() } let result = self.extracting(first: cut) @@ -27,7 +27,7 @@ extension Span where Element: ~Copyable { @_lifetime(copy self) @_alwaysEmitIntoClient package mutating func _trim(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") + precondition(maxLength >= 0, "Cannot have a suffix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init() } let result = self.extracting(last: cut) diff --git a/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift b/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift index 5fc44ca9..07d205af 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift @@ -331,7 +331,7 @@ extension _UnsafeBitSet: BidirectionalCollection { } while w.isEmpty { word -= 1 - precondition(word >= 0, "Can't advance below startIndex") + precondition(word >= 0, "Cannot advance below startIndex") w = _words[word] } return Index(word: word, bit: w.lastMember!) diff --git a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift index 849dbb98..ce2e1895 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift @@ -60,7 +60,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let newCount = Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) } @@ -83,7 +83,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(droppingFirst maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let cut = Swift.min(maxLength, count) return Self(start: baseAddress?.advanced(by: cut), count: count &- cut) } @@ -106,7 +106,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") + precondition(maxLength >= 0, "Cannot have a suffix of negative length") let newCount = Swift.min(maxLength, count) return extracting(Range(uncheckedBounds: (count - newCount, count))) } @@ -129,7 +129,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(droppingLast maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let newCount = count &- Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) } @@ -139,7 +139,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient package mutating func _trim(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init(start: nil, count: 0) } let oldStart = baseAddress.unsafelyUnwrapped @@ -149,7 +149,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient package mutating func _trim(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") + precondition(maxLength >= 0, "Cannot have a suffix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init(start: nil, count: 0) } self = .init(start: baseAddress, count: count &- cut) diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift index 6c974ebc..3b0ded25 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift @@ -63,7 +63,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let newCount = Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) } @@ -86,7 +86,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(droppingFirst maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let cut = Swift.min(maxLength, count) return Self(start: baseAddress?.advanced(by: cut), count: count &- cut) } @@ -109,7 +109,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") + precondition(maxLength >= 0, "Cannot have a suffix of negative length") let newCount = Swift.min(maxLength, count) return extracting(Range(uncheckedBounds: (count - newCount, count))) } @@ -132,7 +132,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package func _extracting(droppingLast maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let newCount = count &- Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) } @@ -142,7 +142,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package mutating func _trim(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") + precondition(maxLength >= 0, "Cannot have a prefix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init(start: nil, count: 0) } let oldStart = baseAddress.unsafelyUnwrapped @@ -153,7 +153,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { @_alwaysEmitIntoClient @inline(__always) package mutating func _trim(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") + precondition(maxLength >= 0, "Cannot have a suffix of negative length") let cut = Swift.min(maxLength, count) guard cut > 0 else { return .init(start: nil, count: 0) } self = .init(start: baseAddress, count: count &- cut) diff --git a/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Partial RangeReplaceableCollection.swift b/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Partial RangeReplaceableCollection.swift index 603319bf..cbca5f45 100644 --- a/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Partial RangeReplaceableCollection.swift +++ b/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Partial RangeReplaceableCollection.swift @@ -121,8 +121,8 @@ extension OrderedDictionary { /// high-quality hashing. @inlinable public mutating func removeLast(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in the collection") + precondition(n >= 0, "Cannot remove a negative number of items") + precondition(n <= count, "Cannot remove more elements than there are in the collection") _keys.removeLast(n) _values.removeLast(n) } @@ -152,8 +152,8 @@ extension OrderedDictionary { /// - Complexity: O(`count`). @inlinable public mutating func removeFirst(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in the collection") + precondition(n >= 0, "Cannot remove a negative number of elements") + precondition(n <= count, "Cannot remove more elements than there are in the collection") _keys.removeFirst(n) _values.removeFirst(n) } diff --git a/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial RangeReplaceableCollection.swift b/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial RangeReplaceableCollection.swift index bb8900f1..ea560e88 100644 --- a/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial RangeReplaceableCollection.swift +++ b/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial RangeReplaceableCollection.swift @@ -157,7 +157,7 @@ extension OrderedSet { /// high-quality hashing. @inlinable public mutating func removeLast(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") + precondition(n >= 0, "Cannot remove a negative number of items") precondition(n <= count, "Can't remove more elements than there are in the collection") removeSubrange(count - n ..< count) } @@ -171,7 +171,7 @@ extension OrderedSet { @inlinable @discardableResult public mutating func removeFirst() -> Element { - precondition(!isEmpty, "Cannot remove first element of an empty collection") + precondition(!isEmpty, "Cannot remove first item of an empty collection") return remove(at: startIndex) } @@ -187,8 +187,8 @@ extension OrderedSet { /// - Complexity: O(`count`). @inlinable public mutating func removeFirst(_ n: Int) { - precondition(n >= 0, "Can't remove a negative number of elements") - precondition(n <= count, "Can't remove more elements than there are in the collection") + precondition(n >= 0, "Cannot remove a negative number of items") + precondition(n <= count, "Cannot remove more elements than there are in the collection") removeSubrange(0 ..< n) } diff --git a/Sources/RopeModule/BigString/Basics/BigString+Contents.swift b/Sources/RopeModule/BigString/Basics/BigString+Contents.swift index 3a998789..2553f5ab 100644 --- a/Sources/RopeModule/BigString/Basics/BigString+Contents.swift +++ b/Sources/RopeModule/BigString/Basics/BigString+Contents.swift @@ -267,7 +267,7 @@ extension BigString { } func _utf8Index(after i: Index) -> Index { - precondition(i < endIndex, "Can't advance above end index") + precondition(i < endIndex, "Cannot advance above end index") let i = resolve(i, preferEnd: false) let ri = i._rope! var ci = i._chunkIndex @@ -299,7 +299,7 @@ extension BigString { } func _utf8Index(before i: Index) -> Index { - precondition(i > startIndex, "Can't advance below start index") + precondition(i > startIndex, "Cannot advance below start index") let i = resolve(i, preferEnd: true) var ri = i._rope! let ci = i._chunkIndex diff --git a/Sources/RopeModule/BigString/Conformances/BigString+RangeReplaceableCollection.swift b/Sources/RopeModule/BigString/Conformances/BigString+RangeReplaceableCollection.swift index ed02eeac..2e6f16c9 100644 --- a/Sources/RopeModule/BigString/Conformances/BigString+RangeReplaceableCollection.swift +++ b/Sources/RopeModule/BigString/Conformances/BigString+RangeReplaceableCollection.swift @@ -105,7 +105,7 @@ extension BigString: RangeReplaceableCollection { } public init(repeating value: Self, count: Int) { - precondition(count >= 0, "Negative count") + precondition(count >= 0, "Cannot add a negative number of items") guard count > 0 else { self.init() return diff --git a/Sources/RopeModule/BigString/Views/BigSubstring+UTF16View.swift b/Sources/RopeModule/BigString/Views/BigSubstring+UTF16View.swift index c1750bc5..231bdb12 100644 --- a/Sources/RopeModule/BigString/Views/BigSubstring+UTF16View.swift +++ b/Sources/RopeModule/BigString/Views/BigSubstring+UTF16View.swift @@ -145,13 +145,13 @@ extension BigSubstring.UTF16View: BidirectionalCollection { @inline(__always) public func index(after i: Index) -> Index { - precondition(i < endIndex, "Can't advance above end index") + precondition(i < endIndex, "Cannot advance above end index") return _base._utf16Index(after: i) } @inline(__always) public func index(before i: Index) -> Index { - precondition(i > startIndex, "Can't advance below start index") + precondition(i > startIndex, "Cannot advance below start index") return _base._utf16Index(before: i) } diff --git a/Sources/RopeModule/BigString/Views/BigSubstring+UTF8View.swift b/Sources/RopeModule/BigString/Views/BigSubstring+UTF8View.swift index 996d78b0..8a4c1e2c 100644 --- a/Sources/RopeModule/BigString/Views/BigSubstring+UTF8View.swift +++ b/Sources/RopeModule/BigString/Views/BigSubstring+UTF8View.swift @@ -117,13 +117,13 @@ extension BigSubstring.UTF8View: BidirectionalCollection { @inline(__always) public func index(after i: Index) -> Index { - precondition(i < endIndex, "Can't advance above end index") + precondition(i < endIndex, "Cannot advance above end index") return _base._utf8Index(after: i) } @inline(__always) public func index(before i: Index) -> Index { - precondition(i > startIndex, "Can't advance below start index") + precondition(i > startIndex, "Cannot advance below start index") return _base._utf8Index(before: i) } diff --git a/Sources/RopeModule/BigString/Views/BigSubstring+UnicodeScalarView.swift b/Sources/RopeModule/BigString/Views/BigSubstring+UnicodeScalarView.swift index 44238691..7e3057a5 100644 --- a/Sources/RopeModule/BigString/Views/BigSubstring+UnicodeScalarView.swift +++ b/Sources/RopeModule/BigString/Views/BigSubstring+UnicodeScalarView.swift @@ -147,13 +147,13 @@ extension BigSubstring.UnicodeScalarView: BidirectionalCollection { @inline(__always) public func index(after i: Index) -> Index { - precondition(i < endIndex, "Can't advance above end index") + precondition(i < endIndex, "Cannot advance above end index") return _base._unicodeScalarIndex(after: i) } @inline(__always) public func index(before i: Index) -> Index { - precondition(i > startIndex, "Can't advance below start index") + precondition(i > startIndex, "Cannot advance below start index") return _base._unicodeScalarIndex(before: i) } diff --git a/Sources/RopeModule/BigString/Views/BigSubstring.swift b/Sources/RopeModule/BigString/Views/BigSubstring.swift index 3f05920d..a69fe4ee 100644 --- a/Sources/RopeModule/BigString/Views/BigSubstring.swift +++ b/Sources/RopeModule/BigString/Views/BigSubstring.swift @@ -174,13 +174,13 @@ extension BigSubstring: BidirectionalCollection { @inline(__always) public func index(after i: Index) -> Index { - precondition(i < endIndex, "Can't advance above end index") + precondition(i < endIndex, "Cannot advance above end index") return _base.index(after: i) } @inline(__always) public func index(before i: Index) -> Index { - precondition(i > startIndex, "Can't advance below start index") + precondition(i > startIndex, "Cannot advance below start index") return _base.index(before: i) } diff --git a/Sources/RopeModule/Rope/Conformances/Rope+Collection.swift b/Sources/RopeModule/Rope/Conformances/Rope+Collection.swift index 2414baed..ea507bbe 100644 --- a/Sources/RopeModule/Rope/Conformances/Rope+Collection.swift +++ b/Sources/RopeModule/Rope/Conformances/Rope+Collection.swift @@ -92,7 +92,7 @@ extension Rope: BidirectionalCollection { @inlinable public func formIndex(after i: inout Index) { validate(i) - precondition(i < endIndex, "Can't move after endIndex") + precondition(i < endIndex, "Cannot advance above endIndex") if let leaf = i._leaf { let done = leaf.read { let slot = i._path[$0.height] &+ 1 @@ -110,7 +110,7 @@ extension Rope: BidirectionalCollection { @inlinable public func formIndex(before i: inout Index) { validate(i) - precondition(i > startIndex, "Can't move before startIndex") + precondition(i > startIndex, "Cannot advance below startIndex") if let leaf = i._leaf { let done = leaf.read { let slot = i._path[$0.height] diff --git a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift index e175b426..8c75cd95 100644 --- a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift +++ b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift @@ -380,7 +380,7 @@ class OrderedSetTests: CollectionTestCase { expectEqual(set[index], count) expectEqualElements(set[.. MinimalIndex { assertValidIndex(index) expectTrue(index._offset < count, - "Can't advance beyond endIndex", + "Cannot advance beyond endIndex", trapping: true) return self.index(at: index._offset + 1) } @@ -132,7 +132,7 @@ extension _MinimalCollectionCore { func index(before index: MinimalIndex) -> MinimalIndex { assertValidIndex(index) expectTrue(index._offset > 0, - "Can't advance before startIndex", + "Cannot advance before startIndex", trapping: true) return self.index(at: index._offset - 1) } @@ -140,7 +140,7 @@ extension _MinimalCollectionCore { func formIndex(after index: inout MinimalIndex) { assertValidIndex(index) expectTrue(index._offset < count, - "Can't advance beyond endIndex", + "Cannot advance beyond endIndex", trapping: true) index._offset += 1 } @@ -148,7 +148,7 @@ extension _MinimalCollectionCore { func formIndex(before index: inout MinimalIndex) { assertValidIndex(index) expectTrue(index._offset > 0, - "Can't advance before startIndex", + "Cannot advance before startIndex", trapping: true) index._offset -= 1 } @@ -165,10 +165,10 @@ extension _MinimalCollectionCore { ) -> MinimalIndex { assertValidIndex(index) expectTrue(index._offset + n >= 0, - "Can't advance before startIndex", + "Cannot advance before startIndex", trapping: true) expectTrue(index._offset + n <= count, - "Can't advance after endIndex", + "Cannot advance after endIndex", trapping: true) return self.index(at: index._offset + n) } @@ -291,7 +291,7 @@ extension _MinimalCollectionCore { mutating func removeFirst() -> Element { expectTrue( count > 0, - "Can't remove first element of an empty collection", + "Cannot remove first element of an empty collection", trapping: true) ensureUniqueState() state.remove(count: 1, at: 0) @@ -301,11 +301,11 @@ extension _MinimalCollectionCore { mutating func removeFirst(_ n: Int) { expectTrue( n >= 0, - "Can't remove a negative number of elements", + "Cannot remove a negative number of elements", trapping: true) expectTrue( n <= count, - "Can't remove more elements than there are in the collection", + "Cannot remove more elements than there are in the collection", trapping: true) ensureUniqueState() state.remove(count: n, at: 0) @@ -315,7 +315,7 @@ extension _MinimalCollectionCore { public mutating func _customRemoveLast() -> Element? { expectTrue( !isEmpty, - "Can't remove last element of an empty collection", + "Cannot remove last element of an empty collection", trapping: true) ensureUniqueState() state.remove(count: 1, at: state.count) @@ -325,11 +325,11 @@ extension _MinimalCollectionCore { public mutating func _customRemoveLast(_ n: Int) -> Bool { expectTrue( n >= 0, - "Can't remove a negative number of elements", + "Cannot remove a negative number of elements", trapping: true) expectTrue( count >= n, - "Can't remove more elements than there are in the collection", + "Cannot remove more elements than there are in the collection", trapping: true) elements.removeLast(n) ensureUniqueState()