about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
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-21/+10
2022-09-29Stabilize `nonnull_slice_from_raw_parts`Yuki Okushi-3/+1
2022-09-28Rollup merge of #102232 - Urgau:stabilize-bench_black_box, r=TaKO8KiYuki Okushi-1/+0
Stabilize bench_black_box This PR stabilize `feature(bench_black_box)`. ```rust pub fn black_box<T>(dummy: T) -> T; ``` The FCP was completed in https://github.com/rust-lang/rust/issues/64102. `@rustbot` label +T-libs-api -T-libs
2022-09-27Stabilize bench_black_boxUrgau-1/+0
2022-09-26remove cfg(bootstrap)Pietro Albini-29/+3
2022-09-26Rollup merge of #102197 - Nilstrieb:const-new-🌲, r=Mark-Simulacrumfee1-dead-8/+8
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-8/+8
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 testGiacomo Stevanato-33/+34
2022-09-10Update documentationGiacomo Stevanato-3/+11
2022-09-10Adapt inplace collection leak test to check for no leaksGiacomo Stevanato-16/+20
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,
2022-09-01Auto merge of #100707 - dzvon:fix-typo, r=davidtwcobors-3/+3
Fix a bunch of typo This PR will fix some typos detected by [typos]. I only picked the ones I was sure were spelling errors to fix, mostly in the comments. [typos]: https://github.com/crate-ci/typos
2022-08-31fix into_iter on ZSTRalf Jung-1/+7
2022-08-31Fix a bunch of typoDezhi Wu-3/+3
This PR will fix some typos detected by [typos]. I only picked the ones I was sure were spelling errors to fix, mostly in the comments. [typos]: https://github.com/crate-ci/typos
2022-08-30Rollup merge of #95376 - WaffleLapkin:drain_keep_rest, r=dtolnayDylan DPC-3/+190
Add `vec::Drain{,Filter}::keep_rest` This PR adds `keep_rest` methods to `vec::Drain` and `vec::DrainFilter` under `drain_keep_rest` feature gate: ```rust // mod alloc::vec impl<T, A: Allocator> Drain<'_, T, A> { pub fn keep_rest(self); } impl<T, F, A: Allocator> DrainFilter<'_, T, F, A> where F: FnMut(&mut T) -> bool, { pub fn keep_rest(self); } ``` Both these methods cancel draining of elements that were not yet yielded from the iterators. While this needs more testing & documentation, I want at least start the discussion. This may be a potential way out of the "should `DrainFilter` exhaust itself on drop?" argument.
2022-08-29Rollup merge of #100819 - WaffleLapkin:use_ptr_byte_methods, r=scottmcmDylan DPC-10/+7
Make use of `[wrapping_]byte_{add,sub}` These new methods trivially replace old `.cast().wrapping_offset().cast()` & similar code. Note that [`arith_offset`](https://doc.rust-lang.org/std/intrinsics/fn.arith_offset.html) and `wrapping_offset` are the same thing. r? ``@scottmcm`` _split off from #100746_
2022-08-28fill-in tracking issue for `feature(drain_keep_rest)`Maybe Waffle-2/+2
2022-08-28add examples to `vec::Drain{,Filter}::keep_rest` docsMaybe Waffle-0/+37
2022-08-28Rollup merge of #99570 - XrXr:box-from-slice-docs, r=thomccMatthias Krüger-1/+1
Box::from(slice): Clarify that contents are copied A colleague mentioned that they interpreted the old text as saying that only the pointer and the length are copied. Add a clause so it is more clear that the pointed to contents are also copied.
2022-08-26`alloc`: add unstable cfg features `no_rc` and `no_sync`Miguel Ojeda-3/+6
In Rust for Linux we are using these to make `alloc` a bit more modular. A `run-make-fulldeps` test is added for each of them, so that enabling each of them independently is kept in a compilable state. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-08-26Rollup merge of #95005 - ssomers:btree_static_assert, r=thomccGuillaume Gomez-7/+9
BTree: evaluate static type-related check at compile time `assert`s like the ones replaced here would only go off when you run the right test cases, if the code were ever incorrectly changed such that rhey would trigger. But [inspired on a nice forum question](https://users.rust-lang.org/t/compile-time-const-generic-parameter-check/69202), they can be checked at compile time.