diff options
| author | bors <bors@rust-lang.org> | 2018-12-03 15:44:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-12-03 15:44:43 +0000 |
| commit | 0c999ed132d67bf2520643e9bd619972cf3888ba (patch) | |
| tree | e9dfee00ab60ea6aaa3fb48c0867fe4d5db3cf1e /src/liballoc | |
| parent | 9cd3bef4cfaaac2a608682d4b0834cda344249e0 (diff) | |
| parent | ac363d8793a1c6b69822a583e6f7d0b2f9904c86 (diff) | |
| download | rust-0c999ed132d67bf2520643e9bd619972cf3888ba.tar.gz rust-0c999ed132d67bf2520643e9bd619972cf3888ba.zip | |
Auto merge of #56451 - kennytm:rollup, r=kennytm
Rollup of 13 pull requests Successful merges: - #56141 ([std] Osstr len clarity) - #56366 (Stabilize self_in_typedefs feature) - #56395 (Stabilize dbg!(...)) - #56401 (Move VecDeque::resize_with out of the impl<T:Clone> block) - #56402 (Improve the unstable book example for #[marker] trait) - #56412 (Update tracking issue for `extern_crate_self`) - #56416 (Remove unneeded body class selector) - #56418 (Fix failing tidy (line endings on Windows)) - #56419 (Remove some uses of try!) - #56432 (Update issue number of `shrink_to` methods to point the tracking issue) - #56433 (Add description about `crate` for parse_visibility's comment) - #56435 (make the C part of compiler-builtins opt-out) - #56438 (Remove not used `DotEq` token) Failed merges: r? @ghost
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/collections/binary_heap.rs | 2 | ||||
| -rw-r--r-- | src/liballoc/collections/vec_deque.rs | 62 | ||||
| -rw-r--r-- | src/liballoc/string.rs | 2 | ||||
| -rw-r--r-- | src/liballoc/vec.rs | 2 |
4 files changed, 31 insertions, 37 deletions
diff --git a/src/liballoc/collections/binary_heap.rs b/src/liballoc/collections/binary_heap.rs index fcadcb544c4..8c36962a299 100644 --- a/src/liballoc/collections/binary_heap.rs +++ b/src/liballoc/collections/binary_heap.rs @@ -529,7 +529,7 @@ impl<T: Ord> BinaryHeap<T> { /// assert!(heap.capacity() >= 10); /// ``` #[inline] - #[unstable(feature = "shrink_to", reason = "new API", issue="0")] + #[unstable(feature = "shrink_to", reason = "new API", issue="56431")] pub fn shrink_to(&mut self, min_capacity: usize) { self.data.shrink_to(min_capacity) } diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index cbf104a8fcd..c8ee40f3d27 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -19,7 +19,7 @@ use core::cmp::Ordering; use core::fmt; -use core::iter::{repeat, repeat_with, FromIterator, FusedIterator}; +use core::iter::{repeat_with, FromIterator, FusedIterator}; use core::mem; use core::ops::Bound::{Excluded, Included, Unbounded}; use core::ops::{Index, IndexMut, RangeBounds}; @@ -701,7 +701,7 @@ impl<T> VecDeque<T> { /// buf.shrink_to(0); /// assert!(buf.capacity() >= 4); /// ``` - #[unstable(feature = "shrink_to", reason = "new API", issue="0")] + #[unstable(feature = "shrink_to", reason = "new API", issue="56431")] pub fn shrink_to(&mut self, min_capacity: usize) { assert!(self.capacity() >= min_capacity, "Tried to shrink to a larger capacity"); @@ -1886,16 +1886,16 @@ impl<T> VecDeque<T> { debug_assert!(!self.is_full()); } } -} -impl<T: Clone> VecDeque<T> { - /// Modifies the `VecDeque` in-place so that `len()` is equal to new_len, - /// either by removing excess elements from the back or by appending clones of `value` - /// to the back. + /// Modifies the `VecDeque` in-place so that `len()` is equal to `new_len`, + /// either by removing excess elements from the back or by appending + /// elements generated by calling `generator` to the back. /// /// # Examples /// /// ``` + /// #![feature(vec_resize_with)] + /// /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); @@ -1904,32 +1904,36 @@ impl<T: Clone> VecDeque<T> { /// buf.push_back(15); /// assert_eq!(buf, [5, 10, 15]); /// - /// buf.resize(2, 0); + /// buf.resize_with(5, Default::default); + /// assert_eq!(buf, [5, 10, 15, 0, 0]); + /// + /// buf.resize_with(2, || unreachable!()); /// assert_eq!(buf, [5, 10]); /// - /// buf.resize(5, 20); - /// assert_eq!(buf, [5, 10, 20, 20, 20]); + /// let mut state = 100; + /// buf.resize_with(5, || { state += 1; state }); + /// assert_eq!(buf, [5, 10, 101, 102, 103]); /// ``` - #[stable(feature = "deque_extras", since = "1.16.0")] - pub fn resize(&mut self, new_len: usize, value: T) { + #[unstable(feature = "vec_resize_with", issue = "41758")] + pub fn resize_with(&mut self, new_len: usize, generator: impl FnMut()->T) { let len = self.len(); if new_len > len { - self.extend(repeat(value).take(new_len - len)) + self.extend(repeat_with(generator).take(new_len - len)) } else { self.truncate(new_len); } } +} - /// Modifies the `VecDeque` in-place so that `len()` is equal to `new_len`, - /// either by removing excess elements from the back or by appending - /// elements generated by calling `generator` to the back. +impl<T: Clone> VecDeque<T> { + /// Modifies the `VecDeque` in-place so that `len()` is equal to new_len, + /// either by removing excess elements from the back or by appending clones of `value` + /// to the back. /// /// # Examples /// /// ``` - /// #![feature(vec_resize_with)] - /// /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); @@ -1938,25 +1942,15 @@ impl<T: Clone> VecDeque<T> { /// buf.push_back(15); /// assert_eq!(buf, [5, 10, 15]); /// - /// buf.resize_with(5, Default::default); - /// assert_eq!(buf, [5, 10, 15, 0, 0]); - /// - /// buf.resize_with(2, || unreachable!()); + /// buf.resize(2, 0); /// assert_eq!(buf, [5, 10]); /// - /// let mut state = 100; - /// buf.resize_with(5, || { state += 1; state }); - /// assert_eq!(buf, [5, 10, 101, 102, 103]); + /// buf.resize(5, 20); + /// assert_eq!(buf, [5, 10, 20, 20, 20]); /// ``` - #[unstable(feature = "vec_resize_with", issue = "41758")] - pub fn resize_with(&mut self, new_len: usize, generator: impl FnMut()->T) { - let len = self.len(); - - if new_len > len { - self.extend(repeat_with(generator).take(new_len - len)) - } else { - self.truncate(new_len); - } + #[stable(feature = "deque_extras", since = "1.16.0")] + pub fn resize(&mut self, new_len: usize, value: T) { + self.resize_with(new_len, || value.clone()); } } diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 0b25d911a29..662f8ae614f 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1050,7 +1050,7 @@ impl String { /// assert!(s.capacity() >= 3); /// ``` #[inline] - #[unstable(feature = "shrink_to", reason = "new API", issue="0")] + #[unstable(feature = "shrink_to", reason = "new API", issue="56431")] pub fn shrink_to(&mut self, min_capacity: usize) { self.vec.shrink_to(min_capacity) } diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index f7a0bbdceaf..ca7c766e413 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -613,7 +613,7 @@ impl<T> Vec<T> { /// vec.shrink_to(0); /// assert!(vec.capacity() >= 3); /// ``` - #[unstable(feature = "shrink_to", reason = "new API", issue="0")] + #[unstable(feature = "shrink_to", reason = "new API", issue="56431")] pub fn shrink_to(&mut self, min_capacity: usize) { self.buf.shrink_to_fit(cmp::max(self.len, min_capacity)); } |
