mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #80003 from glessard/span-gardening
[stdlib] fix `Span`'s `Sendable` conformance
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user