Skip to content

Commit 0e55d96

Browse files
committed
[stdlib] Generalize Optional.take(), ?? and nil comparisons
1 parent 84b6395 commit 0e55d96

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

stdlib/public/core/Optional.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ extension Optional where Wrapped: ~Copyable {
405405
}
406406
}
407407

408-
extension Optional where Wrapped: ~Copyable {
408+
extension Optional where Wrapped: ~Copyable & ~Escapable {
409409
/// Takes the wrapped value being stored in this instance and returns it while
410410
/// also setting the instance to `nil`. If there is no value being stored in
411411
/// this instance, this returns `nil` instead.
@@ -423,6 +423,7 @@ extension Optional where Wrapped: ~Copyable {
423423
/// - Returns: The wrapped value being stored in this instance. If this
424424
/// instance is `nil`, returns `nil`.
425425
@_alwaysEmitIntoClient
426+
@lifetime(self)
426427
public mutating func take() -> Self {
427428
let result = consume self
428429
self = nil
@@ -583,7 +584,7 @@ public struct _OptionalNilComparisonType: ExpressibleByNilLiteral {
583584
}
584585
}
585586

586-
extension Optional where Wrapped: ~Copyable {
587+
extension Optional where Wrapped: ~Copyable & ~Escapable {
587588
/// Returns a Boolean value indicating whether an argument matches `nil`.
588589
///
589590
/// You can use the pattern-matching operator (`~=`) to test whether an
@@ -806,7 +807,8 @@ extension Optional where Wrapped: ~Copyable {
806807
/// type as the `Wrapped` type of `optional`.
807808
@_transparent
808809
@_alwaysEmitIntoClient
809-
public func ?? <T: ~Copyable>(
810+
@lifetime(optional)
811+
public func ?? <T: ~Copyable & ~Escapable>(
810812
optional: consuming T?,
811813
defaultValue: @autoclosure () throws -> T // FIXME: typed throw
812814
) rethrows -> T {
@@ -877,8 +879,9 @@ internal func _legacy_abi_optionalNilCoalescingOperator <T>(
877879
/// `optional` have the same type.
878880
@_transparent
879881
@_alwaysEmitIntoClient
882+
@lifetime(optional)
880883
// FIXME: This needs to support typed throws.
881-
public func ?? <T: ~Copyable>(
884+
public func ?? <T: ~Copyable & ~Escapable>(
882885
optional: consuming T?,
883886
defaultValue: @autoclosure () throws -> T?
884887
) rethrows -> T? {

0 commit comments

Comments
 (0)