@@ -16,6 +16,8 @@ package immutable
16
16
17
17
import scala .collection .immutable .Set .Set4
18
18
import scala .collection .mutable .{Builder , ReusableBuilder }
19
+ import language .experimental .captureChecking
20
+ import annotation .unchecked .uncheckedCaptures
19
21
20
22
/** Base trait for immutable set collections */
21
23
trait Set [A ] extends Iterable [A ]
@@ -94,7 +96,7 @@ object Set extends IterableFactory[Set] {
94
96
95
97
def empty [A ]: Set [A ] = EmptySet .asInstanceOf [Set [A ]]
96
98
97
- def from [E ](it : collection.IterableOnce [E ]): Set [E ] =
99
+ def from [E ](it : collection.IterableOnce [E ]^ ): Set [E ] =
98
100
it match {
99
101
// We want `SortedSet` (and subclasses, such as `BitSet`) to
100
102
// rebuild themselves to avoid element type widening issues
@@ -128,7 +130,7 @@ object Set extends IterableFactory[Set] {
128
130
private [collection] def emptyInstance : Set [Any ] = EmptySet
129
131
130
132
@ SerialVersionUID (3L )
131
- private abstract class SetNIterator [A ](n : Int ) extends AbstractIterator [A ] with Serializable {
133
+ private abstract class SetNIterator [A ](n : Int ) extends AbstractIterator [A ], Serializable , Pure {
132
134
private [this ] var current = 0
133
135
private [this ] var remainder = n
134
136
override def knownSize : Int = remainder
@@ -351,9 +353,9 @@ abstract class AbstractSet[A] extends scala.collection.AbstractSet[A] with Set[A
351
353
* $multipleResults
352
354
*/
353
355
private final class SetBuilderImpl [A ] extends ReusableBuilder [A , Set [A ]] {
354
- private [this ] var elems : Set [A ] = Set .empty
356
+ private [this ] var elems : Set [A @ uncheckedCaptures ] = Set .empty
355
357
private [this ] var switchedToHashSetBuilder : Boolean = false
356
- private [this ] var hashSetBuilder : HashSetBuilder [A ] = _
358
+ private [this ] var hashSetBuilder : HashSetBuilder [A @ uncheckedCaptures ] = _
357
359
358
360
override def clear (): Unit = {
359
361
elems = Set .empty
@@ -388,7 +390,7 @@ private final class SetBuilderImpl[A] extends ReusableBuilder[A, Set[A]] {
388
390
this
389
391
}
390
392
391
- override def addAll (xs : IterableOnce [A ]): this .type =
393
+ override def addAll (xs : IterableOnce [A ]^ ): this .type =
392
394
if (switchedToHashSetBuilder) {
393
395
hashSetBuilder.addAll(xs)
394
396
this
0 commit comments