rollup merge of #19827: japaric/clone-uc
closes #12677 (cc @Valloric) cc #15294 r? @aturon / @alexcrichton (Because of #19358 I had to move the struct bounds from the `where` clause into the parameter list)
This commit is contained in:
@@ -1388,6 +1388,19 @@ pub struct Map<A, B, I: Iterator<A>, F: FnMut(A) -> B> {
|
|||||||
f: F,
|
f: F,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
|
||||||
|
impl<A, B, I, F> Clone for Map<A, B, I, F> where
|
||||||
|
I: Clone + Iterator<A>,
|
||||||
|
F: Clone + FnMut(A) -> B,
|
||||||
|
{
|
||||||
|
fn clone(&self) -> Map<A, B, I, F> {
|
||||||
|
Map {
|
||||||
|
iter: self.iter.clone(),
|
||||||
|
f: self.f.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<A, B, I, F> Map<A, B, I, F> where I: Iterator<A>, F: FnMut(A) -> B {
|
impl<A, B, I, F> Map<A, B, I, F> where I: Iterator<A>, F: FnMut(A) -> B {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn do_map(&mut self, elt: Option<A>) -> Option<B> {
|
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 {
|
|||||||
predicate: P,
|
predicate: P,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
|
||||||
|
impl<A, I, P> Clone for Filter<A, I, P> where
|
||||||
|
I: Clone + Iterator<A>,
|
||||||
|
P: Clone + FnMut(&A) -> bool,
|
||||||
|
{
|
||||||
|
fn clone(&self) -> Filter<A, I, P> {
|
||||||
|
Filter {
|
||||||
|
iter: self.iter.clone(),
|
||||||
|
predicate: self.predicate.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[unstable = "trait is unstable"]
|
#[unstable = "trait is unstable"]
|
||||||
impl<A, I, P> Iterator<A> for Filter<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
|
impl<A, I, P> Iterator<A> for Filter<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -1494,6 +1520,19 @@ pub struct FilterMap<A, B, I, F> where I: Iterator<A>, F: FnMut(A) -> Option<B>
|
|||||||
f: F,
|
f: F,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
|
||||||
|
impl<A, B, I, F> Clone for FilterMap<A, B, I, F> where
|
||||||
|
I: Clone + Iterator<A>,
|
||||||
|
F: Clone + FnMut(A) -> Option<B>,
|
||||||
|
{
|
||||||
|
fn clone(&self) -> FilterMap<A, B, I, F> {
|
||||||
|
FilterMap {
|
||||||
|
iter: self.iter.clone(),
|
||||||
|
f: self.f.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[unstable = "trait is unstable"]
|
#[unstable = "trait is unstable"]
|
||||||
impl<A, B, I, F> Iterator<B> for FilterMap<A, B, I, F> where
|
impl<A, B, I, F> Iterator<B> for FilterMap<A, B, I, F> where
|
||||||
I: Iterator<A>,
|
I: Iterator<A>,
|
||||||
@@ -1657,6 +1696,20 @@ pub struct SkipWhile<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
|
|||||||
predicate: P,
|
predicate: P,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
|
||||||
|
impl<A, I, P> Clone for SkipWhile<A, I, P> where
|
||||||
|
I: Clone + Iterator<A>,
|
||||||
|
P: Clone + FnMut(&A) -> bool,
|
||||||
|
{
|
||||||
|
fn clone(&self) -> SkipWhile<A, I, P> {
|
||||||
|
SkipWhile {
|
||||||
|
iter: self.iter.clone(),
|
||||||
|
flag: self.flag,
|
||||||
|
predicate: self.predicate.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[unstable = "trait is unstable"]
|
#[unstable = "trait is unstable"]
|
||||||
impl<A, I, P> Iterator<A> for SkipWhile<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
|
impl<A, I, P> Iterator<A> for SkipWhile<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -1686,6 +1739,20 @@ pub struct TakeWhile<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
|
|||||||
predicate: P,
|
predicate: P,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
|
||||||
|
impl<A, I, P> Clone for TakeWhile<A, I, P> where
|
||||||
|
I: Clone + Iterator<A>,
|
||||||
|
P: Clone + FnMut(&A) -> bool,
|
||||||
|
{
|
||||||
|
fn clone(&self) -> TakeWhile<A, I, P> {
|
||||||
|
TakeWhile {
|
||||||
|
iter: self.iter.clone(),
|
||||||
|
flag: self.flag,
|
||||||
|
predicate: self.predicate.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[unstable = "trait is unstable"]
|
#[unstable = "trait is unstable"]
|
||||||
impl<A, I, P> Iterator<A> for TakeWhile<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
|
impl<A, I, P> Iterator<A> for TakeWhile<A, I, P> where I: Iterator<A>, P: FnMut(&A) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -1847,6 +1914,21 @@ pub struct Scan<A, B, I, St, F> where I: Iterator<A>, F: FnMut(&mut St, A) -> Op
|
|||||||
pub state: St,
|
pub state: St,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
|
||||||
|
impl<A, B, I, St, F> Clone for Scan<A, B, I, St, F> where
|
||||||
|
I: Clone + Iterator<A>,
|
||||||
|
St: Clone,
|
||||||
|
F: Clone + FnMut(&mut St, A) -> Option<B>,
|
||||||
|
{
|
||||||
|
fn clone(&self) -> Scan<A, B, I, St, F> {
|
||||||
|
Scan {
|
||||||
|
iter: self.iter.clone(),
|
||||||
|
f: self.f.clone(),
|
||||||
|
state: self.state.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[unstable = "trait is unstable"]
|
#[unstable = "trait is unstable"]
|
||||||
impl<A, B, I, St, F> Iterator<B> for Scan<A, B, I, St, F> where
|
impl<A, B, I, St, F> Iterator<B> for Scan<A, B, I, St, F> where
|
||||||
I: Iterator<A>,
|
I: Iterator<A>,
|
||||||
@@ -1876,6 +1958,22 @@ pub struct FlatMap<A, B, I, U, F> where I: Iterator<A>, U: Iterator<B>, F: FnMut
|
|||||||
backiter: Option<U>,
|
backiter: Option<U>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
|
||||||
|
impl<A, B, I, U, F> Clone for FlatMap<A, B, I, U, F> where
|
||||||
|
I: Clone + Iterator<A>,
|
||||||
|
U: Clone + Iterator<B>,
|
||||||
|
F: Clone + FnMut(A) -> U,
|
||||||
|
{
|
||||||
|
fn clone(&self) -> FlatMap<A, B, I, U, F> {
|
||||||
|
FlatMap {
|
||||||
|
iter: self.iter.clone(),
|
||||||
|
f: self.f.clone(),
|
||||||
|
frontiter: self.frontiter.clone(),
|
||||||
|
backiter: self.backiter.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[unstable = "trait is unstable"]
|
#[unstable = "trait is unstable"]
|
||||||
impl<A, B, I, U, F> Iterator<B> for FlatMap<A, B, I, U, F> where
|
impl<A, B, I, U, F> Iterator<B> for FlatMap<A, B, I, U, F> where
|
||||||
I: Iterator<A>,
|
I: Iterator<A>,
|
||||||
@@ -2020,6 +2118,19 @@ pub struct Inspect<A, I, F> where I: Iterator<A>, F: FnMut(&A) {
|
|||||||
f: F,
|
f: F,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
|
||||||
|
impl<A, I, F> Clone for Inspect<A, I, F> where
|
||||||
|
I: Clone + Iterator<A>,
|
||||||
|
F: Clone + FnMut(&A),
|
||||||
|
{
|
||||||
|
fn clone(&self) -> Inspect<A, I, F> {
|
||||||
|
Inspect {
|
||||||
|
iter: self.iter.clone(),
|
||||||
|
f: self.f.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<A, I, F> Inspect<A, I, F> where I: Iterator<A>, F: FnMut(&A) {
|
impl<A, I, F> Inspect<A, I, F> where I: Iterator<A>, F: FnMut(&A) {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn do_inspect(&mut self, elt: Option<A>) -> Option<A> {
|
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> {
|
|||||||
pub state: St,
|
pub state: St,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
|
||||||
|
impl<A, St, F> Clone for Unfold<A, St, F> where
|
||||||
|
F: Clone + FnMut(&mut St) -> Option<A>,
|
||||||
|
St: Clone,
|
||||||
|
{
|
||||||
|
fn clone(&self) -> Unfold<A, St, F> {
|
||||||
|
Unfold {
|
||||||
|
f: self.f.clone(),
|
||||||
|
state: self.state.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[experimental]
|
#[experimental]
|
||||||
impl<A, St, F> Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A> {
|
impl<A, St, F> Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A> {
|
||||||
/// Creates a new iterator with the specified closure as the "iterator
|
/// Creates a new iterator with the specified closure as the "iterator
|
||||||
|
|||||||
@@ -894,6 +894,17 @@ pub struct Splits<'a, T:'a, P> where P: FnMut(&T) -> bool {
|
|||||||
finished: 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"]
|
#[experimental = "needs review"]
|
||||||
impl<'a, T, P> Iterator<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bool {
|
impl<'a, T, P> Iterator<&'a [T]> for Splits<'a, T, P> where P: FnMut(&T) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
17
src/test/run-pass/issue-12677.rs
Normal file
17
src/test/run-pass/issue-12677.rs
Normal file
@@ -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 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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::<Vec<u8>>(), second.collect::<Vec<u8>>())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user