Skip to content

Commit f9ff55e

Browse files
committed
rollup merge of rust-lang#19827: japaric/clone-uc
closes rust-lang#12677 (cc @Valloric) cc rust-lang#15294 r? @aturon / @alexcrichton (Because of rust-lang#19358 I had to move the struct bounds from the `where` clause into the parameter list)
2 parents b530221 + 2f7a5f4 commit f9ff55e

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

src/libcore/iter.rs

+124
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,19 @@ pub struct Map<A, B, I: Iterator<A>, F: FnMut(A) -> B> {
13881388
f: F,
13891389
}
13901390

1391+
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
1392+
impl<A, B, I, F> Clone for Map<A, B, I, F> where
1393+
I: Clone + Iterator<A>,
1394+
F: Clone + FnMut(A) -> B,
1395+
{
1396+
fn clone(&self) -> Map<A, B, I, F> {
1397+
Map {
1398+
iter: self.iter.clone(),
1399+
f: self.f.clone(),
1400+
}
1401+
}
1402+
}
1403+
13911404
impl<A, B, I, F> Map<A, B, I, F> where I: Iterator<A>, F: FnMut(A) -> B {
13921405
#[inline]
13931406
fn do_map(&mut self, elt: Option<A>) -> Option<B> {
@@ -1449,6 +1462,19 @@ pub struct Filter<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
14491462
predicate: P,
14501463
}
14511464

1465+
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
1466+
impl<A, I, P> Clone for Filter<A, I, P> where
1467+
I: Clone + Iterator<A>,
1468+
P: Clone + FnMut(&A) -> bool,
1469+
{
1470+
fn clone(&self) -> Filter<A, I, P> {
1471+
Filter {
1472+
iter: self.iter.clone(),
1473+
predicate: self.predicate.clone(),
1474+
}
1475+
}
1476+
}
1477+
14521478
#[unstable = "trait is unstable"]
14531479
impl<A, I, P> Iterator<A> for Filter<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
14541480
#[inline]
@@ -1494,6 +1520,19 @@ pub struct FilterMap<A, B, I, F> where I: Iterator<A>, F: FnMut(A) -> Option<B>
14941520
f: F,
14951521
}
14961522

1523+
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
1524+
impl<A, B, I, F> Clone for FilterMap<A, B, I, F> where
1525+
I: Clone + Iterator<A>,
1526+
F: Clone + FnMut(A) -> Option<B>,
1527+
{
1528+
fn clone(&self) -> FilterMap<A, B, I, F> {
1529+
FilterMap {
1530+
iter: self.iter.clone(),
1531+
f: self.f.clone(),
1532+
}
1533+
}
1534+
}
1535+
14971536
#[unstable = "trait is unstable"]
14981537
impl<A, B, I, F> Iterator<B> for FilterMap<A, B, I, F> where
14991538
I: Iterator<A>,
@@ -1657,6 +1696,20 @@ pub struct SkipWhile<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
16571696
predicate: P,
16581697
}
16591698

1699+
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
1700+
impl<A, I, P> Clone for SkipWhile<A, I, P> where
1701+
I: Clone + Iterator<A>,
1702+
P: Clone + FnMut(&A) -> bool,
1703+
{
1704+
fn clone(&self) -> SkipWhile<A, I, P> {
1705+
SkipWhile {
1706+
iter: self.iter.clone(),
1707+
flag: self.flag,
1708+
predicate: self.predicate.clone(),
1709+
}
1710+
}
1711+
}
1712+
16601713
#[unstable = "trait is unstable"]
16611714
impl<A, I, P> Iterator<A> for SkipWhile<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
16621715
#[inline]
@@ -1686,6 +1739,20 @@ pub struct TakeWhile<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
16861739
predicate: P,
16871740
}
16881741

1742+
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
1743+
impl<A, I, P> Clone for TakeWhile<A, I, P> where
1744+
I: Clone + Iterator<A>,
1745+
P: Clone + FnMut(&A) -> bool,
1746+
{
1747+
fn clone(&self) -> TakeWhile<A, I, P> {
1748+
TakeWhile {
1749+
iter: self.iter.clone(),
1750+
flag: self.flag,
1751+
predicate: self.predicate.clone(),
1752+
}
1753+
}
1754+
}
1755+
16891756
#[unstable = "trait is unstable"]
16901757
impl<A, I, P> Iterator<A> for TakeWhile<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
16911758
#[inline]
@@ -1847,6 +1914,21 @@ pub struct Scan<A, B, I, St, F> where I: Iterator<A>, F: FnMut(&mut St, A) -> Op
18471914
pub state: St,
18481915
}
18491916

