Skip to content

Commit 325e033

Browse files
committed
Add initial reference for Copyable
Drawing from SE-0427.
1 parent 22919a9 commit 325e033

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

stdlib/public/core/Misc.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,54 @@ func _rethrowsViaClosure(_ fn: () throws -> ()) rethrows {
169169
try fn()
170170
}
171171

172+
/// A type whose values can be implicitly or explicitly copied.
173+
///
174+
/// XXX this protocol has no symbol requirements, but it does have semantic requirements
175+
///
176+
/// Conformance to the `Copyable` protocol
177+
/// is implicitly included in the following places:
178+
///
179+
/// * Structures declarations
180+
/// * Enumerations declarations
181+
/// * Class declarations
182+
/// * Protocol declarations
183+
/// * Associated type declarations
184+
/// * The `Self` type in a protocol extension
185+
///
186+
/// In a declaration that includes generic type parameters,
187+
/// each generic type parameter implicitly includes `Copyable`
188+
/// in its list of requirements.
189+
/// Metatypes and tuples of copyable types are also implicitly copyable.
190+
/// For example,
191+
/// all of the following pairs of declarations are equivalent:
192+
///
193+
/// ```swift
194+
/// struct MyStructure { }
195+
/// struct MyStructere: Copyable { }
196+
///
197+
/// protocol MyProtocol { }
198+
/// protocol MyProtocol: Copyable { }
199+
///
200+
/// XXX example of assoc type or Self
201+
///
202+
/// func genericFunction<T>(t: T) { }
203+
/// func genericFunction<T>(t: T) where T: Copyable { }
204+
/// ```
205+
///
206+
/// To suppress an implicit conformance to `Copyable`
207+
/// you write `~Copyable`.
208+
/// For example,
209+
/// only copyable types can conform to `MyProtocol` in the example above,
210+
/// but both copyable and noncopyable types
211+
/// can conform to the following protocol:
212+
///
213+
/// ```swift
214+
/// protocol NoRequirements: ~Copyable { }
215+
/// ```
216+
///
217+
/// Extensions on the `Copyable` protocol are not allowed.
218+
///
219+
/// XXX xref to TSPL
172220
@_marker public protocol Copyable {}
173221

174222
@_marker public protocol Escapable {}

0 commit comments

Comments
 (0)