Merge pull request #80003 from glessard/span-gardening

[stdlib] fix `Span`'s `Sendable` conformance
This commit is contained in:
Guillaume Lessard
2025-03-13 18:54:42 -07:00
committed by GitHub
2 changed files with 18 additions and 1 deletions

View File

@@ -84,7 +84,7 @@ public struct Span<Element: ~Copyable & ~Escapable>
}
@available(SwiftStdlib 6.2, *)
extension Span: @unchecked Sendable where Element: Sendable {}
extension Span: @unchecked Sendable where Element: Sendable & ~Copyable {}
@available(SwiftStdlib 6.2, *)
extension Span where Element: ~Copyable {

View File

@@ -589,3 +589,20 @@ suite.test("initialize from raw memory")
let first = test(span)
expectEqual(first, 0x07060504)
}
private func send(_: some Sendable & ~Escapable) {}
private struct NCSendable: ~Copyable, Sendable {}
suite.test("Span Sendability")
.require(.stdlib_6_2).code {
guard #available(SwiftStdlib 6.2, *) else { return }
let buffer = UnsafeMutableBufferPointer<NCSendable>.allocate(capacity: 1)
defer { buffer.deallocate() }
buffer.initializeElement(at: 0, to: NCSendable())
defer { buffer.deinitialize() }
let span = Span(_unsafeElements: buffer)
send(span)
}