Skip to content

Commit

Permalink
remove Copy impls from iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Jan 30, 2015
1 parent 9070345 commit ed82b5a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 38 deletions.
7 changes: 3 additions & 4 deletions src/libcore/iter.rs
Expand Up @@ -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> {
Expand Down Expand Up @@ -1827,7 +1827,6 @@ impl<I> RandomAccessIterator for Enumerate<I> 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<T, I> where I: Iterator<Item=T> {
iter: I,
peeked: Option<T>,
Expand Down Expand Up @@ -2501,7 +2500,7 @@ impl<A, St, F> Iterator for Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A

/// 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> {
Expand Down Expand Up @@ -2537,7 +2536,7 @@ impl<A: Add<Output=A> + Clone> Iterator for Counter<A> {
}

/// 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> {
Expand Down
5 changes: 1 addition & 4 deletions src/libcore/slice.rs
Expand Up @@ -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)]
Expand Down Expand Up @@ -800,16 +799,14 @@ 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")]
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")]
Expand Down
7 changes: 4 additions & 3 deletions src/libcore/str/mod.rs
Expand Up @@ -18,6 +18,7 @@

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

use clone::Clone;
use cmp::{self, Eq};
use default::Default;
use error::Error;
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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()))
}}}

Expand Down
50 changes: 25 additions & 25 deletions src/libcoretest/iter.rs
Expand Up @@ -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)));
}

Expand Down Expand Up @@ -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);
}
});
}
4 changes: 2 additions & 2 deletions src/libunicode/u_str.rs
Expand Up @@ -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,
Expand All @@ -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))
}

Expand Down

0 comments on commit ed82b5a

Please sign in to comment.