Skip to content

Commit 3f2655e

Browse files
authored
Add a comment to UnsafePointer assignment. (#4070)
Initializing trivial types via assignment is allowed by convention, so make it official.
1 parent 1a08f52 commit 3f2655e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

stdlib/public/core/UnsafePointer.swift.gyb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ public struct ${Self}<Pointee>
157157

158158
/// Accesses the `Pointee` instance referenced by `self`.
159159
///
160-
/// - Precondition: the pointee has been initialized with an instance of
161-
/// type `Pointee`.
160+
/// - Precondition: Either the pointee has been initialized with an
161+
/// instance of type `Pointee`, or `pointee` is being assigned to
162+
/// and `Pointee` is a trivial type.
162163
public var pointee: Pointee {
163164
% if mutable:
164165
@_transparent unsafeAddress {
@@ -212,8 +213,11 @@ public struct ${Self}<Pointee>
212213
///
213214
/// - Precondition: `count >= 0`
214215
///
215-
/// - Precondition: The `Pointee`s at `self..<self + count` and
216-
/// `source..<source + count` are initialized.
216+
/// - Precondition: The `Pointee`s at `source..<source + count` are
217+
/// initialized.
218+
///
219+
/// - Precondition: Either the `Pointee`s at `self..<self + count`
220+
/// are initialized, or `Pointee` is a trivial type.
217221
public func assign(from source: UnsafePointer<Pointee>, count: Int) {
218222
_debugPrecondition(
219223
count >= 0, "${Self}.assign with negative count")
@@ -380,7 +384,9 @@ public struct ${Self}<Pointee>
380384

381385
/// Accesses the pointee at `self + i`.
382386
///
383-
/// - Precondition: the pointee at `self + i` is initialized.
387+
/// - Precondition: Either the pointee at `self + i` is initialized, or the
388+
/// subscript is the left side of an assignment and `Pointee` is a trivial
389+
/// type.
384390
public subscript(i: Int) -> Pointee {
385391
% if mutable:
386392
@_transparent

0 commit comments

Comments
 (0)