about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/arc.rs13
-rw-r--r--src/liballoc/lib.rs1
-rw-r--r--src/liballoc/tests/btree/map.rs28
-rw-r--r--src/liballoc/tests/str.rs16
-rw-r--r--src/liballoc/tests/string.rs6
-rw-r--r--src/liballoc/tests/vec.rs28
-rw-r--r--src/liballoc/vec.rs12
-rw-r--r--src/liballoc/vec_deque.rs18
8 files changed, 71 insertions, 51 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs
index 4b695ad7c79..3b7dbd813cf 100644
--- a/src/liballoc/arc.rs
+++ b/src/liballoc/arc.rs
@@ -72,13 +72,13 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
 /// first: after all, isn't the point of `Arc<T>` thread safety? The key is
 /// this: `Arc<T>` makes it thread safe to have multiple ownership of the same
 /// data, but it  doesn't add thread safety to its data. Consider
-/// `Arc<RefCell<T>>`. `RefCell<T>` isn't [`Sync`], and if `Arc<T>` was always
-/// [`Send`], `Arc<RefCell<T>>` would be as well. But then we'd have a problem:
-/// `RefCell<T>` is not thread safe; it keeps track of the borrowing count using
+/// `Arc<`[`RefCell<T>`]`>`. [`RefCell<T>`] isn't [`Sync`], and if `Arc<T>` was always
+/// [`Send`], `Arc<`[`RefCell<T>`]`>` would be as well. But then we'd have a problem:
+/// [`RefCell<T>`] is not thread safe; it keeps track of the borrowing count using
 /// non-atomic operations.
 ///
 /// In the end, this means that you may need to pair `Arc<T>` with some sort of
-/// `std::sync` type, usually `Mutex<T>`.
+/// [`std::sync`] type, usually [`Mutex<T>`][mutex].
 ///
 /// ## Breaking cycles with `Weak`
 ///
@@ -106,7 +106,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
 /// // a and b both point to the same memory location as foo.
 /// ```
 ///
-/// The `Arc::clone(&from)` syntax is the most idiomatic because it conveys more explicitly
+/// The [`Arc::clone(&from)`] syntax is the most idiomatic because it conveys more explicitly
 /// the meaning of the code. In the example above, this syntax makes it easier to see that
 /// this code is creating a new reference rather than copying the whole content of foo.
 ///
@@ -141,6 +141,9 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
 /// [upgrade]: struct.Weak.html#method.upgrade
 /// [`None`]: ../../std/option/enum.Option.html#variant.None
 /// [assoc]: ../../book/first-edition/method-syntax.html#associated-functions
+/// [`RefCell<T>`]: ../../std/cell/struct.RefCell.html
+/// [`std::sync`]: ../../std/sync/index.html
+/// [`Arc::clone(&from)`]: #method.clone
 ///
 /// # Examples
 ///
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index 2845d349ae1..d51aaa23c6a 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -98,6 +98,7 @@
 #![feature(generic_param_attrs)]
 #![feature(i128_type)]
 #![feature(inclusive_range)]
+#![feature(iter_rfold)]
 #![feature(lang_items)]
 #![feature(needs_allocator)]
 #![feature(nonzero)]
