Skip to content

Commit c6c7866

Browse files
committed
auto merge of #20490 : japaric/rust/assoc-types, r=aturon
closes #20486 closes #20474 closes #20441 [breaking-change] The `Index[Mut]` traits now have one less input parameter, as the return type of the indexing operation is an associated type. This breaks all existing implementations. --- binop traits (`Add`, `Sub`, etc) now have an associated type for their return type. Also, the RHS input parameter now defaults to `Self` (except for the `Shl` and `Shr` traits). For example, the `Add` trait now looks like this: ``` rust trait Add<Rhs=Self> { type Output; fn add(self, Rhs) -> Self::Output; } ``` The `Neg` and `Not` traits now also have an associated type for their return type. This breaks all existing implementations of these traits. --- Affected traits: - `Iterator { type Item }` - `IteratorExt` no input/output types, uses `<Self as Iterator>::Item` in its methods - `DoubleEndedIterator` no input/output types, uses `<Self as Iterator>::Item` in its methods - `DoubleEndedIteratorExt` no input/output types, uses `<Self as Iterator>::Item` in its methods - `RandomAccessIterator` no input/output types - `ExactSizeIterator` no input/output types, uses `<Self as Iterator>::Item` in its methods This breaks all the implementations of these traits.
2 parents 496dc4e + ce8f748 commit c6c7866

File tree

137 files changed

+1788
-826
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+1788
-826
lines changed

src/libcollections/binary_heap.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,9 @@ impl<'a, T> Clone for Iter<'a, T> {
573573
}
574574

575575
#[stable]
576-
impl<'a, T> Iterator<&'a T> for Iter<'a, T> {
576+
impl<'a, T> Iterator for Iter<'a, T> {
577+
type Item = &'a T;
578+
577579
#[inline]
578580
fn next(&mut self) -> Option<&'a T> { self.iter.next() }
579581

@@ -582,21 +584,23 @@ impl<'a, T> Iterator<&'a T> for Iter<'a, T> {
582584
}
583585

584586
#[stable]
585-
impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> {
587+
impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
586588
#[inline]
587589
fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() }
588590
}
589591

590592
#[stable]
591-
impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {}
593+
impl<'a, T> ExactSizeIterator for Iter<'a, T> {}
592594

593595
/// An iterator that moves out of a `BinaryHeap`.
594596
pub struct IntoIter<T> {
595597
iter: vec::IntoIter<T>,
596598
}
597599

