diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift index b82f20c1..0c3a2f86 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift @@ -234,7 +234,9 @@ extension RigidArray where Element: ~Copyable { >( addingCount newItemCount: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try self.append(addingCount: newItemCount) { target throws(E) in while !target.isFull { guard try producer.generate(into: &target) else { break } @@ -261,7 +263,9 @@ extension RigidArray where Element: ~Copyable { P: Producer & ~Copyable & ~Escapable >( from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { var done = false while !done { try self.append(addingCount: freeCapacity) { target throws(E) in diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift index 6f49ce0c..0659c56d 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift @@ -304,7 +304,9 @@ extension RigidArray where Element: ~Copyable { addingCount newItemCount: Int, from producer: inout P, at index: Int - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try insert(addingCount: newItemCount, at: index) { target throws(E) in while !target.isFull, try producer.generate(into: &target) { // Do nothing diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift index 31166729..3d4ca72b 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift @@ -454,7 +454,9 @@ extension RigidArray where Element: ~Copyable { removing subrange: Range, addingCount newItemCount: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try replace( removing: subrange, addingCount: newItemCount diff --git a/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift b/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift index 14295eec..ab56c761 100644 --- a/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift +++ b/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift @@ -57,7 +57,9 @@ extension RigidSet where Element: ~Copyable { >( capacity: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { self.init(capacity: capacity) try self.insert(maximumCount: capacity, from: &producer) } diff --git a/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift b/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift index 30c8d907..c1917f64 100644 --- a/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift +++ b/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift @@ -173,7 +173,9 @@ extension RigidSet where Element: ~Copyable { >( maximumCount: Int? = nil, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try self.insert( maximumCount: maximumCount ?? freeCapacity ) { target throws(E) in diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift index a4351f5c..fb0ad0eb 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift @@ -206,7 +206,9 @@ extension UniqueArray where Element: ~Copyable { >( addingCount newItemCount: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { _ensureFreeCapacity(newItemCount) try _storage.append(addingCount: newItemCount, from: &producer) } @@ -230,7 +232,9 @@ extension UniqueArray where Element: ~Copyable { P: Producer & ~Copyable & ~Escapable >( from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { var done = false while !done { let c = Swift.max(producer.underestimatedCount, 1) diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift index 671d6c68..cd392666 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift @@ -267,7 +267,9 @@ extension UniqueArray where Element: ~Copyable { addingCount newItemCount: Int, from producer: inout P, at index: Int - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try insert(addingCount: newItemCount, at: index) { target throws(E) in while !target.isFull, try producer.generate(into: &target) { // Do nothing diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift index a2ccc71f..55c2f21a 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift @@ -392,7 +392,9 @@ extension UniqueArray where Element: ~Copyable { removing subrange: Range, addingCount newItemCount: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try replace(removing: subrange, addingCount: newItemCount) { target throws(E) in while !target.isFull, try producer.generate(into: &target) { // Do nothing diff --git a/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift b/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift index fd31b291..412cb406 100644 --- a/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift +++ b/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift @@ -57,7 +57,9 @@ extension UniqueSet where Element: ~Copyable { P: Producer & ~Copyable & ~Escapable >( minimumCapacity: Int? = nil, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { let c = producer.underestimatedCount if let minimumCapacity { self.init(minimumCapacity: Swift.min(minimumCapacity, c)) diff --git a/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift b/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift index 6963fe1f..d6aea3bc 100644 --- a/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift +++ b/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift @@ -86,7 +86,9 @@ extension UniqueSet where Element: ~Copyable { P: Producer & ~Copyable & ~Escapable >( from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { var done = false while !done { _ensureFreeCapacity(Swift.max(producer.underestimatedCount, 1)) diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift index 7c9c978f..8e359470 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift @@ -28,7 +28,9 @@ where Other: BorrowingSequence & ~Copyable & ~Escapable >( _ other: borrowing Other, - ) -> Bool { + ) -> Bool + where Other.Element: ~Copyable + { let it1 = self.makeBorrowingIterator() let it2 = other.makeBorrowingIterator() return it1.elementsEqual(it2) @@ -69,7 +71,9 @@ where >( _ other: borrowing Other, by areEquivalent: (borrowing Element, borrowing Other.Element) throws(E) -> Bool - ) throws(E) -> Bool { + ) throws(E) -> Bool + where Other.Element: ~Copyable + { let it1 = self.makeBorrowingIterator() let it2 = other.makeBorrowingIterator() return try it1.elementsEqual(it2, by: areEquivalent) @@ -87,7 +91,9 @@ where Other: BorrowingIteratorProtocol & ~Copyable & ~Escapable >( _ other: consuming Other, - ) -> Bool { + ) -> Bool + where Other.Element: ~Copyable + { var result = true _spanwiseZip(state: &result, with: other) { state, a, b in if a.isEmpty || b.isEmpty { @@ -111,7 +117,9 @@ where Other: BorrowingIteratorProtocol & ~Copyable & ~Escapable >( _ other: consuming Other, - ) -> Bool { + ) -> Bool + where Other.Element: ~Copyable + { #if true // FIXME: rdar://150228920 Exclusive access scopes aren't expanded enough // Note: This is the less efficient implementation of elementsEqual. The // variant in the #else branch would be preferable, but it doesn't work yet. @@ -179,7 +187,9 @@ where >( _ other: consuming Other, by areEquivalent: (borrowing Element, borrowing Other.Element) throws(E) -> Bool - ) throws(E) -> Bool { + ) throws(E) -> Bool + where Other.Element: ~Copyable + { var result = true try _spanwiseZip(state: &result, with: other) { state, a, b throws(E) in assert(a.count == b.count || a.isEmpty || b.isEmpty) diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift index ad19619c..f1af33a2 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift @@ -31,7 +31,9 @@ where state: inout State, with other: consuming Other, by process: (inout State, Span, Span) throws(E) -> Bool - ) throws(E) { + ) throws(E) + where Other.Element: ~Copyable + { #if true // FIXME: rdar://150228920 Exclusive access scopes aren't expanded enough // Note: This is the less efficient implementation of spanwiseZip. The // variant in the #else branch would be preferable, but it doesn't work yet. diff --git a/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift index 7a528b40..19a98fcc 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift @@ -61,6 +61,7 @@ where ) rethrows -> Bool where OtherSequence: ~Copyable & ~Escapable, OtherSequence.Element: ~Copyable { + // FIXME: Forward to the iterator's implementation of same var iter1 = makeBorrowingIterator() var iter2 = other.makeBorrowingIterator() while true { @@ -90,7 +91,11 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable & Equatable { @inlinable public func elementsEqual>( _ other: borrowing OtherSequence - ) -> Bool where OtherSequence: ~Copyable & ~Escapable { + ) -> Bool + where + OtherSequence: ~Copyable & ~Escapable, + OtherSequence.Element: ~Copyable + { return self.elementsEqual(other, by: ==) } } diff --git a/Sources/ContainersPreview/Protocols/Container/DynamicContainer.swift b/Sources/ContainersPreview/Protocols/Container/DynamicContainer.swift index 16972776..512934c4 100644 --- a/Sources/ContainersPreview/Protocols/Container/DynamicContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/DynamicContainer.swift @@ -48,7 +48,9 @@ extension DynamicContainer where Self: ~Copyable, Element: ~Copyable { >( minimumCapacity: Int? = nil, from producer: consuming P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { self.init(minimumCapacity: minimumCapacity ?? producer.underestimatedCount) try self.append(from: producer) } @@ -59,7 +61,9 @@ extension DynamicContainer where Self: ~Copyable, Element: ~Copyable { P: Producer & ~Copyable & ~Escapable >( from producer: consuming P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { while true { let c = Swift.max(producer.underestimatedCount, self.freeCapacity) try self.append(addingCount: c) { target throws(E) in diff --git a/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift b/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift index 236ff775..2c286b86 100644 --- a/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift @@ -149,7 +149,9 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable removing subrange: some RangeExpression2, addingCount: Int, from producer: inout P - ) throws(P.ProducerError) { + ) throws(P.ProducerError) + where P.Element: ~Copyable + { try replace( removing: subrange.relative(to: self), consumingWith: { _ in }, @@ -309,7 +311,9 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable addingCount newItemCount: Int, at index: Index, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try self.insert(addingCount: newItemCount, at: index) { target throws(E) in while !target.isFull, try producer.generate(into: &target) { } @@ -344,7 +348,9 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable { >( addingCount newItemCount: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try insert(addingCount: newItemCount, at: endIndex, from: &producer) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index b1d85280..71e0df20 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -204,7 +204,9 @@ extension RigidDeque where Element: ~Copyable { >( addingCount newItemCount: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try self.append(addingCount: newItemCount) { target throws(E) in while !target.isFull { guard try producer.generate(into: &target) else { break } @@ -229,7 +231,9 @@ extension RigidDeque where Element: ~Copyable { P: Producer & ~Copyable & ~Escapable >( from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { var done = false try self.append( addingCount: freeCapacity diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift index d654663f..ba902590 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift @@ -90,7 +90,9 @@ extension RigidDeque where Element: ~Copyable { >( capacity: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { self.init(capacity: capacity) try self.append(from: &producer) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index a08d4125..5dd41bd5 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -245,7 +245,9 @@ extension RigidDeque where Element: ~Copyable { addingCount newItemCount: Int, from producer: inout P, at index: Int - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try insert(addingCount: newItemCount, at: index) { target throws(E) in while !target.isFull, try producer.generate(into: &target) { // Do nothing diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 9a2e6396..8c9671ac 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -215,7 +215,9 @@ extension RigidDeque where Element: ~Copyable { >( addingCount newItemCount: Int? = nil, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try self.prepend( addingCount: newItemCount ?? freeCapacity ) { target throws(E) in diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index 0d4f4060..5b8239db 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -325,7 +325,9 @@ extension RigidDeque where Element: ~Copyable { removing subrange: Range, addingCount newItemCount: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try replace( removing: subrange, addingCount: newItemCount diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift index ee0e2cb4..8f84ad3e 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift @@ -195,7 +195,9 @@ extension UniqueDeque where Element: ~Copyable { >( addingCount newItemCount: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { _ensureFreeCapacity(newItemCount) try _storage.append(addingCount: newItemCount, from: &producer) } @@ -219,7 +221,9 @@ extension UniqueDeque where Element: ~Copyable { P: Producer & ~Copyable & ~Escapable >( from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { var done = false while !done { let c = Swift.max(producer.underestimatedCount, 1) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift index f0bd5902..b75b3e6c 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift @@ -93,7 +93,9 @@ extension UniqueDeque where Element: ~Copyable { >( capacity: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { self.init(capacity: capacity) try self.append(addingCount: capacity, from: &producer) } @@ -113,7 +115,9 @@ extension UniqueDeque where Element: ~Copyable { P: Producer & ~Copyable & ~Escapable >( from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { self.init(capacity: producer.underestimatedCount) try self.append(from: &producer) } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift index 1d79cac8..a9b985c1 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift @@ -257,7 +257,9 @@ extension UniqueDeque where Element: ~Copyable { addingCount newItemCount: Int, from producer: inout P, at index: Int - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try insert(addingCount: newItemCount, at: index) { target throws(E) in while !target.isFull, try producer.generate(into: &target) { // Do nothing diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift index f5ab9eb7..565593c6 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift @@ -206,7 +206,9 @@ extension UniqueDeque where Element: ~Copyable { >( addingCount newItemCount: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { _ensureFreeCapacity(newItemCount) try _storage._handle.uncheckedPrepend( addingCount: newItemCount @@ -237,7 +239,9 @@ extension UniqueDeque where Element: ~Copyable { P: Producer & ~Copyable & ~Escapable >( from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { var done = false while !done { let c = Swift.max(producer.underestimatedCount, 1) diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift index 9cea87e6..9a276934 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift @@ -334,7 +334,9 @@ extension UniqueDeque where Element: ~Copyable { removing subrange: Range, addingCount newItemCount: Int, from producer: inout P - ) throws(E) { + ) throws(E) + where P.Element: ~Copyable + { try replace(removing: subrange, addingCount: newItemCount) { target throws(E) in while !target.isFull, try producer.generate(into: &target) { // Do nothing diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift index 5ceaa4c7..2846bc4b 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift @@ -136,7 +136,7 @@ public func expectIterablePayloads< trapping: Bool = false, file: StaticString = #filePath, line: UInt = #line -) { +) where E1.Element: ~Copyable { var it1 = left.makeBorrowingIterator() var it2 = right.makeIterator() var i = 0 @@ -230,7 +230,11 @@ public func expectIterablesWithEquivalentElements< trapping: Bool = false, file: StaticString = #filePath, line: UInt = #line -) { +) +where + S1.Element: ~Copyable, + S2.Element: ~Copyable +{ if left._elementsEqual(right, by: areEquivalent) { return } _expectFailure( "Containers do not have equivalent elements", @@ -250,7 +254,11 @@ public func expectIterablesWithEqualElements< trapping: Bool = false, file: StaticString = #filePath, line: UInt = #line -) { +) +where + S1.Element: ~Copyable, + S2.Element: ~Copyable +{ if left._elementsEqual(right) { return } _expectFailure( "Containers do not have equal elements", @@ -313,7 +321,7 @@ public func expectIterableContents< trapping: Bool = false, file: StaticString = #filePath, line: UInt = #line -) { +) where S1.Element: ~Copyable { var it1 = left.makeBorrowingIterator() var it2 = right.makeIterator() var offset = 0