Skip to content

Commit 168047d

Browse files
Dave AbrahamsDave Abrahams
authored andcommitted
Deprecate the Indexable protocols
Using them is always a mistake; the user should choose the corresponding Collection protocol instead.
1 parent 441be73 commit 168047d

File tree

6 files changed

+18
-1
lines changed

6 files changed

+18
-1
lines changed

stdlib/public/core/BidirectionalCollection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/// In most cases, it's best to ignore this protocol and use the
1717
/// `BidirectionalCollection` protocol instead, because it has a more complete
1818
/// interface.
19+
@available(*, deprecated, renamed: "BidirectionalCollection")
1920
public protocol BidirectionalIndexable : Indexable {
2021
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2122
// to exist apart from missing compiler features that we emulate with it.

stdlib/public/core/Collection.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
///
1616
/// In most cases, it's best to ignore this protocol and use the `Collection`
1717
/// protocol instead, because it has a more complete interface.
18+
@available(*, deprecated, renamed: "Collection")
1819
public protocol IndexableBase {
1920
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2021
// to exist apart from missing compiler features that we emulate with it.
@@ -156,6 +157,7 @@ public protocol IndexableBase {
156157
///
157158
/// In most cases, it's best to ignore this protocol and use the `Collection`
158159
/// protocol instead, because it has a more complete interface.
160+
@available(*, deprecated, renamed: "Collection")
159161
public protocol Indexable : IndexableBase {
160162
/// A type used to represent the number of steps between two indices, where
161163
/// one value is reachable from the other.
@@ -1703,3 +1705,4 @@ extension Collection where Iterator.Element : Equatable {
17031705

17041706
@available(*, unavailable, message: "PermutationGenerator has been removed in Swift 3")
17051707
public struct PermutationGenerator<C : Collection, Indices : Sequence> {}
1708+

stdlib/public/core/MutableCollection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/// In most cases, it's best to ignore this protocol and use the
1616
/// `MutableCollection` protocol instead, because it has a more complete
1717
/// interface.
18+
@available(*, deprecated, renamed: "MutableCollection")
1819
public protocol MutableIndexable : Indexable {
1920
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2021
// to exist apart from missing compiler features that we emulate with it.

stdlib/public/core/RandomAccessCollection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/// In most cases, it's best to ignore this protocol and use the
1616
/// `RandomAccessCollection` protocol instead, because it has a more complete
1717
/// interface.
18+
@available(*, deprecated, renamed: "RandomAccessCollection")
1819
public protocol RandomAccessIndexable : BidirectionalIndexable {
1920
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2021
// to exist apart from missing compiler features that we emulate with it.

stdlib/public/core/RangeReplaceableCollection.swift.gyb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/// In most cases, it's best to ignore this protocol and use the
2323
/// `RangeReplaceableCollection` protocol instead, because it has a more
2424
/// complete interface.
25+
@available(*, deprecated, renamed: "RangeReplaceableCollection")
2526
public protocol RangeReplaceableIndexable : Indexable {
2627
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2728
// to exist apart from missing compiler features that we emulate with it.

validation-test/stdlib/CollectionDiagnostics.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ func sortResultIgnored<
5454
array.sorted { $0 < $1 } // expected-warning {{result of call to 'sorted(by:)' is unused}}
5555
}
5656

57-
struct GoodIndexable : Indexable {
57+
// expected-warning@+2 {{'Indexable' is deprecated: renamed to 'Collection'}}
58+
// expected-note@+1 {{use 'Collection' instead}}
59+
struct GoodIndexable : Indexable {
5860
func index(after i: Int) -> Int { return i + 1 }
5961
var startIndex: Int { return 0 }
6062
var endIndex: Int { return 0 }
@@ -64,6 +66,8 @@ struct GoodIndexable : Indexable {
6466
}
6567

6668

69+
// expected-warning@+3 {{'Indexable' is deprecated: renamed to 'Collection'}}
70+
// expected-note@+2 {{use 'Collection' instead}}
6771
// expected-error@+1 {{type 'BadIndexable1' does not conform to protocol 'IndexableBase'}}
6872
struct BadIndexable1 : Indexable {
6973
func index(after i: Int) -> Int { return i + 1 }
@@ -75,6 +79,8 @@ struct BadIndexable1 : Indexable {
7579
// Missing 'subscript(_:) -> SubSequence'.
7680
}
7781

82+
// expected-warning@+3 {{'Indexable' is deprecated: renamed to 'Collection'}}
83+
// expected-note@+2 {{use 'Collection' instead}}
7884
// expected-error@+1 {{type 'BadIndexable2' does not conform to protocol 'IndexableBase'}}
7985
struct BadIndexable2 : Indexable {
8086
var startIndex: Int { return 0 }
@@ -85,6 +91,8 @@ struct BadIndexable2 : Indexable {
8591
// Missing index(after:) -> Int
8692
}
8793

94+
// expected-warning@+2 {{'BidirectionalIndexable' is deprecated: renamed to 'BidirectionalCollection'}}
95+
// expected-note@+1 {{use 'BidirectionalCollection' instead}}
8896
struct GoodBidirectionalIndexable1 : BidirectionalIndexable {
8997
var startIndex: Int { return 0 }
9098
var endIndex: Int { return 0 }
@@ -97,6 +105,8 @@ struct GoodBidirectionalIndexable1 : BidirectionalIndexable {
97105

98106
// We'd like to see: {{type 'BadBidirectionalIndexable' does not conform to protocol 'BidirectionalIndexable'}}
99107
// But the compiler doesn't generate that error.
108+
// expected-warning@+2 {{'BidirectionalIndexable' is deprecated: renamed to 'BidirectionalCollection'}}
109+
// expected-note@+1 {{use 'BidirectionalCollection' instead}}
100110
struct BadBidirectionalIndexable : BidirectionalIndexable {
101111
var startIndex: Int { return 0 }
102112
var endIndex: Int { return 0 }

0 commit comments

Comments
 (0)