598600
#[stable]
599-
impl<T> Iterator<T> for IntoIter<T> {
601+
impl<T> Iterator for IntoIter<T> {
602+
type Item = T;
603+
600604
#[inline]
601605
fn next(&mut self) -> Option<T> { self.iter.next() }
602606

@@ -605,21 +609,23 @@ impl<T> Iterator<T> for IntoIter<T> {
605609
}
606610

607611
#[stable]
608-
impl<T> DoubleEndedIterator<T> for IntoIter<T> {
612+
impl<T> DoubleEndedIterator for IntoIter<T> {
609613
#[inline]
610614
fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
611615
}
612616

613617
#[stable]
614-
impl<T> ExactSizeIterator<T> for IntoIter<T> {}
618+
impl<T> ExactSizeIterator for IntoIter<T> {}
615619

616620
/// An iterator that drains a `BinaryHeap`.
617621
pub struct Drain<'a, T: 'a> {
618622
iter: vec::Drain<'a, T>,
619623
}
620624

621625
#[stable]
622-
impl<'a, T: 'a> Iterator<T> for Drain<'a, T> {
626+
impl<'a, T: 'a> Iterator for Drain<'a, T> {
627+
type Item = T;
628+
623629
#[inline]
624630
fn next(&mut self) -> Option<T> { self.iter.next() }
625631

@@ -628,24 +634,24 @@ impl<'a, T: 'a> Iterator<T> for Drain<'a, T> {
628634
}
629635

630636
#[stable]
631-
impl<'a, T: 'a> DoubleEndedIterator<T> for Drain<'a, T> {
637+
impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
632638
#[inline]
633639
fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
634640
}
635641

636642
#[stable]
637-
impl<'a, T: 'a> ExactSizeIterator<T> for Drain<'a, T> {}
643+
impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {}
638644

639645
#[stable]
640646
impl<T: Ord> FromIterator<T> for BinaryHeap<T> {
641-
fn from_iter<Iter: Iterator<T>>(iter: Iter) -> BinaryHeap<T> {
647+
fn from_iter<Iter: Iterator<Item=T>>(iter: Iter) -> BinaryHeap<T> {
642648
BinaryHeap::from_vec(iter.collect())
643649
}
644650
}
645651

646652
#[stable]
647653
impl<T: Ord> Extend<T> for BinaryHeap<T> {
648-
fn extend<Iter: Iterator<T>>(&mut self, mut iter: Iter) {
654+
fn extend<Iter: Iterator<Item=T>>(&mut self, mut iter: Iter) {
649655
let (lower, _) = iter.size_hint();
650656

651657
self.reserve(lower);

src/libcollections/bit.rs

+45-14
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ pub struct Bitv {
164164
nbits: uint
165165
}
166166

167+
// NOTE(stage0): remove impl after a snapshot
168+
#[cfg(stage0)]
167169
// FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing)
168170
impl Index<uint,bool> for Bitv {
169171
#[inline]
@@ -176,6 +178,21 @@ impl Index<uint,bool> for Bitv {
176178
}
177179
}
178180

181+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
182+
// FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing)
183+
impl Index<uint> for Bitv {
184+
type Output = bool;
185+
186+
#[inline]
187+
fn index(&self, i: &uint) -> &bool {
188+
if self.get(*i).expect("index out of bounds") {
189+
&TRUE
190+
} else {
191+
&FALSE
192+
}
193+
}
194+
}
195+
179196
/// Computes how many blocks are needed to store that many bits
180197
fn blocks_for_bits(bits: uint) -> uint {
181198
// If we want 17 bits, dividing by 32 will produce 0. So we add 1 to make sure we
@@ -938,7 +955,7 @@ impl Default for Bitv {
938955

939956
#[stable]
940957
impl FromIterator<bool> for Bitv {
941-
fn from_iter<I:Iterator<bool>>(iterator: I) -> Bitv {
958+
fn from_iter<I:Iterator<Item=bool>>(iterator: I) -> Bitv {
942959
let mut ret = Bitv::new();
943960
ret.extend(iterator);
944961
ret
@@ -948,7 +965,7 @@ impl FromIterator<bool> for Bitv {
948965
#[stable]
949966
impl Extend<bool> for Bitv {
950967
#[inline]
951-
fn extend<I: Iterator<bool>>(&mut self, mut iterator: I) {
968+
fn extend<I: Iterator<Item=bool>>(&mut self, mut iterator: I) {
952969
let (min, _) = iterator.size_hint();
953970
self.reserve(min);
954971
for element in iterator {
@@ -1031,7 +1048,9 @@ pub struct Iter<'a> {
10311048
}
10321049

10331050
#[stable]
1034-
impl<'a> Iterator<bool> for Iter<'a> {
1051+
impl<'a> Iterator for Iter<'a> {
1052+
type Item = bool;
1053+
10351054
#[inline]
10361055
fn next(&mut self) -> Option<bool> {
10371056
if self.next_idx != self.end_idx {
@@ -1050,7 +1069,7 @@ impl<'a> Iterator<bool> for Iter<'a> {
10501069
}
10511070

10521071
#[stable]
1053-
impl<'a> DoubleEndedIterator<bool> for Iter<'a> {
1072+
impl<'a> DoubleEndedIterator for Iter<'a> {
10541073
#[inline]
10551074
fn next_back(&mut self) -> Option<bool> {
10561075
if self.next_idx != self.end_idx {
@@ -1063,10 +1082,10 @@ impl<'a> DoubleEndedIterator<bool> for Iter<'a> {
10631082
}
10641083

10651084
#[stable]
1066-
impl<'a> ExactSizeIterator<bool> for Iter<'a> {}
1085+
impl<'a> ExactSizeIterator for Iter<'a> {}
10671086

10681087
#[stable]
1069-
impl<'a> RandomAccessIterator<bool> for Iter<'a> {
1088+
impl<'a> RandomAccessIterator for Iter<'a> {
10701089
#[inline]
10711090
fn indexable(&self) -> uint {
10721091
self.end_idx - self.next_idx
@@ -1134,7 +1153,7 @@ impl Default for BitvSet {
11341153

11351154
#[stable]
11361155
impl FromIterator<uint> for BitvSet {
1137-
fn from_iter<I:Iterator<uint>>(iterator: I) -> BitvSet {
1156+
fn from_iter<I:Iterator<Item=uint>>(iterator: I) -> BitvSet {
11381157
let mut ret = BitvSet::new();
11391158
ret.extend(iterator);
11401159
ret
@@ -1144,7 +1163,7 @@ impl FromIterator<uint> for BitvSet {
11441163
#[stable]
11451164
impl Extend<uint> for BitvSet {
11461165
#[inline]
1147-
fn extend<I: Iterator<uint>>(&mut self, mut iterator: I) {
1166+
fn extend<I: Iterator<Item=uint>>(&mut self, mut iterator: I) {
11481167
for i in iterator {
11491168
self.insert(i);
11501169
}
@@ -1792,7 +1811,9 @@ pub struct Difference<'a>(TwoBitPositions<'a>);
17921811
pub struct SymmetricDifference<'a>(TwoBitPositions<'a>);
17931812

17941813
#[stable]
1795-
impl<'a> Iterator<uint> for SetIter<'a> {
1814+
impl<'a> Iterator for SetIter<'a> {
1815+
type Item = uint;
1816+
17961817
fn next(&mut self) -> Option<uint> {
17971818
while self.next_idx < self.set.bitv.len() {
17981819
let idx = self.next_idx;
@@ -1813,7 +1834,9 @@ impl<'a> Iterator<uint> for SetIter<'a> {
18131834
}
18141835

18151836
#[stable]
1816-
impl<'a> Iterator<uint> for TwoBitPositions<'a> {
1837+
impl<'a> Iterator for TwoBitPositions<'a> {
1838+
type Item = uint;
1839+
18171840
fn next(&mut self) -> Option<uint> {
18181841
while self.next_idx < self.set.bitv.len() ||
18191842
self.next_idx < self.other.bitv.len() {
@@ -1849,25 +1872,33 @@ impl<'a> Iterator<uint> for TwoBitPositions<'a> {
18491872
}
18501873

18511874
#[stable]
1852-
impl<'a> Iterator<uint> for Union<'a> {
1875+
impl<'a> Iterator for Union<'a> {
1876+
type Item = uint;
1877+
18531878
#[inline] fn next(&mut self) -> Option<uint> { self.0.next() }
18541879
#[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.0.size_hint() }
18551880
}
18561881

18571882
#[stable]
1858-
impl<'a> Iterator<uint> for Intersection<'a> {
1883+
impl<'a> Iterator for Intersection<'a> {
1884+
type Item = uint;
1885+
18591886
#[inline] fn next(&mut self) -> Option<uint> { self.0.next() }
18601887
#[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.0.size_hint() }
18611888
}
18621889

18631890
#[stable]
1864-
impl<'a> Iterator<uint> for Difference<'a> {
1891+
impl<'a> Iterator for Difference<'a> {
1892+
type Item = uint;
1893+
18651894
#[inline] fn next(&mut self) -> Option<uint> { self.0.next() }
18661895
#[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.0.size_hint() }
18671896
}
18681897

18691898
#[stable]
1870-
impl<'a> Iterator<uint> for SymmetricDifference<'a> {
1899+
impl<'a> Iterator for SymmetricDifference<'a> {
1900+
type Item = uint;
1901+
18711902
#[inline] fn next(&mut self) -> Option<uint> { self.0.next() }
18721903
#[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.0.size_hint() }
18731904
}

0 commit comments

Comments
 (0)