remove Copy impls from iterators

This commit is contained in:
Jorge Aparicio 2015-01-23 10:54:32 -05:00
parent 9070345c0e
commit ed82b5a70e
5 changed files with 34 additions and 37 deletions

View file

@ -1329,7 +1329,7 @@ impl<T, D, I> ExactSizeIterator for Cloned<I> 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<I> {
@ -1827,7 +1827,6 @@ fn idx(&mut self, index: usize) -> Option<(usize, <I as Iterator>::Item)> {
/// 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<T, I> where I: Iterator<Item=T> {
iter: I,
peeked: Option<T>,
@ -2501,7 +2500,7 @@ fn size_hint(&self) -> (usize, Option<usize>) {
/// An infinite iterator starting at `start` and advancing by `step` with each
/// iteration
#[derive(Clone, Copy)]
#[derive(Clone)]
#[unstable(feature = "core",
reason = "may be renamed or replaced by range notation adapaters")]
pub struct Counter<A> {
@ -2537,7 +2536,7 @@ fn size_hint(&self) -> (usize, Option<usize>) {
}
/// 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<A> {

View file

@ -41,7 +41,6 @@
use cmp;
use default::Default;
use iter::*;
use marker::Copy;
use num::Int;
use ops::{FnMut, self, Index};
#[cfg(stage0)]
@ -800,8 +799,6 @@ pub fn as_slice(&self) -> &'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")]

View file

@ -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 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
/// 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<u8>)
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()))
}}}

View file

@ -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!(vi.clone().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!(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);
}
});
}

View file

@ -447,7 +447,7 @@ fn next(&mut self) -> Option<Utf16Item> {
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 @@ fn next(&mut self) -> Option<Utf16Item> {
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))
}