about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2022-11-14Add `Vec` storage optimization to `Arc` and add testsclubby789-19/+66
2022-11-14Reuse `Vec<T>` backing storage for `Rc<[T]>`clubby789-19/+65
Co-authored-by: joboet <jonas.boettiger@icloud.com>
2022-11-14Auto merge of #103858 - Mark-Simulacrum:bump-bootstrap, r=pietroalbinibors-21/+17
Bump bootstrap compiler to 1.66 This PR: - Bumps version placeholders to release - Bumps to latest beta - cfg-steps code r? `@pietroalbini`
2022-11-08Rollup merge of #104097 - RalfJung:miri-alloc-benches, r=thomccGuillaume Gomez-16/+19
run alloc benchmarks in Miri and fix UB Miri since recently has a "fake monotonic clock" that works even with isolation. Its measurements are not very meaningful but it means we can run these benches and check them for UB. And that's a good thing since there was UB here: fixes https://github.com/rust-lang/rust/issues/104096. r? ``@thomcc``
2022-11-08Rollup merge of #104093 - RalfJung:test-sizes, r=thomccGuillaume Gomez-0/+1
disable btree size tests on Miri Seems fine not to run these in Miri, they can't have UB anyway. And this lets us do layout randomization in Miri. r? ``@thomcc``
2022-11-07fmtRalf Jung-5/+5
2022-11-07Rollup merge of #104090 - wanghaha-dev:master, r=Dylan-DPCDylan DPC-1/+1
Modify comment syntax error Modify comment syntax error
2022-11-07run alloc benchmarks in Miri and fix UBRalf Jung-16/+19
2022-11-07disable btree size tests on MiriRalf Jung-0/+1
2022-11-07Modify comment syntax errorwanghaha-dev-1/+1
2022-11-07Rollup merge of #104056 - ripytide:patch-1, r=Mark-SimulacrumYuki Okushi-3/+3
Vec: IntoIterator signature consistency Also makes the code dryer.
2022-11-06cfg-step codeMark Rousskov-8/+4
2022-11-06Bump version placeholders to releaseMark Rousskov-13/+13
2022-11-06Vec: IntoIterator signature consistencyripytide-3/+3
Also makes the code dryer.
2022-11-05Fix unused_must_use warning for Box::from_rawAnett Seeker-1/+1
2022-11-05Enforce Tuple trait on Fn traitsMichael Goulet-0/+32
2022-11-03Fixed typosDouwe Schulte-2/+2
Fixed a typo that has been found on two locations in comments.
2022-11-02Rollup merge of #103807 - H4x5:string-extend-from-within-tracking-issue, ↵Dylan DPC-1/+1
r=Dylan-DPC Add tracking issue for `string_extend_from_within` Tracking issue: #103806 The original PR didn't create a tracking issue.
2022-10-31Rewrite implementation of `#[alloc_error_handler]`Amanieu d'Antras-6/+5
The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`. The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic. This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called. This is a prerequisite for the stabilization of `default_alloc_error_handler` (#102318).
2022-10-31Add tracking issue for `string_extend_from_within`Sky-1/+1
2022-10-26ptr::eq: clarify that comparing dyn Trait is fragileRalf Jung-10/+10
2022-10-25stabilise array methodsDylan DPC-1/+0
2022-10-24Clairify Vec::capacity docsNixon Enraght-Moony-2/+3
Fixes #103326
2022-10-24Rollup merge of #99578 - steffahn:remove_redundant_bound, r=thomccYuki Okushi-1/+0
Remove redundant lifetime bound from `impl Borrow for Cow` The lifetime bound `B::Owned: 'a` is redundant and doesn't make a difference, because `Cow<'a, B>` comes with an implicit `B: 'a`, and associated types will outlive lifetimes outlived by the `Self` type (and all the trait's generic parameters, of which there are none in this case), so the implicit `B: 'a` implies `B::Owned: 'a` anyway. The explicit lifetime bound here does however [end up in documentation](https://doc.rust-lang.org/std/borrow/enum.Cow.html#impl-Borrow%3CB%3E), and that's confusing in my opinion, so let's remove it ^^ _(Documentation right now, compare to `AsRef`, too:)_ ![Screenshot_20220722_014055](https://user-images.githubusercontent.com/3986214/180332665-424d0c05-afb3-40d8-a330-a57a2c9a494b.png)
2022-10-22Fix typo in docs of `String::leak`.Finn Bear-1/+1
2022-10-22Rollup merge of #103346 - HeroicKatora:metadata_of_const_pointer_argument, ↵Dylan DPC-2/+2
r=dtolnay Adjust argument type for mutable with_metadata_of (#75091) The method takes two pointer arguments: one `self` supplying the pointer value, and a second pointer supplying the metadata. The new parameter type more clearly reflects the actual requirements. The provenance of the metadata parameter is disregarded completely. Using a mutable pointer in the call site can be coerced to a const pointer while the reverse is not true. In some cases, the current parameter type can thus lead to a very slightly confusing additional cast. [Example](https://github.com/HeroicKatora/static-alloc/commit/cad93775eb9adc62f744651e3abf19513e69e7d0). ```rust // Manually taking an unsized object from a `ManuallyDrop` into another allocation. let val: &core::mem::ManuallyDrop<T> = …; let ptr = val as *const _ as *mut T; let ptr = uninit.as_ptr().with_metadata_of(ptr); ``` This could then instead be simplified to: ```rust // Manually taking an unsized object from a `ManuallyDrop` into another allocation. let val: &core::mem::ManuallyDrop<T> = …; let ptr = uninit.as_ptr().with_metadata_of(&**val); ``` Tracking issue: https://github.com/rust-lang/rust/issues/75091 ``@dtolnay`` you're reviewed #95249, would you mind chiming in?
2022-10-22Rollup merge of #103280 - finnbear:impl_string_leak_2, r=joshtriplettDylan DPC-1/+30
(#102929) Implement `String::leak` (attempt 2) Implementation of `String::leak` (#102929) ACP: https://github.com/rust-lang/libs-team/issues/109 Supersedes #102941 (see previous reviews there) ```@rustbot``` label +T-libs-api -T-libs
2022-10-22Rollup merge of #103359 - WaffleLapkin:drain_no_mut_qqq, r=scottmcmMatthias Krüger-3/+1
Remove incorrect comment in `Vec::drain` r? ``@scottmcm`` Turns out this comment wasn't correct for 6 years, since #34951, which switched from using `slice::IterMut` into using `slice::Iter`.
2022-10-21Remove incorrect comment in `Vec::drain`Maybe Waffle-3/+1
2022-10-21Reduce mutability in std-use of with_metadata_ofAndreas Molzer-2/+2
2022-10-19Put fn in the right place.Finn Bear-29/+29
2022-10-19Copy of #102941.Finn Bear-1/+30
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/>.