1917+
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
1918+
impl<A, B, I, St, F> Clone for Scan<A, B, I, St, F> where
1919+
I: Clone + Iterator<A>,
1920+
St: Clone,
1921+
F: Clone + FnMut(&mut St, A) -> Option<B>,
1922+
{
1923+
fn clone(&self) -> Scan<A, B, I, St, F> {
1924+
Scan {
1925+
iter: self.iter.clone(),
1926+
f: self.f.clone(),
1927+
state: self.state.clone(),
1928+
}
1929+
}
1930+
}
1931+
18501932
#[unstable = "trait is unstable"]
18511933
impl<A, B, I, St, F> Iterator<B> for Scan<A, B, I, St, F> where
18521934
I: Iterator<A>,
@@ -1876,6 +1958,22 @@ pub struct FlatMap<A, B, I, U, F> where I: Iterator<A>, U: Iterator<B>, F: FnMut
18761958
backiter: Option<U>,
18771959
}
18781960

1961+
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
1962+
impl<A, B, I, U, F> Clone for FlatMap<A, B, I, U, F> where
1963+
I: Clone + Iterator<A>,
1964+
U: Clone + Iterator<B>,
1965+
F: Clone + FnMut(A) -> U,
1966+
{
1967+
fn clone(&self) -> FlatMap<A, B, I, U, F> {
1968+
FlatMap {
1969+
iter: self.iter.clone(),
1970+
f: self.f.clone(),
1971+
frontiter: self.frontiter.clone(),
1972+
backiter: self.backiter.clone(),
1973+
}
1974+
}
1975+
}
1976+
18791977
#[unstable = "trait is unstable"]
18801978
impl<A, B, I, U, F> Iterator<B> for FlatMap<A, B, I, U, F> where
18811979
I: Iterator<A>,
@@ -2020,6 +2118,19 @@ pub struct Inspect<A, I, F> where I: Iterator<A>, F: FnMut(&A) {
20202118
f: F,
20212119
}
20222120

2121+
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
2122+
impl<A, I, F> Clone for Inspect<A, I, F> where
2123+
I: Clone + Iterator<A>,
2124+
F: Clone + FnMut(&A),
2125+
{
2126+
fn clone(&self) -> Inspect<A, I, F> {
2127+
Inspect {
2128+
iter: self.iter.clone(),
2129+
f: self.f.clone(),
2130+
}
2131+
}
2132+
}
2133+
20232134
impl<A, I, F> Inspect<A, I, F> where I: Iterator<A>, F: FnMut(&A) {
20242135
#[inline]
20252136
fn do_inspect(&mut self, elt: Option<A>) -> Option<A> {
@@ -2114,6 +2225,19 @@ pub struct Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A> {
21142225
pub state: St,
21152226
}
21162227

2228+
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
2229+
impl<A, St, F> Clone for Unfold<A, St, F> where
2230+
F: Clone + FnMut(&mut St) -> Option<A>,
2231+
St: Clone,
2232+
{
2233+
fn clone(&self) -> Unfold<A, St, F> {
2234+
Unfold {
2235+
f: self.f.clone(),
2236+
state: self.state.clone(),
2237+
}
2238+
}
2239+
}
2240+
21172241
#[experimental]
21182242
impl<A, St, F> Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A> {
21192243
/// Creates a new iterator with the specified closure as the "iterator

src/libcore/slice.rs

+11
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,17 @@ pub struct Splits<'a, T:'a, P> where P: FnMut(&T) -> bool {
894894
finished: bool
895895
}
896896

897+
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
898+
impl<'a, T, P> Clone for Splits<'a, T, P> where P: Clone + FnMut(&T) -> bool {
899+
fn clone(&self) -> Splits<'a, T, P> {
900+
Splits {
901+
v: self.v,
902+
pred: self.pred.clone(),
903+
finished: self.finished,
904+
}
905+
}
906+
}
907+
897908
#[experimental = "needs review"]
898909
impl<'a, T, P> Iterator<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bool {
899910
#[inline]

src/test/run-pass/issue-12677.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let s = "Hello";
13+
let first = s.bytes();
14+
let second = first.clone();
15+
16+
assert_eq!(first.collect::<Vec<u8>>(), second.collect::<Vec<u8>>())
17+
}

0 commit comments

Comments
 (0)