Skip to content

Commit b23af7c

Browse files
author
Dave Abrahams
authored
Merge pull request #4091 from apple/deprecate-indexable
Deprecate the Indexable protocols
2 parents b654cc9 + 8a73f0b commit b23af7c

File tree

6 files changed

+13
-1
lines changed

6 files changed

+13
-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, message: "it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead")
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, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
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, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
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, message: "it will be removed in Swift 4.0. Please use 'MutableCollection' instead")
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, message: "it will be removed in Swift 4.0. Please use 'RandomAccessCollection' instead")
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, message: "it will be removed in Swift 4.0. Please use 'RandomAccessCollection' instead")
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ 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@+1 {{'Indexable' is deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead}}
58+
struct GoodIndexable : Indexable {
5859
func index(after i: Int) -> Int { return i + 1 }
5960
var startIndex: Int { return 0 }
6061
var endIndex: Int { return 0 }
@@ -64,6 +65,7 @@ struct GoodIndexable : Indexable {
6465
}
6566

6667

68+
// expected-warning@+2 {{'Indexable' is deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead}}
6769
// expected-error@+1 {{type 'BadIndexable1' does not conform to protocol 'IndexableBase'}}
6870
struct BadIndexable1 : Indexable {
6971
func index(after i: Int) -> Int { return i + 1 }
@@ -75,6 +77,7 @@ struct BadIndexable1 : Indexable {
7577
// Missing 'subscript(_:) -> SubSequence'.
7678
}
7779

80+
// expected-warning@+2 {{'Indexable' is deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead}}
7881
// expected-error@+1 {{type 'BadIndexable2' does not conform to protocol 'IndexableBase'}}
7982
struct BadIndexable2 : Indexable {
8083
var startIndex: Int { return 0 }
@@ -85,6 +88,7 @@ struct BadIndexable2 : Indexable {
8588
// Missing index(after:) -> Int
8689
}
8790

91+
// expected-warning@+1 {{'BidirectionalIndexable' is deprecated: it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead}}
8892
struct GoodBidirectionalIndexable1 : BidirectionalIndexable {
8993
var startIndex: Int { return 0 }
9094
var endIndex: Int { return 0 }
@@ -97,6 +101,7 @@ struct GoodBidirectionalIndexable1 : BidirectionalIndexable {
97101

98102
// We'd like to see: {{type 'BadBidirectionalIndexable' does not conform to protocol 'BidirectionalIndexable'}}
99103
// But the compiler doesn't generate that error.
104+
// expected-warning@+1 {{'BidirectionalIndexable' is deprecated: it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead}}
100105
struct BadBidirectionalIndexable : BidirectionalIndexable {
101106
var startIndex: Int { return 0 }
102107
var endIndex: Int { return 0 }

0 commit comments

Comments
 (0)