Skip to content

Commit d078734

Browse files
committed
[stdlib] InlineArray consumed by OutputSpan
1 parent 9f9565f commit d078734

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

stdlib/public/core/Span/OutputSpan.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,18 @@ extension OutputSpan where Element: ~Copyable {
398398
}
399399
}
400400

401+
@available(SwiftStdlib 6.2, *)
402+
extension OutputSpan where Element: BitwiseCopyable {
403+
//FIXME: We need this for Element: ~Copyable
404+
@_alwaysEmitIntoClient
405+
@lifetime(self: copy self)
406+
public mutating func append<let N: Int>(
407+
consuming source: consuming InlineArray<N, Element>
408+
) {
409+
source._consume { append(moving: &$0) }
410+
}
411+
}
412+
401413
@available(SwiftStdlib 6.2, *)
402414
extension OutputSpan where Element: ~Copyable {
403415
@_alwaysEmitIntoClient

test/stdlib/Span/OutputSpanTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,16 @@ suite.test("InlineArray initialization throws")
420420
}
421421
}
422422
#endif
423+
424+
suite.test("InlineArray consumed")
425+
.require(.stdlib_6_2).code {
426+
guard #available(SwiftStdlib 6.2, *) else { return }
427+
428+
let a: InlineArray<4, Int> = [1, 2, 3, 4]
429+
let b = Array(capacity: 20, initializingWith: {
430+
$0.append(consuming: a)
431+
})
432+
expectEqual(a.count, b.count)
433+
let i = a.indices.randomElement()!
434+
expectEqual(b[i], a[i])
435+
}

0 commit comments

Comments
 (0)