about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
2024-07-06Remove non-focused memory leaks in `alloc` doctests for Miri.Zachary S-0/+12
2024-07-06Fix them doc examples some moreAljoscha Meyer-2/+2
Apologies for the many attempts, my dev loop for this consists of editing on github, committing, and then waiting for the CI failure log to yell at me.
2024-07-06Fix doc examplesAljoscha Meyer-2/+2
2024-07-06Run formatter on alloc/src/boxed.rsAljoscha Meyer-4/+10
2024-07-06Mark format! with must_use hintlukas-21/+30
2024-07-06Add missing try_new_uninit_slice_in and try_new_zeroed_slice_inAljoscha Meyer-2/+75
The methods for fallible slice allocation in a given allocator were missing, which was an oversight according to https://github.com/rust-lang/wg-allocators/issues/130 This PR adds them as `try_new_uninit_slice_in` and `try_new_zeroed_slice_in`. Also adds missing punctuation to the doc comments of ` try_new_uninit_slice` and `try_new_zeroed_slice`
2024-07-05Run alloc sync testsChris Denton-6/+2
2024-07-04Add more checks for pointers with vtable metaMaybe Waffle-3/+3
The rules for casting `*mut X<dyn A>` -> `*mut Y<dyn B>` are as follows: - If `B` has a principal - `A` must have exactly the same principal (including generics) - Auto traits of `B` must be a subset of autotraits in `A` Note that `X<_>` and `Y<_>` can be identity, or arbitrary structs with last field being the dyn type. The lifetime of the trait object itself (`dyn ... + 'a`) is not checked. This prevents a few soundness issues with `#![feature(arbitrary_self_types)]` and trait upcasting. Namely, these checks make sure that vtable is always valid for the pointee.
2024-07-03Rollup merge of #123588 - tgross35:stabilize-assert_unchecked, r=dtolnayJacob Pratt-1/+0
Stabilize `hint::assert_unchecked` Make the following API stable, including const: ```rust // core::hint, std::hint pub const unsafe fn assert_unchecked(p: bool); ``` This PR also reworks some of the documentation and adds an example. Tracking issue: https://github.com/rust-lang/rust/issues/119131 FCP: https://github.com/rust-lang/rust/issues/119131#issuecomment-1906394087. The docs update should resolve the remaining concern.
2024-07-01Avoid MIR bloat in inliningScott McMurray-0/+18
In 126578 we ended up with more binary size increases than expected. This change attempts to avoid inlining large things into small things, to avoid that kind of increase, in cases when top-down inlining will still be able to do that inlining later.
2024-06-30Auto merge of #127026 - Urgau:cleanup-bootstrap-check-cfg, r=Kobzolbors-2/+0
Cleanup bootstrap check-cfg This PR cleanup many custom `check-cfg` in bootstrap that have been accumulated over the years. As well as updating some outdated comments.
2024-07-01LinkedList's Cursor: method to get a ref to the cursor's listPavel Grigorenko-0/+20
2024-06-28Rollup merge of #126970 - DaniPopes:simplify-str-clone_into, r=cuviperMatthias Krüger-3/+4
Simplify `str::clone_into` Removes an `unsafe` in favor of just using `String` methods.
2024-06-27Cleanup bootstrap check-cfgUrgau-2/+0
2024-06-27Rollup merge of #126929 - nnethercote:rm-__rust_force_expr, r=oli-obkJacob Pratt-14/+4
Remove `__rust_force_expr`. This was added (with a different name) to improve an error message. It is no longer needed -- removing it changes the error message, but overall I think the new message is no worse: - the mention of `#` in the first line is a little worse, - but the extra context makes it very clear what the problem is, perhaps even clearer than the old message, - and the removal of the note about the `expr` fragment (an internal detail of `__rust_force_expr`) is an improvement. Overall I think the error is quite clear and still far better than the old message that prompted #61933, which didn't even mention patterns. The motivation for this is #124141, which will cause pasted metavariables to be tokenized and reparsed instead of the AST node being cached. This change in behaviour occasionally has a non-zero perf cost, and `__rust_force_expr` causes the tokenize/reparse step to occur twice. Removing `__rust_force_expr` greatly reduces the extra overhead for the `deep-vector` benchmark. r? ```@oli-obk```
2024-06-25Simplify `str::clone_into`DaniPopes-3/+4
Removes an `unsafe` in favor of just using `String` methods.
2024-06-25Rollup merge of #126302 - mu001999-contrib:ignore/default, r=michaelwoeristerMatthias Krüger-1/+1
Detect unused structs which derived Default <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> Fixes #98871
2024-06-25Detect unused structs which derived Defaultmu001999-1/+1
2024-06-25Remove `__rust_force_expr`.Nicholas Nethercote-14/+4
This was added (with a different name) to improve an error message. It is no longer needed -- removing it changes the error message, but overall I think the new message is no worse: - the mention of `#` in the first line is a little worse, - but the extra context makes it very clear what the problem is, perhaps even clearer than the old message, - and the removal of the note about the `expr` fragment (an internal detail of `__rust_force_expr`) is an improvement. Overall I think the error is quite clear and still far better than the old message that prompted #61933, which didn't even mention patterns. The motivation for this is #124141, which will cause pasted metavariables to be tokenized and reparsed instead of the AST node being cached. This change in behaviour occasionally has a non-zero perf cost, and `__rust_force_expr` causes the tokenize/reparse step to occur twice. Removing `__rust_force_expr` greatly reduces the extra overhead for the `deep-vector` benchmark.
2024-06-24Replace `MaybeUninit::uninit_array()` with array repeat expression.Kevin Reid-3/+2
This is possible now that inline const blocks are stable; the idea was even mentioned as an alternative when `uninit_array()` was added: <https://github.com/rust-lang/rust/pull/65580#issuecomment-544200681> > if it’s stabilized soon enough maybe it’s not worth having a > standard library method that will be replaceable with > `let buffer = [MaybeUninit::<T>::uninit(); $N];` Const array repetition and inline const blocks are now stable (in the next release), so that circumstance has come to pass, and we no longer have reason to want `uninit_array()` other than convenience. Therefore, let’s evaluate the inconvenience by not using `uninit_array()` in the standard library, before potentially deleting it entirely.
2024-06-22Auto merge of #126838 - matthiaskrgr:rollup-qkop22o, r=matthiaskrgrbors-1/+0
Rollup of 3 pull requests Successful merges: - #126140 (Rename `std::fs::try_exists` to `std::fs::exists` and stabilize fs_try_exists) - #126318 (Add a `x perf` command for integrating bootstrap with `rustc-perf`) - #126552 (Remove use of const traits (and `feature(effects)`) from stdlib) r? `@ghost` `@rustbot` modify labels: rollup
2024-06-22Auto merge of #116113 - kpreid:arcmut, r=dtolnaybors-58/+238
Generalize `{Rc,Arc}::make_mut()` to unsized types. * `{Rc,Arc}::make_mut()` now accept any type implementing the new unstable trait `core::clone::CloneToUninit`. * `CloneToUninit` is implemented for `T: Clone` and for `[T] where T: Clone`. * `CloneToUninit` is a generalization of the existing internal trait `alloc::alloc::WriteCloneIntoRaw`. * New feature gate: `clone_to_uninit` This allows performing `make_mut()` on `Rc<[T]>` and `Arc<[T]>`, which was not previously possible. --- Previous PR description, now obsolete: > Add `{Rc, Arc}::make_mut_slice()` > > These functions behave identically to `make_mut()`, but operate on `Arc<[T]>` instead of `Arc<T>`. > > This allows performing the operation on slices, which was not previously possible because `make_mut()` requires `T: Clone` (and slices, being `!Sized`, do not and currently cannot implement `Clone`). > > Feature gate: `make_mut_slice` try-job: test-various
2024-06-22Generalize `{Rc,Arc}::make_mut()` to unsized types.Kevin Reid-26/+229
This requires introducing a new internal type `RcUninit` (and `ArcUninit`), which can own an `RcBox<T>` without requiring it to be initialized, sized, or a slice. This is similar to `UniqueRc`, but `UniqueRc` doesn't support the allocator parameter, and there is no `UniqueArc`.
2024-06-22Replace `WriteCloneIntoRaw` with `CloneToUninit`.Kevin Reid-34/+11
2024-06-21Remove `feature(effects)` from the standard libraryDeadbeef-1/+0
2024-06-20Auto merge of #124032 - Voultapher:a-new-sort, r=thomccbors-118/+115
Replace sort implementations This PR replaces the sort implementations with tailor-made ones that strike a balance of run-time, compile-time and binary-size, yielding run-time and compile-time improvements. Regressing binary-size for `slice::sort` while improving it for `slice::sort_unstable`. All while upholding the existing soft and hard safety guarantees, and even extending the soft guarantees, detecting strict weak ordering violations with a high chance and reporting it to users via a panic. * `slice::sort` -> driftsort [design document](https://github.com/Voultapher/sort-research-rs/blob/main/writeup/driftsort_introduction/text.md), includes detailed benchmarks and analysis. * `slice::sort_unstable` -> ipnsort [design document](https://github.com/Voultapher/sort-research-rs/blob/main/writeup/ipnsort_introduction/text.md), includes detailed benchmarks and analysis. #### Why should we change the sort implementations? In the [2023 Rust survey](https://blog.rust-lang.org/2024/02/19/2023-Rust-Annual-Survey-2023-results.html#challenges), one of the questions was: "In your opinion, how should work on the following aspects of Rust be prioritized?". The second place was "Runtime performance" and the third one "Compile Times". This PR aims to improve both. #### Why is this one big PR and not multiple? * The current documentation gives performance recommendations for `slice::sort` and `slice::sort_unstable`. If for example only one of them were to be changed, this advice would be misleading for some Rust versions. By replacing them atomically, the advice remains largely unchanged, and users don't have to change their code. * driftsort and ipnsort share a substantial part of their implementations. * The implementation of `select_nth_unstable` uses internals of `slice::sort_unstable`, which makes it impractical to split changes. --- This PR is a collaboration with `@orlp.`
2024-06-20Fix wrong big O star bracing in the doc commentsLukas Bergdoll-3/+3
2024-06-20Auto merge of #126736 - matthiaskrgr:rollup-rb20oe3, r=matthiaskrgrbors-3/+5
Rollup of 7 pull requests Successful merges: - #126380 (Add std Xtensa targets support) - #126636 (Resolve Clippy `f16` and `f128` `unimplemented!`/`FIXME`s ) - #126659 (More status-quo tests for the `#[coverage(..)]` attribute) - #126711 (Make Option::as_[mut_]slice const) - #126717 (Clean up some comments near `use` declarations) - #126719 (Fix assertion failure for some `Expect` diagnostics.) - #126730 (Add opaque type corner case test) r? `@ghost` `@rustbot` modify labels: rollup
2024-06-19Stabilize `hint_assert_unchecked`Trevor Gross-1/+0
Make both `hint_assert_unchecked` and `const_hint_assert_unchecked` stable as `hint_assert_unchecked`.
2024-06-20Add blank lines after module-level `//!` comments.Nicholas Nethercote-0/+1
Most modules have such a blank line, but some don't. Inserting the blank line makes it clearer that the `//!` comments are describing the entire module, rather than the `use` declaration(s) that immediately follows.
2024-06-20Convert some module-level `//` and `///` comments to `//!`.Nicholas Nethercote-3/+4
This makes their intent and expected location clearer. We see some examples where these comments were not clearly separate from `use` declarations, which made it hard to understand what the comment is describing.
2024-06-19Stabilise c_unwindGary Guo-1/+1
2024-06-17Revert panic_safe test changesLukas Bergdoll-1/+2
The changes made only a limited improvement for the current small miri coverage and in general test coverage of the sort implementations. But they exploded test times from ~13s to ~240s, which is not deemed worth it.
2024-06-16Update `Arc::try_unwrap()` docslukaslueg-9/+12
Clarify the language wrt `race condition` not meaning `memory unsafety`.
2024-06-14Rollup merge of #126285 - kpreid:unique-rc, r=dtolnayMatthias Krüger-30/+91
`UniqueRc`: support allocators and `T: ?Sized`. Added the following (all unstable): * Defaulted type pararameter `A: Allocator`. * `UniqueRc::new_in()`. * `T: ?Sized` where possible. * `impl CoerceUnsized for UniqueRc`. These changes are motivated by supporting the implementation of unsized `Rc::make_mut()` (PR #116113), but are also intended to be obvious generalizations of `UniqueRc` to support the things `Rc` does. r? ``````@the8472``````
2024-06-11`UniqueRc`: support allocators and `T: ?Sized`.Kevin Reid-30/+91
Added the following (all unstable): * Defaulted type pararameter `A: Allocator`. * `UniqueRc::new_in()`. * `T: ?Sized` where possible. * `impl CoerceUnsized for UniqueRc`. * Drive-by doc polish: links and periods at the end of sentences. These changes are motivated by supporting the implementation of unsized `Rc::make_mut()` (PR #116113), but are also intended to be obvious generalizations of `UniqueRc` to support the things `Rc` does.
2024-06-11remove cfg(bootstrap)Pietro Albini-3/+1
2024-06-11replace version placeholderPietro Albini-24/+21
2024-06-08Rollup merge of #125951 - slanterns:error_in_core_stabilization, r=AmanieuLeón Orell Valerian Liehr-1/+0
Stabilize `error_in_core` Closes: https://github.com/rust-lang/rust/issues/103765. `@rustbot` label: +T-libs-api r? libs-api
2024-06-07Rollup merge of #124012 - slanterns:as_slice_stabilize, r=BurntSushiMatthias Krüger-3/+1
Stabilize `binary_heap_as_slice` This PR stabilizes `binary_heap_as_slice`: ```rust // std::collections::BinaryHeap impl BinaryHeap<T> { pub fn as_slice(&self) -> &[T] } ``` <br> Tracking issue: https://github.com/rust-lang/rust/issues/83659. Implementation PR: https://github.com/rust-lang/rust/pull/82331. FCPs already completed in the tracking issue. Closes https://github.com/rust-lang/rust/issues/83659. r? libs-api
2024-06-07Stabilize `error_in_core`Slanterns-1/+0
2024-06-06less garbage, more examplesRalf Jung-2/+2
2024-06-05Rollup merge of #125982 - xTachyon:fix-linked-list, r=jhprattJubilee-2/+41
Make deleting on LinkedList aware of the allocator Fixed #125950
2024-06-05Rollup merge of #123168 - joshtriplett:size-of-prelude, r=AmanieuJubilee-4/+0
Add `size_of` and `size_of_val` and `align_of` and `align_of_val` to the prelude (Note: need to update the PR to add `align_of` and `align_of_val`, and remove the second commit with the myriad changes to appease the lint.) Many, many projects use `size_of` to get the size of a type. However, it's also often equally easy to hardcode a size (e.g. `8` instead of `size_of::<u64>()`). Minimizing friction in the use of `size_of` helps ensure that people use it and make code more self-documenting. The name `size_of` is unambiguous: the name alone, without any prefix or path, is self-explanatory and unmistakeable for any other functionality. Adding it to the prelude cannot produce any name conflicts, as any local definition will silently shadow the one from the prelude. Thus, we don't need to wait for a new edition prelude to add it.
2024-06-04Make deleting on LinkedList aware of the allocatorAndrei Damian-2/+41
2024-06-04update tracking issue for `const_binary_heap_new_in`coekjan-1/+1
2024-06-03Ignore `vec_deque_alloc_error::test_shrink_to_unwind` test on non-unwind targetsLukas Wirth-0/+1
2024-06-01stablize `const_binary_heap_constructor` & create an unstable feature ↵coekjan-2/+5
`const_binary_heap_new_in` for `BinaryHeap::new_in`
2024-05-26Rollup merge of #125561 - Cyborus04:stabilize-slice-flatten, r=scottmcmMatthias Krüger-4/+1
Stabilize `slice_flatten`
2024-05-26Stabilize `slice_flatten`Cyborus-4/+1