Skip to content

Commit 682c8ac

Browse files
committed
SE-0458: Bring back discussion of unsafe witnesses and how to acknowledge them
This was lost in my restructuring
1 parent 2ffa2d4 commit 682c8ac

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

proposals/0458-strict-memory-safety.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,30 @@ A type has unsafe storage if:
419419
* Any stored instance property (for `actor`, `class`, and `struct` types) or associated value (for cases of `enum` types) have a type that involves an unsafe type or conformance.
420420
* Any stored instance property uses one of the unsafe language features (such as `unowned(unsafe)`).
421421

422+
#### Unsafe witnesses
423+
424+
When a type conforms to a given protocol, it must satisfy all of the requirements of that protocol. Part of this process is determining which declaration (called the *witness*) satisfies a given protocol requirement. If a particular witness is unsafe but the corresponding requirement is not safe, the compiler will produce a warning:
425+
426+
```swift
427+
protocol P {
428+
func f()
429+
}
430+
431+
struct ConformsToP { }
432+
433+
extension ConformsToP: P {
434+
@unsafe func f() { } // warning: unsafe instance method 'f()' cannot satisfy safe requirement
435+
}
436+
```
437+
438+
This unsafety can be acknowledged by marking the conformance as `@unsafe`, e.g.,
439+
440+
```swift
441+
extension ConformsToP: @unsafe P {
442+
@unsafe func f() { } // okay, it's an unsafe conformance
443+
}
444+
```
445+
422446
#### Unsafe overrides
423447

424448
Overriding a safe method within an `@unsafe` one could introduce unsafety, so it will produce a diagnostic in the strict safety mode:

0 commit comments

Comments
 (0)