about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
2021-11-20replace vec::Drain drop loops with drop_in_placeThe8472-14/+37
2021-11-19Fix Iterator::advance_by contract inconsistencyThe8472-0/+3
The `advance_by(n)` docs state that in the error case `Err(k)` that k is always less than n. It also states that `advance_by(0)` may return `Err(0)` to indicate an exhausted iterator. These statements are inconsistent. Since only one implementation (Skip) actually made use of that I changed it to return Ok(()) in that case too. While adding some tests I also found a bug in `Take::advance_back_by`.
2021-11-19Rollup merge of #90607 - WaffleLapkin:const_str_from_utf8, r=oli-obkYuki Okushi-3/+62
Make slice->str conversion and related functions `const` This PR marks the following APIs as `const`: ```rust // core::str pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error>; pub const fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error>; pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str; impl Utf8Error { pub const fn valid_up_to(&self) -> usize; pub const fn error_len(&self) -> Option<usize>; } ``` Everything but `from_utf8_unchecked_mut` uses `const_str_from_utf8` feature gate, `from_utf8_unchecked_mut` uses `const_str_from_utf8_unchecked_mut` feature gate. --- I'm not sure why `from_utf8_unchecked_mut` was left out being non-`const`, considering that `from_utf8_unchecked` is not only `const`, but **`const` stable**. --- r? ```@oli-obk``` (performance-only `const_eval_select` use)
2021-11-19Rollup merge of #90480 - r00ster91:remove, r=kennytmYuki Okushi-1/+4
Mention `Vec::remove` in `Vec::swap_remove`'s docs Thought this was a nice addition.
2021-11-18Make slice->str conversion and related functions constMaybe Waffle-3/+62
This commit makes the following functions from `core::str` `const fn`: - `from_utf8[_mut]` (`feature(const_str_from_utf8)`) - `from_utf8_unchecked_mut` (`feature(const_str_from_utf8_unchecked_mut)`) - `Utf8Error::{valid_up_to,error_len}` (`feature(const_str_from_utf8)`)
2021-11-17Rollup merge of #90772 - GuillaumeGomez:vec-retain-mut, r=joshtriplettMatthias Krüger-1/+29
Add Vec::retain_mut This is to continue the discussion started in #83218. Original comment was: > Take 2 of #34265, since I needed this today. The reason I think why we should add `retain_mut` is for coherency and for discoverability. For example we have `chunks` and `chunks_mut` or `get` and `get_mut` or `iter` and `iter_mut`, etc. When looking for mutable `retain`, I would expect `retain_mut` to exist. It took me a while to find out about `drain_filter`. So even if it provides an API close to `drain_filter`, just for the discoverability, I think it's worth it. cc ``````@m-ou-se`````` ``````@jonas-schievink`````` ``````@Mark-Simulacrum``````
2021-11-15Stabilize format_args_captureJosh Triplett-1/+1
Works as expected, and there are widespread reports of success with it, as well as interest in it.
2021-11-15Give examples of format args capture in the fmt module documentationJosh Triplett-0/+18
2021-11-14Auto merge of #88282 - Neutron3529:patch-4, r=Mark-Simulacrumbors-0/+8
Optimize BinaryHeap::extend from Vec This improves the performance of extending `BinaryHeap`s from vectors directly. Future work may involve extending this optimization to other, similar, cases where the length of the added elements is well-known, but this is not yet done in this PR.
2021-11-13Auto merge of #90542 - the8472:privatize-the-means-of-rawvec-production, ↵bors-58/+6
r=joshtriplett Make RawVec private to alloc RawVec was previously exposed for compiler-internal use (libarena specifically) in 1acbb0a9350560d951359cc359361b87992a6f2b Since it is unstable, doc-hidden and has no associated tracking issue it was never meant for public use. And since it is no longer used outside alloc itself it can be made private again. Also remove some functions that are dead due to lack of internal users.
2021-11-12add tracking issue for `downcast_unchecked`Ibraheem Ahmed-3/+3
2021-11-12add unchecked downcast methodsIbraheem Ahmed-28/+103
2021-11-12Add Vec::retain_mutGuillaume Gomez-1/+29
2021-11-12provide a `SpecExtend` trait for `Vec<T>`Neutron3529-0/+8
The discussion is [here](https://internals.rust-lang.org/t/append-vec-to-binaryheap/15209/3)
2021-11-09Rollup merge of #90723 - asquared31415:box_docs, r=jyn514Matthias Krüger-0/+3
Better document `Box` and `alloc::alloc::box_free` connection The internal `alloc::alloc::box_free` function requires that its signature matches the `owned_box` struct's declaration, but previously that connection was only documented on the `box_free` function. This PR makes the documentation two-way to help anyone making theoretical changes to `Box` to see the connection, since changes are more likely to originate from `Box`.
2021-11-09document Box and box_free connectionasquared31415-0/+3
2021-11-08Add comments regarding superfluous `!Sync` implsbstrie-0/+6
2021-11-05Fix `str::SplitInclusive` stabilisation datembartlett21-1/+1
2021-11-05Add feature to `alloc` so we can re-export.mbartlett21-0/+1
2021-11-05Re-export `core::slice::EscapeAscii`mbartlett21-0/+2
2021-11-05Re-export `core::slice::SplitInclusive[Mut]`mbartlett21-0/+2
2021-11-03Make RawVec private to allocThe8472-58/+6
RawVec was previously exposed for compiler-internal use (libarena specifically) in 1acbb0a9350560d951359cc359361b87992a6f2b Since it is unstable, doc-hidden and has no associated tracking issue it was never meant for public use. And since it is no longer used outside alloc itself it can be made private again. Also remove some functions that are dead due to lack of internal users.
2021-11-02Implement `RefUnwindSafe` for `Rc<T>`inquisitivecrystal-0/+2
2021-11-01mention `remove` in `swap_remove`r00ster91-1/+4
2021-10-31Rollup merge of #89786 - jkugelman:must-use-len-and-is_empty, r=joshtriplettMatthias Krüger-2/+12
Add #[must_use] to len and is_empty Parent issue: #89692 r? `@joshtriplett`
2021-10-31Rollup merge of #90427 - jkugelman:must-use-alloc-leak, r=joshtriplettMatthias Krüger-0/+4
Add #[must_use] to alloc functions that would leak memory As [requested](https://github.com/rust-lang/rust/pull/89899#issuecomment-955600779) by `@joshtriplett.` > Please do go ahead and add the ones whose only legitimate use for ignoring the return value is leaking memory. (In a separate PR please.) I think it's sufficiently error-prone to call something like alloc and ignore the result that it's legitimate to require `let _ =` for that. I added `realloc` myself. Clippy ignored it because of its `mut` argument. ```rust alloc/src/alloc.rs:123:1 alloc unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8; ``` Parent issue: #89692 r? `@joshtriplett`
2021-10-31Rollup merge of #89951 - ojeda:stable-unwrap_unchecked, r=dtolnayMatthias Krüger-1/+0
Stabilize `option_result_unwrap_unchecked` Closes https://github.com/rust-lang/rust/issues/81383. Stabilization report: https://github.com/rust-lang/rust/issues/81383#issuecomment-944498212. ```@rustbot``` label +A-option-result +T-libs-api
2021-10-31Rollup merge of #89897 - jkugelman:must-use-core, r=joshtriplettMatthias Krüger-1/+1
Add #[must_use] to remaining core functions I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is everything remaining from the `core` crate. Ignored by clippy for reasons unknown: ```rust core::alloc::Layout unsafe fn for_value_raw<T: ?Sized>(t: *const T) -> Self; core::any const fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str; ``` Ignored by clippy because of `mut`: ```rust str fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str); ``` <del> Ignored by clippy presumably because a caller might want `f` called for side effects. That seems like a bad usage of `map` to me. ```rust core::cell::Ref<'b, T> fn map<U: ?Sized, F>(orig: Ref<'b, T>, f: F) -> Ref<'b, T>; core::cell::Ref<'b, T> fn map_split<U: ?Sized, V: ?Sized, F>(orig: Ref<'b, T>, f: F) -> (Ref<'b, U>, Ref<'b, V>); ``` </del> Parent issue: #89692 r? ```@joshtriplett```
2021-10-31Rollup merge of #89835 - jkugelman:must-use-expensive-computations, ↵Matthias Krüger-0/+10
r=joshtriplett Add #[must_use] to expensive computations The unifying theme for this commit is weak, admittedly. I put together a list of "expensive" functions when I originally proposed this whole effort, but nobody's cared about that criterion. Still, it's a decent way to bite off a not-too-big chunk of work. Given the grab bag nature of this commit, the messages I used vary quite a bit. I'm open to wording changes. For some reason clippy flagged four `BTreeSet` methods but didn't say boo about equivalent ones on `HashSet`. I stared at them for a while but I can't figure out the difference so I added the `HashSet` ones in. ```rust // Flagged by clippy. alloc::collections::btree_set::BTreeSet<T> fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, T>; alloc::collections::btree_set::BTreeSet<T> fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet<T>) -> SymmetricDifference<'a, T> alloc::collections::btree_set::BTreeSet<T> fn intersection<'a>(&'a self, other: &'a BTreeSet<T>) -> Intersection<'a, T>; alloc::collections::btree_set::BTreeSet<T> fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> Union<'a, T>; // Ignored by clippy, but not by me. std::collections::HashSet<T, S> fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S>; std::collections::HashSet<T, S> fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T, S>) -> SymmetricDifference<'a, T, S> std::collections::HashSet<T, S> fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S>; std::collections::HashSet<T, S> fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S>; ``` Parent issue: #89692 r? ```@joshtriplett```
2021-10-31Rollup merge of #89833 - jkugelman:must-use-rc-downgrade, r=joshtriplettMatthias Krüger-1/+3
Add #[must_use] to Rc::downgrade Missed this in previous PR https://github.com/rust-lang/rust/pull/89796#issuecomment-941456006 Parent issue: #89692 r? ```@joshtriplett```
2021-10-30Add #[must_use] to alloc functions that would leak memoryJohn Kugelman-0/+4
2021-10-30Add #[must_use] to len and is_emptyJohn Kugelman-4/+14
2021-10-31Rollup merge of #89899 - jkugelman:must-use-alloc, r=joshtriplettMatthias Krüger-23/+78
Add #[must_use] to remaining alloc functions I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is everything remaining from the `alloc` crate. I ignored these because they might be used to purposefully leak memory... or other allocator shenanigans? I dunno. I'll add them if y'all tell me to. ```rust alloc::alloc unsafe fn alloc(layout: Layout) -> *mut u8; alloc::alloc unsafe fn alloc_zeroed(layout: Layout) -> *mut u8; alloc::sync::Arc<T> fn into_raw(this: Self) -> *const T; ``` I don't know why clippy ignored these. I added them myself: ```rust alloc::collections::btree_map::BTreeMap<K, V> fn range<T: ?Sized, R>(&self, range: R) -> Range<'_, K, V>; alloc::collections::btree_set::BTreeSet<T> fn range<K: ?Sized, R>(&self, range: R) -> Range<'_, T>; ``` I added these non-mutating `mut` functions: ```rust alloc::collections::btree_map::BTreeMap<K, V> fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<'_, K, V>; alloc::collections::btree_map::BTreeMap<K, V> fn iter_mut(&mut self) -> IterMut<'_, K, V>; alloc::collections::btree_map::BTreeMap<K, V> fn values_mut(&mut self) -> ValuesMut<'_, K, V>; alloc::collections::linked_list::LinkedList<T> fn iter_mut(&mut self) -> IterMut<'_, T>; alloc::collections::linked_list::LinkedList<T> fn cursor_front_mut(&mut self) -> CursorMut<'_, T>; alloc::collections::linked_list::LinkedList<T> fn cursor_back_mut(&mut self) -> CursorMut<'_, T>; alloc::collections::linked_list::LinkedList<T> fn front_mut(&mut self) -> Option<&mut T>; alloc::collections::linked_list::LinkedList<T> fn back_mut(&mut self) -> Option<&mut T>; alloc::collections::linked_list::CursorMut<'a, T> fn current(&mut self) -> Option<&mut T>; alloc::collections::linked_list::CursorMut<'a, T> fn peek_next(&mut self) -> Option<&mut T>; alloc::collections::linked_list::CursorMut<'a, T> fn peek_prev(&mut self) -> Option<&mut T>; alloc::collections::linked_list::CursorMut<'a, T> fn front_mut(&mut self) -> Option<&mut T>; alloc::collections::linked_list::CursorMut<'a, T> fn back_mut(&mut self) -> Option<&mut T>; ``` I moved a few existing `#[must_use]`s from functions onto the iterator types they return: `IntoIterSorted`, `IntoKeys`, `IntoValues`. Parent issue: #89692 r? `@joshtriplett`
2021-10-30Add #[must_use] to remaining core functionsJohn Kugelman-1/+1
2021-10-27Rollup merge of #90239 - r00ster91:patch-1, r=fee1-deadMatthias Krüger-1/+1
Consistent big O notation in map.rs Follow up to #89216
2021-10-27Remove big O notationr00ster91-1/+1
2021-10-25Fix copy-paste error in String::as_mut_vec() docsnyanpasu64-4/+5
2021-10-25remove requirement of T: Debug from Weak<T>Violet-2/+2
2021-10-23update cfg(bootstrap)Pietro Albini-1/+1
2021-10-21Clarify undefined behaviour for binary heap, btree and hashsetWilfred Hughes-9/+9
Previously, it wasn't clear whether "This could include" was referring to logic errors, or undefined behaviour. Tweak wording to clarify this sentence does not relate to UB.
2021-10-21Rollup merge of #90099 - SkiFire13:fix-vec-swap-remove, r=dtolnayYuki Okushi-3/+4
Fix MIRI UB in `Vec::swap_remove` Fixes #90055 I find it weird that `Vec::swap_remove` read the last element to the stack just to immediately put it back in the `Vec` in place of the one at index `index`. It seems much more natural to me to just read the element at position `index` and then move the last element in its place. I guess this might also slightly improve codegen.
2021-10-21Rollup merge of #90010 - rusticstuff:vecdeque_with_capacity_in_overflow, ↵Yuki Okushi-1/+1
r=m-ou-se Avoid overflow in `VecDeque::with_capacity_in()`. The overflow only happens if alloc is compiled with overflow checks enabled and the passed capacity is greater or equal 2^(usize::BITS-1). The overflow shadows the expected "capacity overflow" panic leading to a test failure if overflow checks are enabled for std in the CI. Unblocks [CI: Enable overflow checks for test (non-dist) builds #89776](https://github.com/rust-lang/rust/pull/89776). For some reason the overflow is only observable with optimization turned off, but that is a separate issue.
2021-10-20Prevent invalid values from existing in Vec::swap_removeGiacomo Stevanato-3/+4
2021-10-20Stabilize `option_result_unwrap_unchecked`Miguel Ojeda-1/+0
Closes https://github.com/rust-lang/rust/issues/81383. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-10-19Reenable feature(nll) in alloc.Mara Bos-0/+1
2021-10-19Remove unused language #![feature]s from alloc.Mara Bos-5/+0
2021-10-19Remove unused library #![feature]s from alloc.Mara Bos-3/+0
2021-10-19Sort and categorize #![feature]s in alloc.Mara Bos-42/+52
2021-10-18Avoid overflow in `VecDeque::with_capacity_in()`.Hans Kratz-1/+1
2021-10-16Rollup merge of #89898 - Amanieu:remove_alloc_prelude, r=joshtriplettMatthias Krüger-30/+0
Remove alloc::prelude As per the libs team decision in #58935. Closes #58935