Skip to content

Commit 95a37e3

Browse files
lorenteyairspeedswift
authored andcommitted
[SE-0143] Amend to explicitly allow conditional conformances to Hashable (#808)
1 parent 4e1d873 commit 95a37e3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

proposals/0143-conditional-conformances.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,24 @@ extension ContiguousArray: Equatable where Element: Equatable { /*== already exi
304304
extension Dictionary: Equatable where Value: Equatable { /*== already exists */ }
305305
```
306306

307-
Note that `Set` is already (unconditionally) `Equatable`.
307+
In addition, implement conditional conformances to `Hashable` for the
308+
types above, as well as `Range` and `ClosedRange`:
309+
310+
```swift
311+
extension Optional: Hashable where Wrapped: Hashable { /*...*/ }
312+
extension Array: Hashable where Element: Hashable { /*...*/ }
313+
extension ArraySlice: Hashable where Element: Hashable { /*...*/ }
314+
extension ContiguousArray: Hashable where Element: Hashable { /*...*/ }
315+
extension Dictionary: Hashable where Value: Hashable { /*...*/ }
316+
extension Range: Hashable where Bound: Hashable { /*...*/ }
317+
extension ClosedRange: Hashable where Bound: Hashable { /*...*/ }
318+
```
319+
320+
While the standard library did not previously provide existing
321+
implementations of `hashValue` for these types, conditional `Hashable`
322+
conformance is a natural expectation for them.
323+
324+
Note that `Set` is already (unconditionally) `Equatable` and `Hashable`.
308325

309326
In addition, it is intended that the standard library adopt conditional conformance
310327
to collapse a number of "variants" of base types where other generic parameters

0 commit comments

Comments
 (0)