Skip to content

Commit b7b75ae

Browse files
committed
[stdlib] Generalize Optional.unsafelyUnwrapped
1 parent cf35c65 commit b7b75ae

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

stdlib/public/core/Optional.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ extension Optional where Wrapped: ~Copyable {
324324
}
325325
}
326326

327-
extension Optional {
327+
extension Optional where Wrapped: ~Escapable {
328328
/// The wrapped value of this instance, unwrapped without checking whether
329329
/// the instance is `nil`.
330330
///
@@ -349,6 +349,7 @@ extension Optional {
349349
/// will never be equal to `nil` and only after you've tried using the
350350
/// postfix `!` operator.
351351
@inlinable
352+
@_preInverseGenerics
352353
@unsafe
353354
public var unsafelyUnwrapped: Wrapped {
354355
@inline(__always)
@@ -361,7 +362,7 @@ extension Optional {
361362
}
362363
}
363364

364-
extension Optional where Wrapped: ~Copyable {
365+
extension Optional where Wrapped: ~Copyable & ~Escapable {
365366
// FIXME(NCG): Do we want this? It seems like we do. Make this public.
366367
@_alwaysEmitIntoClient
367368
public consuming func _consumingUnsafelyUnwrap() -> Wrapped {
@@ -374,12 +375,13 @@ extension Optional where Wrapped: ~Copyable {
374375
}
375376
}
376377

377-
extension Optional {
378+
extension Optional where Wrapped: ~Escapable {
378379
/// - Returns: `unsafelyUnwrapped`.
379380
///
380381
/// This version is for internal stdlib use; it avoids any checking
381382
/// overhead for users, even in Debug builds.
382383
@inlinable
384+
@_preInverseGenerics
383385
internal var _unsafelyUnwrappedUnchecked: Wrapped {
384386
@inline(__always)
385387
get {

0 commit comments

Comments
 (0)