Skip to content

Commit 9f484e6

Browse files
committed
auto merge of #13648 : gereeter/rust/removed-rev, r=alexcrichton
In the process, `Splits` got changed to be more like `CharSplits` in `str` to present the DEI interface. Note that `treemap` still has a `rev_iter` function because it seems like it would be a significant interface change to expose a DEI - the iterator would have to gain an extra pointer, the completion checks would be more complicated, and it isn't easy to check that such an implementation is correct due to the use of unsafety to subvert the aliasing properties of `&mut`. This fixes #9391.
2 parents 3aadbed + 03609e5 commit 9f484e6

File tree

17 files changed

+212
-219
lines changed

17 files changed

+212
-219
lines changed

src/doc/guide-container.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,13 @@ differently.
120120
Containers implement iteration over the contained elements by returning an
121121
iterator object. For example, vector slices several iterators available:
122122
123-
* `iter()` and `rev_iter()`, for immutable references to the elements
124-
* `mut_iter()` and `mut_rev_iter()`, for mutable references to the elements
125-
* `move_iter()` and `move_rev_iter()`, to move the elements out by-value
123+
* `iter()` for immutable references to the elements
124+
* `mut_iter()` for mutable references to the elements
125+
* `move_iter()` to move the elements out by-value
126126
127127
A typical mutable container will implement at least `iter()`, `mut_iter()` and
128-
`move_iter()` along with the reverse variants if it maintains an order.
128+
`move_iter()`. If it maintains an order, the returned iterators will be
129+
`DoubleEndedIterator`s, which are described below.
129130
130131
### Freezing
131132
@@ -265,7 +266,7 @@ Iterators offer generic conversion to containers with the `collect` adaptor:
265266
266267
~~~
267268
let xs = [0, 1, 1, 2, 3, 5, 8];
268-
let ys = xs.rev_iter().skip(1).map(|&x| x * 2).collect::<~[int]>();
269+
let ys = xs.iter().rev().skip(1).map(|&x| x * 2).collect::<~[int]>();
269270
assert_eq!(ys, ~[10, 6, 4, 2, 2, 0]);
270271
~~~
271272
@@ -358,9 +359,6 @@ for &x in it.rev() {
358359
}
359360
~~~
360361

361-
The `rev_iter` and `mut_rev_iter` methods on vectors just return an inverted
362-
version of the standard immutable and mutable vector iterators.
363-
364362
The `chain`, `map`, `filter`, `filter_map` and `inspect` adaptors are
365363
`DoubleEndedIterator` implementations if the underlying iterators are.
366364

src/libcollections/bitv.rs

+1
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ impl Bitv {
425425
}
426426

427427
#[inline]
428+
#[deprecated = "replaced by .iter().rev()"]
428429
pub fn rev_iter<'a>(&'a self) -> Rev<Bits<'a>> {
429430
self.iter().rev()
430431
}

src/libcollections/dlist.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -370,8 +370,8 @@ impl<T> DList<T> {
370370
Items{nelem: self.len(), head: &self.list_head, tail: self.list_tail}
371371
}
372372

373-
/// Provide a reverse iterator
374373
#[inline]
374+
#[deprecated = "replaced by .iter().rev()"]
375375
pub fn rev_iter<'a>(&'a self) -> Rev<Items<'a, T>> {
376376
self.iter().rev()
377377
}
@@ -390,8 +390,9 @@ impl<T> DList<T> {
390390
list: self
391391
}
392392
}
393-
/// Provide a reverse iterator with mutable references
393+
394394
#[inline]
395+
#[deprecated = "replaced by .mut_iter().rev()"]
395396
pub fn mut_rev_iter<'a>(&'a mut self) -> Rev<MutItems<'a, T>> {
396397
self.mut_iter().rev()
397398
}
@@ -403,8 +404,8 @@ impl<T> DList<T> {
403404
MoveItems{list: self}
404405
}
405406