diff --git a/src/liballoc/tests/btree/map.rs b/src/liballoc/tests/btree/map.rs
index 2c899d96940..2393101040d 100644
--- a/src/liballoc/tests/btree/map.rs
+++ b/src/liballoc/tests/btree/map.rs
@@ -182,7 +182,7 @@ fn test_range_small() {
 fn test_range_inclusive() {
     let size = 500;
 
-    let map: BTreeMap<_, _> = (0...size).map(|i| (i, i)).collect();
+    let map: BTreeMap<_, _> = (0..=size).map(|i| (i, i)).collect();
 
     fn check<'a, L, R>(lhs: L, rhs: R)
         where L: IntoIterator<Item=(&'a i32, &'a i32)>,
@@ -193,18 +193,18 @@ fn test_range_inclusive() {
         assert_eq!(lhs, rhs);
     }
 
-    check(map.range(size + 1...size + 1), vec![]);
-    check(map.range(size...size), vec![(&size, &size)]);
-    check(map.range(size...size + 1), vec![(&size, &size)]);
-    check(map.range(0...0), vec![(&0, &0)]);
-    check(map.range(0...size - 1), map.range(..size));
-    check(map.range(-1...-1), vec![]);
-    check(map.range(-1...size), map.range(..));
-    check(map.range(...size), map.range(..));
-    check(map.range(...200), map.range(..201));
-    check(map.range(5...8), vec![(&5, &5), (&6, &6), (&7, &7), (&8, &8)]);
-    check(map.range(-1...0), vec![(&0, &0)]);
-    check(map.range(-1...2), vec![(&0, &0), (&1, &1), (&2, &2)]);
+    check(map.range(size + 1..=size + 1), vec![]);
+    check(map.range(size..=size), vec![(&size, &size)]);
+    check(map.range(size..=size + 1), vec![(&size, &size)]);
+    check(map.range(0..=0), vec![(&0, &0)]);
+    check(map.range(0..=size - 1), map.range(..size));
+    check(map.range(-1..=-1), vec![]);
+    check(map.range(-1..=size), map.range(..));
+    check(map.range(..=size), map.range(..));
+    check(map.range(..=200), map.range(..201));
+    check(map.range(5..=8), vec![(&5, &5), (&6, &6), (&7, &7), (&8, &8)]);
+    check(map.range(-1..=0), vec![(&0, &0)]);
+    check(map.range(-1..=2), vec![(&0, &0), (&1, &1), (&2, &2)]);
 }
 
 #[test]
@@ -212,7 +212,7 @@ fn test_range_inclusive_max_value() {
     let max = ::std::usize::MAX;
     let map: BTreeMap<_, _> = vec![(max, 0)].into_iter().collect();
 
-    assert_eq!(map.range(max...max).collect::<Vec<_>>(), &[(&max, &0)]);
+    assert_eq!(map.range(max..=max).collect::<Vec<_>>(), &[(&max, &0)]);
 }
 
 #[test]
diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs
index 9d8ca38b20e..b3178064505 100644
--- a/src/liballoc/tests/str.rs
+++ b/src/liballoc/tests/str.rs
@@ -361,13 +361,13 @@ fn test_slice_fail() {
 #[test]
 #[should_panic]
 fn test_str_slice_rangetoinclusive_max_panics() {
-    &"hello"[...usize::max_value()];
+    &"hello"[..=usize::max_value()];
 }
 
 #[test]
 #[should_panic]
 fn test_str_slice_rangeinclusive_max_panics() {
-    &"hello"[1...usize::max_value()];
+    &"hello"[1..=usize::max_value()];
 }
 
 #[test]
@@ -375,7 +375,7 @@ fn test_str_slice_rangeinclusive_max_panics() {
 fn test_str_slicemut_rangetoinclusive_max_panics() {
     let mut s = "hello".to_owned();
     let s: &mut str = &mut s;
-    &mut s[...usize::max_value()];
+    &mut s[..=usize::max_value()];
 }
 
 #[test]
@@ -383,7 +383,7 @@ fn test_str_slicemut_rangetoinclusive_max_panics() {
 fn test_str_slicemut_rangeinclusive_max_panics() {
     let mut s = "hello".to_owned();
     let s: &mut str = &mut s;
-    &mut s[1...usize::max_value()];
+    &mut s[1..=usize::max_value()];
 }
 
 #[test]
@@ -391,13 +391,13 @@ fn test_str_get_maxinclusive() {
     let mut s = "hello".to_owned();
     {
         let s: &str = &s;
-        assert_eq!(s.get(...usize::max_value()), None);
-        assert_eq!(s.get(1...usize::max_value()), None);
+        assert_eq!(s.get(..=usize::max_value()), None);
+        assert_eq!(s.get(1..=usize::max_value()), None);
     }
     {
         let s: &mut str = &mut s;
-        assert_eq!(s.get(...usize::max_value()), None);
-        assert_eq!(s.get(1...usize::max_value()), None);
+        assert_eq!(s.get(..=usize::max_value()), None);
+        assert_eq!(s.get(1..=usize::max_value()), None);
     }
 }
 
diff --git a/src/liballoc/tests/string.rs b/src/liballoc/tests/string.rs
index 6aba18ddf49..ef6f5e10a72 100644
--- a/src/liballoc/tests/string.rs
+++ b/src/liballoc/tests/string.rs
@@ -456,9 +456,9 @@ fn test_splice_char_boundary() {
 #[test]
 fn test_splice_inclusive_range() {
     let mut v = String::from("12345");
-    v.splice(2...3, "789");
+    v.splice(2..=3, "789");
     assert_eq!(v, "127895");
-    v.splice(1...2, "A");
+    v.splice(1..=2, "A");
     assert_eq!(v, "1A895");
 }
 
@@ -473,7 +473,7 @@ fn test_splice_out_of_bounds() {
 #[should_panic]
 fn test_splice_inclusive_out_of_bounds() {
     let mut s = String::from("12345");
-    s.splice(5...5, "789");
+    s.splice(5..=5, "789");
 }
 
 #[test]
diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs
index 670ea8089fc..0e25da5bd30 100644
--- a/src/liballoc/tests/vec.rs
+++ b/src/liballoc/tests/vec.rs
@@ -537,27 +537,27 @@ fn test_drain_range() {
 #[test]
 fn test_drain_inclusive_range() {
     let mut v = vec!['a', 'b', 'c', 'd', 'e'];
-    for _ in v.drain(1...3) {
+    for _ in v.drain(1..=3) {
     }
     assert_eq!(v, &['a', 'e']);
 
-    let mut v: Vec<_> = (0...5).map(|x| x.to_string()).collect();
-    for _ in v.drain(1...5) {
+    let mut v: Vec<_> = (0..=5).map(|x| x.to_string()).collect();
+    for _ in v.drain(1..=5) {
     }
     assert_eq!(v, &["0".to_string()]);
 
-    let mut v: Vec<String> = (0...5).map(|x| x.to_string()).collect();
-    for _ in v.drain(0...5) {
+    let mut v: Vec<String> = (0..=5).map(|x| x.to_string()).collect();
+    for _ in v.drain(0..=5) {
     }
     assert_eq!(v, Vec::<String>::new());
 
-    let mut v: Vec<_> = (0...5).map(|x| x.to_string()).collect();
-    for _ in v.drain(0...3) {
+    let mut v: Vec<_> = (0..=5).map(|x| x.to_string()).collect();
+    for _ in v.drain(0..=3) {
     }
     assert_eq!(v, &["4".to_string(), "5".to_string()]);
 
-    let mut v: Vec<_> = (0...1).map(|x| x.to_string()).collect();
-    for _ in v.drain(...0) {
+    let mut v: Vec<_> = (0..=1).map(|x| x.to_string()).collect();
+    for _ in v.drain(..=0) {
     }
     assert_eq!(v, &["1".to_string()]);
 }
@@ -572,7 +572,7 @@ fn test_drain_max_vec_size() {
 
     let mut v = Vec::<()>::with_capacity(usize::max_value());
     unsafe { v.set_len(usize::max_value()); }
-    for _ in v.drain(usize::max_value() - 1...usize::max_value() - 1) {
+    for _ in v.drain(usize::max_value() - 1..=usize::max_value() - 1) {
     }
     assert_eq!(v.len(), usize::max_value() - 1);
 }
@@ -581,7 +581,7 @@ fn test_drain_max_vec_size() {
 #[should_panic]
 fn test_drain_inclusive_out_of_bounds() {
     let mut v = vec![1, 2, 3, 4, 5];
-    v.drain(5...5);
+    v.drain(5..=5);
 }
 
 #[test]
@@ -598,10 +598,10 @@ fn test_splice() {
 fn test_splice_inclusive_range() {
     let mut v = vec![1, 2, 3, 4, 5];
     let a = [10, 11, 12];
-    let t1: Vec<_> = v.splice(2...3, a.iter().cloned()).collect();
+    let t1: Vec<_> = v.splice(2..=3, a.iter().cloned()).collect();
     assert_eq!(v, &[1, 2, 10, 11, 12, 5]);
     assert_eq!(t1, &[3, 4]);
-    let t2: Vec<_> = v.splice(1...2, Some(20)).collect();
+    let t2: Vec<_> = v.splice(1..=2, Some(20)).collect();
     assert_eq!(v, &[1, 20, 11, 12, 5]);
     assert_eq!(t2, &[2, 10]);
 }
@@ -619,7 +619,7 @@ fn test_splice_out_of_bounds() {
 fn test_splice_inclusive_out_of_bounds() {
     let mut v = vec![1, 2, 3, 4, 5];
     let a = [10, 11, 12];
-    v.splice(5...5, a.iter().cloned());
+    v.splice(5..=5, a.iter().cloned());
 }
 
 #[test]
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index 7dd8895c1ae..725d3e15f4a 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -1950,7 +1950,7 @@ impl<T> Vec<T> {
     /// assert_eq!(u, &[1, 2]);
     /// ```
     #[inline]
-    #[stable(feature = "vec_splice", since = "1.22.0")]
+    #[stable(feature = "vec_splice", since = "1.21.0")]
     pub fn splice<R, I>(&mut self, range: R, replace_with: I) -> Splice<I::IntoIter>
         where R: RangeArgument<usize>, I: IntoIterator<Item=T>
     {
@@ -2553,13 +2553,13 @@ impl<'a, T> InPlace<T> for PlaceBack<'a, T> {
 /// [`splice()`]: struct.Vec.html#method.splice
 /// [`Vec`]: struct.Vec.html
 #[derive(Debug)]
-#[stable(feature = "vec_splice", since = "1.22.0")]
+#[stable(feature = "vec_splice", since = "1.21.0")]
 pub struct Splice<'a, I: Iterator + 'a> {
     drain: Drain<'a, I::Item>,
     replace_with: I,
 }
 
-#[stable(feature = "vec_splice", since = "1.22.0")]
+#[stable(feature = "vec_splice", since = "1.21.0")]
 impl<'a, I: Iterator> Iterator for Splice<'a, I> {
     type Item = I::Item;
 
@@ -2572,18 +2572,18 @@ impl<'a, I: Iterator> Iterator for Splice<'a, I> {
     }
 }
 
-#[stable(feature = "vec_splice", since = "1.22.0")]
+#[stable(feature = "vec_splice", since = "1.21.0")]
 impl<'a, I: Iterator> DoubleEndedIterator for Splice<'a, I> {
     fn next_back(&mut self) -> Option<Self::Item> {
         self.drain.next_back()
     }
 }
 
-#[stable(feature = "vec_splice", since = "1.22.0")]
+#[stable(feature = "vec_splice", since = "1.21.0")]
 impl<'a, I: Iterator> ExactSizeIterator for Splice<'a, I> {}
 
 
-#[stable(feature = "vec_splice", since = "1.22.0")]
+#[stable(feature = "vec_splice", since = "1.21.0")]
 impl<'a, I: Iterator> Drop for Splice<'a, I> {
     fn drop(&mut self) {
         // exhaust drain first
diff --git a/src/liballoc/vec_deque.rs b/src/liballoc/vec_deque.rs
index 00def2a1eac..6d64e9e303f 100644
--- a/src/liballoc/vec_deque.rs
+++ b/src/liballoc/vec_deque.rs
@@ -558,7 +558,7 @@ impl<T> VecDeque<T> {
             .and_then(|needed_cap| needed_cap.checked_next_power_of_two())
             .expect("capacity overflow");
 
-        if new_cap > self.capacity() {
+        if new_cap > old_cap {
             self.buf.reserve_exact(used_cap, new_cap - used_cap);
             unsafe {
                 self.handle_cap_increase(old_cap);
@@ -1973,6 +1973,14 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
         self.head = wrap_index(self.head.wrapping_sub(1), self.ring.len());
         unsafe { Some(self.ring.get_unchecked(self.head)) }
     }
+
+    fn rfold<Acc, F>(self, mut accum: Acc, mut f: F) -> Acc
+        where F: FnMut(Acc, Self::Item) -> Acc
+    {
+        let (front, back) = RingSlices::ring_slices(self.ring, self.head, self.tail);
+        accum = back.iter().rfold(accum, &mut f);
+        front.iter().rfold(accum, &mut f)
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -2058,6 +2066,14 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
             Some(&mut *(elem as *mut _))
         }
     }
+
+    fn rfold<Acc, F>(self, mut accum: Acc, mut f: F) -> Acc
+        where F: FnMut(Acc, Self::Item) -> Acc
+    {
+        let (front, back) = RingSlices::ring_slices(self.ring, self.head, self.tail);
+        accum = back.iter_mut().rfold(accum, &mut f);
+        front.iter_mut().rfold(accum, &mut f)
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]