about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
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,
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/+1
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/+130
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.
2022-08-24Rollup merge of #100855 - IsaacCloos:master, r=joshtriplettMatthias Krüger-0/+2
Extra documentation for new formatting feature Documentation of this feature was added in #90473 and released in Rust 1.58. However, high traffic macros did not receive new examples. Namely `println!()` and `format!()`. The doc comments included in Rust are super important to the community- especially newcomers. I have met several other newbies like myself who are unaware of this recent (well about 7 months old now) update to the language allowing for convenient intra-string identifiers. Bringing small examples of this feature to the doc comments of `println!()` and `format!()` would be helpful to everyone learning the language. [Blog Post Announcing Feature](https://blog.rust-lang.org/2022/01/13/Rust-1.58.0.html) [Feature PR](https://github.com/rust-lang/rust/pull/90473) - includes several instances of documentation of the feature- minus the macros in question for this PR *This is my first time contributing to a project this large. Feedback would mean the world to me 😄* --- *Recreated; I violated the [No-Merge Policy](https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy)*
2022-08-23Auto merge of #99917 - yaahc:error-in-core-move, r=thomccbors-0/+403
Move Error trait into core This PR moves the error trait from the standard library into a new unstable `error` module within the core library. The goal of this PR is to help unify error reporting across the std and no_std ecosystems, as well as open the door to integrating the error trait into the panic reporting system when reporting panics whose source is an errors (such as via `expect`). This PR is a rewrite of https://github.com/rust-lang/rust/pull/90328 using new compiler features that have been added to support error in core.
2022-08-23Make use of `[wrapping_]byte_{add,sub}`Maybe Waffle-10/+7
...replacing `.cast().wrapping_offset().cast()` & similar code.
2022-08-22Move error trait into coreJane Losare-Lusby-0/+403
2022-08-22Rollup merge of #100872 - JanBeh:PR_vec_default_alloc_doc, r=fee1-deadDylan DPC-0/+2
Add guarantee that Vec::default() does not alloc Currently `Vec::new()` is guaranteed to not allocate until elements are pushed onto the `Vec`, but such a guarantee is missing for `Vec`'s implementation of `Default::default`. This adds such a guarantee for `Vec::default()` to the API reference. See also [this discussion on URLO](https://users.rust-lang.org/t/guarantee-that-vec-default-does-not-allocate/79903).
2022-08-22Rollup merge of #100820 - WaffleLapkin:use_ptr_is_aligned_methods, r=scottmcmDylan DPC-1/+1
Use pointer `is_aligned*` methods This PR replaces some manual alignment checks with calls to `pointer::{is_aligned, is_aligned_to}` and removes a useless pointer cast. r? `@scottmcm` _split off from #100746_
2022-08-22Rollup merge of #100331 - lo48576:try-reserve-preserve-on-failure, r=thomccDylan DPC-4/+8
Guarantee `try_reserve` preserves the contents on error Update doc comments to make the guarantee explicit. However, some implementations does not have the statement though. * `HashMap`, `HashSet`: require guarantees on hashbrown side. * `PathBuf`: simply redirecting to `OsString`. Fixes #99606.
2022-08-22Add guarantee that Vec::default() does not allocJan Behrens-0/+2
Currently `Vec::new()` is guaranteed to not allocate until elements are pushed onto the `Vec`, but such a guarantee is missing for `Vec`'s implementation of `Default::default`. This adds such a guarantee for `Vec::default()` to the API reference.