406-
/// Consume the list into an iterator yielding elements by value, in reverse
407407
#[inline]
408+
#[deprecated = "replaced by .move_iter().rev()"]
408409
pub fn move_rev_iter(self) -> Rev<MoveItems<T>> {
409410
self.move_iter().rev()
410411
}
@@ -849,13 +850,13 @@ mod tests {
849850
#[test]
850851
fn test_rev_iter() {
851852
let m = generate_test();
852-
for (i, elt) in m.rev_iter().enumerate() {
853+
for (i, elt) in m.iter().rev().enumerate() {
853854
assert_eq!((6 - i) as int, *elt);
854855
}
855856
let mut n = DList::new();
856-
assert_eq!(n.rev_iter().next(), None);
857+
assert_eq!(n.iter().rev().next(), None);
857858
n.push_front(4);
858-
let mut it = n.rev_iter();
859+
let mut it = n.iter().rev();
859860
assert_eq!(it.size_hint(), (1, Some(1)));
860861
assert_eq!(it.next().unwrap(), &4);
861862
assert_eq!(it.size_hint(), (0, Some(0)));
@@ -958,13 +959,13 @@ mod tests {
958959
#[test]
959960
fn test_mut_rev_iter() {
960961
let mut m = generate_test();
961-
for (i, elt) in m.mut_rev_iter().enumerate() {
962+
for (i, elt) in m.mut_iter().rev().enumerate() {
962963
assert_eq!((6-i) as int, *elt);
963964
}
964965
let mut n = DList::new();
965-
assert!(n.mut_rev_iter().next().is_none());
966+
assert!(n.mut_iter().rev().next().is_none());
966967
n.push_front(4);
967-
let mut it = n.mut_rev_iter();
968+
let mut it = n.mut_iter().rev();
968969
assert!(it.next().is_some());
969970
assert!(it.next().is_none());
970971
}
@@ -1164,15 +1165,15 @@ mod tests {
11641165
let v = &[0, ..128];
11651166
let m: DList<int> = v.iter().map(|&x|x).collect();
11661167
b.iter(|| {
1167-
assert!(m.rev_iter().len() == 128);
1168+
assert!(m.iter().rev().len() == 128);
11681169
})
11691170
}
11701171
#[bench]
11711172
fn bench_iter_mut_rev(b: &mut test::Bencher) {
11721173
let v = &[0, ..128];
11731174
let mut m: DList<int> = v.iter().map(|&x|x).collect();
11741175
b.iter(|| {
1175-
assert!(m.mut_rev_iter().len() == 128);
1176+
assert!(m.mut_iter().rev().len() == 128);
11761177
})
11771178
}
11781179
}

src/libcollections/priority_queue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -382,7 +382,7 @@ mod tests {
382382
fn test_from_iter() {
383383
let xs = vec!(9u, 8, 7, 6, 5, 4, 3, 2, 1);
384384

385-
let mut q: PriorityQueue<uint> = xs.as_slice().rev_iter().map(|&x| x).collect();
385+
let mut q: PriorityQueue<uint> = xs.as_slice().iter().rev().map(|&x| x).collect();
386386

387387
for &x in xs.iter() {
388388
assert_eq!(q.pop(), x);

src/libcollections/ringbuf.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -190,7 +190,7 @@ impl<T> RingBuf<T> {
190190
Items{index: 0, rindex: self.nelts, lo: self.lo, elts: self.elts.as_slice()}
191191
}
192192

193-
/// Back-to-front iterator.
193+
#[deprecated = "replaced by .iter().rev()"]
194194
pub fn rev_iter<'a>(&'a self) -> Rev<Items<'a, T>> {
195195
self.iter().rev()
196196
}
@@ -221,7 +221,7 @@ impl<T> RingBuf<T> {
221221
}
222222
}
223223

224-
/// Back-to-front iterator which returns mutable values.
224+
#[deprecated = "replaced by .mut_iter().rev()"]
225225
pub fn mut_rev_iter<'a>(&'a mut self) -> Rev<MutItems<'a, T>> {
226226
self.mut_iter().rev()
227227
}
@@ -702,31 +702,31 @@ mod tests {
702702
#[test]
703703
fn test_rev_iter() {
704704
let mut d = RingBuf::new();
705-
assert_eq!(d.rev_iter().next(), None);
705+
assert_eq!(d.iter().rev().next(), None);
706706

707707
for i in range(0, 5) {
708708
d.push_back(i);
709709
}
710-
assert_eq!(d.rev_iter().collect::<Vec<&int>>().as_slice(), &[&4,&3,&2,&1,&0]);
710+
assert_eq!(d.iter().rev().collect::<Vec<&int>>().as_slice(), &[&4,&3,&2,&1,&0]);
711711

712712
for i in range(6, 9) {
713713
d.push_front(i);
714714
}
715-
assert_eq!(d.rev_iter().collect::<Vec<&int>>().as_slice(), &[&4,&3,&2,&1,&0,&6,&7,&8]);
715+
assert_eq!(d.iter().rev().collect::<Vec<&int>>().as_slice(), &[&4,&3,&2,&1,&0,&6,&7,&8]);
716716
}
717717

718718
#[test]
719719
fn test_mut_rev_iter_wrap() {
720720
let mut d = RingBuf::with_capacity(3);
721-
assert!(d.mut_rev_iter().next().is_none());
721+
assert!(d.mut_iter().rev().next().is_none());
722722

723723
d.push_back(1);
724724
d.push_back(2);
725725
d.push_back(3);
726726
assert_eq!(d.pop_front(), Some(1));
727727
d.push_back(4);
728728

729-
assert_eq!(d.mut_rev_iter().map(|x| *x).collect::<Vec<int>>(),
729+
assert_eq!(d.mut_iter().rev().map(|x| *x).collect::<Vec<int>>(),
730730
vec!(4, 3, 2));
731731
}
732732

@@ -756,19 +756,19 @@ mod tests {
756756
#[test]
757757
fn test_mut_rev_iter() {
758758
let mut d = RingBuf::new();
759-
assert!(d.mut_rev_iter().next().is_none());
759+
assert!(d.mut_iter().rev().next().is_none());
760760

761761
for i in range(0u, 3) {
762762
d.push_front(i);
763763
}
764764

765-
for (i, elt) in d.mut_rev_iter().enumerate() {
765+
for (i, elt) in d.mut_iter().rev().enumerate() {
766766
assert_eq!(*elt, i);
767767
*elt = i;
768768
}
769769

770770
{
771-
let mut it = d.mut_rev_iter();
771+
let mut it = d.mut_iter().rev();
772772
assert_eq!(*it.next().unwrap(), 0);
773773
assert_eq!(*it.next().unwrap(), 1);
774774
assert_eq!(*it.next().unwrap(), 2);

src/libcollections/smallintmap.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -142,16 +142,13 @@ impl<V> SmallIntMap<V> {
142142
}
143143
}
144144

145-
/// An iterator visiting all key-value pairs in descending order by the keys.
146-
/// Iterator element type is (uint, &'r V)
147-
pub fn rev_iter<'r>(&'r self) -> RevEntries<'r, V> {
145+
#[deprecated = "replaced by .iter().rev()"]
146+
pub fn rev_iter<'r>(&'r self) -> Rev<Entries<'r, V>> {
148147
self.iter().rev()
149148
}
150149

151-
/// An iterator visiting all key-value pairs in descending order by the keys,
152-
/// with mutable references to the values
153-
/// Iterator element type is (uint, &'r mut V)
154-
pub fn mut_rev_iter<'r>(&'r mut self) -> RevMutEntries <'r, V> {
150+
#[deprecated = "replaced by .mut_iter().rev()"]
151+
pub fn mut_rev_iter<'r>(&'r mut self) -> Rev<MutEntries<'r, V>> {
155152
self.mut_iter().rev()
156153
}
157154

@@ -246,6 +243,7 @@ pub struct Entries<'a, T> {
246243

247244
iterator!(impl Entries -> (uint, &'a T), get_ref)
248245
double_ended_iterator!(impl Entries -> (uint, &'a T), get_ref)
246+
#[deprecated = "replaced by Rev<Entries<'a, T>>"]
249247
pub type RevEntries<'a, T> = Rev<Entries<'a, T>>;
250248

251249
pub struct MutEntries<'a, T> {
@@ -256,6 +254,7 @@ pub struct MutEntries<'a, T> {
256254

257255
iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref)
258256
double_ended_iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref)
257+
#[deprecated = "replaced by Rev<MutEntries<'a, T>"]
259258
pub type RevMutEntries<'a, T> = Rev<MutEntries<'a, T>>;
260259

261260
#[cfg(test)]
@@ -387,9 +386,9 @@ mod test_map {
387386
assert!(m.insert(10, 11));
388387

389388
assert_eq!(m.iter().size_hint(), (0, Some(11)));
390-
assert_eq!(m.rev_iter().size_hint(), (0, Some(11)));
389+
assert_eq!(m.iter().rev().size_hint(), (0, Some(11)));
391390
assert_eq!(m.mut_iter().size_hint(), (0, Some(11)));
392-
assert_eq!(m.mut_rev_iter().size_hint(), (0, Some(11)));
391+
assert_eq!(m.mut_iter().rev().size_hint(), (0, Some(11)));
393392
}
394393

395394
#[test]
@@ -425,7 +424,7 @@ mod test_map {
425424
assert!(m.insert(6, 10));
426425
assert!(m.insert(10, 11));
427426

428-
let mut it = m.rev_iter();
427+
let mut it = m.iter().rev();
429428
assert_eq!(it.next().unwrap(), (10, &11));
430429
assert_eq!(it.next().unwrap(), (6, &10));
431430
assert_eq!(it.next().unwrap(), (3, &5));
@@ -444,7 +443,7 @@ mod test_map {
444443
assert!(m.insert(6, 10));
445444
assert!(m.insert(10, 11));
446445

447-
for (k, v) in m.mut_rev_iter() {
446+
for (k, v) in m.mut_iter().rev() {
448447
*v += k as int;
449448
}
450449

src/libcollections/trie.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ impl<T> TrieNode<T> {
395395

396396
impl<T> TrieNode<T> {
397397
fn each_reverse<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
398-
for elt in self.children.rev_iter() {
398+
for elt in self.children.iter().rev() {
399399
match *elt {
400400
Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false },
401401
External(k, ref v) => if !f(&k, v) { return false },

src/libnum/bigint.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl Integer for BigUint {
439439
let bn = *b.data.last().unwrap();
440440
let mut d = Vec::with_capacity(an.len());
441441
let mut carry = 0;
442-
for elt in an.rev_iter() {
442+
for elt in an.iter().rev() {
443443
let ai = BigDigit::to_uint(carry, *elt);
444444
let di = ai / (bn as uint);
445445
assert!(di < BigDigit::base);
@@ -668,7 +668,7 @@ impl ToStrRadix for BigUint {
668668
fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> ~str {
669669
if v.is_empty() { return "0".to_owned() }
670670
let mut s = StrBuf::with_capacity(v.len() * l);
671-
for n in v.rev_iter() {
671+
for n in v.iter().rev() {
672672
let ss = (*n as uint).to_str_radix(radix);
673673
s.push_str("0".repeat(l - ss.len()));
674674
s.push_str(ss);
@@ -2187,7 +2187,7 @@ mod bigint_tests {
21872187
fn test_cmp() {
21882188
let vs = [ &[2 as BigDigit], &[1, 1], &[2, 1], &[1, 1, 1] ];
21892189
let mut nums = Vec::new();
2190-
for s in vs.rev_iter() {
2190+
for s in vs.iter().rev() {
21912191
nums.push(BigInt::from_slice(Minus, *s));
21922192
}
21932193
nums.push(Zero::zero());

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ impl<'a> Liveness<'a> {
927927

928928
fn propagate_through_exprs(&mut self, exprs: &[@Expr], succ: LiveNode)
929929
-> LiveNode {
930-
exprs.rev_iter().fold(succ, |succ, expr| {
930+
exprs.iter().rev().fold(succ, |succ, expr| {
931931
self.propagate_through_expr(*expr, succ)
932932
})
933933
}

src/librustc/middle/typeck/check/vtable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -94,7 +94,7 @@ fn lookup_vtables(vcx: &VtableContext,
9494
let mut result: Vec<vtable_param_res> =
9595
substs.tps.iter()
9696
.rev()
97-
.zip(type_param_defs.rev_iter())
97+
.zip(type_param_defs.iter().rev())
9898
.map(|(ty, def)|
9999
lookup_vtables_for_param(vcx, span, Some(substs),
100100
&*def.bounds, *ty, is_early))

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
304304
None => {}
305305
}
306306
if default_passes {
307-
for name in DEFAULT_PASSES.rev_iter() {
307+
for name in DEFAULT_PASSES.iter().rev() {
308308
passes.unshift(name.to_owned());
309309
}
310310
}

src/libserialize/json.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,7 @@ impl ::Decoder<DecoderError> for Decoder {
19311931
};
19321932
match o.pop(&"fields".to_owned()) {
19331933
Some(List(l)) => {
1934-
for field in l.move_rev_iter() {
1934+
for field in l.move_iter().rev() {
19351935
self.stack.push(field.clone());
19361936
}
19371937
},
@@ -2042,7 +2042,7 @@ impl ::Decoder<DecoderError> for Decoder {
20422042
debug!("read_seq()");
20432043
let list = try!(expect!(self.pop(), List));
20442044
let len = list.len();
2045-
for v in list.move_rev_iter() {
2045+
for v in list.move_iter().rev() {
20462046
self.stack.push(v);
20472047
}
20482048
f(self, len)

0 commit comments

Comments
 (0)