Skip to content

Commit 888e884

Browse files
authored
Merge pull request #73239 from amartini51/copyable_126377559_CP
Add reference for Copyable (Swift 6) 🍒 Cherry pick of #73238 Fixes: rdar://126377559
2 parents f184f19 + dd5f18d commit 888e884

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

stdlib/public/core/Misc.swift

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

172+
/// A type whose values can be implicitly or explicitly copied.
173+
///
174+
/// Conforming to this protocol indicates that a type's value can be copied;
175+
/// this protocol doesn’t have any required methods or properties.
176+
/// You don't generally need to write an explicit conformance to `Copyable`.
177+
/// The following places implicitly include `Copyable` conformance:
178+
///
179+
/// * Structure declarations,
180+
/// unless it has a noncopyable stored property
181+
/// * Enumeration declarations,
182+
/// unless it has a case whose associated value isn't copyable
183+
/// * Class declarations
184+
/// * Actor declarations
185+
/// * Protocol declarations
186+
/// * Associated type declarations
187+
/// * The `Self` type in a protocol extension
188+
/// * In an extension, the generic parameters of the type being extended
189+
///
190+
/// A class or actor can contain noncopyable stored properties,
191+
/// while still being copyable itself ---
192+
/// classes and actors are copied by retaining and releasing references.
193+
///
194+
/// In a declaration that includes generic type parameters,
195+
/// each generic type parameter implicitly includes `Copyable`
196+
/// in its list of requirements.
197+
/// Metatypes and tuples of copyable types are also implicitly copyable,
198+
/// as are boxed protocol types.
199+
/// For example,
200+
/// all of the following pairs of declarations are equivalent:
201+
///
202+
/// struct MyStructure { }
203+
/// struct MyStructere: Copyable { }
204+
///
205+
/// protocol MyProtocol { }
206+
/// protocol MyProtocol: Copyable { }
207+
///
208+
/// protocol AnotherProtocol {
209+
/// associatedtype MyType
210+
/// associatedtype MyType: Copyable
211+
/// }
212+
///
213+
/// func genericFunction<T>(t: T) { }
214+
/// func genericFunction<T>(t: T) where T: Copyable { }
215+
///
216+
/// let x: any MyProtocol
217+
/// let x: any MyProtocol & Copyable
218+
///
219+
/// To suppress an implicit conformance to `Copyable` you write `~Copyable`.
220+
/// For example,
221+
/// only copyable types can conform to `MyProtocol` in the example above,
222+
/// but both copyable and noncopyable types
223+
/// can conform `NoRequirements` in the example below:
224+
///
225+
/// protocol NoRequirements: ~Copyable { }
226+
///
227+
/// Extensions to the `Copyable` protocol are not allowed.
172228
@_marker public protocol Copyable {}
173229

174230
@_documentation(visibility: internal)

0 commit comments

Comments
 (0)