diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 7847ed13ca9f8..8f3c0a4483574 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -1329,7 +1329,7 @@ impl ExactSizeIterator for Cloned where {} /// An iterator that repeats endlessly -#[derive(Clone, Copy)] +#[derive(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Cycle { @@ -1827,7 +1827,6 @@ impl RandomAccessIterator for Enumerate where I: RandomAccessIterator { /// An iterator with a `peek()` that returns an optional reference to the next element. #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -#[derive(Copy)] pub struct Peekable where I: Iterator { iter: I, peeked: Option, @@ -2501,7 +2500,7 @@ impl Iterator for Unfold where F: FnMut(&mut St) -> Option { @@ -2537,7 +2536,7 @@ impl + Clone> Iterator for Counter { } /// An iterator over the range [start, stop) -#[derive(Clone, Copy)] +#[derive(Clone)] #[unstable(feature = "core", reason = "will be replaced by range notation")] pub struct Range { diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 11e3d196f73fa..a368ddba9bc30 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -41,7 +41,6 @@ use cmp::Ordering::{Less, Equal, Greater}; use cmp; use default::Default; use iter::*; -use marker::Copy; use num::Int; use ops::{FnMut, self, Index}; #[cfg(stage0)] @@ -800,8 +799,6 @@ impl<'a, T> Iter<'a, T> { } } -impl<'a,T> Copy for Iter<'a,T> {} - iterator!{struct Iter -> *const T, &'a T} #[stable(feature = "rust1", since = "1.0.0")] @@ -809,7 +806,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> Clone for Iter<'a, T> { - fn clone(&self) -> Iter<'a, T> { *self } + fn clone(&self) -> Iter<'a, T> { Iter { ptr: self.ptr, end: self.end, marker: self.marker } } } #[unstable(feature = "core", reason = "trait is experimental")] diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 8495a03747e7b..f545c56a060ca 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -18,6 +18,7 @@ use self::Searcher::{Naive, TwoWay, TwoWayLong}; +use clone::Clone; use cmp::{self, Eq}; use default::Default; use error::Error; @@ -279,7 +280,7 @@ Section: Iterators /// Iterator for the char (representing *Unicode Scalar Values*) of a string /// /// Created with the method `.chars()`. -#[derive(Clone, Copy)] +#[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Chars<'a> { iter: slice::Iter<'a, u8> @@ -1007,11 +1008,11 @@ fn run_utf8_validation_iterator(iter: &mut slice::Iter) let whole = iter.as_slice(); loop { // save the current thing we're pointing at. - let old = *iter; + let old = iter.clone(); // restore the iterator we had at the start of this codepoint. macro_rules! err { () => {{ - *iter = old; + *iter = old.clone(); return Err(Utf8Error::InvalidByte(whole.len() - iter.as_slice().len())) }}} diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 8bcd4982fba5d..2590b20450218 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -366,32 +366,32 @@ fn test_iterator_size_hint() { let vi = v.iter(); assert_eq!(c.size_hint(), (uint::MAX, None)); - assert_eq!(vi.size_hint(), (10, Some(10))); - - assert_eq!(c.take(5).size_hint(), (5, Some(5))); - assert_eq!(c.skip(5).size_hint().1, None); - assert_eq!(c.take_while(|_| false).size_hint(), (0, None)); - assert_eq!(c.skip_while(|_| false).size_hint(), (0, None)); - assert_eq!(c.enumerate().size_hint(), (uint::MAX, None)); - assert_eq!(c.chain(vi.map(|&i| i)).size_hint(), (uint::MAX, None)); - assert_eq!(c.zip(vi).size_hint(), (10, Some(10))); - assert_eq!(c.scan(0i, |_,_| Some(0i)).size_hint(), (0, None)); - assert_eq!(c.filter(|_| false).size_hint(), (0, None)); - assert_eq!(c.map(|_| 0i).size_hint(), (uint::MAX, None)); + assert_eq!(vi.clone().size_hint(), (10, Some(10))); + + assert_eq!(c.clone().take(5).size_hint(), (5, Some(5))); + assert_eq!(c.clone().skip(5).size_hint().1, None); + assert_eq!(c.clone().take_while(|_| false).size_hint(), (0, None)); + assert_eq!(c.clone().skip_while(|_| false).size_hint(), (0, None)); + assert_eq!(c.clone().enumerate().size_hint(), (uint::MAX, None)); + assert_eq!(c.clone().chain(vi.clone().map(|&i| i)).size_hint(), (uint::MAX, None)); + assert_eq!(c.clone().zip(vi.clone()).size_hint(), (10, Some(10))); + assert_eq!(c.clone().scan(0i, |_,_| Some(0i)).size_hint(), (0, None)); + assert_eq!(c.clone().filter(|_| false).size_hint(), (0, None)); + assert_eq!(c.clone().map(|_| 0i).size_hint(), (uint::MAX, None)); assert_eq!(c.filter_map(|_| Some(0i)).size_hint(), (0, None)); - assert_eq!(vi.take(5).size_hint(), (5, Some(5))); - assert_eq!(vi.take(12).size_hint(), (10, Some(10))); - assert_eq!(vi.skip(3).size_hint(), (7, Some(7))); - assert_eq!(vi.skip(12).size_hint(), (0, Some(0))); - assert_eq!(vi.take_while(|_| false).size_hint(), (0, Some(10))); - assert_eq!(vi.skip_while(|_| false).size_hint(), (0, Some(10))); - assert_eq!(vi.enumerate().size_hint(), (10, Some(10))); - assert_eq!(vi.chain(v2.iter()).size_hint(), (13, Some(13))); - assert_eq!(vi.zip(v2.iter()).size_hint(), (3, Some(3))); - assert_eq!(vi.scan(0i, |_,_| Some(0i)).size_hint(), (0, Some(10))); - assert_eq!(vi.filter(|_| false).size_hint(), (0, Some(10))); - assert_eq!(vi.map(|&i| i+1).size_hint(), (10, Some(10))); + assert_eq!(vi.clone().take(5).size_hint(), (5, Some(5))); + assert_eq!(vi.clone().take(12).size_hint(), (10, Some(10))); + assert_eq!(vi.clone().skip(3).size_hint(), (7, Some(7))); + assert_eq!(vi.clone().skip(12).size_hint(), (0, Some(0))); + assert_eq!(vi.clone().take_while(|_| false).size_hint(), (0, Some(10))); + assert_eq!(vi.clone().skip_while(|_| false).size_hint(), (0, Some(10))); + assert_eq!(vi.clone().enumerate().size_hint(), (10, Some(10))); + assert_eq!(vi.clone().chain(v2.iter()).size_hint(), (13, Some(13))); + assert_eq!(vi.clone().zip(v2.iter()).size_hint(), (3, Some(3))); + assert_eq!(vi.clone().scan(0i, |_,_| Some(0i)).size_hint(), (0, Some(10))); + assert_eq!(vi.clone().filter(|_| false).size_hint(), (0, Some(10))); + assert_eq!(vi.clone().map(|&i| i+1).size_hint(), (10, Some(10))); assert_eq!(vi.filter_map(|_| Some(0i)).size_hint(), (0, Some(10))); } @@ -904,7 +904,7 @@ fn bench_multiple_take(b: &mut Bencher) { b.iter(|| { let n = it.next().unwrap(); for _ in 0u..n { - it.take(it.next().unwrap()).all(|_| true); + it.clone().take(it.next().unwrap()).all(|_| true); } }); } diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 370f59a5b2679..9a757c0c980dd 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -447,7 +447,7 @@ impl<'a> Iterator for Utf16Items<'a> { Some(Utf16Item::LoneSurrogate(u)) } else { // preserve state for rewinding. - let old = self.iter; + let old = self.iter.clone(); let u2 = match self.iter.next() { Some(u2) => *u2, @@ -457,7 +457,7 @@ impl<'a> Iterator for Utf16Items<'a> { if u2 < 0xDC00 || u2 > 0xDFFF { // not a trailing surrogate so we're not a valid // surrogate pair, so rewind to redecode u2 next time. - self.iter = old; + self.iter = old.clone(); return Some(Utf16Item::LoneSurrogate(u)) }