Skip to content

Commit ed82b5a

Browse files
author
Jorge Aparicio
committed
remove Copy impls from iterators
1 parent 9070345 commit ed82b5a

File tree

5 files changed

+35
-38
lines changed

5 files changed

+35
-38
lines changed

src/libcore/iter.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ impl<T, D, I> ExactSizeIterator for Cloned<I> where
13291329
{}
13301330

13311331
/// An iterator that repeats endlessly
1332-
#[derive(Clone, Copy)]
1332+
#[derive(Clone)]
13331333
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
13341334
#[stable(feature = "rust1", since = "1.0.0")]
13351335
pub struct Cycle<I> {
@@ -1827,7 +1827,6 @@ impl<I> RandomAccessIterator for Enumerate<I> where I: RandomAccessIterator {
18271827
/// An iterator with a `peek()` that returns an optional reference to the next element.
18281828
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
18291829
#[stable(feature = "rust1", since = "1.0.0")]
1830-
#[derive(Copy)]
18311830
pub struct Peekable<T, I> where I: Iterator<Item=T> {
18321831
iter: I,
18331832
peeked: Option<T>,
@@ -2501,7 +2500,7 @@ impl<A, St, F> Iterator for Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A
25012500

25022501
/// An infinite iterator starting at `start` and advancing by `step` with each
25032502
/// iteration
2504-
#[derive(Clone, Copy)]
2503+
#[derive(Clone)]
25052504
#[unstable(feature = "core",
25062505
reason = "may be renamed or replaced by range notation adapaters")]
25072506
pub struct Counter<A> {
@@ -2537,7 +2536,7 @@ impl<A: Add<Output=A> + Clone> Iterator for Counter<A> {
25372536
}
25382537

25392538
/// An iterator over the range [start, stop)
2540-
#[derive(Clone, Copy)]
2539+
#[derive(Clone)]
25412540
#[unstable(feature = "core",
25422541
reason = "will be replaced by range notation")]
25432542
pub struct Range<A> {

src/libcore/slice.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use cmp::Ordering::{Less, Equal, Greater};
4141
use cmp;
4242
use default::Default;
4343
use iter::*;
44-
use marker::Copy;
4544
use num::Int;
4645
use ops::{FnMut, self, Index};
4746
#[cfg(stage0)]
@@ -800,16 +799,14 @@ impl<'a, T> Iter<'a, T> {
800799
}
801800
}
802801

