about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
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
2023-02-25Rollup merge of #108407 - notriddle:notriddle/vec-get-mut, r=thomccMatthias Krüger-2/+2
docs: use intra-doc links for `Vec::get(_mut)` Now that #63351 is fixed, there's no reason not to. CC #75672
2023-02-25binary_heap: Unify Extend implementation.Tatsuyuki Ishi-34/+2
Previously the bulk rebuild specialization was only available with Vec, and for general iterators Extend only provided pre-allocation through reserve(). By using a drop guard, we can safely bulk rebuild even if the iterator may panic. This allows benefiting from the bulk rebuild optimization without collecting iterator elements into a Vec beforehand, which would nullify any performance gains from bulk rebuild.
2023-02-25binary_heap: Make RebuildOnDrop a common helper.Tatsuyuki Ishi-17/+17
This helper was written for retain() but will also be useful for extend().
2023-02-24Rollup merge of #106918 - dtolnay:heapretain, r=the8472Dylan DPC-6/+37
Rebuild BinaryHeap on unwind from retain This closes the hole identified in https://github.com/rust-lang/rust/issues/71503#issuecomment-1383251315 which had made it possible for the caller to end up with a heap in invalid state. As of #105851, heaps in invalid state are not supposed to exist.
2023-02-23docs: use intra-doc links for `Vec::get(_mut)`Michael Howell-2/+2
Now that #63351 is fixed, there's no reason not to.
2023-02-20Changes according to reviewMarkus Everling-11/+11
2023-02-19Remove the assume(!is_null) from Vec::as_ptrBen Kimock-11/+2
2023-02-18Auto merge of #106241 - Sp00ph:vec_deque_iter_methods, r=the8472bors-2/+329
Implement more methods for `vec_deque::IntoIter` This implements a couple `Iterator` methods on `vec_deque::IntoIter` (`(try_)fold`, `(try_)rfold` `advance_(back_)by`, `next_chunk`, `count` and `last`) to allow these to be more efficient than their default implementations, also allowing many other `Iterator` methods that use these under the hood to take advantage of these manual implementations. `vec::IntoIter` has similar implementations for many of these methods. This PR does not yet implement `TrustedRandomAccess` and friends, as I'm not very familiar with the required safety guarantees. r? `@the8472` (since you also took over my last PR)
2023-02-12Auto merge of #105671 - lukas-code:depreciate-char, r=scottmcmbors-4/+4
Use associated items of `char` instead of freestanding items in `core::char` The associated functions and constants on `char` have been stable since 1.52 and the freestanding items have soft-deprecated since 1.62 (https://github.com/rust-lang/rust/pull/95566). This PR ~~marks them as "deprecated in future", similar to the integer and floating point modules (`core::{i32, f32}` etc)~~ replaces all uses of `core::char::*` with `char::*` to prepare for future deprecation of `core::char::*`.
2023-02-11Auto merge of #106677 - tbu-:pr_less_doc_hidden_pub, r=scottmcmbors-7/+1
Remove a couple of `#[doc(hidden)] pub fn` and their `#[feature]` gates
2023-02-11Auto merge of #107167 - the8472:rawvec-simpler-layout, r=thomccbors-5/+12
simplify layout calculations in rawvec The use of `Layout::array` was introduced in #83706 which lead to a [perf regression](https://github.com/rust-lang/rust/pull/83706#issuecomment-1048377719). This PR basically reverts that change since rust currently only supports stride == size types, but to be on the safe side it leaves a const-assert there to make sure this gets caught if those assumptions ever change.
2023-02-10Remove a couple of `#[doc(hidden)] pub fn` and their `#[feature]` gatesTobias Bucher-7/+1
2023-02-08Rollup merge of #107429 - tgross35:from-bytes-until-null-stabilization, ↵Michael Goulet-1/+0
r=dtolnay Stabilize feature `cstr_from_bytes_until_nul` This PR seeks to stabilize `cstr_from_bytes_until_nul`. Partially addresses #95027 This function has only been on nightly for about 10 months, but I think it is simple enough that there isn't harm discussing stabilization. It has also had at least a handful of mentions on both the user forum and the discord, so it seems like it's already in use or at least known. This needs FCP still. Comment on potential discussion points: - eventual conversion of `CStr` to be a single thin pointer: this function will still be useful to provide a safe way to create a `CStr` after this change. - should this return a length too, to address concerns about the `CStr` change? I don't see it as being particularly useful, and it seems less ergonomic (i.e. returning `Result<(&CStr, usize), FromBytesUntilNulError>`). I think users that also need this length without the additional `strlen` call are likely better off using a combination of other methods, but this is up for discussion - `CString::from_vec_until_nul`: this is also useful, but it doesn't even have a nightly implementation merged yet. I propose feature gating that separately, as opposed to blocking this `CStr` implementation on that Possible alternatives: A user can use `from_bytes_with_nul` on a slice up to `my_slice[..my_slice.iter().find(|c| c == 0).unwrap()]`. However; that is significantly less ergonomic, and is a bit more work for the compiler to optimize compared the direct `memchr` call that this wraps. ## New stable API ```rs // both in core::ffi pub struct FromBytesUntilNulError(()); impl CStr { pub const fn from_bytes_until_nul( bytes: &[u8] ) -> Result<&CStr, FromBytesUntilNulError> } ``` cc ```@ericseppanen``` original author, ```@Mark-Simulacrum``` original reviewer, ```@m-ou-se``` brought up some issues on the thin pointer CStr ```@rustbot``` modify labels: +T-libs-api +needs-fcp
2023-02-08Rollup merge of #105641 - Amanieu:btree_cursor, r=m-ou-seMatthias Krüger-41/+957
Implement cursors for BTreeMap See the ACP for an overview of the API: https://github.com/rust-lang/libs-team/issues/141 The implementation is split into 2 commits: - The first changes the internal insertion functions to return a handle to the newly inserted element. The lifetimes involved are a bit hairy since we need a mutable handle to both the `BTreeMap` itself (which holds the root) and the nodes allocated in memory. I have tested that this passes the standard library testsuite under miri. - The second commit implements the cursor API itself. This is more straightforward to follow but still involves some unsafe code to deal with simultaneous mutable borrows of the tree root and the node that is currently being iterated.
2023-02-07Docs: Fix format of headings in String::reserveDanilo Bargen-2/+2
2023-02-05Add `slice_ranges` safety commentMarkus Everling-5/+12
2023-02-01Stabilize feature 'cstr_from_bytes_until_nul'Trevor Gross-1/+0
2023-02-01BTreeMap: Add Cursor and CursorMutAmanieu d'Antras-5/+839
2023-02-01BTreeMap: Change internal insert function to return a handleAmanieu d'Antras-37/+119
This is a prerequisite for cursor support for `BTreeMap`.
2023-01-31Auto merge of #107297 - Mark-Simulacrum:bump-bootstrap, r=pietroalbinibors-2/+2
Bump bootstrap compiler to 1.68 This also changes our stage0.json to include the rustc component for the rustfmt pinned nightly toolchain, which is currently necessary due to rustfmt dynamically linking to that toolchain's librustc_driver and libstd. r? `@pietroalbini`
2023-01-31Fix `vec_deque::Drain` FIXMEMarkus Everling-31/+19
2023-01-30Rollup merge of #107424 - bpeel:clone-into-from-share-code, r=scottmcmMatthias Krüger-40/+34
Make Vec::clone_from and slice::clone_into share the same code In the past, `Vec::clone_from` was implemented using `slice::clone_into`. The code from `clone_into` was later duplicated into `clone_from` in 8725e4c337, which is the commit that adds custom allocator support to Vec. Presumably this was done because the `slice::clone_into` method only works for vecs with the default allocator so it would have the wrong type to clone into `Vec<T, A>`. Later on in 361398009be6 the code for the two methods diverged because the `Vec::clone_from` version gained a specialization to optimize the case when T is Copy. In order to reduce code duplication and make them both be able to take advantage of this specialization, this PR moves the specialization into the slice module and makes vec use it again.
2023-01-30Rollup merge of #107452 - y21:get-mut-unchecked-typo, r=Mark-SimulacrumDylan DPC-2/+2
Fix typo in `{Rc, Arc}::get_mut_unchecked` docs Just a correction in the documentation of `{Rc, Arc}::get_mut_unchecked`.
2023-01-30Rollup merge of #101569 - m-ou-se:alloc-no-rexport-argumentv1, r=thomccDylan DPC-1/+1
Don't re-export private/unstable ArgumentV1 from `alloc`. The `alloc::fmt::ArgumentV1` re-export was marked as `#[stable]` even though the original `core::fmt::ArgumentV1` is `#[unstable]` (and `#[doc(hidden)]`). (It wasn't usable though: ``` error[E0658]: use of unstable library feature 'fmt_internals': internal to format_args! --> src/main.rs:4:12 | 4 | let _: alloc::fmt::ArgumentV1 = todo!(); | ^^^^^^^^^^^^^^^^^^^^^^ | = help: add `#![feature(fmt_internals)]` to the crate attributes to enable ``` ) Part of #99012
2023-01-29Don't re-export private/unstable ArgumentV1 from `alloc`.Mara Bos-1/+1
2023-01-29fix typo in {Rc, Arc}::get_mut_unchecked docsy21-2/+2
2023-01-28vec: Use SpecCloneIntoVec::clone_into to implement Vec::clone_fromNeil Roberts-30/+1
In the past, Vec::clone_from was implemented using slice::clone_into. The code from clone_into was later duplicated into clone_from in 8725e4c337, which is the commit that adds custom allocator support to Vec. Presumably this was done because the slice::clone_into only works for vecs with the default allocator so it would have the wrong type to clone into Vec<T, A>. Now that the clone_into implementation is moved out into a specializable trait anyway we might as well use that to share the code between the two methods.
2023-01-28slice: Add a specialization for clone_into when T is CopyNeil Roberts-10/+33
The implementation for the ToOwned::clone_into method on [T] is a copy of the code for vec::clone_from. In 361398009be6 the code for vec::clone_from gained a specialization for when T is Copy. This commit copies that specialization over to the clone_into implementation.
2023-01-28Reintroduce multiple_supertrait_upcastable lintGary Guo-0/+2
2023-01-25Set version placeholders to 1.68Mark Rousskov-2/+2
2023-01-23Rollup merge of #107109 - est31:thin_box_link, r=Mark-SimulacrumYuki Okushi-2/+6
ThinBox: Add intra-doc-links for Metadata
2023-01-23Rollup merge of #106854 - steffahn:drop_linear_arc_rebased, r=Mark-SimulacrumDylan DPC-0/+177
Add `Arc::into_inner` for safely discarding `Arc`s without calling the destructor on the inner type. ACP: rust-lang/libs-team#162 Reviving #79665. I want to get this merged this time; this does not contain changes (apart from very minor changes in comments/docs). See #79665 for further description of the PR. The only “unresolved” points that led to that PR being closed, AFAICT, were * The desire to also implement a `Rc::into_inner` function * however, this can very well also happen as a subsequent PR * Possible need for further discussion on the naming “`into_inner`” (?) * `into_inner` seems fine to me; also, this PR introduces unstable API, and names can be changed later, too * ~~I don't know if a tracking issue for the feature flag is supposed to be opened before or after this PR gets merged (if *before*, then I can add the issue number to the `#[unstable…]` attribute)~~ There is a [tracking issue](https://github.com/rust-lang/rust/issues/106894) now. I say “unresolved” in quotation marks because from my point of view, if reviewers agree, the PR can be merged immediately and as-is :-)
2023-01-22simplify layout calculations in rawvecThe 8472-5/+12
2023-01-22Add Arc::into_inner for safely discarding Arcs without calling the ↵Frank Steffahn-0/+177
destructor on the inner type. Mainly rebased and squashed from PR rust-lang/rust#79665, furthermore includes minor changes in comments.
2023-01-20Rollup merge of #104672 - Voultapher:unify-sort-modules, r=thomccMichael Goulet-309/+39
Unify stable and unstable sort implementations in same core module This moves the stable sort implementation to the core::slice::sort module. By virtue of being in core it can't access `Vec`. The two `Vec` used by merge sort, `buf` and `runs`, are modelled as custom types that implement the very limited required `Vec` interface with the help of provided allocation and free functions. This is done to allow future re-use of functions and logic between stable and unstable sort. Such as `insert_head`. This is in preparation of #100856 and #104116. It only moves code, it *doesn't* change any of the sort related logic. This unlocks the ability to share `insert_head`, `insert_tail`, `swap_if_less` `merge` and more. Tagging ````@Mark-Simulacrum```` I hope this allows progress on #100856, by moving `merge_sort` here I hope future changes will be easier to review.
2023-01-20ThinBox: Add intra-doc-links for Metadataest31-2/+6
2023-01-19Auto merge of #106989 - clubby789:is-zero-num, r=scottmcmbors-1/+20
Implement `alloc::vec::IsZero` for `Option<$NUM>` types Fixes #106911 Mirrors the `NonZero$NUM` implementations with an additional `assert_zero_valid`. `None::<i32>` doesn't stricly satisfy `IsZero` but for the purpose of allocating we can produce more efficient codegen.