Skip to content

Commit 84d6372

Browse files
committed
Call out a tripping hazard & wordsmith a bit
1 parent 567a78b commit 84d6372

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

TSPL.docc/LanguageGuide/Generics.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,12 +1988,13 @@ types also implicitly conform to these common protocol.
19881988
For more information,
19891989
see <doc:Protocols#Implicit-Conformance-to-a-Protocol>.
19901990

1991-
To suppress an implicit constraint
1992-
that requires conformance to a given protocol,
1991+
To suppress an implicit constraint,
19931992
you write the protocol name with a tilde (`~`) in front of it.
1994-
You can read the `~Copyable` constraint as "maybe copyable",
1995-
because values of this type
1996-
can contain values of both copyable and noncopyable types.
1993+
You can read `~Copyable` as "maybe copyable" ---
1994+
this suppressed constraint allows
1995+
both copyable and noncopyable types in this position.
1996+
Note that `~Copyable` doesn't *require* the type to be noncopyable.
1997+
For example:
19971998

19981999
```swift
19992000
func f<MyType>(x: inout MyType) {
@@ -2011,10 +2012,12 @@ In the code above,
20112012
the function `f()` implicitly requires `MyType` to be copyable.
20122013
Within the function body,
20132014
the value of `x` is copied to `x1` and `x2` in the assignment.
2014-
In contrast, `g()` suppresses the implicit constraint,
2015-
which allows you to pass either a copyable or noncopyable type.
2015+
In contrast, `g()` suppresses the implicit constraint on `AnotherType`,
2016+
which allows you to pass either a copyable or noncopyable value.
20162017
Within the function body,
2017-
the value of `y` is consumed instead of copied,
2018+
you can't copy the value of `y`
2019+
because `AnotherType` might be noncopyable.
2020+
Assignment consumes the value of `y`
20182021
and it's an error to consume that value more than once.
20192022
Noncopyable values like `y`
20202023
must be passed as in-out, borrowing, or consuming parameters ---

0 commit comments

Comments
 (0)