[DequeModule] Make UniqueDeque Iterable without ContainersPreview

842f125c removed the trait conditions around the Iterable APIs, but
UniqueDeque only got its conformance through Container in ContainersPreview.
RigidDeque had no underestimatedCount, so it was 0 through Iterable.
This commit is contained in:
Tolga Unal committed 2026-11-05 09:09:48 -05:00
1 parent ed857ee877
commit 68fd4f2cc8
4 files changed
+45 -1

No files matched your search

@@ -80,6 +80,9 @@ extension RigidDeque: Iterable where Element: ~Copyable {
}
}
@inlinable
public var underestimatedCount: Int { count }
@_alwaysEmitIntoClient
@_lifetime(borrow self)
public borrowing func makeBorrowingIterator() -> BorrowingIterator {
@@ -14,9 +14,12 @@
#if compiler(>=6.4)
@available(SwiftStdlib 5.0, *)
extension UniqueDeque where Element: ~Copyable {
extension UniqueDeque: Iterable where Element: ~Copyable {
public typealias BorrowingIterator = RigidDeque<Element>.BorrowingIterator
@inlinable
public var underestimatedCount: Int { count }
@_alwaysEmitIntoClient
@_lifetime(borrow self)
public borrowing func makeBorrowingIterator() -> BorrowingIterator {
+19
View File
@@ -206,6 +206,25 @@ final class RigidDequeTests: CollectionTestCase {
}
}
@available(SwiftStdlib 6.4, *)
func test_iteration() {
func underestimatedCount<T: Iterable & ~Copyable>(of items: borrowing T) -> Int {
items.underestimatedCount
}
withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in
withLifetimeTracking { tracker in
let data = tracker.rigidDeque(with: layout)
expectEqual(underestimatedCount(of: data.deque), layout.count)
var i = 0
for item in data.deque {
expectEqual(item, data.contents[i])
i += 1
}
expectEqual(i, layout.count)
}
}
}
func test_subscriptMutate() {
withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in
withEvery("i", in: 0 ..< layout.count) { i in
+19
View File
@@ -187,6 +187,25 @@ final class UniqueDequeTests: CollectionTestCase {
}
}
@available(SwiftStdlib 6.4, *)
func test_iteration() {
func underestimatedCount<T: Iterable & ~Copyable>(of items: borrowing T) -> Int {
items.underestimatedCount
}
withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in
withLifetimeTracking { tracker in
let data = tracker.uniqueDeque(with: layout)
expectEqual(underestimatedCount(of: data.deque), layout.count)
var i = 0
for item in data.deque {
expectEqual(item, data.contents[i])
i += 1
}
expectEqual(i, layout.count)
}
}
}
func test_subscriptMutate() {
withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in
withEvery("i", in: 0 ..< layout.count) { i in