Skip to content

Commit 42eb453

Browse files
author
Max Moiseev
committed
[stdlib] Conditional gardening
1 parent 94d0e4e commit 42eb453

File tree

4 files changed

+23
-28
lines changed

4 files changed

+23
-28
lines changed

stdlib/public/core/Indices.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,7 @@ extension Collection where Indices == DefaultIndices<Self> {
130130
}
131131
}
132132

133-
public typealias DefaultBidirectionalIndices<T: BidirectionalCollection> = DefaultIndices<T>
134-
public typealias DefaultRandomAccessIndices<T: RandomAccessCollection> = DefaultIndices<T>
133+
@available(*, deprecated, renamed: "DefaultIndices")
134+
public typealias DefaultBidirectionalIndices<T> = DefaultIndices<T> where T : BidirectionalCollection
135+
@available(*, deprecated, renamed: "DefaultIndices")
136+
public typealias DefaultRandomAccessIndices<T> = DefaultIndices<T> where T : RandomAccessCollection

stdlib/public/core/RangeReplaceableCollection.swift

+4-10
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ public typealias RangeReplaceableIndexable = RangeReplaceableCollection
7070
/// `replaceSubrange(_:with:)` with an empty collection for the `newElements`
7171
/// parameter. You can override any of the protocol's required methods to
7272
/// provide your own custom implementation.
73-
public protocol RangeReplaceableCollection: Collection
74-
where SubSequence: RangeReplaceableCollection
75-
{
73+
public protocol RangeReplaceableCollection : Collection
74+
where SubSequence : RangeReplaceableCollection {
7675
// FIXME(ABI): Associated type inference requires this.
7776
associatedtype SubSequence = Slice<Self>
7877

@@ -782,9 +781,7 @@ extension RangeReplaceableCollection {
782781
}
783782

784783
extension RangeReplaceableCollection
785-
where
786-
Self : BidirectionalCollection,
787-
SubSequence == Self {
784+
where Self : BidirectionalCollection, SubSequence == Self {
788785

789786
@_inlineable
790787
public mutating func _customRemoveLast() -> Element? {
@@ -854,10 +851,7 @@ extension RangeReplaceableCollection where Self : BidirectionalCollection {
854851
// FIXME: swift-3-indexing-model: file a bug for the compiler?
855852
/// Ambiguity breakers.
856853
extension RangeReplaceableCollection
857-
where
858-
Self : BidirectionalCollection,
859-
SubSequence == Self
860-
{
854+
where Self : BidirectionalCollection, SubSequence == Self {
861855
/// Removes and returns the last element of the collection.
862856
///
863857
/// The collection must not be empty.

stdlib/public/core/Slice.swift

+14-15
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ extension Slice: MutableCollection where Base: MutableCollection {
264264

265265
extension Slice: RandomAccessCollection where Base: RandomAccessCollection { }
266266

267-
extension Slice: RangeReplaceableCollection where Base: RangeReplaceableCollection {
267+
extension Slice: RangeReplaceableCollection
268+
where Base: RangeReplaceableCollection {
268269
@_inlineable // FIXME(sil-serialize-all)
269270
public init() {
270271
self._base = Base()
@@ -354,7 +355,7 @@ extension Slice: RangeReplaceableCollection where Base: RangeReplaceableCollecti
354355
}
355356

356357
extension Slice
357-
where Base: RangeReplaceableCollection, Base: BidirectionalCollection {
358+
where Base: RangeReplaceableCollection, Base: BidirectionalCollection {
358359

359360
@_inlineable // FIXME(sil-serialize-all)
360361
public mutating func replaceSubrange<C>(
@@ -476,27 +477,25 @@ where Base: RangeReplaceableCollection, Base: BidirectionalCollection {
476477
}
477478

478479
@available(*, deprecated, renamed: "Slice")
479-
public typealias BidirectionalSlice<T> = Slice<T> where T: BidirectionalCollection
480+
public typealias BidirectionalSlice<T> = Slice<T> where T : BidirectionalCollection
480481
@available(*, deprecated, renamed: "Slice")
481-
public typealias RandomAccessSlice<T> = Slice<T> where T: RandomAccessCollection
482+
public typealias RandomAccessSlice<T> = Slice<T> where T : RandomAccessCollection
482483
@available(*, deprecated, renamed: "Slice")
483-
public typealias RangeReplaceableSlice<T> = Slice<T> where T: RangeReplaceableCollection
484+
public typealias RangeReplaceableSlice<T> = Slice<T> where T : RangeReplaceableCollection
484485
@available(*, deprecated, renamed: "Slice")
485-
public typealias RangeReplaceableBidirectionalSlice<T> = Slice<T> where T: RangeReplaceableCollection, T: BidirectionalCollection
486+
public typealias RangeReplaceableBidirectionalSlice<T> = Slice<T> where T : RangeReplaceableCollection & BidirectionalCollection
486487
@available(*, deprecated, renamed: "Slice")
487-
public typealias RangeReplaceableRandomAccessSlice<T> = Slice<T> where T: RangeReplaceableCollection, T: RandomAccessCollection
488+
public typealias RangeReplaceableRandomAccessSlice<T> = Slice<T> where T : RangeReplaceableCollection & RandomAccessCollection
488489

489490
@available(*, deprecated, renamed: "Slice")
490-
public typealias MutableSlice<T: MutableCollection> = Slice<T>
491+
public typealias MutableSlice<T> = Slice<T> where T : MutableCollection
491492
@available(*, deprecated, renamed: "Slice")
492-
public typealias MutableBidirectionalSlice<T: MutableCollection> = Slice<T> where T: BidirectionalCollection
493+
public typealias MutableBidirectionalSlice<T> = Slice<T> where T : MutableCollection & BidirectionalCollection
493494
@available(*, deprecated, renamed: "Slice")
494-
public typealias MutableRandomAccessSlice<T: MutableCollection> = Slice<T> where T: RandomAccessCollection
495+
public typealias MutableRandomAccessSlice<T> = Slice<T> where T : MutableCollection & RandomAccessCollection
495496
@available(*, deprecated, renamed: "Slice")
496-
public typealias MutableRangeReplaceableSlice<T: MutableCollection> = Slice<T> where T: RangeReplaceableCollection
497+
public typealias MutableRangeReplaceableSlice<T> = Slice<T> where T : MutableCollection & RangeReplaceableCollection
497498
@available(*, deprecated, renamed: "Slice")
498-
public typealias MutableRangeReplaceableBidirectionalSlice<T: MutableCollection> = Slice<T> where T: RangeReplaceableCollection, T: BidirectionalCollection
499+
public typealias MutableRangeReplaceableBidirectionalSlice<T> = Slice<T> where T : MutableCollection & RangeReplaceableCollection & BidirectionalCollection
499500
@available(*, deprecated, renamed: "Slice")
500-
public typealias MutableRangeReplaceableRandomAccessSlice<T: MutableCollection> = Slice<T> where T: RangeReplaceableCollection, T: RandomAccessCollection
501-
502-
501+
public typealias MutableRangeReplaceableRandomAccessSlice<T> = Slice<T> where T : MutableCollection & RangeReplaceableCollection & RandomAccessCollection

test/stdlib/collection-combinatorics.swift.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ struct ${indexLabel}${mutable}${rangeReplaceable}${capability}Butt
6666
// This type alias is required for some random-access collections with
6767
// a custom index type -- without it the default implementation for
6868
// `indices` doesn't attach.
69-
typealias Indices = DefaultRandomAccessIndices<${indexLabel}${mutable}${rangeReplaceable}${capability}Butt>
69+
typealias Indices = DefaultIndices<${indexLabel}${mutable}${rangeReplaceable}${capability}Butt>
7070
% end
7171
}

0 commit comments

Comments
 (0)