diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 5405c7aa3b7dd..11217f8dc791e 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -1388,6 +1388,19 @@ pub struct Map, F: FnMut(A) -> B> { f: F, } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl Clone for Map where + I: Clone + Iterator, + F: Clone + FnMut(A) -> B, +{ + fn clone(&self) -> Map { + Map { + iter: self.iter.clone(), + f: self.f.clone(), + } + } +} + impl Map where I: Iterator, F: FnMut(A) -> B { #[inline] fn do_map(&mut self, elt: Option) -> Option { @@ -1449,6 +1462,19 @@ pub struct Filter where I: Iterator, P: FnMut(&A) -> bool { predicate: P, } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl Clone for Filter where + I: Clone + Iterator, + P: Clone + FnMut(&A) -> bool, +{ + fn clone(&self) -> Filter { + Filter { + iter: self.iter.clone(), + predicate: self.predicate.clone(), + } + } +} + #[unstable = "trait is unstable"] impl Iterator for Filter where I: Iterator, P: FnMut(&A) -> bool { #[inline] @@ -1494,6 +1520,19 @@ pub struct FilterMap where I: Iterator, F: FnMut(A) -> Option f: F, } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl Clone for FilterMap where + I: Clone + Iterator, + F: Clone + FnMut(A) -> Option, +{ + fn clone(&self) -> FilterMap { + FilterMap { + iter: self.iter.clone(), + f: self.f.clone(), + } + } +} + #[unstable = "trait is unstable"] impl Iterator for FilterMap where I: Iterator, @@ -1657,6 +1696,20 @@ pub struct SkipWhile where I: Iterator, P: FnMut(&A) -> bool { predicate: P, } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl Clone for SkipWhile where + I: Clone + Iterator, + P: Clone + FnMut(&A) -> bool, +{ + fn clone(&self) -> SkipWhile { + SkipWhile { + iter: self.iter.clone(), + flag: self.flag, + predicate: self.predicate.clone(), + } + } +} + #[unstable = "trait is unstable"] impl Iterator for SkipWhile where I: Iterator, P: FnMut(&A) -> bool { #[inline] @@ -1686,6 +1739,20 @@ pub struct TakeWhile where I: Iterator, P: FnMut(&A) -> bool { predicate: P, } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl Clone for TakeWhile where + I: Clone + Iterator, + P: Clone + FnMut(&A) -> bool, +{ + fn clone(&self) -> TakeWhile { + TakeWhile { + iter: self.iter.clone(), + flag: self.flag, + predicate: self.predicate.clone(), + } + } +} + #[unstable = "trait is unstable"] impl Iterator for TakeWhile where I: Iterator, P: FnMut(&A) -> bool { #[inline] @@ -1847,6 +1914,21 @@ pub struct Scan where I: Iterator, F: FnMut(&mut St, A) -> Op pub state: St, } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl Clone for Scan where + I: Clone + Iterator, + St: Clone, + F: Clone + FnMut(&mut St, A) -> Option, +{ + fn clone(&self) -> Scan { + Scan { + iter: self.iter.clone(), + f: self.f.clone(), + state: self.state.clone(), + } + } +} + #[unstable = "trait is unstable"] impl Iterator for Scan where I: Iterator, @@ -1876,6 +1958,22 @@ pub struct FlatMap where I: Iterator, U: Iterator, F: FnMut backiter: Option, } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl Clone for FlatMap where + I: Clone + Iterator, + U: Clone + Iterator, + F: Clone + FnMut(A) -> U, +{ + fn clone(&self) -> FlatMap { + FlatMap { + iter: self.iter.clone(), + f: self.f.clone(), + frontiter: self.frontiter.clone(), + backiter: self.backiter.clone(), + } + } +} + #[unstable = "trait is unstable"] impl Iterator for FlatMap where I: Iterator, @@ -2020,6 +2118,19 @@ pub struct Inspect where I: Iterator, F: FnMut(&A) { f: F, } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl Clone for Inspect where + I: Clone + Iterator, + F: Clone + FnMut(&A), +{ + fn clone(&self) -> Inspect { + Inspect { + iter: self.iter.clone(), + f: self.f.clone(), + } + } +} + impl Inspect where I: Iterator, F: FnMut(&A) { #[inline] fn do_inspect(&mut self, elt: Option) -> Option { @@ -2114,6 +2225,19 @@ pub struct Unfold where F: FnMut(&mut St) -> Option { pub state: St, } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl Clone for Unfold where + F: Clone + FnMut(&mut St) -> Option, + St: Clone, +{ + fn clone(&self) -> Unfold { + Unfold { + f: self.f.clone(), + state: self.state.clone(), + } + } +} + #[experimental] impl Unfold where F: FnMut(&mut St) -> Option { /// Creates a new iterator with the specified closure as the "iterator diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index a80cf9dab6444..c51fe97a1de6d 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -894,6 +894,17 @@ pub struct Splits<'a, T:'a, P> where P: FnMut(&T) -> bool { finished: bool } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl<'a, T, P> Clone for Splits<'a, T, P> where P: Clone + FnMut(&T) -> bool { + fn clone(&self) -> Splits<'a, T, P> { + Splits { + v: self.v, + pred: self.pred.clone(), + finished: self.finished, + } + } +} + #[experimental = "needs review"] impl<'a, T, P> Iterator<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bool { #[inline] diff --git a/src/test/run-pass/issue-12677.rs b/src/test/run-pass/issue-12677.rs new file mode 100644 index 0000000000000..ef68daa8ce592 --- /dev/null +++ b/src/test/run-pass/issue-12677.rs @@ -0,0 +1,17 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let s = "Hello"; + let first = s.bytes(); + let second = first.clone(); + + assert_eq!(first.collect::>(), second.collect::>()) +}