make Extend use IntoIterator

This breaks all implementors of Extend, as they must now accept IntoIterator instead of Iterator. The fix for this is generally trivial (change the bound, and maybe call into_iter() on the argument to get the old argument).

Users of Extend should be unaffected because Iterators are IntoIterator.

[breaking-change]
This commit is contained in:
Alexis 2015-02-18 10:04:30 -05:00
parent 5fa9de16df
commit 4a9d190423
16 changed files with 32 additions and 26 deletions

View File

@ -677,7 +677,8 @@ impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Extend<T> for BinaryHeap<T> { impl<T: Ord> Extend<T> for BinaryHeap<T> {
fn extend<Iter: Iterator<Item=T>>(&mut self, iter: Iter) { fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
let iter = iterable.into_iter();
let (lower, _) = iter.size_hint(); let (lower, _) = iter.size_hint();
self.reserve(lower); self.reserve(lower);

View File

@ -934,7 +934,8 @@ impl FromIterator<bool> for BitVec {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Extend<bool> for BitVec { impl Extend<bool> for BitVec {
#[inline] #[inline]
fn extend<I: Iterator<Item=bool>>(&mut self, iterator: I) { fn extend<I: IntoIterator<Item=bool>>(&mut self, iterable: I) {
let iterator = iterable.into_iter();
let (min, _) = iterator.size_hint(); let (min, _) = iterator.size_hint();
self.reserve(min); self.reserve(min);
for element in iterator { for element in iterator {
@ -1143,8 +1144,8 @@ impl FromIterator<usize> for BitSet {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Extend<usize> for BitSet { impl Extend<usize> for BitSet {
#[inline] #[inline]
fn extend<I: Iterator<Item=usize>>(&mut self, iterator: I) { fn extend<I: IntoIterator<Item=usize>>(&mut self, iter: I) {
for i in iterator { for i in iter {
self.insert(i); self.insert(i);
} }
} }

View File

@ -836,7 +836,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> { impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> {
#[inline] #[inline]
fn extend<T: Iterator<Item=(K, V)>>(&mut self, iter: T) { fn extend<T: IntoIterator<Item=(K, V)>>(&mut self, iter: T) {
for (k, v) in iter { for (k, v) in iter {
self.insert(k, v); self.insert(k, v);
} }

View File

@ -503,7 +503,7 @@ impl<'a, T> IntoIterator for &'a BTreeSet<T> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Extend<T> for BTreeSet<T> { impl<T: Ord> Extend<T> for BTreeSet<T> {
#[inline] #[inline]
fn extend<Iter: Iterator<Item=T>>(&mut self, iter: Iter) { fn extend<Iter: IntoIterator<Item=T>>(&mut self, iter: Iter) {
for elem in iter { for elem in iter {
self.insert(elem); self.insert(elem);
} }

View File

@ -268,8 +268,8 @@ impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike {
} }
impl<E:CLike> Extend<E> for EnumSet<E> { impl<E:CLike> Extend<E> for EnumSet<E> {
fn extend<I: Iterator<Item=E>>(&mut self, iterator: I) { fn extend<I: IntoIterator<Item=E>>(&mut self, iter: I) {
for element in iterator { for element in iter {
self.insert(element); self.insert(element);
} }
} }

View File

@ -872,8 +872,8 @@ impl<'a, T> IntoIterator for &'a mut LinkedList<T> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A> Extend<A> for LinkedList<A> { impl<A> Extend<A> for LinkedList<A> {
fn extend<T: Iterator<Item=A>>(&mut self, iterator: T) { fn extend<T: IntoIterator<Item=A>>(&mut self, iter: T) {
for elt in iterator { self.push_back(elt); } for elt in iter { self.push_back(elt); }
} }
} }

View File

@ -21,7 +21,7 @@ use core::default::Default;
use core::error::Error; use core::error::Error;
use core::fmt; use core::fmt;
use core::hash; use core::hash;
use core::iter::FromIterator; use core::iter::{IntoIterator, FromIterator};
use core::mem; use core::mem;
use core::ops::{self, Deref, Add, Index}; use core::ops::{self, Deref, Add, Index};
use core::ptr; use core::ptr;
@ -728,7 +728,8 @@ impl<'a> FromIterator<&'a str> for String {
#[unstable(feature = "collections", #[unstable(feature = "collections",
reason = "waiting on Extend stabilization")] reason = "waiting on Extend stabilization")]
impl Extend<char> for String { impl Extend<char> for String {
fn extend<I:Iterator<Item=char>>(&mut self, iterator: I) { fn extend<I: IntoIterator<Item=char>>(&mut self, iterable: I) {
let iterator = iterable.into_iter();
let (lower_bound, _) = iterator.size_hint(); let (lower_bound, _) = iterator.size_hint();
self.reserve(lower_bound); self.reserve(lower_bound);
for ch in iterator { for ch in iterator {
@ -740,7 +741,8 @@ impl Extend<char> for String {
#[unstable(feature = "collections", #[unstable(feature = "collections",
reason = "waiting on Extend stabilization")] reason = "waiting on Extend stabilization")]
impl<'a> Extend<&'a str> for String { impl<'a> Extend<&'a str> for String {
fn extend<I: Iterator<Item=&'a str>>(&mut self, iterator: I) { fn extend<I: IntoIterator<Item=&'a str>>(&mut self, iterable: I) {
let iterator = iterable.into_iter();
// A guess that at least one byte per iterator element will be needed. // A guess that at least one byte per iterator element will be needed.
let (lower_bound, _) = iterator.size_hint(); let (lower_bound, _) = iterator.size_hint();
self.reserve(lower_bound); self.reserve(lower_bound);

View File

@ -1480,7 +1480,8 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
#[unstable(feature = "collections", reason = "waiting on Extend stability")] #[unstable(feature = "collections", reason = "waiting on Extend stability")]
impl<T> Extend<T> for Vec<T> { impl<T> Extend<T> for Vec<T> {
#[inline] #[inline]
fn extend<I: Iterator<Item=T>>(&mut self, iterator: I) { fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
let iterator = iterable.into_iter();
let (lower, _) = iterator.size_hint(); let (lower, _) = iterator.size_hint();
self.reserve(lower); self.reserve(lower);
for element in iterator { for element in iterator {

View File

@ -1741,8 +1741,8 @@ impl<'a, T> IntoIterator for &'a mut VecDeque<T> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<A> Extend<A> for VecDeque<A> { impl<A> Extend<A> for VecDeque<A> {
fn extend<T: Iterator<Item=A>>(&mut self, iterator: T) { fn extend<T: IntoIterator<Item=A>>(&mut self, iter: T) {
for elt in iterator { for elt in iter {
self.push_back(elt); self.push_back(elt);
} }
} }

View File

@ -700,7 +700,7 @@ impl<'a, T> IntoIterator for &'a mut VecMap<T> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<V> Extend<(usize, V)> for VecMap<V> { impl<V> Extend<(usize, V)> for VecMap<V> {
fn extend<Iter: Iterator<Item=(usize, V)>>(&mut self, iter: Iter) { fn extend<I: IntoIterator<Item=(usize, V)>>(&mut self, iter: I) {
for (k, v) in iter { for (k, v) in iter {
self.insert(k, v); self.insert(k, v);
} }

View File

@ -147,7 +147,7 @@ impl<I: Iterator> IntoIterator for I {
pub trait Extend<A> { pub trait Extend<A> {
/// Extend a container with the elements yielded by an arbitrary iterator /// Extend a container with the elements yielded by an arbitrary iterator
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
fn extend<T: Iterator<Item=A>>(&mut self, iterator: T); fn extend<T: IntoIterator<Item=A>>(&mut self, iterable: T);
} }
/// An extension trait providing numerous methods applicable to all iterators. /// An extension trait providing numerous methods applicable to all iterators.

View File

@ -1570,7 +1570,7 @@ impl<K, V, S, H> Extend<(K, V)> for HashMap<K, V, S>
S: HashState<Hasher=H>, S: HashState<Hasher=H>,
H: hash::Hasher<Output=u64> H: hash::Hasher<Output=u64>
{ {
fn extend<T: Iterator<Item=(K, V)>>(&mut self, iter: T) { fn extend<T: IntoIterator<Item=(K, V)>>(&mut self, iter: T) {
for (k, v) in iter { for (k, v) in iter {
self.insert(k, v); self.insert(k, v);
} }

View File

@ -636,7 +636,7 @@ impl<T, S, H> Extend<T> for HashSet<T, S>
S: HashState<Hasher=H>, S: HashState<Hasher=H>,
H: hash::Hasher<Output=u64> H: hash::Hasher<Output=u64>
{ {
fn extend<I: Iterator<Item=T>>(&mut self, iter: I) { fn extend<I: IntoIterator<Item=T>>(&mut self, iter: I) {
for k in iter { for k in iter {
self.insert(k); self.insert(k);
} }

View File

@ -110,7 +110,7 @@ use core::prelude::*;
use ascii::*; use ascii::*;
use borrow::BorrowFrom; use borrow::BorrowFrom;
use cmp; use cmp;
use iter; use iter::{self, IntoIterator};
use mem; use mem;
use ops::{self, Deref}; use ops::{self, Deref};
use string::CowString; use string::CowString;
@ -961,7 +961,7 @@ impl<'a, P: ?Sized + 'a> iter::FromIterator<&'a P> for PathBuf where P: AsPath {
} }
impl<'a, P: ?Sized + 'a> iter::Extend<&'a P> for PathBuf where P: AsPath { impl<'a, P: ?Sized + 'a> iter::Extend<&'a P> for PathBuf where P: AsPath {
fn extend<I: Iterator<Item = &'a P>>(&mut self, iter: I) { fn extend<I: IntoIterator<Item = &'a P>>(&mut self, iter: I) {
for p in iter { for p in iter {
self.push(p) self.push(p)
} }

View File

@ -32,7 +32,7 @@ use borrow::Cow;
use cmp; use cmp;
use fmt; use fmt;
use hash::{Hash, Writer, Hasher}; use hash::{Hash, Writer, Hasher};
use iter::FromIterator; use iter::{FromIterator, IntoIterator};
use mem; use mem;
use num::Int; use num::Int;
use ops; use ops;
@ -368,7 +368,8 @@ impl FromIterator<CodePoint> for Wtf8Buf {
/// This replaces surrogate code point pairs with supplementary code points, /// This replaces surrogate code point pairs with supplementary code points,
/// like concatenating ill-formed UTF-16 strings effectively would. /// like concatenating ill-formed UTF-16 strings effectively would.
impl Extend<CodePoint> for Wtf8Buf { impl Extend<CodePoint> for Wtf8Buf {
fn extend<T: Iterator<Item=CodePoint>>(&mut self, iterator: T) { fn extend<T: IntoIterator<Item=CodePoint>>(&mut self, iterable: T) {
let iterator = iterable.into_iter();
let (low, _high) = iterator.size_hint(); let (low, _high) = iterator.size_hint();
// Lower bound of one byte per code point (ASCII only) // Lower bound of one byte per code point (ASCII only)
self.bytes.reserve(low); self.bytes.reserve(low);

View File

@ -11,7 +11,7 @@
use self::SmallVectorRepr::*; use self::SmallVectorRepr::*;
use self::IntoIterRepr::*; use self::IntoIterRepr::*;
use std::iter::FromIterator; use std::iter::{IntoIterator, FromIterator};
use std::mem; use std::mem;
use std::slice; use std::slice;
use std::vec; use std::vec;
@ -38,7 +38,7 @@ impl<T> FromIterator<T> for SmallVector<T> {
} }
impl<T> Extend<T> for SmallVector<T> { impl<T> Extend<T> for SmallVector<T> {
fn extend<I: Iterator<Item=T>>(&mut self, iter: I) { fn extend<I: IntoIterator<Item=T>>(&mut self, iter: I) {
for val in iter { for val in iter {
self.push(val); self.push(val);
} }