about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2023-04-03Auto merge of #108448 - ishitatsuyuki:binary-heap, r=Mark-Simulacrumbors-51/+19
binary_heap: Optimize Extend implementation. This PR makes the `Extend` implementation for `BinaryHeap` no longer rely on specialization, so that it always use the bulk rebuild optimization that was previously only available for the `Vec` specialization.
2023-04-02Auto merge of #109701 - Amanieu:binaryheap_retain, r=ChrisDentonbors-2/+1
Stabilize `binary_heap_retain` FCP finished in tracking issue: #71503
2023-03-31Rollup merge of #109598 - veera-sivarajan:improve-wording, r=thomccMatthias Krüger-2/+2
Improve documentation for str::replace() and str::replacen() Currently, to know what the function will return when the pattern doesn't match, the docs require the reader to understand the implementation detail and mentally evaluate or run the example code. It is not immediately clear. This PR makes it more explicit so the reader can quickly find the information.
2023-03-30Rollup merge of #106985 - jofas:106746-fix, r=ChrisDentonYuki Okushi-10/+10
Enhanced doucmentation of binary search methods for `slice` and `VecDeque` for unsorted instances Fixes #106746. Issue #106746 raises the concern that the binary search methods for slices and deques aren't explicit enough about the fact that they are only applicable to sorted slices/deques. I changed the explanation for these methods. I took the relatively harsh description of the behaviour of binary search on unsorted collections ("unspecified and meaningless") from the description of the [`partition_point`](https://doc.rust-lang.org/std/primitive.slice.html#method.partition_point) method: > If this slice is not partitioned, the returned result is unspecified and meaningless, as this method performs a kind of binary search.
2023-03-30removed deprecated markdown links from documentationjofas-3/+0
2023-03-29Rollup merge of #109693 - workingjubilee:maybe-unconstify-alloc, r=fee1-deadMatthias Krüger-38/+19
Remove ~const from alloc There is currently an effort underway to stop using `~const Trait`, temporarily, so as to refactor the logic underlying const traits with relative ease. This means it has to go from the standard library, as well. I have taken the initial step of just removing these impls from alloc, as removing them from core is a much more tangled task. In addition, all of these implementations are one more-or-less logically-connected group, so reverting their deconstification as a group seems like it will also be sensible. r? `@fee1-dead`
2023-03-29enhanced documentation of binary search methods for slice and VecDeque for ↵jofas-7/+10
unsorted instances
2023-03-28Remove ~const from allocJubilee Young-38/+19
2023-03-28Stabilize `binary_heap_retain`Amanieu d'Antras-2/+1
FCP finished in tracking issue: #71503
2023-03-28Rollup merge of #92284 - the8472:simplify-advance-by, r=scottmcmnils-53/+56
Change advance(_back)_by to return the remainder instead of the number of processed elements When advance_by can't advance the iterator by the number of requested elements it now returns the amount by which it couldn't be advanced instead of the amount by which it did. This simplifies adapters like chain, flatten or cycle because the remainder doesn't have to be calculated as the difference between requested steps and completed steps anymore. Additionally switching from `Result<(), usize>` to `Result<(), NonZeroUsize>` reduces the size of the result and makes converting from/to a usize representing the number of remaining steps cheap.
2023-03-27fix advance_by impl for vec_deque and add testsThe 8472-7/+7
2023-03-27replace advance_by returning usize with Result<(), NonZeroUsize>The 8472-33/+44
2023-03-27Change advance(_back)_by to return `usize` instead of `Result<(), usize>`The 8472-42/+34
A successful advance is now signalled by returning `0` and other values now represent the remaining number of steps that couldn't be advanced as opposed to the amount of steps that have been advanced during a partial advance_by. This simplifies adapters a bit, replacing some `match`/`if` with arithmetic. Whether this is beneficial overall depends on whether `advance_by` is mostly used as a building-block for other iterator methods and adapters or whether we also see uses by users where `Result` might be more useful.
2023-03-27Rollup merge of #97506 - JohnTitor:stabilize-nonnull-slice-from-raw-parts, ↵Matthias Krüger-1/+0
r=m-ou-se,the8472 Stabilize `nonnull_slice_from_raw_parts` FCP is done: https://github.com/rust-lang/rust/issues/71941#issuecomment-1100910416 Note that this doesn't const-stabilize `NonNull::slice_from_raw_parts` as `slice_from_raw_parts_mut` isn't const-stabilized yet. Given #67456 and #57349, it's not likely available soon, meanwhile, stabilizing only the feature makes some sense, I think. Closes #71941
2023-03-25Improve documentation for str::replace() and str::replacen()Veera-2/+2
Currently, to know what the function will return when the pattern doesn't match, the docs require the reader to understand the implementation detail and mentally evaluate or run the example code. It is not immediately clear. This PR makes it more explicit so the reader can quickly find the information.
2023-03-25Auto merge of #99929 - the8472:default-iters, r=scottmcmbors-0/+246
Implement Default for some alloc/core iterators Add `Default` impls to the following collection iterators: * slice::{Iter, IterMut} * binary_heap::IntoIter * btree::map::{Iter, IterMut, Keys, Values, Range, IntoIter, IntoKeys, IntoValues} * btree::set::{Iter, IntoIter, Range} * linked_list::IntoIter * vec::IntoIter and these adapters: * adapters::{Chain, Cloned, Copied, Rev, Enumerate, Flatten, Fuse, Rev} For iterators which are generic over allocators it only implements it for the global allocator because we can't conjure an allocator from nothing or would have to turn the allocator field into an `Option` just for this change. These changes will be insta-stable. ACP: https://github.com/rust-lang/libs-team/issues/77
2023-03-24Rollup merge of #109406 - WaffleLapkin:🥛, r=cuviperMatthias Krüger-6/+0
Remove outdated comments What the title said
2023-03-23Stabilize `arc_into_inner` and `rc_into_inner`.Frank Steffahn-23/+6
Includes resolving the FIXMEs in the documentation, and some very minor documentation improvements.
2023-03-21Auto merge of #106967 - saethlin:remove-vec-as-ptr-assume, r=thomccbors-11/+2
Remove the assume(!is_null) from Vec::as_ptr At a guess, this code is leftover from LLVM was worse at keeping track of the niche information here. In any case, we don't need this anymore: Removing this `assume` doesn't get rid of the `nonnull` attribute on the return type.
2023-03-20Remove outdated commentsMaybe Waffle-6/+0
2023-03-17Auto merge of #108862 - Mark-Simulacrum:bootstrap-bump, r=pietroalbinibors-2/+2
Bump bootstrap compiler to 1.69 beta r? `@pietroalbini`
2023-03-15unequal → not equalgimbles-4/+4
2023-03-15Bump to latest betaMark Rousskov-2/+2
2023-03-12Rollup merge of #109026 - joshtriplett:rc-into-inner, r=dtolnayMatthias Krüger-0/+33
Introduce `Rc::into_inner`, as a parallel to `Arc::into_inner` Unlike `Arc`, `Rc` doesn't have the same race condition to avoid, but maintaining an equivalent API still makes it easier to work with both `Rc` and `Arc`.
2023-03-12Fix formatting of new Rc::into_inner testDavid Tolnay-1/+0
2023-03-11Introduce `Rc::into_inner`, as a parallel to `Arc::into_inner`Josh Triplett-0/+34
Unlike `Arc`, `Rc` doesn't have the same race condition to avoid, but maintaining an equivalent API still makes it easier to work with both `Rc` and `Arc`.
2023-03-11Auto merge of #109019 - matthiaskrgr:rollup-ihjntil, r=matthiaskrgrbors-19/+26
Rollup of 9 pull requests Successful merges: - #104363 (Make `unused_allocation` lint against `Box::new` too) - #106633 (Stabilize `nonzero_min_max`) - #106844 (allow negative numeric literals in `concat!`) - #108071 (Implement goal caching with the new solver) - #108542 (Force parentheses around `match` expression in binary expression) - #108690 (Place size limits on query keys and values) - #108708 (Prevent overflow through Arc::downgrade) - #108739 (Prevent the `start_bx` basic block in codegen from having two `Builder`s at the same time) - #108806 (Querify register_tools and post-expansion early lints) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-11Rollup merge of #108708 - noamtashma:issue-108706-fix, r=m-ou-seMatthias Krüger-3/+17
Prevent overflow through Arc::downgrade Fixes #108706
2023-03-11Rollup merge of #104363 - WaffleLapkin:bonk_box_new, r=NilstriebMatthias Krüger-16/+9
Make `unused_allocation` lint against `Box::new` too Previously it only linted against `box` syntax, which likely won't ever be stabilized, which is pretty useless. Even now I'm not sure if it's a meaningful lint, but it's at least something :shrug: This means that code like the following will be linted against: ```rust Box::new([1, 2, 3]).len(); f(&Box::new(1)); // where f : &i32 -> () ``` The lint works by checking if a `Box::new` (or `box`) expression has an a borrow adjustment, meaning that the code that first stores the box in a variable won't be linted against: ```rust let boxed = Box::new([1, 2, 3]); // no lint boxed.len(); ```
2023-03-11Rollup merge of #106276 - Sp00ph:unify_slice_ranges, r=the8472Matthias Krüger-36/+31
Fix `vec_deque::Drain` FIXME In my original `VecDeque` rewrite, I didn't use `VecDeque::slice_ranges` in `Drain::as_slices`, even though that's basically the exact use case for `slice_ranges`. The reason for this was that a `VecDeque` wrapped in a `Drain` actually has its length set to `drain_start`, so that there's no potential use after free if you `mem::forget` the `Drain`. I modified `slice_ranges` to accept an explicit `len` parameter instead, which it now uses to bounds check the given range. This way, `Drain::as_slices` can use `slice_ranges` internally instead of having to basically just copy paste the `slice_ranges` code. Since `slice_ranges` is just an internal helper function, this shouldn't change the user facing behavior in any way.
2023-03-06issue-108706-fixNoam Ta Shma-3/+17
2023-03-04Rollup merge of #108660 - xfix:remove-ne-method-from-str, r=thomccDylan DPC-4/+0
Remove ne implementations from strings As far as I can tell, there isn't really a reason for those.
2023-03-03fix an alloc testMaybe Waffle-16/+8
2023-03-03Make `unused_allocation` lint warn against `Box::new`Maybe Waffle-0/+1
2023-03-03Match unmatched backticks in library/est31-2/+2
2023-03-02Remove manual implementation of String::neKonrad Borowski-4/+0
2023-03-01Rollup merge of #108462 - pommicket:fix-vecdeque-zst-overflow, r=AmanieuDylan DPC-1/+1
Fix `VecDeque::append` capacity overflow for ZSTs Fixes #108454.
2023-03-01Auto merge of #108476 - saethlin:remove-library-rustc-box, r=thomccbors-9/+7
Remove or document uses of #[rustc_box] in library r? `@thomcc` Only one of these uses is tested for in the rustc-perf benchmark suite. The impact there on compile time is somewhat dramatic, but I am inclined to make this change as a simplification to the library and wait for people to complain if it explodes their compilation time. I think in the absence of data or reports from users about what code paths really matter, if we are optimizing for compilation time, it's hard to argue against using `#[rustc_box]` everywhere we currently call `Box::new`.
2023-02-28Support allocators in various Default for IntoIter implsThe 8472-7/+22
Global implements Default so we can use that as bound for all allocators
2023-02-28rewrite iterator `Default` tests as doctestsThe 8472-22/+106
2023-02-28Implement Default for some alloc/core iteratorsThe 8472-0/+147
This way one can `mem::take()` them out of structs or #[derive(Default)] on structs containing them. These changes will be insta-stable.
2023-02-27Remove or justify use of #[rustc_box]Ben Kimock-9/+7
2023-02-26Disambiguate commentsMarkus Everling-2/+2
2023-02-26Fix `VecDeque::shrink_to` and add tests.Markus Everling-55/+104
This adds both a test specific to #108453 as well as an exhaustive test that goes through all possible combinations of head index, length and target capacity for a deque with capacity 16.
2023-02-25Use checked_add in VecDeque::append for ZSTs to avoid overflowpommicket-1/+1
2023-02-25Rollup merge of #108407 - notriddle:notriddle/vec-get-mut, r=thomccMatthias Krüger-2/+2
docs: use intra-doc links for `Vec::get(_mut)` Now that #63351 is fixed, there's no reason not to. CC #75672
2023-02-25binary_heap: Unify Extend implementation.Tatsuyuki Ishi-34/+2
Previously the bulk rebuild specialization was only available with Vec, and for general iterators Extend only provided pre-allocation through reserve(). By using a drop guard, we can safely bulk rebuild even if the iterator may panic. This allows benefiting from the bulk rebuild optimization without collecting iterator elements into a Vec beforehand, which would nullify any performance gains from bulk rebuild.
2023-02-25binary_heap: Make RebuildOnDrop a common helper.Tatsuyuki Ishi-17/+17
This helper was written for retain() but will also be useful for extend().
2023-02-24Rollup merge of #106918 - dtolnay:heapretain, r=the8472Dylan DPC-6/+37
Rebuild BinaryHeap on unwind from retain This closes the hole identified in https://github.com/rust-lang/rust/issues/71503#issuecomment-1383251315 which had made it possible for the caller to end up with a heap in invalid state. As of #105851, heaps in invalid state are not supposed to exist.
2023-02-23docs: use intra-doc links for `Vec::get(_mut)`Michael Howell-2/+2
Now that #63351 is fixed, there's no reason not to.