Skip to content

Commit 4e52796

Browse files
committed
Improve flow & re-adjust awkward wording
1 parent 64c1b20 commit 4e52796

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

TSPL.docc/LanguageGuide/Generics.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,23 +1957,17 @@ is a sequence of integers.
19571957

19581958
## Implicit Constraints
19591959

1960-
In addition to the constraints you write explicitly,
1961-
many places in your generic code
1962-
also include implicit constraints
1963-
that require types to conform to some very common protocols
1964-
like [`Copyable`][].
1965-
<!-- When SE-0446 is implemented, add Escapable above -->
1966-
For information on when a protocol is implied,
1967-
see the reference for that protocol.
1968-
1969-
[`Copyable`]: https://developer.apple.com/documentation/swift/copyable
1970-
1971-
These constraints are implicit because
1972-
almost all types in Swift conform to these protocols,
1973-
so you specify only the exceptions.
1960+
In addition to constraints you write explicitly,
1961+
many places in your generic code also implicitly require
1962+
conformance to some very common protocols like [`Copyable`][].
1963+
<!-- When SE-0446 is implemented, add Escapable above. -->
1964+
These generic constraints that you don't have to write
1965+
are known as *implicit constraints*.
19741966
For example, both of the following function declarations
19751967
require `MyType` to be copyable:
19761968

1969+
[`Copyable`]: https://developer.apple.com/documentation/swift/copyable
1970+
19771971
```swift
19781972
function someFunction<MyType> { ... }
19791973
function someFunction<MyType: Copyable> { ... }
@@ -1988,8 +1982,12 @@ types also implicitly conform to these common protocols.
19881982
For more information,
19891983
see <doc:Protocols#Implicit-Conformance-to-a-Protocol>.
19901984

1985+
Because most types in Swift conform to these protocols,
1986+
writing them almost everywhere would be repetitive.
1987+
Instead, by marking only the exceptions,
1988+
your call out the places that omit a common constraint.
19911989
To suppress an implicit constraint,
1992-
you write the protocol name with a tilde (`~`) in front of it.
1990+
write the protocol name with a tilde (`~`) in front of it.
19931991
You can read `~Copyable` as "maybe copyable" ---
19941992
this suppressed constraint allows
19951993
both copyable and noncopyable types in this position.
@@ -2024,6 +2022,10 @@ must be passed as in-out, borrowing, or consuming parameters ---
20242022
for more information,
20252023
see <doc:Declarations#Borrowing-and-Consuming-Parameters>.
20262024

2025+
For details about when generic code
2026+
includes an implicit constraint to a given protocol,
2027+
see the reference for that protocol.
2028+
20272029
<!--
20282030
TODO: Generic Enumerations
20292031
--------------------------

0 commit comments

Comments
 (0)