about summary refs log tree commit diff
path: root/library/alloc/tests/lib.rs
AgeCommit message (Collapse)AuthorLines
2021-10-04Rollup merge of #87993 - kornelski:try_reserve_stable, r=joshtriplettJubilee-1/+0
Stabilize try_reserve Stabilization PR for the [`try_reserve` feature](https://github.com/rust-lang/rust/issues/48043#issuecomment-898040475).
2021-10-04Stabilize try_reserveKornel-1/+0
2021-09-30implement advance_(back_)_by on more iteratorsThe8472-0/+1
2021-09-17Stabilize `Iterator::map_while`Maybe Waffle-1/+0
2021-08-17Constified `Default` implementationsDeadbeef-0/+1
The libs-api team agrees to allow const_trait_impl to appear in the standard library as long as stable code cannot be broken (they are properly gated) this means if the compiler teams thinks it's okay, then it's okay. My priority on constifying would be: 1. Non-generic impls (e.g. Default) or generic impls with no bounds 2. Generic functions with bounds (that use const impls) 3. Generic impls with bounds 4. Impls for traits with associated types For people opening constification PRs: please cc me and/or oli-obk.
2021-08-14Assign FIXMEs to me and remove obsolete onesDeadbeef-2/+0
Also fixed capitalization of documentation
2021-08-13allow incomplete features for nowDeadbeef-0/+2
2021-08-13Moved ui testDeadbeef-0/+3
2021-08-07Use assert_matches! instead of if let {} elseKornel-0/+1
2021-07-24Hide allocator details from TryReserveErrorKornel-0/+1
2021-06-02Stabilize `vecdeque_binary_search`SOFe-1/+0
2021-04-28Stabilize vec_extend_from_withinAmanieu d'Antras-1/+0
2021-03-30Rollup merge of #82331 - frol:feat/std-binary-heap-as-slice, r=AmanieuDylan DPC-0/+1
alloc: Added `as_slice` method to `BinaryHeap` collection I initially asked about whether it is useful addition on https://internals.rust-lang.org/t/should-i-add-as-slice-method-to-binaryheap/13816, and it seems there were no objections, so went ahead with this PR. > There is [`BinaryHeap::into_vec`](https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#method.into_vec), but it consumes the value. I wonder if there is API design limitation that should be taken into account. Implementation-wise, the inner buffer is just a Vec, so it is trivial to expose as_slice from it. Please, guide me through if I need to add tests or something else. UPD: Tracking issue #83659
2021-03-24Revert "Revert stabilizing integer::BITS."Mara Bos-1/+0
2021-03-19Auto merge of #71780 - jcotton42:string_remove_matches, r=joshtriplettbors-0/+1
Implement String::remove_matches Closes #50206. I lifted the function help from `@frewsxcv's` original PR (#50015), hope they don't mind. I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.
2021-03-15Merge branch 'master' into dedupSoveu-2/+2
2021-03-15Vec::dedup optimization - add testsSoveu-0/+1
2021-03-05Implement String::remove_matchesJosh Cotton-0/+1
2021-03-04Rollup merge of #82564 - WaffleLapkin:revert_spare_mut, r=RalfJungYuki Okushi-0/+1
Revert `Vec::spare_capacity_mut` impl to prevent pointers invalidation The implementation was changed in #79015. Later it was [pointed out](https://github.com/rust-lang/rust/issues/81944#issuecomment-782849785) that the implementation invalidates pointers to the buffer (initialized elements) by creating a unique reference to the buffer. This PR reverts the implementation. r? ```@RalfJung```
2021-03-03Add test that Vec::spare_capacity_mut doesn't invalidate pointersWaffle-0/+1
2021-02-20alloc: Added `as_slice` method to `BinaryHeap` collectionVlad Frolov-0/+1
2021-02-09Stabilize str_split_onceJacob Pratt-1/+0
2021-02-03Revert stabilizing integer::BITS.Mara Bos-0/+1
2021-02-02Auto merge of #79015 - WaffleLapkin:vec_append_from_within, r=KodrAusbors-0/+1
add `Vec::extend_from_within` method under `vec_extend_from_within` feature gate Implement <https://github.com/rust-lang/rfcs/pull/2714> ### tl;dr This PR adds a `extend_from_within` method to `Vec` which allows copying elements from a range to the end: ```rust #![feature(vec_extend_from_within)] let mut vec = vec![0, 1, 2, 3, 4]; vec.extend_from_within(2..); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4]); vec.extend_from_within(..2); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1]); vec.extend_from_within(4..8); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1, 4, 2, 3, 4]); ``` ### Implementation notes Originally I've copied `@Shnatsel's` [implementation](https://github.com/WanzenBug/rle-decode-helper/blob/690742a0de158d391b7bde1a0c71cccfdad33ab3/src/lib.rs#L74) with some minor changes to support other ranges: ```rust pub fn append_from_within<R>(&mut self, src: R) where T: Copy, R: RangeBounds<usize>, { let len = self.len(); let Range { start, end } = src.assert_len(len);; let count = end - start; self.reserve(count); unsafe { // This is safe because `reserve()` above succeeded, // so `self.len() + count` did not overflow usize ptr::copy_nonoverlapping( self.get_unchecked(src.start), self.as_mut_ptr().add(len), count, ); self.set_len(len + count); } } ``` But then I've realized that this duplicates most of the code from (private) `Vec::append_elements`, so I've used it instead. Then I've applied `@KodrAus` suggestions from https://github.com/rust-lang/rust/pull/79015#issuecomment-727200852.
2021-01-31add `Vec::extend_from_within` methodWaffle-0/+1
Implement <https://github.com/rust-lang/rfcs/pull/2714>, changes from the RFC: - Rename the method `append_from_within` => `extend_from_within` - Loose :Copy bound => :Clone - Specialize in case of :Copy This commit also adds `Vec::split_at_spare` private method and use it to implement `Vec::spare_capacity_mut` and `Vec::extend_from_within`. This method returns 2 slices - initialized elements (same as `&mut vec[..]`) and uninitialized but allocated space (same as `vec.spare_capacity_mut()`).
2021-01-31stabilize int_bits_constAshley Mannix-1/+0
2021-01-04Stabilize split_inclusiveIan Jackson-1/+0
Closes #72360. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-12-31Auto merge of #79895 - Kerollmops:slice-group-by, r=m-ou-sebors-0/+1
The return of the GroupBy and GroupByMut iterators on slice According to https://github.com/rust-lang/rfcs/pull/2477#issuecomment-742034372, I am opening this PR again, this time I implemented it in safe Rust only, it is therefore much easier to read and is completely safe. This PR proposes to add two new methods to the slice, the `group_by` and `group_by_mut`. These two methods provide a way to iterate over non-overlapping sub-slices of a base slice that are separated by the predicate given by the user (e.g. `Partial::eq`, `|a, b| a.abs() < b.abs()`). ```rust let slice = &[1, 1, 1, 3, 3, 2, 2, 2]; let mut iter = slice.group_by(|a, b| a == b); assert_eq!(iter.next(), Some(&[1, 1, 1][..])); assert_eq!(iter.next(), Some(&[3, 3][..])); assert_eq!(iter.next(), Some(&[2, 2, 2][..])); assert_eq!(iter.next(), None); ``` [An RFC](https://github.com/rust-lang/rfcs/pull/2477) was open 2 years ago but wasn't necessary.
2020-12-10Introduce the GroupBy and GroupByMut IteratorsClément Renault-0/+1
2020-11-15stabilize deque_rangeSpyros Roum-1/+0
2020-10-09liballoc: VecDeque: Add binary search functionsVojtech Kral-0/+1
2020-09-22Update library functions with stability attributesDylan MacKenzie-0/+1
This may not be strictly minimal, but all unstable functions also need a `rustc_const_unstable` attribute.
2020-09-19Use `T::BITS` instead of `size_of::<T> * 8`.Mara Bos-0/+1
2020-09-16Rollup merge of #75146 - tmiasko:range-overflow, r=Mark-SimulacrumDylan DPC-0/+1
Detect overflow in proc_macro_server subspan * Detect overflow in proc_macro_server subspan * Add tests for overflow in Vec::drain * Add tests for overflow in String / VecDeque operations using ranges
2020-09-04Move various ui const tests to `library`Christiaan Dirkx-0/+1
Move: - `src\test\ui\consts\const-nonzero.rs` to `library\core` - `src\test\ui\consts\ascii.rs` to `library\core` - `src\test\ui\consts\cow-is-borrowed` to `library\alloc` Part of #76268
2020-09-04Add tests for overflow in String / VecDeque operations using rangesTomasz Miąsko-0/+1
2020-09-03support in-place collect for MapWhile adaptersThe8472-0/+1
2020-09-03in-place collect for Vec. Box<[]> and BinaryHeap IntoIter and some adaptersThe8472-0/+1
2020-08-14Move btree unit test to their native, privileged locationStein Somers-4/+1
2020-08-07Add unit tests for new `BTreeMap::into_{keys,values}` methodsNazım Can Altınova-0/+1
2020-08-04Replace `Memoryblock` with `NonNull<[u8]>`Tim Diekmann-0/+1
2020-07-28Add str::[r]split_onceAleksey Kladov-0/+1
This is useful for quick&dirty parsing of key: value config pairs
2020-07-27mv std libs to library/mark-0/+57