Skip to content

Commit 805da6d

Browse files
committed
[stdlib] improve note about subscripts and initialization
1 parent 1f4ed8d commit 805da6d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
342342
/// }
343343
/// print(numbers)
344344
/// // Prints "[2, 1, 4, 3, 5]"
345+
///
346+
/// Uninitialized memory cannot be initialized to a nontrivial type
347+
/// using this subscript. Instead, use an initializing method, such as
348+
/// `initializeElement(at:to:)`
345349
%else:
346350
/// The following example uses the buffer pointer's subscript to access every
347351
/// other element of the buffer:

stdlib/public/core/UnsafePointer.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,9 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
694694
/// side of an assignment, the instance is updated. The instance must
695695
/// be initialized or this pointer's `Pointee` type must be a trivial type.
696696
///
697-
/// Do not update an instance of a nontrivial type through `pointee` to
698-
/// uninitialized memory. Instead, use an initializing method, such as
699-
/// `initialize(repeating:count:)`.
697+
/// Uninitialized memory cannot be initialized to a nontrivial type
698+
/// using `pointee`. Instead, use an initializing method, such as
699+
/// `initialize(to:)`.
700700
@inlinable // unsafe-performance
701701
public var pointee: Pointee {
702702
@_transparent unsafeAddress {
@@ -1096,9 +1096,9 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
10961096
/// side of an assignment, the memory at `p + i` is updated. The memory must
10971097
/// be initialized or the pointer's `Pointee` type must be a trivial type.
10981098
///
1099-
/// Do not update an instance of a nontrivial type through the subscript to
1100-
/// uninitialized memory. Instead, use an initializing method, such as
1101-
/// `initialize(repeating:count:)`.
1099+
/// Uninitialized memory cannot be initialized to a nontrivial type
1100+
/// using this subscript. Instead, use an initializing method, such as
1101+
/// `initialize(to:)`.
11021102
///
11031103
/// - Parameter i: The offset from this pointer at which to access an
11041104
/// instance, measured in strides of the pointer's `Pointee` type.

0 commit comments

Comments
 (0)