Skip to content

Commit 4096ca3

Browse files
committed
[stdlib] add missing Element type witnesses
With `NoncopyableGenerics` enabled, we currently lose some ability for associatedtype inference to find a suitable type witness based on a value witness. (rdar://118998138) The stdlib accidentally uses that inference for Sequence.Element, due to the default witness for `_customContainsEquatableElement` mentioning `Iterator.Element` whereas the requirement only states `Element`.
1 parent eff3255 commit 4096ca3

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

stdlib/public/core/Bitset.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ extension _UnsafeBitset.Word {
309309
// problems in normal use, because `next()` is usually called on a separate
310310
// iterator, not the original word.
311311
extension _UnsafeBitset.Word: Sequence, IteratorProtocol {
312+
313+
#if $NoncopyableGenerics
314+
@usableFromInline
315+
typealias Element = Int
316+
#endif
317+
312318
@inlinable
313319
internal var count: Int {
314320
return value.nonzeroBitCount

stdlib/public/core/ExistentialCollection.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,11 @@ internal struct _ClosureBasedSequence<Iterator: IteratorProtocol> {
12311231
}
12321232

12331233
extension _ClosureBasedSequence: Sequence {
1234+
1235+
#if $NoncopyableGenerics
1236+
public typealias Element = Iterator.Element
1237+
#endif
1238+
12341239
@inlinable
12351240
internal func makeIterator() -> Iterator {
12361241
return _makeUnderlyingIterator()

stdlib/public/core/Sequence.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,11 @@ public struct IteratorSequence<Base: IteratorProtocol> {
12411241
}
12421242

12431243
extension IteratorSequence: IteratorProtocol, Sequence {
1244+
1245+
#if $NoncopyableGenerics
1246+
public typealias Element = Base.Element
1247+
#endif
1248+
12441249
/// Advances to the next element and returns it, or `nil` if no next element
12451250
/// exists.
12461251
///

0 commit comments

Comments
 (0)