From 4e4374b7de0beec459f6d9db8e06f2cad0c969e7 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Tue, 19 May 2015 03:33:17 +0200 Subject: [PATCH 1/3] collections: Avoid unstable code in examples for String Prefer String::from over from_str; String::from_str is unstable while String::from is stable. Promote the latter by using it in examples. Simply migrating unstable function to the closest alternative. --- src/liballoc/rc.rs | 4 ++-- src/libcollections/string.rs | 30 +++++++++--------------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 88c5c38172a..1e773b7f206 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -32,7 +32,7 @@ //! and have the `Owner` remain allocated as long as any `Gadget` points at it. //! //! ```rust -//! # #![feature(alloc, collections)] +//! # #![feature(alloc)] //! use std::rc::Rc; //! //! struct Owner { @@ -49,7 +49,7 @@ //! fn main() { //! // Create a reference counted Owner. //! let gadget_owner : Rc = Rc::new( -//! Owner { name: String::from_str("Gadget Man") } +//! Owner { name: String::from("Gadget Man") } //! ); //! //! // Create Gadgets belonging to gadget_owner. To increment the reference diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 1f2443d9771..7563bb76b52 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -121,9 +121,6 @@ impl String { /// # Examples /// /// ``` - /// # #![feature(core)] - /// use std::str::Utf8Error; - /// /// let hello_vec = vec![104, 101, 108, 108, 111]; /// let s = String::from_utf8(hello_vec).unwrap(); /// assert_eq!(s, "hello"); @@ -346,8 +343,7 @@ impl String { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let s = String::from_str("hello"); + /// let s = String::from("hello"); /// let bytes = s.into_bytes(); /// assert_eq!(bytes, [104, 101, 108, 108, 111]); /// ``` @@ -370,8 +366,7 @@ impl String { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("foo"); + /// let mut s = String::from("foo"); /// s.push_str("bar"); /// assert_eq!(s, "foobar"); /// ``` @@ -447,8 +442,7 @@ impl String { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("foo"); + /// let mut s = String::from("foo"); /// s.reserve(100); /// assert!(s.capacity() >= 100); /// s.shrink_to_fit(); @@ -465,8 +459,7 @@ impl String { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("abc"); + /// let mut s = String::from("abc"); /// s.push('1'); /// s.push('2'); /// s.push('3'); @@ -501,8 +494,7 @@ impl String { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let s = String::from_str("hello"); + /// let s = String::from("hello"); /// let b: &[_] = &[104, 101, 108, 108, 111]; /// assert_eq!(s.as_bytes(), b); /// ``` @@ -522,8 +514,7 @@ impl String { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("hello"); + /// let mut s = String::from("hello"); /// s.truncate(2); /// assert_eq!(s, "he"); /// ``` @@ -540,8 +531,7 @@ impl String { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("foo"); + /// let mut s = String::from("foo"); /// assert_eq!(s.pop(), Some('o')); /// assert_eq!(s.pop(), Some('o')); /// assert_eq!(s.pop(), Some('f')); @@ -578,8 +568,7 @@ impl String { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("foo"); + /// let mut s = String::from("foo"); /// assert_eq!(s.remove(0), 'f'); /// assert_eq!(s.remove(1), 'o'); /// assert_eq!(s.remove(0), 'o'); @@ -641,8 +630,7 @@ impl String { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("hello"); + /// let mut s = String::from("hello"); /// unsafe { /// let vec = s.as_mut_vec(); /// assert!(vec == &[104, 101, 108, 108, 111]); From 4a53456628a90ac5c3a4c0be306ec8119a52483e Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Tue, 19 May 2015 03:33:17 +0200 Subject: [PATCH 2/3] collections: Avoid unstable code in examples for Vec --- src/libcollections/vec.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index d3315758df0..5ec71b7353c 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -91,7 +91,6 @@ static MAX_MEMORY_SIZE: usize = isize::MAX as usize; /// # Examples /// /// ``` -/// # #![feature(collections)] /// let mut vec = Vec::new(); /// vec.push(1); /// vec.push(2); @@ -105,9 +104,9 @@ static MAX_MEMORY_SIZE: usize = isize::MAX as usize; /// vec[0] = 7; /// assert_eq!(vec[0], 7); /// -/// vec.push_all(&[1, 2, 3]); +/// vec.extend([1, 2, 3].iter().cloned()); /// -/// for x in vec.iter() { +/// for x in &vec { /// println!("{}", x); /// } /// assert_eq!(vec, [7, 1, 2, 3]); @@ -369,9 +368,8 @@ impl Vec { /// # Examples /// /// ``` - /// # #![feature(collections)] /// let mut vec = Vec::with_capacity(10); - /// vec.push_all(&[1, 2, 3]); + /// vec.extend([1, 2, 3].iter().cloned()); /// assert_eq!(vec.capacity(), 10); /// vec.shrink_to_fit(); /// assert!(vec.capacity() >= 3); @@ -425,7 +423,6 @@ impl Vec { /// # Examples /// /// ``` - /// # #![feature(collections)] /// let mut vec = vec![1, 2, 3, 4]; /// vec.truncate(2); /// assert_eq!(vec, [1, 2]); @@ -555,7 +552,6 @@ impl Vec { /// # Examples /// /// ``` - /// # #![feature(collections)] /// let mut v = vec![1, 2, 3]; /// assert_eq!(v.remove(1), 2); /// assert_eq!(v, [1, 3]); @@ -743,7 +739,7 @@ impl Vec { /// # Examples /// /// ``` - /// # #![feature(collections_drain, collections_range)] + /// # #![feature(collections_drain)] /// /// // Draining using `..` clears the whole vector. /// let mut v = vec![1, 2, 3]; From 93701b399b2d3cbb056c1eaaf1fba421585bb2bd Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Tue, 19 May 2015 03:33:17 +0200 Subject: [PATCH 3/3] collections: Clean up feature flags doc examples --- src/libcollections/btree/map.rs | 5 +---- src/libcollections/btree/set.rs | 22 ++++++---------------- src/libcollections/linked_list.rs | 5 ----- src/libcollections/slice.rs | 2 -- src/libcollections/vec_deque.rs | 6 ------ 5 files changed, 7 insertions(+), 33 deletions(-) diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 291b66939e5..c5de4d3572c 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -1291,14 +1291,13 @@ impl BTreeMap { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeMap; /// /// let mut a = BTreeMap::new(); /// a.insert(1, "a"); /// a.insert(2, "b"); /// - /// let keys: Vec = a.keys().cloned().collect(); + /// let keys: Vec<_> = a.keys().cloned().collect(); /// assert_eq!(keys, [1, 2]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -1314,7 +1313,6 @@ impl BTreeMap { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeMap; /// /// let mut a = BTreeMap::new(); @@ -1555,7 +1553,6 @@ impl BTreeMap { /// # Examples /// /// ``` - /// # #![feature(collections)] /// use std::collections::BTreeMap; /// /// let mut count: BTreeMap<&str, usize> = BTreeMap::new(); diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index fc346151e0b..e9878b96653 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -115,7 +115,6 @@ impl BTreeSet { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let set: BTreeSet = [1, 2, 3, 4].iter().cloned().collect(); @@ -124,7 +123,7 @@ impl BTreeSet { /// println!("{}", x); /// } /// - /// let v: Vec = set.iter().cloned().collect(); + /// let v: Vec<_> = set.iter().cloned().collect(); /// assert_eq!(v, [1, 2, 3, 4]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -171,7 +170,6 @@ impl BTreeSet { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let mut a = BTreeSet::new(); @@ -182,7 +180,7 @@ impl BTreeSet { /// b.insert(2); /// b.insert(3); /// - /// let diff: Vec = a.difference(&b).cloned().collect(); + /// let diff: Vec<_> = a.difference(&b).cloned().collect(); /// assert_eq!(diff, [1]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -195,7 +193,6 @@ impl BTreeSet { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let mut a = BTreeSet::new(); @@ -206,7 +203,7 @@ impl BTreeSet { /// b.insert(2); /// b.insert(3); /// - /// let sym_diff: Vec = a.symmetric_difference(&b).cloned().collect(); + /// let sym_diff: Vec<_> = a.symmetric_difference(&b).cloned().collect(); /// assert_eq!(sym_diff, [1, 3]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -220,7 +217,6 @@ impl BTreeSet { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let mut a = BTreeSet::new(); @@ -231,7 +227,7 @@ impl BTreeSet { /// b.insert(2); /// b.insert(3); /// - /// let intersection: Vec = a.intersection(&b).cloned().collect(); + /// let intersection: Vec<_> = a.intersection(&b).cloned().collect(); /// assert_eq!(intersection, [2]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -245,7 +241,6 @@ impl BTreeSet { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let mut a = BTreeSet::new(); @@ -254,7 +249,7 @@ impl BTreeSet { /// let mut b = BTreeSet::new(); /// b.insert(2); /// - /// let union: Vec = a.union(&b).cloned().collect(); + /// let union: Vec<_> = a.union(&b).cloned().collect(); /// assert_eq!(union, [1, 2]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -318,7 +313,6 @@ impl BTreeSet { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); @@ -336,7 +330,6 @@ impl BTreeSet { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let a: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); @@ -358,7 +351,6 @@ impl BTreeSet { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let sup: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); @@ -401,7 +393,6 @@ impl BTreeSet { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let sub: BTreeSet<_> = [1, 2].iter().cloned().collect(); @@ -483,12 +474,11 @@ impl IntoIterator for BTreeSet { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let set: BTreeSet = [1, 2, 3, 4].iter().cloned().collect(); /// - /// let v: Vec = set.into_iter().collect(); + /// let v: Vec<_> = set.into_iter().collect(); /// assert_eq!(v, [1, 2, 3, 4]); /// ``` fn into_iter(self) -> IntoIter { diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs index f6dc5cf7d90..669f05b33ca 100644 --- a/src/libcollections/linked_list.rs +++ b/src/libcollections/linked_list.rs @@ -230,7 +230,6 @@ impl LinkedList { /// # Examples /// /// ``` - /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut a = LinkedList::new(); @@ -473,7 +472,6 @@ impl LinkedList { /// # Examples /// /// ``` - /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut dl = LinkedList::new(); @@ -521,7 +519,6 @@ impl LinkedList { /// # Examples /// /// ``` - /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut d = LinkedList::new(); @@ -540,7 +537,6 @@ impl LinkedList { /// # Examples /// /// ``` - /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut d = LinkedList::new(); @@ -566,7 +562,6 @@ impl LinkedList { /// # Examples /// /// ``` - /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut d = LinkedList::new(); diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index d5a069b194a..c0da6331b22 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -529,7 +529,6 @@ impl [T] { /// found; the fourth could match any position in `[1,4]`. /// /// ```rust - /// # #![feature(core)] /// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; /// /// let seek = 13; @@ -865,7 +864,6 @@ impl [T] { /// found; the fourth could match any position in `[1,4]`. /// /// ```rust - /// # #![feature(core)] /// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; /// /// assert_eq!(s.binary_search(&13), Ok(9)); diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index f70906f84b8..80bbe4681e7 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -247,7 +247,6 @@ impl VecDeque { /// # Examples /// /// ``` - /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); @@ -275,7 +274,6 @@ impl VecDeque { /// # Examples /// /// ``` - /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let buf: VecDeque = VecDeque::with_capacity(10); @@ -299,7 +297,6 @@ impl VecDeque { /// # Examples /// /// ``` - /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf: VecDeque = vec![1].into_iter().collect(); @@ -321,7 +318,6 @@ impl VecDeque { /// # Examples /// /// ``` - /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf: VecDeque = vec![1].into_iter().collect(); @@ -508,7 +504,6 @@ impl VecDeque { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); @@ -533,7 +528,6 @@ impl VecDeque { /// # Examples /// /// ``` - /// # #![feature(core)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new();