about summary refs log tree commit diff
path: root/library/alloc
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-3/+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-30Auto merge of #109769 - JohnTitor:rollup-7n2bnpg, r=JohnTitorbors-10/+10
Rollup of 7 pull requests Successful merges: - #106985 (Enhanced doucmentation of binary search methods for `slice` and `VecDeque` for unsorted instances) - #109509 (compiletest: Don't allow tests with overlapping prefix names) - #109719 (RELEASES: Add "Only support Android NDK 25 or newer" to 1.68.0) - #109748 (Don't ICE on `DiscriminantKind` projection in new solver) - #109749 (Canonicalize float var as float in new solver) - #109761 (Drop binutils on powerpc-unknown-freebsd) - #109766 (Fix title for openharmony.md) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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-30Auto merge of #105587 - tgross35:once-cell-min, r=m-ou-sebors-1/+0
Partial stabilization of `once_cell` This PR aims to stabilize a portion of the `once_cell` feature: - `core::cell::OnceCell` - `std::cell::OnceCell` (re-export of the above) - `std::sync::OnceLock` This will leave `LazyCell` and `LazyLock` unstabilized, which have been moved to the `lazy_cell` feature flag. Tracking issue: https://github.com/rust-lang/rust/issues/74465 (does not fully close, but it may make sense to move to a new issue) Future steps for separate PRs: - ~~Add `#[inline]` to many methods~~ #105651 - Update cranelift usage of the `once_cell` crate - Update rust-analyzer usage of the `once_cell` crate - Update error messages discussing once_cell ## To be stabilized API summary ```rust // core::cell (in core/cell/once.rs) pub struct OnceCell<T> { .. } impl<T> OnceCell<T> { pub const fn new() -> OnceCell<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceCell<T>; impl<T: Debug> Debug for OnceCell<T> impl<T> Default for OnceCell<T>; impl<T> From<T> for OnceCell<T>; impl<T: PartialEq> PartialEq for OnceCell<T>; impl<T: Eq> Eq for OnceCell<T>; ``` ```rust // std::sync (in std/sync/once_lock.rs) impl<T> OnceLock<T> { pub const fn new() -> OnceLock<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceLock<T>; impl<T: Debug> Debug for OnceLock<T>; impl<T> Default for OnceLock<T>; impl<#[may_dangle] T> Drop for OnceLock<T>; impl<T> From<T> for OnceLock<T>; impl<T: PartialEq> PartialEq for OnceLock<T> impl<T: Eq> Eq for OnceLock<T>; impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T>; unsafe impl<T: Send> Send for OnceLock<T>; unsafe impl<T: Sync + Send> Sync for OnceLock<T>; impl<T: UnwindSafe> UnwindSafe for OnceLock<T>; ``` No longer planned as part of this PR, and moved to the `rust_cell_try` feature gate: ```rust impl<T> OnceCell<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } impl<T> OnceLock<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } ``` I am new to this process so would appreciate mentorship wherever needed.
2023-03-30removed deprecated markdown links from documentationjofas-3/+0
2023-03-29Stabilize a portion of 'once_cell'Trevor Gross-1/+0
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-29Rollup merge of #109693 - workingjubilee:maybe-unconstify-alloc, r=fee1-deadMatthias Krüger-54/+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-54/+19
2023-03-28Stabilize `binary_heap_retain`Amanieu d'Antras-3/+1
FCP finished in tracking issue: #71503
2023-03-28Rollup merge of #92284 - the8472:simplify-advance-by, r=scottmcmnils-63/+91
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/+30
2023-03-27replace advance_by returning usize with Result<(), NonZeroUsize>The 8472-42/+54
2023-03-27Change advance(_back)_by to return `usize` instead of `Result<(), usize>`The 8472-52/+45
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-3/+1
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-23Rollup merge of #100311 - xfix:lines-fix-handling-of-bare-cr, r=ChrisDentonDylan DPC-7/+19
Fix handling of trailing bare CR in str::lines Continuing from #91191. Fixes #94435.
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/+15
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-31/+107
2023-02-28Implement Default for some alloc/core iteratorsThe 8472-1/+156
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-25Add test for VecDeque::append ZST capacity overflowpommicket-0/+14
2023-02-25Use checked_add in VecDeque::append for ZSTs to avoid overflowpommicket-1/+1