diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 11576fbb00c9b..66374b639c1a6 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -255,7 +255,7 @@ impl BinaryHeap { /// /// // Print 1, 2, 3, 4 in arbitrary order /// for x in heap.into_iter() { - /// // x has type int, not &int + /// // x has type i32, not &i32 /// println!("{}", x); /// } /// ``` diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 0e4a4002d6a09..895fa076ab604 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -1783,7 +1783,7 @@ mod test { fn test_entry(){ let xs = [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)]; - let mut map: BTreeMap<_, _> = xs.iter().map(|&x| x).collect(); + let mut map: BTreeMap<_, _> = xs.iter().cloned().collect(); // Existing key (insert) match map.entry(1) { diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 7cb31ab1f6dbe..8628879295b83 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -89,7 +89,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let mut set: BTreeSet = BTreeSet::new(); + /// let mut set: BTreeSet = BTreeSet::new(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> BTreeSet { @@ -114,13 +114,13 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let set: BTreeSet = [1, 2, 3, 4].iter().map(|&x| x).collect(); + /// let set: BTreeSet = [1, 2, 3, 4].iter().cloned().collect(); /// /// for x in set.iter() { /// println!("{}", x); /// } /// - /// let v: Vec = set.iter().map(|&x| x).collect(); + /// let v: Vec = set.iter().cloned().collect(); /// assert_eq!(v, vec![1,2,3,4]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -135,7 +135,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let set: BTreeSet = [1, 2, 3, 4].iter().map(|&x| x).collect(); + /// let set: BTreeSet = [1, 2, 3, 4].iter().cloned().collect(); /// /// let v: Vec = set.into_iter().collect(); /// assert_eq!(v, vec![1,2,3,4]); @@ -331,7 +331,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let set: BTreeSet = [1, 2, 3].iter().map(|&x| x).collect(); + /// let set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); /// assert_eq!(set.contains(&1), true); /// assert_eq!(set.contains(&4), false); /// ``` @@ -348,8 +348,8 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let a: BTreeSet = [1, 2, 3].iter().map(|&x| x).collect(); - /// let mut b: BTreeSet = BTreeSet::new(); + /// let a: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let mut b = BTreeSet::new(); /// /// assert_eq!(a.is_disjoint(&b), true); /// b.insert(4); @@ -369,8 +369,8 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let sup: BTreeSet = [1, 2, 3].iter().map(|&x| x).collect(); - /// let mut set: BTreeSet = BTreeSet::new(); + /// let sup: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let mut set = BTreeSet::new(); /// /// assert_eq!(set.is_subset(&sup), true); /// set.insert(2); @@ -411,8 +411,8 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let sub: BTreeSet = [1, 2].iter().map(|&x| x).collect(); - /// let mut set: BTreeSet = BTreeSet::new(); + /// let sub: BTreeSet<_> = [1, 2].iter().cloned().collect(); + /// let mut set = BTreeSet::new(); /// /// assert_eq!(set.is_superset(&sub), false); /// @@ -525,11 +525,11 @@ impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet> for &'a BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let a: BTreeSet = vec![1, 2, 3].into_iter().collect(); - /// let b: BTreeSet = vec![3, 4, 5].into_iter().collect(); + /// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect(); + /// let b: BTreeSet<_> = vec![3, 4, 5].into_iter().collect(); /// - /// let result: BTreeSet = &a - &b; - /// let result_vec: Vec = result.into_iter().collect(); + /// let result = &a - &b; + /// let result_vec: Vec<_> = result.into_iter().collect(); /// assert_eq!(result_vec, vec![1, 2]); /// ``` fn sub(self, rhs: &BTreeSet) -> BTreeSet { @@ -548,11 +548,11 @@ impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet> for &'a BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let a: BTreeSet = vec![1, 2, 3].into_iter().collect(); - /// let b: BTreeSet = vec![2, 3, 4].into_iter().collect(); + /// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect(); + /// let b: BTreeSet<_> = vec![2, 3, 4].into_iter().collect(); /// - /// let result: BTreeSet = &a ^ &b; - /// let result_vec: Vec = result.into_iter().collect(); + /// let result = &a ^ &b; + /// let result_vec: Vec<_> = result.into_iter().collect(); /// assert_eq!(result_vec, vec![1, 4]); /// ``` fn bitxor(self, rhs: &BTreeSet) -> BTreeSet { @@ -571,11 +571,11 @@ impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet> for &'a BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let a: BTreeSet = vec![1, 2, 3].into_iter().collect(); - /// let b: BTreeSet = vec![2, 3, 4].into_iter().collect(); + /// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect(); + /// let b: BTreeSet<_> = vec![2, 3, 4].into_iter().collect(); /// - /// let result: BTreeSet = &a & &b; - /// let result_vec: Vec = result.into_iter().collect(); + /// let result = &a & &b; + /// let result_vec: Vec<_> = result.into_iter().collect(); /// assert_eq!(result_vec, vec![2, 3]); /// ``` fn bitand(self, rhs: &BTreeSet) -> BTreeSet { @@ -594,11 +594,11 @@ impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet> for &'a BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let a: BTreeSet = vec![1, 2, 3].into_iter().collect(); - /// let b: BTreeSet = vec![3, 4, 5].into_iter().collect(); + /// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect(); + /// let b: BTreeSet<_> = vec![3, 4, 5].into_iter().collect(); /// - /// let result: BTreeSet = &a | &b; - /// let result_vec: Vec = result.into_iter().collect(); + /// let result = &a | &b; + /// let result_vec: Vec<_> = result.into_iter().collect(); /// assert_eq!(result_vec, vec![1, 2, 3, 4, 5]); /// ``` fn bitor(self, rhs: &BTreeSet) -> BTreeSet { diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index a080146e0ec50..356df24611b37 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -756,7 +756,7 @@ impl<'a, A> IterMut<'a, A> { /// ``` /// use std::collections::DList; /// - /// let mut list: DList = vec![1, 3, 4].into_iter().collect(); + /// let mut list: DList<_> = vec![1, 3, 4].into_iter().collect(); /// /// { /// let mut it = list.iter_mut(); @@ -765,7 +765,7 @@ impl<'a, A> IterMut<'a, A> { /// it.insert_next(2); /// } /// { - /// let vec: Vec = list.into_iter().collect(); + /// let vec: Vec<_> = list.into_iter().collect(); /// assert_eq!(vec, vec![1, 2, 3, 4]); /// } /// ``` @@ -783,7 +783,7 @@ impl<'a, A> IterMut<'a, A> { /// ``` /// use std::collections::DList; /// - /// let mut list: DList = vec![1, 2, 3].into_iter().collect(); + /// let mut list: DList<_> = vec![1, 2, 3].into_iter().collect(); /// /// let mut it = list.iter_mut(); /// assert_eq!(it.next().unwrap(), &1); diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index 8f02f9fd580fa..0892a1c200885 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -108,7 +108,7 @@ //! There are various parameters which do require a particular type, however. //! Namely if the syntax `{:.*}` is used, then the number of characters to print //! precedes the actual object being formatted, and the number of characters -//! must have the type `uint`. Although a `uint` can be printed with `{}`, it is +//! must have the type `usize`. Although a `usize` can be printed with `{}`, it is //! illegal to reference an argument as such. For example this is another //! invalid format string: //! @@ -121,7 +121,7 @@ //! When requesting that an argument be formatted with a particular type, you //! are actually requesting that an argument ascribes to a particular trait. //! This allows multiple actual types to be formatted via `{:x}` (like `i8` as -//! well as `int`). The current mapping of types to traits is: +//! well as `isize`). The current mapping of types to traits is: //! //! * *nothing* ⇒ `Display` //! * `?` ⇒ `Debug` @@ -173,8 +173,8 @@ //! //! #[derive(Debug)] //! struct Vector2D { -//! x: int, -//! y: int, +//! x: isize, +//! y: isize, //! } //! //! impl fmt::Display for Vector2D { @@ -380,9 +380,9 @@ //! the '0' flag is specified for numerics, then the implicit fill character is //! '0'. //! -//! The value for the width can also be provided as a `uint` in the list of +//! The value for the width can also be provided as a `usize` in the list of //! parameters by using the `2$` syntax indicating that the second argument is a -//! `uint` specifying the width. +//! `usize` specifying the width. //! //! ### Precision //! diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index b3f398b9cdf49..945cceddfb5e1 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -73,7 +73,7 @@ //! //! The method `iter()` returns an iteration value for a slice. The iterator //! yields references to the slice's elements, so if the element -//! type of the slice is `int`, the element type of the iterator is `&int`. +//! type of the slice is `isize`, the element type of the iterator is `&isize`. //! //! ```rust //! let numbers = [0, 1, 2]; @@ -1218,7 +1218,7 @@ impl Iterator for ElementSwaps { // Find the index of the largest mobile element: // The direction should point into the vector, and the // swap should be with a smaller `size` element. - let max = self.sdir.iter().map(|&x| x).enumerate() + let max = self.sdir.iter().cloned().enumerate() .filter(|&(i, sd)| new_pos(i, sd.dir) < self.sdir.len() && self.sdir[new_pos(i, sd.dir)].size < sd.size) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index edb6d2de1c850..8382acfe3da05 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -2705,22 +2705,22 @@ mod tests { for &(s, g) in &test_same[] { // test forward iterator - assert!(order::equals(s.graphemes(true), g.iter().map(|&x| x))); - assert!(order::equals(s.graphemes(false), g.iter().map(|&x| x))); + assert!(order::equals(s.graphemes(true), g.iter().cloned())); + assert!(order::equals(s.graphemes(false), g.iter().cloned())); // test reverse iterator - assert!(order::equals(s.graphemes(true).rev(), g.iter().rev().map(|&x| x))); - assert!(order::equals(s.graphemes(false).rev(), g.iter().rev().map(|&x| x))); + assert!(order::equals(s.graphemes(true).rev(), g.iter().rev().cloned())); + assert!(order::equals(s.graphemes(false).rev(), g.iter().rev().cloned())); } for &(s, gt, gf) in &test_diff { // test forward iterator - assert!(order::equals(s.graphemes(true), gt.iter().map(|&x| x))); - assert!(order::equals(s.graphemes(false), gf.iter().map(|&x| x))); + assert!(order::equals(s.graphemes(true), gt.iter().cloned())); + assert!(order::equals(s.graphemes(false), gf.iter().cloned())); // test reverse iterator - assert!(order::equals(s.graphemes(true).rev(), gt.iter().rev().map(|&x| x))); - assert!(order::equals(s.graphemes(false).rev(), gf.iter().rev().map(|&x| x))); + assert!(order::equals(s.graphemes(true).rev(), gt.iter().rev().cloned())); + assert!(order::equals(s.graphemes(false).rev(), gf.iter().rev().cloned())); } // test the indices iterators diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 341d91538adb6..ad3adc0ddb551 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -158,7 +158,7 @@ impl Vec { /// # Examples /// /// ``` - /// let mut vec: Vec = Vec::new(); + /// let mut vec: Vec = Vec::new(); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -277,7 +277,7 @@ impl Vec { /// # Examples /// /// ``` - /// let vec: Vec = Vec::with_capacity(10); + /// let vec: Vec = Vec::with_capacity(10); /// assert_eq!(vec.capacity(), 10); /// ``` #[inline] @@ -296,7 +296,7 @@ impl Vec { /// # Examples /// /// ``` - /// let mut vec: Vec = vec![1]; + /// let mut vec = vec![1]; /// vec.reserve(10); /// assert!(vec.capacity() >= 11); /// ``` @@ -325,7 +325,7 @@ impl Vec { /// # Examples /// /// ``` - /// let mut vec: Vec = vec![1]; + /// let mut vec = vec![1]; /// vec.reserve_exact(10); /// assert!(vec.capacity() >= 11); /// ``` @@ -347,7 +347,7 @@ impl Vec { /// # Examples /// /// ``` - /// let mut vec: Vec = Vec::with_capacity(10); + /// let mut vec = Vec::with_capacity(10); /// vec.push_all(&[1, 2, 3]); /// assert_eq!(vec.capacity(), 10); /// vec.shrink_to_fit(); @@ -424,7 +424,7 @@ impl Vec { /// # Examples /// /// ``` - /// fn foo(slice: &mut [int]) {} + /// fn foo(slice: &mut [i32]) {} /// /// let mut vec = vec![1, 2]; /// foo(vec.as_mut_slice()); @@ -845,7 +845,7 @@ impl Vec { // This `as isize` cast is safe, because the size of the elements of the // vector is not 0, and: // - // 1) If the size of the elements in the vector is 1, the `int` may + // 1) If the size of the elements in the vector is 1, the `isize` may // overflow, but it has the correct bit pattern so that the // `.offset()` function will work. // @@ -858,7 +858,7 @@ impl Vec { // (0x1 + 0x8 = 0x1 - 0x8) // // 2) If the size of the elements in the vector is >1, the `usize` -> - // `int` conversion can't overflow. + // `isize` conversion can't overflow. let offset = vec.len() as isize; let start = vec.as_mut_ptr(); @@ -1518,7 +1518,7 @@ impl AsSlice for Vec { /// # Examples /// /// ``` - /// fn foo(slice: &[int]) {} + /// fn foo(slice: &[i32]) {} /// /// let vec = vec![1, 2]; /// foo(vec.as_slice()); @@ -2162,7 +2162,7 @@ mod tests { fn test_zip_unzip() { let z1 = vec![(1, 4), (2, 5), (3, 6)]; - let (left, right): (Vec<_>, Vec<_>) = z1.iter().map(|&x| x).unzip(); + let (left, right): (Vec<_>, Vec<_>) = z1.iter().cloned().unzip(); assert_eq!((1, 4), (left[0], right[0])); assert_eq!((2, 5), (left[1], right[1])); diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index de3c0424c9a85..96af556dbccb7 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -104,7 +104,7 @@ impl + Eq> HashSet { /// /// ``` /// use std::collections::HashSet; - /// let mut set: HashSet = HashSet::new(); + /// let mut set: HashSet = HashSet::new(); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -119,7 +119,7 @@ impl + Eq> HashSet { /// /// ``` /// use std::collections::HashSet; - /// let mut set: HashSet = HashSet::with_capacity(10); + /// let mut set: HashSet = HashSet::with_capacity(10); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -187,7 +187,7 @@ impl HashSet /// /// ``` /// use std::collections::HashSet; - /// let set: HashSet = HashSet::with_capacity(100); + /// let set: HashSet = HashSet::with_capacity(100); /// assert!(set.capacity() >= 100); /// ``` #[inline] @@ -208,7 +208,7 @@ impl HashSet /// /// ``` /// use std::collections::HashSet; - /// let mut set: HashSet = HashSet::new(); + /// let mut set: HashSet = HashSet::new(); /// set.reserve(10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -225,7 +225,7 @@ impl HashSet /// ``` /// use std::collections::HashSet; /// - /// let mut set: HashSet = HashSet::with_capacity(100); + /// let mut set = HashSet::with_capacity(100); /// set.insert(1); /// set.insert(2); /// assert!(set.capacity() >= 100); @@ -292,21 +292,21 @@ impl HashSet /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet = [1, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet = [4, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); /// /// // Can be seen as `a - b`. /// for x in a.difference(&b) { /// println!("{}", x); // Print 1 /// } /// - /// let diff: HashSet = a.difference(&b).map(|&x| x).collect(); - /// assert_eq!(diff, [1].iter().map(|&x| x).collect()); + /// let diff: HashSet<_> = a.difference(&b).cloned().collect(); + /// assert_eq!(diff, [1].iter().cloned().collect()); /// /// // Note that difference is not symmetric, /// // and `b - a` means something else: - /// let diff: HashSet = b.difference(&a).map(|&x| x).collect(); - /// assert_eq!(diff, [4].iter().map(|&x| x).collect()); + /// let diff: HashSet<_> = b.difference(&a).cloned().collect(); + /// assert_eq!(diff, [4].iter().cloned().collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn difference<'a>(&'a self, other: &'a HashSet) -> Difference<'a, T, S> { @@ -322,19 +322,19 @@ impl HashSet /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet = [1, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet = [4, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); /// /// // Print 1, 4 in arbitrary order. /// for x in a.symmetric_difference(&b) { /// println!("{}", x); /// } /// - /// let diff1: HashSet = a.symmetric_difference(&b).map(|&x| x).collect(); - /// let diff2: HashSet = b.symmetric_difference(&a).map(|&x| x).collect(); + /// let diff1: HashSet<_> = a.symmetric_difference(&b).cloned().collect(); + /// let diff2: HashSet<_> = b.symmetric_difference(&a).cloned().collect(); /// /// assert_eq!(diff1, diff2); - /// assert_eq!(diff1, [1, 4].iter().map(|&x| x).collect()); + /// assert_eq!(diff1, [1, 4].iter().cloned().collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn symmetric_difference<'a>(&'a self, other: &'a HashSet) @@ -348,16 +348,16 @@ impl HashSet /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet = [1, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet = [4, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); /// /// // Print 2, 3 in arbitrary order. /// for x in a.intersection(&b) { /// println!("{}", x); /// } /// - /// let diff: HashSet = a.intersection(&b).map(|&x| x).collect(); - /// assert_eq!(diff, [2, 3].iter().map(|&x| x).collect()); + /// let diff: HashSet<_> = a.intersection(&b).cloned().collect(); + /// assert_eq!(diff, [2, 3].iter().cloned().collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn intersection<'a>(&'a self, other: &'a HashSet) -> Intersection<'a, T, S> { @@ -373,16 +373,16 @@ impl HashSet /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet = [1, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet = [4, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); /// /// // Print 1, 2, 3, 4 in arbitrary order. /// for x in a.union(&b) { /// println!("{}", x); /// } /// - /// let diff: HashSet = a.union(&b).map(|&x| x).collect(); - /// assert_eq!(diff, [1, 2, 3, 4].iter().map(|&x| x).collect()); + /// let diff: HashSet<_> = a.union(&b).cloned().collect(); + /// assert_eq!(diff, [1, 2, 3, 4].iter().cloned().collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn union<'a>(&'a self, other: &'a HashSet) -> Union<'a, T, S> { diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index 55924bc73a8d5..be441bfec8865 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -65,8 +65,8 @@ //! * You want a sorted map. //! //! ### Use a `VecMap` when: -//! * You want a `HashMap` but with known to be small `uint` keys. -//! * You want a `BTreeMap`, but with known to be small `uint` keys. +//! * You want a `HashMap` but with known to be small `usize` keys. +//! * You want a `BTreeMap`, but with known to be small `usize` keys. //! //! ### Use the `Set` variant of any of these `Map`s when: //! * You just want to remember which keys you've seen. @@ -243,7 +243,7 @@ //! use std::collections::RingBuf; //! //! let vec = vec![1, 2, 3, 4]; -//! let buf: RingBuf = vec.into_iter().collect(); +//! let buf: RingBuf<_> = vec.into_iter().collect(); //! ``` //! //! Iterators also provide a series of *adapter* methods for performing common tasks to