803-
impl<'a,T> Copy for Iter<'a,T> {}
804-
805802
iterator!{struct Iter -> *const T, &'a T}
806803

807804
#[stable(feature = "rust1", since = "1.0.0")]
808805
impl<'a, T> ExactSizeIterator for Iter<'a, T> {}
809806

810807
#[stable(feature = "rust1", since = "1.0.0")]
811808
impl<'a, T> Clone for Iter<'a, T> {
812-
fn clone(&self) -> Iter<'a, T> { *self }
809+
fn clone(&self) -> Iter<'a, T> { Iter { ptr: self.ptr, end: self.end, marker: self.marker } }
813810
}
814811

815812
#[unstable(feature = "core", reason = "trait is experimental")]

src/libcore/str/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use self::Searcher::{Naive, TwoWay, TwoWayLong};
2020

21+
use clone::Clone;
2122
use cmp::{self, Eq};
2223
use default::Default;
2324
use error::Error;
@@ -279,7 +280,7 @@ Section: Iterators
279280
/// Iterator for the char (representing *Unicode Scalar Values*) of a string
280281
///
281282
/// Created with the method `.chars()`.
282-
#[derive(Clone, Copy)]
283+
#[derive(Clone)]
283284
#[stable(feature = "rust1", since = "1.0.0")]
284285
pub struct Chars<'a> {
285286
iter: slice::Iter<'a, u8>
@@ -1007,11 +1008,11 @@ fn run_utf8_validation_iterator(iter: &mut slice::Iter<u8>)
10071008
let whole = iter.as_slice();
10081009
loop {
10091010
// save the current thing we're pointing at.
1010-
let old = *iter;
1011+
let old = iter.clone();
10111012

10121013
// restore the iterator we had at the start of this codepoint.
10131014
macro_rules! err { () => {{
1014-
*iter = old;
1015+
*iter = old.clone();
10151016
return Err(Utf8Error::InvalidByte(whole.len() - iter.as_slice().len()))
10161017
}}}
10171018

src/libcoretest/iter.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -366,32 +366,32 @@ fn test_iterator_size_hint() {
366366
let vi = v.iter();
367367

368368
assert_eq!(c.size_hint(), (uint::MAX, None));
369-
assert_eq!(vi.size_hint(), (10, Some(10)));
370-
371-
assert_eq!(c.take(5).size_hint(), (5, Some(5)));
372-
assert_eq!(c.skip(5).size_hint().1, None);
373-
assert_eq!(c.take_while(|_| false).size_hint(), (0, None));
374-
assert_eq!(c.skip_while(|_| false).size_hint(), (0, None));
375-
assert_eq!(c.enumerate().size_hint(), (uint::MAX, None));
376-
assert_eq!(c.chain(vi.map(|&i| i)).size_hint(), (uint::MAX, None));
377-
assert_eq!(c.zip(vi).size_hint(), (10, Some(10)));
378-
assert_eq!(c.scan(0i, |_,_| Some(0i)).size_hint(), (0, None));
379-
assert_eq!(c.filter(|_| false).size_hint(), (0, None));
380-
assert_eq!(c.map(|_| 0i).size_hint(), (uint::MAX, None));
369+
assert_eq!(vi.clone().size_hint(), (10, Some(10)));
370+
371+
assert_eq!(c.clone().take(5).size_hint(), (5, Some(5)));
372+
assert_eq!(c.clone().skip(5).size_hint().1, None);
373+
assert_eq!(c.clone().take_while(|_| false).size_hint(), (0, None));
374+
assert_eq!(c.clone().skip_while(|_| false).size_hint(), (0, None));
375+
assert_eq!(c.clone().enumerate().size_hint(), (uint::MAX, None));
376+
assert_eq!(c.clone().chain(vi.clone().map(|&i| i)).size_hint(), (uint::MAX, None));
377+
assert_eq!(c.clone().zip(vi.clone()).size_hint(), (10, Some(10)));
378+
assert_eq!(c.clone().scan(0i, |_,_| Some(0i)).size_hint(), (0, None));
379+
assert_eq!(c.clone().filter(|_| false).size_hint(), (0, None));
380+
assert_eq!(c.clone().map(|_| 0i).size_hint(), (uint::MAX, None));
381381
assert_eq!(c.filter_map(|_| Some(0i)).size_hint(), (0, None));
382382

383-
assert_eq!(vi.take(5).size_hint(), (5, Some(5)));
384-
assert_eq!(vi.take(12).size_hint(), (10, Some(10)));
385-
assert_eq!(vi.skip(3).size_hint(), (7, Some(7)));
386-
assert_eq!(vi.skip(12).size_hint(), (0, Some(0)));
387-
assert_eq!(vi.take_while(|_| false).size_hint(), (0, Some(10)));
388-
assert_eq!(vi.skip_while(|_| false).size_hint(), (0, Some(10)));
389-
assert_eq!(vi.enumerate().size_hint(), (10, Some(10)));
390-
assert_eq!(vi.chain(v2.iter()).size_hint(), (13, Some(13)));
391-
assert_eq!(vi.zip(v2.iter()).size_hint(), (3, Some(3)));
392-
assert_eq!(vi.scan(0i, |_,_| Some(0i)).size_hint(), (0, Some(10)));
393-
assert_eq!(vi.filter(|_| false).size_hint(), (0, Some(10)));
394-
assert_eq!(vi.map(|&i| i+1).size_hint(), (10, Some(10)));
383+
assert_eq!(vi.clone().take(5).size_hint(), (5, Some(5)));
384+
assert_eq!(vi.clone().take(12).size_hint(), (10, Some(10)));
385+
assert_eq!(vi.clone().skip(3).size_hint(), (7, Some(7)));
386+
assert_eq!(vi.clone().skip(12).size_hint(), (0, Some(0)));
387+
assert_eq!(vi.clone().take_while(|_| false).size_hint(), (0, Some(10)));
388+
assert_eq!(vi.clone().skip_while(|_| false).size_hint(), (0, Some(10)));
389+
assert_eq!(vi.clone().enumerate().size_hint(), (10, Some(10)));
390+
assert_eq!(vi.clone().chain(v2.iter()).size_hint(), (13, Some(13)));
391+
assert_eq!(vi.clone().zip(v2.iter()).size_hint(), (3, Some(3)));
392+
assert_eq!(vi.clone().scan(0i, |_,_| Some(0i)).size_hint(), (0, Some(10)));
393+
assert_eq!(vi.clone().filter(|_| false).size_hint(), (0, Some(10)));
394+
assert_eq!(vi.clone().map(|&i| i+1).size_hint(), (10, Some(10)));
395395
assert_eq!(vi.filter_map(|_| Some(0i)).size_hint(), (0, Some(10)));
396396
}
397397

@@ -904,7 +904,7 @@ fn bench_multiple_take(b: &mut Bencher) {
904904
b.iter(|| {
905905
let n = it.next().unwrap();
906906
for _ in 0u..n {
907-
it.take(it.next().unwrap()).all(|_| true);
907+
it.clone().take(it.next().unwrap()).all(|_| true);
908908
}
909909
});
910910
}

src/libunicode/u_str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl<'a> Iterator for Utf16Items<'a> {
447447
Some(Utf16Item::LoneSurrogate(u))
448448
} else {
449449
// preserve state for rewinding.
450-
let old = self.iter;
450+
let old = self.iter.clone();
451451

452452
let u2 = match self.iter.next() {
453453
Some(u2) => *u2,
@@ -457,7 +457,7 @@ impl<'a> Iterator for Utf16Items<'a> {
457457
if u2 < 0xDC00 || u2 > 0xDFFF {
458458
// not a trailing surrogate so we're not a valid
459459
// surrogate pair, so rewind to redecode u2 next time.
460-
self.iter = old;
460+
self.iter = old.clone();
461461
return Some(Utf16Item::LoneSurrogate(u))
462462
}
463463

0 commit comments

Comments
 (0)