about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2022-10-19Rollup merge of #103153 - ChrisDenton:leak-oom, r=m-ou-seDylan DPC-1/+0
Allow `Vec::leak` when using `no_global_oom_handling` As [the documentation notes](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.leak), `Vec::leak` hasn't allocated since 1.57. cc `@Ericson2314` in case I'm missing something.
2022-10-18Rollup merge of #103163 - SUPERCILEX:uninit-array-assume2, r=scottmcmYuki Okushi-3/+3
Remove all uses of array_assume_init See https://github.com/rust-lang/rust/pull/103134#discussion_r997462733 r? `@scottmcm`
2022-10-17Remove all uses of array_assume_initAlex Saveau-3/+3
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-17Auto merge of #101837 - scottmcm:box-array-from-vec, r=m-ou-sebors-1/+50
Add `Box<[T; N]>: TryFrom<Vec<T>>` We have `[T; N]: TryFrom<Vec<T>>` (#76310) and `Box<[T; N]>: TryFrom<Box<[T]>>`, but not this combination. `vec.into_boxed_slice().try_into()` isn't quite a replacement for this, as that'll reallocate unnecessarily in the error case. **Insta-stable, so needs an FCP** (I tried to make this work with `, A`, but that's disallowed because of `#[fundamental]` https://github.com/rust-lang/rust/issues/29635#issuecomment-1247598385)
2022-10-17Allow `Vec::leak` with `no_global_oom_handling`Chris Denton-1/+0
2022-10-15Documentation BTreeMap::append's behavior for already existing keysphilipp-3/+6
2022-10-14Auto merge of #102529 - colinba:master, r=joshtriplettbors-1/+1
Detect and reject out-of-range integers in format string literals Until now out-of-range integers in format string literals were silently ignored. They wrapped around to zero at usize::MAX, producing unexpected results. When using debug builds of rustc, such integers in format string literals even cause an 'attempt to add with overflow' panic in rustc. Fix this by producing an error diagnostic for integers in format string literals which do not fit into usize. Fixes #102528
2022-10-14more dupe word typosRageking8-1/+1
2022-10-11rename rustc_allocator_nounwind to rustc_nounwindRalf Jung-4/+8
2022-10-11Rollup merge of #101727 - est31:stabilize_map_first_last, r=m-ou-seMatthias Krüger-20/+10
Stabilize map_first_last Stabilizes the following functions: ```Rust impl<T> BTreeSet<T> { pub fn first(&self) -> Option<&T> where T: Ord; pub fn last(&self) -> Option<&T> where T: Ord; pub fn pop_first(&mut self) -> Option<T> where T: Ord; pub fn pop_last(&mut self) -> Option<T> where T: Ord; } impl<K, V> BTreeMap<K, V> { pub fn first_key_value(&self) -> Option<(&K, &V)> where K: Ord; pub fn last_key_value(&self) -> Option<(&K, &V)> where K: Ord; pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>> where K: Ord; pub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>> where K: Ord; pub fn pop_first(&mut self) -> Option<(K, V)> where K: Ord; pub fn pop_last(&mut self) -> Option<(K, V)> where K: Ord; } ``` Closes #62924 ~~Blocked on the [FCP](https://github.com/rust-lang/rust/issues/62924#issuecomment-1179489929) finishing.~~ Edit: It finished!
2022-10-10Auto merge of #102596 - scottmcm:option-bool-calloc, r=Mark-Simulacrumbors-0/+22
Do the `calloc` optimization for `Option<bool>` Inspired by <https://old.reddit.com/r/rust/comments/xtiqj8/why_is_this_functional_version_faster_than_my_for/iqqy37b/>.
2022-10-09Auto merge of #89123 - the8472:push_in_capacity, r=amanieubors-0/+45
add Vec::push_within_capacity - fallible, does not allocate This method can serve several purposes. It * is fallible * guarantees that items in Vec aren't moved * allows loops that do `reserve` and `push` separately to avoid pulling in the allocation machinery a second time in the `push` part which should make things easier on the optimizer * eases the path towards `ArrayVec` a bit since - compared to `push()` - there are fewer questions around how it should be implemented I haven't named it `try_push` because that should probably occupy a middle ground that will still try to reserve and only return an error in the unlikely OOM case. resolves #84649
2022-10-05Fix overconstrained Send impls in btree internalsDavid Tolnay-3/+3
2022-10-04Rollup merge of #101642 - SkiFire13:fix-inplace-collection-leak, r=the8472Dylan DPC-6/+32
Fix in-place collection leak when remaining element destructor panic Fixes #101628 cc `@the8472` I went for the drop guard route, placing it immediately before the `forget_allocation_drop_remaining` call and after the comment, as to signal they are closely related. I also updated the test to check for the leak, though the only change really needed was removing the leak clean up for miri since now that's no longer leaked.
2022-10-03Rollup merge of #99216 - duarten:master, r=joshtriplettMatthias Krüger-8/+73
docs: be less harsh in wording for Vec::from_raw_parts In particular, be clear that it is sound to specify memory not originating from a previous `Vec` allocation. That is already suggested in other parts of the documentation about zero-alloc conversions to Box<[T]>. Incorporate a constraint from `slice::from_raw_parts` that was missing but needs to be fulfilled, since a `Vec` can be converted into a slice. Fixes https://github.com/rust-lang/rust/issues/98780.
2022-10-03Rollup merge of #98218 - kpreid:nostdarc, r=joshtriplettMatthias Krüger-0/+15
Document the conditional existence of `alloc::sync` and `alloc::task`. `alloc` declares ```rust #[cfg(target_has_atomic = "ptr")] pub mod sync; ``` but there is no public documentation of this condition. This PR fixes that, so that users of `alloc` can understand how to make their code compile everywhere `alloc` does, if they are writing a library with impls for `Arc`. The wording is copied from `std::sync::atomic::AtomicPtr`, with additional advice on how to `#[cfg]` for it. I feel quite uncertain about whether the paragraph I added to `Arc`'s documentation should actually be there, as it is a distraction for anyone using `std`. On the other hand, maybe more reminders that no_std exists would benefit the ecosystem. Note: `target_has_atomic` is [stabilized](https://github.com/rust-lang/rust/issues/32976) but [not yet documented in the reference](https://github.com/rust-lang/reference/pull/1171).
2022-10-03Clarify documentationGiacomo Stevanato-4/+3
2022-10-02Do the `calloc` optimization for `Option<bool>`Scott McMurray-0/+22
Inspired by <https://old.reddit.com/r/rust/comments/xtiqj8/why_is_this_functional_version_faster_than_my_for/iqqy37b/>.
2022-10-02Rollup merge of #102556 - WaffleLapkin:implied_by_btree_new, r=Mark-SimulacrumDylan DPC-4/+20
Make `feature(const_btree_len)` implied by `feature(const_btree_new)` ...this should fix code that used the old feature that was changed in #102197 cc ```@davidtwco``` it seems like tidy doesn't check `implied_by`, should it?
2022-10-02Rollup merge of #102098 - xfix:weak-upgrade-fetch-update, r=Mark-SimulacrumDylan DPC-23/+16
Use fetch_update in sync::Weak::upgrade Using `fetch_update` makes it more clear that it's CAS loop then manually implementing one.
2022-10-01Make `feature(const_btree_len)` implied by `feature(const_btree_new)`Maybe Waffle-4/+20
2022-10-01Detect and reject out-of-range integers in format string literalsColin Baumgarten-1/+1
Until now out-of-range integers in format string literals were silently ignored. They wrapped around to zero at usize::MAX, producing unexpected results. When using debug builds of rustc, such integers in format string literals even cause an 'attempt to add with overflow' panic in rustc. Fix this by producing an error diagnostic for integers in format string literals which do not fit into usize. Fixes #102528
2022-09-30Stabilize map_first_lastest31-20/+10
2022-09-29Stabilize `nonnull_slice_from_raw_parts`Yuki Okushi-1/+0
2022-09-26remove cfg(bootstrap)Pietro Albini-29/+3
2022-09-26Rollup merge of #102197 - Nilstrieb:const-new-🌲, r=Mark-Simulacrumfee1-dead-7/+7
Stabilize const `BTree{Map,Set}::new` The FCP was completed in #71835. Since `len` and `is_empty` are not const stable yet, this also creates a new feature for them since they previously used the same `const_btree_new` feature.
2022-09-25Auto merge of #102169 - scottmcm:constify-some-conditions, r=thomccbors-29/+34
Make ZST checks in core/alloc more readable There's a bunch of these checks because of special handing for ZSTs in various unsafe implementations of stuff. This lets them be `T::IS_ZST` instead of `mem::size_of::<T>() == 0` every time, making them both more readable and more terse. *Not* proposed for stabilization. Would be `pub(crate)` except `alloc` wants to use it too. (And while it doesn't matter now, if we ever get something like #85836 making it a const can help codegen be simpler.)
2022-09-23Put back one of the `use`s for intra-doc mentionsScott McMurray-0/+6
2022-09-23Stabilize const `BTree{Map,Set}::new`Nilstrieb-7/+7
Since `len` and `is_empty` are not const stable yet, this also creates a new feature for them since they previously used the same `const_btree_new` feature.
2022-09-22Make ZST checks in core/alloc more readableScott McMurray-29/+28
There's a bunch of these checks because of special handing for ZSTs in various unsafe implementations of stuff. This lets them be `T::IS_ZST` instead of `mem::size_of::<T>() == 0` every time, making them both more readable and more terse. *Not* proposed for stabilization at this time. Would be `pub(crate)` except `alloc` wants to use it too. (And while it doesn't matter now, if we ever get something like 85836 making it a const can help codegen be simpler.)
2022-09-22Auto merge of #100982 - fee1-dead-contrib:const-impl-requires-const-trait, ↵bors-2/+1
r=oli-obk Require `#[const_trait]` on `Trait` for `impl const Trait` r? `@oli-obk`
2022-09-21Use fetch_update in sync::Weak::upgradeKonrad Borowski-23/+16
2022-09-21Rollup merge of #89891 - ojeda:modular-alloc, r=Mark-SimulacrumDylan DPC-3/+6
`alloc`: add unstable cfg features `no_rc` and `no_sync` In Rust for Linux we are using these to make `alloc` a bit more modular. See https://github.com/rust-lang/rust/pull/86048 and https://github.com/rust-lang/rust/pull/84266 for similar requests. Of course, the particular names are not important.
2022-09-19Rollup merge of #101798 - y86-dev:const_waker, r=lcnrMatthias Krüger-0/+1
Make `from_waker`, `waker` and `from_raw` unstably `const` Make - `Context::from_waker` - `Context::waker` - `Waker::from_raw` `const`. Also added a small test.
2022-09-18Auto merge of #101816 - raldone01:cleanup/select_nth_unstable, r=Mark-Simulacrumbors-1/+1
Cleanup slice sort related closures in core and alloc
2022-09-17Add `Box<[T; N]>: TryFrom<Vec<T>>`Scott McMurray-1/+50
We have `[T; N]: TryFrom<Vec<T>>` and `Box<[T; N]>: TryFrom<Box<[T]>>`, but not the combination. `vec.into_boxed_slice().try_into()` isn't quite a replacement for this, as that'll reallocate unnecessarily in the error case. **Insta-stable, so needs an FCP**
2022-09-17Rollup merge of #101931 - msakuta:master, r=thomccDylan DPC-1/+1
doc: Fix a typo in `Rc::make_mut` docstring A very minor typo fix.
2022-09-17Fix a typo in docstringmsakuta-1/+1
2022-09-16Do not implement `Unpin` as constDeadbeef-2/+1
2022-09-15Only enable the let_else feature on bootstrapest31-1/+1
On later stages, the feature is already stable. Result of running: rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-14Cleanup closures.raldone01-1/+1
2022-09-14Made from_waker, waker, from_raw consty86-dev-0/+1
2022-09-10Alternate approach; just modify DrainBen Kimock-52/+59
2022-09-10Remove &[T] from vec_deque::DrainBen Kimock-23/+41
2022-09-10Make the one-liner more descriptiveStefan Schindler-2/+2
2022-09-10Update documentationGiacomo Stevanato-3/+11
2022-09-10Fix leaking in inplace collection when destructor panicsGiacomo Stevanato-3/+22
2022-09-04Auto merge of #93455 - asquared31415:vec-zero-opts, r=thomccbors-0/+17
Implement internal `IsZero` for Wrapping and Saturating for `Vec` optimizations This implements the `IsZero` trait for the `Wrapping` and `Saturating` types so that users of these types can get the improved performance from the specialization of creating a `Vec` from a single element repeated when it has a zero bit pattern (example `vec![0_i32; 500]`, or after this PR `vec![Wrapping(0_i32); 500]`) CC #60978
2022-09-02implement IsZero for Saturating and Wrappingasquared31415-0/+17
2022-09-02Fix internal doc linkChris Denton-1/+3
The doc link from `DedupSortedIter` to `BTreeMap::bulk_build_from_sorted_iter` was broken when building internal documentation,